blob: ea511d18f0ecaa0621a386056d7f7795822fdc63 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
182 break;
183 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 }
James Smart0c287582009-06-10 17:22:56 -0400192 else
James Smartc8685952009-11-18 15:39:16 -0500193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400194
dea31012005-04-17 16:05:31 -0500195 icmd = &elsiocb->iocb;
196
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 if (pcmd)
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500204
205 INIT_LIST_HEAD(&pcmd->list);
206
207 /* Allocate buffer for response payload */
208 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500210 if (prsp)
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500215 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500216 } else
dea31012005-04-17 16:05:31 -0500217 prsp = NULL;
dea31012005-04-17 16:05:31 -0500218
219 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500221 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500226
227 INIT_LIST_HEAD(&pbuflist->list);
228
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500232 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400236 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500237 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 }
dea31012005-04-17 16:05:31 -0500241 icmd->ulpBdeCount = 1;
242 icmd->ulpLe = 1;
243 icmd->ulpClass = CLASS3;
244
James Smart92d7f7b2007-06-17 19:56:38 -0500245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
247
248 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400249 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 else
255 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500256 }
257
dea31012005-04-17 16:05:31 -0500258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264
265 if (expectRsp) {
266 bpl++;
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
272 }
273
James Smartfa4066b2008-01-11 01:53:27 -0500274 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400275 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500280 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500281 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
283
284 if (prsp) {
285 list_add(&prsp->list, &pcmd->list);
286 }
dea31012005-04-17 16:05:31 -0500287 if (expectRsp) {
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
293 vport->port_state);
dea31012005-04-17 16:05:31 -0500294 } else {
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
300 cmdSize);
dea31012005-04-17 16:05:31 -0500301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return elsiocb;
dea31012005-04-17 16:05:31 -0500303
James Smartfa4066b2008-01-11 01:53:27 -0500304els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500305 if (expectRsp)
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500307 kfree(pbuflist);
308
309els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
311 kfree(prsp);
312
313els_iocb_free_pcmb_exit:
314 kfree(pcmd);
315 lpfc_sli_release_iocbq(phba, elsiocb);
316 return NULL;
317}
dea31012005-04-17 16:05:31 -0500318
James Smarte59058c2008-08-24 21:49:00 -0400319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400321 * @vport: pointer to a host virtual N_Port data structure.
322 *
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
329 * with the @vport.
330 *
331 * Return code
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
334 **/
James Smart3772a992009-05-22 14:50:54 -0400335int
James Smart92d7f7b2007-06-17 19:56:38 -0500336lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337{
338 struct lpfc_hba *phba = vport->phba;
339 LPFC_MBOXQ_t *mbox;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
343 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400344 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400349 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500350 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400354 if (!mbox) {
355 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500356 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400357 }
James Smart92d7f7b2007-06-17 19:56:38 -0500358
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 mbox->vport = vport;
363
James Smart0b727fe2007-10-27 13:37:25 -0400364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400365 if (rc == MBX_NOT_FINISHED) {
366 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400371 if (!mbox) {
372 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400374 }
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400376 if (rc) {
377 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
385 */
James Smart92d7f7b2007-06-17 19:56:38 -0500386 mbox->context2 = lpfc_nlp_get(ndlp);
387
James Smart0b727fe2007-10-27 13:37:25 -0400388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400389 if (rc == MBX_NOT_FINISHED) {
390 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500391 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400392 }
James Smart92d7f7b2007-06-17 19:56:38 -0500393
394 return 0;
395
396fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
399 */
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_put(ndlp);
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
403 kfree(mp);
404fail_free_mbox:
405 mempool_free(mbox, phba->mbox_mem_pool);
406
407fail:
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return -ENXIO;
412}
413
James Smarte59058c2008-08-24 21:49:00 -0400414/**
James Smart6fb120a2009-05-22 14:52:59 -0400415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
417 *
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
420 *
421 * Return code
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
424 **/
425static int
426lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427{
428 struct lpfc_hba *phba = vport->phba;
429 LPFC_MBOXQ_t *mboxq;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
433 int rc = 0;
434
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
438 rc = -ENODEV;
439 goto fail;
440 }
441
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
443 if (!dmabuf) {
444 rc = -ENOMEM;
445 goto fail;
446 }
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
448 if (!dmabuf->virt) {
449 rc = -ENOMEM;
450 goto fail_free_dmabuf;
451 }
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
453 if (!mboxq) {
454 rc = -ENOMEM;
455 goto fail_free_coherent;
456 }
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
465 rc = -ENXIO;
466 goto fail_free_mbox;
467 }
468 return 0;
469
470fail_free_mbox:
471 mempool_free(mboxq, phba->mbox_mem_pool);
472fail_free_coherent:
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
474fail_free_dmabuf:
475 kfree(dmabuf);
476fail:
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
480 return rc;
481}
482
483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 *
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
499 *
500 * Return code
501 * 0 - Success (currently, always return 0)
502 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500503static int
James Smart2e0fef82007-06-17 19:56:36 -0500504lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519
James Smart12265f62010-10-22 11:05:53 -0400520 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500521 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
522
523 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500524 spin_lock_irq(shost->host_lock);
525 vport->fc_flag |= FC_PUBLIC_LOOP;
526 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500527 }
528
James Smart2e0fef82007-06-17 19:56:36 -0500529 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500530 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500531 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500532 ndlp->nlp_class_sup = 0;
533 if (sp->cls1.classValid)
534 ndlp->nlp_class_sup |= FC_COS_CLASS1;
535 if (sp->cls2.classValid)
536 ndlp->nlp_class_sup |= FC_COS_CLASS2;
537 if (sp->cls3.classValid)
538 ndlp->nlp_class_sup |= FC_COS_CLASS3;
539 if (sp->cls4.classValid)
540 ndlp->nlp_class_sup |= FC_COS_CLASS4;
541 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
542 sp->cmn.bbRcvSizeLsb;
543 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
544
James Smart92d7f7b2007-06-17 19:56:38 -0500545 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
546 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400547 lpfc_printf_vlog(vport, KERN_WARNING,
548 LOG_ELS | LOG_VPORT,
549 "1816 FLOGI NPIV supported, "
550 "response data 0x%x\n",
551 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500552 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500553 } else {
554 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400555 to call reg_vnpid atleast for the physcial host */
556 lpfc_printf_vlog(vport, KERN_WARNING,
557 LOG_ELS | LOG_VPORT,
558 "1817 Fabric does not support NPIV "
559 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500560 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
561 }
562 }
563
564 if ((vport->fc_prevDID != vport->fc_myDID) &&
565 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
566
567 /* If our NportID changed, we need to ensure all
568 * remaining NPORTs get unreg_login'ed.
569 */
570 list_for_each_entry_safe(np, next_np,
571 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400572 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500573 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500574 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
575 !(np->nlp_flag & NLP_NPR_ADISC))
576 continue;
577 spin_lock_irq(shost->host_lock);
578 np->nlp_flag &= ~NLP_NPR_ADISC;
579 spin_unlock_irq(shost->host_lock);
580 lpfc_unreg_rpi(vport, np);
581 }
James Smart78730cf2010-04-06 15:06:30 -0400582 lpfc_cleanup_pending_mbox(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500583 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
584 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500585 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500586 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500587 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500588 }
James Smartecfd03c2010-02-12 14:41:27 -0500589 /*
590 * If VPI is unreged, driver need to do INIT_VPI
591 * before re-registering
592 */
593 if (phba->sli_rev == LPFC_SLI_REV4) {
594 spin_lock_irq(shost->host_lock);
595 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
596 spin_unlock_irq(shost->host_lock);
597 }
James Smart38b92ef2010-08-04 16:11:39 -0400598 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
599 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
600 /*
601 * Driver needs to re-reg VPI in order for f/w
602 * to update the MAC address.
603 */
604 lpfc_register_new_vport(phba, vport, ndlp);
605 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500606 }
607
James Smart6fb120a2009-05-22 14:52:59 -0400608 if (phba->sli_rev < LPFC_SLI_REV4) {
609 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
610 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
611 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
612 lpfc_register_new_vport(phba, vport, ndlp);
613 else
614 lpfc_issue_fabric_reglogin(vport);
615 } else {
616 ndlp->nlp_type |= NLP_FABRIC;
617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500618 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
619 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400620 lpfc_start_fdiscs(phba);
621 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500622 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500623 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500624 else
James Smart6fb120a2009-05-22 14:52:59 -0400625 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500626 }
dea31012005-04-17 16:05:31 -0500627 return 0;
dea31012005-04-17 16:05:31 -0500628}
James Smarte59058c2008-08-24 21:49:00 -0400629/**
James Smart3621a712009-04-06 18:47:14 -0400630 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400631 * @vport: pointer to a host virtual N_Port data structure.
632 * @ndlp: pointer to a node-list data structure.
633 * @sp: pointer to service parameter data structure.
634 *
635 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
636 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
637 * in a point-to-point topology. First, the @vport's N_Port Name is compared
638 * with the received N_Port Name: if the @vport's N_Port Name is greater than
639 * the received N_Port Name lexicographically, this node shall assign local
640 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
641 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
642 * this node shall just wait for the remote node to issue PLOGI and assign
643 * N_Port IDs.
644 *
645 * Return code
646 * 0 - Success
647 * -ENXIO - Fail
648 **/
dea31012005-04-17 16:05:31 -0500649static int
James Smart2e0fef82007-06-17 19:56:36 -0500650lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
651 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500652{
James Smart2e0fef82007-06-17 19:56:36 -0500653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
654 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500655 LPFC_MBOXQ_t *mbox;
656 int rc;
657
James Smart2e0fef82007-06-17 19:56:36 -0500658 spin_lock_irq(shost->host_lock);
659 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
660 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500661
662 phba->fc_edtov = FF_DEF_EDTOV;
663 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500664 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500665 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500666 if (rc >= 0) {
667 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500668 spin_lock_irq(shost->host_lock);
669 vport->fc_flag |= FC_PT2PT_PLOGI;
670 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500671
672 /*
673 * N_Port ID cannot be 0, set our to LocalID the other
674 * side will be RemoteID.
675 */
676
677 /* not equal */
678 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500679 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500680
681 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
682 if (!mbox)
683 goto fail;
684
685 lpfc_config_link(phba, mbox);
686
687 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500688 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400689 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500690 if (rc == MBX_NOT_FINISHED) {
691 mempool_free(mbox, phba->mbox_mem_pool);
692 goto fail;
693 }
James Smarte47c9092008-02-08 18:49:26 -0500694 /* Decrement ndlp reference count indicating that ndlp can be
695 * safely released when other references to it are done.
696 */
James Smart329f9bc2007-04-25 09:53:01 -0400697 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500698
James Smart2e0fef82007-06-17 19:56:36 -0500699 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500700 if (!ndlp) {
701 /*
702 * Cannot find existing Fabric ndlp, so allocate a
703 * new one
704 */
705 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
706 if (!ndlp)
707 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500708 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500709 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
710 ndlp = lpfc_enable_node(vport, ndlp,
711 NLP_STE_UNUSED_NODE);
712 if(!ndlp)
713 goto fail;
dea31012005-04-17 16:05:31 -0500714 }
715
716 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500717 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500718 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500719 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500720 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
722 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500723 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500724 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500725 } else
726 /* This side will wait for the PLOGI, decrement ndlp reference
727 * count indicating that ndlp can be released when other
728 * references to it are done.
729 */
James Smart329f9bc2007-04-25 09:53:01 -0400730 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500731
James Smart09372822008-01-11 01:52:54 -0500732 /* If we are pt2pt with another NPort, force NPIV off! */
733 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
734
James Smart2e0fef82007-06-17 19:56:36 -0500735 spin_lock_irq(shost->host_lock);
736 vport->fc_flag |= FC_PT2PT;
737 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500738
739 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500740 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500741 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500742fail:
dea31012005-04-17 16:05:31 -0500743 return -ENXIO;
744}
745
James Smarte59058c2008-08-24 21:49:00 -0400746/**
James Smart3621a712009-04-06 18:47:14 -0400747 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400748 * @phba: pointer to lpfc hba data structure.
749 * @cmdiocb: pointer to lpfc command iocb data structure.
750 * @rspiocb: pointer to lpfc response iocb data structure.
751 *
752 * This routine is the top-level completion callback function for issuing
753 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
754 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
755 * retry has been made (either immediately or delayed with lpfc_els_retry()
756 * returning 1), the command IOCB will be released and function returned.
757 * If the retry attempt has been given up (possibly reach the maximum
758 * number of retries), one additional decrement of ndlp reference shall be
759 * invoked before going out after releasing the command IOCB. This will
760 * actually release the remote node (Note, lpfc_els_free_iocb() will also
761 * invoke one decrement of ndlp reference count). If no error reported in
762 * the IOCB status, the command Port ID field is used to determine whether
763 * this is a point-to-point topology or a fabric topology: if the Port ID
764 * field is assigned, it is a fabric topology; otherwise, it is a
765 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
766 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
767 * specific topology completion conditions.
768 **/
dea31012005-04-17 16:05:31 -0500769static void
James Smart329f9bc2007-04-25 09:53:01 -0400770lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
771 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500772{
James Smart2e0fef82007-06-17 19:56:36 -0500773 struct lpfc_vport *vport = cmdiocb->vport;
774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500775 IOCB_t *irsp = &rspiocb->iocb;
776 struct lpfc_nodelist *ndlp = cmdiocb->context1;
777 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
778 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500779 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500780 int rc;
781
782 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500783 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500784 /* One additional decrement on node reference count to
785 * trigger the release of the node
786 */
James Smart329f9bc2007-04-25 09:53:01 -0400787 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500788 goto out;
789 }
790
James Smart858c9f62007-06-17 19:56:39 -0500791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
792 "FLOGI cmpl: status:x%x/x%x state:x%x",
793 irsp->ulpStatus, irsp->un.ulpWord[4],
794 vport->port_state);
795
dea31012005-04-17 16:05:31 -0500796 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500797 /*
798 * In case of FIP mode, perform round robin FCF failover
799 * due to new FCF discovery
800 */
801 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400802 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
803 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
804 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500805 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
806 "2611 FLOGI failed on registered "
James Smart38b92ef2010-08-04 16:11:39 -0400807 "FCF record fcf_index(%d), status: "
808 "x%x/x%x, tmo:x%x, trying to perform "
809 "round robin failover\n",
810 phba->fcf.current_rec.fcf_indx,
811 irsp->ulpStatus, irsp->un.ulpWord[4],
812 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500813 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
814 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
815 /*
816 * Exhausted the eligible FCF record list,
817 * fail through to retry FLOGI on current
818 * FCF record.
819 */
820 lpfc_printf_log(phba, KERN_WARNING,
821 LOG_FIP | LOG_ELS,
James Smart3804dc82010-07-14 15:31:37 -0400822 "2760 Completed one round "
823 "of FLOGI FCF round robin "
824 "failover list, retry FLOGI "
825 "on currently registered "
826 "FCF index:%d\n",
James Smart0c9ab6f2010-02-26 14:15:57 -0500827 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500828 } else {
James Smart3804dc82010-07-14 15:31:37 -0400829 lpfc_printf_log(phba, KERN_INFO,
830 LOG_FIP | LOG_ELS,
831 "2794 FLOGI FCF round robin "
832 "failover to FCF index x%x\n",
833 fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -0500834 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
835 fcf_index);
James Smart3804dc82010-07-14 15:31:37 -0400836 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -0500837 lpfc_printf_log(phba, KERN_WARNING,
838 LOG_FIP | LOG_ELS,
839 "2761 FLOGI round "
840 "robin FCF failover "
841 "read FCF failed "
842 "rc:x%x, fcf_index:"
843 "%d\n", rc,
844 phba->fcf.current_rec.fcf_indx);
James Smart3804dc82010-07-14 15:31:37 -0400845 else
James Smart0c9ab6f2010-02-26 14:15:57 -0500846 goto out;
847 }
848 }
849
James Smart38b92ef2010-08-04 16:11:39 -0400850 /* FLOGI failure */
851 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
852 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
853 irsp->ulpStatus, irsp->un.ulpWord[4],
854 irsp->ulpTimeout);
855
dea31012005-04-17 16:05:31 -0500856 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500857 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500858 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500859
dea31012005-04-17 16:05:31 -0500860 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500861 spin_lock_irq(shost->host_lock);
862 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
863 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500864
James Smart329f9bc2007-04-25 09:53:01 -0400865 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500866 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
867 * alpa map would take too long otherwise.
868 */
869 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400870 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500871 }
872
873 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500874 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
875 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400876 irsp->ulpStatus, irsp->un.ulpWord[4],
877 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500878 goto flogifail;
879 }
James Smart695a8142010-01-26 23:08:03 -0500880 spin_lock_irq(shost->host_lock);
881 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400882 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500883 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500884
885 /*
886 * The FLogI succeeded. Sync the data for the CPU before
887 * accessing it.
888 */
889 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
890
891 sp = prsp->virt + sizeof(uint32_t);
892
893 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400894 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200895 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400896 "Data: x%x x%x x%x x%x\n",
897 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
898 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500899
James Smart2e0fef82007-06-17 19:56:36 -0500900 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500901 /*
902 * If Common Service Parameters indicate Nport
903 * we are point to point, if Fport we are Fabric.
904 */
905 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500906 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400907 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
James Smart2e0fef82007-06-17 19:56:36 -0500908 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400909 else {
910 lpfc_printf_vlog(vport, KERN_ERR,
911 LOG_FIP | LOG_ELS,
912 "2831 FLOGI response with cleared Fabric "
913 "bit fcf_index 0x%x "
914 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
915 "Fabric Name "
916 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
917 phba->fcf.current_rec.fcf_indx,
918 phba->fcf.current_rec.switch_name[0],
919 phba->fcf.current_rec.switch_name[1],
920 phba->fcf.current_rec.switch_name[2],
921 phba->fcf.current_rec.switch_name[3],
922 phba->fcf.current_rec.switch_name[4],
923 phba->fcf.current_rec.switch_name[5],
924 phba->fcf.current_rec.switch_name[6],
925 phba->fcf.current_rec.switch_name[7],
926 phba->fcf.current_rec.fabric_name[0],
927 phba->fcf.current_rec.fabric_name[1],
928 phba->fcf.current_rec.fabric_name[2],
929 phba->fcf.current_rec.fabric_name[3],
930 phba->fcf.current_rec.fabric_name[4],
931 phba->fcf.current_rec.fabric_name[5],
932 phba->fcf.current_rec.fabric_name[6],
933 phba->fcf.current_rec.fabric_name[7]);
934 lpfc_nlp_put(ndlp);
935 spin_lock_irq(&phba->hbalock);
936 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
937 spin_unlock_irq(&phba->hbalock);
938 goto out;
939 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500940 if (!rc) {
941 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400942 if (phba->hba_flag & HBA_FIP_SUPPORT)
943 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
944 LOG_ELS,
945 "2769 FLOGI successful on FCF "
946 "record: current_fcf_index:"
947 "x%x, terminate FCF round "
948 "robin failover process\n",
949 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500950 spin_lock_irq(&phba->hbalock);
951 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
952 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500953 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500954 }
dea31012005-04-17 16:05:31 -0500955 }
956
957flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400958 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500959
James Smart858c9f62007-06-17 19:56:39 -0500960 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500961 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500962 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500963
964 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500965 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400966 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
967 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
968 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
969 (phba->link_state != LPFC_CLEAR_LA)) {
970 /* If FLOGI failed enable link interrupt. */
971 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500972 }
dea31012005-04-17 16:05:31 -0500973out:
974 lpfc_els_free_iocb(phba, cmdiocb);
975}
976
James Smarte59058c2008-08-24 21:49:00 -0400977/**
James Smart3621a712009-04-06 18:47:14 -0400978 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400979 * @vport: pointer to a host virtual N_Port data structure.
980 * @ndlp: pointer to a node-list data structure.
981 * @retry: number of retries to the command IOCB.
982 *
983 * This routine issues a Fabric Login (FLOGI) Request ELS command
984 * for a @vport. The initiator service parameters are put into the payload
985 * of the FLOGI Request IOCB and the top-level callback function pointer
986 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
987 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
988 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
989 *
990 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
991 * will be incremented by 1 for holding the ndlp and the reference to ndlp
992 * will be stored into the context1 field of the IOCB for the completion
993 * callback function to the FLOGI ELS command.
994 *
995 * Return code
996 * 0 - successfully issued flogi iocb for @vport
997 * 1 - failed to issue flogi iocb for @vport
998 **/
dea31012005-04-17 16:05:31 -0500999static int
James Smart2e0fef82007-06-17 19:56:36 -05001000lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001001 uint8_t retry)
1002{
James Smart2e0fef82007-06-17 19:56:36 -05001003 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001004 struct serv_parm *sp;
1005 IOCB_t *icmd;
1006 struct lpfc_iocbq *elsiocb;
1007 struct lpfc_sli_ring *pring;
1008 uint8_t *pcmd;
1009 uint16_t cmdsize;
1010 uint32_t tmo;
1011 int rc;
1012
1013 pring = &phba->sli.ring[LPFC_ELS_RING];
1014
James Smart92d7f7b2007-06-17 19:56:38 -05001015 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001016 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1017 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001018
James Smart488d1462006-03-07 15:02:37 -05001019 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001020 return 1;
dea31012005-04-17 16:05:31 -05001021
1022 icmd = &elsiocb->iocb;
1023 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1024
1025 /* For FLOGI request, remainder of payload is service parameters */
1026 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001027 pcmd += sizeof(uint32_t);
1028 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001029 sp = (struct serv_parm *) pcmd;
1030
1031 /* Setup CSPs accordingly for Fabric */
1032 sp->cmn.e_d_tov = 0;
1033 sp->cmn.w2.r_a_tov = 0;
1034 sp->cls1.classValid = 0;
1035 sp->cls2.seqDelivery = 1;
1036 sp->cls3.seqDelivery = 1;
1037 if (sp->cmn.fcphLow < FC_PH3)
1038 sp->cmn.fcphLow = FC_PH3;
1039 if (sp->cmn.fcphHigh < FC_PH3)
1040 sp->cmn.fcphHigh = FC_PH3;
1041
James Smart6fb120a2009-05-22 14:52:59 -04001042 if (phba->sli_rev == LPFC_SLI_REV4) {
1043 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1044 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1045 /* FLOGI needs to be 3 for WQE FCFI */
1046 /* Set the fcfi to the fcfi we registered with */
1047 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1048 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001049 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001050 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1051 icmd->ulpCt_h = 1;
1052 icmd->ulpCt_l = 0;
1053 }
1054
James Smart858c9f62007-06-17 19:56:39 -05001055 if (phba->fc_topology != TOPOLOGY_LOOP) {
1056 icmd->un.elsreq64.myID = 0;
1057 icmd->un.elsreq64.fl = 1;
1058 }
1059
dea31012005-04-17 16:05:31 -05001060 tmo = phba->fc_ratov;
1061 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001062 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001063 phba->fc_ratov = tmo;
1064
1065 phba->fc_stat.elsXmitFLOGI++;
1066 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001067
1068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1069 "Issue FLOGI: opt:x%x",
1070 phba->sli3_options, 0, 0);
1071
James Smart92d7f7b2007-06-17 19:56:38 -05001072 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001073 if (rc == IOCB_ERROR) {
1074 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001075 return 1;
dea31012005-04-17 16:05:31 -05001076 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001077 return 0;
dea31012005-04-17 16:05:31 -05001078}
1079
James Smarte59058c2008-08-24 21:49:00 -04001080/**
James Smart3621a712009-04-06 18:47:14 -04001081 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001082 * @phba: pointer to lpfc hba data structure.
1083 *
1084 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1085 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1086 * list and issues an abort IOCB commond on each outstanding IOCB that
1087 * contains a active Fabric_DID ndlp. Note that this function is to issue
1088 * the abort IOCB command on all the outstanding IOCBs, thus when this
1089 * function returns, it does not guarantee all the IOCBs are actually aborted.
1090 *
1091 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001092 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001093 **/
dea31012005-04-17 16:05:31 -05001094int
James Smart2e0fef82007-06-17 19:56:36 -05001095lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001096{
1097 struct lpfc_sli_ring *pring;
1098 struct lpfc_iocbq *iocb, *next_iocb;
1099 struct lpfc_nodelist *ndlp;
1100 IOCB_t *icmd;
1101
1102 /* Abort outstanding I/O on NPort <nlp_DID> */
1103 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001104 "0201 Abort outstanding I/O on NPort x%x\n",
1105 Fabric_DID);
dea31012005-04-17 16:05:31 -05001106
1107 pring = &phba->sli.ring[LPFC_ELS_RING];
1108
1109 /*
1110 * Check the txcmplq for an iocb that matches the nport the driver is
1111 * searching for.
1112 */
James Smart2e0fef82007-06-17 19:56:36 -05001113 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001114 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1115 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001116 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1117 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001118 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001119 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1120 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001121 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001122 }
1123 }
James Smart2e0fef82007-06-17 19:56:36 -05001124 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001125
1126 return 0;
1127}
1128
James Smarte59058c2008-08-24 21:49:00 -04001129/**
James Smart3621a712009-04-06 18:47:14 -04001130 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001131 * @vport: pointer to a host virtual N_Port data structure.
1132 *
1133 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1134 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1135 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1136 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1137 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1138 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1139 * @vport.
1140 *
1141 * Return code
1142 * 0 - failed to issue initial flogi for @vport
1143 * 1 - successfully issued initial flogi for @vport
1144 **/
dea31012005-04-17 16:05:31 -05001145int
James Smart2e0fef82007-06-17 19:56:36 -05001146lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001147{
James Smart2e0fef82007-06-17 19:56:36 -05001148 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001149 struct lpfc_nodelist *ndlp;
1150
James Smart98c9ea52007-10-27 13:37:33 -04001151 vport->port_state = LPFC_FLOGI;
1152 lpfc_set_disctmo(vport);
1153
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001154 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001155 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001156 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001157 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001158 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1159 if (!ndlp)
1160 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001161 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001162 /* Set the node type */
1163 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001164 /* Put ndlp onto node list */
1165 lpfc_enqueue_node(vport, ndlp);
1166 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1167 /* re-setup ndlp without removing from node list */
1168 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1169 if (!ndlp)
1170 return 0;
dea31012005-04-17 16:05:31 -05001171 }
James Smart87af33f2007-10-27 13:37:43 -04001172
James Smart5ac6b302010-10-22 11:05:36 -04001173 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001174 /* This decrement of reference count to node shall kick off
1175 * the release of the node.
1176 */
James Smart329f9bc2007-04-25 09:53:01 -04001177 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001178 return 0;
1179 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001180 return 1;
dea31012005-04-17 16:05:31 -05001181}
1182
James Smarte59058c2008-08-24 21:49:00 -04001183/**
James Smart3621a712009-04-06 18:47:14 -04001184 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001185 * @vport: pointer to a host virtual N_Port data structure.
1186 *
1187 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1188 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1189 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1190 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1191 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1192 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1193 * @vport.
1194 *
1195 * Return code
1196 * 0 - failed to issue initial fdisc for @vport
1197 * 1 - successfully issued initial fdisc for @vport
1198 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001199int
1200lpfc_initial_fdisc(struct lpfc_vport *vport)
1201{
1202 struct lpfc_hba *phba = vport->phba;
1203 struct lpfc_nodelist *ndlp;
1204
1205 /* First look for the Fabric ndlp */
1206 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1207 if (!ndlp) {
1208 /* Cannot find existing Fabric ndlp, so allocate a new one */
1209 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1210 if (!ndlp)
1211 return 0;
1212 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001213 /* Put ndlp onto node list */
1214 lpfc_enqueue_node(vport, ndlp);
1215 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1216 /* re-setup ndlp without removing from node list */
1217 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1218 if (!ndlp)
1219 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001220 }
James Smarte47c9092008-02-08 18:49:26 -05001221
James Smart92d7f7b2007-06-17 19:56:38 -05001222 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001223 /* decrement node reference count to trigger the release of
1224 * the node.
1225 */
James Smart92d7f7b2007-06-17 19:56:38 -05001226 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001227 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001228 }
1229 return 1;
1230}
James Smart87af33f2007-10-27 13:37:43 -04001231
James Smarte59058c2008-08-24 21:49:00 -04001232/**
James Smart3621a712009-04-06 18:47:14 -04001233 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001234 * @vport: pointer to a host virtual N_Port data structure.
1235 *
1236 * This routine checks whether there are more remaining Port Logins
1237 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1238 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1239 * to issue ELS PLOGIs up to the configured discover threads with the
1240 * @vport (@vport->cfg_discovery_threads). The function also decrement
1241 * the @vport's num_disc_node by 1 if it is not already 0.
1242 **/
James Smart87af33f2007-10-27 13:37:43 -04001243void
James Smart2e0fef82007-06-17 19:56:36 -05001244lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001245{
1246 int sentplogi;
1247
James Smart2e0fef82007-06-17 19:56:36 -05001248 if (vport->num_disc_nodes)
1249 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001250
1251 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001252 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1253 "0232 Continue discovery with %d PLOGIs to go "
1254 "Data: x%x x%x x%x\n",
1255 vport->num_disc_nodes, vport->fc_plogi_cnt,
1256 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001257 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001258 if (vport->fc_flag & FC_NLP_MORE)
1259 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1260 sentplogi = lpfc_els_disc_plogi(vport);
1261
dea31012005-04-17 16:05:31 -05001262 return;
1263}
1264
James Smarte59058c2008-08-24 21:49:00 -04001265/**
James Smart3621a712009-04-06 18:47:14 -04001266 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001267 * @phba: pointer to lpfc hba data structure.
1268 * @prsp: pointer to response IOCB payload.
1269 * @ndlp: pointer to a node-list data structure.
1270 *
1271 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1272 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1273 * The following cases are considered N_Port confirmed:
1274 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1275 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1276 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1277 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1278 * 1) if there is a node on vport list other than the @ndlp with the same
1279 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1280 * on that node to release the RPI associated with the node; 2) if there is
1281 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1282 * into, a new node shall be allocated (or activated). In either case, the
1283 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1284 * be released and the new_ndlp shall be put on to the vport node list and
1285 * its pointer returned as the confirmed node.
1286 *
1287 * Note that before the @ndlp got "released", the keepDID from not-matching
1288 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1289 * of the @ndlp. This is because the release of @ndlp is actually to put it
1290 * into an inactive state on the vport node list and the vport node list
1291 * management algorithm does not allow two node with a same DID.
1292 *
1293 * Return code
1294 * pointer to the PLOGI N_Port @ndlp
1295 **/
James Smart488d1462006-03-07 15:02:37 -05001296static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001297lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001298 struct lpfc_nodelist *ndlp)
1299{
James Smart2e0fef82007-06-17 19:56:36 -05001300 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001301 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001302 struct lpfc_rport_data *rdata;
1303 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001304 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001305 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001306 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001307 int put_node;
1308 int put_rport;
James Smart488d1462006-03-07 15:02:37 -05001309
James Smart2fb9bd82006-12-02 13:33:57 -05001310 /* Fabric nodes can have the same WWPN so we don't bother searching
1311 * by WWPN. Just return the ndlp that was given to us.
1312 */
1313 if (ndlp->nlp_type & NLP_FABRIC)
1314 return ndlp;
1315
James Smart92d7f7b2007-06-17 19:56:38 -05001316 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001317 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001318
James Smart685f0bf2007-04-25 09:53:08 -04001319 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001320 * we have for that ndlp. If not, we have some work to do.
1321 */
James Smart2e0fef82007-06-17 19:56:36 -05001322 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001323
James Smarte47c9092008-02-08 18:49:26 -05001324 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001325 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001326
1327 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001328 rc = memcmp(&ndlp->nlp_portname, name,
1329 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001330 if (!rc)
1331 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001332 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1333 if (!new_ndlp)
1334 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001335 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001336 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001337 rc = memcmp(&ndlp->nlp_portname, name,
1338 sizeof(struct lpfc_name));
1339 if (!rc)
1340 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001341 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1342 NLP_STE_UNUSED_NODE);
1343 if (!new_ndlp)
1344 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001345 keepDID = new_ndlp->nlp_DID;
1346 } else
1347 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001348
James Smart2e0fef82007-06-17 19:56:36 -05001349 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001350 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001351 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001352
1353 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1354 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1355 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1356
James Smarte47c9092008-02-08 18:49:26 -05001357 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001358 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001359
James Smart2e0fef82007-06-17 19:56:36 -05001360 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001361 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1362 /* The new_ndlp is replacing ndlp totally, so we need
1363 * to put ndlp on UNUSED list and try to free it.
1364 */
James Smart0ff10d42008-01-11 01:52:36 -05001365
1366 /* Fix up the rport accordingly */
1367 rport = ndlp->rport;
1368 if (rport) {
1369 rdata = rport->dd_data;
1370 if (rdata->pnode == ndlp) {
1371 lpfc_nlp_put(ndlp);
1372 ndlp->rport = NULL;
1373 rdata->pnode = lpfc_nlp_get(new_ndlp);
1374 new_ndlp->rport = rport;
1375 }
1376 new_ndlp->nlp_type = ndlp->nlp_type;
1377 }
James Smart58da1ff2008-04-07 10:15:56 -04001378 /* We shall actually free the ndlp with both nlp_DID and
1379 * nlp_portname fields equals 0 to avoid any ndlp on the
1380 * nodelist never to be used.
1381 */
1382 if (ndlp->nlp_DID == 0) {
1383 spin_lock_irq(&phba->ndlp_lock);
1384 NLP_SET_FREE_REQ(ndlp);
1385 spin_unlock_irq(&phba->ndlp_lock);
1386 }
James Smart0ff10d42008-01-11 01:52:36 -05001387
James Smart58da1ff2008-04-07 10:15:56 -04001388 /* Two ndlps cannot have the same did on the nodelist */
1389 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001390 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001391 }
James Smart92795652006-07-06 15:50:02 -04001392 else {
James Smart2e0fef82007-06-17 19:56:36 -05001393 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001394 /* Two ndlps cannot have the same did */
1395 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001396 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001397 /* Since we are swapping the ndlp passed in with the new one
1398 * and the did has already been swapped, copy over the
1399 * state and names.
1400 */
1401 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1402 sizeof(struct lpfc_name));
1403 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1404 sizeof(struct lpfc_name));
1405 new_ndlp->nlp_state = ndlp->nlp_state;
1406 /* Fix up the rport accordingly */
1407 rport = ndlp->rport;
1408 if (rport) {
1409 rdata = rport->dd_data;
1410 put_node = rdata->pnode != NULL;
1411 put_rport = ndlp->rport != NULL;
1412 rdata->pnode = NULL;
1413 ndlp->rport = NULL;
1414 if (put_node)
1415 lpfc_nlp_put(ndlp);
1416 if (put_rport)
1417 put_device(&rport->dev);
1418 }
James Smart92795652006-07-06 15:50:02 -04001419 }
James Smart488d1462006-03-07 15:02:37 -05001420 return new_ndlp;
1421}
1422
James Smarte59058c2008-08-24 21:49:00 -04001423/**
James Smart3621a712009-04-06 18:47:14 -04001424 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001425 * @vport: pointer to a host virtual N_Port data structure.
1426 *
1427 * This routine checks whether more Registration State Change
1428 * Notifications (RSCNs) came in while the discovery state machine was in
1429 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1430 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1431 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1432 * handling the RSCNs.
1433 **/
James Smart87af33f2007-10-27 13:37:43 -04001434void
1435lpfc_end_rscn(struct lpfc_vport *vport)
1436{
1437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1438
1439 if (vport->fc_flag & FC_RSCN_MODE) {
1440 /*
1441 * Check to see if more RSCNs came in while we were
1442 * processing this one.
1443 */
1444 if (vport->fc_rscn_id_cnt ||
1445 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1446 lpfc_els_handle_rscn(vport);
1447 else {
1448 spin_lock_irq(shost->host_lock);
1449 vport->fc_flag &= ~FC_RSCN_MODE;
1450 spin_unlock_irq(shost->host_lock);
1451 }
1452 }
1453}
1454
James Smarte59058c2008-08-24 21:49:00 -04001455/**
James Smart3621a712009-04-06 18:47:14 -04001456 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001457 * @phba: pointer to lpfc hba data structure.
1458 * @cmdiocb: pointer to lpfc command iocb data structure.
1459 * @rspiocb: pointer to lpfc response iocb data structure.
1460 *
1461 * This routine is the completion callback function for issuing the Port
1462 * Login (PLOGI) command. For PLOGI completion, there must be an active
1463 * ndlp on the vport node list that matches the remote node ID from the
1464 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1465 * ignored and command IOCB released. The PLOGI response IOCB status is
1466 * checked for error conditons. If there is error status reported, PLOGI
1467 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1468 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1469 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1470 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1471 * there are additional N_Port nodes with the vport that need to perform
1472 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1473 * PLOGIs.
1474 **/
dea31012005-04-17 16:05:31 -05001475static void
James Smart2e0fef82007-06-17 19:56:36 -05001476lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1477 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001478{
James Smart2e0fef82007-06-17 19:56:36 -05001479 struct lpfc_vport *vport = cmdiocb->vport;
1480 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001481 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001482 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001483 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001484 int disc, rc, did, type;
1485
dea31012005-04-17 16:05:31 -05001486 /* we pass cmdiocb to state machine which needs rspiocb as well */
1487 cmdiocb->context_un.rsp_iocb = rspiocb;
1488
1489 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1491 "PLOGI cmpl: status:x%x/x%x did:x%x",
1492 irsp->ulpStatus, irsp->un.ulpWord[4],
1493 irsp->un.elsreq64.remoteID);
1494
James Smart2e0fef82007-06-17 19:56:36 -05001495 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001496 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001497 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1498 "0136 PLOGI completes to NPort x%x "
1499 "with no ndlp. Data: x%x x%x x%x\n",
1500 irsp->un.elsreq64.remoteID,
1501 irsp->ulpStatus, irsp->un.ulpWord[4],
1502 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001503 goto out;
James Smarted957682007-06-17 19:56:37 -05001504 }
dea31012005-04-17 16:05:31 -05001505
1506 /* Since ndlp can be freed in the disc state machine, note if this node
1507 * is being used during discovery.
1508 */
James Smart2e0fef82007-06-17 19:56:36 -05001509 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001510 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001511 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001512 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001513 rc = 0;
1514
1515 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001516 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1517 "0102 PLOGI completes to NPort x%x "
1518 "Data: x%x x%x x%x x%x x%x\n",
1519 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1520 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001521 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001522 if (lpfc_els_chk_latt(vport)) {
1523 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001524 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001526 goto out;
1527 }
1528
1529 /* ndlp could be freed in DSM, save these values now */
1530 type = ndlp->nlp_type;
1531 did = ndlp->nlp_DID;
1532
1533 if (irsp->ulpStatus) {
1534 /* Check for retry */
1535 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1536 /* ELS command is being retried */
1537 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001538 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001539 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001540 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001541 }
1542 goto out;
1543 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001544 /* PLOGI failed Don't print the vport to vport rjts */
1545 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1546 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1547 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1548 (phba)->pport->cfg_log_verbose & LOG_ELS)
1549 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001550 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1551 ndlp->nlp_DID, irsp->ulpStatus,
1552 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001553 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001554 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001555 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001556 else
James Smart2e0fef82007-06-17 19:56:36 -05001557 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001558 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001559 } else {
1560 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001561 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001562 cmdiocb->context2)->list.next,
1563 struct lpfc_dmabuf, list);
1564 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001565 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001566 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001567 }
1568
James Smart2e0fef82007-06-17 19:56:36 -05001569 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001570 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001571 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001572
James Smart2e0fef82007-06-17 19:56:36 -05001573 if (vport->num_disc_nodes == 0) {
1574 spin_lock_irq(shost->host_lock);
1575 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1576 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001577
James Smart2e0fef82007-06-17 19:56:36 -05001578 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001579 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001580 }
1581 }
1582
1583out:
1584 lpfc_els_free_iocb(phba, cmdiocb);
1585 return;
1586}
1587
James Smarte59058c2008-08-24 21:49:00 -04001588/**
James Smart3621a712009-04-06 18:47:14 -04001589 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001590 * @vport: pointer to a host virtual N_Port data structure.
1591 * @did: destination port identifier.
1592 * @retry: number of retries to the command IOCB.
1593 *
1594 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1595 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1596 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1597 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1598 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1599 *
1600 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1601 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1602 * will be stored into the context1 field of the IOCB for the completion
1603 * callback function to the PLOGI ELS command.
1604 *
1605 * Return code
1606 * 0 - Successfully issued a plogi for @vport
1607 * 1 - failed to issue a plogi for @vport
1608 **/
dea31012005-04-17 16:05:31 -05001609int
James Smart2e0fef82007-06-17 19:56:36 -05001610lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001611{
James Smart2e0fef82007-06-17 19:56:36 -05001612 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001613 struct serv_parm *sp;
1614 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001615 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001616 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001617 struct lpfc_sli *psli;
1618 uint8_t *pcmd;
1619 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001620 int ret;
dea31012005-04-17 16:05:31 -05001621
1622 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001623
James Smart98c9ea52007-10-27 13:37:33 -04001624 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001625 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1626 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001627
James Smarte47c9092008-02-08 18:49:26 -05001628 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001629 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001630 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001631 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001632 if (!elsiocb)
1633 return 1;
dea31012005-04-17 16:05:31 -05001634
1635 icmd = &elsiocb->iocb;
1636 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1637
1638 /* For PLOGI request, remainder of payload is service parameters */
1639 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001640 pcmd += sizeof(uint32_t);
1641 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001642 sp = (struct serv_parm *) pcmd;
1643
James Smart5ac6b302010-10-22 11:05:36 -04001644 /*
1645 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1646 * to device on remote loops work.
1647 */
1648 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1649 sp->cmn.altBbCredit = 1;
1650
dea31012005-04-17 16:05:31 -05001651 if (sp->cmn.fcphLow < FC_PH_4_3)
1652 sp->cmn.fcphLow = FC_PH_4_3;
1653
1654 if (sp->cmn.fcphHigh < FC_PH3)
1655 sp->cmn.fcphHigh = FC_PH3;
1656
James Smart858c9f62007-06-17 19:56:39 -05001657 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1658 "Issue PLOGI: did:x%x",
1659 did, 0, 0);
1660
dea31012005-04-17 16:05:31 -05001661 phba->fc_stat.elsXmitPLOGI++;
1662 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001663 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001664
1665 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001666 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001667 return 1;
dea31012005-04-17 16:05:31 -05001668 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001669 return 0;
dea31012005-04-17 16:05:31 -05001670}
1671
James Smarte59058c2008-08-24 21:49:00 -04001672/**
James Smart3621a712009-04-06 18:47:14 -04001673 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001674 * @phba: pointer to lpfc hba data structure.
1675 * @cmdiocb: pointer to lpfc command iocb data structure.
1676 * @rspiocb: pointer to lpfc response iocb data structure.
1677 *
1678 * This routine is the completion callback function for a Process Login
1679 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1680 * status. If there is error status reported, PRLI retry shall be attempted
1681 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1682 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1683 * ndlp to mark the PRLI completion.
1684 **/
dea31012005-04-17 16:05:31 -05001685static void
James Smart2e0fef82007-06-17 19:56:36 -05001686lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1687 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001688{
James Smart2e0fef82007-06-17 19:56:36 -05001689 struct lpfc_vport *vport = cmdiocb->vport;
1690 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001691 IOCB_t *irsp;
1692 struct lpfc_sli *psli;
1693 struct lpfc_nodelist *ndlp;
1694
1695 psli = &phba->sli;
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;
James Smart2e0fef82007-06-17 19:56:36 -05001701 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001702 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001703 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001704
James Smart858c9f62007-06-17 19:56:39 -05001705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1706 "PRLI cmpl: status:x%x/x%x did:x%x",
1707 irsp->ulpStatus, irsp->un.ulpWord[4],
1708 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001709 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001710 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1711 "0103 PRLI completes to NPort x%x "
1712 "Data: x%x x%x x%x x%x\n",
1713 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1714 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001715
James Smart2e0fef82007-06-17 19:56:36 -05001716 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001717 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001718 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001719 goto out;
1720
1721 if (irsp->ulpStatus) {
1722 /* Check for retry */
1723 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1724 /* ELS command is being retried */
1725 goto out;
1726 }
1727 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001728 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1729 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1730 ndlp->nlp_DID, irsp->ulpStatus,
1731 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001732 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001733 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001734 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001735 else
James Smart2e0fef82007-06-17 19:56:36 -05001736 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001737 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001738 } else
dea31012005-04-17 16:05:31 -05001739 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001740 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001741 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001742out:
1743 lpfc_els_free_iocb(phba, cmdiocb);
1744 return;
1745}
1746
James Smarte59058c2008-08-24 21:49:00 -04001747/**
James Smart3621a712009-04-06 18:47:14 -04001748 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001749 * @vport: pointer to a host virtual N_Port data structure.
1750 * @ndlp: pointer to a node-list data structure.
1751 * @retry: number of retries to the command IOCB.
1752 *
1753 * This routine issues a Process Login (PRLI) ELS command for the
1754 * @vport. The PRLI service parameters are set up in the payload of the
1755 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1756 * is put to the IOCB completion callback func field before invoking the
1757 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1758 *
1759 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1760 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1761 * will be stored into the context1 field of the IOCB for the completion
1762 * callback function to the PRLI ELS command.
1763 *
1764 * Return code
1765 * 0 - successfully issued prli iocb command for @vport
1766 * 1 - failed to issue prli iocb command for @vport
1767 **/
dea31012005-04-17 16:05:31 -05001768int
James Smart2e0fef82007-06-17 19:56:36 -05001769lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001770 uint8_t retry)
1771{
James Smart2e0fef82007-06-17 19:56:36 -05001772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1773 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001774 PRLI *npr;
1775 IOCB_t *icmd;
1776 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001777 uint8_t *pcmd;
1778 uint16_t cmdsize;
1779
James Smart92d7f7b2007-06-17 19:56:38 -05001780 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001781 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1782 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001783 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001784 return 1;
dea31012005-04-17 16:05:31 -05001785
1786 icmd = &elsiocb->iocb;
1787 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1788
1789 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001790 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001791 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001792 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001793
1794 /* For PRLI, remainder of payload is PRLI parameter page */
1795 npr = (PRLI *) pcmd;
1796 /*
1797 * If our firmware version is 3.20 or later,
1798 * set the following bits for FC-TAPE support.
1799 */
1800 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1801 npr->ConfmComplAllowed = 1;
1802 npr->Retry = 1;
1803 npr->TaskRetryIdReq = 1;
1804 }
1805 npr->estabImagePair = 1;
1806 npr->readXferRdyDis = 1;
1807
1808 /* For FCP support */
1809 npr->prliType = PRLI_FCP_TYPE;
1810 npr->initiatorFunc = 1;
1811
James Smart858c9f62007-06-17 19:56:39 -05001812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1813 "Issue PRLI: did:x%x",
1814 ndlp->nlp_DID, 0, 0);
1815
dea31012005-04-17 16:05:31 -05001816 phba->fc_stat.elsXmitPRLI++;
1817 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001818 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001819 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001820 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001821 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1822 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001823 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001824 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001825 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001826 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001827 return 1;
dea31012005-04-17 16:05:31 -05001828 }
James Smart2e0fef82007-06-17 19:56:36 -05001829 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001830 return 0;
dea31012005-04-17 16:05:31 -05001831}
1832
James Smarte59058c2008-08-24 21:49:00 -04001833/**
James Smart3621a712009-04-06 18:47:14 -04001834 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001835 * @vport: pointer to a host virtual N_Port data structure.
1836 *
1837 * This routine performs Registration State Change Notification (RSCN)
1838 * discovery for a @vport. If the @vport's node port recovery count is not
1839 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1840 * the nodes that need recovery. If none of the PLOGI were needed through
1841 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1842 * invoked to check and handle possible more RSCN came in during the period
1843 * of processing the current ones.
1844 **/
1845static void
1846lpfc_rscn_disc(struct lpfc_vport *vport)
1847{
1848 lpfc_can_disctmo(vport);
1849
1850 /* RSCN discovery */
1851 /* go thru NPR nodes and issue ELS PLOGIs */
1852 if (vport->fc_npr_cnt)
1853 if (lpfc_els_disc_plogi(vport))
1854 return;
1855
1856 lpfc_end_rscn(vport);
1857}
1858
1859/**
James Smart3621a712009-04-06 18:47:14 -04001860 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001861 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1862 *
1863 * This function is called when the final ADISC is completed during discovery.
1864 * This function handles clearing link attention or issuing reg_vpi depending
1865 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1866 * discovery.
1867 * This function is called with no locks held.
1868 **/
1869static void
1870lpfc_adisc_done(struct lpfc_vport *vport)
1871{
1872 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1873 struct lpfc_hba *phba = vport->phba;
1874
1875 /*
1876 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1877 * and continue discovery.
1878 */
1879 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001880 !(vport->fc_flag & FC_RSCN_MODE) &&
1881 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001882 lpfc_issue_reg_vpi(phba, vport);
1883 return;
1884 }
1885 /*
1886 * For SLI2, we need to set port_state to READY
1887 * and continue discovery.
1888 */
1889 if (vport->port_state < LPFC_VPORT_READY) {
1890 /* If we get here, there is nothing to ADISC */
1891 if (vport->port_type == LPFC_PHYSICAL_PORT)
1892 lpfc_issue_clear_la(phba, vport);
1893 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1894 vport->num_disc_nodes = 0;
1895 /* go thru NPR list, issue ELS PLOGIs */
1896 if (vport->fc_npr_cnt)
1897 lpfc_els_disc_plogi(vport);
1898 if (!vport->num_disc_nodes) {
1899 spin_lock_irq(shost->host_lock);
1900 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1901 spin_unlock_irq(shost->host_lock);
1902 lpfc_can_disctmo(vport);
1903 lpfc_end_rscn(vport);
1904 }
1905 }
1906 vport->port_state = LPFC_VPORT_READY;
1907 } else
1908 lpfc_rscn_disc(vport);
1909}
1910
1911/**
James Smart3621a712009-04-06 18:47:14 -04001912 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001913 * @vport: pointer to a host virtual N_Port data structure.
1914 *
1915 * This routine determines whether there are more ndlps on a @vport
1916 * node list need to have Address Discover (ADISC) issued. If so, it will
1917 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1918 * remaining nodes which need to have ADISC sent.
1919 **/
James Smart0ff10d42008-01-11 01:52:36 -05001920void
James Smart2e0fef82007-06-17 19:56:36 -05001921lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001922{
1923 int sentadisc;
1924
James Smart2e0fef82007-06-17 19:56:36 -05001925 if (vport->num_disc_nodes)
1926 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001927 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001928 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1929 "0210 Continue discovery with %d ADISCs to go "
1930 "Data: x%x x%x x%x\n",
1931 vport->num_disc_nodes, vport->fc_adisc_cnt,
1932 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001933 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001934 if (vport->fc_flag & FC_NLP_MORE) {
1935 lpfc_set_disctmo(vport);
1936 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1937 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001938 }
James Smart90160e02008-08-24 21:49:45 -04001939 if (!vport->num_disc_nodes)
1940 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001941 return;
1942}
1943
James Smarte59058c2008-08-24 21:49:00 -04001944/**
James Smart3621a712009-04-06 18:47:14 -04001945 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001946 * @phba: pointer to lpfc hba data structure.
1947 * @cmdiocb: pointer to lpfc command iocb data structure.
1948 * @rspiocb: pointer to lpfc response iocb data structure.
1949 *
1950 * This routine is the completion function for issuing the Address Discover
1951 * (ADISC) command. It first checks to see whether link went down during
1952 * the discovery process. If so, the node will be marked as node port
1953 * recovery for issuing discover IOCB by the link attention handler and
1954 * exit. Otherwise, the response status is checked. If error was reported
1955 * in the response status, the ADISC command shall be retried by invoking
1956 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1957 * the response status, the state machine is invoked to set transition
1958 * with respect to NLP_EVT_CMPL_ADISC event.
1959 **/
dea31012005-04-17 16:05:31 -05001960static void
James Smart2e0fef82007-06-17 19:56:36 -05001961lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1962 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001963{
James Smart2e0fef82007-06-17 19:56:36 -05001964 struct lpfc_vport *vport = cmdiocb->vport;
1965 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001966 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001967 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001968 int disc;
dea31012005-04-17 16:05:31 -05001969
1970 /* we pass cmdiocb to state machine which needs rspiocb as well */
1971 cmdiocb->context_un.rsp_iocb = rspiocb;
1972
1973 irsp = &(rspiocb->iocb);
1974 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001975
James Smart858c9f62007-06-17 19:56:39 -05001976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1977 "ADISC cmpl: status:x%x/x%x did:x%x",
1978 irsp->ulpStatus, irsp->un.ulpWord[4],
1979 ndlp->nlp_DID);
1980
dea31012005-04-17 16:05:31 -05001981 /* Since ndlp can be freed in the disc state machine, note if this node
1982 * is being used during discovery.
1983 */
James Smart2e0fef82007-06-17 19:56:36 -05001984 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001985 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001986 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001987 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001988 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001989 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1990 "0104 ADISC completes to NPort x%x "
1991 "Data: x%x x%x x%x x%x x%x\n",
1992 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1993 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001994 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001995 if (lpfc_els_chk_latt(vport)) {
1996 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001997 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001998 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001999 goto out;
2000 }
2001
2002 if (irsp->ulpStatus) {
2003 /* Check for retry */
2004 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2005 /* ELS command is being retried */
2006 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002007 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002008 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002009 spin_unlock_irq(shost->host_lock);
2010 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002011 }
2012 goto out;
2013 }
2014 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002015 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2016 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2017 ndlp->nlp_DID, irsp->ulpStatus,
2018 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002019 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002020 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002021 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002022 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002023 } else
dea31012005-04-17 16:05:31 -05002024 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002025 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002026 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002027
James Smart90160e02008-08-24 21:49:45 -04002028 /* Check to see if there are more ADISCs to be sent */
2029 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002030 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002031out:
2032 lpfc_els_free_iocb(phba, cmdiocb);
2033 return;
2034}
2035
James Smarte59058c2008-08-24 21:49:00 -04002036/**
James Smart3621a712009-04-06 18:47:14 -04002037 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002038 * @vport: pointer to a virtual N_Port data structure.
2039 * @ndlp: pointer to a node-list data structure.
2040 * @retry: number of retries to the command IOCB.
2041 *
2042 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2043 * @vport. It prepares the payload of the ADISC ELS command, updates the
2044 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2045 * to issue the ADISC ELS command.
2046 *
2047 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2048 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2049 * will be stored into the context1 field of the IOCB for the completion
2050 * callback function to the ADISC ELS command.
2051 *
2052 * Return code
2053 * 0 - successfully issued adisc
2054 * 1 - failed to issue adisc
2055 **/
dea31012005-04-17 16:05:31 -05002056int
James Smart2e0fef82007-06-17 19:56:36 -05002057lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002058 uint8_t retry)
2059{
James Smart2e0fef82007-06-17 19:56:36 -05002060 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2061 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002062 ADISC *ap;
2063 IOCB_t *icmd;
2064 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002065 uint8_t *pcmd;
2066 uint16_t cmdsize;
2067
James Smart92d7f7b2007-06-17 19:56:38 -05002068 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002069 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2070 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002071 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002072 return 1;
dea31012005-04-17 16:05:31 -05002073
2074 icmd = &elsiocb->iocb;
2075 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2076
2077 /* For ADISC request, remainder of payload is service parameters */
2078 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002079 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002080
2081 /* Fill in ADISC payload */
2082 ap = (ADISC *) pcmd;
2083 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002084 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2085 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002086 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002087
James Smart858c9f62007-06-17 19:56:39 -05002088 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2089 "Issue ADISC: did:x%x",
2090 ndlp->nlp_DID, 0, 0);
2091
dea31012005-04-17 16:05:31 -05002092 phba->fc_stat.elsXmitADISC++;
2093 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002094 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002095 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002096 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002097 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2098 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002099 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002100 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002101 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002102 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002103 return 1;
dea31012005-04-17 16:05:31 -05002104 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002105 return 0;
dea31012005-04-17 16:05:31 -05002106}
2107
James Smarte59058c2008-08-24 21:49:00 -04002108/**
James Smart3621a712009-04-06 18:47:14 -04002109 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002110 * @phba: pointer to lpfc hba data structure.
2111 * @cmdiocb: pointer to lpfc command iocb data structure.
2112 * @rspiocb: pointer to lpfc response iocb data structure.
2113 *
2114 * This routine is the completion function for issuing the ELS Logout (LOGO)
2115 * command. If no error status was reported from the LOGO response, the
2116 * state machine of the associated ndlp shall be invoked for transition with
2117 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2118 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2119 **/
dea31012005-04-17 16:05:31 -05002120static void
James Smart2e0fef82007-06-17 19:56:36 -05002121lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2122 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002123{
James Smart2e0fef82007-06-17 19:56:36 -05002124 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2125 struct lpfc_vport *vport = ndlp->vport;
2126 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002127 IOCB_t *irsp;
2128 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002129
2130 psli = &phba->sli;
2131 /* we pass cmdiocb to state machine which needs rspiocb as well */
2132 cmdiocb->context_un.rsp_iocb = rspiocb;
2133
2134 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002135 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002136 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002137 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002138
James Smart858c9f62007-06-17 19:56:39 -05002139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2140 "LOGO cmpl: status:x%x/x%x did:x%x",
2141 irsp->ulpStatus, irsp->un.ulpWord[4],
2142 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002143 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002144 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2145 "0105 LOGO completes to NPort x%x "
2146 "Data: x%x x%x x%x x%x\n",
2147 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2148 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002149 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002150 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002151 goto out;
2152
James Smart92d7f7b2007-06-17 19:56:38 -05002153 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2154 /* NLP_EVT_DEVICE_RM should unregister the RPI
2155 * which should abort all outstanding IOs.
2156 */
2157 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2158 NLP_EVT_DEVICE_RM);
2159 goto out;
2160 }
2161
dea31012005-04-17 16:05:31 -05002162 if (irsp->ulpStatus) {
2163 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002164 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002165 /* ELS command is being retried */
2166 goto out;
dea31012005-04-17 16:05:31 -05002167 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002168 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2169 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2170 ndlp->nlp_DID, irsp->ulpStatus,
2171 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002172 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002173 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002174 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002175 else
James Smart2e0fef82007-06-17 19:56:36 -05002176 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002177 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002178 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002179 /* Good status, call state machine.
2180 * This will unregister the rpi if needed.
2181 */
James Smart2e0fef82007-06-17 19:56:36 -05002182 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002183 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002184out:
2185 lpfc_els_free_iocb(phba, cmdiocb);
2186 return;
2187}
2188
James Smarte59058c2008-08-24 21:49:00 -04002189/**
James Smart3621a712009-04-06 18:47:14 -04002190 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002191 * @vport: pointer to a virtual N_Port data structure.
2192 * @ndlp: pointer to a node-list data structure.
2193 * @retry: number of retries to the command IOCB.
2194 *
2195 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2196 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2197 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2198 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2199 *
2200 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2201 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2202 * will be stored into the context1 field of the IOCB for the completion
2203 * callback function to the LOGO ELS command.
2204 *
2205 * Return code
2206 * 0 - successfully issued logo
2207 * 1 - failed to issue logo
2208 **/
dea31012005-04-17 16:05:31 -05002209int
James Smart2e0fef82007-06-17 19:56:36 -05002210lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002211 uint8_t retry)
2212{
James Smart2e0fef82007-06-17 19:56:36 -05002213 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2214 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002215 IOCB_t *icmd;
2216 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002217 uint8_t *pcmd;
2218 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002219 int rc;
dea31012005-04-17 16:05:31 -05002220
James Smart98c9ea52007-10-27 13:37:33 -04002221 spin_lock_irq(shost->host_lock);
2222 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2223 spin_unlock_irq(shost->host_lock);
2224 return 0;
2225 }
2226 spin_unlock_irq(shost->host_lock);
2227
James Smart92d7f7b2007-06-17 19:56:38 -05002228 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002229 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2230 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002231 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002232 return 1;
dea31012005-04-17 16:05:31 -05002233
2234 icmd = &elsiocb->iocb;
2235 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2236 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002237 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002238
2239 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002240 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002241 pcmd += sizeof(uint32_t);
2242 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002243
James Smart858c9f62007-06-17 19:56:39 -05002244 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2245 "Issue LOGO: did:x%x",
2246 ndlp->nlp_DID, 0, 0);
2247
dea31012005-04-17 16:05:31 -05002248 phba->fc_stat.elsXmitLOGO++;
2249 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002250 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002251 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002252 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002253 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002254
2255 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002256 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002257 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002258 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002259 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002260 return 1;
dea31012005-04-17 16:05:31 -05002261 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002262 return 0;
dea31012005-04-17 16:05:31 -05002263}
2264
James Smarte59058c2008-08-24 21:49:00 -04002265/**
James Smart3621a712009-04-06 18:47:14 -04002266 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002267 * @phba: pointer to lpfc hba data structure.
2268 * @cmdiocb: pointer to lpfc command iocb data structure.
2269 * @rspiocb: pointer to lpfc response iocb data structure.
2270 *
2271 * This routine is a generic completion callback function for ELS commands.
2272 * Specifically, it is the callback function which does not need to perform
2273 * any command specific operations. It is currently used by the ELS command
2274 * issuing routines for the ELS State Change Request (SCR),
2275 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2276 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2277 * certain debug loggings, this callback function simply invokes the
2278 * lpfc_els_chk_latt() routine to check whether link went down during the
2279 * discovery process.
2280 **/
dea31012005-04-17 16:05:31 -05002281static void
James Smart2e0fef82007-06-17 19:56:36 -05002282lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2283 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002284{
James Smart2e0fef82007-06-17 19:56:36 -05002285 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002286 IOCB_t *irsp;
2287
2288 irsp = &rspiocb->iocb;
2289
James Smart858c9f62007-06-17 19:56:39 -05002290 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2291 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2292 irsp->ulpStatus, irsp->un.ulpWord[4],
2293 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002294 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002295 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2296 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2297 irsp->ulpIoTag, irsp->ulpStatus,
2298 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002299 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002300 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002301 lpfc_els_free_iocb(phba, cmdiocb);
2302 return;
2303}
2304
James Smarte59058c2008-08-24 21:49:00 -04002305/**
James Smart3621a712009-04-06 18:47:14 -04002306 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002307 * @vport: pointer to a host virtual N_Port data structure.
2308 * @nportid: N_Port identifier to the remote node.
2309 * @retry: number of retries to the command IOCB.
2310 *
2311 * This routine issues a State Change Request (SCR) to a fabric node
2312 * on a @vport. The remote node @nportid is passed into the function. It
2313 * first search the @vport node list to find the matching ndlp. If no such
2314 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2315 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2316 * routine is invoked to send the SCR IOCB.
2317 *
2318 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2319 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2320 * will be stored into the context1 field of the IOCB for the completion
2321 * callback function to the SCR ELS command.
2322 *
2323 * Return code
2324 * 0 - Successfully issued scr command
2325 * 1 - Failed to issue scr command
2326 **/
dea31012005-04-17 16:05:31 -05002327int
James Smart2e0fef82007-06-17 19:56:36 -05002328lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002329{
James Smart2e0fef82007-06-17 19:56:36 -05002330 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002331 IOCB_t *icmd;
2332 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002333 struct lpfc_sli *psli;
2334 uint8_t *pcmd;
2335 uint16_t cmdsize;
2336 struct lpfc_nodelist *ndlp;
2337
2338 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002339 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002340
James Smarte47c9092008-02-08 18:49:26 -05002341 ndlp = lpfc_findnode_did(vport, nportid);
2342 if (!ndlp) {
2343 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2344 if (!ndlp)
2345 return 1;
2346 lpfc_nlp_init(vport, ndlp, nportid);
2347 lpfc_enqueue_node(vport, ndlp);
2348 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2349 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2350 if (!ndlp)
2351 return 1;
2352 }
dea31012005-04-17 16:05:31 -05002353
James Smart2e0fef82007-06-17 19:56:36 -05002354 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2355 ndlp->nlp_DID, ELS_CMD_SCR);
2356
James Smart488d1462006-03-07 15:02:37 -05002357 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002358 /* This will trigger the release of the node just
2359 * allocated
2360 */
James Smart329f9bc2007-04-25 09:53:01 -04002361 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002362 return 1;
dea31012005-04-17 16:05:31 -05002363 }
2364
2365 icmd = &elsiocb->iocb;
2366 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2367
2368 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002369 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002370
2371 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002372 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002373 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2374
James Smart858c9f62007-06-17 19:56:39 -05002375 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2376 "Issue SCR: did:x%x",
2377 ndlp->nlp_DID, 0, 0);
2378
dea31012005-04-17 16:05:31 -05002379 phba->fc_stat.elsXmitSCR++;
2380 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002381 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2382 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002383 /* The additional lpfc_nlp_put will cause the following
2384 * lpfc_els_free_iocb routine to trigger the rlease of
2385 * the node.
2386 */
James Smart329f9bc2007-04-25 09:53:01 -04002387 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002388 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002389 return 1;
dea31012005-04-17 16:05:31 -05002390 }
James Smartfa4066b2008-01-11 01:53:27 -05002391 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2392 * trigger the release of node.
2393 */
James Smart329f9bc2007-04-25 09:53:01 -04002394 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002395 return 0;
dea31012005-04-17 16:05:31 -05002396}
2397
James Smarte59058c2008-08-24 21:49:00 -04002398/**
James Smart3621a712009-04-06 18:47:14 -04002399 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002400 * @vport: pointer to a host virtual N_Port data structure.
2401 * @nportid: N_Port identifier to the remote node.
2402 * @retry: number of retries to the command IOCB.
2403 *
2404 * This routine issues a Fibre Channel Address Resolution Response
2405 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2406 * is passed into the function. It first search the @vport node list to find
2407 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2408 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2409 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2410 *
2411 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2412 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2413 * will be stored into the context1 field of the IOCB for the completion
2414 * callback function to the PARPR ELS command.
2415 *
2416 * Return code
2417 * 0 - Successfully issued farpr command
2418 * 1 - Failed to issue farpr command
2419 **/
dea31012005-04-17 16:05:31 -05002420static int
James Smart2e0fef82007-06-17 19:56:36 -05002421lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002422{
James Smart2e0fef82007-06-17 19:56:36 -05002423 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002424 IOCB_t *icmd;
2425 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002426 struct lpfc_sli *psli;
2427 FARP *fp;
2428 uint8_t *pcmd;
2429 uint32_t *lp;
2430 uint16_t cmdsize;
2431 struct lpfc_nodelist *ondlp;
2432 struct lpfc_nodelist *ndlp;
2433
2434 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002435 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002436
James Smarte47c9092008-02-08 18:49:26 -05002437 ndlp = lpfc_findnode_did(vport, nportid);
2438 if (!ndlp) {
2439 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2440 if (!ndlp)
2441 return 1;
2442 lpfc_nlp_init(vport, ndlp, nportid);
2443 lpfc_enqueue_node(vport, ndlp);
2444 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2445 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2446 if (!ndlp)
2447 return 1;
2448 }
James Smart2e0fef82007-06-17 19:56:36 -05002449
2450 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2451 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002452 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002453 /* This will trigger the release of the node just
2454 * allocated
2455 */
James Smart329f9bc2007-04-25 09:53:01 -04002456 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002457 return 1;
dea31012005-04-17 16:05:31 -05002458 }
2459
2460 icmd = &elsiocb->iocb;
2461 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2462
2463 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002464 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002465
2466 /* Fill in FARPR payload */
2467 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002468 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002469 lp = (uint32_t *) pcmd;
2470 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002471 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002472 fp->Rflags = 0;
2473 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2474
James Smart92d7f7b2007-06-17 19:56:38 -05002475 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2476 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002477 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002478 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002479 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002480 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002481 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002482 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002483 }
2484
James Smart858c9f62007-06-17 19:56:39 -05002485 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2486 "Issue FARPR: did:x%x",
2487 ndlp->nlp_DID, 0, 0);
2488
dea31012005-04-17 16:05:31 -05002489 phba->fc_stat.elsXmitFARPR++;
2490 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002491 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2492 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002493 /* The additional lpfc_nlp_put will cause the following
2494 * lpfc_els_free_iocb routine to trigger the release of
2495 * the node.
2496 */
James Smart329f9bc2007-04-25 09:53:01 -04002497 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002498 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002499 return 1;
dea31012005-04-17 16:05:31 -05002500 }
James Smartfa4066b2008-01-11 01:53:27 -05002501 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2502 * trigger the release of the node.
2503 */
James Smart329f9bc2007-04-25 09:53:01 -04002504 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002505 return 0;
dea31012005-04-17 16:05:31 -05002506}
2507
James Smarte59058c2008-08-24 21:49:00 -04002508/**
James Smart3621a712009-04-06 18:47:14 -04002509 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002510 * @vport: pointer to a host virtual N_Port data structure.
2511 * @nlp: pointer to a node-list data structure.
2512 *
2513 * This routine cancels the timer with a delayed IOCB-command retry for
2514 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2515 * removes the ELS retry event if it presents. In addition, if the
2516 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2517 * commands are sent for the @vport's nodes that require issuing discovery
2518 * ADISC.
2519 **/
dea31012005-04-17 16:05:31 -05002520void
James Smart2e0fef82007-06-17 19:56:36 -05002521lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002522{
James Smart2e0fef82007-06-17 19:56:36 -05002523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002524 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002525
James Smart0d2b6b82008-06-14 22:52:47 -04002526 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2527 return;
James Smart2e0fef82007-06-17 19:56:36 -05002528 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002529 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002530 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002531 del_timer_sync(&nlp->nlp_delayfunc);
2532 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002533 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002534 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002535 /* Decrement nlp reference count held for the delayed retry */
2536 evtp = &nlp->els_retry_evt;
2537 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2538 }
James Smartfdcebe22006-03-07 15:04:01 -05002539 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002540 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002541 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002542 spin_unlock_irq(shost->host_lock);
2543 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002544 if (vport->port_state < LPFC_VPORT_READY) {
2545 /* Check if there are more ADISCs to be sent */
2546 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002547 } else {
2548 /* Check if there are more PLOGIs to be sent */
2549 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002550 if (vport->num_disc_nodes == 0) {
2551 spin_lock_irq(shost->host_lock);
2552 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2553 spin_unlock_irq(shost->host_lock);
2554 lpfc_can_disctmo(vport);
2555 lpfc_end_rscn(vport);
2556 }
James Smartfdcebe22006-03-07 15:04:01 -05002557 }
2558 }
2559 }
2560 return;
2561}
2562
James Smarte59058c2008-08-24 21:49:00 -04002563/**
James Smart3621a712009-04-06 18:47:14 -04002564 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002565 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2566 *
2567 * This routine is invoked by the ndlp delayed-function timer to check
2568 * whether there is any pending ELS retry event(s) with the node. If not, it
2569 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2570 * adds the delayed events to the HBA work list and invokes the
2571 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2572 * event. Note that lpfc_nlp_get() is called before posting the event to
2573 * the work list to hold reference count of ndlp so that it guarantees the
2574 * reference to ndlp will still be available when the worker thread gets
2575 * to the event associated with the ndlp.
2576 **/
James Smartfdcebe22006-03-07 15:04:01 -05002577void
dea31012005-04-17 16:05:31 -05002578lpfc_els_retry_delay(unsigned long ptr)
2579{
James Smart2e0fef82007-06-17 19:56:36 -05002580 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2581 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002582 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002583 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002584 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002585
James Smart92d7f7b2007-06-17 19:56:38 -05002586 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002587 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002588 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002589 return;
2590 }
2591
James Smartfa4066b2008-01-11 01:53:27 -05002592 /* We need to hold the node by incrementing the reference
2593 * count until the queued work is done
2594 */
2595 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002596 if (evtp->evt_arg1) {
2597 evtp->evt = LPFC_EVT_ELS_RETRY;
2598 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002599 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002600 }
James Smart92d7f7b2007-06-17 19:56:38 -05002601 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002602 return;
2603}
2604
James Smarte59058c2008-08-24 21:49:00 -04002605/**
James Smart3621a712009-04-06 18:47:14 -04002606 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002607 * @ndlp: pointer to a node-list data structure.
2608 *
2609 * This routine is the worker-thread handler for processing the @ndlp delayed
2610 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2611 * the last ELS command from the associated ndlp and invokes the proper ELS
2612 * function according to the delayed ELS command to retry the command.
2613 **/
dea31012005-04-17 16:05:31 -05002614void
2615lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2616{
James Smart2e0fef82007-06-17 19:56:36 -05002617 struct lpfc_vport *vport = ndlp->vport;
2618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2619 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002620
James Smart2e0fef82007-06-17 19:56:36 -05002621 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002622 did = ndlp->nlp_DID;
2623 cmd = ndlp->nlp_last_elscmd;
2624 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002625
2626 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002627 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002628 return;
2629 }
2630
2631 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002632 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002633 /*
2634 * If a discovery event readded nlp_delayfunc after timer
2635 * firing and before processing the timer, cancel the
2636 * nlp_delayfunc.
2637 */
2638 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002639 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002640 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002641
2642 switch (cmd) {
2643 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002644 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002645 break;
2646 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002647 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002648 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002649 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002650 }
dea31012005-04-17 16:05:31 -05002651 break;
2652 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002653 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002654 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002655 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002656 }
dea31012005-04-17 16:05:31 -05002657 break;
2658 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002659 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002660 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002661 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002662 }
dea31012005-04-17 16:05:31 -05002663 break;
2664 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002665 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002666 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002667 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002668 }
dea31012005-04-17 16:05:31 -05002669 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002670 case ELS_CMD_FDISC:
2671 lpfc_issue_els_fdisc(vport, ndlp, retry);
2672 break;
dea31012005-04-17 16:05:31 -05002673 }
2674 return;
2675}
2676
James Smarte59058c2008-08-24 21:49:00 -04002677/**
James Smart3621a712009-04-06 18:47:14 -04002678 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002679 * @phba: pointer to lpfc hba data structure.
2680 * @cmdiocb: pointer to lpfc command iocb data structure.
2681 * @rspiocb: pointer to lpfc response iocb data structure.
2682 *
2683 * This routine makes a retry decision on an ELS command IOCB, which has
2684 * failed. The following ELS IOCBs use this function for retrying the command
2685 * when previously issued command responsed with error status: FLOGI, PLOGI,
2686 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2687 * returned error status, it makes the decision whether a retry shall be
2688 * issued for the command, and whether a retry shall be made immediately or
2689 * delayed. In the former case, the corresponding ELS command issuing-function
2690 * is called to retry the command. In the later case, the ELS command shall
2691 * be posted to the ndlp delayed event and delayed function timer set to the
2692 * ndlp for the delayed command issusing.
2693 *
2694 * Return code
2695 * 0 - No retry of els command is made
2696 * 1 - Immediate or delayed retry of els command is made
2697 **/
dea31012005-04-17 16:05:31 -05002698static int
James Smart2e0fef82007-06-17 19:56:36 -05002699lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2700 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002701{
James Smart2e0fef82007-06-17 19:56:36 -05002702 struct lpfc_vport *vport = cmdiocb->vport;
2703 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2704 IOCB_t *irsp = &rspiocb->iocb;
2705 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2706 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002707 uint32_t *elscmd;
2708 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002709 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002710 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002711 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002712 uint32_t did;
dea31012005-04-17 16:05:31 -05002713
James Smart488d1462006-03-07 15:02:37 -05002714
dea31012005-04-17 16:05:31 -05002715 /* Note: context2 may be 0 for internal driver abort
2716 * of delays ELS command.
2717 */
2718
2719 if (pcmd && pcmd->virt) {
2720 elscmd = (uint32_t *) (pcmd->virt);
2721 cmd = *elscmd++;
2722 }
2723
James Smarte47c9092008-02-08 18:49:26 -05002724 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002725 did = ndlp->nlp_DID;
2726 else {
2727 /* We should only hit this case for retrying PLOGI */
2728 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002729 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002730 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2731 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002732 return 1;
2733 }
2734
James Smart858c9f62007-06-17 19:56:39 -05002735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2736 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2737 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2738
dea31012005-04-17 16:05:31 -05002739 switch (irsp->ulpStatus) {
2740 case IOSTAT_FCP_RSP_ERROR:
2741 case IOSTAT_REMOTE_STOP:
2742 break;
2743
2744 case IOSTAT_LOCAL_REJECT:
2745 switch ((irsp->un.ulpWord[4] & 0xff)) {
2746 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002747 if (cmd == ELS_CMD_FLOGI) {
2748 if (PCI_DEVICE_ID_HORNET ==
2749 phba->pcidev->device) {
2750 phba->fc_topology = TOPOLOGY_LOOP;
2751 phba->pport->fc_myDID = 0;
2752 phba->alpa_map[0] = 0;
2753 phba->alpa_map[1] = 0;
2754 }
2755 }
James Smart2e0fef82007-06-17 19:56:36 -05002756 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002757 delay = 1000;
dea31012005-04-17 16:05:31 -05002758 retry = 1;
2759 break;
2760
James Smart92d7f7b2007-06-17 19:56:38 -05002761 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002762 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2763 "0124 Retry illegal cmd x%x "
2764 "retry:x%x delay:x%x\n",
2765 cmd, cmdiocb->retry, delay);
2766 retry = 1;
2767 /* All command's retry policy */
2768 maxretry = 8;
2769 if (cmdiocb->retry > 2)
2770 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002771 break;
2772
dea31012005-04-17 16:05:31 -05002773 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002774 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002775 retry = 1;
2776 if (cmdiocb->retry > 100)
2777 delay = 100;
2778 maxretry = 250;
2779 break;
2780
2781 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002782 delay = 100;
dea31012005-04-17 16:05:31 -05002783 retry = 1;
2784 break;
2785
James Smart858c9f62007-06-17 19:56:39 -05002786 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002787 case IOERR_INVALID_RPI:
2788 retry = 1;
2789 break;
2790 }
2791 break;
2792
2793 case IOSTAT_NPORT_RJT:
2794 case IOSTAT_FABRIC_RJT:
2795 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2796 retry = 1;
2797 break;
2798 }
2799 break;
2800
2801 case IOSTAT_NPORT_BSY:
2802 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002803 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002804 retry = 1;
2805 break;
2806
2807 case IOSTAT_LS_RJT:
2808 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2809 /* Added for Vendor specifc support
2810 * Just keep retrying for these Rsn / Exp codes
2811 */
2812 switch (stat.un.b.lsRjtRsnCode) {
2813 case LSRJT_UNABLE_TPC:
2814 if (stat.un.b.lsRjtRsnCodeExp ==
2815 LSEXP_CMD_IN_PROGRESS) {
2816 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002817 delay = 1000;
dea31012005-04-17 16:05:31 -05002818 maxretry = 48;
2819 }
2820 retry = 1;
2821 break;
2822 }
James Smartffc95492010-06-07 15:23:17 -04002823 if (stat.un.b.lsRjtRsnCodeExp ==
2824 LSEXP_CANT_GIVE_DATA) {
2825 if (cmd == ELS_CMD_PLOGI) {
2826 delay = 1000;
2827 maxretry = 48;
2828 }
2829 retry = 1;
2830 break;
2831 }
dea31012005-04-17 16:05:31 -05002832 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002833 delay = 1000;
dea31012005-04-17 16:05:31 -05002834 maxretry = lpfc_max_els_tries + 1;
2835 retry = 1;
2836 break;
2837 }
James Smart92d7f7b2007-06-17 19:56:38 -05002838 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2839 (cmd == ELS_CMD_FDISC) &&
2840 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002841 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2842 "0125 FDISC Failed (x%x). "
2843 "Fabric out of resources\n",
2844 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002845 lpfc_vport_set_state(vport,
2846 FC_VPORT_NO_FABRIC_RSCS);
2847 }
dea31012005-04-17 16:05:31 -05002848 break;
2849
2850 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002851 if ((cmd == ELS_CMD_PLOGI) ||
2852 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002853 delay = 1000;
dea31012005-04-17 16:05:31 -05002854 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002855 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002856 /* FDISC retry policy */
2857 maxretry = 48;
2858 if (cmdiocb->retry >= 32)
2859 delay = 1000;
dea31012005-04-17 16:05:31 -05002860 }
2861 retry = 1;
2862 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002863
2864 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002865 /* There are some cases where switches return this
2866 * error when they are not ready and should be returning
2867 * Logical Busy. We should delay every time.
2868 */
2869 if (cmd == ELS_CMD_FDISC &&
2870 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2871 maxretry = 3;
2872 delay = 1000;
2873 retry = 1;
2874 break;
2875 }
James Smart92d7f7b2007-06-17 19:56:38 -05002876 case LSRJT_PROTOCOL_ERR:
2877 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2878 (cmd == ELS_CMD_FDISC) &&
2879 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2880 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2881 ) {
James Smarte8b62012007-08-02 11:10:09 -04002882 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002883 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002884 "Fabric Detected Bad WWN\n",
2885 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002886 lpfc_vport_set_state(vport,
2887 FC_VPORT_FABRIC_REJ_WWN);
2888 }
2889 break;
dea31012005-04-17 16:05:31 -05002890 }
2891 break;
2892
2893 case IOSTAT_INTERMED_RSP:
2894 case IOSTAT_BA_RJT:
2895 break;
2896
2897 default:
2898 break;
2899 }
2900
James Smart488d1462006-03-07 15:02:37 -05002901 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002902 retry = 1;
dea31012005-04-17 16:05:31 -05002903
James Smart695a8142010-01-26 23:08:03 -05002904 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002905 (phba->fc_topology != TOPOLOGY_LOOP) &&
2906 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002907 /* FLOGI retry policy */
2908 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002909 /* retry forever */
2910 maxretry = 0;
2911 if (cmdiocb->retry >= 100)
2912 delay = 5000;
2913 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002914 delay = 1000;
2915 }
2916
James Smart6669f9b2009-10-02 15:16:45 -04002917 cmdiocb->retry++;
2918 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002919 phba->fc_stat.elsRetryExceeded++;
2920 retry = 0;
2921 }
2922
James Smarted957682007-06-17 19:56:37 -05002923 if ((vport->load_flag & FC_UNLOADING) != 0)
2924 retry = 0;
2925
dea31012005-04-17 16:05:31 -05002926 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04002927 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2928 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2929 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2930 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2931 "2849 Stop retry ELS command "
2932 "x%x to remote NPORT x%x, "
2933 "Data: x%x x%x\n", cmd, did,
2934 cmdiocb->retry, delay);
2935 return 0;
2936 }
2937 }
dea31012005-04-17 16:05:31 -05002938
2939 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002940 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2941 "0107 Retry ELS command x%x to remote "
2942 "NPORT x%x Data: x%x x%x\n",
2943 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002944
James Smart858c9f62007-06-17 19:56:39 -05002945 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2946 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2947 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2948 /* Don't reset timer for no resources */
2949
dea31012005-04-17 16:05:31 -05002950 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002951 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002952 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002953 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002954 }
2955
2956 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002957 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002958 phba->fc_stat.elsDelayRetry++;
2959 ndlp->nlp_retry = cmdiocb->retry;
2960
James Smart92d7f7b2007-06-17 19:56:38 -05002961 /* delay is specified in milliseconds */
2962 mod_timer(&ndlp->nlp_delayfunc,
2963 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002964 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002965 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002966 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002967
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002968 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002969 if (cmd == ELS_CMD_PRLI)
2970 lpfc_nlp_set_state(vport, ndlp,
2971 NLP_STE_REG_LOGIN_ISSUE);
2972 else
2973 lpfc_nlp_set_state(vport, ndlp,
2974 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002975 ndlp->nlp_last_elscmd = cmd;
2976
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002977 return 1;
dea31012005-04-17 16:05:31 -05002978 }
2979 switch (cmd) {
2980 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002981 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002982 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002983 case ELS_CMD_FDISC:
2984 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2985 return 1;
dea31012005-04-17 16:05:31 -05002986 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002987 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002988 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002989 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002990 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002991 }
James Smart2e0fef82007-06-17 19:56:36 -05002992 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002993 return 1;
dea31012005-04-17 16:05:31 -05002994 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002995 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002996 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2997 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002998 return 1;
dea31012005-04-17 16:05:31 -05002999 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003000 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003001 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3002 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003003 return 1;
dea31012005-04-17 16:05:31 -05003004 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003005 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003006 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3007 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003008 return 1;
dea31012005-04-17 16:05:31 -05003009 }
3010 }
dea31012005-04-17 16:05:31 -05003011 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003012 if (logerr) {
3013 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3014 "0137 No retry ELS command x%x to remote "
3015 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3016 cmd, did, irsp->ulpStatus,
3017 irsp->un.ulpWord[4]);
3018 }
3019 else {
3020 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003021 "0108 No retry ELS command x%x to remote "
3022 "NPORT x%x Retried:%d Error:x%x/%x\n",
3023 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3024 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003025 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003026 return 0;
dea31012005-04-17 16:05:31 -05003027}
3028
James Smarte59058c2008-08-24 21:49:00 -04003029/**
James Smart3621a712009-04-06 18:47:14 -04003030 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003031 * @phba: pointer to lpfc hba data structure.
3032 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3033 *
3034 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3035 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3036 * checks to see whether there is a lpfc DMA buffer associated with the
3037 * response of the command IOCB. If so, it will be released before releasing
3038 * the lpfc DMA buffer associated with the IOCB itself.
3039 *
3040 * Return code
3041 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3042 **/
James Smart09372822008-01-11 01:52:54 -05003043static int
James Smart87af33f2007-10-27 13:37:43 -04003044lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3045{
3046 struct lpfc_dmabuf *buf_ptr;
3047
James Smarte59058c2008-08-24 21:49:00 -04003048 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003049 if (!list_empty(&buf_ptr1->list)) {
3050 list_remove_head(&buf_ptr1->list, buf_ptr,
3051 struct lpfc_dmabuf,
3052 list);
3053 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3054 kfree(buf_ptr);
3055 }
3056 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3057 kfree(buf_ptr1);
3058 return 0;
3059}
3060
James Smarte59058c2008-08-24 21:49:00 -04003061/**
James Smart3621a712009-04-06 18:47:14 -04003062 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003063 * @phba: pointer to lpfc hba data structure.
3064 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3065 *
3066 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3067 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3068 * pool.
3069 *
3070 * Return code
3071 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3072 **/
James Smart09372822008-01-11 01:52:54 -05003073static int
James Smart87af33f2007-10-27 13:37:43 -04003074lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3075{
3076 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3077 kfree(buf_ptr);
3078 return 0;
3079}
3080
James Smarte59058c2008-08-24 21:49:00 -04003081/**
James Smart3621a712009-04-06 18:47:14 -04003082 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003083 * @phba: pointer to lpfc hba data structure.
3084 * @elsiocb: pointer to lpfc els command iocb data structure.
3085 *
3086 * This routine frees a command IOCB and its associated resources. The
3087 * command IOCB data structure contains the reference to various associated
3088 * resources, these fields must be set to NULL if the associated reference
3089 * not present:
3090 * context1 - reference to ndlp
3091 * context2 - reference to cmd
3092 * context2->next - reference to rsp
3093 * context3 - reference to bpl
3094 *
3095 * It first properly decrements the reference count held on ndlp for the
3096 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3097 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3098 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3099 * adds the DMA buffer the @phba data structure for the delayed release.
3100 * If reference to the Buffer Pointer List (BPL) is present, the
3101 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3102 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3103 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3104 *
3105 * Return code
3106 * 0 - Success (currently, always return 0)
3107 **/
James Smart87af33f2007-10-27 13:37:43 -04003108int
James Smart329f9bc2007-04-25 09:53:01 -04003109lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003110{
3111 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003112 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003113
James Smarta8adb832007-10-27 13:37:53 -04003114 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3115 if (ndlp) {
3116 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3117 lpfc_nlp_put(ndlp);
3118
3119 /* If the ndlp is not being used by another discovery
3120 * thread, free it.
3121 */
3122 if (!lpfc_nlp_not_used(ndlp)) {
3123 /* If ndlp is being used by another discovery
3124 * thread, just clear NLP_DEFER_RM
3125 */
3126 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3127 }
3128 }
3129 else
3130 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003131 elsiocb->context1 = NULL;
3132 }
dea31012005-04-17 16:05:31 -05003133 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3134 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003135 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3136 /* Firmware could still be in progress of DMAing
3137 * payload, so don't free data buffer till after
3138 * a hbeat.
3139 */
3140 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3141 buf_ptr = elsiocb->context2;
3142 elsiocb->context2 = NULL;
3143 if (buf_ptr) {
3144 buf_ptr1 = NULL;
3145 spin_lock_irq(&phba->hbalock);
3146 if (!list_empty(&buf_ptr->list)) {
3147 list_remove_head(&buf_ptr->list,
3148 buf_ptr1, struct lpfc_dmabuf,
3149 list);
3150 INIT_LIST_HEAD(&buf_ptr1->list);
3151 list_add_tail(&buf_ptr1->list,
3152 &phba->elsbuf);
3153 phba->elsbuf_cnt++;
3154 }
3155 INIT_LIST_HEAD(&buf_ptr->list);
3156 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3157 phba->elsbuf_cnt++;
3158 spin_unlock_irq(&phba->hbalock);
3159 }
3160 } else {
3161 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3162 lpfc_els_free_data(phba, buf_ptr1);
3163 }
dea31012005-04-17 16:05:31 -05003164 }
3165
3166 if (elsiocb->context3) {
3167 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003168 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003169 }
James Bottomley604a3e32005-10-29 10:28:33 -05003170 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003171 return 0;
3172}
3173
James Smarte59058c2008-08-24 21:49:00 -04003174/**
James Smart3621a712009-04-06 18:47:14 -04003175 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003176 * @phba: pointer to lpfc hba data structure.
3177 * @cmdiocb: pointer to lpfc command iocb data structure.
3178 * @rspiocb: pointer to lpfc response iocb data structure.
3179 *
3180 * This routine is the completion callback function to the Logout (LOGO)
3181 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3182 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3183 * release the ndlp if it has the last reference remaining (reference count
3184 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3185 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3186 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3187 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3188 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3189 * IOCB data structure.
3190 **/
dea31012005-04-17 16:05:31 -05003191static void
James Smart2e0fef82007-06-17 19:56:36 -05003192lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3193 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003194{
James Smart2e0fef82007-06-17 19:56:36 -05003195 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3196 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003197 IOCB_t *irsp;
3198
3199 irsp = &rspiocb->iocb;
3200 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3201 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3202 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003203 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003204 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3205 "0109 ACC to LOGO completes to NPort x%x "
3206 "Data: x%x x%x x%x\n",
3207 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3208 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003209
3210 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3211 /* NPort Recovery mode or node is just allocated */
3212 if (!lpfc_nlp_not_used(ndlp)) {
3213 /* If the ndlp is being used by another discovery
3214 * thread, just unregister the RPI.
3215 */
3216 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003217 } else {
3218 /* Indicate the node has already released, should
3219 * not reference to it from within lpfc_els_free_iocb.
3220 */
3221 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003222 }
dea31012005-04-17 16:05:31 -05003223 }
3224 lpfc_els_free_iocb(phba, cmdiocb);
3225 return;
3226}
3227
James Smarte59058c2008-08-24 21:49:00 -04003228/**
James Smart3621a712009-04-06 18:47:14 -04003229 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003230 * @phba: pointer to lpfc hba data structure.
3231 * @pmb: pointer to the driver internal queue element for mailbox command.
3232 *
3233 * This routine is the completion callback function for unregister default
3234 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3235 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3236 * decrements the ndlp reference count held for this completion callback
3237 * function. After that, it invokes the lpfc_nlp_not_used() to check
3238 * whether there is only one reference left on the ndlp. If so, it will
3239 * perform one more decrement and trigger the release of the ndlp.
3240 **/
James Smart858c9f62007-06-17 19:56:39 -05003241void
3242lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3243{
3244 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3245 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3246
James Smart6fb120a2009-05-22 14:52:59 -04003247 /*
3248 * This routine is used to register and unregister in previous SLI
3249 * modes.
3250 */
3251 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3252 (phba->sli_rev == LPFC_SLI_REV4))
3253 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3254
James Smart858c9f62007-06-17 19:56:39 -05003255 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003256 pmb->context2 = NULL;
3257
James Smart858c9f62007-06-17 19:56:39 -05003258 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3259 kfree(mp);
3260 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003261 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003262 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003263 /* This is the end of the default RPI cleanup logic for this
3264 * ndlp. If no other discovery threads are using this ndlp.
3265 * we should free all resources associated with it.
3266 */
3267 lpfc_nlp_not_used(ndlp);
3268 }
James Smart3772a992009-05-22 14:50:54 -04003269
James Smart858c9f62007-06-17 19:56:39 -05003270 return;
3271}
3272
James Smarte59058c2008-08-24 21:49:00 -04003273/**
James Smart3621a712009-04-06 18:47:14 -04003274 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003275 * @phba: pointer to lpfc hba data structure.
3276 * @cmdiocb: pointer to lpfc command iocb data structure.
3277 * @rspiocb: pointer to lpfc response iocb data structure.
3278 *
3279 * This routine is the completion callback function for ELS Response IOCB
3280 * command. In normal case, this callback function just properly sets the
3281 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3282 * field in the command IOCB is not NULL, the referred mailbox command will
3283 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3284 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3285 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3286 * routine shall be invoked trying to release the ndlp if no other threads
3287 * are currently referring it.
3288 **/
dea31012005-04-17 16:05:31 -05003289static void
James Smart858c9f62007-06-17 19:56:39 -05003290lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003291 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003292{
James Smart2e0fef82007-06-17 19:56:36 -05003293 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3294 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3295 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003296 IOCB_t *irsp;
3297 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003298 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003299 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003300 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003301
James Smart33ccf8d2006-08-17 11:57:58 -04003302 irsp = &rspiocb->iocb;
3303
dea31012005-04-17 16:05:31 -05003304 if (cmdiocb->context_un.mbox)
3305 mbox = cmdiocb->context_un.mbox;
3306
James Smartfa4066b2008-01-11 01:53:27 -05003307 /* First determine if this is a LS_RJT cmpl. Note, this callback
3308 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3309 */
James Smart87af33f2007-10-27 13:37:43 -04003310 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003311 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3312 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003313 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003314 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003315 */
3316 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3317 ls_rjt = 1;
3318 }
3319
dea31012005-04-17 16:05:31 -05003320 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003321 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003322 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003323 mp = (struct lpfc_dmabuf *) mbox->context1;
3324 if (mp) {
3325 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3326 kfree(mp);
3327 }
James Smart329f9bc2007-04-25 09:53:01 -04003328 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003329 }
James Smart58da1ff2008-04-07 10:15:56 -04003330 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3331 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003332 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003333 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003334 /* Indicate the node has already released,
3335 * should not reference to it from within
3336 * the routine lpfc_els_free_iocb.
3337 */
3338 cmdiocb->context1 = NULL;
3339 }
dea31012005-04-17 16:05:31 -05003340 goto out;
3341 }
3342
James Smart858c9f62007-06-17 19:56:39 -05003343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003344 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003345 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003346 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003347 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003348 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3349 "0110 ELS response tag x%x completes "
3350 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3351 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3352 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3353 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3354 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003355 if (mbox) {
3356 if ((rspiocb->iocb.ulpStatus == 0)
3357 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003358 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003359 /* Increment reference count to ndlp to hold the
3360 * reference to ndlp for the callback function.
3361 */
James Smart329f9bc2007-04-25 09:53:01 -04003362 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003363 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003364 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3365 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3366 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3367 }
3368 else {
3369 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3370 ndlp->nlp_prev_state = ndlp->nlp_state;
3371 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003372 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003373 }
James Smart0b727fe2007-10-27 13:37:25 -04003374 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003375 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003376 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003377 else
3378 /* Decrement the ndlp reference count we
3379 * set for this failed mailbox command.
3380 */
3381 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003382
3383 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3384 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3385 "0138 ELS rsp: Cannot issue reg_login for x%x "
3386 "Data: x%x x%x x%x\n",
3387 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3388 ndlp->nlp_rpi);
3389
James Smartfa4066b2008-01-11 01:53:27 -05003390 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003391 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003392 /* Indicate node has already been released,
3393 * should not reference to it from within
3394 * the routine lpfc_els_free_iocb.
3395 */
3396 cmdiocb->context1 = NULL;
3397 }
dea31012005-04-17 16:05:31 -05003398 } else {
James Smart858c9f62007-06-17 19:56:39 -05003399 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3400 if (!lpfc_error_lost_link(irsp) &&
3401 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003402 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003403 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003404 /* Indicate node has already been
3405 * released, should not reference
3406 * to it from within the routine
3407 * lpfc_els_free_iocb.
3408 */
3409 cmdiocb->context1 = NULL;
3410 }
dea31012005-04-17 16:05:31 -05003411 }
3412 }
James Smart14691152006-12-02 13:34:28 -05003413 mp = (struct lpfc_dmabuf *) mbox->context1;
3414 if (mp) {
3415 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3416 kfree(mp);
3417 }
3418 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003419 }
3420out:
James Smart58da1ff2008-04-07 10:15:56 -04003421 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003422 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003423 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003424 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003425
3426 /* If the node is not being used by another discovery thread,
3427 * and we are sending a reject, we are done with it.
3428 * Release driver reference count here and free associated
3429 * resources.
3430 */
3431 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003432 if (lpfc_nlp_not_used(ndlp))
3433 /* Indicate node has already been released,
3434 * should not reference to it from within
3435 * the routine lpfc_els_free_iocb.
3436 */
3437 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003438 }
James Smart87af33f2007-10-27 13:37:43 -04003439
dea31012005-04-17 16:05:31 -05003440 lpfc_els_free_iocb(phba, cmdiocb);
3441 return;
3442}
3443
James Smarte59058c2008-08-24 21:49:00 -04003444/**
James Smart3621a712009-04-06 18:47:14 -04003445 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003446 * @vport: pointer to a host virtual N_Port data structure.
3447 * @flag: the els command code to be accepted.
3448 * @oldiocb: pointer to the original lpfc command iocb data structure.
3449 * @ndlp: pointer to a node-list data structure.
3450 * @mbox: pointer to the driver internal queue element for mailbox command.
3451 *
3452 * This routine prepares and issues an Accept (ACC) response IOCB
3453 * command. It uses the @flag to properly set up the IOCB field for the
3454 * specific ACC response command to be issued and invokes the
3455 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3456 * @mbox pointer is passed in, it will be put into the context_un.mbox
3457 * field of the IOCB for the completion callback function to issue the
3458 * mailbox command to the HBA later when callback is invoked.
3459 *
3460 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3461 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3462 * will be stored into the context1 field of the IOCB for the completion
3463 * callback function to the corresponding response ELS IOCB command.
3464 *
3465 * Return code
3466 * 0 - Successfully issued acc response
3467 * 1 - Failed to issue acc response
3468 **/
dea31012005-04-17 16:05:31 -05003469int
James Smart2e0fef82007-06-17 19:56:36 -05003470lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3471 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003472 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003473{
James Smart2e0fef82007-06-17 19:56:36 -05003474 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3475 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003476 IOCB_t *icmd;
3477 IOCB_t *oldcmd;
3478 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003479 struct lpfc_sli *psli;
3480 uint8_t *pcmd;
3481 uint16_t cmdsize;
3482 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003483 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003484
3485 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003486 oldcmd = &oldiocb->iocb;
3487
3488 switch (flag) {
3489 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003490 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003491 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3492 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003493 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003494 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003495 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003496 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003497 return 1;
dea31012005-04-17 16:05:31 -05003498 }
James Smart2e0fef82007-06-17 19:56:36 -05003499
dea31012005-04-17 16:05:31 -05003500 icmd = &elsiocb->iocb;
3501 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3502 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3503 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003504 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003505
3506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3507 "Issue ACC: did:x%x flg:x%x",
3508 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003509 break;
3510 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003511 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003512 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3513 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003514 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003515 return 1;
James Smart488d1462006-03-07 15:02:37 -05003516
dea31012005-04-17 16:05:31 -05003517 icmd = &elsiocb->iocb;
3518 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3519 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3520
3521 if (mbox)
3522 elsiocb->context_un.mbox = mbox;
3523
3524 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003525 pcmd += sizeof(uint32_t);
3526 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003527
3528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3529 "Issue ACC PLOGI: did:x%x flg:x%x",
3530 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003531 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003532 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003533 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003534 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003535 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3536 if (!elsiocb)
3537 return 1;
3538
3539 icmd = &elsiocb->iocb;
3540 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3541 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3542
3543 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003544 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003545 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3546 els_pkt_ptr = (ELS_PKT *) pcmd;
3547 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003548
3549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3550 "Issue ACC PRLO: did:x%x flg:x%x",
3551 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003552 break;
dea31012005-04-17 16:05:31 -05003553 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003554 return 1;
dea31012005-04-17 16:05:31 -05003555 }
dea31012005-04-17 16:05:31 -05003556 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003557 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3558 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3559 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3560 elsiocb->iotag, elsiocb->iocb.ulpContext,
3561 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3562 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003563 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003564 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003565 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003566 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003567 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3568 } else {
James Smart858c9f62007-06-17 19:56:39 -05003569 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003570 }
3571
3572 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003573 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003574 if (rc == IOCB_ERROR) {
3575 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003576 return 1;
dea31012005-04-17 16:05:31 -05003577 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003578 return 0;
dea31012005-04-17 16:05:31 -05003579}
3580
James Smarte59058c2008-08-24 21:49:00 -04003581/**
James Smart3621a712009-04-06 18:47:14 -04003582 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003583 * @vport: pointer to a virtual N_Port data structure.
3584 * @rejectError:
3585 * @oldiocb: pointer to the original lpfc command iocb data structure.
3586 * @ndlp: pointer to a node-list data structure.
3587 * @mbox: pointer to the driver internal queue element for mailbox command.
3588 *
3589 * This routine prepares and issue an Reject (RJT) response IOCB
3590 * command. If a @mbox pointer is passed in, it will be put into the
3591 * context_un.mbox field of the IOCB for the completion callback function
3592 * to issue to the HBA later.
3593 *
3594 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3595 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3596 * will be stored into the context1 field of the IOCB for the completion
3597 * callback function to the reject response ELS IOCB command.
3598 *
3599 * Return code
3600 * 0 - Successfully issued reject response
3601 * 1 - Failed to issue reject response
3602 **/
dea31012005-04-17 16:05:31 -05003603int
James Smart2e0fef82007-06-17 19:56:36 -05003604lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003605 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3606 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003607{
James Smart2e0fef82007-06-17 19:56:36 -05003608 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003609 IOCB_t *icmd;
3610 IOCB_t *oldcmd;
3611 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003612 struct lpfc_sli *psli;
3613 uint8_t *pcmd;
3614 uint16_t cmdsize;
3615 int rc;
3616
3617 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003618 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003619 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3620 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003621 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003622 return 1;
dea31012005-04-17 16:05:31 -05003623
3624 icmd = &elsiocb->iocb;
3625 oldcmd = &oldiocb->iocb;
3626 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3627 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3628
3629 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003630 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003631 *((uint32_t *) (pcmd)) = rejectError;
3632
James Smart51ef4c22007-08-02 11:10:31 -04003633 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003634 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003635
dea31012005-04-17 16:05:31 -05003636 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003637 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3638 "0129 Xmit ELS RJT x%x response tag x%x "
3639 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3640 "rpi x%x\n",
3641 rejectError, elsiocb->iotag,
3642 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3643 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003644 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3645 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3646 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3647
dea31012005-04-17 16:05:31 -05003648 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003649 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003650 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003651
dea31012005-04-17 16:05:31 -05003652 if (rc == IOCB_ERROR) {
3653 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003654 return 1;
dea31012005-04-17 16:05:31 -05003655 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003656 return 0;
dea31012005-04-17 16:05:31 -05003657}
3658
James Smarte59058c2008-08-24 21:49:00 -04003659/**
James Smart3621a712009-04-06 18:47:14 -04003660 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003661 * @vport: pointer to a virtual N_Port data structure.
3662 * @oldiocb: pointer to the original lpfc command iocb data structure.
3663 * @ndlp: pointer to a node-list data structure.
3664 *
3665 * This routine prepares and issues an Accept (ACC) response to Address
3666 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3667 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3668 *
3669 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3670 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3671 * will be stored into the context1 field of the IOCB for the completion
3672 * callback function to the ADISC Accept response ELS IOCB command.
3673 *
3674 * Return code
3675 * 0 - Successfully issued acc adisc response
3676 * 1 - Failed to issue adisc acc response
3677 **/
dea31012005-04-17 16:05:31 -05003678int
James Smart2e0fef82007-06-17 19:56:36 -05003679lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3680 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003681{
James Smart2e0fef82007-06-17 19:56:36 -05003682 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003683 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003684 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003685 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003686 uint8_t *pcmd;
3687 uint16_t cmdsize;
3688 int rc;
3689
James Smart92d7f7b2007-06-17 19:56:38 -05003690 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003691 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3692 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003693 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003694 return 1;
dea31012005-04-17 16:05:31 -05003695
dea31012005-04-17 16:05:31 -05003696 icmd = &elsiocb->iocb;
3697 oldcmd = &oldiocb->iocb;
3698 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003699
3700 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003701 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3702 "0130 Xmit ADISC ACC response iotag x%x xri: "
3703 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3704 elsiocb->iotag, elsiocb->iocb.ulpContext,
3705 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3706 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003707 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3708
3709 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003710 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003711
3712 ap = (ADISC *) (pcmd);
3713 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003714 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3715 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003716 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003717
James Smart858c9f62007-06-17 19:56:39 -05003718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3719 "Issue ACC ADISC: did:x%x flg:x%x",
3720 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3721
dea31012005-04-17 16:05:31 -05003722 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003723 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003724 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003725 if (rc == IOCB_ERROR) {
3726 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003727 return 1;
dea31012005-04-17 16:05:31 -05003728 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003729 return 0;
dea31012005-04-17 16:05:31 -05003730}
3731
James Smarte59058c2008-08-24 21:49:00 -04003732/**
James Smart3621a712009-04-06 18:47:14 -04003733 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003734 * @vport: pointer to a virtual N_Port data structure.
3735 * @oldiocb: pointer to the original lpfc command iocb data structure.
3736 * @ndlp: pointer to a node-list data structure.
3737 *
3738 * This routine prepares and issues an Accept (ACC) response to Process
3739 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3740 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3741 *
3742 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3743 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3744 * will be stored into the context1 field of the IOCB for the completion
3745 * callback function to the PRLI Accept response ELS IOCB command.
3746 *
3747 * Return code
3748 * 0 - Successfully issued acc prli response
3749 * 1 - Failed to issue acc prli response
3750 **/
dea31012005-04-17 16:05:31 -05003751int
James Smart2e0fef82007-06-17 19:56:36 -05003752lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003753 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003754{
James Smart2e0fef82007-06-17 19:56:36 -05003755 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003756 PRLI *npr;
3757 lpfc_vpd_t *vpd;
3758 IOCB_t *icmd;
3759 IOCB_t *oldcmd;
3760 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003761 struct lpfc_sli *psli;
3762 uint8_t *pcmd;
3763 uint16_t cmdsize;
3764 int rc;
3765
3766 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003767
James Smart92d7f7b2007-06-17 19:56:38 -05003768 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003769 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003770 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003771 if (!elsiocb)
3772 return 1;
dea31012005-04-17 16:05:31 -05003773
dea31012005-04-17 16:05:31 -05003774 icmd = &elsiocb->iocb;
3775 oldcmd = &oldiocb->iocb;
3776 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003777 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003778 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3779 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3780 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3781 elsiocb->iotag, elsiocb->iocb.ulpContext,
3782 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3783 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003784 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3785
3786 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003787 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003788
3789 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003790 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003791
3792 npr = (PRLI *) pcmd;
3793 vpd = &phba->vpd;
3794 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003795 * If the remote port is a target and our firmware version is 3.20 or
3796 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003797 */
James Smart0d2b6b82008-06-14 22:52:47 -04003798 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3799 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003800 npr->ConfmComplAllowed = 1;
3801 npr->Retry = 1;
3802 npr->TaskRetryIdReq = 1;
3803 }
3804
3805 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3806 npr->estabImagePair = 1;
3807 npr->readXferRdyDis = 1;
3808 npr->ConfmComplAllowed = 1;
3809
3810 npr->prliType = PRLI_FCP_TYPE;
3811 npr->initiatorFunc = 1;
3812
James Smart858c9f62007-06-17 19:56:39 -05003813 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3814 "Issue ACC PRLI: did:x%x flg:x%x",
3815 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3816
dea31012005-04-17 16:05:31 -05003817 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003818 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003819
James Smart3772a992009-05-22 14:50:54 -04003820 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003821 if (rc == IOCB_ERROR) {
3822 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003823 return 1;
dea31012005-04-17 16:05:31 -05003824 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003825 return 0;
dea31012005-04-17 16:05:31 -05003826}
3827
James Smarte59058c2008-08-24 21:49:00 -04003828/**
James Smart3621a712009-04-06 18:47:14 -04003829 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003830 * @vport: pointer to a virtual N_Port data structure.
3831 * @format: rnid command format.
3832 * @oldiocb: pointer to the original lpfc command iocb data structure.
3833 * @ndlp: pointer to a node-list data structure.
3834 *
3835 * This routine issues a Request Node Identification Data (RNID) Accept
3836 * (ACC) response. It constructs the RNID ACC response command according to
3837 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3838 * issue the response. Note that this command does not need to hold the ndlp
3839 * reference count for the callback. So, the ndlp reference count taken by
3840 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3841 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3842 * there is no ndlp reference available.
3843 *
3844 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3845 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3846 * will be stored into the context1 field of the IOCB for the completion
3847 * callback function. However, for the RNID Accept Response ELS command,
3848 * this is undone later by this routine after the IOCB is allocated.
3849 *
3850 * Return code
3851 * 0 - Successfully issued acc rnid response
3852 * 1 - Failed to issue acc rnid response
3853 **/
dea31012005-04-17 16:05:31 -05003854static int
James Smart2e0fef82007-06-17 19:56:36 -05003855lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003856 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003857{
James Smart2e0fef82007-06-17 19:56:36 -05003858 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003859 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003860 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003861 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003862 struct lpfc_sli *psli;
3863 uint8_t *pcmd;
3864 uint16_t cmdsize;
3865 int rc;
3866
3867 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003868 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3869 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003870 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003871 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003872
James Smart2e0fef82007-06-17 19:56:36 -05003873 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3874 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003875 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003876 return 1;
dea31012005-04-17 16:05:31 -05003877
dea31012005-04-17 16:05:31 -05003878 icmd = &elsiocb->iocb;
3879 oldcmd = &oldiocb->iocb;
3880 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003881 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003882 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3883 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3884 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003885 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003886 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003887 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003888
James Smart92d7f7b2007-06-17 19:56:38 -05003889 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003890 rn = (RNID *) (pcmd);
3891 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003892 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3893 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3894 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003895 switch (format) {
3896 case 0:
3897 rn->SpecificLen = 0;
3898 break;
3899 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003900 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003901 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003902 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003903 rn->un.topologyDisc.unitType = RNID_HBA;
3904 rn->un.topologyDisc.physPort = 0;
3905 rn->un.topologyDisc.attachedNodes = 0;
3906 break;
3907 default:
3908 rn->CommonLen = 0;
3909 rn->SpecificLen = 0;
3910 break;
3911 }
3912
James Smart858c9f62007-06-17 19:56:39 -05003913 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3914 "Issue ACC RNID: did:x%x flg:x%x",
3915 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3916
dea31012005-04-17 16:05:31 -05003917 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003918 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003919 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003920 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3921 * it could be freed */
3922
James Smart3772a992009-05-22 14:50:54 -04003923 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003924 if (rc == IOCB_ERROR) {
3925 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003926 return 1;
dea31012005-04-17 16:05:31 -05003927 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003928 return 0;
dea31012005-04-17 16:05:31 -05003929}
3930
James Smarte59058c2008-08-24 21:49:00 -04003931/**
James Smart12265f62010-10-22 11:05:53 -04003932 * lpfc_els_rsp_echo_acc - Issue echo acc response
3933 * @vport: pointer to a virtual N_Port data structure.
3934 * @data: pointer to echo data to return in the accept.
3935 * @oldiocb: pointer to the original lpfc command iocb data structure.
3936 * @ndlp: pointer to a node-list data structure.
3937 *
3938 * Return code
3939 * 0 - Successfully issued acc echo response
3940 * 1 - Failed to issue acc echo response
3941 **/
3942static int
3943lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3944 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3945{
3946 struct lpfc_hba *phba = vport->phba;
3947 struct lpfc_iocbq *elsiocb;
3948 struct lpfc_sli *psli;
3949 uint8_t *pcmd;
3950 uint16_t cmdsize;
3951 int rc;
3952
3953 psli = &phba->sli;
3954 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3955
3956 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3957 ndlp->nlp_DID, ELS_CMD_ACC);
3958 if (!elsiocb)
3959 return 1;
3960
3961 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3962 /* Xmit ECHO ACC response tag <ulpIoTag> */
3963 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3964 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3965 elsiocb->iotag, elsiocb->iocb.ulpContext);
3966 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3967 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3968 pcmd += sizeof(uint32_t);
3969 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3970
3971 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3972 "Issue ACC ECHO: did:x%x flg:x%x",
3973 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3974
3975 phba->fc_stat.elsXmitACC++;
3976 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3977 lpfc_nlp_put(ndlp);
3978 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3979 * it could be freed */
3980
3981 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3982 if (rc == IOCB_ERROR) {
3983 lpfc_els_free_iocb(phba, elsiocb);
3984 return 1;
3985 }
3986 return 0;
3987}
3988
3989/**
James Smart3621a712009-04-06 18:47:14 -04003990 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003991 * @vport: pointer to a host virtual N_Port data structure.
3992 *
3993 * This routine issues Address Discover (ADISC) ELS commands to those
3994 * N_Ports which are in node port recovery state and ADISC has not been issued
3995 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3996 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3997 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3998 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3999 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4000 * IOCBs quit for later pick up. On the other hand, after walking through
4001 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4002 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4003 * no more ADISC need to be sent.
4004 *
4005 * Return code
4006 * The number of N_Ports with adisc issued.
4007 **/
dea31012005-04-17 16:05:31 -05004008int
James Smart2e0fef82007-06-17 19:56:36 -05004009lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004010{
James Smart2e0fef82007-06-17 19:56:36 -05004011 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004012 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004013 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004014
James Smart685f0bf2007-04-25 09:53:08 -04004015 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004016 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004017 if (!NLP_CHK_NODE_ACT(ndlp))
4018 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004019 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4020 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4021 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004022 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004023 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004024 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004025 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004026 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4027 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004028 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004029 vport->num_disc_nodes++;
4030 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004031 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004032 spin_lock_irq(shost->host_lock);
4033 vport->fc_flag |= FC_NLP_MORE;
4034 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004035 break;
dea31012005-04-17 16:05:31 -05004036 }
4037 }
4038 }
4039 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004040 spin_lock_irq(shost->host_lock);
4041 vport->fc_flag &= ~FC_NLP_MORE;
4042 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004043 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004044 return sentadisc;
dea31012005-04-17 16:05:31 -05004045}
4046
James Smarte59058c2008-08-24 21:49:00 -04004047/**
James Smart3621a712009-04-06 18:47:14 -04004048 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004049 * @vport: pointer to a host virtual N_Port data structure.
4050 *
4051 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4052 * which are in node port recovery state, with a @vport. Each time an ELS
4053 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4054 * the per @vport number of discover count (num_disc_nodes) shall be
4055 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4056 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4057 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4058 * later pick up. On the other hand, after walking through all the ndlps with
4059 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4060 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4061 * PLOGI need to be sent.
4062 *
4063 * Return code
4064 * The number of N_Ports with plogi issued.
4065 **/
dea31012005-04-17 16:05:31 -05004066int
James Smart2e0fef82007-06-17 19:56:36 -05004067lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004068{
James Smart2e0fef82007-06-17 19:56:36 -05004069 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004070 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004071 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004072
James Smart2e0fef82007-06-17 19:56:36 -05004073 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4074 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004075 if (!NLP_CHK_NODE_ACT(ndlp))
4076 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004077 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4078 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4079 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4080 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4081 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4083 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004084 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004085 vport->num_disc_nodes++;
4086 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004087 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004088 spin_lock_irq(shost->host_lock);
4089 vport->fc_flag |= FC_NLP_MORE;
4090 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004091 break;
dea31012005-04-17 16:05:31 -05004092 }
4093 }
4094 }
James Smart87af33f2007-10-27 13:37:43 -04004095 if (sentplogi) {
4096 lpfc_set_disctmo(vport);
4097 }
4098 else {
James Smart2e0fef82007-06-17 19:56:36 -05004099 spin_lock_irq(shost->host_lock);
4100 vport->fc_flag &= ~FC_NLP_MORE;
4101 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004102 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004103 return sentplogi;
dea31012005-04-17 16:05:31 -05004104}
4105
James Smarte59058c2008-08-24 21:49:00 -04004106/**
James Smart3621a712009-04-06 18:47:14 -04004107 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004108 * @vport: pointer to a host virtual N_Port data structure.
4109 *
4110 * This routine cleans up any Registration State Change Notification
4111 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4112 * @vport together with the host_lock is used to prevent multiple thread
4113 * trying to access the RSCN array on a same @vport at the same time.
4114 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004115void
James Smart2e0fef82007-06-17 19:56:36 -05004116lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004117{
James Smart2e0fef82007-06-17 19:56:36 -05004118 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4119 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004120 int i;
4121
James Smart7f5f3d02008-02-08 18:50:14 -05004122 spin_lock_irq(shost->host_lock);
4123 if (vport->fc_rscn_flush) {
4124 /* Another thread is walking fc_rscn_id_list on this vport */
4125 spin_unlock_irq(shost->host_lock);
4126 return;
4127 }
4128 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4129 vport->fc_rscn_flush = 1;
4130 spin_unlock_irq(shost->host_lock);
4131
James Smart2e0fef82007-06-17 19:56:36 -05004132 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004133 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004134 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004135 }
James Smart2e0fef82007-06-17 19:56:36 -05004136 spin_lock_irq(shost->host_lock);
4137 vport->fc_rscn_id_cnt = 0;
4138 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4139 spin_unlock_irq(shost->host_lock);
4140 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004141 /* Indicate we are done walking this fc_rscn_id_list */
4142 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004143}
4144
James Smarte59058c2008-08-24 21:49:00 -04004145/**
James Smart3621a712009-04-06 18:47:14 -04004146 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004147 * @vport: pointer to a host virtual N_Port data structure.
4148 * @did: remote destination port identifier.
4149 *
4150 * This routine checks whether there is any pending Registration State
4151 * Configuration Notification (RSCN) to a @did on @vport.
4152 *
4153 * Return code
4154 * None zero - The @did matched with a pending rscn
4155 * 0 - not able to match @did with a pending rscn
4156 **/
dea31012005-04-17 16:05:31 -05004157int
James Smart2e0fef82007-06-17 19:56:36 -05004158lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004159{
4160 D_ID ns_did;
4161 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004162 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004163 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004164 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004165
4166 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004167
4168 /* Never match fabric nodes for RSCNs */
4169 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004170 return 0;
dea31012005-04-17 16:05:31 -05004171
4172 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004173 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004174 return did;
dea31012005-04-17 16:05:31 -05004175
James Smart7f5f3d02008-02-08 18:50:14 -05004176 spin_lock_irq(shost->host_lock);
4177 if (vport->fc_rscn_flush) {
4178 /* Another thread is walking fc_rscn_id_list on this vport */
4179 spin_unlock_irq(shost->host_lock);
4180 return 0;
4181 }
4182 /* Indicate we are walking fc_rscn_id_list on this vport */
4183 vport->fc_rscn_flush = 1;
4184 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004185 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004186 lp = vport->fc_rscn_id_list[i]->virt;
4187 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4188 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004189 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004190 rscn_did.un.word = be32_to_cpu(*lp++);
4191 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004192 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4193 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004194 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4195 && (ns_did.un.b.area == rscn_did.un.b.area)
4196 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004197 goto return_did_out;
dea31012005-04-17 16:05:31 -05004198 break;
James Smarteaf15d52008-12-04 22:39:29 -05004199 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004200 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4201 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004202 goto return_did_out;
dea31012005-04-17 16:05:31 -05004203 break;
James Smarteaf15d52008-12-04 22:39:29 -05004204 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004205 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004206 goto return_did_out;
dea31012005-04-17 16:05:31 -05004207 break;
James Smarteaf15d52008-12-04 22:39:29 -05004208 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004209 goto return_did_out;
dea31012005-04-17 16:05:31 -05004210 }
4211 }
James Smart92d7f7b2007-06-17 19:56:38 -05004212 }
James Smart7f5f3d02008-02-08 18:50:14 -05004213 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4214 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004215 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004216return_did_out:
4217 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4218 vport->fc_rscn_flush = 0;
4219 return did;
dea31012005-04-17 16:05:31 -05004220}
4221
James Smarte59058c2008-08-24 21:49:00 -04004222/**
James Smart3621a712009-04-06 18:47:14 -04004223 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004224 * @vport: pointer to a host virtual N_Port data structure.
4225 *
4226 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4227 * state machine for a @vport's nodes that are with pending RSCN (Registration
4228 * State Change Notification).
4229 *
4230 * Return code
4231 * 0 - Successful (currently alway return 0)
4232 **/
dea31012005-04-17 16:05:31 -05004233static int
James Smart2e0fef82007-06-17 19:56:36 -05004234lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004235{
James Smart685f0bf2007-04-25 09:53:08 -04004236 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004237
James Smart0d2b6b82008-06-14 22:52:47 -04004238 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004239 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004240 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004241 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4242 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004243 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004244 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004245 NLP_EVT_DEVICE_RECOVERY);
4246 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004247 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004248 return 0;
dea31012005-04-17 16:05:31 -05004249}
4250
James Smarte59058c2008-08-24 21:49:00 -04004251/**
James Smart3621a712009-04-06 18:47:14 -04004252 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004253 * @vport: pointer to a host virtual N_Port data structure.
4254 * @cmdiocb: pointer to lpfc command iocb data structure.
4255 *
4256 * lpfc_send_rscn_event sends an RSCN netlink event to management
4257 * applications.
4258 */
4259static void
4260lpfc_send_rscn_event(struct lpfc_vport *vport,
4261 struct lpfc_iocbq *cmdiocb)
4262{
4263 struct lpfc_dmabuf *pcmd;
4264 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4265 uint32_t *payload_ptr;
4266 uint32_t payload_len;
4267 struct lpfc_rscn_event_header *rscn_event_data;
4268
4269 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4270 payload_ptr = (uint32_t *) pcmd->virt;
4271 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4272
4273 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4274 payload_len, GFP_KERNEL);
4275 if (!rscn_event_data) {
4276 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4277 "0147 Failed to allocate memory for RSCN event\n");
4278 return;
4279 }
4280 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4281 rscn_event_data->payload_length = payload_len;
4282 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4283 payload_len);
4284
4285 fc_host_post_vendor_event(shost,
4286 fc_get_event_number(),
4287 sizeof(struct lpfc_els_event_header) + payload_len,
4288 (char *)rscn_event_data,
4289 LPFC_NL_VENDOR_ID);
4290
4291 kfree(rscn_event_data);
4292}
4293
4294/**
James Smart3621a712009-04-06 18:47:14 -04004295 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004296 * @vport: pointer to a host virtual N_Port data structure.
4297 * @cmdiocb: pointer to lpfc command iocb data structure.
4298 * @ndlp: pointer to a node-list data structure.
4299 *
4300 * This routine processes an unsolicited RSCN (Registration State Change
4301 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4302 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4303 * discover state machine is about to begin discovery, it just accepts the
4304 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4305 * contains N_Port IDs for other vports on this HBA, it just accepts the
4306 * RSCN and ignore processing it. If the state machine is in the recovery
4307 * state, the fc_rscn_id_list of this @vport is walked and the
4308 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4309 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4310 * routine is invoked to handle the RSCN event.
4311 *
4312 * Return code
4313 * 0 - Just sent the acc response
4314 * 1 - Sent the acc response and waited for name server completion
4315 **/
dea31012005-04-17 16:05:31 -05004316static int
James Smart2e0fef82007-06-17 19:56:36 -05004317lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004318 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004319{
James Smart2e0fef82007-06-17 19:56:36 -05004320 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4321 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004322 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004323 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004324 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004325 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004326 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004327 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004328 int i;
dea31012005-04-17 16:05:31 -05004329
4330 icmd = &cmdiocb->iocb;
4331 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4332 lp = (uint32_t *) pcmd->virt;
4333
James Smart92d7f7b2007-06-17 19:56:38 -05004334 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4335 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004336 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004337 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4338 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004339 vport->fc_flag, payload_len, *lp,
4340 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004341
4342 /* Send an RSCN event to the management application */
4343 lpfc_send_rscn_event(vport, cmdiocb);
4344
James Smartd2873e42006-08-18 17:46:43 -04004345 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004346 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004347 FCH_EVT_RSCN, lp[i]);
4348
dea31012005-04-17 16:05:31 -05004349 /* If we are about to begin discovery, just ACC the RSCN.
4350 * Discovery processing will satisfy it.
4351 */
James Smart2e0fef82007-06-17 19:56:36 -05004352 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004353 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4354 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4355 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4356
James Smart51ef4c22007-08-02 11:10:31 -04004357 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004358 return 0;
dea31012005-04-17 16:05:31 -05004359 }
4360
James Smart92d7f7b2007-06-17 19:56:38 -05004361 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4362 * just ACC and ignore it.
4363 */
4364 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004365 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004366 i = payload_len;
4367 datap = lp;
4368 while (i > 0) {
4369 nportid = *datap++;
4370 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4371 i -= sizeof(uint32_t);
4372 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004373 if (lpfc_find_vport_by_did(phba, nportid))
4374 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004375 }
4376 if (rscn_id == hba_id) {
4377 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004378 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004379 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004380 "Data: x%x x%x x%x x%x\n",
4381 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004382 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004383 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4384 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4385 ndlp->nlp_DID, vport->port_state,
4386 ndlp->nlp_flag);
4387
James Smart92d7f7b2007-06-17 19:56:38 -05004388 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004389 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004390 return 0;
4391 }
4392 }
4393
James Smart7f5f3d02008-02-08 18:50:14 -05004394 spin_lock_irq(shost->host_lock);
4395 if (vport->fc_rscn_flush) {
4396 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004397 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004398 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004399 /* Send back ACC */
4400 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004401 return 0;
4402 }
4403 /* Indicate we are walking fc_rscn_id_list on this vport */
4404 vport->fc_rscn_flush = 1;
4405 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004406 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004407 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004408 /* If we are already processing an RSCN, save the received
4409 * RSCN payload buffer, cmdiocb->context2 to process later.
4410 */
James Smart2e0fef82007-06-17 19:56:36 -05004411 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004412 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4413 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4414 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4415
James Smart09372822008-01-11 01:52:54 -05004416 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004417 vport->fc_flag |= FC_RSCN_DEFERRED;
4418 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004419 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004420 vport->fc_flag |= FC_RSCN_MODE;
4421 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004422 if (rscn_cnt) {
4423 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4424 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4425 }
4426 if ((rscn_cnt) &&
4427 (payload_len + length <= LPFC_BPL_SIZE)) {
4428 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004429 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004430 memcpy(((uint8_t *)cmd) + length, lp,
4431 payload_len);
4432 } else {
4433 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4434 vport->fc_rscn_id_cnt++;
4435 /* If we zero, cmdiocb->context2, the calling
4436 * routine will not try to free it.
4437 */
4438 cmdiocb->context2 = NULL;
4439 }
dea31012005-04-17 16:05:31 -05004440 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004441 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4442 "0235 Deferred RSCN "
4443 "Data: x%x x%x x%x\n",
4444 vport->fc_rscn_id_cnt, vport->fc_flag,
4445 vport->port_state);
dea31012005-04-17 16:05:31 -05004446 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004447 vport->fc_flag |= FC_RSCN_DISCOVERY;
4448 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004449 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004450 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4451 "0234 ReDiscovery RSCN "
4452 "Data: x%x x%x x%x\n",
4453 vport->fc_rscn_id_cnt, vport->fc_flag,
4454 vport->port_state);
dea31012005-04-17 16:05:31 -05004455 }
James Smart7f5f3d02008-02-08 18:50:14 -05004456 /* Indicate we are done walking fc_rscn_id_list on this vport */
4457 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004458 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004459 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004460 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004461 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004462 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004463 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004464 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004465 return 0;
dea31012005-04-17 16:05:31 -05004466 }
James Smart858c9f62007-06-17 19:56:39 -05004467 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4468 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4469 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4470
James Smart2e0fef82007-06-17 19:56:36 -05004471 spin_lock_irq(shost->host_lock);
4472 vport->fc_flag |= FC_RSCN_MODE;
4473 spin_unlock_irq(shost->host_lock);
4474 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004475 /* Indicate we are done walking fc_rscn_id_list on this vport */
4476 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004477 /*
4478 * If we zero, cmdiocb->context2, the calling routine will
4479 * not try to free it.
4480 */
4481 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004482 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004483 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004484 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004485 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004486 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004487 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004488}
4489
James Smarte59058c2008-08-24 21:49:00 -04004490/**
James Smart3621a712009-04-06 18:47:14 -04004491 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004492 * @vport: pointer to a host virtual N_Port data structure.
4493 *
4494 * This routine handles the Registration State Configuration Notification
4495 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4496 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4497 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4498 * NameServer shall be issued. If CT command to the NameServer fails to be
4499 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4500 * RSCN activities with the @vport.
4501 *
4502 * Return code
4503 * 0 - Cleaned up rscn on the @vport
4504 * 1 - Wait for plogi to name server before proceed
4505 **/
dea31012005-04-17 16:05:31 -05004506int
James Smart2e0fef82007-06-17 19:56:36 -05004507lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004508{
4509 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004510 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004511
James Smart92d7f7b2007-06-17 19:56:38 -05004512 /* Ignore RSCN if the port is being torn down. */
4513 if (vport->load_flag & FC_UNLOADING) {
4514 lpfc_els_flush_rscn(vport);
4515 return 0;
4516 }
4517
dea31012005-04-17 16:05:31 -05004518 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004519 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004520
4521 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004522 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4523 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4524 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4525 vport->port_state);
dea31012005-04-17 16:05:31 -05004526
4527 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004528 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004529 vport->num_disc_nodes = 0;
4530
James Smart2e0fef82007-06-17 19:56:36 -05004531 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004532 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4533 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004534 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004535 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004536 /* Wait for NameServer query cmpl before we can
4537 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004538 return 1;
dea31012005-04-17 16:05:31 -05004539 } else {
4540 /* If login to NameServer does not exist, issue one */
4541 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004542 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004543 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004544 /* Wait for NameServer login cmpl before we can
4545 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004546 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004547
James Smarte47c9092008-02-08 18:49:26 -05004548 if (ndlp) {
4549 ndlp = lpfc_enable_node(vport, ndlp,
4550 NLP_STE_PLOGI_ISSUE);
4551 if (!ndlp) {
4552 lpfc_els_flush_rscn(vport);
4553 return 0;
4554 }
4555 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004556 } else {
James Smarte47c9092008-02-08 18:49:26 -05004557 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4558 if (!ndlp) {
4559 lpfc_els_flush_rscn(vport);
4560 return 0;
4561 }
James Smart2e0fef82007-06-17 19:56:36 -05004562 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004563 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004564 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004565 }
James Smarte47c9092008-02-08 18:49:26 -05004566 ndlp->nlp_type |= NLP_FABRIC;
4567 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4568 /* Wait for NameServer login cmpl before we can
4569 * continue
4570 */
4571 return 1;
dea31012005-04-17 16:05:31 -05004572 }
4573
James Smart2e0fef82007-06-17 19:56:36 -05004574 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004575 return 0;
dea31012005-04-17 16:05:31 -05004576}
4577
James Smarte59058c2008-08-24 21:49:00 -04004578/**
James Smart3621a712009-04-06 18:47:14 -04004579 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004580 * @vport: pointer to a host virtual N_Port data structure.
4581 * @cmdiocb: pointer to lpfc command iocb data structure.
4582 * @ndlp: pointer to a node-list data structure.
4583 *
4584 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4585 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4586 * point topology. As an unsolicited FLOGI should not be received in a loop
4587 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4588 * lpfc_check_sparm() routine is invoked to check the parameters in the
4589 * unsolicited FLOGI. If parameters validation failed, the routine
4590 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4591 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4592 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4593 * will initiate PLOGI. The higher lexicographical value party shall has
4594 * higher priority (as the winning port) and will initiate PLOGI and
4595 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4596 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4597 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4598 *
4599 * Return code
4600 * 0 - Successfully processed the unsolicited flogi
4601 * 1 - Failed to process the unsolicited flogi
4602 **/
dea31012005-04-17 16:05:31 -05004603static int
James Smart2e0fef82007-06-17 19:56:36 -05004604lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004605 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004606{
James Smart2e0fef82007-06-17 19:56:36 -05004607 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4608 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004609 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4610 uint32_t *lp = (uint32_t *) pcmd->virt;
4611 IOCB_t *icmd = &cmdiocb->iocb;
4612 struct serv_parm *sp;
4613 LPFC_MBOXQ_t *mbox;
4614 struct ls_rjt stat;
4615 uint32_t cmd, did;
4616 int rc;
4617
4618 cmd = *lp++;
4619 sp = (struct serv_parm *) lp;
4620
4621 /* FLOGI received */
4622
James Smart2e0fef82007-06-17 19:56:36 -05004623 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004624
4625 if (phba->fc_topology == TOPOLOGY_LOOP) {
4626 /* We should never receive a FLOGI in loop mode, ignore it */
4627 did = icmd->un.elsreq64.remoteID;
4628
4629 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4630 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004631 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4632 "0113 An FLOGI ELS command x%x was "
4633 "received from DID x%x in Loop Mode\n",
4634 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004635 return 1;
dea31012005-04-17 16:05:31 -05004636 }
4637
4638 did = Fabric_DID;
4639
James Smart341af102010-01-26 23:07:37 -05004640 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004641 /* For a FLOGI we accept, then if our portname is greater
4642 * then the remote portname we initiate Nport login.
4643 */
4644
James Smart2e0fef82007-06-17 19:56:36 -05004645 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004646 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004647
4648 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004649 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4650 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004651 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004652
dea31012005-04-17 16:05:31 -05004653 lpfc_linkdown(phba);
4654 lpfc_init_link(phba, mbox,
4655 phba->cfg_topology,
4656 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004657 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004658 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004659 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004660 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004661 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004662 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004663 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004664 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004665 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004666 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004667 spin_lock_irq(shost->host_lock);
4668 vport->fc_flag |= FC_PT2PT_PLOGI;
4669 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004670 }
James Smart2e0fef82007-06-17 19:56:36 -05004671 spin_lock_irq(shost->host_lock);
4672 vport->fc_flag |= FC_PT2PT;
4673 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4674 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004675 } else {
4676 /* Reject this request because invalid parameters */
4677 stat.un.b.lsRjtRsvd0 = 0;
4678 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4679 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4680 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004681 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4682 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004683 return 1;
dea31012005-04-17 16:05:31 -05004684 }
4685
4686 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004687 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004688
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004689 return 0;
dea31012005-04-17 16:05:31 -05004690}
4691
James Smarte59058c2008-08-24 21:49:00 -04004692/**
James Smart3621a712009-04-06 18:47:14 -04004693 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004694 * @vport: pointer to a host virtual N_Port data structure.
4695 * @cmdiocb: pointer to lpfc command iocb data structure.
4696 * @ndlp: pointer to a node-list data structure.
4697 *
4698 * This routine processes Request Node Identification Data (RNID) IOCB
4699 * received as an ELS unsolicited event. Only when the RNID specified format
4700 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4701 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4702 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4703 * rejected by invoking the lpfc_els_rsp_reject() routine.
4704 *
4705 * Return code
4706 * 0 - Successfully processed rnid iocb (currently always return 0)
4707 **/
dea31012005-04-17 16:05:31 -05004708static int
James Smart2e0fef82007-06-17 19:56:36 -05004709lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4710 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004711{
4712 struct lpfc_dmabuf *pcmd;
4713 uint32_t *lp;
4714 IOCB_t *icmd;
4715 RNID *rn;
4716 struct ls_rjt stat;
4717 uint32_t cmd, did;
4718
4719 icmd = &cmdiocb->iocb;
4720 did = icmd->un.elsreq64.remoteID;
4721 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4722 lp = (uint32_t *) pcmd->virt;
4723
4724 cmd = *lp++;
4725 rn = (RNID *) lp;
4726
4727 /* RNID received */
4728
4729 switch (rn->Format) {
4730 case 0:
4731 case RNID_TOPOLOGY_DISC:
4732 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004733 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004734 break;
4735 default:
4736 /* Reject this request because format not supported */
4737 stat.un.b.lsRjtRsvd0 = 0;
4738 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4739 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4740 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004741 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4742 NULL);
dea31012005-04-17 16:05:31 -05004743 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004744 return 0;
dea31012005-04-17 16:05:31 -05004745}
4746
James Smarte59058c2008-08-24 21:49:00 -04004747/**
James Smart12265f62010-10-22 11:05:53 -04004748 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4749 * @vport: pointer to a host virtual N_Port data structure.
4750 * @cmdiocb: pointer to lpfc command iocb data structure.
4751 * @ndlp: pointer to a node-list data structure.
4752 *
4753 * Return code
4754 * 0 - Successfully processed echo iocb (currently always return 0)
4755 **/
4756static int
4757lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4758 struct lpfc_nodelist *ndlp)
4759{
4760 uint8_t *pcmd;
4761
4762 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4763
4764 /* skip over first word of echo command to find echo data */
4765 pcmd += sizeof(uint32_t);
4766
4767 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4768 return 0;
4769}
4770
4771/**
James Smart3621a712009-04-06 18:47:14 -04004772 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004773 * @vport: pointer to a host virtual N_Port data structure.
4774 * @cmdiocb: pointer to lpfc command iocb data structure.
4775 * @ndlp: pointer to a node-list data structure.
4776 *
4777 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4778 * received as an ELS unsolicited event. Currently, this function just invokes
4779 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4780 *
4781 * Return code
4782 * 0 - Successfully processed lirr iocb (currently always return 0)
4783 **/
dea31012005-04-17 16:05:31 -05004784static int
James Smart2e0fef82007-06-17 19:56:36 -05004785lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4786 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004787{
4788 struct ls_rjt stat;
4789
4790 /* For now, unconditionally reject this command */
4791 stat.un.b.lsRjtRsvd0 = 0;
4792 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4793 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4794 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004795 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004796 return 0;
4797}
4798
James Smarte59058c2008-08-24 21:49:00 -04004799/**
James Smart5ffc2662009-11-18 15:39:44 -05004800 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4801 * @vport: pointer to a host virtual N_Port data structure.
4802 * @cmdiocb: pointer to lpfc command iocb data structure.
4803 * @ndlp: pointer to a node-list data structure.
4804 *
4805 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4806 * received as an ELS unsolicited event. A request to RRQ shall only
4807 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4808 * Nx_Port N_Port_ID of the target Exchange is the same as the
4809 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4810 * not accepted, an LS_RJT with reason code "Unable to perform
4811 * command request" and reason code explanation "Invalid Originator
4812 * S_ID" shall be returned. For now, we just unconditionally accept
4813 * RRQ from the target.
4814 **/
4815static void
4816lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4817 struct lpfc_nodelist *ndlp)
4818{
4819 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4820}
4821
4822/**
James Smart12265f62010-10-22 11:05:53 -04004823 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4824 * @phba: pointer to lpfc hba data structure.
4825 * @pmb: pointer to the driver internal queue element for mailbox command.
4826 *
4827 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4828 * mailbox command. This callback function is to actually send the Accept
4829 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4830 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4831 * mailbox command, constructs the RPS response with the link statistics
4832 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4833 * response to the RPS.
4834 *
4835 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4836 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4837 * will be stored into the context1 field of the IOCB for the completion
4838 * callback function to the RPS Accept Response ELS IOCB command.
4839 *
4840 **/
4841static void
4842lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4843{
4844 MAILBOX_t *mb;
4845 IOCB_t *icmd;
4846 struct RLS_RSP *rls_rsp;
4847 uint8_t *pcmd;
4848 struct lpfc_iocbq *elsiocb;
4849 struct lpfc_nodelist *ndlp;
4850 uint16_t xri;
4851 uint32_t cmdsize;
4852
4853 mb = &pmb->u.mb;
4854
4855 ndlp = (struct lpfc_nodelist *) pmb->context2;
4856 xri = (uint16_t) ((unsigned long)(pmb->context1));
4857 pmb->context1 = NULL;
4858 pmb->context2 = NULL;
4859
4860 if (mb->mbxStatus) {
4861 mempool_free(pmb, phba->mbox_mem_pool);
4862 return;
4863 }
4864
4865 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4866 mempool_free(pmb, phba->mbox_mem_pool);
4867 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4868 lpfc_max_els_tries, ndlp,
4869 ndlp->nlp_DID, ELS_CMD_ACC);
4870
4871 /* Decrement the ndlp reference count from previous mbox command */
4872 lpfc_nlp_put(ndlp);
4873
4874 if (!elsiocb)
4875 return;
4876
4877 icmd = &elsiocb->iocb;
4878 icmd->ulpContext = xri;
4879
4880 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4881 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4882 pcmd += sizeof(uint32_t); /* Skip past command */
4883 rls_rsp = (struct RLS_RSP *)pcmd;
4884
4885 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4886 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4887 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4888 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4889 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4890 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4891
4892 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4893 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4894 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4895 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4896 elsiocb->iotag, elsiocb->iocb.ulpContext,
4897 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4898 ndlp->nlp_rpi);
4899 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4900 phba->fc_stat.elsXmitACC++;
4901 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4902 lpfc_els_free_iocb(phba, elsiocb);
4903}
4904
4905/**
James Smart3621a712009-04-06 18:47:14 -04004906 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004907 * @phba: pointer to lpfc hba data structure.
4908 * @pmb: pointer to the driver internal queue element for mailbox command.
4909 *
4910 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4911 * mailbox command. This callback function is to actually send the Accept
4912 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4913 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4914 * mailbox command, constructs the RPS response with the link statistics
4915 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4916 * response to the RPS.
4917 *
4918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4920 * will be stored into the context1 field of the IOCB for the completion
4921 * callback function to the RPS Accept Response ELS IOCB command.
4922 *
4923 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004924static void
James Smart329f9bc2007-04-25 09:53:01 -04004925lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004926{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004927 MAILBOX_t *mb;
4928 IOCB_t *icmd;
4929 RPS_RSP *rps_rsp;
4930 uint8_t *pcmd;
4931 struct lpfc_iocbq *elsiocb;
4932 struct lpfc_nodelist *ndlp;
4933 uint16_t xri, status;
4934 uint32_t cmdsize;
4935
James Smart04c68492009-05-22 14:52:52 -04004936 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004937
4938 ndlp = (struct lpfc_nodelist *) pmb->context2;
4939 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004940 pmb->context1 = NULL;
4941 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004942
4943 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004944 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004945 return;
4946 }
4947
4948 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004949 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004950 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4951 lpfc_max_els_tries, ndlp,
4952 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004953
4954 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004955 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004956
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004957 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004958 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004959
4960 icmd = &elsiocb->iocb;
4961 icmd->ulpContext = xri;
4962
4963 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4964 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004965 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004966 rps_rsp = (RPS_RSP *)pcmd;
4967
4968 if (phba->fc_topology != TOPOLOGY_LOOP)
4969 status = 0x10;
4970 else
4971 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004972 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004973 status |= 0x4;
4974
4975 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004976 rps_rsp->portStatus = cpu_to_be16(status);
4977 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4978 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4979 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4980 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4981 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4982 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004983 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004984 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4985 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4986 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4987 elsiocb->iotag, elsiocb->iocb.ulpContext,
4988 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4989 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004990 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004991 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004992 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004993 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004994 return;
4995}
4996
James Smarte59058c2008-08-24 21:49:00 -04004997/**
James Smart12265f62010-10-22 11:05:53 -04004998 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4999 * @vport: pointer to a host virtual N_Port data structure.
5000 * @cmdiocb: pointer to lpfc command iocb data structure.
5001 * @ndlp: pointer to a node-list data structure.
5002 *
5003 * This routine processes Read Port Status (RPL) IOCB received as an
5004 * ELS unsolicited event. It first checks the remote port state. If the
5005 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5006 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5007 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5008 * for reading the HBA link statistics. It is for the callback function,
5009 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5010 * to actually sending out RPL Accept (ACC) response.
5011 *
5012 * Return codes
5013 * 0 - Successfully processed rls iocb (currently always return 0)
5014 **/
5015static int
5016lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5017 struct lpfc_nodelist *ndlp)
5018{
5019 struct lpfc_hba *phba = vport->phba;
5020 LPFC_MBOXQ_t *mbox;
5021 struct lpfc_dmabuf *pcmd;
5022 struct ls_rjt stat;
5023
5024 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5025 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5026 /* reject the unsolicited RPS request and done with it */
5027 goto reject_out;
5028
5029 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5030
5031 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5032 if (mbox) {
5033 lpfc_read_lnk_stat(phba, mbox);
5034 mbox->context1 =
5035 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5036 mbox->context2 = lpfc_nlp_get(ndlp);
5037 mbox->vport = vport;
5038 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5039 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5040 != MBX_NOT_FINISHED)
5041 /* Mbox completion will send ELS Response */
5042 return 0;
5043 /* Decrement reference count used for the failed mbox
5044 * command.
5045 */
5046 lpfc_nlp_put(ndlp);
5047 mempool_free(mbox, phba->mbox_mem_pool);
5048 }
5049reject_out:
5050 /* issue rejection response */
5051 stat.un.b.lsRjtRsvd0 = 0;
5052 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5053 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5054 stat.un.b.vendorUnique = 0;
5055 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5056 return 0;
5057}
5058
5059/**
5060 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5061 * @vport: pointer to a host virtual N_Port data structure.
5062 * @cmdiocb: pointer to lpfc command iocb data structure.
5063 * @ndlp: pointer to a node-list data structure.
5064 *
5065 * This routine processes Read Timout Value (RTV) IOCB received as an
5066 * ELS unsolicited event. It first checks the remote port state. If the
5067 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5068 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5069 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5070 * Value (RTV) unsolicited IOCB event.
5071 *
5072 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5073 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5074 * will be stored into the context1 field of the IOCB for the completion
5075 * callback function to the RPS Accept Response ELS IOCB command.
5076 *
5077 * Return codes
5078 * 0 - Successfully processed rtv iocb (currently always return 0)
5079 **/
5080static int
5081lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5082 struct lpfc_nodelist *ndlp)
5083{
5084 struct lpfc_hba *phba = vport->phba;
5085 struct ls_rjt stat;
5086 struct RTV_RSP *rtv_rsp;
5087 uint8_t *pcmd;
5088 struct lpfc_iocbq *elsiocb;
5089 uint32_t cmdsize;
5090
5091
5092 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5093 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5094 /* reject the unsolicited RPS request and done with it */
5095 goto reject_out;
5096
5097 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5098 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5099 lpfc_max_els_tries, ndlp,
5100 ndlp->nlp_DID, ELS_CMD_ACC);
5101
5102 if (!elsiocb)
5103 return 1;
5104
5105 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5106 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5107 pcmd += sizeof(uint32_t); /* Skip past command */
5108
5109 /* use the command's xri in the response */
5110 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5111
5112 rtv_rsp = (struct RTV_RSP *)pcmd;
5113
5114 /* populate RTV payload */
5115 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5116 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5117 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5118 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5119 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5120
5121 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5122 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5123 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5124 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5125 "Data: x%x x%x x%x\n",
5126 elsiocb->iotag, elsiocb->iocb.ulpContext,
5127 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5128 ndlp->nlp_rpi,
5129 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5130 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5131 phba->fc_stat.elsXmitACC++;
5132 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5133 lpfc_els_free_iocb(phba, elsiocb);
5134 return 0;
5135
5136reject_out:
5137 /* issue rejection response */
5138 stat.un.b.lsRjtRsvd0 = 0;
5139 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5140 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5141 stat.un.b.vendorUnique = 0;
5142 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5143 return 0;
5144}
5145
5146/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005147 * @vport: pointer to a host virtual N_Port data structure.
5148 * @cmdiocb: pointer to lpfc command iocb data structure.
5149 * @ndlp: pointer to a node-list data structure.
5150 *
5151 * This routine processes Read Port Status (RPS) IOCB received as an
5152 * ELS unsolicited event. It first checks the remote port state. If the
5153 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5154 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5155 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5156 * for reading the HBA link statistics. It is for the callback function,
5157 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5158 * to actually sending out RPS Accept (ACC) response.
5159 *
5160 * Return codes
5161 * 0 - Successfully processed rps iocb (currently always return 0)
5162 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005163static int
James Smart2e0fef82007-06-17 19:56:36 -05005164lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5165 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005166{
James Smart2e0fef82007-06-17 19:56:36 -05005167 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005168 uint32_t *lp;
5169 uint8_t flag;
5170 LPFC_MBOXQ_t *mbox;
5171 struct lpfc_dmabuf *pcmd;
5172 RPS *rps;
5173 struct ls_rjt stat;
5174
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005175 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005176 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5177 /* reject the unsolicited RPS request and done with it */
5178 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005179
5180 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5181 lp = (uint32_t *) pcmd->virt;
5182 flag = (be32_to_cpu(*lp++) & 0xf);
5183 rps = (RPS *) lp;
5184
5185 if ((flag == 0) ||
5186 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005187 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005188 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005189
James Smart92d7f7b2007-06-17 19:56:38 -05005190 printk("Fix me....\n");
5191 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005192 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5193 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005194 lpfc_read_lnk_stat(phba, mbox);
5195 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005196 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005197 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005198 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005199 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005200 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005201 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005202 /* Mbox completion will send ELS Response */
5203 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005204 /* Decrement reference count used for the failed mbox
5205 * command.
5206 */
James Smart329f9bc2007-04-25 09:53:01 -04005207 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005208 mempool_free(mbox, phba->mbox_mem_pool);
5209 }
5210 }
James Smart90160e02008-08-24 21:49:45 -04005211
5212reject_out:
5213 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005214 stat.un.b.lsRjtRsvd0 = 0;
5215 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5216 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5217 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005218 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005219 return 0;
5220}
5221
James Smarte59058c2008-08-24 21:49:00 -04005222/**
James Smart3621a712009-04-06 18:47:14 -04005223 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005224 * @vport: pointer to a host virtual N_Port data structure.
5225 * @cmdsize: size of the ELS command.
5226 * @oldiocb: pointer to the original lpfc command iocb data structure.
5227 * @ndlp: pointer to a node-list data structure.
5228 *
5229 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5230 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5231 *
5232 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5233 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5234 * will be stored into the context1 field of the IOCB for the completion
5235 * callback function to the RPL Accept Response ELS command.
5236 *
5237 * Return code
5238 * 0 - Successfully issued ACC RPL ELS command
5239 * 1 - Failed to issue ACC RPL ELS command
5240 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005241static int
James Smart2e0fef82007-06-17 19:56:36 -05005242lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5243 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005244{
James Smart2e0fef82007-06-17 19:56:36 -05005245 struct lpfc_hba *phba = vport->phba;
5246 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005247 RPL_RSP rpl_rsp;
5248 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005249 uint8_t *pcmd;
5250
James Smart2e0fef82007-06-17 19:56:36 -05005251 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5252 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005253
James Smart488d1462006-03-07 15:02:37 -05005254 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005255 return 1;
James Smart488d1462006-03-07 15:02:37 -05005256
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005257 icmd = &elsiocb->iocb;
5258 oldcmd = &oldiocb->iocb;
5259 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5260
5261 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5262 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005263 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005264 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5265 pcmd += sizeof(uint16_t);
5266
5267 /* Setup the RPL ACC payload */
5268 rpl_rsp.listLen = be32_to_cpu(1);
5269 rpl_rsp.index = 0;
5270 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005271 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5272 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005273 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005274 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005275 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005276 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5277 "0120 Xmit ELS RPL ACC response tag x%x "
5278 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5279 "rpi x%x\n",
5280 elsiocb->iotag, elsiocb->iocb.ulpContext,
5281 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5282 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005283 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005284 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005285 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5286 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005287 lpfc_els_free_iocb(phba, elsiocb);
5288 return 1;
5289 }
5290 return 0;
5291}
5292
James Smarte59058c2008-08-24 21:49:00 -04005293/**
James Smart3621a712009-04-06 18:47:14 -04005294 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005295 * @vport: pointer to a host virtual N_Port data structure.
5296 * @cmdiocb: pointer to lpfc command iocb data structure.
5297 * @ndlp: pointer to a node-list data structure.
5298 *
5299 * This routine processes Read Port List (RPL) IOCB received as an ELS
5300 * unsolicited event. It first checks the remote port state. If the remote
5301 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5302 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5303 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5304 * to accept the RPL.
5305 *
5306 * Return code
5307 * 0 - Successfully processed rpl iocb (currently always return 0)
5308 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005309static int
James Smart2e0fef82007-06-17 19:56:36 -05005310lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5311 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005312{
5313 struct lpfc_dmabuf *pcmd;
5314 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005315 uint32_t maxsize;
5316 uint16_t cmdsize;
5317 RPL *rpl;
5318 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005319
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005320 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5321 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005322 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005323 stat.un.b.lsRjtRsvd0 = 0;
5324 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5325 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5326 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005327 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5328 NULL);
James Smart90160e02008-08-24 21:49:45 -04005329 /* rejected the unsolicited RPL request and done with it */
5330 return 0;
dea31012005-04-17 16:05:31 -05005331 }
5332
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005333 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5334 lp = (uint32_t *) pcmd->virt;
5335 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005336 maxsize = be32_to_cpu(rpl->maxsize);
5337
5338 /* We support only one port */
5339 if ((rpl->index == 0) &&
5340 ((maxsize == 0) ||
5341 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5342 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005343 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005344 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5345 }
James Smart2e0fef82007-06-17 19:56:36 -05005346 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005347
5348 return 0;
5349}
5350
James Smarte59058c2008-08-24 21:49:00 -04005351/**
James Smart3621a712009-04-06 18:47:14 -04005352 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005353 * @vport: pointer to a virtual N_Port data structure.
5354 * @cmdiocb: pointer to lpfc command iocb data structure.
5355 * @ndlp: pointer to a node-list data structure.
5356 *
5357 * This routine processes Fibre Channel Address Resolution Protocol
5358 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5359 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5360 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5361 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5362 * remote PortName is compared against the FC PortName stored in the @vport
5363 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5364 * compared against the FC NodeName stored in the @vport data structure.
5365 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5366 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5367 * invoked to send out FARP Response to the remote node. Before sending the
5368 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5369 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5370 * routine is invoked to log into the remote port first.
5371 *
5372 * Return code
5373 * 0 - Either the FARP Match Mode not supported or successfully processed
5374 **/
dea31012005-04-17 16:05:31 -05005375static int
James Smart2e0fef82007-06-17 19:56:36 -05005376lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5377 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005378{
5379 struct lpfc_dmabuf *pcmd;
5380 uint32_t *lp;
5381 IOCB_t *icmd;
5382 FARP *fp;
5383 uint32_t cmd, cnt, did;
5384
5385 icmd = &cmdiocb->iocb;
5386 did = icmd->un.elsreq64.remoteID;
5387 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5388 lp = (uint32_t *) pcmd->virt;
5389
5390 cmd = *lp++;
5391 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005392 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005393 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5394 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005395 /* We will only support match on WWPN or WWNN */
5396 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005397 return 0;
dea31012005-04-17 16:05:31 -05005398 }
5399
5400 cnt = 0;
5401 /* If this FARP command is searching for my portname */
5402 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005403 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005404 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005405 cnt = 1;
5406 }
5407
5408 /* If this FARP command is searching for my nodename */
5409 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005410 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005411 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005412 cnt = 1;
5413 }
5414
5415 if (cnt) {
5416 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5417 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5418 /* Log back into the node before sending the FARP. */
5419 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005420 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005421 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005422 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005423 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005424 }
5425
5426 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005427 if (fp->Rflags & FARP_REQUEST_FARPR)
5428 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005429 }
5430 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005431 return 0;
dea31012005-04-17 16:05:31 -05005432}
5433
James Smarte59058c2008-08-24 21:49:00 -04005434/**
James Smart3621a712009-04-06 18:47:14 -04005435 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005436 * @vport: pointer to a host virtual N_Port data structure.
5437 * @cmdiocb: pointer to lpfc command iocb data structure.
5438 * @ndlp: pointer to a node-list data structure.
5439 *
5440 * This routine processes Fibre Channel Address Resolution Protocol
5441 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5442 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5443 * the FARP response request.
5444 *
5445 * Return code
5446 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5447 **/
dea31012005-04-17 16:05:31 -05005448static int
James Smart2e0fef82007-06-17 19:56:36 -05005449lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5450 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005451{
5452 struct lpfc_dmabuf *pcmd;
5453 uint32_t *lp;
5454 IOCB_t *icmd;
5455 uint32_t cmd, did;
5456
5457 icmd = &cmdiocb->iocb;
5458 did = icmd->un.elsreq64.remoteID;
5459 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5460 lp = (uint32_t *) pcmd->virt;
5461
5462 cmd = *lp++;
5463 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005464 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5465 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005466 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005467 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005468
5469 return 0;
5470}
5471
James Smarte59058c2008-08-24 21:49:00 -04005472/**
James Smart3621a712009-04-06 18:47:14 -04005473 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005474 * @vport: pointer to a host virtual N_Port data structure.
5475 * @cmdiocb: pointer to lpfc command iocb data structure.
5476 * @fan_ndlp: pointer to a node-list data structure.
5477 *
5478 * This routine processes a Fabric Address Notification (FAN) IOCB
5479 * command received as an ELS unsolicited event. The FAN ELS command will
5480 * only be processed on a physical port (i.e., the @vport represents the
5481 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5482 * compared against those in the phba data structure. If any of those is
5483 * different, the lpfc_initial_flogi() routine is invoked to initialize
5484 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5485 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5486 * is invoked to register login to the fabric.
5487 *
5488 * Return code
5489 * 0 - Successfully processed fan iocb (currently always return 0).
5490 **/
dea31012005-04-17 16:05:31 -05005491static int
James Smart2e0fef82007-06-17 19:56:36 -05005492lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5493 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005494{
James Smart2e0fef82007-06-17 19:56:36 -05005495 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005496 uint32_t *lp;
5497 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005498
James Smart0d2b6b82008-06-14 22:52:47 -04005499 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5500 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5501 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005502 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005503 if ((vport == phba->pport) &&
5504 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005505 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005506 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005507 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005508 sizeof(struct lpfc_name)))) {
5509 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005510 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005511 } else {
5512 /* FAN verified - skip FLOGI */
5513 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005514 if (phba->sli_rev < LPFC_SLI_REV4)
5515 lpfc_issue_fabric_reglogin(vport);
5516 else
5517 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005518 }
dea31012005-04-17 16:05:31 -05005519 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005520 return 0;
dea31012005-04-17 16:05:31 -05005521}
5522
James Smarte59058c2008-08-24 21:49:00 -04005523/**
James Smart3621a712009-04-06 18:47:14 -04005524 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005525 * @ptr: holder for the timer function associated data.
5526 *
5527 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5528 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5529 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5530 * up the worker thread. It is for the worker thread to invoke the routine
5531 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5532 **/
dea31012005-04-17 16:05:31 -05005533void
5534lpfc_els_timeout(unsigned long ptr)
5535{
James Smart2e0fef82007-06-17 19:56:36 -05005536 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5537 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005538 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005539 unsigned long iflag;
5540
James Smart2e0fef82007-06-17 19:56:36 -05005541 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005542 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5543 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005544 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005545 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005546
James Smart5e9d9b82008-06-14 22:52:53 -04005547 if (!tmo_posted)
5548 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005549 return;
5550}
5551
James Smart2a9bf3d2010-06-07 15:24:45 -04005552
James Smarte59058c2008-08-24 21:49:00 -04005553/**
James Smart3621a712009-04-06 18:47:14 -04005554 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005555 * @vport: pointer to a virtual N_Port data structure.
5556 *
5557 * This routine is the actual handler function that processes an ELS timeout
5558 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5559 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5560 * invoking the lpfc_sli_issue_abort_iotag() routine.
5561 **/
dea31012005-04-17 16:05:31 -05005562void
James Smart2e0fef82007-06-17 19:56:36 -05005563lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005564{
James Smart2e0fef82007-06-17 19:56:36 -05005565 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005566 struct lpfc_sli_ring *pring;
5567 struct lpfc_iocbq *tmp_iocb, *piocb;
5568 IOCB_t *cmd = NULL;
5569 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005570 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005571 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005572 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005573 LIST_HEAD(txcmplq_completions);
5574 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005575
James Smart2a9bf3d2010-06-07 15:24:45 -04005576
dea31012005-04-17 16:05:31 -05005577 timeout = (uint32_t)(phba->fc_ratov << 1);
5578
5579 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005580
James Smart2a9bf3d2010-06-07 15:24:45 -04005581 spin_lock_irq(&phba->hbalock);
5582 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5583 spin_unlock_irq(&phba->hbalock);
5584
5585 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005586 cmd = &piocb->iocb;
5587
James Smart2e0fef82007-06-17 19:56:36 -05005588 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5589 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5590 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005591 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005592
5593 if (piocb->vport != vport)
5594 continue;
5595
dea31012005-04-17 16:05:31 -05005596 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005597 if (pcmd)
5598 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005599
James Smart92d7f7b2007-06-17 19:56:38 -05005600 if (els_command == ELS_CMD_FARP ||
5601 els_command == ELS_CMD_FARPR ||
5602 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005603 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005604
dea31012005-04-17 16:05:31 -05005605 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005606 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005607 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005608 else
dea31012005-04-17 16:05:31 -05005609 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005610 continue;
5611 }
5612
James Smart2e0fef82007-06-17 19:56:36 -05005613 remote_ID = 0xffffffff;
5614 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005615 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005616 else {
5617 struct lpfc_nodelist *ndlp;
5618 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005619 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005620 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005621 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005622 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005623 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005624 spin_lock_irq(&phba->hbalock);
5625 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005626 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005627
James Smart2a9bf3d2010-06-07 15:24:45 -04005628 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5629 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5630 "0127 ELS timeout Data: x%x x%x x%x "
5631 "x%x\n", els_command,
5632 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5633 spin_lock_irq(&phba->hbalock);
5634 list_del_init(&piocb->dlist);
5635 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5636 spin_unlock_irq(&phba->hbalock);
5637 }
5638
James Smart2e0fef82007-06-17 19:56:36 -05005639 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5640 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005641}
5642
James Smarte59058c2008-08-24 21:49:00 -04005643/**
James Smart3621a712009-04-06 18:47:14 -04005644 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005645 * @vport: pointer to a host virtual N_Port data structure.
5646 *
5647 * This routine is used to clean up all the outstanding ELS commands on a
5648 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5649 * routine. After that, it walks the ELS transmit queue to remove all the
5650 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5651 * the IOCBs with a non-NULL completion callback function, the callback
5652 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5653 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5654 * callback function, the IOCB will simply be released. Finally, it walks
5655 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5656 * completion queue IOCB that is associated with the @vport and is not
5657 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5658 * part of the discovery state machine) out to HBA by invoking the
5659 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5660 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5661 * the IOCBs are aborted when this function returns.
5662 **/
dea31012005-04-17 16:05:31 -05005663void
James Smart2e0fef82007-06-17 19:56:36 -05005664lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005665{
James Smart2534ba72007-04-25 09:52:20 -04005666 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005667 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005668 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005669 struct lpfc_iocbq *tmp_iocb, *piocb;
5670 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005671
5672 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005673
James Smart2e0fef82007-06-17 19:56:36 -05005674 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005675 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5676 cmd = &piocb->iocb;
5677
5678 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5679 continue;
5680 }
5681
5682 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005683 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5684 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5685 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5686 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005687 continue;
dea31012005-04-17 16:05:31 -05005688
James Smart2e0fef82007-06-17 19:56:36 -05005689 if (piocb->vport != vport)
5690 continue;
5691
James Smart2534ba72007-04-25 09:52:20 -04005692 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005693 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005694 }
5695
5696 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005697 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5698 continue;
5699 }
dea31012005-04-17 16:05:31 -05005700
James Smart2e0fef82007-06-17 19:56:36 -05005701 if (piocb->vport != vport)
5702 continue;
5703
James Smart07951072007-04-25 09:51:38 -04005704 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005705 }
James Smart2e0fef82007-06-17 19:56:36 -05005706 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005707
James Smarta257bf92009-04-06 18:48:10 -04005708 /* Cancell all the IOCBs from the completions list */
5709 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5710 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005711
dea31012005-04-17 16:05:31 -05005712 return;
5713}
5714
James Smarte59058c2008-08-24 21:49:00 -04005715/**
James Smart3621a712009-04-06 18:47:14 -04005716 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005717 * @phba: pointer to lpfc hba data structure.
5718 *
5719 * This routine is used to clean up all the outstanding ELS commands on a
5720 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5721 * routine. After that, it walks the ELS transmit queue to remove all the
5722 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5723 * the IOCBs with the completion callback function associated, the callback
5724 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5725 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5726 * callback function associated, the IOCB will simply be released. Finally,
5727 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5728 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5729 * management plane IOCBs that are not part of the discovery state machine)
5730 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5731 **/
James Smart549e55c2007-08-02 11:09:51 -04005732void
5733lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5734{
5735 LIST_HEAD(completions);
5736 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5737 struct lpfc_iocbq *tmp_iocb, *piocb;
5738 IOCB_t *cmd = NULL;
5739
5740 lpfc_fabric_abort_hba(phba);
5741 spin_lock_irq(&phba->hbalock);
5742 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5743 cmd = &piocb->iocb;
5744 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5745 continue;
5746 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5747 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5748 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5749 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5750 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5751 continue;
5752 list_move_tail(&piocb->list, &completions);
5753 pring->txq_cnt--;
5754 }
5755 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5756 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5757 continue;
5758 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5759 }
5760 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005761
5762 /* Cancel all the IOCBs from the completions list */
5763 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5764 IOERR_SLI_ABORTED);
5765
James Smart549e55c2007-08-02 11:09:51 -04005766 return;
5767}
5768
James Smarte59058c2008-08-24 21:49:00 -04005769/**
James Smart3621a712009-04-06 18:47:14 -04005770 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005771 * @phba: Pointer to hba context object.
5772 * @cmdiocbp: Pointer to command iocb which reported error.
5773 * @rspiocbp: Pointer to response iocb which reported error.
5774 *
5775 * This function sends an event when there is an ELS command
5776 * failure.
5777 **/
5778void
5779lpfc_send_els_failure_event(struct lpfc_hba *phba,
5780 struct lpfc_iocbq *cmdiocbp,
5781 struct lpfc_iocbq *rspiocbp)
5782{
5783 struct lpfc_vport *vport = cmdiocbp->vport;
5784 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5785 struct lpfc_lsrjt_event lsrjt_event;
5786 struct lpfc_fabric_event_header fabric_event;
5787 struct ls_rjt stat;
5788 struct lpfc_nodelist *ndlp;
5789 uint32_t *pcmd;
5790
5791 ndlp = cmdiocbp->context1;
5792 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5793 return;
5794
5795 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5796 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5797 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5798 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5799 sizeof(struct lpfc_name));
5800 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5801 sizeof(struct lpfc_name));
5802 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5803 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005804 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005805 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5806 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5807 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5808 fc_host_post_vendor_event(shost,
5809 fc_get_event_number(),
5810 sizeof(lsrjt_event),
5811 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005812 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005813 return;
5814 }
5815 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5816 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5817 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5818 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5819 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5820 else
5821 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5822 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5823 sizeof(struct lpfc_name));
5824 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5825 sizeof(struct lpfc_name));
5826 fc_host_post_vendor_event(shost,
5827 fc_get_event_number(),
5828 sizeof(fabric_event),
5829 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005830 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005831 return;
5832 }
5833
5834}
5835
5836/**
James Smart3621a712009-04-06 18:47:14 -04005837 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005838 * @vport: Pointer to vport object.
5839 * @ndlp: Pointer FC node object.
5840 * @cmd: ELS command code.
5841 *
5842 * This function posts an event when there is an incoming
5843 * unsolicited ELS command.
5844 **/
5845static void
5846lpfc_send_els_event(struct lpfc_vport *vport,
5847 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005848 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005849{
James Smartddcc50f2008-12-04 22:38:46 -05005850 struct lpfc_els_event_header *els_data = NULL;
5851 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005852 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5853
James Smartddcc50f2008-12-04 22:38:46 -05005854 if (*payload == ELS_CMD_LOGO) {
5855 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5856 if (!logo_data) {
5857 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5858 "0148 Failed to allocate memory "
5859 "for LOGO event\n");
5860 return;
5861 }
5862 els_data = &logo_data->header;
5863 } else {
5864 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5865 GFP_KERNEL);
5866 if (!els_data) {
5867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5868 "0149 Failed to allocate memory "
5869 "for ELS event\n");
5870 return;
5871 }
5872 }
5873 els_data->event_type = FC_REG_ELS_EVENT;
5874 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005875 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005876 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005877 break;
5878 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005879 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005880 break;
5881 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005882 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5883 break;
5884 case ELS_CMD_LOGO:
5885 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5886 /* Copy the WWPN in the LOGO payload */
5887 memcpy(logo_data->logo_wwpn, &payload[2],
5888 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005889 break;
5890 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005891 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005892 return;
5893 }
James Smartddcc50f2008-12-04 22:38:46 -05005894 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5895 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5896 if (*payload == ELS_CMD_LOGO) {
5897 fc_host_post_vendor_event(shost,
5898 fc_get_event_number(),
5899 sizeof(struct lpfc_logo_event),
5900 (char *)logo_data,
5901 LPFC_NL_VENDOR_ID);
5902 kfree(logo_data);
5903 } else {
5904 fc_host_post_vendor_event(shost,
5905 fc_get_event_number(),
5906 sizeof(struct lpfc_els_event_header),
5907 (char *)els_data,
5908 LPFC_NL_VENDOR_ID);
5909 kfree(els_data);
5910 }
James Smartea2151b2008-09-07 11:52:10 -04005911
5912 return;
5913}
5914
5915
5916/**
James Smart3621a712009-04-06 18:47:14 -04005917 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005918 * @phba: pointer to lpfc hba data structure.
5919 * @pring: pointer to a SLI ring.
5920 * @vport: pointer to a host virtual N_Port data structure.
5921 * @elsiocb: pointer to lpfc els command iocb data structure.
5922 *
5923 * This routine is used for processing the IOCB associated with a unsolicited
5924 * event. It first determines whether there is an existing ndlp that matches
5925 * the DID from the unsolicited IOCB. If not, it will create a new one with
5926 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5927 * IOCB is then used to invoke the proper routine and to set up proper state
5928 * of the discovery state machine.
5929 **/
James Smarted957682007-06-17 19:56:37 -05005930static void
5931lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005932 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005933{
James Smart87af33f2007-10-27 13:37:43 -04005934 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005935 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005936 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005937 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005938 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005939 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005940
James Smarte47c9092008-02-08 18:49:26 -05005941 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005942 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005943
dea31012005-04-17 16:05:31 -05005944 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005945 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5946 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005947 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005948 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005949
James Smart858c9f62007-06-17 19:56:39 -05005950 did = icmd->un.rcvels.remoteID;
5951 if (icmd->ulpStatus) {
5952 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5953 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5954 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005955 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005956 }
dea31012005-04-17 16:05:31 -05005957
5958 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005959 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005960 goto dropit;
dea31012005-04-17 16:05:31 -05005961
James Smartc8685952009-11-18 15:39:16 -05005962 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005963 if (vport->load_flag & FC_UNLOADING)
5964 goto dropit;
5965
James Smart2e0fef82007-06-17 19:56:36 -05005966 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005967 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005968 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005969 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005970 if (!ndlp)
dea31012005-04-17 16:05:31 -05005971 goto dropit;
dea31012005-04-17 16:05:31 -05005972
James Smart2e0fef82007-06-17 19:56:36 -05005973 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005974 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005975 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005976 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005977 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005978 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5979 ndlp = lpfc_enable_node(vport, ndlp,
5980 NLP_STE_UNUSED_NODE);
5981 if (!ndlp)
5982 goto dropit;
5983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5984 newnode = 1;
5985 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5986 ndlp->nlp_type |= NLP_FABRIC;
5987 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5988 /* This is similar to the new node path */
5989 ndlp = lpfc_nlp_get(ndlp);
5990 if (!ndlp)
5991 goto dropit;
5992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5993 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005994 }
dea31012005-04-17 16:05:31 -05005995
5996 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005997
James Smart329f9bc2007-04-25 09:53:01 -04005998 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005999 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006000
6001 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6002 cmd &= ELS_CMD_MASK;
6003 }
6004 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006005 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6006 "0112 ELS command x%x received from NPORT x%x "
6007 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006008 switch (cmd) {
6009 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006010 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6011 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6012 did, vport->port_state, ndlp->nlp_flag);
6013
dea31012005-04-17 16:05:31 -05006014 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006015 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6016
James Smartddcc50f2008-12-04 22:38:46 -05006017 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05006018 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006019 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6020 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6021 rjt_err = LSRJT_UNABLE_TPC;
6022 break;
6023 }
6024 /* We get here, and drop thru, if we are PT2PT with
6025 * another NPort and the other side has initiated
6026 * the PLOGI before responding to our FLOGI.
6027 */
dea31012005-04-17 16:05:31 -05006028 }
James Smart87af33f2007-10-27 13:37:43 -04006029
6030 shost = lpfc_shost_from_vport(vport);
6031 spin_lock_irq(shost->host_lock);
6032 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6033 spin_unlock_irq(shost->host_lock);
6034
James Smart2e0fef82007-06-17 19:56:36 -05006035 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6036 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006037
dea31012005-04-17 16:05:31 -05006038 break;
6039 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006040 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6041 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6042 did, vport->port_state, ndlp->nlp_flag);
6043
dea31012005-04-17 16:05:31 -05006044 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006045 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006046 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006047 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006048 break;
6049 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6051 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6052 did, vport->port_state, ndlp->nlp_flag);
6053
dea31012005-04-17 16:05:31 -05006054 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006055 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006056 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006057 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006058 break;
6059 }
James Smart2e0fef82007-06-17 19:56:36 -05006060 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006061 break;
6062 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6064 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6065 did, vport->port_state, ndlp->nlp_flag);
6066
dea31012005-04-17 16:05:31 -05006067 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006068 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006069 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006070 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006071 break;
6072 }
James Smart2e0fef82007-06-17 19:56:36 -05006073 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006074 break;
6075 case ELS_CMD_RSCN:
6076 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006077 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006078 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006079 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006080 break;
6081 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006082 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6083 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6084 did, vport->port_state, ndlp->nlp_flag);
6085
James Smartddcc50f2008-12-04 22:38:46 -05006086 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006087 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006088 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006089 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006090 break;
6091 }
James Smart2e0fef82007-06-17 19:56:36 -05006092 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6093 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006094 break;
6095 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006096 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6097 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6098 did, vport->port_state, ndlp->nlp_flag);
6099
dea31012005-04-17 16:05:31 -05006100 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006101 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006102 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006103 break;
6104 }
James Smart2e0fef82007-06-17 19:56:36 -05006105 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6106 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006107 break;
6108 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6110 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6111 did, vport->port_state, ndlp->nlp_flag);
6112
dea31012005-04-17 16:05:31 -05006113 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006114 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006115 break;
6116 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6118 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6119 did, vport->port_state, ndlp->nlp_flag);
6120
dea31012005-04-17 16:05:31 -05006121 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006122 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006123 break;
6124 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006125 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6126 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6127 did, vport->port_state, ndlp->nlp_flag);
6128
dea31012005-04-17 16:05:31 -05006129 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006130 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006131 break;
dea31012005-04-17 16:05:31 -05006132 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006133 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6134 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6135 did, vport->port_state, ndlp->nlp_flag);
6136
dea31012005-04-17 16:05:31 -05006137 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006138 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006139 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006140 break;
6141 }
James Smart2e0fef82007-06-17 19:56:36 -05006142 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006143 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006144 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006145 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6146 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6147 did, vport->port_state, ndlp->nlp_flag);
6148
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006149 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006150 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006151 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006152 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006153 break;
James Smart12265f62010-10-22 11:05:53 -04006154 case ELS_CMD_RLS:
6155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6156 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6157 did, vport->port_state, ndlp->nlp_flag);
6158
6159 phba->fc_stat.elsRcvRLS++;
6160 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6161 if (newnode)
6162 lpfc_nlp_put(ndlp);
6163 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006164 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006165 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6166 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6167 did, vport->port_state, ndlp->nlp_flag);
6168
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006169 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006170 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006171 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006172 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006173 break;
6174 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6176 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6177 did, vport->port_state, ndlp->nlp_flag);
6178
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006179 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006180 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006181 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006182 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006183 break;
dea31012005-04-17 16:05:31 -05006184 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006185 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6186 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6187 did, vport->port_state, ndlp->nlp_flag);
6188
dea31012005-04-17 16:05:31 -05006189 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006190 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006191 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006192 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006193 break;
James Smart12265f62010-10-22 11:05:53 -04006194 case ELS_CMD_RTV:
6195 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6196 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6197 did, vport->port_state, ndlp->nlp_flag);
6198 phba->fc_stat.elsRcvRTV++;
6199 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6200 if (newnode)
6201 lpfc_nlp_put(ndlp);
6202 break;
James Smart5ffc2662009-11-18 15:39:44 -05006203 case ELS_CMD_RRQ:
6204 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6205 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6206 did, vport->port_state, ndlp->nlp_flag);
6207
6208 phba->fc_stat.elsRcvRRQ++;
6209 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6210 if (newnode)
6211 lpfc_nlp_put(ndlp);
6212 break;
James Smart12265f62010-10-22 11:05:53 -04006213 case ELS_CMD_ECHO:
6214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6215 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6216 did, vport->port_state, ndlp->nlp_flag);
6217
6218 phba->fc_stat.elsRcvECHO++;
6219 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6220 if (newnode)
6221 lpfc_nlp_put(ndlp);
6222 break;
dea31012005-04-17 16:05:31 -05006223 default:
James Smart858c9f62007-06-17 19:56:39 -05006224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6225 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6226 cmd, did, vport->port_state);
6227
dea31012005-04-17 16:05:31 -05006228 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05006229 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05006230
6231 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006232 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6233 "0115 Unknown ELS command x%x "
6234 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006235 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006236 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006237 break;
6238 }
6239
6240 /* check if need to LS_RJT received ELS cmd */
6241 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006242 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006243 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006244 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006245 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6246 NULL);
dea31012005-04-17 16:05:31 -05006247 }
6248
James Smartd7c255b2008-08-24 21:50:00 -04006249 lpfc_nlp_put(elsiocb->context1);
6250 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006251 return;
6252
6253dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006254 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006255 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6256 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006257 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006258 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006259 phba->fc_stat.elsRcvDrop++;
6260}
6261
James Smarte59058c2008-08-24 21:49:00 -04006262/**
James Smart3621a712009-04-06 18:47:14 -04006263 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006264 * @phba: pointer to lpfc hba data structure.
6265 * @vpi: host virtual N_Port identifier.
6266 *
6267 * This routine finds a vport on a HBA (referred by @phba) through a
6268 * @vpi. The function walks the HBA's vport list and returns the address
6269 * of the vport with the matching @vpi.
6270 *
6271 * Return code
6272 * NULL - No vport with the matching @vpi found
6273 * Otherwise - Address to the vport with the matching @vpi.
6274 **/
James Smart6669f9b2009-10-02 15:16:45 -04006275struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006276lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6277{
6278 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006279 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006280
James Smart549e55c2007-08-02 11:09:51 -04006281 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006282 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006283 if (vport->vpi == vpi) {
6284 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006285 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006286 }
James Smart92d7f7b2007-06-17 19:56:38 -05006287 }
James Smart549e55c2007-08-02 11:09:51 -04006288 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006289 return NULL;
6290}
James Smarted957682007-06-17 19:56:37 -05006291
James Smarte59058c2008-08-24 21:49:00 -04006292/**
James Smart3621a712009-04-06 18:47:14 -04006293 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006294 * @phba: pointer to lpfc hba data structure.
6295 * @pring: pointer to a SLI ring.
6296 * @elsiocb: pointer to lpfc els iocb data structure.
6297 *
6298 * This routine is used to process an unsolicited event received from a SLI
6299 * (Service Level Interface) ring. The actual processing of the data buffer
6300 * associated with the unsolicited event is done by invoking the routine
6301 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6302 * SLI ring on which the unsolicited event was received.
6303 **/
James Smarted957682007-06-17 19:56:37 -05006304void
6305lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6306 struct lpfc_iocbq *elsiocb)
6307{
6308 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006309 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006310 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006311 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6312 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006313
James Smartd7c255b2008-08-24 21:50:00 -04006314 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006315 elsiocb->context2 = NULL;
6316 elsiocb->context3 = NULL;
6317
6318 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6319 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6320 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6321 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006322 phba->fc_stat.NoRcvBuf++;
6323 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006324 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006325 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006326 return;
6327 }
6328
James Smart92d7f7b2007-06-17 19:56:38 -05006329 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6330 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6331 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6332 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6333 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006334 else
6335 vport = lpfc_find_vport_by_vpid(phba,
6336 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006337 }
James Smart7f5f3d02008-02-08 18:50:14 -05006338 /* If there are no BDEs associated
6339 * with this IOCB, there is nothing to do.
6340 */
James Smarted957682007-06-17 19:56:37 -05006341 if (icmd->ulpBdeCount == 0)
6342 return;
6343
James Smart7f5f3d02008-02-08 18:50:14 -05006344 /* type of ELS cmd is first 32bit word
6345 * in packet
6346 */
James Smarted957682007-06-17 19:56:37 -05006347 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006348 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006349 } else {
6350 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6351 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006352 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6353 paddr);
James Smarted957682007-06-17 19:56:37 -05006354 }
6355
James Smart92d7f7b2007-06-17 19:56:38 -05006356 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6357 /*
6358 * The different unsolicited event handlers would tell us
6359 * if they are done with "mp" by setting context2 to NULL.
6360 */
dea31012005-04-17 16:05:31 -05006361 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006362 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6363 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006364 }
James Smarted957682007-06-17 19:56:37 -05006365
6366 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006367 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006368 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006369 elsiocb->context2 = bdeBuf2;
6370 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006371 /* free mp if we are done with it */
6372 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006373 lpfc_in_buf_free(phba, elsiocb->context2);
6374 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006375 }
dea31012005-04-17 16:05:31 -05006376 }
dea31012005-04-17 16:05:31 -05006377}
James Smart92d7f7b2007-06-17 19:56:38 -05006378
James Smarte59058c2008-08-24 21:49:00 -04006379/**
James Smart3621a712009-04-06 18:47:14 -04006380 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006381 * @phba: pointer to lpfc hba data structure.
6382 * @vport: pointer to a virtual N_Port data structure.
6383 *
6384 * This routine issues a Port Login (PLOGI) to the Name Server with
6385 * State Change Request (SCR) for a @vport. This routine will create an
6386 * ndlp for the Name Server associated to the @vport if such node does
6387 * not already exist. The PLOGI to Name Server is issued by invoking the
6388 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6389 * (FDMI) is configured to the @vport, a FDMI node will be created and
6390 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6391 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006392void
6393lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6394{
6395 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6396
6397 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6398 if (!ndlp) {
6399 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6400 if (!ndlp) {
6401 if (phba->fc_topology == TOPOLOGY_LOOP) {
6402 lpfc_disc_start(vport);
6403 return;
6404 }
6405 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006406 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6407 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006408 return;
6409 }
6410 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006411 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6412 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6413 if (!ndlp) {
6414 if (phba->fc_topology == TOPOLOGY_LOOP) {
6415 lpfc_disc_start(vport);
6416 return;
6417 }
6418 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6419 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6420 "0348 NameServer login: node freed\n");
6421 return;
6422 }
James Smart92d7f7b2007-06-17 19:56:38 -05006423 }
James Smart58da1ff2008-04-07 10:15:56 -04006424 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006425
6426 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6427
6428 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6429 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006430 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6431 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006432 return;
6433 }
6434
James Smart3de2a652007-08-02 11:09:59 -04006435 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006436 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6437 GFP_KERNEL);
6438 if (ndlp_fdmi) {
6439 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6440 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006441 lpfc_nlp_set_state(vport, ndlp_fdmi,
6442 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006443 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6444 0);
6445 }
6446 }
6447 return;
6448}
6449
James Smarte59058c2008-08-24 21:49:00 -04006450/**
James Smart3621a712009-04-06 18:47:14 -04006451 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006452 * @phba: pointer to lpfc hba data structure.
6453 * @pmb: pointer to the driver internal queue element for mailbox command.
6454 *
6455 * This routine is the completion callback function to register new vport
6456 * mailbox command. If the new vport mailbox command completes successfully,
6457 * the fabric registration login shall be performed on physical port (the
6458 * new vport created is actually a physical port, with VPI 0) or the port
6459 * login to Name Server for State Change Request (SCR) will be performed
6460 * on virtual port (real virtual port, with VPI greater than 0).
6461 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006462static void
6463lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6464{
6465 struct lpfc_vport *vport = pmb->vport;
6466 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6467 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006468 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006469 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006470
James Smart09372822008-01-11 01:52:54 -05006471 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006472 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006473 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006474
6475 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006476 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006477 "0915 Register VPI failed : Status: x%x"
6478 " upd bit: x%x \n", mb->mbxStatus,
6479 mb->un.varRegVpi.upd);
6480 if (phba->sli_rev == LPFC_SLI_REV4 &&
6481 mb->un.varRegVpi.upd)
6482 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006483
6484 switch (mb->mbxStatus) {
6485 case 0x11: /* unsupported feature */
6486 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006487 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006488 /* giving up on vport registration */
6489 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6490 spin_lock_irq(shost->host_lock);
6491 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6492 spin_unlock_irq(shost->host_lock);
6493 lpfc_can_disctmo(vport);
6494 break;
James Smart695a8142010-01-26 23:08:03 -05006495 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6496 case 0x20:
6497 spin_lock_irq(shost->host_lock);
6498 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6499 spin_unlock_irq(shost->host_lock);
6500 lpfc_init_vpi(phba, pmb, vport->vpi);
6501 pmb->vport = vport;
6502 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6503 rc = lpfc_sli_issue_mbox(phba, pmb,
6504 MBX_NOWAIT);
6505 if (rc == MBX_NOT_FINISHED) {
6506 lpfc_printf_vlog(vport,
6507 KERN_ERR, LOG_MBOX,
6508 "2732 Failed to issue INIT_VPI"
6509 " mailbox command\n");
6510 } else {
6511 lpfc_nlp_put(ndlp);
6512 return;
6513 }
6514
James Smart92d7f7b2007-06-17 19:56:38 -05006515 default:
6516 /* Try to recover from this error */
6517 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006518 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006519 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006520 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006521 if (vport->port_type == LPFC_PHYSICAL_PORT
6522 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006523 lpfc_initial_flogi(vport);
6524 else
6525 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006526 break;
6527 }
James Smart92d7f7b2007-06-17 19:56:38 -05006528 } else {
James Smart695a8142010-01-26 23:08:03 -05006529 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006530 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006531 spin_unlock_irq(shost->host_lock);
6532 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006533 if (phba->sli_rev < LPFC_SLI_REV4)
6534 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006535 else {
James Smartfc2b9892010-02-26 14:15:29 -05006536 /*
6537 * If the physical port is instantiated using
6538 * FDISC, do not start vport discovery.
6539 */
6540 if (vport->port_state != LPFC_FDISC)
6541 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006542 lpfc_do_scr_ns_plogi(phba, vport);
6543 }
6544 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006545 lpfc_do_scr_ns_plogi(phba, vport);
6546 }
James Smart38b92ef2010-08-04 16:11:39 -04006547mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006548 /* Now, we decrement the ndlp reference count held for this
6549 * callback function
6550 */
6551 lpfc_nlp_put(ndlp);
6552
James Smart92d7f7b2007-06-17 19:56:38 -05006553 mempool_free(pmb, phba->mbox_mem_pool);
6554 return;
6555}
6556
James Smarte59058c2008-08-24 21:49:00 -04006557/**
James Smart3621a712009-04-06 18:47:14 -04006558 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006559 * @phba: pointer to lpfc hba data structure.
6560 * @vport: pointer to a host virtual N_Port data structure.
6561 * @ndlp: pointer to a node-list data structure.
6562 *
6563 * This routine registers the @vport as a new virtual port with a HBA.
6564 * It is done through a registering vpi mailbox command.
6565 **/
James Smart695a8142010-01-26 23:08:03 -05006566void
James Smart92d7f7b2007-06-17 19:56:38 -05006567lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6568 struct lpfc_nodelist *ndlp)
6569{
James Smart09372822008-01-11 01:52:54 -05006570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006571 LPFC_MBOXQ_t *mbox;
6572
6573 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6574 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006575 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006576 mbox->vport = vport;
6577 mbox->context2 = lpfc_nlp_get(ndlp);
6578 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006579 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006580 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006581 /* mailbox command not success, decrement ndlp
6582 * reference count for this command
6583 */
6584 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006585 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006586
James Smarte8b62012007-08-02 11:10:09 -04006587 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6588 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006589 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006590 }
6591 } else {
James Smarte8b62012007-08-02 11:10:09 -04006592 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6593 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006594 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006595 }
James Smartfa4066b2008-01-11 01:53:27 -05006596 return;
6597
6598mbox_err_exit:
6599 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6600 spin_lock_irq(shost->host_lock);
6601 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6602 spin_unlock_irq(shost->host_lock);
6603 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006604}
6605
James Smarte59058c2008-08-24 21:49:00 -04006606/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006607 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006608 * @phba: pointer to lpfc hba data structure.
6609 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006610 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006611 **/
6612void
James Smart0c9ab6f2010-02-26 14:15:57 -05006613lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006614{
6615 struct lpfc_vport **vports;
6616 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006617 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006618 int i;
James Smart695a8142010-01-26 23:08:03 -05006619
6620 /* Treat this failure as linkdown for all vports */
6621 link_state = phba->link_state;
6622 lpfc_linkdown(phba);
6623 phba->link_state = link_state;
6624
6625 vports = lpfc_create_vport_work_array(phba);
6626
6627 if (vports) {
6628 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6629 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6630 if (ndlp)
6631 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6632 lpfc_els_flush_cmd(vports[i]);
6633 }
6634 lpfc_destroy_vport_work_array(phba, vports);
6635 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006636}
6637
6638/**
6639 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6640 * @phba: pointer to lpfc hba data structure.
6641 *
6642 * This routine abort all pending discovery commands and
6643 * start a timer to retry FLOGI for the physical port
6644 * discovery.
6645 **/
6646void
6647lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6648{
6649 struct lpfc_nodelist *ndlp;
6650 struct Scsi_Host *shost;
6651
6652 /* Cancel the all vports retry delay retry timers */
6653 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006654
6655 /* If fabric require FLOGI, then re-instantiate physical login */
6656 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6657 if (!ndlp)
6658 return;
6659
James Smart695a8142010-01-26 23:08:03 -05006660 shost = lpfc_shost_from_vport(phba->pport);
6661 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6662 spin_lock_irq(shost->host_lock);
6663 ndlp->nlp_flag |= NLP_DELAY_TMO;
6664 spin_unlock_irq(shost->host_lock);
6665 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6666 phba->pport->port_state = LPFC_FLOGI;
6667 return;
6668}
6669
6670/**
6671 * lpfc_fabric_login_reqd - Check if FLOGI required.
6672 * @phba: pointer to lpfc hba data structure.
6673 * @cmdiocb: pointer to FDISC command iocb.
6674 * @rspiocb: pointer to FDISC response iocb.
6675 *
6676 * This routine checks if a FLOGI is reguired for FDISC
6677 * to succeed.
6678 **/
6679static int
6680lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6681 struct lpfc_iocbq *cmdiocb,
6682 struct lpfc_iocbq *rspiocb)
6683{
6684
6685 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6686 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6687 return 0;
6688 else
6689 return 1;
6690}
6691
6692/**
James Smart3621a712009-04-06 18:47:14 -04006693 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006694 * @phba: pointer to lpfc hba data structure.
6695 * @cmdiocb: pointer to lpfc command iocb data structure.
6696 * @rspiocb: pointer to lpfc response iocb data structure.
6697 *
6698 * This routine is the completion callback function to a Fabric Discover
6699 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6700 * single threaded, each FDISC completion callback function will reset
6701 * the discovery timer for all vports such that the timers will not get
6702 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6703 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6704 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6705 * assigned to the vport has been changed with the completion of the FDISC
6706 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6707 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6708 * routine is invoked to register new vport with the HBA. Otherwise, the
6709 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6710 * Server for State Change Request (SCR).
6711 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006712static void
6713lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6714 struct lpfc_iocbq *rspiocb)
6715{
6716 struct lpfc_vport *vport = cmdiocb->vport;
6717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6718 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6719 struct lpfc_nodelist *np;
6720 struct lpfc_nodelist *next_np;
6721 IOCB_t *irsp = &rspiocb->iocb;
6722 struct lpfc_iocbq *piocb;
6723
James Smarte8b62012007-08-02 11:10:09 -04006724 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6725 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6726 irsp->ulpStatus, irsp->un.ulpWord[4],
6727 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006728 /* Since all FDISCs are being single threaded, we
6729 * must reset the discovery timer for ALL vports
6730 * waiting to send FDISC when one completes.
6731 */
6732 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6733 lpfc_set_disctmo(piocb->vport);
6734 }
6735
James Smart858c9f62007-06-17 19:56:39 -05006736 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6737 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6738 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6739
James Smart92d7f7b2007-06-17 19:56:38 -05006740 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006741
6742 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6743 lpfc_retry_pport_discovery(phba);
6744 goto out;
6745 }
6746
James Smart92d7f7b2007-06-17 19:56:38 -05006747 /* Check for retry */
6748 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6749 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006750 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006752 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006753 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006754 goto fdisc_failed;
6755 }
James Smartd7c255b2008-08-24 21:50:00 -04006756 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006757 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006758 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006759 vport->fc_flag |= FC_FABRIC;
6760 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6761 vport->fc_flag |= FC_PUBLIC_LOOP;
6762 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006763
James Smartd7c255b2008-08-24 21:50:00 -04006764 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6765 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6766 if ((vport->fc_prevDID != vport->fc_myDID) &&
6767 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6768 /* If our NportID changed, we need to ensure all
6769 * remaining NPORTs get unreg_login'ed so we can
6770 * issue unreg_vpi.
6771 */
6772 list_for_each_entry_safe(np, next_np,
6773 &vport->fc_nodes, nlp_listp) {
6774 if (!NLP_CHK_NODE_ACT(ndlp) ||
6775 (np->nlp_state != NLP_STE_NPR_NODE) ||
6776 !(np->nlp_flag & NLP_NPR_ADISC))
6777 continue;
James Smart09372822008-01-11 01:52:54 -05006778 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006779 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006780 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006781 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006782 }
James Smart78730cf2010-04-06 15:06:30 -04006783 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006784 lpfc_mbx_unreg_vpi(vport);
6785 spin_lock_irq(shost->host_lock);
6786 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006787 if (phba->sli_rev == LPFC_SLI_REV4)
6788 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006789 else
6790 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006791 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04006792 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6793 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6794 /*
6795 * Driver needs to re-reg VPI in order for f/w
6796 * to update the MAC address.
6797 */
6798 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04006799 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006800 }
6801
James Smartecfd03c2010-02-12 14:41:27 -05006802 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6803 lpfc_issue_init_vpi(vport);
6804 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006805 lpfc_register_new_vport(phba, vport, ndlp);
6806 else
6807 lpfc_do_scr_ns_plogi(phba, vport);
6808 goto out;
6809fdisc_failed:
6810 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6811 /* Cancel discovery timer */
6812 lpfc_can_disctmo(vport);
6813 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006814out:
6815 lpfc_els_free_iocb(phba, cmdiocb);
6816}
6817
James Smarte59058c2008-08-24 21:49:00 -04006818/**
James Smart3621a712009-04-06 18:47:14 -04006819 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006820 * @vport: pointer to a virtual N_Port data structure.
6821 * @ndlp: pointer to a node-list data structure.
6822 * @retry: number of retries to the command IOCB.
6823 *
6824 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6825 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6826 * routine to issue the IOCB, which makes sure only one outstanding fabric
6827 * IOCB will be sent off HBA at any given time.
6828 *
6829 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6830 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6831 * will be stored into the context1 field of the IOCB for the completion
6832 * callback function to the FDISC ELS command.
6833 *
6834 * Return code
6835 * 0 - Successfully issued fdisc iocb command
6836 * 1 - Failed to issue fdisc iocb command
6837 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006838static int
James Smart92d7f7b2007-06-17 19:56:38 -05006839lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6840 uint8_t retry)
6841{
6842 struct lpfc_hba *phba = vport->phba;
6843 IOCB_t *icmd;
6844 struct lpfc_iocbq *elsiocb;
6845 struct serv_parm *sp;
6846 uint8_t *pcmd;
6847 uint16_t cmdsize;
6848 int did = ndlp->nlp_DID;
6849 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006850
James Smart5ffc2662009-11-18 15:39:44 -05006851 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006852 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6853 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6854 ELS_CMD_FDISC);
6855 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006856 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006857 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6858 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006859 return 1;
6860 }
6861
6862 icmd = &elsiocb->iocb;
6863 icmd->un.elsreq64.myID = 0;
6864 icmd->un.elsreq64.fl = 1;
6865
James Smartf1126682009-06-10 17:22:44 -04006866 if (phba->sli_rev == LPFC_SLI_REV4) {
6867 /* FDISC needs to be 1 for WQE VPI */
6868 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6869 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6870 /* Set the ulpContext to the vpi */
6871 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6872 } else {
6873 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6874 icmd->ulpCt_h = 1;
6875 icmd->ulpCt_l = 0;
6876 }
James Smart92d7f7b2007-06-17 19:56:38 -05006877
6878 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6879 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6880 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6881 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6882 sp = (struct serv_parm *) pcmd;
6883 /* Setup CSPs accordingly for Fabric */
6884 sp->cmn.e_d_tov = 0;
6885 sp->cmn.w2.r_a_tov = 0;
6886 sp->cls1.classValid = 0;
6887 sp->cls2.seqDelivery = 1;
6888 sp->cls3.seqDelivery = 1;
6889
6890 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6891 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6892 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6893 pcmd += sizeof(uint32_t); /* Port Name */
6894 memcpy(pcmd, &vport->fc_portname, 8);
6895 pcmd += sizeof(uint32_t); /* Node Name */
6896 pcmd += sizeof(uint32_t); /* Node Name */
6897 memcpy(pcmd, &vport->fc_nodename, 8);
6898
6899 lpfc_set_disctmo(vport);
6900
6901 phba->fc_stat.elsXmitFDISC++;
6902 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6903
James Smart858c9f62007-06-17 19:56:39 -05006904 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6905 "Issue FDISC: did:x%x",
6906 did, 0, 0);
6907
James Smart92d7f7b2007-06-17 19:56:38 -05006908 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6909 if (rc == IOCB_ERROR) {
6910 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006911 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006912 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6913 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006914 return 1;
6915 }
6916 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006917 return 0;
6918}
6919
James Smarte59058c2008-08-24 21:49:00 -04006920/**
James Smart3621a712009-04-06 18:47:14 -04006921 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006922 * @phba: pointer to lpfc hba data structure.
6923 * @cmdiocb: pointer to lpfc command iocb data structure.
6924 * @rspiocb: pointer to lpfc response iocb data structure.
6925 *
6926 * This routine is the completion callback function to the issuing of a LOGO
6927 * ELS command off a vport. It frees the command IOCB and then decrement the
6928 * reference count held on ndlp for this completion function, indicating that
6929 * the reference to the ndlp is no long needed. Note that the
6930 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6931 * callback function and an additional explicit ndlp reference decrementation
6932 * will trigger the actual release of the ndlp.
6933 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006934static void
6935lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6936 struct lpfc_iocbq *rspiocb)
6937{
6938 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006939 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006940 struct lpfc_nodelist *ndlp;
6941 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006942
6943 irsp = &rspiocb->iocb;
6944 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6945 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6946 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006947
6948 lpfc_els_free_iocb(phba, cmdiocb);
6949 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006950
6951 /* Trigger the release of the ndlp after logo */
6952 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006953}
6954
James Smarte59058c2008-08-24 21:49:00 -04006955/**
James Smart3621a712009-04-06 18:47:14 -04006956 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006957 * @vport: pointer to a virtual N_Port data structure.
6958 * @ndlp: pointer to a node-list data structure.
6959 *
6960 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6961 *
6962 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6963 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6964 * will be stored into the context1 field of the IOCB for the completion
6965 * callback function to the LOGO ELS command.
6966 *
6967 * Return codes
6968 * 0 - Successfully issued logo off the @vport
6969 * 1 - Failed to issue logo off the @vport
6970 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006971int
6972lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6973{
6974 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6975 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006976 IOCB_t *icmd;
6977 struct lpfc_iocbq *elsiocb;
6978 uint8_t *pcmd;
6979 uint16_t cmdsize;
6980
6981 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6982 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6983 ELS_CMD_LOGO);
6984 if (!elsiocb)
6985 return 1;
6986
6987 icmd = &elsiocb->iocb;
6988 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6989 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6990 pcmd += sizeof(uint32_t);
6991
6992 /* Fill in LOGO payload */
6993 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6994 pcmd += sizeof(uint32_t);
6995 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6996
James Smart858c9f62007-06-17 19:56:39 -05006997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6998 "Issue LOGO npiv did:x%x flg:x%x",
6999 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7000
James Smart92d7f7b2007-06-17 19:56:38 -05007001 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7002 spin_lock_irq(shost->host_lock);
7003 ndlp->nlp_flag |= NLP_LOGO_SND;
7004 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007005 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7006 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007007 spin_lock_irq(shost->host_lock);
7008 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7009 spin_unlock_irq(shost->host_lock);
7010 lpfc_els_free_iocb(phba, elsiocb);
7011 return 1;
7012 }
7013 return 0;
7014}
7015
James Smarte59058c2008-08-24 21:49:00 -04007016/**
James Smart3621a712009-04-06 18:47:14 -04007017 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007018 * @ptr: holder for the timer function associated data.
7019 *
7020 * This routine is invoked by the fabric iocb block timer after
7021 * timeout. It posts the fabric iocb block timeout event by setting the
7022 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7023 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7024 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7025 * posted event WORKER_FABRIC_BLOCK_TMO.
7026 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007027void
7028lpfc_fabric_block_timeout(unsigned long ptr)
7029{
7030 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7031 unsigned long iflags;
7032 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007033
James Smart92d7f7b2007-06-17 19:56:38 -05007034 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7035 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7036 if (!tmo_posted)
7037 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7038 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7039
James Smart5e9d9b82008-06-14 22:52:53 -04007040 if (!tmo_posted)
7041 lpfc_worker_wake_up(phba);
7042 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007043}
7044
James Smarte59058c2008-08-24 21:49:00 -04007045/**
James Smart3621a712009-04-06 18:47:14 -04007046 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007047 * @phba: pointer to lpfc hba data structure.
7048 *
7049 * This routine issues one fabric iocb from the driver internal list to
7050 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7051 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7052 * remove one pending fabric iocb from the driver internal list and invokes
7053 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7054 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007055static void
7056lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7057{
7058 struct lpfc_iocbq *iocb;
7059 unsigned long iflags;
7060 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007061 IOCB_t *cmd;
7062
7063repeat:
7064 iocb = NULL;
7065 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007066 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007067 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7068 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7069 list);
7070 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007071 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007072 atomic_inc(&phba->fabric_iocb_count);
7073 }
7074 spin_unlock_irqrestore(&phba->hbalock, iflags);
7075 if (iocb) {
7076 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7077 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7078 iocb->iocb_flag |= LPFC_IO_FABRIC;
7079
James Smart858c9f62007-06-17 19:56:39 -05007080 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7081 "Fabric sched1: ste:x%x",
7082 iocb->vport->port_state, 0, 0);
7083
James Smart3772a992009-05-22 14:50:54 -04007084 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007085
7086 if (ret == IOCB_ERROR) {
7087 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7088 iocb->fabric_iocb_cmpl = NULL;
7089 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7090 cmd = &iocb->iocb;
7091 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7092 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7093 iocb->iocb_cmpl(phba, iocb, iocb);
7094
7095 atomic_dec(&phba->fabric_iocb_count);
7096 goto repeat;
7097 }
7098 }
7099
7100 return;
7101}
7102
James Smarte59058c2008-08-24 21:49:00 -04007103/**
James Smart3621a712009-04-06 18:47:14 -04007104 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007105 * @phba: pointer to lpfc hba data structure.
7106 *
7107 * This routine unblocks the issuing fabric iocb command. The function
7108 * will clear the fabric iocb block bit and then invoke the routine
7109 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7110 * from the driver internal fabric iocb list.
7111 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007112void
7113lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7114{
7115 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7116
7117 lpfc_resume_fabric_iocbs(phba);
7118 return;
7119}
7120
James Smarte59058c2008-08-24 21:49:00 -04007121/**
James Smart3621a712009-04-06 18:47:14 -04007122 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007123 * @phba: pointer to lpfc hba data structure.
7124 *
7125 * This routine blocks the issuing fabric iocb for a specified amount of
7126 * time (currently 100 ms). This is done by set the fabric iocb block bit
7127 * and set up a timeout timer for 100ms. When the block bit is set, no more
7128 * fabric iocb will be issued out of the HBA.
7129 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007130static void
7131lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7132{
7133 int blocked;
7134
7135 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007136 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007137 if (!blocked)
7138 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7139
7140 return;
7141}
7142
James Smarte59058c2008-08-24 21:49:00 -04007143/**
James Smart3621a712009-04-06 18:47:14 -04007144 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007145 * @phba: pointer to lpfc hba data structure.
7146 * @cmdiocb: pointer to lpfc command iocb data structure.
7147 * @rspiocb: pointer to lpfc response iocb data structure.
7148 *
7149 * This routine is the callback function that is put to the fabric iocb's
7150 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7151 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7152 * function first restores and invokes the original iocb's callback function
7153 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7154 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7155 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007156static void
7157lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7158 struct lpfc_iocbq *rspiocb)
7159{
7160 struct ls_rjt stat;
7161
7162 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7163 BUG();
7164
7165 switch (rspiocb->iocb.ulpStatus) {
7166 case IOSTAT_NPORT_RJT:
7167 case IOSTAT_FABRIC_RJT:
7168 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7169 lpfc_block_fabric_iocbs(phba);
7170 }
7171 break;
7172
7173 case IOSTAT_NPORT_BSY:
7174 case IOSTAT_FABRIC_BSY:
7175 lpfc_block_fabric_iocbs(phba);
7176 break;
7177
7178 case IOSTAT_LS_RJT:
7179 stat.un.lsRjtError =
7180 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7181 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7182 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7183 lpfc_block_fabric_iocbs(phba);
7184 break;
7185 }
7186
7187 if (atomic_read(&phba->fabric_iocb_count) == 0)
7188 BUG();
7189
7190 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7191 cmdiocb->fabric_iocb_cmpl = NULL;
7192 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7193 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7194
7195 atomic_dec(&phba->fabric_iocb_count);
7196 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007197 /* Post any pending iocbs to HBA */
7198 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007199 }
7200}
7201
James Smarte59058c2008-08-24 21:49:00 -04007202/**
James Smart3621a712009-04-06 18:47:14 -04007203 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007204 * @phba: pointer to lpfc hba data structure.
7205 * @iocb: pointer to lpfc command iocb data structure.
7206 *
7207 * This routine is used as the top-level API for issuing a fabric iocb command
7208 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7209 * function makes sure that only one fabric bound iocb will be outstanding at
7210 * any given time. As such, this function will first check to see whether there
7211 * is already an outstanding fabric iocb on the wire. If so, it will put the
7212 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7213 * issued later. Otherwise, it will issue the iocb on the wire and update the
7214 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7215 *
7216 * Note, this implementation has a potential sending out fabric IOCBs out of
7217 * order. The problem is caused by the construction of the "ready" boolen does
7218 * not include the condition that the internal fabric IOCB list is empty. As
7219 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7220 * ahead of the fabric IOCBs in the internal list.
7221 *
7222 * Return code
7223 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7224 * IOCB_ERROR - failed to issue fabric iocb
7225 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007226static int
James Smart92d7f7b2007-06-17 19:56:38 -05007227lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7228{
7229 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007230 int ready;
7231 int ret;
7232
7233 if (atomic_read(&phba->fabric_iocb_count) > 1)
7234 BUG();
7235
7236 spin_lock_irqsave(&phba->hbalock, iflags);
7237 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7238 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7239
James Smart7f5f3d02008-02-08 18:50:14 -05007240 if (ready)
7241 /* Increment fabric iocb count to hold the position */
7242 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007243 spin_unlock_irqrestore(&phba->hbalock, iflags);
7244 if (ready) {
7245 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7246 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7247 iocb->iocb_flag |= LPFC_IO_FABRIC;
7248
James Smart858c9f62007-06-17 19:56:39 -05007249 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7250 "Fabric sched2: ste:x%x",
7251 iocb->vport->port_state, 0, 0);
7252
James Smart3772a992009-05-22 14:50:54 -04007253 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007254
7255 if (ret == IOCB_ERROR) {
7256 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7257 iocb->fabric_iocb_cmpl = NULL;
7258 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7259 atomic_dec(&phba->fabric_iocb_count);
7260 }
7261 } else {
7262 spin_lock_irqsave(&phba->hbalock, iflags);
7263 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7264 spin_unlock_irqrestore(&phba->hbalock, iflags);
7265 ret = IOCB_SUCCESS;
7266 }
7267 return ret;
7268}
7269
James Smarte59058c2008-08-24 21:49:00 -04007270/**
James Smart3621a712009-04-06 18:47:14 -04007271 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007272 * @vport: pointer to a virtual N_Port data structure.
7273 *
7274 * This routine aborts all the IOCBs associated with a @vport from the
7275 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7276 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7277 * list, removes each IOCB associated with the @vport off the list, set the
7278 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7279 * associated with the IOCB.
7280 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007281static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007282{
7283 LIST_HEAD(completions);
7284 struct lpfc_hba *phba = vport->phba;
7285 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007286
7287 spin_lock_irq(&phba->hbalock);
7288 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7289 list) {
7290
7291 if (piocb->vport != vport)
7292 continue;
7293
7294 list_move_tail(&piocb->list, &completions);
7295 }
7296 spin_unlock_irq(&phba->hbalock);
7297
James Smarta257bf92009-04-06 18:48:10 -04007298 /* Cancel all the IOCBs from the completions list */
7299 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7300 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007301}
7302
James Smarte59058c2008-08-24 21:49:00 -04007303/**
James Smart3621a712009-04-06 18:47:14 -04007304 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007305 * @ndlp: pointer to a node-list data structure.
7306 *
7307 * This routine aborts all the IOCBs associated with an @ndlp from the
7308 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7309 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7310 * list, removes each IOCB associated with the @ndlp off the list, set the
7311 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7312 * associated with the IOCB.
7313 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007314void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7315{
7316 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007317 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007318 struct lpfc_iocbq *tmp_iocb, *piocb;
7319 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007320
7321 spin_lock_irq(&phba->hbalock);
7322 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7323 list) {
7324 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7325
7326 list_move_tail(&piocb->list, &completions);
7327 }
7328 }
7329 spin_unlock_irq(&phba->hbalock);
7330
James Smarta257bf92009-04-06 18:48:10 -04007331 /* Cancel all the IOCBs from the completions list */
7332 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7333 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007334}
7335
James Smarte59058c2008-08-24 21:49:00 -04007336/**
James Smart3621a712009-04-06 18:47:14 -04007337 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007338 * @phba: pointer to lpfc hba data structure.
7339 *
7340 * This routine aborts all the IOCBs currently on the driver internal
7341 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7342 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7343 * list, removes IOCBs off the list, set the status feild to
7344 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7345 * the IOCB.
7346 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007347void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7348{
7349 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007350
7351 spin_lock_irq(&phba->hbalock);
7352 list_splice_init(&phba->fabric_iocb_list, &completions);
7353 spin_unlock_irq(&phba->hbalock);
7354
James Smarta257bf92009-04-06 18:48:10 -04007355 /* Cancel all the IOCBs from the completions list */
7356 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7357 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007358}
James Smart6fb120a2009-05-22 14:52:59 -04007359
7360/**
7361 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7362 * @phba: pointer to lpfc hba data structure.
7363 * @axri: pointer to the els xri abort wcqe structure.
7364 *
7365 * This routine is invoked by the worker thread to process a SLI4 slow-path
7366 * ELS aborted xri.
7367 **/
7368void
7369lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7370 struct sli4_wcqe_xri_aborted *axri)
7371{
7372 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7373 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7374 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04007375 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007376
James Smart0f65ff62010-02-26 14:14:23 -05007377 spin_lock_irqsave(&phba->hbalock, iflag);
7378 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007379 list_for_each_entry_safe(sglq_entry, sglq_next,
7380 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7381 if (sglq_entry->sli4_xritag == xri) {
7382 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007383 list_add_tail(&sglq_entry->list,
7384 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007385 sglq_entry->state = SGL_FREED;
7386 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007387 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04007388
7389 /* Check if TXQ queue needs to be serviced */
7390 if (pring->txq_cnt)
7391 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007392 return;
7393 }
7394 }
James Smart0f65ff62010-02-26 14:14:23 -05007395 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7396 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7397 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7398 spin_unlock_irqrestore(&phba->hbalock, iflag);
7399 return;
7400 }
7401 sglq_entry->state = SGL_XRI_ABORTED;
7402 spin_unlock_irqrestore(&phba->hbalock, iflag);
7403 return;
James Smart6fb120a2009-05-22 14:52:59 -04007404}