blob: 2c034a554c88c9848ef08da69f2eb00674d39247 [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 Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 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 Smart3621a712009-04-06 18:47:14 -0400391 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400392 * @vport: pointer to a host virtual N_Port data structure.
393 * @ndlp: pointer to a node-list data structure.
394 * @sp: pointer to service parameter data structure.
395 * @irsp: pointer to the IOCB within the lpfc response IOCB.
396 *
397 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
398 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
399 * port in a fabric topology. It properly sets up the parameters to the @ndlp
400 * from the IOCB response. It also check the newly assigned N_Port ID to the
401 * @vport against the previously assigned N_Port ID. If it is different from
402 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
403 * is invoked on all the remaining nodes with the @vport to unregister the
404 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
405 * is invoked to register login to the fabric.
406 *
407 * Return code
408 * 0 - Success (currently, always return 0)
409 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500410static int
James Smart2e0fef82007-06-17 19:56:36 -0500411lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
412 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500413{
James Smart2e0fef82007-06-17 19:56:36 -0500414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
415 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500416 struct lpfc_nodelist *np;
417 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500418
James Smart2e0fef82007-06-17 19:56:36 -0500419 spin_lock_irq(shost->host_lock);
420 vport->fc_flag |= FC_FABRIC;
421 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500422
423 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
424 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
425 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
426
427 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
428
429 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500430 spin_lock_irq(shost->host_lock);
431 vport->fc_flag |= FC_PUBLIC_LOOP;
432 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500433 } else {
434 /*
435 * If we are a N-port connected to a Fabric, fixup sparam's so
436 * logins to devices on remote loops work.
437 */
James Smart2e0fef82007-06-17 19:56:36 -0500438 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500439 }
440
James Smart2e0fef82007-06-17 19:56:36 -0500441 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500442 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500443 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500444 ndlp->nlp_class_sup = 0;
445 if (sp->cls1.classValid)
446 ndlp->nlp_class_sup |= FC_COS_CLASS1;
447 if (sp->cls2.classValid)
448 ndlp->nlp_class_sup |= FC_COS_CLASS2;
449 if (sp->cls3.classValid)
450 ndlp->nlp_class_sup |= FC_COS_CLASS3;
451 if (sp->cls4.classValid)
452 ndlp->nlp_class_sup |= FC_COS_CLASS4;
453 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
454 sp->cmn.bbRcvSizeLsb;
455 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
456
James Smart92d7f7b2007-06-17 19:56:38 -0500457 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
458 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400459 lpfc_printf_vlog(vport, KERN_WARNING,
460 LOG_ELS | LOG_VPORT,
461 "1816 FLOGI NPIV supported, "
462 "response data 0x%x\n",
463 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500464 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500465 } else {
466 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400467 to call reg_vnpid atleast for the physcial host */
468 lpfc_printf_vlog(vport, KERN_WARNING,
469 LOG_ELS | LOG_VPORT,
470 "1817 Fabric does not support NPIV "
471 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500472 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
473 }
474 }
475
476 if ((vport->fc_prevDID != vport->fc_myDID) &&
477 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
478
479 /* If our NportID changed, we need to ensure all
480 * remaining NPORTs get unreg_login'ed.
481 */
482 list_for_each_entry_safe(np, next_np,
483 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400484 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500485 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500486 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
487 !(np->nlp_flag & NLP_NPR_ADISC))
488 continue;
489 spin_lock_irq(shost->host_lock);
490 np->nlp_flag &= ~NLP_NPR_ADISC;
491 spin_unlock_irq(shost->host_lock);
492 lpfc_unreg_rpi(vport, np);
493 }
494 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
495 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500496 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500497 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500498 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500499 }
500 }
501
James Smart92d7f7b2007-06-17 19:56:38 -0500502 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500503
James Smart92d7f7b2007-06-17 19:56:38 -0500504 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
505 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
506 lpfc_register_new_vport(phba, vport, ndlp);
507 return 0;
508 }
509 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500510 return 0;
dea31012005-04-17 16:05:31 -0500511}
512
James Smarte59058c2008-08-24 21:49:00 -0400513/**
James Smart3621a712009-04-06 18:47:14 -0400514 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400515 * @vport: pointer to a host virtual N_Port data structure.
516 * @ndlp: pointer to a node-list data structure.
517 * @sp: pointer to service parameter data structure.
518 *
519 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
520 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
521 * in a point-to-point topology. First, the @vport's N_Port Name is compared
522 * with the received N_Port Name: if the @vport's N_Port Name is greater than
523 * the received N_Port Name lexicographically, this node shall assign local
524 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
525 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
526 * this node shall just wait for the remote node to issue PLOGI and assign
527 * N_Port IDs.
528 *
529 * Return code
530 * 0 - Success
531 * -ENXIO - Fail
532 **/
dea31012005-04-17 16:05:31 -0500533static int
James Smart2e0fef82007-06-17 19:56:36 -0500534lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
535 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500536{
James Smart2e0fef82007-06-17 19:56:36 -0500537 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
538 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500539 LPFC_MBOXQ_t *mbox;
540 int rc;
541
James Smart2e0fef82007-06-17 19:56:36 -0500542 spin_lock_irq(shost->host_lock);
543 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
544 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500545
546 phba->fc_edtov = FF_DEF_EDTOV;
547 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500548 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500549 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500550 if (rc >= 0) {
551 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500552 spin_lock_irq(shost->host_lock);
553 vport->fc_flag |= FC_PT2PT_PLOGI;
554 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500555
556 /*
557 * N_Port ID cannot be 0, set our to LocalID the other
558 * side will be RemoteID.
559 */
560
561 /* not equal */
562 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500563 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500564
565 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
566 if (!mbox)
567 goto fail;
568
569 lpfc_config_link(phba, mbox);
570
571 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500572 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400573 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500574 if (rc == MBX_NOT_FINISHED) {
575 mempool_free(mbox, phba->mbox_mem_pool);
576 goto fail;
577 }
James Smarte47c9092008-02-08 18:49:26 -0500578 /* Decrement ndlp reference count indicating that ndlp can be
579 * safely released when other references to it are done.
580 */
James Smart329f9bc2007-04-25 09:53:01 -0400581 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500582
James Smart2e0fef82007-06-17 19:56:36 -0500583 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500584 if (!ndlp) {
585 /*
586 * Cannot find existing Fabric ndlp, so allocate a
587 * new one
588 */
589 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
590 if (!ndlp)
591 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500592 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500593 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
594 ndlp = lpfc_enable_node(vport, ndlp,
595 NLP_STE_UNUSED_NODE);
596 if(!ndlp)
597 goto fail;
dea31012005-04-17 16:05:31 -0500598 }
599
600 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500601 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500602 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500603 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500604 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
606 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500607 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500608 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500609 } else
610 /* This side will wait for the PLOGI, decrement ndlp reference
611 * count indicating that ndlp can be released when other
612 * references to it are done.
613 */
James Smart329f9bc2007-04-25 09:53:01 -0400614 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500615
James Smart09372822008-01-11 01:52:54 -0500616 /* If we are pt2pt with another NPort, force NPIV off! */
617 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
618
James Smart2e0fef82007-06-17 19:56:36 -0500619 spin_lock_irq(shost->host_lock);
620 vport->fc_flag |= FC_PT2PT;
621 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500622
623 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500624 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500625 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500626fail:
dea31012005-04-17 16:05:31 -0500627 return -ENXIO;
628}
629
James Smarte59058c2008-08-24 21:49:00 -0400630/**
James Smart3621a712009-04-06 18:47:14 -0400631 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400632 * @phba: pointer to lpfc hba data structure.
633 * @cmdiocb: pointer to lpfc command iocb data structure.
634 * @rspiocb: pointer to lpfc response iocb data structure.
635 *
636 * This routine is the top-level completion callback function for issuing
637 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
638 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
639 * retry has been made (either immediately or delayed with lpfc_els_retry()
640 * returning 1), the command IOCB will be released and function returned.
641 * If the retry attempt has been given up (possibly reach the maximum
642 * number of retries), one additional decrement of ndlp reference shall be
643 * invoked before going out after releasing the command IOCB. This will
644 * actually release the remote node (Note, lpfc_els_free_iocb() will also
645 * invoke one decrement of ndlp reference count). If no error reported in
646 * the IOCB status, the command Port ID field is used to determine whether
647 * this is a point-to-point topology or a fabric topology: if the Port ID
648 * field is assigned, it is a fabric topology; otherwise, it is a
649 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
650 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
651 * specific topology completion conditions.
652 **/
dea31012005-04-17 16:05:31 -0500653static void
James Smart329f9bc2007-04-25 09:53:01 -0400654lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
655 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500656{
James Smart2e0fef82007-06-17 19:56:36 -0500657 struct lpfc_vport *vport = cmdiocb->vport;
658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500659 IOCB_t *irsp = &rspiocb->iocb;
660 struct lpfc_nodelist *ndlp = cmdiocb->context1;
661 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
662 struct serv_parm *sp;
663 int rc;
664
665 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500666 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500667 /* One additional decrement on node reference count to
668 * trigger the release of the node
669 */
James Smart329f9bc2007-04-25 09:53:01 -0400670 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500671 goto out;
672 }
673
James Smart858c9f62007-06-17 19:56:39 -0500674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
675 "FLOGI cmpl: status:x%x/x%x state:x%x",
676 irsp->ulpStatus, irsp->un.ulpWord[4],
677 vport->port_state);
678
dea31012005-04-17 16:05:31 -0500679 if (irsp->ulpStatus) {
680 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500681 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500682 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500683
dea31012005-04-17 16:05:31 -0500684 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500685 spin_lock_irq(shost->host_lock);
686 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
687 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500688
James Smart329f9bc2007-04-25 09:53:01 -0400689 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500690 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
691 * alpa map would take too long otherwise.
692 */
693 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400694 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500695 }
696
697 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
699 "0100 FLOGI failure Data: x%x x%x "
700 "x%x\n",
701 irsp->ulpStatus, irsp->un.ulpWord[4],
702 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500703 goto flogifail;
704 }
705
706 /*
707 * The FLogI succeeded. Sync the data for the CPU before
708 * accessing it.
709 */
710 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
711
712 sp = prsp->virt + sizeof(uint32_t);
713
714 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400715 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
716 "0101 FLOGI completes sucessfully "
717 "Data: x%x x%x x%x x%x\n",
718 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
719 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500720
James Smart2e0fef82007-06-17 19:56:36 -0500721 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500722 /*
723 * If Common Service Parameters indicate Nport
724 * we are point to point, if Fport we are Fabric.
725 */
726 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500727 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500728 else
James Smart2e0fef82007-06-17 19:56:36 -0500729 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500730
731 if (!rc)
732 goto out;
733 }
734
735flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400736 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500737
James Smart858c9f62007-06-17 19:56:39 -0500738 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500739 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500740 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500741
742 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500743 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400744 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
745 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
746 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
747 (phba->link_state != LPFC_CLEAR_LA)) {
748 /* If FLOGI failed enable link interrupt. */
749 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500750 }
dea31012005-04-17 16:05:31 -0500751out:
752 lpfc_els_free_iocb(phba, cmdiocb);
753}
754
James Smarte59058c2008-08-24 21:49:00 -0400755/**
James Smart3621a712009-04-06 18:47:14 -0400756 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400757 * @vport: pointer to a host virtual N_Port data structure.
758 * @ndlp: pointer to a node-list data structure.
759 * @retry: number of retries to the command IOCB.
760 *
761 * This routine issues a Fabric Login (FLOGI) Request ELS command
762 * for a @vport. The initiator service parameters are put into the payload
763 * of the FLOGI Request IOCB and the top-level callback function pointer
764 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
765 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
766 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
767 *
768 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
769 * will be incremented by 1 for holding the ndlp and the reference to ndlp
770 * will be stored into the context1 field of the IOCB for the completion
771 * callback function to the FLOGI ELS command.
772 *
773 * Return code
774 * 0 - successfully issued flogi iocb for @vport
775 * 1 - failed to issue flogi iocb for @vport
776 **/
dea31012005-04-17 16:05:31 -0500777static int
James Smart2e0fef82007-06-17 19:56:36 -0500778lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500779 uint8_t retry)
780{
James Smart2e0fef82007-06-17 19:56:36 -0500781 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500782 struct serv_parm *sp;
783 IOCB_t *icmd;
784 struct lpfc_iocbq *elsiocb;
785 struct lpfc_sli_ring *pring;
786 uint8_t *pcmd;
787 uint16_t cmdsize;
788 uint32_t tmo;
789 int rc;
790
791 pring = &phba->sli.ring[LPFC_ELS_RING];
792
James Smart92d7f7b2007-06-17 19:56:38 -0500793 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500794 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
795 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500796
James Smart488d1462006-03-07 15:02:37 -0500797 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500798 return 1;
dea31012005-04-17 16:05:31 -0500799
800 icmd = &elsiocb->iocb;
801 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
802
803 /* For FLOGI request, remainder of payload is service parameters */
804 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500805 pcmd += sizeof(uint32_t);
806 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500807 sp = (struct serv_parm *) pcmd;
808
809 /* Setup CSPs accordingly for Fabric */
810 sp->cmn.e_d_tov = 0;
811 sp->cmn.w2.r_a_tov = 0;
812 sp->cls1.classValid = 0;
813 sp->cls2.seqDelivery = 1;
814 sp->cls3.seqDelivery = 1;
815 if (sp->cmn.fcphLow < FC_PH3)
816 sp->cmn.fcphLow = FC_PH3;
817 if (sp->cmn.fcphHigh < FC_PH3)
818 sp->cmn.fcphHigh = FC_PH3;
819
James Smart92d7f7b2007-06-17 19:56:38 -0500820 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
821 sp->cmn.request_multiple_Nport = 1;
822
823 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
824 icmd->ulpCt_h = 1;
825 icmd->ulpCt_l = 0;
826 }
827
James Smart858c9f62007-06-17 19:56:39 -0500828 if (phba->fc_topology != TOPOLOGY_LOOP) {
829 icmd->un.elsreq64.myID = 0;
830 icmd->un.elsreq64.fl = 1;
831 }
832
dea31012005-04-17 16:05:31 -0500833 tmo = phba->fc_ratov;
834 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500835 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500836 phba->fc_ratov = tmo;
837
838 phba->fc_stat.elsXmitFLOGI++;
839 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500840
841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
842 "Issue FLOGI: opt:x%x",
843 phba->sli3_options, 0, 0);
844
James Smart92d7f7b2007-06-17 19:56:38 -0500845 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500846 if (rc == IOCB_ERROR) {
847 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500848 return 1;
dea31012005-04-17 16:05:31 -0500849 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500850 return 0;
dea31012005-04-17 16:05:31 -0500851}
852
James Smarte59058c2008-08-24 21:49:00 -0400853/**
James Smart3621a712009-04-06 18:47:14 -0400854 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -0400855 * @phba: pointer to lpfc hba data structure.
856 *
857 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
858 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
859 * list and issues an abort IOCB commond on each outstanding IOCB that
860 * contains a active Fabric_DID ndlp. Note that this function is to issue
861 * the abort IOCB command on all the outstanding IOCBs, thus when this
862 * function returns, it does not guarantee all the IOCBs are actually aborted.
863 *
864 * Return code
865 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
866 **/
dea31012005-04-17 16:05:31 -0500867int
James Smart2e0fef82007-06-17 19:56:36 -0500868lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500869{
870 struct lpfc_sli_ring *pring;
871 struct lpfc_iocbq *iocb, *next_iocb;
872 struct lpfc_nodelist *ndlp;
873 IOCB_t *icmd;
874
875 /* Abort outstanding I/O on NPort <nlp_DID> */
876 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400877 "0201 Abort outstanding I/O on NPort x%x\n",
878 Fabric_DID);
dea31012005-04-17 16:05:31 -0500879
880 pring = &phba->sli.ring[LPFC_ELS_RING];
881
882 /*
883 * Check the txcmplq for an iocb that matches the nport the driver is
884 * searching for.
885 */
James Smart2e0fef82007-06-17 19:56:36 -0500886 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500887 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
888 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500889 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
890 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500891 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -0400892 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
893 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -0400894 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -0500895 }
896 }
James Smart2e0fef82007-06-17 19:56:36 -0500897 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500898
899 return 0;
900}
901
James Smarte59058c2008-08-24 21:49:00 -0400902/**
James Smart3621a712009-04-06 18:47:14 -0400903 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400904 * @vport: pointer to a host virtual N_Port data structure.
905 *
906 * This routine issues an initial Fabric Login (FLOGI) for the @vport
907 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
908 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
909 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
910 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
911 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
912 * @vport.
913 *
914 * Return code
915 * 0 - failed to issue initial flogi for @vport
916 * 1 - successfully issued initial flogi for @vport
917 **/
dea31012005-04-17 16:05:31 -0500918int
James Smart2e0fef82007-06-17 19:56:36 -0500919lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500920{
James Smart2e0fef82007-06-17 19:56:36 -0500921 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500922 struct lpfc_nodelist *ndlp;
923
James Smart98c9ea52007-10-27 13:37:33 -0400924 vport->port_state = LPFC_FLOGI;
925 lpfc_set_disctmo(vport);
926
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500927 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500928 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500929 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500930 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500931 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
932 if (!ndlp)
933 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500934 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500935 /* Put ndlp onto node list */
936 lpfc_enqueue_node(vport, ndlp);
937 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
938 /* re-setup ndlp without removing from node list */
939 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
940 if (!ndlp)
941 return 0;
dea31012005-04-17 16:05:31 -0500942 }
James Smart87af33f2007-10-27 13:37:43 -0400943
James Smarte47c9092008-02-08 18:49:26 -0500944 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -0500945 /* This decrement of reference count to node shall kick off
946 * the release of the node.
947 */
James Smart329f9bc2007-04-25 09:53:01 -0400948 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -0500949
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500950 return 1;
dea31012005-04-17 16:05:31 -0500951}
952
James Smarte59058c2008-08-24 21:49:00 -0400953/**
James Smart3621a712009-04-06 18:47:14 -0400954 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -0400955 * @vport: pointer to a host virtual N_Port data structure.
956 *
957 * This routine issues an initial Fabric Discover (FDISC) for the @vport
958 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
959 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
960 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
961 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
962 * is then invoked with the @vport and the ndlp to perform the FDISC for the
963 * @vport.
964 *
965 * Return code
966 * 0 - failed to issue initial fdisc for @vport
967 * 1 - successfully issued initial fdisc for @vport
968 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500969int
970lpfc_initial_fdisc(struct lpfc_vport *vport)
971{
972 struct lpfc_hba *phba = vport->phba;
973 struct lpfc_nodelist *ndlp;
974
975 /* First look for the Fabric ndlp */
976 ndlp = lpfc_findnode_did(vport, Fabric_DID);
977 if (!ndlp) {
978 /* Cannot find existing Fabric ndlp, so allocate a new one */
979 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
980 if (!ndlp)
981 return 0;
982 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500983 /* Put ndlp onto node list */
984 lpfc_enqueue_node(vport, ndlp);
985 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
986 /* re-setup ndlp without removing from node list */
987 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
988 if (!ndlp)
989 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500990 }
James Smarte47c9092008-02-08 18:49:26 -0500991
James Smart92d7f7b2007-06-17 19:56:38 -0500992 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500993 /* decrement node reference count to trigger the release of
994 * the node.
995 */
James Smart92d7f7b2007-06-17 19:56:38 -0500996 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500997 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500998 }
999 return 1;
1000}
James Smart87af33f2007-10-27 13:37:43 -04001001
James Smarte59058c2008-08-24 21:49:00 -04001002/**
James Smart3621a712009-04-06 18:47:14 -04001003 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001004 * @vport: pointer to a host virtual N_Port data structure.
1005 *
1006 * This routine checks whether there are more remaining Port Logins
1007 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1008 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1009 * to issue ELS PLOGIs up to the configured discover threads with the
1010 * @vport (@vport->cfg_discovery_threads). The function also decrement
1011 * the @vport's num_disc_node by 1 if it is not already 0.
1012 **/
James Smart87af33f2007-10-27 13:37:43 -04001013void
James Smart2e0fef82007-06-17 19:56:36 -05001014lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001015{
1016 int sentplogi;
1017
James Smart2e0fef82007-06-17 19:56:36 -05001018 if (vport->num_disc_nodes)
1019 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001020
1021 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001022 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1023 "0232 Continue discovery with %d PLOGIs to go "
1024 "Data: x%x x%x x%x\n",
1025 vport->num_disc_nodes, vport->fc_plogi_cnt,
1026 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001027 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001028 if (vport->fc_flag & FC_NLP_MORE)
1029 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1030 sentplogi = lpfc_els_disc_plogi(vport);
1031
dea31012005-04-17 16:05:31 -05001032 return;
1033}
1034
James Smarte59058c2008-08-24 21:49:00 -04001035/**
James Smart3621a712009-04-06 18:47:14 -04001036 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001037 * @phba: pointer to lpfc hba data structure.
1038 * @prsp: pointer to response IOCB payload.
1039 * @ndlp: pointer to a node-list data structure.
1040 *
1041 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1042 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1043 * The following cases are considered N_Port confirmed:
1044 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1045 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1046 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1047 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1048 * 1) if there is a node on vport list other than the @ndlp with the same
1049 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1050 * on that node to release the RPI associated with the node; 2) if there is
1051 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1052 * into, a new node shall be allocated (or activated). In either case, the
1053 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1054 * be released and the new_ndlp shall be put on to the vport node list and
1055 * its pointer returned as the confirmed node.
1056 *
1057 * Note that before the @ndlp got "released", the keepDID from not-matching
1058 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1059 * of the @ndlp. This is because the release of @ndlp is actually to put it
1060 * into an inactive state on the vport node list and the vport node list
1061 * management algorithm does not allow two node with a same DID.
1062 *
1063 * Return code
1064 * pointer to the PLOGI N_Port @ndlp
1065 **/
James Smart488d1462006-03-07 15:02:37 -05001066static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001067lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001068 struct lpfc_nodelist *ndlp)
1069{
James Smart2e0fef82007-06-17 19:56:36 -05001070 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001071 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001072 struct lpfc_rport_data *rdata;
1073 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001074 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001075 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001076 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001077
James Smart2fb9bd82006-12-02 13:33:57 -05001078 /* Fabric nodes can have the same WWPN so we don't bother searching
1079 * by WWPN. Just return the ndlp that was given to us.
1080 */
1081 if (ndlp->nlp_type & NLP_FABRIC)
1082 return ndlp;
1083
James Smart92d7f7b2007-06-17 19:56:38 -05001084 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001085 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001086
James Smart685f0bf2007-04-25 09:53:08 -04001087 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001088 * we have for that ndlp. If not, we have some work to do.
1089 */
James Smart2e0fef82007-06-17 19:56:36 -05001090 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001091
James Smarte47c9092008-02-08 18:49:26 -05001092 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001093 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001094
1095 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001096 rc = memcmp(&ndlp->nlp_portname, name,
1097 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001098 if (!rc)
1099 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001100 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1101 if (!new_ndlp)
1102 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001103 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001104 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001105 rc = memcmp(&ndlp->nlp_portname, name,
1106 sizeof(struct lpfc_name));
1107 if (!rc)
1108 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001109 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1110 NLP_STE_UNUSED_NODE);
1111 if (!new_ndlp)
1112 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001113 keepDID = new_ndlp->nlp_DID;
1114 } else
1115 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001116
James Smart2e0fef82007-06-17 19:56:36 -05001117 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001118 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001119 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001120
1121 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1122 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1123 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1124
James Smarte47c9092008-02-08 18:49:26 -05001125 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001126 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001127
James Smart2e0fef82007-06-17 19:56:36 -05001128 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001129 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1130 /* The new_ndlp is replacing ndlp totally, so we need
1131 * to put ndlp on UNUSED list and try to free it.
1132 */
James Smart0ff10d42008-01-11 01:52:36 -05001133
1134 /* Fix up the rport accordingly */
1135 rport = ndlp->rport;
1136 if (rport) {
1137 rdata = rport->dd_data;
1138 if (rdata->pnode == ndlp) {
1139 lpfc_nlp_put(ndlp);
1140 ndlp->rport = NULL;
1141 rdata->pnode = lpfc_nlp_get(new_ndlp);
1142 new_ndlp->rport = rport;
1143 }
1144 new_ndlp->nlp_type = ndlp->nlp_type;
1145 }
James Smart58da1ff2008-04-07 10:15:56 -04001146 /* We shall actually free the ndlp with both nlp_DID and
1147 * nlp_portname fields equals 0 to avoid any ndlp on the
1148 * nodelist never to be used.
1149 */
1150 if (ndlp->nlp_DID == 0) {
1151 spin_lock_irq(&phba->ndlp_lock);
1152 NLP_SET_FREE_REQ(ndlp);
1153 spin_unlock_irq(&phba->ndlp_lock);
1154 }
James Smart0ff10d42008-01-11 01:52:36 -05001155
James Smart58da1ff2008-04-07 10:15:56 -04001156 /* Two ndlps cannot have the same did on the nodelist */
1157 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001158 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001159 }
James Smart92795652006-07-06 15:50:02 -04001160 else {
James Smart2e0fef82007-06-17 19:56:36 -05001161 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001162 /* Two ndlps cannot have the same did */
1163 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001164 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001165 }
James Smart488d1462006-03-07 15:02:37 -05001166 return new_ndlp;
1167}
1168
James Smarte59058c2008-08-24 21:49:00 -04001169/**
James Smart3621a712009-04-06 18:47:14 -04001170 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001171 * @vport: pointer to a host virtual N_Port data structure.
1172 *
1173 * This routine checks whether more Registration State Change
1174 * Notifications (RSCNs) came in while the discovery state machine was in
1175 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1176 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1177 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1178 * handling the RSCNs.
1179 **/
James Smart87af33f2007-10-27 13:37:43 -04001180void
1181lpfc_end_rscn(struct lpfc_vport *vport)
1182{
1183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1184
1185 if (vport->fc_flag & FC_RSCN_MODE) {
1186 /*
1187 * Check to see if more RSCNs came in while we were
1188 * processing this one.
1189 */
1190 if (vport->fc_rscn_id_cnt ||
1191 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1192 lpfc_els_handle_rscn(vport);
1193 else {
1194 spin_lock_irq(shost->host_lock);
1195 vport->fc_flag &= ~FC_RSCN_MODE;
1196 spin_unlock_irq(shost->host_lock);
1197 }
1198 }
1199}
1200
James Smarte59058c2008-08-24 21:49:00 -04001201/**
James Smart3621a712009-04-06 18:47:14 -04001202 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001203 * @phba: pointer to lpfc hba data structure.
1204 * @cmdiocb: pointer to lpfc command iocb data structure.
1205 * @rspiocb: pointer to lpfc response iocb data structure.
1206 *
1207 * This routine is the completion callback function for issuing the Port
1208 * Login (PLOGI) command. For PLOGI completion, there must be an active
1209 * ndlp on the vport node list that matches the remote node ID from the
1210 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1211 * ignored and command IOCB released. The PLOGI response IOCB status is
1212 * checked for error conditons. If there is error status reported, PLOGI
1213 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1214 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1215 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1216 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1217 * there are additional N_Port nodes with the vport that need to perform
1218 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1219 * PLOGIs.
1220 **/
dea31012005-04-17 16:05:31 -05001221static void
James Smart2e0fef82007-06-17 19:56:36 -05001222lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1223 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001224{
James Smart2e0fef82007-06-17 19:56:36 -05001225 struct lpfc_vport *vport = cmdiocb->vport;
1226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001227 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001228 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001229 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001230 int disc, rc, did, type;
1231
dea31012005-04-17 16:05:31 -05001232 /* we pass cmdiocb to state machine which needs rspiocb as well */
1233 cmdiocb->context_un.rsp_iocb = rspiocb;
1234
1235 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1237 "PLOGI cmpl: status:x%x/x%x did:x%x",
1238 irsp->ulpStatus, irsp->un.ulpWord[4],
1239 irsp->un.elsreq64.remoteID);
1240
James Smart2e0fef82007-06-17 19:56:36 -05001241 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001242 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001243 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1244 "0136 PLOGI completes to NPort x%x "
1245 "with no ndlp. Data: x%x x%x x%x\n",
1246 irsp->un.elsreq64.remoteID,
1247 irsp->ulpStatus, irsp->un.ulpWord[4],
1248 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001249 goto out;
James Smarted957682007-06-17 19:56:37 -05001250 }
dea31012005-04-17 16:05:31 -05001251
1252 /* Since ndlp can be freed in the disc state machine, note if this node
1253 * is being used during discovery.
1254 */
James Smart2e0fef82007-06-17 19:56:36 -05001255 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001256 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001257 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001258 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001259 rc = 0;
1260
1261 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001262 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1263 "0102 PLOGI completes to NPort x%x "
1264 "Data: x%x x%x x%x x%x x%x\n",
1265 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1266 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001267 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001268 if (lpfc_els_chk_latt(vport)) {
1269 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001270 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001271 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001272 goto out;
1273 }
1274
1275 /* ndlp could be freed in DSM, save these values now */
1276 type = ndlp->nlp_type;
1277 did = ndlp->nlp_DID;
1278
1279 if (irsp->ulpStatus) {
1280 /* Check for retry */
1281 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1282 /* ELS command is being retried */
1283 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001284 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001285 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001286 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001287 }
1288 goto out;
1289 }
dea31012005-04-17 16:05:31 -05001290 /* PLOGI failed */
1291 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001292 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001293 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001294 else
James Smart2e0fef82007-06-17 19:56:36 -05001295 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001296 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001297 } else {
1298 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001299 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001300 cmdiocb->context2)->list.next,
1301 struct lpfc_dmabuf, list);
1302 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001303 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001304 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001305 }
1306
James Smart2e0fef82007-06-17 19:56:36 -05001307 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001308 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001309 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001310
James Smart2e0fef82007-06-17 19:56:36 -05001311 if (vport->num_disc_nodes == 0) {
1312 spin_lock_irq(shost->host_lock);
1313 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1314 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001315
James Smart2e0fef82007-06-17 19:56:36 -05001316 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001317 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001318 }
1319 }
1320
1321out:
1322 lpfc_els_free_iocb(phba, cmdiocb);
1323 return;
1324}
1325
James Smarte59058c2008-08-24 21:49:00 -04001326/**
James Smart3621a712009-04-06 18:47:14 -04001327 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001328 * @vport: pointer to a host virtual N_Port data structure.
1329 * @did: destination port identifier.
1330 * @retry: number of retries to the command IOCB.
1331 *
1332 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1333 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1334 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1335 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1336 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1337 *
1338 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1339 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1340 * will be stored into the context1 field of the IOCB for the completion
1341 * callback function to the PLOGI ELS command.
1342 *
1343 * Return code
1344 * 0 - Successfully issued a plogi for @vport
1345 * 1 - failed to issue a plogi for @vport
1346 **/
dea31012005-04-17 16:05:31 -05001347int
James Smart2e0fef82007-06-17 19:56:36 -05001348lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001349{
James Smart2e0fef82007-06-17 19:56:36 -05001350 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001351 struct serv_parm *sp;
1352 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001353 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001354 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001355 struct lpfc_sli *psli;
1356 uint8_t *pcmd;
1357 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001358 int ret;
dea31012005-04-17 16:05:31 -05001359
1360 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001361
James Smart98c9ea52007-10-27 13:37:33 -04001362 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001363 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1364 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001365
James Smarte47c9092008-02-08 18:49:26 -05001366 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001367 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001368 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001369 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001370 if (!elsiocb)
1371 return 1;
dea31012005-04-17 16:05:31 -05001372
1373 icmd = &elsiocb->iocb;
1374 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1375
1376 /* For PLOGI request, remainder of payload is service parameters */
1377 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001378 pcmd += sizeof(uint32_t);
1379 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001380 sp = (struct serv_parm *) pcmd;
1381
1382 if (sp->cmn.fcphLow < FC_PH_4_3)
1383 sp->cmn.fcphLow = FC_PH_4_3;
1384
1385 if (sp->cmn.fcphHigh < FC_PH3)
1386 sp->cmn.fcphHigh = FC_PH3;
1387
James Smart858c9f62007-06-17 19:56:39 -05001388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1389 "Issue PLOGI: did:x%x",
1390 did, 0, 0);
1391
dea31012005-04-17 16:05:31 -05001392 phba->fc_stat.elsXmitPLOGI++;
1393 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001394 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001395
1396 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001397 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398 return 1;
dea31012005-04-17 16:05:31 -05001399 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001400 return 0;
dea31012005-04-17 16:05:31 -05001401}
1402
James Smarte59058c2008-08-24 21:49:00 -04001403/**
James Smart3621a712009-04-06 18:47:14 -04001404 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001405 * @phba: pointer to lpfc hba data structure.
1406 * @cmdiocb: pointer to lpfc command iocb data structure.
1407 * @rspiocb: pointer to lpfc response iocb data structure.
1408 *
1409 * This routine is the completion callback function for a Process Login
1410 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1411 * status. If there is error status reported, PRLI retry shall be attempted
1412 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1413 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1414 * ndlp to mark the PRLI completion.
1415 **/
dea31012005-04-17 16:05:31 -05001416static void
James Smart2e0fef82007-06-17 19:56:36 -05001417lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1418 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001419{
James Smart2e0fef82007-06-17 19:56:36 -05001420 struct lpfc_vport *vport = cmdiocb->vport;
1421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001422 IOCB_t *irsp;
1423 struct lpfc_sli *psli;
1424 struct lpfc_nodelist *ndlp;
1425
1426 psli = &phba->sli;
1427 /* we pass cmdiocb to state machine which needs rspiocb as well */
1428 cmdiocb->context_un.rsp_iocb = rspiocb;
1429
1430 irsp = &(rspiocb->iocb);
1431 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001432 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001433 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001434 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001435
James Smart858c9f62007-06-17 19:56:39 -05001436 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1437 "PRLI cmpl: status:x%x/x%x did:x%x",
1438 irsp->ulpStatus, irsp->un.ulpWord[4],
1439 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001440 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001441 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1442 "0103 PRLI completes to NPort x%x "
1443 "Data: x%x x%x x%x x%x\n",
1444 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1445 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001446
James Smart2e0fef82007-06-17 19:56:36 -05001447 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001448 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001449 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001450 goto out;
1451
1452 if (irsp->ulpStatus) {
1453 /* Check for retry */
1454 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1455 /* ELS command is being retried */
1456 goto out;
1457 }
1458 /* PRLI failed */
1459 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001460 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001461 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001462 else
James Smart2e0fef82007-06-17 19:56:36 -05001463 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001464 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001465 } else
dea31012005-04-17 16:05:31 -05001466 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001467 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001468 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001469out:
1470 lpfc_els_free_iocb(phba, cmdiocb);
1471 return;
1472}
1473
James Smarte59058c2008-08-24 21:49:00 -04001474/**
James Smart3621a712009-04-06 18:47:14 -04001475 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001476 * @vport: pointer to a host virtual N_Port data structure.
1477 * @ndlp: pointer to a node-list data structure.
1478 * @retry: number of retries to the command IOCB.
1479 *
1480 * This routine issues a Process Login (PRLI) ELS command for the
1481 * @vport. The PRLI service parameters are set up in the payload of the
1482 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1483 * is put to the IOCB completion callback func field before invoking the
1484 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1485 *
1486 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1487 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1488 * will be stored into the context1 field of the IOCB for the completion
1489 * callback function to the PRLI ELS command.
1490 *
1491 * Return code
1492 * 0 - successfully issued prli iocb command for @vport
1493 * 1 - failed to issue prli iocb command for @vport
1494 **/
dea31012005-04-17 16:05:31 -05001495int
James Smart2e0fef82007-06-17 19:56:36 -05001496lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001497 uint8_t retry)
1498{
James Smart2e0fef82007-06-17 19:56:36 -05001499 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1500 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001501 PRLI *npr;
1502 IOCB_t *icmd;
1503 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001504 uint8_t *pcmd;
1505 uint16_t cmdsize;
1506
James Smart92d7f7b2007-06-17 19:56:38 -05001507 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001508 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1509 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001510 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001511 return 1;
dea31012005-04-17 16:05:31 -05001512
1513 icmd = &elsiocb->iocb;
1514 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1515
1516 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001517 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001518 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001519 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001520
1521 /* For PRLI, remainder of payload is PRLI parameter page */
1522 npr = (PRLI *) pcmd;
1523 /*
1524 * If our firmware version is 3.20 or later,
1525 * set the following bits for FC-TAPE support.
1526 */
1527 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1528 npr->ConfmComplAllowed = 1;
1529 npr->Retry = 1;
1530 npr->TaskRetryIdReq = 1;
1531 }
1532 npr->estabImagePair = 1;
1533 npr->readXferRdyDis = 1;
1534
1535 /* For FCP support */
1536 npr->prliType = PRLI_FCP_TYPE;
1537 npr->initiatorFunc = 1;
1538
James Smart858c9f62007-06-17 19:56:39 -05001539 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1540 "Issue PRLI: did:x%x",
1541 ndlp->nlp_DID, 0, 0);
1542
dea31012005-04-17 16:05:31 -05001543 phba->fc_stat.elsXmitPRLI++;
1544 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001545 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001546 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001547 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001548 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1549 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001550 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001551 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001552 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001553 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001554 return 1;
dea31012005-04-17 16:05:31 -05001555 }
James Smart2e0fef82007-06-17 19:56:36 -05001556 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001557 return 0;
dea31012005-04-17 16:05:31 -05001558}
1559
James Smarte59058c2008-08-24 21:49:00 -04001560/**
James Smart3621a712009-04-06 18:47:14 -04001561 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001562 * @vport: pointer to a host virtual N_Port data structure.
1563 *
1564 * This routine performs Registration State Change Notification (RSCN)
1565 * discovery for a @vport. If the @vport's node port recovery count is not
1566 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1567 * the nodes that need recovery. If none of the PLOGI were needed through
1568 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1569 * invoked to check and handle possible more RSCN came in during the period
1570 * of processing the current ones.
1571 **/
1572static void
1573lpfc_rscn_disc(struct lpfc_vport *vport)
1574{
1575 lpfc_can_disctmo(vport);
1576
1577 /* RSCN discovery */
1578 /* go thru NPR nodes and issue ELS PLOGIs */
1579 if (vport->fc_npr_cnt)
1580 if (lpfc_els_disc_plogi(vport))
1581 return;
1582
1583 lpfc_end_rscn(vport);
1584}
1585
1586/**
James Smart3621a712009-04-06 18:47:14 -04001587 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001588 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1589 *
1590 * This function is called when the final ADISC is completed during discovery.
1591 * This function handles clearing link attention or issuing reg_vpi depending
1592 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1593 * discovery.
1594 * This function is called with no locks held.
1595 **/
1596static void
1597lpfc_adisc_done(struct lpfc_vport *vport)
1598{
1599 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1600 struct lpfc_hba *phba = vport->phba;
1601
1602 /*
1603 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1604 * and continue discovery.
1605 */
1606 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1607 !(vport->fc_flag & FC_RSCN_MODE)) {
1608 lpfc_issue_reg_vpi(phba, vport);
1609 return;
1610 }
1611 /*
1612 * For SLI2, we need to set port_state to READY
1613 * and continue discovery.
1614 */
1615 if (vport->port_state < LPFC_VPORT_READY) {
1616 /* If we get here, there is nothing to ADISC */
1617 if (vport->port_type == LPFC_PHYSICAL_PORT)
1618 lpfc_issue_clear_la(phba, vport);
1619 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1620 vport->num_disc_nodes = 0;
1621 /* go thru NPR list, issue ELS PLOGIs */
1622 if (vport->fc_npr_cnt)
1623 lpfc_els_disc_plogi(vport);
1624 if (!vport->num_disc_nodes) {
1625 spin_lock_irq(shost->host_lock);
1626 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1627 spin_unlock_irq(shost->host_lock);
1628 lpfc_can_disctmo(vport);
1629 lpfc_end_rscn(vport);
1630 }
1631 }
1632 vport->port_state = LPFC_VPORT_READY;
1633 } else
1634 lpfc_rscn_disc(vport);
1635}
1636
1637/**
James Smart3621a712009-04-06 18:47:14 -04001638 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001639 * @vport: pointer to a host virtual N_Port data structure.
1640 *
1641 * This routine determines whether there are more ndlps on a @vport
1642 * node list need to have Address Discover (ADISC) issued. If so, it will
1643 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1644 * remaining nodes which need to have ADISC sent.
1645 **/
James Smart0ff10d42008-01-11 01:52:36 -05001646void
James Smart2e0fef82007-06-17 19:56:36 -05001647lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001648{
1649 int sentadisc;
1650
James Smart2e0fef82007-06-17 19:56:36 -05001651 if (vport->num_disc_nodes)
1652 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001653 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001654 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1655 "0210 Continue discovery with %d ADISCs to go "
1656 "Data: x%x x%x x%x\n",
1657 vport->num_disc_nodes, vport->fc_adisc_cnt,
1658 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001659 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001660 if (vport->fc_flag & FC_NLP_MORE) {
1661 lpfc_set_disctmo(vport);
1662 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1663 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001664 }
James Smart90160e02008-08-24 21:49:45 -04001665 if (!vport->num_disc_nodes)
1666 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001667 return;
1668}
1669
James Smarte59058c2008-08-24 21:49:00 -04001670/**
James Smart3621a712009-04-06 18:47:14 -04001671 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001672 * @phba: pointer to lpfc hba data structure.
1673 * @cmdiocb: pointer to lpfc command iocb data structure.
1674 * @rspiocb: pointer to lpfc response iocb data structure.
1675 *
1676 * This routine is the completion function for issuing the Address Discover
1677 * (ADISC) command. It first checks to see whether link went down during
1678 * the discovery process. If so, the node will be marked as node port
1679 * recovery for issuing discover IOCB by the link attention handler and
1680 * exit. Otherwise, the response status is checked. If error was reported
1681 * in the response status, the ADISC command shall be retried by invoking
1682 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1683 * the response status, the state machine is invoked to set transition
1684 * with respect to NLP_EVT_CMPL_ADISC event.
1685 **/
dea31012005-04-17 16:05:31 -05001686static void
James Smart2e0fef82007-06-17 19:56:36 -05001687lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1688 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001689{
James Smart2e0fef82007-06-17 19:56:36 -05001690 struct lpfc_vport *vport = cmdiocb->vport;
1691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001692 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001693 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001694 int disc;
dea31012005-04-17 16:05:31 -05001695
1696 /* we pass cmdiocb to state machine which needs rspiocb as well */
1697 cmdiocb->context_un.rsp_iocb = rspiocb;
1698
1699 irsp = &(rspiocb->iocb);
1700 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001701
James Smart858c9f62007-06-17 19:56:39 -05001702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1703 "ADISC cmpl: status:x%x/x%x did:x%x",
1704 irsp->ulpStatus, irsp->un.ulpWord[4],
1705 ndlp->nlp_DID);
1706
dea31012005-04-17 16:05:31 -05001707 /* Since ndlp can be freed in the disc state machine, note if this node
1708 * is being used during discovery.
1709 */
James Smart2e0fef82007-06-17 19:56:36 -05001710 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001711 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001712 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001713 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001714 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001715 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1716 "0104 ADISC completes to NPort x%x "
1717 "Data: x%x x%x x%x x%x x%x\n",
1718 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1719 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001720 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001721 if (lpfc_els_chk_latt(vport)) {
1722 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001723 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001724 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001725 goto out;
1726 }
1727
1728 if (irsp->ulpStatus) {
1729 /* Check for retry */
1730 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1731 /* ELS command is being retried */
1732 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001733 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001734 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001735 spin_unlock_irq(shost->host_lock);
1736 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001737 }
1738 goto out;
1739 }
1740 /* ADISC failed */
1741 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001742 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001743 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001744 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001745 } else
dea31012005-04-17 16:05:31 -05001746 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001747 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001748 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001749
James Smart90160e02008-08-24 21:49:45 -04001750 /* Check to see if there are more ADISCs to be sent */
1751 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001752 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001753out:
1754 lpfc_els_free_iocb(phba, cmdiocb);
1755 return;
1756}
1757
James Smarte59058c2008-08-24 21:49:00 -04001758/**
James Smart3621a712009-04-06 18:47:14 -04001759 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001760 * @vport: pointer to a virtual N_Port data structure.
1761 * @ndlp: pointer to a node-list data structure.
1762 * @retry: number of retries to the command IOCB.
1763 *
1764 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1765 * @vport. It prepares the payload of the ADISC ELS command, updates the
1766 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1767 * to issue the ADISC ELS command.
1768 *
1769 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1770 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1771 * will be stored into the context1 field of the IOCB for the completion
1772 * callback function to the ADISC ELS command.
1773 *
1774 * Return code
1775 * 0 - successfully issued adisc
1776 * 1 - failed to issue adisc
1777 **/
dea31012005-04-17 16:05:31 -05001778int
James Smart2e0fef82007-06-17 19:56:36 -05001779lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001780 uint8_t retry)
1781{
James Smart2e0fef82007-06-17 19:56:36 -05001782 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1783 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001784 ADISC *ap;
1785 IOCB_t *icmd;
1786 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001787 uint8_t *pcmd;
1788 uint16_t cmdsize;
1789
James Smart92d7f7b2007-06-17 19:56:38 -05001790 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001791 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1792 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001793 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001794 return 1;
dea31012005-04-17 16:05:31 -05001795
1796 icmd = &elsiocb->iocb;
1797 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1798
1799 /* For ADISC request, remainder of payload is service parameters */
1800 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001801 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001802
1803 /* Fill in ADISC payload */
1804 ap = (ADISC *) pcmd;
1805 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001806 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1807 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001808 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001809
James Smart858c9f62007-06-17 19:56:39 -05001810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1811 "Issue ADISC: did:x%x",
1812 ndlp->nlp_DID, 0, 0);
1813
dea31012005-04-17 16:05:31 -05001814 phba->fc_stat.elsXmitADISC++;
1815 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001816 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001817 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001818 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001819 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1820 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001821 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001822 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001823 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001824 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001825 return 1;
dea31012005-04-17 16:05:31 -05001826 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001827 return 0;
dea31012005-04-17 16:05:31 -05001828}
1829
James Smarte59058c2008-08-24 21:49:00 -04001830/**
James Smart3621a712009-04-06 18:47:14 -04001831 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04001832 * @phba: pointer to lpfc hba data structure.
1833 * @cmdiocb: pointer to lpfc command iocb data structure.
1834 * @rspiocb: pointer to lpfc response iocb data structure.
1835 *
1836 * This routine is the completion function for issuing the ELS Logout (LOGO)
1837 * command. If no error status was reported from the LOGO response, the
1838 * state machine of the associated ndlp shall be invoked for transition with
1839 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1840 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1841 **/
dea31012005-04-17 16:05:31 -05001842static void
James Smart2e0fef82007-06-17 19:56:36 -05001843lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1844 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001845{
James Smart2e0fef82007-06-17 19:56:36 -05001846 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1847 struct lpfc_vport *vport = ndlp->vport;
1848 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001849 IOCB_t *irsp;
1850 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001851
1852 psli = &phba->sli;
1853 /* we pass cmdiocb to state machine which needs rspiocb as well */
1854 cmdiocb->context_un.rsp_iocb = rspiocb;
1855
1856 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001857 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001858 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001859 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001860
James Smart858c9f62007-06-17 19:56:39 -05001861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1862 "LOGO cmpl: status:x%x/x%x did:x%x",
1863 irsp->ulpStatus, irsp->un.ulpWord[4],
1864 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001865 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001866 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1867 "0105 LOGO completes to NPort x%x "
1868 "Data: x%x x%x x%x x%x\n",
1869 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1870 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001871 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001872 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001873 goto out;
1874
James Smart92d7f7b2007-06-17 19:56:38 -05001875 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1876 /* NLP_EVT_DEVICE_RM should unregister the RPI
1877 * which should abort all outstanding IOs.
1878 */
1879 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1880 NLP_EVT_DEVICE_RM);
1881 goto out;
1882 }
1883
dea31012005-04-17 16:05:31 -05001884 if (irsp->ulpStatus) {
1885 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001886 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001887 /* ELS command is being retried */
1888 goto out;
dea31012005-04-17 16:05:31 -05001889 /* LOGO failed */
1890 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001891 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001892 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001893 else
James Smart2e0fef82007-06-17 19:56:36 -05001894 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001895 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05001896 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001897 /* Good status, call state machine.
1898 * This will unregister the rpi if needed.
1899 */
James Smart2e0fef82007-06-17 19:56:36 -05001900 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001901 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001902out:
1903 lpfc_els_free_iocb(phba, cmdiocb);
1904 return;
1905}
1906
James Smarte59058c2008-08-24 21:49:00 -04001907/**
James Smart3621a712009-04-06 18:47:14 -04001908 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001909 * @vport: pointer to a virtual N_Port data structure.
1910 * @ndlp: pointer to a node-list data structure.
1911 * @retry: number of retries to the command IOCB.
1912 *
1913 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1914 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1915 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1916 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1917 *
1918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1920 * will be stored into the context1 field of the IOCB for the completion
1921 * callback function to the LOGO ELS command.
1922 *
1923 * Return code
1924 * 0 - successfully issued logo
1925 * 1 - failed to issue logo
1926 **/
dea31012005-04-17 16:05:31 -05001927int
James Smart2e0fef82007-06-17 19:56:36 -05001928lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001929 uint8_t retry)
1930{
James Smart2e0fef82007-06-17 19:56:36 -05001931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1932 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001933 IOCB_t *icmd;
1934 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001935 uint8_t *pcmd;
1936 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001937 int rc;
dea31012005-04-17 16:05:31 -05001938
James Smart98c9ea52007-10-27 13:37:33 -04001939 spin_lock_irq(shost->host_lock);
1940 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1941 spin_unlock_irq(shost->host_lock);
1942 return 0;
1943 }
1944 spin_unlock_irq(shost->host_lock);
1945
James Smart92d7f7b2007-06-17 19:56:38 -05001946 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001947 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1948 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001949 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001950 return 1;
dea31012005-04-17 16:05:31 -05001951
1952 icmd = &elsiocb->iocb;
1953 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1954 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001955 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001956
1957 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001958 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001959 pcmd += sizeof(uint32_t);
1960 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001961
James Smart858c9f62007-06-17 19:56:39 -05001962 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1963 "Issue LOGO: did:x%x",
1964 ndlp->nlp_DID, 0, 0);
1965
dea31012005-04-17 16:05:31 -05001966 phba->fc_stat.elsXmitLOGO++;
1967 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001968 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001969 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001970 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001971 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001972
1973 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001974 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001975 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001976 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001977 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001978 return 1;
dea31012005-04-17 16:05:31 -05001979 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001980 return 0;
dea31012005-04-17 16:05:31 -05001981}
1982
James Smarte59058c2008-08-24 21:49:00 -04001983/**
James Smart3621a712009-04-06 18:47:14 -04001984 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04001985 * @phba: pointer to lpfc hba data structure.
1986 * @cmdiocb: pointer to lpfc command iocb data structure.
1987 * @rspiocb: pointer to lpfc response iocb data structure.
1988 *
1989 * This routine is a generic completion callback function for ELS commands.
1990 * Specifically, it is the callback function which does not need to perform
1991 * any command specific operations. It is currently used by the ELS command
1992 * issuing routines for the ELS State Change Request (SCR),
1993 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
1994 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
1995 * certain debug loggings, this callback function simply invokes the
1996 * lpfc_els_chk_latt() routine to check whether link went down during the
1997 * discovery process.
1998 **/
dea31012005-04-17 16:05:31 -05001999static void
James Smart2e0fef82007-06-17 19:56:36 -05002000lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2001 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002002{
James Smart2e0fef82007-06-17 19:56:36 -05002003 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002004 IOCB_t *irsp;
2005
2006 irsp = &rspiocb->iocb;
2007
James Smart858c9f62007-06-17 19:56:39 -05002008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2009 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2010 irsp->ulpStatus, irsp->un.ulpWord[4],
2011 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002012 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002013 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2014 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2015 irsp->ulpIoTag, irsp->ulpStatus,
2016 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002017 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002018 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002019 lpfc_els_free_iocb(phba, cmdiocb);
2020 return;
2021}
2022
James Smarte59058c2008-08-24 21:49:00 -04002023/**
James Smart3621a712009-04-06 18:47:14 -04002024 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002025 * @vport: pointer to a host virtual N_Port data structure.
2026 * @nportid: N_Port identifier to the remote node.
2027 * @retry: number of retries to the command IOCB.
2028 *
2029 * This routine issues a State Change Request (SCR) to a fabric node
2030 * on a @vport. The remote node @nportid is passed into the function. It
2031 * first search the @vport node list to find the matching ndlp. If no such
2032 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2033 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2034 * routine is invoked to send the SCR IOCB.
2035 *
2036 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2037 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2038 * will be stored into the context1 field of the IOCB for the completion
2039 * callback function to the SCR ELS command.
2040 *
2041 * Return code
2042 * 0 - Successfully issued scr command
2043 * 1 - Failed to issue scr command
2044 **/
dea31012005-04-17 16:05:31 -05002045int
James Smart2e0fef82007-06-17 19:56:36 -05002046lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002047{
James Smart2e0fef82007-06-17 19:56:36 -05002048 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002049 IOCB_t *icmd;
2050 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002051 struct lpfc_sli *psli;
2052 uint8_t *pcmd;
2053 uint16_t cmdsize;
2054 struct lpfc_nodelist *ndlp;
2055
2056 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002057 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002058
James Smarte47c9092008-02-08 18:49:26 -05002059 ndlp = lpfc_findnode_did(vport, nportid);
2060 if (!ndlp) {
2061 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2062 if (!ndlp)
2063 return 1;
2064 lpfc_nlp_init(vport, ndlp, nportid);
2065 lpfc_enqueue_node(vport, ndlp);
2066 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2067 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2068 if (!ndlp)
2069 return 1;
2070 }
dea31012005-04-17 16:05:31 -05002071
James Smart2e0fef82007-06-17 19:56:36 -05002072 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2073 ndlp->nlp_DID, ELS_CMD_SCR);
2074
James Smart488d1462006-03-07 15:02:37 -05002075 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002076 /* This will trigger the release of the node just
2077 * allocated
2078 */
James Smart329f9bc2007-04-25 09:53:01 -04002079 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002080 return 1;
dea31012005-04-17 16:05:31 -05002081 }
2082
2083 icmd = &elsiocb->iocb;
2084 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2085
2086 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002087 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002088
2089 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002090 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002091 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2092
James Smart858c9f62007-06-17 19:56:39 -05002093 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2094 "Issue SCR: did:x%x",
2095 ndlp->nlp_DID, 0, 0);
2096
dea31012005-04-17 16:05:31 -05002097 phba->fc_stat.elsXmitSCR++;
2098 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002099 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2100 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002101 /* The additional lpfc_nlp_put will cause the following
2102 * lpfc_els_free_iocb routine to trigger the rlease of
2103 * the node.
2104 */
James Smart329f9bc2007-04-25 09:53:01 -04002105 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002106 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002107 return 1;
dea31012005-04-17 16:05:31 -05002108 }
James Smartfa4066b2008-01-11 01:53:27 -05002109 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2110 * trigger the release of node.
2111 */
James Smart329f9bc2007-04-25 09:53:01 -04002112 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002113 return 0;
dea31012005-04-17 16:05:31 -05002114}
2115
James Smarte59058c2008-08-24 21:49:00 -04002116/**
James Smart3621a712009-04-06 18:47:14 -04002117 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002118 * @vport: pointer to a host virtual N_Port data structure.
2119 * @nportid: N_Port identifier to the remote node.
2120 * @retry: number of retries to the command IOCB.
2121 *
2122 * This routine issues a Fibre Channel Address Resolution Response
2123 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2124 * is passed into the function. It first search the @vport node list to find
2125 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2126 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2127 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2128 *
2129 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2130 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2131 * will be stored into the context1 field of the IOCB for the completion
2132 * callback function to the PARPR ELS command.
2133 *
2134 * Return code
2135 * 0 - Successfully issued farpr command
2136 * 1 - Failed to issue farpr command
2137 **/
dea31012005-04-17 16:05:31 -05002138static int
James Smart2e0fef82007-06-17 19:56:36 -05002139lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002140{
James Smart2e0fef82007-06-17 19:56:36 -05002141 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002142 IOCB_t *icmd;
2143 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002144 struct lpfc_sli *psli;
2145 FARP *fp;
2146 uint8_t *pcmd;
2147 uint32_t *lp;
2148 uint16_t cmdsize;
2149 struct lpfc_nodelist *ondlp;
2150 struct lpfc_nodelist *ndlp;
2151
2152 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002153 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002154
James Smarte47c9092008-02-08 18:49:26 -05002155 ndlp = lpfc_findnode_did(vport, nportid);
2156 if (!ndlp) {
2157 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2158 if (!ndlp)
2159 return 1;
2160 lpfc_nlp_init(vport, ndlp, nportid);
2161 lpfc_enqueue_node(vport, ndlp);
2162 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2163 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2164 if (!ndlp)
2165 return 1;
2166 }
James Smart2e0fef82007-06-17 19:56:36 -05002167
2168 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2169 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002170 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002171 /* This will trigger the release of the node just
2172 * allocated
2173 */
James Smart329f9bc2007-04-25 09:53:01 -04002174 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002175 return 1;
dea31012005-04-17 16:05:31 -05002176 }
2177
2178 icmd = &elsiocb->iocb;
2179 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2180
2181 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002182 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002183
2184 /* Fill in FARPR payload */
2185 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002186 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002187 lp = (uint32_t *) pcmd;
2188 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002189 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002190 fp->Rflags = 0;
2191 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2192
James Smart92d7f7b2007-06-17 19:56:38 -05002193 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2194 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002195 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002196 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002197 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002198 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002199 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002200 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002201 }
2202
James Smart858c9f62007-06-17 19:56:39 -05002203 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2204 "Issue FARPR: did:x%x",
2205 ndlp->nlp_DID, 0, 0);
2206
dea31012005-04-17 16:05:31 -05002207 phba->fc_stat.elsXmitFARPR++;
2208 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002209 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2210 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002211 /* The additional lpfc_nlp_put will cause the following
2212 * lpfc_els_free_iocb routine to trigger the release of
2213 * the node.
2214 */
James Smart329f9bc2007-04-25 09:53:01 -04002215 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002216 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002217 return 1;
dea31012005-04-17 16:05:31 -05002218 }
James Smartfa4066b2008-01-11 01:53:27 -05002219 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2220 * trigger the release of the node.
2221 */
James Smart329f9bc2007-04-25 09:53:01 -04002222 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002223 return 0;
dea31012005-04-17 16:05:31 -05002224}
2225
James Smarte59058c2008-08-24 21:49:00 -04002226/**
James Smart3621a712009-04-06 18:47:14 -04002227 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002228 * @vport: pointer to a host virtual N_Port data structure.
2229 * @nlp: pointer to a node-list data structure.
2230 *
2231 * This routine cancels the timer with a delayed IOCB-command retry for
2232 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2233 * removes the ELS retry event if it presents. In addition, if the
2234 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2235 * commands are sent for the @vport's nodes that require issuing discovery
2236 * ADISC.
2237 **/
dea31012005-04-17 16:05:31 -05002238void
James Smart2e0fef82007-06-17 19:56:36 -05002239lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002240{
James Smart2e0fef82007-06-17 19:56:36 -05002241 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002242 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002243
James Smart0d2b6b82008-06-14 22:52:47 -04002244 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2245 return;
James Smart2e0fef82007-06-17 19:56:36 -05002246 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002247 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002248 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002249 del_timer_sync(&nlp->nlp_delayfunc);
2250 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002251 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002252 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002253 /* Decrement nlp reference count held for the delayed retry */
2254 evtp = &nlp->els_retry_evt;
2255 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2256 }
James Smartfdcebe22006-03-07 15:04:01 -05002257 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002258 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002259 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002260 spin_unlock_irq(shost->host_lock);
2261 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002262 if (vport->port_state < LPFC_VPORT_READY) {
2263 /* Check if there are more ADISCs to be sent */
2264 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002265 } else {
2266 /* Check if there are more PLOGIs to be sent */
2267 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002268 if (vport->num_disc_nodes == 0) {
2269 spin_lock_irq(shost->host_lock);
2270 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2271 spin_unlock_irq(shost->host_lock);
2272 lpfc_can_disctmo(vport);
2273 lpfc_end_rscn(vport);
2274 }
James Smartfdcebe22006-03-07 15:04:01 -05002275 }
2276 }
2277 }
2278 return;
2279}
2280
James Smarte59058c2008-08-24 21:49:00 -04002281/**
James Smart3621a712009-04-06 18:47:14 -04002282 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002283 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2284 *
2285 * This routine is invoked by the ndlp delayed-function timer to check
2286 * whether there is any pending ELS retry event(s) with the node. If not, it
2287 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2288 * adds the delayed events to the HBA work list and invokes the
2289 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2290 * event. Note that lpfc_nlp_get() is called before posting the event to
2291 * the work list to hold reference count of ndlp so that it guarantees the
2292 * reference to ndlp will still be available when the worker thread gets
2293 * to the event associated with the ndlp.
2294 **/
James Smartfdcebe22006-03-07 15:04:01 -05002295void
dea31012005-04-17 16:05:31 -05002296lpfc_els_retry_delay(unsigned long ptr)
2297{
James Smart2e0fef82007-06-17 19:56:36 -05002298 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2299 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002300 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002301 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002302 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002303
James Smart92d7f7b2007-06-17 19:56:38 -05002304 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002305 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002306 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002307 return;
2308 }
2309
James Smartfa4066b2008-01-11 01:53:27 -05002310 /* We need to hold the node by incrementing the reference
2311 * count until the queued work is done
2312 */
2313 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002314 if (evtp->evt_arg1) {
2315 evtp->evt = LPFC_EVT_ELS_RETRY;
2316 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002317 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002318 }
James Smart92d7f7b2007-06-17 19:56:38 -05002319 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002320 return;
2321}
2322
James Smarte59058c2008-08-24 21:49:00 -04002323/**
James Smart3621a712009-04-06 18:47:14 -04002324 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002325 * @ndlp: pointer to a node-list data structure.
2326 *
2327 * This routine is the worker-thread handler for processing the @ndlp delayed
2328 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2329 * the last ELS command from the associated ndlp and invokes the proper ELS
2330 * function according to the delayed ELS command to retry the command.
2331 **/
dea31012005-04-17 16:05:31 -05002332void
2333lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2334{
James Smart2e0fef82007-06-17 19:56:36 -05002335 struct lpfc_vport *vport = ndlp->vport;
2336 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2337 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002338
James Smart2e0fef82007-06-17 19:56:36 -05002339 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002340 did = ndlp->nlp_DID;
2341 cmd = ndlp->nlp_last_elscmd;
2342 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002343
2344 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002345 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002346 return;
2347 }
2348
2349 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002350 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002351 /*
2352 * If a discovery event readded nlp_delayfunc after timer
2353 * firing and before processing the timer, cancel the
2354 * nlp_delayfunc.
2355 */
2356 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002357 retry = ndlp->nlp_retry;
2358
2359 switch (cmd) {
2360 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002361 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002362 break;
2363 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002364 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002365 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002366 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002367 }
dea31012005-04-17 16:05:31 -05002368 break;
2369 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002370 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002371 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002372 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002373 }
dea31012005-04-17 16:05:31 -05002374 break;
2375 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002376 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002377 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002379 }
dea31012005-04-17 16:05:31 -05002380 break;
2381 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002382 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002383 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002385 }
dea31012005-04-17 16:05:31 -05002386 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002387 case ELS_CMD_FDISC:
2388 lpfc_issue_els_fdisc(vport, ndlp, retry);
2389 break;
dea31012005-04-17 16:05:31 -05002390 }
2391 return;
2392}
2393
James Smarte59058c2008-08-24 21:49:00 -04002394/**
James Smart3621a712009-04-06 18:47:14 -04002395 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002396 * @phba: pointer to lpfc hba data structure.
2397 * @cmdiocb: pointer to lpfc command iocb data structure.
2398 * @rspiocb: pointer to lpfc response iocb data structure.
2399 *
2400 * This routine makes a retry decision on an ELS command IOCB, which has
2401 * failed. The following ELS IOCBs use this function for retrying the command
2402 * when previously issued command responsed with error status: FLOGI, PLOGI,
2403 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2404 * returned error status, it makes the decision whether a retry shall be
2405 * issued for the command, and whether a retry shall be made immediately or
2406 * delayed. In the former case, the corresponding ELS command issuing-function
2407 * is called to retry the command. In the later case, the ELS command shall
2408 * be posted to the ndlp delayed event and delayed function timer set to the
2409 * ndlp for the delayed command issusing.
2410 *
2411 * Return code
2412 * 0 - No retry of els command is made
2413 * 1 - Immediate or delayed retry of els command is made
2414 **/
dea31012005-04-17 16:05:31 -05002415static int
James Smart2e0fef82007-06-17 19:56:36 -05002416lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2417 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002418{
James Smart2e0fef82007-06-17 19:56:36 -05002419 struct lpfc_vport *vport = cmdiocb->vport;
2420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2421 IOCB_t *irsp = &rspiocb->iocb;
2422 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2423 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002424 uint32_t *elscmd;
2425 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002426 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002427 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002428 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002429 uint32_t did;
dea31012005-04-17 16:05:31 -05002430
James Smart488d1462006-03-07 15:02:37 -05002431
dea31012005-04-17 16:05:31 -05002432 /* Note: context2 may be 0 for internal driver abort
2433 * of delays ELS command.
2434 */
2435
2436 if (pcmd && pcmd->virt) {
2437 elscmd = (uint32_t *) (pcmd->virt);
2438 cmd = *elscmd++;
2439 }
2440
James Smarte47c9092008-02-08 18:49:26 -05002441 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002442 did = ndlp->nlp_DID;
2443 else {
2444 /* We should only hit this case for retrying PLOGI */
2445 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002446 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002447 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2448 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002449 return 1;
2450 }
2451
James Smart858c9f62007-06-17 19:56:39 -05002452 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2453 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2454 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2455
dea31012005-04-17 16:05:31 -05002456 switch (irsp->ulpStatus) {
2457 case IOSTAT_FCP_RSP_ERROR:
2458 case IOSTAT_REMOTE_STOP:
2459 break;
2460
2461 case IOSTAT_LOCAL_REJECT:
2462 switch ((irsp->un.ulpWord[4] & 0xff)) {
2463 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002464 if (cmd == ELS_CMD_FLOGI) {
2465 if (PCI_DEVICE_ID_HORNET ==
2466 phba->pcidev->device) {
2467 phba->fc_topology = TOPOLOGY_LOOP;
2468 phba->pport->fc_myDID = 0;
2469 phba->alpa_map[0] = 0;
2470 phba->alpa_map[1] = 0;
2471 }
2472 }
James Smart2e0fef82007-06-17 19:56:36 -05002473 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002474 delay = 1000;
dea31012005-04-17 16:05:31 -05002475 retry = 1;
2476 break;
2477
James Smart92d7f7b2007-06-17 19:56:38 -05002478 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002479 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2480 "0124 Retry illegal cmd x%x "
2481 "retry:x%x delay:x%x\n",
2482 cmd, cmdiocb->retry, delay);
2483 retry = 1;
2484 /* All command's retry policy */
2485 maxretry = 8;
2486 if (cmdiocb->retry > 2)
2487 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002488 break;
2489
dea31012005-04-17 16:05:31 -05002490 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002491 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002492 retry = 1;
2493 if (cmdiocb->retry > 100)
2494 delay = 100;
2495 maxretry = 250;
2496 break;
2497
2498 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002499 delay = 100;
dea31012005-04-17 16:05:31 -05002500 retry = 1;
2501 break;
2502
James Smart858c9f62007-06-17 19:56:39 -05002503 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002504 case IOERR_INVALID_RPI:
2505 retry = 1;
2506 break;
2507 }
2508 break;
2509
2510 case IOSTAT_NPORT_RJT:
2511 case IOSTAT_FABRIC_RJT:
2512 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2513 retry = 1;
2514 break;
2515 }
2516 break;
2517
2518 case IOSTAT_NPORT_BSY:
2519 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002520 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002521 retry = 1;
2522 break;
2523
2524 case IOSTAT_LS_RJT:
2525 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2526 /* Added for Vendor specifc support
2527 * Just keep retrying for these Rsn / Exp codes
2528 */
2529 switch (stat.un.b.lsRjtRsnCode) {
2530 case LSRJT_UNABLE_TPC:
2531 if (stat.un.b.lsRjtRsnCodeExp ==
2532 LSEXP_CMD_IN_PROGRESS) {
2533 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002534 delay = 1000;
dea31012005-04-17 16:05:31 -05002535 maxretry = 48;
2536 }
2537 retry = 1;
2538 break;
2539 }
2540 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002541 delay = 1000;
dea31012005-04-17 16:05:31 -05002542 maxretry = lpfc_max_els_tries + 1;
2543 retry = 1;
2544 break;
2545 }
James Smart92d7f7b2007-06-17 19:56:38 -05002546 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2547 (cmd == ELS_CMD_FDISC) &&
2548 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002549 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2550 "0125 FDISC Failed (x%x). "
2551 "Fabric out of resources\n",
2552 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002553 lpfc_vport_set_state(vport,
2554 FC_VPORT_NO_FABRIC_RSCS);
2555 }
dea31012005-04-17 16:05:31 -05002556 break;
2557
2558 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002559 if ((cmd == ELS_CMD_PLOGI) ||
2560 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002561 delay = 1000;
dea31012005-04-17 16:05:31 -05002562 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002563 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002564 /* FDISC retry policy */
2565 maxretry = 48;
2566 if (cmdiocb->retry >= 32)
2567 delay = 1000;
dea31012005-04-17 16:05:31 -05002568 }
2569 retry = 1;
2570 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002571
2572 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002573 /* There are some cases where switches return this
2574 * error when they are not ready and should be returning
2575 * Logical Busy. We should delay every time.
2576 */
2577 if (cmd == ELS_CMD_FDISC &&
2578 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2579 maxretry = 3;
2580 delay = 1000;
2581 retry = 1;
2582 break;
2583 }
James Smart92d7f7b2007-06-17 19:56:38 -05002584 case LSRJT_PROTOCOL_ERR:
2585 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2586 (cmd == ELS_CMD_FDISC) &&
2587 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2588 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2589 ) {
James Smarte8b62012007-08-02 11:10:09 -04002590 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002591 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002592 "Fabric Detected Bad WWN\n",
2593 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002594 lpfc_vport_set_state(vport,
2595 FC_VPORT_FABRIC_REJ_WWN);
2596 }
2597 break;
dea31012005-04-17 16:05:31 -05002598 }
2599 break;
2600
2601 case IOSTAT_INTERMED_RSP:
2602 case IOSTAT_BA_RJT:
2603 break;
2604
2605 default:
2606 break;
2607 }
2608
James Smart488d1462006-03-07 15:02:37 -05002609 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002610 retry = 1;
dea31012005-04-17 16:05:31 -05002611
James Smart98c9ea52007-10-27 13:37:33 -04002612 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002613 (phba->fc_topology != TOPOLOGY_LOOP) &&
2614 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002615 /* FLOGI retry policy */
2616 retry = 1;
2617 maxretry = 48;
2618 if (cmdiocb->retry >= 32)
2619 delay = 1000;
2620 }
2621
dea31012005-04-17 16:05:31 -05002622 if ((++cmdiocb->retry) >= maxretry) {
2623 phba->fc_stat.elsRetryExceeded++;
2624 retry = 0;
2625 }
2626
James Smarted957682007-06-17 19:56:37 -05002627 if ((vport->load_flag & FC_UNLOADING) != 0)
2628 retry = 0;
2629
dea31012005-04-17 16:05:31 -05002630 if (retry) {
2631
2632 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002633 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2634 "0107 Retry ELS command x%x to remote "
2635 "NPORT x%x Data: x%x x%x\n",
2636 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002637
James Smart858c9f62007-06-17 19:56:39 -05002638 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2639 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2640 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2641 /* Don't reset timer for no resources */
2642
dea31012005-04-17 16:05:31 -05002643 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002644 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002645 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002646 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002647 }
2648
2649 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002650 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002651 phba->fc_stat.elsDelayRetry++;
2652 ndlp->nlp_retry = cmdiocb->retry;
2653
James Smart92d7f7b2007-06-17 19:56:38 -05002654 /* delay is specified in milliseconds */
2655 mod_timer(&ndlp->nlp_delayfunc,
2656 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002657 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002658 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002659 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002660
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002661 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002662 if (cmd == ELS_CMD_PRLI)
2663 lpfc_nlp_set_state(vport, ndlp,
2664 NLP_STE_REG_LOGIN_ISSUE);
2665 else
2666 lpfc_nlp_set_state(vport, ndlp,
2667 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002668 ndlp->nlp_last_elscmd = cmd;
2669
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002670 return 1;
dea31012005-04-17 16:05:31 -05002671 }
2672 switch (cmd) {
2673 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002674 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002675 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002676 case ELS_CMD_FDISC:
2677 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2678 return 1;
dea31012005-04-17 16:05:31 -05002679 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002680 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002681 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002682 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002683 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002684 }
James Smart2e0fef82007-06-17 19:56:36 -05002685 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002686 return 1;
dea31012005-04-17 16:05:31 -05002687 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002688 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002689 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2690 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002691 return 1;
dea31012005-04-17 16:05:31 -05002692 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002693 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002694 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2695 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002696 return 1;
dea31012005-04-17 16:05:31 -05002697 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002698 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002699 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2700 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002701 return 1;
dea31012005-04-17 16:05:31 -05002702 }
2703 }
dea31012005-04-17 16:05:31 -05002704 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002705 if (logerr) {
2706 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2707 "0137 No retry ELS command x%x to remote "
2708 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2709 cmd, did, irsp->ulpStatus,
2710 irsp->un.ulpWord[4]);
2711 }
2712 else {
2713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002714 "0108 No retry ELS command x%x to remote "
2715 "NPORT x%x Retried:%d Error:x%x/%x\n",
2716 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2717 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002718 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002719 return 0;
dea31012005-04-17 16:05:31 -05002720}
2721
James Smarte59058c2008-08-24 21:49:00 -04002722/**
James Smart3621a712009-04-06 18:47:14 -04002723 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002724 * @phba: pointer to lpfc hba data structure.
2725 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2726 *
2727 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2728 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2729 * checks to see whether there is a lpfc DMA buffer associated with the
2730 * response of the command IOCB. If so, it will be released before releasing
2731 * the lpfc DMA buffer associated with the IOCB itself.
2732 *
2733 * Return code
2734 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2735 **/
James Smart09372822008-01-11 01:52:54 -05002736static int
James Smart87af33f2007-10-27 13:37:43 -04002737lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2738{
2739 struct lpfc_dmabuf *buf_ptr;
2740
James Smarte59058c2008-08-24 21:49:00 -04002741 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002742 if (!list_empty(&buf_ptr1->list)) {
2743 list_remove_head(&buf_ptr1->list, buf_ptr,
2744 struct lpfc_dmabuf,
2745 list);
2746 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2747 kfree(buf_ptr);
2748 }
2749 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2750 kfree(buf_ptr1);
2751 return 0;
2752}
2753
James Smarte59058c2008-08-24 21:49:00 -04002754/**
James Smart3621a712009-04-06 18:47:14 -04002755 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002756 * @phba: pointer to lpfc hba data structure.
2757 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2758 *
2759 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2760 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2761 * pool.
2762 *
2763 * Return code
2764 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2765 **/
James Smart09372822008-01-11 01:52:54 -05002766static int
James Smart87af33f2007-10-27 13:37:43 -04002767lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2768{
2769 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2770 kfree(buf_ptr);
2771 return 0;
2772}
2773
James Smarte59058c2008-08-24 21:49:00 -04002774/**
James Smart3621a712009-04-06 18:47:14 -04002775 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002776 * @phba: pointer to lpfc hba data structure.
2777 * @elsiocb: pointer to lpfc els command iocb data structure.
2778 *
2779 * This routine frees a command IOCB and its associated resources. The
2780 * command IOCB data structure contains the reference to various associated
2781 * resources, these fields must be set to NULL if the associated reference
2782 * not present:
2783 * context1 - reference to ndlp
2784 * context2 - reference to cmd
2785 * context2->next - reference to rsp
2786 * context3 - reference to bpl
2787 *
2788 * It first properly decrements the reference count held on ndlp for the
2789 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2790 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2791 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2792 * adds the DMA buffer the @phba data structure for the delayed release.
2793 * If reference to the Buffer Pointer List (BPL) is present, the
2794 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2795 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2796 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2797 *
2798 * Return code
2799 * 0 - Success (currently, always return 0)
2800 **/
James Smart87af33f2007-10-27 13:37:43 -04002801int
James Smart329f9bc2007-04-25 09:53:01 -04002802lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002803{
2804 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002805 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002806
James Smarta8adb832007-10-27 13:37:53 -04002807 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2808 if (ndlp) {
2809 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2810 lpfc_nlp_put(ndlp);
2811
2812 /* If the ndlp is not being used by another discovery
2813 * thread, free it.
2814 */
2815 if (!lpfc_nlp_not_used(ndlp)) {
2816 /* If ndlp is being used by another discovery
2817 * thread, just clear NLP_DEFER_RM
2818 */
2819 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2820 }
2821 }
2822 else
2823 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002824 elsiocb->context1 = NULL;
2825 }
dea31012005-04-17 16:05:31 -05002826 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2827 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002828 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2829 /* Firmware could still be in progress of DMAing
2830 * payload, so don't free data buffer till after
2831 * a hbeat.
2832 */
2833 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2834 buf_ptr = elsiocb->context2;
2835 elsiocb->context2 = NULL;
2836 if (buf_ptr) {
2837 buf_ptr1 = NULL;
2838 spin_lock_irq(&phba->hbalock);
2839 if (!list_empty(&buf_ptr->list)) {
2840 list_remove_head(&buf_ptr->list,
2841 buf_ptr1, struct lpfc_dmabuf,
2842 list);
2843 INIT_LIST_HEAD(&buf_ptr1->list);
2844 list_add_tail(&buf_ptr1->list,
2845 &phba->elsbuf);
2846 phba->elsbuf_cnt++;
2847 }
2848 INIT_LIST_HEAD(&buf_ptr->list);
2849 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2850 phba->elsbuf_cnt++;
2851 spin_unlock_irq(&phba->hbalock);
2852 }
2853 } else {
2854 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2855 lpfc_els_free_data(phba, buf_ptr1);
2856 }
dea31012005-04-17 16:05:31 -05002857 }
2858
2859 if (elsiocb->context3) {
2860 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002861 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002862 }
James Bottomley604a3e32005-10-29 10:28:33 -05002863 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002864 return 0;
2865}
2866
James Smarte59058c2008-08-24 21:49:00 -04002867/**
James Smart3621a712009-04-06 18:47:14 -04002868 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04002869 * @phba: pointer to lpfc hba data structure.
2870 * @cmdiocb: pointer to lpfc command iocb data structure.
2871 * @rspiocb: pointer to lpfc response iocb data structure.
2872 *
2873 * This routine is the completion callback function to the Logout (LOGO)
2874 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2875 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2876 * release the ndlp if it has the last reference remaining (reference count
2877 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2878 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2879 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2880 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2881 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2882 * IOCB data structure.
2883 **/
dea31012005-04-17 16:05:31 -05002884static void
James Smart2e0fef82007-06-17 19:56:36 -05002885lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2886 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002887{
James Smart2e0fef82007-06-17 19:56:36 -05002888 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2889 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002890 IOCB_t *irsp;
2891
2892 irsp = &rspiocb->iocb;
2893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2894 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2895 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002896 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002897 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2898 "0109 ACC to LOGO completes to NPort x%x "
2899 "Data: x%x x%x x%x\n",
2900 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2901 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002902
2903 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2904 /* NPort Recovery mode or node is just allocated */
2905 if (!lpfc_nlp_not_used(ndlp)) {
2906 /* If the ndlp is being used by another discovery
2907 * thread, just unregister the RPI.
2908 */
2909 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002910 } else {
2911 /* Indicate the node has already released, should
2912 * not reference to it from within lpfc_els_free_iocb.
2913 */
2914 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002915 }
dea31012005-04-17 16:05:31 -05002916 }
2917 lpfc_els_free_iocb(phba, cmdiocb);
2918 return;
2919}
2920
James Smarte59058c2008-08-24 21:49:00 -04002921/**
James Smart3621a712009-04-06 18:47:14 -04002922 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04002923 * @phba: pointer to lpfc hba data structure.
2924 * @pmb: pointer to the driver internal queue element for mailbox command.
2925 *
2926 * This routine is the completion callback function for unregister default
2927 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2928 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2929 * decrements the ndlp reference count held for this completion callback
2930 * function. After that, it invokes the lpfc_nlp_not_used() to check
2931 * whether there is only one reference left on the ndlp. If so, it will
2932 * perform one more decrement and trigger the release of the ndlp.
2933 **/
James Smart858c9f62007-06-17 19:56:39 -05002934void
2935lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2936{
2937 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2938 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2939
2940 pmb->context1 = NULL;
2941 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2942 kfree(mp);
2943 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04002944 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04002945 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002946 /* This is the end of the default RPI cleanup logic for this
2947 * ndlp. If no other discovery threads are using this ndlp.
2948 * we should free all resources associated with it.
2949 */
2950 lpfc_nlp_not_used(ndlp);
2951 }
James Smart3772a992009-05-22 14:50:54 -04002952
James Smart858c9f62007-06-17 19:56:39 -05002953 return;
2954}
2955
James Smarte59058c2008-08-24 21:49:00 -04002956/**
James Smart3621a712009-04-06 18:47:14 -04002957 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04002958 * @phba: pointer to lpfc hba data structure.
2959 * @cmdiocb: pointer to lpfc command iocb data structure.
2960 * @rspiocb: pointer to lpfc response iocb data structure.
2961 *
2962 * This routine is the completion callback function for ELS Response IOCB
2963 * command. In normal case, this callback function just properly sets the
2964 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2965 * field in the command IOCB is not NULL, the referred mailbox command will
2966 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2967 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2968 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2969 * routine shall be invoked trying to release the ndlp if no other threads
2970 * are currently referring it.
2971 **/
dea31012005-04-17 16:05:31 -05002972static void
James Smart858c9f62007-06-17 19:56:39 -05002973lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002974 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002975{
James Smart2e0fef82007-06-17 19:56:36 -05002976 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2977 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2978 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002979 IOCB_t *irsp;
2980 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002981 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002982 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002983 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002984
James Smart33ccf8d2006-08-17 11:57:58 -04002985 irsp = &rspiocb->iocb;
2986
dea31012005-04-17 16:05:31 -05002987 if (cmdiocb->context_un.mbox)
2988 mbox = cmdiocb->context_un.mbox;
2989
James Smartfa4066b2008-01-11 01:53:27 -05002990 /* First determine if this is a LS_RJT cmpl. Note, this callback
2991 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2992 */
James Smart87af33f2007-10-27 13:37:43 -04002993 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04002994 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
2995 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05002996 /* A LS_RJT associated with Default RPI cleanup has its own
2997 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04002998 */
2999 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3000 ls_rjt = 1;
3001 }
3002
dea31012005-04-17 16:05:31 -05003003 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003004 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003005 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003006 mp = (struct lpfc_dmabuf *) mbox->context1;
3007 if (mp) {
3008 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3009 kfree(mp);
3010 }
James Smart329f9bc2007-04-25 09:53:01 -04003011 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003012 }
James Smart58da1ff2008-04-07 10:15:56 -04003013 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3014 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003015 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003016 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003017 /* Indicate the node has already released,
3018 * should not reference to it from within
3019 * the routine lpfc_els_free_iocb.
3020 */
3021 cmdiocb->context1 = NULL;
3022 }
dea31012005-04-17 16:05:31 -05003023 goto out;
3024 }
3025
James Smart858c9f62007-06-17 19:56:39 -05003026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003027 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003028 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003029 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003030 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003031 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3032 "0110 ELS response tag x%x completes "
3033 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3034 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3035 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3036 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3037 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003038 if (mbox) {
3039 if ((rspiocb->iocb.ulpStatus == 0)
3040 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003041 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003042 /* Increment reference count to ndlp to hold the
3043 * reference to ndlp for the callback function.
3044 */
James Smart329f9bc2007-04-25 09:53:01 -04003045 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003046 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003047 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3048 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3049 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3050 }
3051 else {
3052 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3053 ndlp->nlp_prev_state = ndlp->nlp_state;
3054 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003055 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003056 }
James Smart0b727fe2007-10-27 13:37:25 -04003057 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003058 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003059 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003060 else
3061 /* Decrement the ndlp reference count we
3062 * set for this failed mailbox command.
3063 */
3064 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003065
3066 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3067 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3068 "0138 ELS rsp: Cannot issue reg_login for x%x "
3069 "Data: x%x x%x x%x\n",
3070 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3071 ndlp->nlp_rpi);
3072
James Smartfa4066b2008-01-11 01:53:27 -05003073 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003074 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003075 /* Indicate node has already been released,
3076 * should not reference to it from within
3077 * the routine lpfc_els_free_iocb.
3078 */
3079 cmdiocb->context1 = NULL;
3080 }
dea31012005-04-17 16:05:31 -05003081 } else {
James Smart858c9f62007-06-17 19:56:39 -05003082 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3083 if (!lpfc_error_lost_link(irsp) &&
3084 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003085 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003086 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003087 /* Indicate node has already been
3088 * released, should not reference
3089 * to it from within the routine
3090 * lpfc_els_free_iocb.
3091 */
3092 cmdiocb->context1 = NULL;
3093 }
dea31012005-04-17 16:05:31 -05003094 }
3095 }
James Smart14691152006-12-02 13:34:28 -05003096 mp = (struct lpfc_dmabuf *) mbox->context1;
3097 if (mp) {
3098 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3099 kfree(mp);
3100 }
3101 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003102 }
3103out:
James Smart58da1ff2008-04-07 10:15:56 -04003104 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003105 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003106 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003107 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003108
3109 /* If the node is not being used by another discovery thread,
3110 * and we are sending a reject, we are done with it.
3111 * Release driver reference count here and free associated
3112 * resources.
3113 */
3114 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003115 if (lpfc_nlp_not_used(ndlp))
3116 /* Indicate node has already been released,
3117 * should not reference to it from within
3118 * the routine lpfc_els_free_iocb.
3119 */
3120 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003121 }
James Smart87af33f2007-10-27 13:37:43 -04003122
dea31012005-04-17 16:05:31 -05003123 lpfc_els_free_iocb(phba, cmdiocb);
3124 return;
3125}
3126
James Smarte59058c2008-08-24 21:49:00 -04003127/**
James Smart3621a712009-04-06 18:47:14 -04003128 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003129 * @vport: pointer to a host virtual N_Port data structure.
3130 * @flag: the els command code to be accepted.
3131 * @oldiocb: pointer to the original lpfc command iocb data structure.
3132 * @ndlp: pointer to a node-list data structure.
3133 * @mbox: pointer to the driver internal queue element for mailbox command.
3134 *
3135 * This routine prepares and issues an Accept (ACC) response IOCB
3136 * command. It uses the @flag to properly set up the IOCB field for the
3137 * specific ACC response command to be issued and invokes the
3138 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3139 * @mbox pointer is passed in, it will be put into the context_un.mbox
3140 * field of the IOCB for the completion callback function to issue the
3141 * mailbox command to the HBA later when callback is invoked.
3142 *
3143 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3144 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3145 * will be stored into the context1 field of the IOCB for the completion
3146 * callback function to the corresponding response ELS IOCB command.
3147 *
3148 * Return code
3149 * 0 - Successfully issued acc response
3150 * 1 - Failed to issue acc response
3151 **/
dea31012005-04-17 16:05:31 -05003152int
James Smart2e0fef82007-06-17 19:56:36 -05003153lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3154 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003155 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003156{
James Smart2e0fef82007-06-17 19:56:36 -05003157 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3158 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003159 IOCB_t *icmd;
3160 IOCB_t *oldcmd;
3161 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003162 struct lpfc_sli *psli;
3163 uint8_t *pcmd;
3164 uint16_t cmdsize;
3165 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003166 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003167
3168 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003169 oldcmd = &oldiocb->iocb;
3170
3171 switch (flag) {
3172 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003173 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003174 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3175 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003176 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003177 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003178 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003179 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003180 return 1;
dea31012005-04-17 16:05:31 -05003181 }
James Smart2e0fef82007-06-17 19:56:36 -05003182
dea31012005-04-17 16:05:31 -05003183 icmd = &elsiocb->iocb;
3184 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3185 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3186 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003187 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003188
3189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3190 "Issue ACC: did:x%x flg:x%x",
3191 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003192 break;
3193 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003194 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003195 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3196 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003197 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003198 return 1;
James Smart488d1462006-03-07 15:02:37 -05003199
dea31012005-04-17 16:05:31 -05003200 icmd = &elsiocb->iocb;
3201 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3202 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3203
3204 if (mbox)
3205 elsiocb->context_un.mbox = mbox;
3206
3207 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003208 pcmd += sizeof(uint32_t);
3209 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003210
3211 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3212 "Issue ACC PLOGI: did:x%x flg:x%x",
3213 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003214 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003215 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003216 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003217 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003218 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3219 if (!elsiocb)
3220 return 1;
3221
3222 icmd = &elsiocb->iocb;
3223 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3224 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3225
3226 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003227 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003228 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3229 els_pkt_ptr = (ELS_PKT *) pcmd;
3230 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003231
3232 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3233 "Issue ACC PRLO: did:x%x flg:x%x",
3234 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003235 break;
dea31012005-04-17 16:05:31 -05003236 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003237 return 1;
dea31012005-04-17 16:05:31 -05003238 }
dea31012005-04-17 16:05:31 -05003239 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003240 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3241 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3242 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3243 elsiocb->iotag, elsiocb->iocb.ulpContext,
3244 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3245 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003246 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003247 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003248 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003249 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003250 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3251 } else {
James Smart858c9f62007-06-17 19:56:39 -05003252 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003253 }
3254
3255 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003256 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003257 if (rc == IOCB_ERROR) {
3258 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003259 return 1;
dea31012005-04-17 16:05:31 -05003260 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003261 return 0;
dea31012005-04-17 16:05:31 -05003262}
3263
James Smarte59058c2008-08-24 21:49:00 -04003264/**
James Smart3621a712009-04-06 18:47:14 -04003265 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003266 * @vport: pointer to a virtual N_Port data structure.
3267 * @rejectError:
3268 * @oldiocb: pointer to the original lpfc command iocb data structure.
3269 * @ndlp: pointer to a node-list data structure.
3270 * @mbox: pointer to the driver internal queue element for mailbox command.
3271 *
3272 * This routine prepares and issue an Reject (RJT) response IOCB
3273 * command. If a @mbox pointer is passed in, it will be put into the
3274 * context_un.mbox field of the IOCB for the completion callback function
3275 * to issue to the HBA later.
3276 *
3277 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3278 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3279 * will be stored into the context1 field of the IOCB for the completion
3280 * callback function to the reject response ELS IOCB command.
3281 *
3282 * Return code
3283 * 0 - Successfully issued reject response
3284 * 1 - Failed to issue reject response
3285 **/
dea31012005-04-17 16:05:31 -05003286int
James Smart2e0fef82007-06-17 19:56:36 -05003287lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003288 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3289 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003290{
James Smart2e0fef82007-06-17 19:56:36 -05003291 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003292 IOCB_t *icmd;
3293 IOCB_t *oldcmd;
3294 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003295 struct lpfc_sli *psli;
3296 uint8_t *pcmd;
3297 uint16_t cmdsize;
3298 int rc;
3299
3300 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003301 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003302 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3303 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003304 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003305 return 1;
dea31012005-04-17 16:05:31 -05003306
3307 icmd = &elsiocb->iocb;
3308 oldcmd = &oldiocb->iocb;
3309 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3310 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3311
3312 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003313 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003314 *((uint32_t *) (pcmd)) = rejectError;
3315
James Smart51ef4c22007-08-02 11:10:31 -04003316 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003317 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003318
dea31012005-04-17 16:05:31 -05003319 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003320 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3321 "0129 Xmit ELS RJT x%x response tag x%x "
3322 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3323 "rpi x%x\n",
3324 rejectError, elsiocb->iotag,
3325 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3326 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003327 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3328 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3329 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3330
dea31012005-04-17 16:05:31 -05003331 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003332 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003333 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003334
dea31012005-04-17 16:05:31 -05003335 if (rc == IOCB_ERROR) {
3336 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003337 return 1;
dea31012005-04-17 16:05:31 -05003338 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003339 return 0;
dea31012005-04-17 16:05:31 -05003340}
3341
James Smarte59058c2008-08-24 21:49:00 -04003342/**
James Smart3621a712009-04-06 18:47:14 -04003343 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003344 * @vport: pointer to a virtual N_Port data structure.
3345 * @oldiocb: pointer to the original lpfc command iocb data structure.
3346 * @ndlp: pointer to a node-list data structure.
3347 *
3348 * This routine prepares and issues an Accept (ACC) response to Address
3349 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3350 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3351 *
3352 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3353 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3354 * will be stored into the context1 field of the IOCB for the completion
3355 * callback function to the ADISC Accept response ELS IOCB command.
3356 *
3357 * Return code
3358 * 0 - Successfully issued acc adisc response
3359 * 1 - Failed to issue adisc acc response
3360 **/
dea31012005-04-17 16:05:31 -05003361int
James Smart2e0fef82007-06-17 19:56:36 -05003362lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3363 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003364{
James Smart2e0fef82007-06-17 19:56:36 -05003365 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003366 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003367 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003368 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003369 uint8_t *pcmd;
3370 uint16_t cmdsize;
3371 int rc;
3372
James Smart92d7f7b2007-06-17 19:56:38 -05003373 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003374 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3375 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003376 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003377 return 1;
dea31012005-04-17 16:05:31 -05003378
dea31012005-04-17 16:05:31 -05003379 icmd = &elsiocb->iocb;
3380 oldcmd = &oldiocb->iocb;
3381 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003382
3383 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003384 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3385 "0130 Xmit ADISC ACC response iotag x%x xri: "
3386 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3387 elsiocb->iotag, elsiocb->iocb.ulpContext,
3388 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3389 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003390 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3391
3392 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003393 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003394
3395 ap = (ADISC *) (pcmd);
3396 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003397 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3398 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003399 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003400
James Smart858c9f62007-06-17 19:56:39 -05003401 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3402 "Issue ACC ADISC: did:x%x flg:x%x",
3403 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3404
dea31012005-04-17 16:05:31 -05003405 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003406 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003407 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003408 if (rc == IOCB_ERROR) {
3409 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003410 return 1;
dea31012005-04-17 16:05:31 -05003411 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003412 return 0;
dea31012005-04-17 16:05:31 -05003413}
3414
James Smarte59058c2008-08-24 21:49:00 -04003415/**
James Smart3621a712009-04-06 18:47:14 -04003416 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003417 * @vport: pointer to a virtual N_Port data structure.
3418 * @oldiocb: pointer to the original lpfc command iocb data structure.
3419 * @ndlp: pointer to a node-list data structure.
3420 *
3421 * This routine prepares and issues an Accept (ACC) response to Process
3422 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3423 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3424 *
3425 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3426 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3427 * will be stored into the context1 field of the IOCB for the completion
3428 * callback function to the PRLI Accept response ELS IOCB command.
3429 *
3430 * Return code
3431 * 0 - Successfully issued acc prli response
3432 * 1 - Failed to issue acc prli response
3433 **/
dea31012005-04-17 16:05:31 -05003434int
James Smart2e0fef82007-06-17 19:56:36 -05003435lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003436 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003437{
James Smart2e0fef82007-06-17 19:56:36 -05003438 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003439 PRLI *npr;
3440 lpfc_vpd_t *vpd;
3441 IOCB_t *icmd;
3442 IOCB_t *oldcmd;
3443 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003444 struct lpfc_sli *psli;
3445 uint8_t *pcmd;
3446 uint16_t cmdsize;
3447 int rc;
3448
3449 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003450
James Smart92d7f7b2007-06-17 19:56:38 -05003451 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003452 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003453 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003454 if (!elsiocb)
3455 return 1;
dea31012005-04-17 16:05:31 -05003456
dea31012005-04-17 16:05:31 -05003457 icmd = &elsiocb->iocb;
3458 oldcmd = &oldiocb->iocb;
3459 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003460 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003461 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3462 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3463 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3464 elsiocb->iotag, elsiocb->iocb.ulpContext,
3465 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3466 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003467 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3468
3469 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003470 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003471
3472 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003473 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003474
3475 npr = (PRLI *) pcmd;
3476 vpd = &phba->vpd;
3477 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003478 * If the remote port is a target and our firmware version is 3.20 or
3479 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003480 */
James Smart0d2b6b82008-06-14 22:52:47 -04003481 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3482 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003483 npr->ConfmComplAllowed = 1;
3484 npr->Retry = 1;
3485 npr->TaskRetryIdReq = 1;
3486 }
3487
3488 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3489 npr->estabImagePair = 1;
3490 npr->readXferRdyDis = 1;
3491 npr->ConfmComplAllowed = 1;
3492
3493 npr->prliType = PRLI_FCP_TYPE;
3494 npr->initiatorFunc = 1;
3495
James Smart858c9f62007-06-17 19:56:39 -05003496 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3497 "Issue ACC PRLI: did:x%x flg:x%x",
3498 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3499
dea31012005-04-17 16:05:31 -05003500 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003501 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003502
James Smart3772a992009-05-22 14:50:54 -04003503 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003504 if (rc == IOCB_ERROR) {
3505 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003506 return 1;
dea31012005-04-17 16:05:31 -05003507 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003508 return 0;
dea31012005-04-17 16:05:31 -05003509}
3510
James Smarte59058c2008-08-24 21:49:00 -04003511/**
James Smart3621a712009-04-06 18:47:14 -04003512 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003513 * @vport: pointer to a virtual N_Port data structure.
3514 * @format: rnid command format.
3515 * @oldiocb: pointer to the original lpfc command iocb data structure.
3516 * @ndlp: pointer to a node-list data structure.
3517 *
3518 * This routine issues a Request Node Identification Data (RNID) Accept
3519 * (ACC) response. It constructs the RNID ACC response command according to
3520 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3521 * issue the response. Note that this command does not need to hold the ndlp
3522 * reference count for the callback. So, the ndlp reference count taken by
3523 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3524 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3525 * there is no ndlp reference available.
3526 *
3527 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3528 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3529 * will be stored into the context1 field of the IOCB for the completion
3530 * callback function. However, for the RNID Accept Response ELS command,
3531 * this is undone later by this routine after the IOCB is allocated.
3532 *
3533 * Return code
3534 * 0 - Successfully issued acc rnid response
3535 * 1 - Failed to issue acc rnid response
3536 **/
dea31012005-04-17 16:05:31 -05003537static int
James Smart2e0fef82007-06-17 19:56:36 -05003538lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003539 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003540{
James Smart2e0fef82007-06-17 19:56:36 -05003541 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003542 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003543 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003544 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003545 struct lpfc_sli *psli;
3546 uint8_t *pcmd;
3547 uint16_t cmdsize;
3548 int rc;
3549
3550 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003551 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3552 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003553 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003554 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003555
James Smart2e0fef82007-06-17 19:56:36 -05003556 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3557 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003558 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003559 return 1;
dea31012005-04-17 16:05:31 -05003560
dea31012005-04-17 16:05:31 -05003561 icmd = &elsiocb->iocb;
3562 oldcmd = &oldiocb->iocb;
3563 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003564 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003565 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3566 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3567 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003568 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003569 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003570 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003571
James Smart92d7f7b2007-06-17 19:56:38 -05003572 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003573 rn = (RNID *) (pcmd);
3574 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003575 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3576 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3577 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003578 switch (format) {
3579 case 0:
3580 rn->SpecificLen = 0;
3581 break;
3582 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003583 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003584 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003585 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003586 rn->un.topologyDisc.unitType = RNID_HBA;
3587 rn->un.topologyDisc.physPort = 0;
3588 rn->un.topologyDisc.attachedNodes = 0;
3589 break;
3590 default:
3591 rn->CommonLen = 0;
3592 rn->SpecificLen = 0;
3593 break;
3594 }
3595
James Smart858c9f62007-06-17 19:56:39 -05003596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3597 "Issue ACC RNID: did:x%x flg:x%x",
3598 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3599
dea31012005-04-17 16:05:31 -05003600 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003601 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003602 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003603 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3604 * it could be freed */
3605
James Smart3772a992009-05-22 14:50:54 -04003606 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003607 if (rc == IOCB_ERROR) {
3608 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003609 return 1;
dea31012005-04-17 16:05:31 -05003610 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003611 return 0;
dea31012005-04-17 16:05:31 -05003612}
3613
James Smarte59058c2008-08-24 21:49:00 -04003614/**
James Smart3621a712009-04-06 18:47:14 -04003615 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003616 * @vport: pointer to a host virtual N_Port data structure.
3617 *
3618 * This routine issues Address Discover (ADISC) ELS commands to those
3619 * N_Ports which are in node port recovery state and ADISC has not been issued
3620 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3621 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3622 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3623 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3624 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3625 * IOCBs quit for later pick up. On the other hand, after walking through
3626 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3627 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3628 * no more ADISC need to be sent.
3629 *
3630 * Return code
3631 * The number of N_Ports with adisc issued.
3632 **/
dea31012005-04-17 16:05:31 -05003633int
James Smart2e0fef82007-06-17 19:56:36 -05003634lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003635{
James Smart2e0fef82007-06-17 19:56:36 -05003636 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003637 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003638 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003639
James Smart685f0bf2007-04-25 09:53:08 -04003640 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003641 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003642 if (!NLP_CHK_NODE_ACT(ndlp))
3643 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003644 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3645 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3646 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003647 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003648 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003649 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003650 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003651 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3652 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003653 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003654 vport->num_disc_nodes++;
3655 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003656 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003657 spin_lock_irq(shost->host_lock);
3658 vport->fc_flag |= FC_NLP_MORE;
3659 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003660 break;
dea31012005-04-17 16:05:31 -05003661 }
3662 }
3663 }
3664 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003665 spin_lock_irq(shost->host_lock);
3666 vport->fc_flag &= ~FC_NLP_MORE;
3667 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003668 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003669 return sentadisc;
dea31012005-04-17 16:05:31 -05003670}
3671
James Smarte59058c2008-08-24 21:49:00 -04003672/**
James Smart3621a712009-04-06 18:47:14 -04003673 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003674 * @vport: pointer to a host virtual N_Port data structure.
3675 *
3676 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3677 * which are in node port recovery state, with a @vport. Each time an ELS
3678 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3679 * the per @vport number of discover count (num_disc_nodes) shall be
3680 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3681 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3682 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3683 * later pick up. On the other hand, after walking through all the ndlps with
3684 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3685 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3686 * PLOGI need to be sent.
3687 *
3688 * Return code
3689 * The number of N_Ports with plogi issued.
3690 **/
dea31012005-04-17 16:05:31 -05003691int
James Smart2e0fef82007-06-17 19:56:36 -05003692lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003693{
James Smart2e0fef82007-06-17 19:56:36 -05003694 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003695 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003696 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003697
James Smart2e0fef82007-06-17 19:56:36 -05003698 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3699 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003700 if (!NLP_CHK_NODE_ACT(ndlp))
3701 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003702 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3703 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3704 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3705 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3706 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003707 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3708 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003709 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003710 vport->num_disc_nodes++;
3711 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003712 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003713 spin_lock_irq(shost->host_lock);
3714 vport->fc_flag |= FC_NLP_MORE;
3715 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003716 break;
dea31012005-04-17 16:05:31 -05003717 }
3718 }
3719 }
James Smart87af33f2007-10-27 13:37:43 -04003720 if (sentplogi) {
3721 lpfc_set_disctmo(vport);
3722 }
3723 else {
James Smart2e0fef82007-06-17 19:56:36 -05003724 spin_lock_irq(shost->host_lock);
3725 vport->fc_flag &= ~FC_NLP_MORE;
3726 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003727 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003728 return sentplogi;
dea31012005-04-17 16:05:31 -05003729}
3730
James Smarte59058c2008-08-24 21:49:00 -04003731/**
James Smart3621a712009-04-06 18:47:14 -04003732 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003733 * @vport: pointer to a host virtual N_Port data structure.
3734 *
3735 * This routine cleans up any Registration State Change Notification
3736 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3737 * @vport together with the host_lock is used to prevent multiple thread
3738 * trying to access the RSCN array on a same @vport at the same time.
3739 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003740void
James Smart2e0fef82007-06-17 19:56:36 -05003741lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003742{
James Smart2e0fef82007-06-17 19:56:36 -05003743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3744 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003745 int i;
3746
James Smart7f5f3d02008-02-08 18:50:14 -05003747 spin_lock_irq(shost->host_lock);
3748 if (vport->fc_rscn_flush) {
3749 /* Another thread is walking fc_rscn_id_list on this vport */
3750 spin_unlock_irq(shost->host_lock);
3751 return;
3752 }
3753 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3754 vport->fc_rscn_flush = 1;
3755 spin_unlock_irq(shost->host_lock);
3756
James Smart2e0fef82007-06-17 19:56:36 -05003757 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003758 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003759 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003760 }
James Smart2e0fef82007-06-17 19:56:36 -05003761 spin_lock_irq(shost->host_lock);
3762 vport->fc_rscn_id_cnt = 0;
3763 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3764 spin_unlock_irq(shost->host_lock);
3765 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003766 /* Indicate we are done walking this fc_rscn_id_list */
3767 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003768}
3769
James Smarte59058c2008-08-24 21:49:00 -04003770/**
James Smart3621a712009-04-06 18:47:14 -04003771 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003772 * @vport: pointer to a host virtual N_Port data structure.
3773 * @did: remote destination port identifier.
3774 *
3775 * This routine checks whether there is any pending Registration State
3776 * Configuration Notification (RSCN) to a @did on @vport.
3777 *
3778 * Return code
3779 * None zero - The @did matched with a pending rscn
3780 * 0 - not able to match @did with a pending rscn
3781 **/
dea31012005-04-17 16:05:31 -05003782int
James Smart2e0fef82007-06-17 19:56:36 -05003783lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003784{
3785 D_ID ns_did;
3786 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003787 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003788 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003789 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003790
3791 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05003792
3793 /* Never match fabric nodes for RSCNs */
3794 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003795 return 0;
dea31012005-04-17 16:05:31 -05003796
3797 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003798 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003799 return did;
dea31012005-04-17 16:05:31 -05003800
James Smart7f5f3d02008-02-08 18:50:14 -05003801 spin_lock_irq(shost->host_lock);
3802 if (vport->fc_rscn_flush) {
3803 /* Another thread is walking fc_rscn_id_list on this vport */
3804 spin_unlock_irq(shost->host_lock);
3805 return 0;
3806 }
3807 /* Indicate we are walking fc_rscn_id_list on this vport */
3808 vport->fc_rscn_flush = 1;
3809 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003810 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003811 lp = vport->fc_rscn_id_list[i]->virt;
3812 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3813 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003814 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003815 rscn_did.un.word = be32_to_cpu(*lp++);
3816 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05003817 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3818 case RSCN_ADDRESS_FORMAT_PORT:
James Smart2e0fef82007-06-17 19:56:36 -05003819 if (ns_did.un.word == rscn_did.un.word)
James Smart7f5f3d02008-02-08 18:50:14 -05003820 goto return_did_out;
dea31012005-04-17 16:05:31 -05003821 break;
James Smarteaf15d52008-12-04 22:39:29 -05003822 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05003823 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3824 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003825 goto return_did_out;
dea31012005-04-17 16:05:31 -05003826 break;
James Smarteaf15d52008-12-04 22:39:29 -05003827 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05003828 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003829 goto return_did_out;
dea31012005-04-17 16:05:31 -05003830 break;
James Smarteaf15d52008-12-04 22:39:29 -05003831 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05003832 goto return_did_out;
dea31012005-04-17 16:05:31 -05003833 }
3834 }
James Smart92d7f7b2007-06-17 19:56:38 -05003835 }
James Smart7f5f3d02008-02-08 18:50:14 -05003836 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3837 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003838 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003839return_did_out:
3840 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3841 vport->fc_rscn_flush = 0;
3842 return did;
dea31012005-04-17 16:05:31 -05003843}
3844
James Smarte59058c2008-08-24 21:49:00 -04003845/**
James Smart3621a712009-04-06 18:47:14 -04003846 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04003847 * @vport: pointer to a host virtual N_Port data structure.
3848 *
3849 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3850 * state machine for a @vport's nodes that are with pending RSCN (Registration
3851 * State Change Notification).
3852 *
3853 * Return code
3854 * 0 - Successful (currently alway return 0)
3855 **/
dea31012005-04-17 16:05:31 -05003856static int
James Smart2e0fef82007-06-17 19:56:36 -05003857lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003858{
James Smart685f0bf2007-04-25 09:53:08 -04003859 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003860
James Smart0d2b6b82008-06-14 22:52:47 -04003861 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003862 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003863 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04003864 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3865 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05003866 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003867 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04003868 NLP_EVT_DEVICE_RECOVERY);
3869 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003870 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003871 return 0;
dea31012005-04-17 16:05:31 -05003872}
3873
James Smarte59058c2008-08-24 21:49:00 -04003874/**
James Smart3621a712009-04-06 18:47:14 -04003875 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05003876 * @vport: pointer to a host virtual N_Port data structure.
3877 * @cmdiocb: pointer to lpfc command iocb data structure.
3878 *
3879 * lpfc_send_rscn_event sends an RSCN netlink event to management
3880 * applications.
3881 */
3882static void
3883lpfc_send_rscn_event(struct lpfc_vport *vport,
3884 struct lpfc_iocbq *cmdiocb)
3885{
3886 struct lpfc_dmabuf *pcmd;
3887 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3888 uint32_t *payload_ptr;
3889 uint32_t payload_len;
3890 struct lpfc_rscn_event_header *rscn_event_data;
3891
3892 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3893 payload_ptr = (uint32_t *) pcmd->virt;
3894 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
3895
3896 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
3897 payload_len, GFP_KERNEL);
3898 if (!rscn_event_data) {
3899 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3900 "0147 Failed to allocate memory for RSCN event\n");
3901 return;
3902 }
3903 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
3904 rscn_event_data->payload_length = payload_len;
3905 memcpy(rscn_event_data->rscn_payload, payload_ptr,
3906 payload_len);
3907
3908 fc_host_post_vendor_event(shost,
3909 fc_get_event_number(),
3910 sizeof(struct lpfc_els_event_header) + payload_len,
3911 (char *)rscn_event_data,
3912 LPFC_NL_VENDOR_ID);
3913
3914 kfree(rscn_event_data);
3915}
3916
3917/**
James Smart3621a712009-04-06 18:47:14 -04003918 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04003919 * @vport: pointer to a host virtual N_Port data structure.
3920 * @cmdiocb: pointer to lpfc command iocb data structure.
3921 * @ndlp: pointer to a node-list data structure.
3922 *
3923 * This routine processes an unsolicited RSCN (Registration State Change
3924 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3925 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3926 * discover state machine is about to begin discovery, it just accepts the
3927 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3928 * contains N_Port IDs for other vports on this HBA, it just accepts the
3929 * RSCN and ignore processing it. If the state machine is in the recovery
3930 * state, the fc_rscn_id_list of this @vport is walked and the
3931 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3932 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3933 * routine is invoked to handle the RSCN event.
3934 *
3935 * Return code
3936 * 0 - Just sent the acc response
3937 * 1 - Sent the acc response and waited for name server completion
3938 **/
dea31012005-04-17 16:05:31 -05003939static int
James Smart2e0fef82007-06-17 19:56:36 -05003940lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003941 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003942{
James Smart2e0fef82007-06-17 19:56:36 -05003943 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3944 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003945 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003946 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05003947 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003948 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003949 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05003950 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04003951 int i;
dea31012005-04-17 16:05:31 -05003952
3953 icmd = &cmdiocb->iocb;
3954 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3955 lp = (uint32_t *) pcmd->virt;
3956
James Smart92d7f7b2007-06-17 19:56:38 -05003957 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3958 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003959 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04003960 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3961 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05003962 vport->fc_flag, payload_len, *lp,
3963 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05003964
3965 /* Send an RSCN event to the management application */
3966 lpfc_send_rscn_event(vport, cmdiocb);
3967
James Smartd2873e42006-08-18 17:46:43 -04003968 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05003969 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04003970 FCH_EVT_RSCN, lp[i]);
3971
dea31012005-04-17 16:05:31 -05003972 /* If we are about to begin discovery, just ACC the RSCN.
3973 * Discovery processing will satisfy it.
3974 */
James Smart2e0fef82007-06-17 19:56:36 -05003975 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05003976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3977 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3978 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3979
James Smart51ef4c22007-08-02 11:10:31 -04003980 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003981 return 0;
dea31012005-04-17 16:05:31 -05003982 }
3983
James Smart92d7f7b2007-06-17 19:56:38 -05003984 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3985 * just ACC and ignore it.
3986 */
3987 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04003988 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003989 i = payload_len;
3990 datap = lp;
3991 while (i > 0) {
3992 nportid = *datap++;
3993 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3994 i -= sizeof(uint32_t);
3995 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04003996 if (lpfc_find_vport_by_did(phba, nportid))
3997 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05003998 }
3999 if (rscn_id == hba_id) {
4000 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004001 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004002 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004003 "Data: x%x x%x x%x x%x\n",
4004 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004005 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4007 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4008 ndlp->nlp_DID, vport->port_state,
4009 ndlp->nlp_flag);
4010
James Smart92d7f7b2007-06-17 19:56:38 -05004011 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004012 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004013 return 0;
4014 }
4015 }
4016
James Smart7f5f3d02008-02-08 18:50:14 -05004017 spin_lock_irq(shost->host_lock);
4018 if (vport->fc_rscn_flush) {
4019 /* Another thread is walking fc_rscn_id_list on this vport */
4020 spin_unlock_irq(shost->host_lock);
4021 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart58da1ff2008-04-07 10:15:56 -04004022 /* Send back ACC */
4023 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004024 return 0;
4025 }
4026 /* Indicate we are walking fc_rscn_id_list on this vport */
4027 vport->fc_rscn_flush = 1;
4028 spin_unlock_irq(shost->host_lock);
4029 /* Get the array count after sucessfully have the token */
4030 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004031 /* If we are already processing an RSCN, save the received
4032 * RSCN payload buffer, cmdiocb->context2 to process later.
4033 */
James Smart2e0fef82007-06-17 19:56:36 -05004034 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004035 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4036 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4037 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4038
James Smart09372822008-01-11 01:52:54 -05004039 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004040 vport->fc_flag |= FC_RSCN_DEFERRED;
4041 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004042 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004043 vport->fc_flag |= FC_RSCN_MODE;
4044 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004045 if (rscn_cnt) {
4046 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4047 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4048 }
4049 if ((rscn_cnt) &&
4050 (payload_len + length <= LPFC_BPL_SIZE)) {
4051 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004052 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004053 memcpy(((uint8_t *)cmd) + length, lp,
4054 payload_len);
4055 } else {
4056 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4057 vport->fc_rscn_id_cnt++;
4058 /* If we zero, cmdiocb->context2, the calling
4059 * routine will not try to free it.
4060 */
4061 cmdiocb->context2 = NULL;
4062 }
dea31012005-04-17 16:05:31 -05004063 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004064 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4065 "0235 Deferred RSCN "
4066 "Data: x%x x%x x%x\n",
4067 vport->fc_rscn_id_cnt, vport->fc_flag,
4068 vport->port_state);
dea31012005-04-17 16:05:31 -05004069 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004070 vport->fc_flag |= FC_RSCN_DISCOVERY;
4071 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004072 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004073 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4074 "0234 ReDiscovery RSCN "
4075 "Data: x%x x%x x%x\n",
4076 vport->fc_rscn_id_cnt, vport->fc_flag,
4077 vport->port_state);
dea31012005-04-17 16:05:31 -05004078 }
James Smart7f5f3d02008-02-08 18:50:14 -05004079 /* Indicate we are done walking fc_rscn_id_list on this vport */
4080 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004081 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004082 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004083 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004084 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004085 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004086 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004087 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004088 return 0;
dea31012005-04-17 16:05:31 -05004089 }
James Smart858c9f62007-06-17 19:56:39 -05004090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4091 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4092 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4093
James Smart2e0fef82007-06-17 19:56:36 -05004094 spin_lock_irq(shost->host_lock);
4095 vport->fc_flag |= FC_RSCN_MODE;
4096 spin_unlock_irq(shost->host_lock);
4097 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004098 /* Indicate we are done walking fc_rscn_id_list on this vport */
4099 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004100 /*
4101 * If we zero, cmdiocb->context2, the calling routine will
4102 * not try to free it.
4103 */
4104 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004105 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004106 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004107 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004108 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004109 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004110 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004111}
4112
James Smarte59058c2008-08-24 21:49:00 -04004113/**
James Smart3621a712009-04-06 18:47:14 -04004114 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004115 * @vport: pointer to a host virtual N_Port data structure.
4116 *
4117 * This routine handles the Registration State Configuration Notification
4118 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4119 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4120 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4121 * NameServer shall be issued. If CT command to the NameServer fails to be
4122 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4123 * RSCN activities with the @vport.
4124 *
4125 * Return code
4126 * 0 - Cleaned up rscn on the @vport
4127 * 1 - Wait for plogi to name server before proceed
4128 **/
dea31012005-04-17 16:05:31 -05004129int
James Smart2e0fef82007-06-17 19:56:36 -05004130lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004131{
4132 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004133 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004134
James Smart92d7f7b2007-06-17 19:56:38 -05004135 /* Ignore RSCN if the port is being torn down. */
4136 if (vport->load_flag & FC_UNLOADING) {
4137 lpfc_els_flush_rscn(vport);
4138 return 0;
4139 }
4140
dea31012005-04-17 16:05:31 -05004141 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004142 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004143
4144 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004145 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4146 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4147 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4148 vport->port_state);
dea31012005-04-17 16:05:31 -05004149
4150 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004151 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004152 vport->num_disc_nodes = 0;
4153
James Smart2e0fef82007-06-17 19:56:36 -05004154 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004155 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4156 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004157 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004158 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004159 /* Wait for NameServer query cmpl before we can
4160 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004161 return 1;
dea31012005-04-17 16:05:31 -05004162 } else {
4163 /* If login to NameServer does not exist, issue one */
4164 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004165 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004166 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004167 /* Wait for NameServer login cmpl before we can
4168 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004169 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004170
James Smarte47c9092008-02-08 18:49:26 -05004171 if (ndlp) {
4172 ndlp = lpfc_enable_node(vport, ndlp,
4173 NLP_STE_PLOGI_ISSUE);
4174 if (!ndlp) {
4175 lpfc_els_flush_rscn(vport);
4176 return 0;
4177 }
4178 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004179 } else {
James Smarte47c9092008-02-08 18:49:26 -05004180 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4181 if (!ndlp) {
4182 lpfc_els_flush_rscn(vport);
4183 return 0;
4184 }
James Smart2e0fef82007-06-17 19:56:36 -05004185 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004186 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004187 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004188 }
James Smarte47c9092008-02-08 18:49:26 -05004189 ndlp->nlp_type |= NLP_FABRIC;
4190 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4191 /* Wait for NameServer login cmpl before we can
4192 * continue
4193 */
4194 return 1;
dea31012005-04-17 16:05:31 -05004195 }
4196
James Smart2e0fef82007-06-17 19:56:36 -05004197 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004198 return 0;
dea31012005-04-17 16:05:31 -05004199}
4200
James Smarte59058c2008-08-24 21:49:00 -04004201/**
James Smart3621a712009-04-06 18:47:14 -04004202 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004203 * @vport: pointer to a host virtual N_Port data structure.
4204 * @cmdiocb: pointer to lpfc command iocb data structure.
4205 * @ndlp: pointer to a node-list data structure.
4206 *
4207 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4208 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4209 * point topology. As an unsolicited FLOGI should not be received in a loop
4210 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4211 * lpfc_check_sparm() routine is invoked to check the parameters in the
4212 * unsolicited FLOGI. If parameters validation failed, the routine
4213 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4214 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4215 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4216 * will initiate PLOGI. The higher lexicographical value party shall has
4217 * higher priority (as the winning port) and will initiate PLOGI and
4218 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4219 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4220 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4221 *
4222 * Return code
4223 * 0 - Successfully processed the unsolicited flogi
4224 * 1 - Failed to process the unsolicited flogi
4225 **/
dea31012005-04-17 16:05:31 -05004226static int
James Smart2e0fef82007-06-17 19:56:36 -05004227lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004228 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004229{
James Smart2e0fef82007-06-17 19:56:36 -05004230 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4231 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004232 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4233 uint32_t *lp = (uint32_t *) pcmd->virt;
4234 IOCB_t *icmd = &cmdiocb->iocb;
4235 struct serv_parm *sp;
4236 LPFC_MBOXQ_t *mbox;
4237 struct ls_rjt stat;
4238 uint32_t cmd, did;
4239 int rc;
4240
4241 cmd = *lp++;
4242 sp = (struct serv_parm *) lp;
4243
4244 /* FLOGI received */
4245
James Smart2e0fef82007-06-17 19:56:36 -05004246 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004247
4248 if (phba->fc_topology == TOPOLOGY_LOOP) {
4249 /* We should never receive a FLOGI in loop mode, ignore it */
4250 did = icmd->un.elsreq64.remoteID;
4251
4252 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4253 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004254 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4255 "0113 An FLOGI ELS command x%x was "
4256 "received from DID x%x in Loop Mode\n",
4257 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004258 return 1;
dea31012005-04-17 16:05:31 -05004259 }
4260
4261 did = Fabric_DID;
4262
James Smart2e0fef82007-06-17 19:56:36 -05004263 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05004264 /* For a FLOGI we accept, then if our portname is greater
4265 * then the remote portname we initiate Nport login.
4266 */
4267
James Smart2e0fef82007-06-17 19:56:36 -05004268 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004269 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004270
4271 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004272 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4273 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004274 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004275
dea31012005-04-17 16:05:31 -05004276 lpfc_linkdown(phba);
4277 lpfc_init_link(phba, mbox,
4278 phba->cfg_topology,
4279 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004280 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004281 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004282 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004283 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004284 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004285 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004286 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004287 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004288 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004289 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004290 spin_lock_irq(shost->host_lock);
4291 vport->fc_flag |= FC_PT2PT_PLOGI;
4292 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004293 }
James Smart2e0fef82007-06-17 19:56:36 -05004294 spin_lock_irq(shost->host_lock);
4295 vport->fc_flag |= FC_PT2PT;
4296 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4297 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004298 } else {
4299 /* Reject this request because invalid parameters */
4300 stat.un.b.lsRjtRsvd0 = 0;
4301 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4302 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4303 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004304 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4305 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004306 return 1;
dea31012005-04-17 16:05:31 -05004307 }
4308
4309 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004310 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004311
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004312 return 0;
dea31012005-04-17 16:05:31 -05004313}
4314
James Smarte59058c2008-08-24 21:49:00 -04004315/**
James Smart3621a712009-04-06 18:47:14 -04004316 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004317 * @vport: pointer to a host virtual N_Port data structure.
4318 * @cmdiocb: pointer to lpfc command iocb data structure.
4319 * @ndlp: pointer to a node-list data structure.
4320 *
4321 * This routine processes Request Node Identification Data (RNID) IOCB
4322 * received as an ELS unsolicited event. Only when the RNID specified format
4323 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4324 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4325 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4326 * rejected by invoking the lpfc_els_rsp_reject() routine.
4327 *
4328 * Return code
4329 * 0 - Successfully processed rnid iocb (currently always return 0)
4330 **/
dea31012005-04-17 16:05:31 -05004331static int
James Smart2e0fef82007-06-17 19:56:36 -05004332lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4333 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004334{
4335 struct lpfc_dmabuf *pcmd;
4336 uint32_t *lp;
4337 IOCB_t *icmd;
4338 RNID *rn;
4339 struct ls_rjt stat;
4340 uint32_t cmd, did;
4341
4342 icmd = &cmdiocb->iocb;
4343 did = icmd->un.elsreq64.remoteID;
4344 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4345 lp = (uint32_t *) pcmd->virt;
4346
4347 cmd = *lp++;
4348 rn = (RNID *) lp;
4349
4350 /* RNID received */
4351
4352 switch (rn->Format) {
4353 case 0:
4354 case RNID_TOPOLOGY_DISC:
4355 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004356 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004357 break;
4358 default:
4359 /* Reject this request because format not supported */
4360 stat.un.b.lsRjtRsvd0 = 0;
4361 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4362 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4363 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004364 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4365 NULL);
dea31012005-04-17 16:05:31 -05004366 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004367 return 0;
dea31012005-04-17 16:05:31 -05004368}
4369
James Smarte59058c2008-08-24 21:49:00 -04004370/**
James Smart3621a712009-04-06 18:47:14 -04004371 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004372 * @vport: pointer to a host virtual N_Port data structure.
4373 * @cmdiocb: pointer to lpfc command iocb data structure.
4374 * @ndlp: pointer to a node-list data structure.
4375 *
4376 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4377 * received as an ELS unsolicited event. Currently, this function just invokes
4378 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4379 *
4380 * Return code
4381 * 0 - Successfully processed lirr iocb (currently always return 0)
4382 **/
dea31012005-04-17 16:05:31 -05004383static int
James Smart2e0fef82007-06-17 19:56:36 -05004384lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4385 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004386{
4387 struct ls_rjt stat;
4388
4389 /* For now, unconditionally reject this command */
4390 stat.un.b.lsRjtRsvd0 = 0;
4391 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4392 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4393 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004394 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004395 return 0;
4396}
4397
James Smarte59058c2008-08-24 21:49:00 -04004398/**
James Smart3621a712009-04-06 18:47:14 -04004399 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004400 * @phba: pointer to lpfc hba data structure.
4401 * @pmb: pointer to the driver internal queue element for mailbox command.
4402 *
4403 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4404 * mailbox command. This callback function is to actually send the Accept
4405 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4406 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4407 * mailbox command, constructs the RPS response with the link statistics
4408 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4409 * response to the RPS.
4410 *
4411 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4412 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4413 * will be stored into the context1 field of the IOCB for the completion
4414 * callback function to the RPS Accept Response ELS IOCB command.
4415 *
4416 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004417static void
James Smart329f9bc2007-04-25 09:53:01 -04004418lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004419{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004420 MAILBOX_t *mb;
4421 IOCB_t *icmd;
4422 RPS_RSP *rps_rsp;
4423 uint8_t *pcmd;
4424 struct lpfc_iocbq *elsiocb;
4425 struct lpfc_nodelist *ndlp;
4426 uint16_t xri, status;
4427 uint32_t cmdsize;
4428
James Smart04c68492009-05-22 14:52:52 -04004429 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004430
4431 ndlp = (struct lpfc_nodelist *) pmb->context2;
4432 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004433 pmb->context1 = NULL;
4434 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004435
4436 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004437 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004438 return;
4439 }
4440
4441 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004442 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004443 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4444 lpfc_max_els_tries, ndlp,
4445 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004446
4447 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004448 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004449
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004450 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004451 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004452
4453 icmd = &elsiocb->iocb;
4454 icmd->ulpContext = xri;
4455
4456 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4457 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004458 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004459 rps_rsp = (RPS_RSP *)pcmd;
4460
4461 if (phba->fc_topology != TOPOLOGY_LOOP)
4462 status = 0x10;
4463 else
4464 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004465 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004466 status |= 0x4;
4467
4468 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004469 rps_rsp->portStatus = cpu_to_be16(status);
4470 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4471 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4472 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4473 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4474 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4475 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004476 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004477 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4478 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4479 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4480 elsiocb->iotag, elsiocb->iocb.ulpContext,
4481 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4482 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004483 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004484 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004485 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004486 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004487 return;
4488}
4489
James Smarte59058c2008-08-24 21:49:00 -04004490/**
James Smart3621a712009-04-06 18:47:14 -04004491 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004492 * @vport: pointer to a host virtual N_Port data structure.
4493 * @cmdiocb: pointer to lpfc command iocb data structure.
4494 * @ndlp: pointer to a node-list data structure.
4495 *
4496 * This routine processes Read Port Status (RPS) IOCB received as an
4497 * ELS unsolicited event. It first checks the remote port state. If the
4498 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4499 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4500 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4501 * for reading the HBA link statistics. It is for the callback function,
4502 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4503 * to actually sending out RPS Accept (ACC) response.
4504 *
4505 * Return codes
4506 * 0 - Successfully processed rps iocb (currently always return 0)
4507 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004508static int
James Smart2e0fef82007-06-17 19:56:36 -05004509lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4510 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004511{
James Smart2e0fef82007-06-17 19:56:36 -05004512 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004513 uint32_t *lp;
4514 uint8_t flag;
4515 LPFC_MBOXQ_t *mbox;
4516 struct lpfc_dmabuf *pcmd;
4517 RPS *rps;
4518 struct ls_rjt stat;
4519
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004520 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004521 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4522 /* reject the unsolicited RPS request and done with it */
4523 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004524
4525 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4526 lp = (uint32_t *) pcmd->virt;
4527 flag = (be32_to_cpu(*lp++) & 0xf);
4528 rps = (RPS *) lp;
4529
4530 if ((flag == 0) ||
4531 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004532 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004533 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004534
James Smart92d7f7b2007-06-17 19:56:38 -05004535 printk("Fix me....\n");
4536 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004537 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4538 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004539 lpfc_read_lnk_stat(phba, mbox);
4540 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004541 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004542 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004543 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004544 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004545 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004546 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004547 /* Mbox completion will send ELS Response */
4548 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004549 /* Decrement reference count used for the failed mbox
4550 * command.
4551 */
James Smart329f9bc2007-04-25 09:53:01 -04004552 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004553 mempool_free(mbox, phba->mbox_mem_pool);
4554 }
4555 }
James Smart90160e02008-08-24 21:49:45 -04004556
4557reject_out:
4558 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004559 stat.un.b.lsRjtRsvd0 = 0;
4560 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4561 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4562 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004563 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004564 return 0;
4565}
4566
James Smarte59058c2008-08-24 21:49:00 -04004567/**
James Smart3621a712009-04-06 18:47:14 -04004568 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004569 * @vport: pointer to a host virtual N_Port data structure.
4570 * @cmdsize: size of the ELS command.
4571 * @oldiocb: pointer to the original lpfc command iocb data structure.
4572 * @ndlp: pointer to a node-list data structure.
4573 *
4574 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4575 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4576 *
4577 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4578 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4579 * will be stored into the context1 field of the IOCB for the completion
4580 * callback function to the RPL Accept Response ELS command.
4581 *
4582 * Return code
4583 * 0 - Successfully issued ACC RPL ELS command
4584 * 1 - Failed to issue ACC RPL ELS command
4585 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004586static int
James Smart2e0fef82007-06-17 19:56:36 -05004587lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4588 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004589{
James Smart2e0fef82007-06-17 19:56:36 -05004590 struct lpfc_hba *phba = vport->phba;
4591 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004592 RPL_RSP rpl_rsp;
4593 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004594 uint8_t *pcmd;
4595
James Smart2e0fef82007-06-17 19:56:36 -05004596 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4597 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004598
James Smart488d1462006-03-07 15:02:37 -05004599 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004600 return 1;
James Smart488d1462006-03-07 15:02:37 -05004601
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004602 icmd = &elsiocb->iocb;
4603 oldcmd = &oldiocb->iocb;
4604 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4605
4606 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4607 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004608 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004609 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4610 pcmd += sizeof(uint16_t);
4611
4612 /* Setup the RPL ACC payload */
4613 rpl_rsp.listLen = be32_to_cpu(1);
4614 rpl_rsp.index = 0;
4615 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004616 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4617 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004618 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004619 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004620 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004621 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4622 "0120 Xmit ELS RPL ACC response tag x%x "
4623 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4624 "rpi x%x\n",
4625 elsiocb->iotag, elsiocb->iocb.ulpContext,
4626 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4627 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004628 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004629 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004630 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4631 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004632 lpfc_els_free_iocb(phba, elsiocb);
4633 return 1;
4634 }
4635 return 0;
4636}
4637
James Smarte59058c2008-08-24 21:49:00 -04004638/**
James Smart3621a712009-04-06 18:47:14 -04004639 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004640 * @vport: pointer to a host virtual N_Port data structure.
4641 * @cmdiocb: pointer to lpfc command iocb data structure.
4642 * @ndlp: pointer to a node-list data structure.
4643 *
4644 * This routine processes Read Port List (RPL) IOCB received as an ELS
4645 * unsolicited event. It first checks the remote port state. If the remote
4646 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4647 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4648 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4649 * to accept the RPL.
4650 *
4651 * Return code
4652 * 0 - Successfully processed rpl iocb (currently always return 0)
4653 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004654static int
James Smart2e0fef82007-06-17 19:56:36 -05004655lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4656 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004657{
4658 struct lpfc_dmabuf *pcmd;
4659 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004660 uint32_t maxsize;
4661 uint16_t cmdsize;
4662 RPL *rpl;
4663 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004664
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004665 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4666 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004667 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004668 stat.un.b.lsRjtRsvd0 = 0;
4669 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4670 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4671 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004672 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4673 NULL);
James Smart90160e02008-08-24 21:49:45 -04004674 /* rejected the unsolicited RPL request and done with it */
4675 return 0;
dea31012005-04-17 16:05:31 -05004676 }
4677
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004678 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4679 lp = (uint32_t *) pcmd->virt;
4680 rpl = (RPL *) (lp + 1);
4681
4682 maxsize = be32_to_cpu(rpl->maxsize);
4683
4684 /* We support only one port */
4685 if ((rpl->index == 0) &&
4686 ((maxsize == 0) ||
4687 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4688 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004689 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004690 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4691 }
James Smart2e0fef82007-06-17 19:56:36 -05004692 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004693
4694 return 0;
4695}
4696
James Smarte59058c2008-08-24 21:49:00 -04004697/**
James Smart3621a712009-04-06 18:47:14 -04004698 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004699 * @vport: pointer to a virtual N_Port data structure.
4700 * @cmdiocb: pointer to lpfc command iocb data structure.
4701 * @ndlp: pointer to a node-list data structure.
4702 *
4703 * This routine processes Fibre Channel Address Resolution Protocol
4704 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4705 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4706 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4707 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4708 * remote PortName is compared against the FC PortName stored in the @vport
4709 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4710 * compared against the FC NodeName stored in the @vport data structure.
4711 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4712 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4713 * invoked to send out FARP Response to the remote node. Before sending the
4714 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4715 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4716 * routine is invoked to log into the remote port first.
4717 *
4718 * Return code
4719 * 0 - Either the FARP Match Mode not supported or successfully processed
4720 **/
dea31012005-04-17 16:05:31 -05004721static int
James Smart2e0fef82007-06-17 19:56:36 -05004722lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4723 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004724{
4725 struct lpfc_dmabuf *pcmd;
4726 uint32_t *lp;
4727 IOCB_t *icmd;
4728 FARP *fp;
4729 uint32_t cmd, cnt, did;
4730
4731 icmd = &cmdiocb->iocb;
4732 did = icmd->un.elsreq64.remoteID;
4733 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4734 lp = (uint32_t *) pcmd->virt;
4735
4736 cmd = *lp++;
4737 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004738 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004739 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4740 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004741 /* We will only support match on WWPN or WWNN */
4742 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004743 return 0;
dea31012005-04-17 16:05:31 -05004744 }
4745
4746 cnt = 0;
4747 /* If this FARP command is searching for my portname */
4748 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004749 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004750 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004751 cnt = 1;
4752 }
4753
4754 /* If this FARP command is searching for my nodename */
4755 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004756 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004757 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004758 cnt = 1;
4759 }
4760
4761 if (cnt) {
4762 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4763 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4764 /* Log back into the node before sending the FARP. */
4765 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004766 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004767 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004768 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004769 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05004770 }
4771
4772 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05004773 if (fp->Rflags & FARP_REQUEST_FARPR)
4774 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05004775 }
4776 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004777 return 0;
dea31012005-04-17 16:05:31 -05004778}
4779
James Smarte59058c2008-08-24 21:49:00 -04004780/**
James Smart3621a712009-04-06 18:47:14 -04004781 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04004782 * @vport: pointer to a host virtual N_Port data structure.
4783 * @cmdiocb: pointer to lpfc command iocb data structure.
4784 * @ndlp: pointer to a node-list data structure.
4785 *
4786 * This routine processes Fibre Channel Address Resolution Protocol
4787 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4788 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4789 * the FARP response request.
4790 *
4791 * Return code
4792 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4793 **/
dea31012005-04-17 16:05:31 -05004794static int
James Smart2e0fef82007-06-17 19:56:36 -05004795lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4796 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004797{
4798 struct lpfc_dmabuf *pcmd;
4799 uint32_t *lp;
4800 IOCB_t *icmd;
4801 uint32_t cmd, did;
4802
4803 icmd = &cmdiocb->iocb;
4804 did = icmd->un.elsreq64.remoteID;
4805 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4806 lp = (uint32_t *) pcmd->virt;
4807
4808 cmd = *lp++;
4809 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004810 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4811 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004812 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04004813 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004814
4815 return 0;
4816}
4817
James Smarte59058c2008-08-24 21:49:00 -04004818/**
James Smart3621a712009-04-06 18:47:14 -04004819 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04004820 * @vport: pointer to a host virtual N_Port data structure.
4821 * @cmdiocb: pointer to lpfc command iocb data structure.
4822 * @fan_ndlp: pointer to a node-list data structure.
4823 *
4824 * This routine processes a Fabric Address Notification (FAN) IOCB
4825 * command received as an ELS unsolicited event. The FAN ELS command will
4826 * only be processed on a physical port (i.e., the @vport represents the
4827 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4828 * compared against those in the phba data structure. If any of those is
4829 * different, the lpfc_initial_flogi() routine is invoked to initialize
4830 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4831 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4832 * is invoked to register login to the fabric.
4833 *
4834 * Return code
4835 * 0 - Successfully processed fan iocb (currently always return 0).
4836 **/
dea31012005-04-17 16:05:31 -05004837static int
James Smart2e0fef82007-06-17 19:56:36 -05004838lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4839 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05004840{
James Smart2e0fef82007-06-17 19:56:36 -05004841 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04004842 uint32_t *lp;
4843 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004844
James Smart0d2b6b82008-06-14 22:52:47 -04004845 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4846 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4847 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004848 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04004849 if ((vport == phba->pport) &&
4850 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004851 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04004852 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004853 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04004854 sizeof(struct lpfc_name)))) {
4855 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05004856 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04004857 } else {
4858 /* FAN verified - skip FLOGI */
4859 vport->fc_myDID = vport->fc_prevDID;
4860 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -05004861 }
dea31012005-04-17 16:05:31 -05004862 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004863 return 0;
dea31012005-04-17 16:05:31 -05004864}
4865
James Smarte59058c2008-08-24 21:49:00 -04004866/**
James Smart3621a712009-04-06 18:47:14 -04004867 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04004868 * @ptr: holder for the timer function associated data.
4869 *
4870 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4871 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4872 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4873 * up the worker thread. It is for the worker thread to invoke the routine
4874 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4875 **/
dea31012005-04-17 16:05:31 -05004876void
4877lpfc_els_timeout(unsigned long ptr)
4878{
James Smart2e0fef82007-06-17 19:56:36 -05004879 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4880 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04004881 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05004882 unsigned long iflag;
4883
James Smart2e0fef82007-06-17 19:56:36 -05004884 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04004885 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4886 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05004887 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04004888 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05004889
James Smart5e9d9b82008-06-14 22:52:53 -04004890 if (!tmo_posted)
4891 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05004892 return;
4893}
4894
James Smarte59058c2008-08-24 21:49:00 -04004895/**
James Smart3621a712009-04-06 18:47:14 -04004896 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04004897 * @vport: pointer to a virtual N_Port data structure.
4898 *
4899 * This routine is the actual handler function that processes an ELS timeout
4900 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4901 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4902 * invoking the lpfc_sli_issue_abort_iotag() routine.
4903 **/
dea31012005-04-17 16:05:31 -05004904void
James Smart2e0fef82007-06-17 19:56:36 -05004905lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004906{
James Smart2e0fef82007-06-17 19:56:36 -05004907 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004908 struct lpfc_sli_ring *pring;
4909 struct lpfc_iocbq *tmp_iocb, *piocb;
4910 IOCB_t *cmd = NULL;
4911 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05004912 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05004913 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05004914 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05004915
James Smart2e0fef82007-06-17 19:56:36 -05004916 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004917 timeout = (uint32_t)(phba->fc_ratov << 1);
4918
4919 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05004920
4921 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4922 cmd = &piocb->iocb;
4923
James Smart2e0fef82007-06-17 19:56:36 -05004924 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
4925 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
4926 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05004927 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004928
4929 if (piocb->vport != vport)
4930 continue;
4931
dea31012005-04-17 16:05:31 -05004932 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05004933 if (pcmd)
4934 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05004935
James Smart92d7f7b2007-06-17 19:56:38 -05004936 if (els_command == ELS_CMD_FARP ||
4937 els_command == ELS_CMD_FARPR ||
4938 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05004939 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05004940
dea31012005-04-17 16:05:31 -05004941 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05004942 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05004943 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05004944 else
dea31012005-04-17 16:05:31 -05004945 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05004946 continue;
4947 }
4948
James Smart2e0fef82007-06-17 19:56:36 -05004949 remote_ID = 0xffffffff;
4950 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05004951 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05004952 else {
4953 struct lpfc_nodelist *ndlp;
4954 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04004955 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05004956 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05004957 }
James Smarte8b62012007-08-02 11:10:09 -04004958 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4959 "0127 ELS timeout Data: x%x x%x x%x "
4960 "x%x\n", els_command,
4961 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04004962 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05004963 }
James Smart2e0fef82007-06-17 19:56:36 -05004964 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04004965
James Smart2e0fef82007-06-17 19:56:36 -05004966 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
4967 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05004968}
4969
James Smarte59058c2008-08-24 21:49:00 -04004970/**
James Smart3621a712009-04-06 18:47:14 -04004971 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04004972 * @vport: pointer to a host virtual N_Port data structure.
4973 *
4974 * This routine is used to clean up all the outstanding ELS commands on a
4975 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
4976 * routine. After that, it walks the ELS transmit queue to remove all the
4977 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
4978 * the IOCBs with a non-NULL completion callback function, the callback
4979 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
4980 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
4981 * callback function, the IOCB will simply be released. Finally, it walks
4982 * the ELS transmit completion queue to issue an abort IOCB to any transmit
4983 * completion queue IOCB that is associated with the @vport and is not
4984 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
4985 * part of the discovery state machine) out to HBA by invoking the
4986 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
4987 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
4988 * the IOCBs are aborted when this function returns.
4989 **/
dea31012005-04-17 16:05:31 -05004990void
James Smart2e0fef82007-06-17 19:56:36 -05004991lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004992{
James Smart2534ba72007-04-25 09:52:20 -04004993 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05004994 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04004995 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05004996 struct lpfc_iocbq *tmp_iocb, *piocb;
4997 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004998
4999 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005000
James Smart2e0fef82007-06-17 19:56:36 -05005001 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005002 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5003 cmd = &piocb->iocb;
5004
5005 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5006 continue;
5007 }
5008
5009 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005010 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5011 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5012 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5013 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005014 continue;
dea31012005-04-17 16:05:31 -05005015
James Smart2e0fef82007-06-17 19:56:36 -05005016 if (piocb->vport != vport)
5017 continue;
5018
James Smart2534ba72007-04-25 09:52:20 -04005019 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005020 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005021 }
5022
5023 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005024 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5025 continue;
5026 }
dea31012005-04-17 16:05:31 -05005027
James Smart2e0fef82007-06-17 19:56:36 -05005028 if (piocb->vport != vport)
5029 continue;
5030
James Smart07951072007-04-25 09:51:38 -04005031 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005032 }
James Smart2e0fef82007-06-17 19:56:36 -05005033 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005034
James Smarta257bf92009-04-06 18:48:10 -04005035 /* Cancell all the IOCBs from the completions list */
5036 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5037 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005038
dea31012005-04-17 16:05:31 -05005039 return;
5040}
5041
James Smarte59058c2008-08-24 21:49:00 -04005042/**
James Smart3621a712009-04-06 18:47:14 -04005043 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005044 * @phba: pointer to lpfc hba data structure.
5045 *
5046 * This routine is used to clean up all the outstanding ELS commands on a
5047 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5048 * routine. After that, it walks the ELS transmit queue to remove all the
5049 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5050 * the IOCBs with the completion callback function associated, the callback
5051 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5052 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5053 * callback function associated, the IOCB will simply be released. Finally,
5054 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5055 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5056 * management plane IOCBs that are not part of the discovery state machine)
5057 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5058 **/
James Smart549e55c2007-08-02 11:09:51 -04005059void
5060lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5061{
5062 LIST_HEAD(completions);
5063 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5064 struct lpfc_iocbq *tmp_iocb, *piocb;
5065 IOCB_t *cmd = NULL;
5066
5067 lpfc_fabric_abort_hba(phba);
5068 spin_lock_irq(&phba->hbalock);
5069 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5070 cmd = &piocb->iocb;
5071 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5072 continue;
5073 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5074 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5075 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5076 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5077 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5078 continue;
5079 list_move_tail(&piocb->list, &completions);
5080 pring->txq_cnt--;
5081 }
5082 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5083 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5084 continue;
5085 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5086 }
5087 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005088
5089 /* Cancel all the IOCBs from the completions list */
5090 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5091 IOERR_SLI_ABORTED);
5092
James Smart549e55c2007-08-02 11:09:51 -04005093 return;
5094}
5095
James Smarte59058c2008-08-24 21:49:00 -04005096/**
James Smart3621a712009-04-06 18:47:14 -04005097 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005098 * @phba: Pointer to hba context object.
5099 * @cmdiocbp: Pointer to command iocb which reported error.
5100 * @rspiocbp: Pointer to response iocb which reported error.
5101 *
5102 * This function sends an event when there is an ELS command
5103 * failure.
5104 **/
5105void
5106lpfc_send_els_failure_event(struct lpfc_hba *phba,
5107 struct lpfc_iocbq *cmdiocbp,
5108 struct lpfc_iocbq *rspiocbp)
5109{
5110 struct lpfc_vport *vport = cmdiocbp->vport;
5111 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5112 struct lpfc_lsrjt_event lsrjt_event;
5113 struct lpfc_fabric_event_header fabric_event;
5114 struct ls_rjt stat;
5115 struct lpfc_nodelist *ndlp;
5116 uint32_t *pcmd;
5117
5118 ndlp = cmdiocbp->context1;
5119 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5120 return;
5121
5122 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5123 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5124 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5125 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5126 sizeof(struct lpfc_name));
5127 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5128 sizeof(struct lpfc_name));
5129 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5130 cmdiocbp->context2)->virt);
5131 lsrjt_event.command = *pcmd;
5132 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5133 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5134 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5135 fc_host_post_vendor_event(shost,
5136 fc_get_event_number(),
5137 sizeof(lsrjt_event),
5138 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005139 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005140 return;
5141 }
5142 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5143 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5144 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5145 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5146 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5147 else
5148 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5149 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5150 sizeof(struct lpfc_name));
5151 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5152 sizeof(struct lpfc_name));
5153 fc_host_post_vendor_event(shost,
5154 fc_get_event_number(),
5155 sizeof(fabric_event),
5156 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005157 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005158 return;
5159 }
5160
5161}
5162
5163/**
James Smart3621a712009-04-06 18:47:14 -04005164 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005165 * @vport: Pointer to vport object.
5166 * @ndlp: Pointer FC node object.
5167 * @cmd: ELS command code.
5168 *
5169 * This function posts an event when there is an incoming
5170 * unsolicited ELS command.
5171 **/
5172static void
5173lpfc_send_els_event(struct lpfc_vport *vport,
5174 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005175 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005176{
James Smartddcc50f2008-12-04 22:38:46 -05005177 struct lpfc_els_event_header *els_data = NULL;
5178 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005179 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5180
James Smartddcc50f2008-12-04 22:38:46 -05005181 if (*payload == ELS_CMD_LOGO) {
5182 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5183 if (!logo_data) {
5184 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5185 "0148 Failed to allocate memory "
5186 "for LOGO event\n");
5187 return;
5188 }
5189 els_data = &logo_data->header;
5190 } else {
5191 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5192 GFP_KERNEL);
5193 if (!els_data) {
5194 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5195 "0149 Failed to allocate memory "
5196 "for ELS event\n");
5197 return;
5198 }
5199 }
5200 els_data->event_type = FC_REG_ELS_EVENT;
5201 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005202 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005203 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005204 break;
5205 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005206 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005207 break;
5208 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005209 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5210 break;
5211 case ELS_CMD_LOGO:
5212 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5213 /* Copy the WWPN in the LOGO payload */
5214 memcpy(logo_data->logo_wwpn, &payload[2],
5215 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005216 break;
5217 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005218 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005219 return;
5220 }
James Smartddcc50f2008-12-04 22:38:46 -05005221 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5222 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5223 if (*payload == ELS_CMD_LOGO) {
5224 fc_host_post_vendor_event(shost,
5225 fc_get_event_number(),
5226 sizeof(struct lpfc_logo_event),
5227 (char *)logo_data,
5228 LPFC_NL_VENDOR_ID);
5229 kfree(logo_data);
5230 } else {
5231 fc_host_post_vendor_event(shost,
5232 fc_get_event_number(),
5233 sizeof(struct lpfc_els_event_header),
5234 (char *)els_data,
5235 LPFC_NL_VENDOR_ID);
5236 kfree(els_data);
5237 }
James Smartea2151b2008-09-07 11:52:10 -04005238
5239 return;
5240}
5241
5242
5243/**
James Smart3621a712009-04-06 18:47:14 -04005244 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005245 * @phba: pointer to lpfc hba data structure.
5246 * @pring: pointer to a SLI ring.
5247 * @vport: pointer to a host virtual N_Port data structure.
5248 * @elsiocb: pointer to lpfc els command iocb data structure.
5249 *
5250 * This routine is used for processing the IOCB associated with a unsolicited
5251 * event. It first determines whether there is an existing ndlp that matches
5252 * the DID from the unsolicited IOCB. If not, it will create a new one with
5253 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5254 * IOCB is then used to invoke the proper routine and to set up proper state
5255 * of the discovery state machine.
5256 **/
James Smarted957682007-06-17 19:56:37 -05005257static void
5258lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005259 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005260{
James Smart87af33f2007-10-27 13:37:43 -04005261 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005262 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005263 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005264 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005265 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005266 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005267
James Smarte47c9092008-02-08 18:49:26 -05005268 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005269 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005270
dea31012005-04-17 16:05:31 -05005271 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005272 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5273 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005274 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005275 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005276
James Smart858c9f62007-06-17 19:56:39 -05005277 did = icmd->un.rcvels.remoteID;
5278 if (icmd->ulpStatus) {
5279 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5280 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5281 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005282 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005283 }
dea31012005-04-17 16:05:31 -05005284
5285 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005286 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005287 goto dropit;
dea31012005-04-17 16:05:31 -05005288
James Smart92d7f7b2007-06-17 19:56:38 -05005289 /* Ignore traffic recevied during vport shutdown. */
5290 if (vport->load_flag & FC_UNLOADING)
5291 goto dropit;
5292
James Smart2e0fef82007-06-17 19:56:36 -05005293 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005294 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005295 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005296 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005297 if (!ndlp)
dea31012005-04-17 16:05:31 -05005298 goto dropit;
dea31012005-04-17 16:05:31 -05005299
James Smart2e0fef82007-06-17 19:56:36 -05005300 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005301 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005302 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005303 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005304 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005305 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5306 ndlp = lpfc_enable_node(vport, ndlp,
5307 NLP_STE_UNUSED_NODE);
5308 if (!ndlp)
5309 goto dropit;
5310 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5311 newnode = 1;
5312 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5313 ndlp->nlp_type |= NLP_FABRIC;
5314 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5315 /* This is similar to the new node path */
5316 ndlp = lpfc_nlp_get(ndlp);
5317 if (!ndlp)
5318 goto dropit;
5319 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5320 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005321 }
dea31012005-04-17 16:05:31 -05005322
5323 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005324
James Smart329f9bc2007-04-25 09:53:01 -04005325 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005326 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005327
5328 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5329 cmd &= ELS_CMD_MASK;
5330 }
5331 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5333 "0112 ELS command x%x received from NPORT x%x "
5334 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005335 switch (cmd) {
5336 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5338 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5339 did, vport->port_state, ndlp->nlp_flag);
5340
dea31012005-04-17 16:05:31 -05005341 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005342 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5343
James Smartddcc50f2008-12-04 22:38:46 -05005344 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005345 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005346 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5347 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5348 rjt_err = LSRJT_UNABLE_TPC;
5349 break;
5350 }
5351 /* We get here, and drop thru, if we are PT2PT with
5352 * another NPort and the other side has initiated
5353 * the PLOGI before responding to our FLOGI.
5354 */
dea31012005-04-17 16:05:31 -05005355 }
James Smart87af33f2007-10-27 13:37:43 -04005356
5357 shost = lpfc_shost_from_vport(vport);
5358 spin_lock_irq(shost->host_lock);
5359 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5360 spin_unlock_irq(shost->host_lock);
5361
James Smart2e0fef82007-06-17 19:56:36 -05005362 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5363 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005364
dea31012005-04-17 16:05:31 -05005365 break;
5366 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005367 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5368 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5369 did, vport->port_state, ndlp->nlp_flag);
5370
dea31012005-04-17 16:05:31 -05005371 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005372 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005373 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005374 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005375 break;
5376 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005377 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5378 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5379 did, vport->port_state, ndlp->nlp_flag);
5380
dea31012005-04-17 16:05:31 -05005381 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005382 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005383 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005384 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005385 break;
5386 }
James Smart2e0fef82007-06-17 19:56:36 -05005387 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005388 break;
5389 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005390 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5391 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5392 did, vport->port_state, ndlp->nlp_flag);
5393
dea31012005-04-17 16:05:31 -05005394 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005395 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005396 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005397 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005398 break;
5399 }
James Smart2e0fef82007-06-17 19:56:36 -05005400 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005401 break;
5402 case ELS_CMD_RSCN:
5403 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005404 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005405 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005406 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005407 break;
5408 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5410 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5411 did, vport->port_state, ndlp->nlp_flag);
5412
James Smartddcc50f2008-12-04 22:38:46 -05005413 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005414 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005415 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005416 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005417 break;
5418 }
James Smart2e0fef82007-06-17 19:56:36 -05005419 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5420 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005421 break;
5422 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005423 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5424 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5425 did, vport->port_state, ndlp->nlp_flag);
5426
dea31012005-04-17 16:05:31 -05005427 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005428 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005429 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005430 break;
5431 }
James Smart2e0fef82007-06-17 19:56:36 -05005432 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5433 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005434 break;
5435 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005436 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5437 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5438 did, vport->port_state, ndlp->nlp_flag);
5439
dea31012005-04-17 16:05:31 -05005440 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005441 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005442 break;
5443 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005444 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5445 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5446 did, vport->port_state, ndlp->nlp_flag);
5447
dea31012005-04-17 16:05:31 -05005448 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005449 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005450 break;
5451 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005452 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5453 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5454 did, vport->port_state, ndlp->nlp_flag);
5455
dea31012005-04-17 16:05:31 -05005456 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005457 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005458 break;
dea31012005-04-17 16:05:31 -05005459 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5461 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5462 did, vport->port_state, ndlp->nlp_flag);
5463
dea31012005-04-17 16:05:31 -05005464 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005465 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005466 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005467 break;
5468 }
James Smart2e0fef82007-06-17 19:56:36 -05005469 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005470 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005471 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005472 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5473 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5474 did, vport->port_state, ndlp->nlp_flag);
5475
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005476 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005477 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005478 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005479 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005480 break;
5481 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5483 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5484 did, vport->port_state, ndlp->nlp_flag);
5485
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005486 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005487 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005488 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005489 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005490 break;
5491 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005492 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5493 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5494 did, vport->port_state, ndlp->nlp_flag);
5495
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005496 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005497 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005498 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005499 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005500 break;
dea31012005-04-17 16:05:31 -05005501 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5503 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5504 did, vport->port_state, ndlp->nlp_flag);
5505
dea31012005-04-17 16:05:31 -05005506 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005507 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005508 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005509 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005510 break;
5511 default:
James Smart858c9f62007-06-17 19:56:39 -05005512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5513 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5514 cmd, did, vport->port_state);
5515
dea31012005-04-17 16:05:31 -05005516 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005517 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005518
5519 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005520 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5521 "0115 Unknown ELS command x%x "
5522 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005523 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005524 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005525 break;
5526 }
5527
5528 /* check if need to LS_RJT received ELS cmd */
5529 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005530 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005531 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005532 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005533 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5534 NULL);
dea31012005-04-17 16:05:31 -05005535 }
5536
James Smartd7c255b2008-08-24 21:50:00 -04005537 lpfc_nlp_put(elsiocb->context1);
5538 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005539 return;
5540
5541dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005542 if (vport && !(vport->load_flag & FC_UNLOADING))
5543 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04005544 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005545 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04005546 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04005547 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005548 phba->fc_stat.elsRcvDrop++;
5549}
5550
James Smarte59058c2008-08-24 21:49:00 -04005551/**
James Smart3621a712009-04-06 18:47:14 -04005552 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005553 * @phba: pointer to lpfc hba data structure.
5554 * @vpi: host virtual N_Port identifier.
5555 *
5556 * This routine finds a vport on a HBA (referred by @phba) through a
5557 * @vpi. The function walks the HBA's vport list and returns the address
5558 * of the vport with the matching @vpi.
5559 *
5560 * Return code
5561 * NULL - No vport with the matching @vpi found
5562 * Otherwise - Address to the vport with the matching @vpi.
5563 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005564static struct lpfc_vport *
5565lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5566{
5567 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005568 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005569
James Smart549e55c2007-08-02 11:09:51 -04005570 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005571 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005572 if (vport->vpi == vpi) {
5573 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005574 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005575 }
James Smart92d7f7b2007-06-17 19:56:38 -05005576 }
James Smart549e55c2007-08-02 11:09:51 -04005577 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005578 return NULL;
5579}
James Smarted957682007-06-17 19:56:37 -05005580
James Smarte59058c2008-08-24 21:49:00 -04005581/**
James Smart3621a712009-04-06 18:47:14 -04005582 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005583 * @phba: pointer to lpfc hba data structure.
5584 * @pring: pointer to a SLI ring.
5585 * @elsiocb: pointer to lpfc els iocb data structure.
5586 *
5587 * This routine is used to process an unsolicited event received from a SLI
5588 * (Service Level Interface) ring. The actual processing of the data buffer
5589 * associated with the unsolicited event is done by invoking the routine
5590 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5591 * SLI ring on which the unsolicited event was received.
5592 **/
James Smarted957682007-06-17 19:56:37 -05005593void
5594lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5595 struct lpfc_iocbq *elsiocb)
5596{
5597 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005598 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005599 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005600 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5601 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005602
James Smartd7c255b2008-08-24 21:50:00 -04005603 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005604 elsiocb->context2 = NULL;
5605 elsiocb->context3 = NULL;
5606
5607 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5608 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5609 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5610 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005611 phba->fc_stat.NoRcvBuf++;
5612 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005613 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005614 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005615 return;
5616 }
5617
James Smart92d7f7b2007-06-17 19:56:38 -05005618 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5619 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5620 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5621 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5622 vport = phba->pport;
5623 else {
5624 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
5625 vport = lpfc_find_vport_by_vpid(phba, vpi);
5626 }
5627 }
James Smart7f5f3d02008-02-08 18:50:14 -05005628 /* If there are no BDEs associated
5629 * with this IOCB, there is nothing to do.
5630 */
James Smarted957682007-06-17 19:56:37 -05005631 if (icmd->ulpBdeCount == 0)
5632 return;
5633
James Smart7f5f3d02008-02-08 18:50:14 -05005634 /* type of ELS cmd is first 32bit word
5635 * in packet
5636 */
James Smarted957682007-06-17 19:56:37 -05005637 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005638 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005639 } else {
5640 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5641 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005642 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5643 paddr);
James Smarted957682007-06-17 19:56:37 -05005644 }
5645
James Smart92d7f7b2007-06-17 19:56:38 -05005646 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5647 /*
5648 * The different unsolicited event handlers would tell us
5649 * if they are done with "mp" by setting context2 to NULL.
5650 */
dea31012005-04-17 16:05:31 -05005651 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005652 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5653 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005654 }
James Smarted957682007-06-17 19:56:37 -05005655
5656 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005657 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005658 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005659 elsiocb->context2 = bdeBuf2;
5660 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005661 /* free mp if we are done with it */
5662 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005663 lpfc_in_buf_free(phba, elsiocb->context2);
5664 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005665 }
dea31012005-04-17 16:05:31 -05005666 }
dea31012005-04-17 16:05:31 -05005667}
James Smart92d7f7b2007-06-17 19:56:38 -05005668
James Smarte59058c2008-08-24 21:49:00 -04005669/**
James Smart3621a712009-04-06 18:47:14 -04005670 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005671 * @phba: pointer to lpfc hba data structure.
5672 * @vport: pointer to a virtual N_Port data structure.
5673 *
5674 * This routine issues a Port Login (PLOGI) to the Name Server with
5675 * State Change Request (SCR) for a @vport. This routine will create an
5676 * ndlp for the Name Server associated to the @vport if such node does
5677 * not already exist. The PLOGI to Name Server is issued by invoking the
5678 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5679 * (FDMI) is configured to the @vport, a FDMI node will be created and
5680 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5681 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005682void
5683lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5684{
5685 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5686
5687 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5688 if (!ndlp) {
5689 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5690 if (!ndlp) {
5691 if (phba->fc_topology == TOPOLOGY_LOOP) {
5692 lpfc_disc_start(vport);
5693 return;
5694 }
5695 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005696 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5697 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005698 return;
5699 }
5700 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005701 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5702 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5703 if (!ndlp) {
5704 if (phba->fc_topology == TOPOLOGY_LOOP) {
5705 lpfc_disc_start(vport);
5706 return;
5707 }
5708 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5709 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5710 "0348 NameServer login: node freed\n");
5711 return;
5712 }
James Smart92d7f7b2007-06-17 19:56:38 -05005713 }
James Smart58da1ff2008-04-07 10:15:56 -04005714 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005715
5716 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5717
5718 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5719 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005720 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5721 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005722 return;
5723 }
5724
James Smart3de2a652007-08-02 11:09:59 -04005725 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005726 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5727 GFP_KERNEL);
5728 if (ndlp_fdmi) {
5729 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5730 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005731 lpfc_nlp_set_state(vport, ndlp_fdmi,
5732 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005733 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5734 0);
5735 }
5736 }
5737 return;
5738}
5739
James Smarte59058c2008-08-24 21:49:00 -04005740/**
James Smart3621a712009-04-06 18:47:14 -04005741 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005742 * @phba: pointer to lpfc hba data structure.
5743 * @pmb: pointer to the driver internal queue element for mailbox command.
5744 *
5745 * This routine is the completion callback function to register new vport
5746 * mailbox command. If the new vport mailbox command completes successfully,
5747 * the fabric registration login shall be performed on physical port (the
5748 * new vport created is actually a physical port, with VPI 0) or the port
5749 * login to Name Server for State Change Request (SCR) will be performed
5750 * on virtual port (real virtual port, with VPI greater than 0).
5751 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005752static void
5753lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5754{
5755 struct lpfc_vport *vport = pmb->vport;
5756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5757 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04005758 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05005759
James Smart09372822008-01-11 01:52:54 -05005760 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005761 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005762 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005763
5764 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04005765 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5766 "0915 Register VPI failed: 0x%x\n",
5767 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05005768
5769 switch (mb->mbxStatus) {
5770 case 0x11: /* unsupported feature */
5771 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05005772 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05005773 /* giving up on vport registration */
5774 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5775 spin_lock_irq(shost->host_lock);
5776 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5777 spin_unlock_irq(shost->host_lock);
5778 lpfc_can_disctmo(vport);
5779 break;
5780 default:
5781 /* Try to recover from this error */
5782 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005783 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005784 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005785 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05005786 if (vport->port_type == LPFC_PHYSICAL_PORT)
5787 lpfc_initial_flogi(vport);
5788 else
5789 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005790 break;
5791 }
5792
5793 } else {
5794 if (vport == phba->pport)
5795 lpfc_issue_fabric_reglogin(vport);
5796 else
5797 lpfc_do_scr_ns_plogi(phba, vport);
5798 }
James Smartfa4066b2008-01-11 01:53:27 -05005799
5800 /* Now, we decrement the ndlp reference count held for this
5801 * callback function
5802 */
5803 lpfc_nlp_put(ndlp);
5804
James Smart92d7f7b2007-06-17 19:56:38 -05005805 mempool_free(pmb, phba->mbox_mem_pool);
5806 return;
5807}
5808
James Smarte59058c2008-08-24 21:49:00 -04005809/**
James Smart3621a712009-04-06 18:47:14 -04005810 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04005811 * @phba: pointer to lpfc hba data structure.
5812 * @vport: pointer to a host virtual N_Port data structure.
5813 * @ndlp: pointer to a node-list data structure.
5814 *
5815 * This routine registers the @vport as a new virtual port with a HBA.
5816 * It is done through a registering vpi mailbox command.
5817 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005818static void
James Smart92d7f7b2007-06-17 19:56:38 -05005819lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5820 struct lpfc_nodelist *ndlp)
5821{
James Smart09372822008-01-11 01:52:54 -05005822 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005823 LPFC_MBOXQ_t *mbox;
5824
5825 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5826 if (mbox) {
5827 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
5828 mbox->vport = vport;
5829 mbox->context2 = lpfc_nlp_get(ndlp);
5830 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04005831 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005832 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05005833 /* mailbox command not success, decrement ndlp
5834 * reference count for this command
5835 */
5836 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005837 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05005838
James Smarte8b62012007-08-02 11:10:09 -04005839 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5840 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05005841 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005842 }
5843 } else {
James Smarte8b62012007-08-02 11:10:09 -04005844 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5845 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05005846 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005847 }
James Smartfa4066b2008-01-11 01:53:27 -05005848 return;
5849
5850mbox_err_exit:
5851 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5852 spin_lock_irq(shost->host_lock);
5853 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5854 spin_unlock_irq(shost->host_lock);
5855 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005856}
5857
James Smarte59058c2008-08-24 21:49:00 -04005858/**
James Smart3621a712009-04-06 18:47:14 -04005859 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04005860 * @phba: pointer to lpfc hba data structure.
5861 * @cmdiocb: pointer to lpfc command iocb data structure.
5862 * @rspiocb: pointer to lpfc response iocb data structure.
5863 *
5864 * This routine is the completion callback function to a Fabric Discover
5865 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5866 * single threaded, each FDISC completion callback function will reset
5867 * the discovery timer for all vports such that the timers will not get
5868 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5869 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5870 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5871 * assigned to the vport has been changed with the completion of the FDISC
5872 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5873 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5874 * routine is invoked to register new vport with the HBA. Otherwise, the
5875 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5876 * Server for State Change Request (SCR).
5877 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005878static void
5879lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5880 struct lpfc_iocbq *rspiocb)
5881{
5882 struct lpfc_vport *vport = cmdiocb->vport;
5883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5884 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5885 struct lpfc_nodelist *np;
5886 struct lpfc_nodelist *next_np;
5887 IOCB_t *irsp = &rspiocb->iocb;
5888 struct lpfc_iocbq *piocb;
5889
James Smarte8b62012007-08-02 11:10:09 -04005890 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5891 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5892 irsp->ulpStatus, irsp->un.ulpWord[4],
5893 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05005894 /* Since all FDISCs are being single threaded, we
5895 * must reset the discovery timer for ALL vports
5896 * waiting to send FDISC when one completes.
5897 */
5898 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5899 lpfc_set_disctmo(piocb->vport);
5900 }
5901
James Smart858c9f62007-06-17 19:56:39 -05005902 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5903 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
5904 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
5905
James Smart92d7f7b2007-06-17 19:56:38 -05005906 if (irsp->ulpStatus) {
5907 /* Check for retry */
5908 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
5909 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05005910 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04005911 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04005912 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04005913 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04005914 goto fdisc_failed;
5915 }
James Smart92d7f7b2007-06-17 19:56:38 -05005916 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
5917 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05005918 lpfc_nlp_put(ndlp);
5919 /* giving up on FDISC. Cancel discovery timer */
5920 lpfc_can_disctmo(vport);
James Smartd7c255b2008-08-24 21:50:00 -04005921 spin_lock_irq(shost->host_lock);
5922 vport->fc_flag |= FC_FABRIC;
5923 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
5924 vport->fc_flag |= FC_PUBLIC_LOOP;
5925 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005926
James Smartd7c255b2008-08-24 21:50:00 -04005927 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
5928 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
5929 if ((vport->fc_prevDID != vport->fc_myDID) &&
5930 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
5931 /* If our NportID changed, we need to ensure all
5932 * remaining NPORTs get unreg_login'ed so we can
5933 * issue unreg_vpi.
5934 */
5935 list_for_each_entry_safe(np, next_np,
5936 &vport->fc_nodes, nlp_listp) {
5937 if (!NLP_CHK_NODE_ACT(ndlp) ||
5938 (np->nlp_state != NLP_STE_NPR_NODE) ||
5939 !(np->nlp_flag & NLP_NPR_ADISC))
5940 continue;
James Smart09372822008-01-11 01:52:54 -05005941 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04005942 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05005943 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04005944 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05005945 }
James Smartd7c255b2008-08-24 21:50:00 -04005946 lpfc_mbx_unreg_vpi(vport);
5947 spin_lock_irq(shost->host_lock);
5948 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5949 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005950 }
5951
James Smartd7c255b2008-08-24 21:50:00 -04005952 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
5953 lpfc_register_new_vport(phba, vport, ndlp);
5954 else
5955 lpfc_do_scr_ns_plogi(phba, vport);
5956 goto out;
5957fdisc_failed:
5958 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5959 /* Cancel discovery timer */
5960 lpfc_can_disctmo(vport);
5961 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005962out:
5963 lpfc_els_free_iocb(phba, cmdiocb);
5964}
5965
James Smarte59058c2008-08-24 21:49:00 -04005966/**
James Smart3621a712009-04-06 18:47:14 -04005967 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04005968 * @vport: pointer to a virtual N_Port data structure.
5969 * @ndlp: pointer to a node-list data structure.
5970 * @retry: number of retries to the command IOCB.
5971 *
5972 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
5973 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
5974 * routine to issue the IOCB, which makes sure only one outstanding fabric
5975 * IOCB will be sent off HBA at any given time.
5976 *
5977 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5978 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5979 * will be stored into the context1 field of the IOCB for the completion
5980 * callback function to the FDISC ELS command.
5981 *
5982 * Return code
5983 * 0 - Successfully issued fdisc iocb command
5984 * 1 - Failed to issue fdisc iocb command
5985 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005986static int
James Smart92d7f7b2007-06-17 19:56:38 -05005987lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5988 uint8_t retry)
5989{
5990 struct lpfc_hba *phba = vport->phba;
5991 IOCB_t *icmd;
5992 struct lpfc_iocbq *elsiocb;
5993 struct serv_parm *sp;
5994 uint8_t *pcmd;
5995 uint16_t cmdsize;
5996 int did = ndlp->nlp_DID;
5997 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05005998
5999 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6000 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6001 ELS_CMD_FDISC);
6002 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006003 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006004 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6005 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006006 return 1;
6007 }
6008
6009 icmd = &elsiocb->iocb;
6010 icmd->un.elsreq64.myID = 0;
6011 icmd->un.elsreq64.fl = 1;
6012
6013 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6014 icmd->ulpCt_h = 1;
6015 icmd->ulpCt_l = 0;
6016
6017 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6018 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6019 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6020 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6021 sp = (struct serv_parm *) pcmd;
6022 /* Setup CSPs accordingly for Fabric */
6023 sp->cmn.e_d_tov = 0;
6024 sp->cmn.w2.r_a_tov = 0;
6025 sp->cls1.classValid = 0;
6026 sp->cls2.seqDelivery = 1;
6027 sp->cls3.seqDelivery = 1;
6028
6029 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6030 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6031 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6032 pcmd += sizeof(uint32_t); /* Port Name */
6033 memcpy(pcmd, &vport->fc_portname, 8);
6034 pcmd += sizeof(uint32_t); /* Node Name */
6035 pcmd += sizeof(uint32_t); /* Node Name */
6036 memcpy(pcmd, &vport->fc_nodename, 8);
6037
6038 lpfc_set_disctmo(vport);
6039
6040 phba->fc_stat.elsXmitFDISC++;
6041 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6042
James Smart858c9f62007-06-17 19:56:39 -05006043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6044 "Issue FDISC: did:x%x",
6045 did, 0, 0);
6046
James Smart92d7f7b2007-06-17 19:56:38 -05006047 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6048 if (rc == IOCB_ERROR) {
6049 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006050 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006051 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6052 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006053 return 1;
6054 }
6055 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6056 vport->port_state = LPFC_FDISC;
6057 return 0;
6058}
6059
James Smarte59058c2008-08-24 21:49:00 -04006060/**
James Smart3621a712009-04-06 18:47:14 -04006061 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006062 * @phba: pointer to lpfc hba data structure.
6063 * @cmdiocb: pointer to lpfc command iocb data structure.
6064 * @rspiocb: pointer to lpfc response iocb data structure.
6065 *
6066 * This routine is the completion callback function to the issuing of a LOGO
6067 * ELS command off a vport. It frees the command IOCB and then decrement the
6068 * reference count held on ndlp for this completion function, indicating that
6069 * the reference to the ndlp is no long needed. Note that the
6070 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6071 * callback function and an additional explicit ndlp reference decrementation
6072 * will trigger the actual release of the ndlp.
6073 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006074static void
6075lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6076 struct lpfc_iocbq *rspiocb)
6077{
6078 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006079 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006080 struct lpfc_nodelist *ndlp;
6081 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006082
6083 irsp = &rspiocb->iocb;
6084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6085 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6086 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006087
6088 lpfc_els_free_iocb(phba, cmdiocb);
6089 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006090
6091 /* Trigger the release of the ndlp after logo */
6092 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006093}
6094
James Smarte59058c2008-08-24 21:49:00 -04006095/**
James Smart3621a712009-04-06 18:47:14 -04006096 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006097 * @vport: pointer to a virtual N_Port data structure.
6098 * @ndlp: pointer to a node-list data structure.
6099 *
6100 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6101 *
6102 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6103 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6104 * will be stored into the context1 field of the IOCB for the completion
6105 * callback function to the LOGO ELS command.
6106 *
6107 * Return codes
6108 * 0 - Successfully issued logo off the @vport
6109 * 1 - Failed to issue logo off the @vport
6110 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006111int
6112lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6113{
6114 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6115 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006116 IOCB_t *icmd;
6117 struct lpfc_iocbq *elsiocb;
6118 uint8_t *pcmd;
6119 uint16_t cmdsize;
6120
6121 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6122 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6123 ELS_CMD_LOGO);
6124 if (!elsiocb)
6125 return 1;
6126
6127 icmd = &elsiocb->iocb;
6128 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6129 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6130 pcmd += sizeof(uint32_t);
6131
6132 /* Fill in LOGO payload */
6133 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6134 pcmd += sizeof(uint32_t);
6135 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6136
James Smart858c9f62007-06-17 19:56:39 -05006137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6138 "Issue LOGO npiv did:x%x flg:x%x",
6139 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6140
James Smart92d7f7b2007-06-17 19:56:38 -05006141 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6142 spin_lock_irq(shost->host_lock);
6143 ndlp->nlp_flag |= NLP_LOGO_SND;
6144 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006145 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6146 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006147 spin_lock_irq(shost->host_lock);
6148 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6149 spin_unlock_irq(shost->host_lock);
6150 lpfc_els_free_iocb(phba, elsiocb);
6151 return 1;
6152 }
6153 return 0;
6154}
6155
James Smarte59058c2008-08-24 21:49:00 -04006156/**
James Smart3621a712009-04-06 18:47:14 -04006157 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006158 * @ptr: holder for the timer function associated data.
6159 *
6160 * This routine is invoked by the fabric iocb block timer after
6161 * timeout. It posts the fabric iocb block timeout event by setting the
6162 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6163 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6164 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6165 * posted event WORKER_FABRIC_BLOCK_TMO.
6166 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006167void
6168lpfc_fabric_block_timeout(unsigned long ptr)
6169{
6170 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6171 unsigned long iflags;
6172 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006173
James Smart92d7f7b2007-06-17 19:56:38 -05006174 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6175 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6176 if (!tmo_posted)
6177 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6178 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6179
James Smart5e9d9b82008-06-14 22:52:53 -04006180 if (!tmo_posted)
6181 lpfc_worker_wake_up(phba);
6182 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006183}
6184
James Smarte59058c2008-08-24 21:49:00 -04006185/**
James Smart3621a712009-04-06 18:47:14 -04006186 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006187 * @phba: pointer to lpfc hba data structure.
6188 *
6189 * This routine issues one fabric iocb from the driver internal list to
6190 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6191 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6192 * remove one pending fabric iocb from the driver internal list and invokes
6193 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6194 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006195static void
6196lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6197{
6198 struct lpfc_iocbq *iocb;
6199 unsigned long iflags;
6200 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006201 IOCB_t *cmd;
6202
6203repeat:
6204 iocb = NULL;
6205 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006206 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006207 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6208 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6209 list);
6210 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006211 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006212 atomic_inc(&phba->fabric_iocb_count);
6213 }
6214 spin_unlock_irqrestore(&phba->hbalock, iflags);
6215 if (iocb) {
6216 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6217 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6218 iocb->iocb_flag |= LPFC_IO_FABRIC;
6219
James Smart858c9f62007-06-17 19:56:39 -05006220 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6221 "Fabric sched1: ste:x%x",
6222 iocb->vport->port_state, 0, 0);
6223
James Smart3772a992009-05-22 14:50:54 -04006224 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006225
6226 if (ret == IOCB_ERROR) {
6227 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6228 iocb->fabric_iocb_cmpl = NULL;
6229 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6230 cmd = &iocb->iocb;
6231 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6232 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6233 iocb->iocb_cmpl(phba, iocb, iocb);
6234
6235 atomic_dec(&phba->fabric_iocb_count);
6236 goto repeat;
6237 }
6238 }
6239
6240 return;
6241}
6242
James Smarte59058c2008-08-24 21:49:00 -04006243/**
James Smart3621a712009-04-06 18:47:14 -04006244 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006245 * @phba: pointer to lpfc hba data structure.
6246 *
6247 * This routine unblocks the issuing fabric iocb command. The function
6248 * will clear the fabric iocb block bit and then invoke the routine
6249 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6250 * from the driver internal fabric iocb list.
6251 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006252void
6253lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6254{
6255 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6256
6257 lpfc_resume_fabric_iocbs(phba);
6258 return;
6259}
6260
James Smarte59058c2008-08-24 21:49:00 -04006261/**
James Smart3621a712009-04-06 18:47:14 -04006262 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006263 * @phba: pointer to lpfc hba data structure.
6264 *
6265 * This routine blocks the issuing fabric iocb for a specified amount of
6266 * time (currently 100 ms). This is done by set the fabric iocb block bit
6267 * and set up a timeout timer for 100ms. When the block bit is set, no more
6268 * fabric iocb will be issued out of the HBA.
6269 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006270static void
6271lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6272{
6273 int blocked;
6274
6275 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006276 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006277 if (!blocked)
6278 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6279
6280 return;
6281}
6282
James Smarte59058c2008-08-24 21:49:00 -04006283/**
James Smart3621a712009-04-06 18:47:14 -04006284 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006285 * @phba: pointer to lpfc hba data structure.
6286 * @cmdiocb: pointer to lpfc command iocb data structure.
6287 * @rspiocb: pointer to lpfc response iocb data structure.
6288 *
6289 * This routine is the callback function that is put to the fabric iocb's
6290 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6291 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6292 * function first restores and invokes the original iocb's callback function
6293 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6294 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6295 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006296static void
6297lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6298 struct lpfc_iocbq *rspiocb)
6299{
6300 struct ls_rjt stat;
6301
6302 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6303 BUG();
6304
6305 switch (rspiocb->iocb.ulpStatus) {
6306 case IOSTAT_NPORT_RJT:
6307 case IOSTAT_FABRIC_RJT:
6308 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6309 lpfc_block_fabric_iocbs(phba);
6310 }
6311 break;
6312
6313 case IOSTAT_NPORT_BSY:
6314 case IOSTAT_FABRIC_BSY:
6315 lpfc_block_fabric_iocbs(phba);
6316 break;
6317
6318 case IOSTAT_LS_RJT:
6319 stat.un.lsRjtError =
6320 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6321 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6322 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6323 lpfc_block_fabric_iocbs(phba);
6324 break;
6325 }
6326
6327 if (atomic_read(&phba->fabric_iocb_count) == 0)
6328 BUG();
6329
6330 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6331 cmdiocb->fabric_iocb_cmpl = NULL;
6332 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6333 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6334
6335 atomic_dec(&phba->fabric_iocb_count);
6336 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006337 /* Post any pending iocbs to HBA */
6338 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006339 }
6340}
6341
James Smarte59058c2008-08-24 21:49:00 -04006342/**
James Smart3621a712009-04-06 18:47:14 -04006343 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006344 * @phba: pointer to lpfc hba data structure.
6345 * @iocb: pointer to lpfc command iocb data structure.
6346 *
6347 * This routine is used as the top-level API for issuing a fabric iocb command
6348 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6349 * function makes sure that only one fabric bound iocb will be outstanding at
6350 * any given time. As such, this function will first check to see whether there
6351 * is already an outstanding fabric iocb on the wire. If so, it will put the
6352 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6353 * issued later. Otherwise, it will issue the iocb on the wire and update the
6354 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6355 *
6356 * Note, this implementation has a potential sending out fabric IOCBs out of
6357 * order. The problem is caused by the construction of the "ready" boolen does
6358 * not include the condition that the internal fabric IOCB list is empty. As
6359 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6360 * ahead of the fabric IOCBs in the internal list.
6361 *
6362 * Return code
6363 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6364 * IOCB_ERROR - failed to issue fabric iocb
6365 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006366static int
James Smart92d7f7b2007-06-17 19:56:38 -05006367lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6368{
6369 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006370 int ready;
6371 int ret;
6372
6373 if (atomic_read(&phba->fabric_iocb_count) > 1)
6374 BUG();
6375
6376 spin_lock_irqsave(&phba->hbalock, iflags);
6377 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6378 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6379
James Smart7f5f3d02008-02-08 18:50:14 -05006380 if (ready)
6381 /* Increment fabric iocb count to hold the position */
6382 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006383 spin_unlock_irqrestore(&phba->hbalock, iflags);
6384 if (ready) {
6385 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6386 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6387 iocb->iocb_flag |= LPFC_IO_FABRIC;
6388
James Smart858c9f62007-06-17 19:56:39 -05006389 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6390 "Fabric sched2: ste:x%x",
6391 iocb->vport->port_state, 0, 0);
6392
James Smart3772a992009-05-22 14:50:54 -04006393 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006394
6395 if (ret == IOCB_ERROR) {
6396 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6397 iocb->fabric_iocb_cmpl = NULL;
6398 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6399 atomic_dec(&phba->fabric_iocb_count);
6400 }
6401 } else {
6402 spin_lock_irqsave(&phba->hbalock, iflags);
6403 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6404 spin_unlock_irqrestore(&phba->hbalock, iflags);
6405 ret = IOCB_SUCCESS;
6406 }
6407 return ret;
6408}
6409
James Smarte59058c2008-08-24 21:49:00 -04006410/**
James Smart3621a712009-04-06 18:47:14 -04006411 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006412 * @vport: pointer to a virtual N_Port data structure.
6413 *
6414 * This routine aborts all the IOCBs associated with a @vport from the
6415 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6416 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6417 * list, removes each IOCB associated with the @vport off the list, set the
6418 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6419 * associated with the IOCB.
6420 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006421static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006422{
6423 LIST_HEAD(completions);
6424 struct lpfc_hba *phba = vport->phba;
6425 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006426
6427 spin_lock_irq(&phba->hbalock);
6428 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6429 list) {
6430
6431 if (piocb->vport != vport)
6432 continue;
6433
6434 list_move_tail(&piocb->list, &completions);
6435 }
6436 spin_unlock_irq(&phba->hbalock);
6437
James Smarta257bf92009-04-06 18:48:10 -04006438 /* Cancel all the IOCBs from the completions list */
6439 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6440 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006441}
6442
James Smarte59058c2008-08-24 21:49:00 -04006443/**
James Smart3621a712009-04-06 18:47:14 -04006444 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006445 * @ndlp: pointer to a node-list data structure.
6446 *
6447 * This routine aborts all the IOCBs associated with an @ndlp from the
6448 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6449 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6450 * list, removes each IOCB associated with the @ndlp off the list, set the
6451 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6452 * associated with the IOCB.
6453 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006454void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6455{
6456 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006457 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006458 struct lpfc_iocbq *tmp_iocb, *piocb;
6459 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006460
6461 spin_lock_irq(&phba->hbalock);
6462 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6463 list) {
6464 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6465
6466 list_move_tail(&piocb->list, &completions);
6467 }
6468 }
6469 spin_unlock_irq(&phba->hbalock);
6470
James Smarta257bf92009-04-06 18:48:10 -04006471 /* Cancel all the IOCBs from the completions list */
6472 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6473 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006474}
6475
James Smarte59058c2008-08-24 21:49:00 -04006476/**
James Smart3621a712009-04-06 18:47:14 -04006477 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006478 * @phba: pointer to lpfc hba data structure.
6479 *
6480 * This routine aborts all the IOCBs currently on the driver internal
6481 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6482 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6483 * list, removes IOCBs off the list, set the status feild to
6484 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6485 * the IOCB.
6486 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006487void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6488{
6489 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006490
6491 spin_lock_irq(&phba->hbalock);
6492 list_splice_init(&phba->fabric_iocb_list, &completions);
6493 spin_unlock_irq(&phba->hbalock);
6494
James Smarta257bf92009-04-06 18:48:10 -04006495 /* Cancel all the IOCBs from the completions list */
6496 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6497 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006498}