blob: e61b57df241b85912adc556c4db0e25c6da6b0a5 [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 Smart5af5eee2010-10-22 11:06:38 -0400583
584 if (phba->sli_rev == LPFC_SLI_REV4)
585 lpfc_sli4_unreg_all_rpis(vport);
586
James Smart92d7f7b2007-06-17 19:56:38 -0500587 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
588 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500589 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500590 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500591 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500592 }
James Smartecfd03c2010-02-12 14:41:27 -0500593 /*
594 * If VPI is unreged, driver need to do INIT_VPI
595 * before re-registering
596 */
597 if (phba->sli_rev == LPFC_SLI_REV4) {
598 spin_lock_irq(shost->host_lock);
599 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
600 spin_unlock_irq(shost->host_lock);
601 }
James Smart38b92ef2010-08-04 16:11:39 -0400602 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
603 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
604 /*
605 * Driver needs to re-reg VPI in order for f/w
606 * to update the MAC address.
607 */
608 lpfc_register_new_vport(phba, vport, ndlp);
609 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500610 }
611
James Smart6fb120a2009-05-22 14:52:59 -0400612 if (phba->sli_rev < LPFC_SLI_REV4) {
613 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
614 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
615 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
616 lpfc_register_new_vport(phba, vport, ndlp);
617 else
618 lpfc_issue_fabric_reglogin(vport);
619 } else {
620 ndlp->nlp_type |= NLP_FABRIC;
621 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500622 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
623 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400624 lpfc_start_fdiscs(phba);
625 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500626 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500627 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500628 else
James Smart6fb120a2009-05-22 14:52:59 -0400629 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500630 }
dea31012005-04-17 16:05:31 -0500631 return 0;
dea31012005-04-17 16:05:31 -0500632}
James Smarte59058c2008-08-24 21:49:00 -0400633/**
James Smart3621a712009-04-06 18:47:14 -0400634 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400635 * @vport: pointer to a host virtual N_Port data structure.
636 * @ndlp: pointer to a node-list data structure.
637 * @sp: pointer to service parameter data structure.
638 *
639 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
640 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
641 * in a point-to-point topology. First, the @vport's N_Port Name is compared
642 * with the received N_Port Name: if the @vport's N_Port Name is greater than
643 * the received N_Port Name lexicographically, this node shall assign local
644 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
645 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
646 * this node shall just wait for the remote node to issue PLOGI and assign
647 * N_Port IDs.
648 *
649 * Return code
650 * 0 - Success
651 * -ENXIO - Fail
652 **/
dea31012005-04-17 16:05:31 -0500653static int
James Smart2e0fef82007-06-17 19:56:36 -0500654lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
655 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500656{
James Smart2e0fef82007-06-17 19:56:36 -0500657 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
658 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500659 LPFC_MBOXQ_t *mbox;
660 int rc;
661
James Smart2e0fef82007-06-17 19:56:36 -0500662 spin_lock_irq(shost->host_lock);
663 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
664 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500665
666 phba->fc_edtov = FF_DEF_EDTOV;
667 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500668 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500669 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500670 if (rc >= 0) {
671 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500672 spin_lock_irq(shost->host_lock);
673 vport->fc_flag |= FC_PT2PT_PLOGI;
674 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500675
676 /*
677 * N_Port ID cannot be 0, set our to LocalID the other
678 * side will be RemoteID.
679 */
680
681 /* not equal */
682 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500683 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500684
685 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
686 if (!mbox)
687 goto fail;
688
689 lpfc_config_link(phba, mbox);
690
691 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500692 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400693 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500694 if (rc == MBX_NOT_FINISHED) {
695 mempool_free(mbox, phba->mbox_mem_pool);
696 goto fail;
697 }
James Smarte47c9092008-02-08 18:49:26 -0500698 /* Decrement ndlp reference count indicating that ndlp can be
699 * safely released when other references to it are done.
700 */
James Smart329f9bc2007-04-25 09:53:01 -0400701 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500702
James Smart2e0fef82007-06-17 19:56:36 -0500703 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500704 if (!ndlp) {
705 /*
706 * Cannot find existing Fabric ndlp, so allocate a
707 * new one
708 */
709 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
710 if (!ndlp)
711 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500712 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500713 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
714 ndlp = lpfc_enable_node(vport, ndlp,
715 NLP_STE_UNUSED_NODE);
716 if(!ndlp)
717 goto fail;
dea31012005-04-17 16:05:31 -0500718 }
719
720 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500721 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500722 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500723 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500724 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500725 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
726 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500727 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500728 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500729 } else
730 /* This side will wait for the PLOGI, decrement ndlp reference
731 * count indicating that ndlp can be released when other
732 * references to it are done.
733 */
James Smart329f9bc2007-04-25 09:53:01 -0400734 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500735
James Smart09372822008-01-11 01:52:54 -0500736 /* If we are pt2pt with another NPort, force NPIV off! */
737 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
738
James Smart2e0fef82007-06-17 19:56:36 -0500739 spin_lock_irq(shost->host_lock);
740 vport->fc_flag |= FC_PT2PT;
741 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500742
743 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500744 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500745 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500746fail:
dea31012005-04-17 16:05:31 -0500747 return -ENXIO;
748}
749
James Smarte59058c2008-08-24 21:49:00 -0400750/**
James Smart3621a712009-04-06 18:47:14 -0400751 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400752 * @phba: pointer to lpfc hba data structure.
753 * @cmdiocb: pointer to lpfc command iocb data structure.
754 * @rspiocb: pointer to lpfc response iocb data structure.
755 *
756 * This routine is the top-level completion callback function for issuing
757 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
758 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
759 * retry has been made (either immediately or delayed with lpfc_els_retry()
760 * returning 1), the command IOCB will be released and function returned.
761 * If the retry attempt has been given up (possibly reach the maximum
762 * number of retries), one additional decrement of ndlp reference shall be
763 * invoked before going out after releasing the command IOCB. This will
764 * actually release the remote node (Note, lpfc_els_free_iocb() will also
765 * invoke one decrement of ndlp reference count). If no error reported in
766 * the IOCB status, the command Port ID field is used to determine whether
767 * this is a point-to-point topology or a fabric topology: if the Port ID
768 * field is assigned, it is a fabric topology; otherwise, it is a
769 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
770 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
771 * specific topology completion conditions.
772 **/
dea31012005-04-17 16:05:31 -0500773static void
James Smart329f9bc2007-04-25 09:53:01 -0400774lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
775 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500776{
James Smart2e0fef82007-06-17 19:56:36 -0500777 struct lpfc_vport *vport = cmdiocb->vport;
778 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500779 IOCB_t *irsp = &rspiocb->iocb;
780 struct lpfc_nodelist *ndlp = cmdiocb->context1;
781 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
782 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500783 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500784 int rc;
785
786 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500787 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500788 /* One additional decrement on node reference count to
789 * trigger the release of the node
790 */
James Smart329f9bc2007-04-25 09:53:01 -0400791 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500792 goto out;
793 }
794
James Smart858c9f62007-06-17 19:56:39 -0500795 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
796 "FLOGI cmpl: status:x%x/x%x state:x%x",
797 irsp->ulpStatus, irsp->un.ulpWord[4],
798 vport->port_state);
799
dea31012005-04-17 16:05:31 -0500800 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500801 /*
James Smarta93ff372010-10-22 11:06:08 -0400802 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500803 * due to new FCF discovery
804 */
805 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400806 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
807 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
808 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500809 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400810 "2611 FLOGI failed on FCF (x%x), "
811 "status:x%x/x%x, tmo:x%x, perform "
812 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400813 phba->fcf.current_rec.fcf_indx,
814 irsp->ulpStatus, irsp->un.ulpWord[4],
815 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500816 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400817 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
818 if (rc)
819 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500820 }
821
James Smart38b92ef2010-08-04 16:11:39 -0400822 /* FLOGI failure */
823 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
824 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
825 irsp->ulpStatus, irsp->un.ulpWord[4],
826 irsp->ulpTimeout);
827
dea31012005-04-17 16:05:31 -0500828 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500829 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500830 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500831
dea31012005-04-17 16:05:31 -0500832 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500833 spin_lock_irq(shost->host_lock);
834 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
835 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500836
James Smart329f9bc2007-04-25 09:53:01 -0400837 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500838 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
839 * alpa map would take too long otherwise.
840 */
841 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400842 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500843 }
844
845 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500846 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
847 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400848 irsp->ulpStatus, irsp->un.ulpWord[4],
849 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500850 goto flogifail;
851 }
James Smart695a8142010-01-26 23:08:03 -0500852 spin_lock_irq(shost->host_lock);
853 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400854 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500855 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500856
857 /*
858 * The FLogI succeeded. Sync the data for the CPU before
859 * accessing it.
860 */
861 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
862
863 sp = prsp->virt + sizeof(uint32_t);
864
865 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400866 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200867 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400868 "Data: x%x x%x x%x x%x\n",
869 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
870 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500871
James Smart2e0fef82007-06-17 19:56:36 -0500872 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500873 /*
874 * If Common Service Parameters indicate Nport
875 * we are point to point, if Fport we are Fabric.
876 */
877 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500878 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400879 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
James Smart2e0fef82007-06-17 19:56:36 -0500880 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400881 else {
882 lpfc_printf_vlog(vport, KERN_ERR,
883 LOG_FIP | LOG_ELS,
884 "2831 FLOGI response with cleared Fabric "
885 "bit fcf_index 0x%x "
886 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
887 "Fabric Name "
888 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
889 phba->fcf.current_rec.fcf_indx,
890 phba->fcf.current_rec.switch_name[0],
891 phba->fcf.current_rec.switch_name[1],
892 phba->fcf.current_rec.switch_name[2],
893 phba->fcf.current_rec.switch_name[3],
894 phba->fcf.current_rec.switch_name[4],
895 phba->fcf.current_rec.switch_name[5],
896 phba->fcf.current_rec.switch_name[6],
897 phba->fcf.current_rec.switch_name[7],
898 phba->fcf.current_rec.fabric_name[0],
899 phba->fcf.current_rec.fabric_name[1],
900 phba->fcf.current_rec.fabric_name[2],
901 phba->fcf.current_rec.fabric_name[3],
902 phba->fcf.current_rec.fabric_name[4],
903 phba->fcf.current_rec.fabric_name[5],
904 phba->fcf.current_rec.fabric_name[6],
905 phba->fcf.current_rec.fabric_name[7]);
906 lpfc_nlp_put(ndlp);
907 spin_lock_irq(&phba->hbalock);
908 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400909 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400910 spin_unlock_irq(&phba->hbalock);
911 goto out;
912 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500913 if (!rc) {
914 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400915 if (phba->hba_flag & HBA_FIP_SUPPORT)
916 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
917 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400918 "2769 FLOGI to FCF (x%x) "
919 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400920 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500921 spin_lock_irq(&phba->hbalock);
922 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400923 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500924 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500925 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500926 }
dea31012005-04-17 16:05:31 -0500927 }
928
929flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400930 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500931
James Smart858c9f62007-06-17 19:56:39 -0500932 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500933 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500934 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500935
936 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500937 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400938 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
939 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
940 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
941 (phba->link_state != LPFC_CLEAR_LA)) {
942 /* If FLOGI failed enable link interrupt. */
943 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500944 }
dea31012005-04-17 16:05:31 -0500945out:
946 lpfc_els_free_iocb(phba, cmdiocb);
947}
948
James Smarte59058c2008-08-24 21:49:00 -0400949/**
James Smart3621a712009-04-06 18:47:14 -0400950 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400951 * @vport: pointer to a host virtual N_Port data structure.
952 * @ndlp: pointer to a node-list data structure.
953 * @retry: number of retries to the command IOCB.
954 *
955 * This routine issues a Fabric Login (FLOGI) Request ELS command
956 * for a @vport. The initiator service parameters are put into the payload
957 * of the FLOGI Request IOCB and the top-level callback function pointer
958 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
959 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
960 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
961 *
962 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
963 * will be incremented by 1 for holding the ndlp and the reference to ndlp
964 * will be stored into the context1 field of the IOCB for the completion
965 * callback function to the FLOGI ELS command.
966 *
967 * Return code
968 * 0 - successfully issued flogi iocb for @vport
969 * 1 - failed to issue flogi iocb for @vport
970 **/
dea31012005-04-17 16:05:31 -0500971static int
James Smart2e0fef82007-06-17 19:56:36 -0500972lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500973 uint8_t retry)
974{
James Smart2e0fef82007-06-17 19:56:36 -0500975 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500976 struct serv_parm *sp;
977 IOCB_t *icmd;
978 struct lpfc_iocbq *elsiocb;
979 struct lpfc_sli_ring *pring;
980 uint8_t *pcmd;
981 uint16_t cmdsize;
982 uint32_t tmo;
983 int rc;
984
985 pring = &phba->sli.ring[LPFC_ELS_RING];
986
James Smart92d7f7b2007-06-17 19:56:38 -0500987 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500988 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
989 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500990
James Smart488d1462006-03-07 15:02:37 -0500991 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500992 return 1;
dea31012005-04-17 16:05:31 -0500993
994 icmd = &elsiocb->iocb;
995 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
996
997 /* For FLOGI request, remainder of payload is service parameters */
998 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500999 pcmd += sizeof(uint32_t);
1000 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001001 sp = (struct serv_parm *) pcmd;
1002
1003 /* Setup CSPs accordingly for Fabric */
1004 sp->cmn.e_d_tov = 0;
1005 sp->cmn.w2.r_a_tov = 0;
1006 sp->cls1.classValid = 0;
1007 sp->cls2.seqDelivery = 1;
1008 sp->cls3.seqDelivery = 1;
1009 if (sp->cmn.fcphLow < FC_PH3)
1010 sp->cmn.fcphLow = FC_PH3;
1011 if (sp->cmn.fcphHigh < FC_PH3)
1012 sp->cmn.fcphHigh = FC_PH3;
1013
James Smart6fb120a2009-05-22 14:52:59 -04001014 if (phba->sli_rev == LPFC_SLI_REV4) {
1015 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1016 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1017 /* FLOGI needs to be 3 for WQE FCFI */
1018 /* Set the fcfi to the fcfi we registered with */
1019 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1020 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001021 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001022 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1023 icmd->ulpCt_h = 1;
1024 icmd->ulpCt_l = 0;
1025 }
1026
James Smart858c9f62007-06-17 19:56:39 -05001027 if (phba->fc_topology != TOPOLOGY_LOOP) {
1028 icmd->un.elsreq64.myID = 0;
1029 icmd->un.elsreq64.fl = 1;
1030 }
1031
dea31012005-04-17 16:05:31 -05001032 tmo = phba->fc_ratov;
1033 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001034 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001035 phba->fc_ratov = tmo;
1036
1037 phba->fc_stat.elsXmitFLOGI++;
1038 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001039
1040 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1041 "Issue FLOGI: opt:x%x",
1042 phba->sli3_options, 0, 0);
1043
James Smart92d7f7b2007-06-17 19:56:38 -05001044 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001045 if (rc == IOCB_ERROR) {
1046 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001047 return 1;
dea31012005-04-17 16:05:31 -05001048 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001049 return 0;
dea31012005-04-17 16:05:31 -05001050}
1051
James Smarte59058c2008-08-24 21:49:00 -04001052/**
James Smart3621a712009-04-06 18:47:14 -04001053 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001054 * @phba: pointer to lpfc hba data structure.
1055 *
1056 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1057 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1058 * list and issues an abort IOCB commond on each outstanding IOCB that
1059 * contains a active Fabric_DID ndlp. Note that this function is to issue
1060 * the abort IOCB command on all the outstanding IOCBs, thus when this
1061 * function returns, it does not guarantee all the IOCBs are actually aborted.
1062 *
1063 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001064 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001065 **/
dea31012005-04-17 16:05:31 -05001066int
James Smart2e0fef82007-06-17 19:56:36 -05001067lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001068{
1069 struct lpfc_sli_ring *pring;
1070 struct lpfc_iocbq *iocb, *next_iocb;
1071 struct lpfc_nodelist *ndlp;
1072 IOCB_t *icmd;
1073
1074 /* Abort outstanding I/O on NPort <nlp_DID> */
1075 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001076 "0201 Abort outstanding I/O on NPort x%x\n",
1077 Fabric_DID);
dea31012005-04-17 16:05:31 -05001078
1079 pring = &phba->sli.ring[LPFC_ELS_RING];
1080
1081 /*
1082 * Check the txcmplq for an iocb that matches the nport the driver is
1083 * searching for.
1084 */
James Smart2e0fef82007-06-17 19:56:36 -05001085 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001086 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1087 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001088 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1089 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001090 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001091 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1092 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001093 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001094 }
1095 }
James Smart2e0fef82007-06-17 19:56:36 -05001096 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001097
1098 return 0;
1099}
1100
James Smarte59058c2008-08-24 21:49:00 -04001101/**
James Smart3621a712009-04-06 18:47:14 -04001102 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001103 * @vport: pointer to a host virtual N_Port data structure.
1104 *
1105 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1106 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1107 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1108 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1109 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1110 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1111 * @vport.
1112 *
1113 * Return code
1114 * 0 - failed to issue initial flogi for @vport
1115 * 1 - successfully issued initial flogi for @vport
1116 **/
dea31012005-04-17 16:05:31 -05001117int
James Smart2e0fef82007-06-17 19:56:36 -05001118lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001119{
James Smart2e0fef82007-06-17 19:56:36 -05001120 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001121 struct lpfc_nodelist *ndlp;
1122
James Smart98c9ea52007-10-27 13:37:33 -04001123 vport->port_state = LPFC_FLOGI;
1124 lpfc_set_disctmo(vport);
1125
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001126 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001127 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001128 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001129 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001130 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1131 if (!ndlp)
1132 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001133 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001134 /* Set the node type */
1135 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001136 /* Put ndlp onto node list */
1137 lpfc_enqueue_node(vport, ndlp);
1138 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1139 /* re-setup ndlp without removing from node list */
1140 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1141 if (!ndlp)
1142 return 0;
dea31012005-04-17 16:05:31 -05001143 }
James Smart87af33f2007-10-27 13:37:43 -04001144
James Smart5ac6b302010-10-22 11:05:36 -04001145 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001146 /* This decrement of reference count to node shall kick off
1147 * the release of the node.
1148 */
James Smart329f9bc2007-04-25 09:53:01 -04001149 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001150 return 0;
1151 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001152 return 1;
dea31012005-04-17 16:05:31 -05001153}
1154
James Smarte59058c2008-08-24 21:49:00 -04001155/**
James Smart3621a712009-04-06 18:47:14 -04001156 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001157 * @vport: pointer to a host virtual N_Port data structure.
1158 *
1159 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1160 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1161 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1162 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1163 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1164 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1165 * @vport.
1166 *
1167 * Return code
1168 * 0 - failed to issue initial fdisc for @vport
1169 * 1 - successfully issued initial fdisc for @vport
1170 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001171int
1172lpfc_initial_fdisc(struct lpfc_vport *vport)
1173{
1174 struct lpfc_hba *phba = vport->phba;
1175 struct lpfc_nodelist *ndlp;
1176
1177 /* First look for the Fabric ndlp */
1178 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1179 if (!ndlp) {
1180 /* Cannot find existing Fabric ndlp, so allocate a new one */
1181 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1182 if (!ndlp)
1183 return 0;
1184 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001185 /* Put ndlp onto node list */
1186 lpfc_enqueue_node(vport, ndlp);
1187 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1188 /* re-setup ndlp without removing from node list */
1189 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1190 if (!ndlp)
1191 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001192 }
James Smarte47c9092008-02-08 18:49:26 -05001193
James Smart92d7f7b2007-06-17 19:56:38 -05001194 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001195 /* decrement node reference count to trigger the release of
1196 * the node.
1197 */
James Smart92d7f7b2007-06-17 19:56:38 -05001198 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001199 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001200 }
1201 return 1;
1202}
James Smart87af33f2007-10-27 13:37:43 -04001203
James Smarte59058c2008-08-24 21:49:00 -04001204/**
James Smart3621a712009-04-06 18:47:14 -04001205 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001206 * @vport: pointer to a host virtual N_Port data structure.
1207 *
1208 * This routine checks whether there are more remaining Port Logins
1209 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1210 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1211 * to issue ELS PLOGIs up to the configured discover threads with the
1212 * @vport (@vport->cfg_discovery_threads). The function also decrement
1213 * the @vport's num_disc_node by 1 if it is not already 0.
1214 **/
James Smart87af33f2007-10-27 13:37:43 -04001215void
James Smart2e0fef82007-06-17 19:56:36 -05001216lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001217{
1218 int sentplogi;
1219
James Smart2e0fef82007-06-17 19:56:36 -05001220 if (vport->num_disc_nodes)
1221 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001222
1223 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001224 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1225 "0232 Continue discovery with %d PLOGIs to go "
1226 "Data: x%x x%x x%x\n",
1227 vport->num_disc_nodes, vport->fc_plogi_cnt,
1228 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001229 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001230 if (vport->fc_flag & FC_NLP_MORE)
1231 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1232 sentplogi = lpfc_els_disc_plogi(vport);
1233
dea31012005-04-17 16:05:31 -05001234 return;
1235}
1236
James Smarte59058c2008-08-24 21:49:00 -04001237/**
James Smart3621a712009-04-06 18:47:14 -04001238 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001239 * @phba: pointer to lpfc hba data structure.
1240 * @prsp: pointer to response IOCB payload.
1241 * @ndlp: pointer to a node-list data structure.
1242 *
1243 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1244 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1245 * The following cases are considered N_Port confirmed:
1246 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1247 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1248 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1249 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1250 * 1) if there is a node on vport list other than the @ndlp with the same
1251 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1252 * on that node to release the RPI associated with the node; 2) if there is
1253 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1254 * into, a new node shall be allocated (or activated). In either case, the
1255 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1256 * be released and the new_ndlp shall be put on to the vport node list and
1257 * its pointer returned as the confirmed node.
1258 *
1259 * Note that before the @ndlp got "released", the keepDID from not-matching
1260 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1261 * of the @ndlp. This is because the release of @ndlp is actually to put it
1262 * into an inactive state on the vport node list and the vport node list
1263 * management algorithm does not allow two node with a same DID.
1264 *
1265 * Return code
1266 * pointer to the PLOGI N_Port @ndlp
1267 **/
James Smart488d1462006-03-07 15:02:37 -05001268static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001269lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001270 struct lpfc_nodelist *ndlp)
1271{
James Smart2e0fef82007-06-17 19:56:36 -05001272 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001273 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001274 struct lpfc_rport_data *rdata;
1275 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001276 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001277 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001278 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001279 int put_node;
1280 int put_rport;
James Smart488d1462006-03-07 15:02:37 -05001281
James Smart2fb9bd82006-12-02 13:33:57 -05001282 /* Fabric nodes can have the same WWPN so we don't bother searching
1283 * by WWPN. Just return the ndlp that was given to us.
1284 */
1285 if (ndlp->nlp_type & NLP_FABRIC)
1286 return ndlp;
1287
James Smart92d7f7b2007-06-17 19:56:38 -05001288 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001289 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001290
James Smart685f0bf2007-04-25 09:53:08 -04001291 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001292 * we have for that ndlp. If not, we have some work to do.
1293 */
James Smart2e0fef82007-06-17 19:56:36 -05001294 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001295
James Smarte47c9092008-02-08 18:49:26 -05001296 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001297 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001298
1299 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001300 rc = memcmp(&ndlp->nlp_portname, name,
1301 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001302 if (!rc)
1303 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001304 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1305 if (!new_ndlp)
1306 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001307 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001308 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001309 rc = memcmp(&ndlp->nlp_portname, name,
1310 sizeof(struct lpfc_name));
1311 if (!rc)
1312 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001313 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1314 NLP_STE_UNUSED_NODE);
1315 if (!new_ndlp)
1316 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001317 keepDID = new_ndlp->nlp_DID;
1318 } else
1319 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001320
James Smart2e0fef82007-06-17 19:56:36 -05001321 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001322 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001323 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001324
1325 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1326 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1327 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1328
James Smarte47c9092008-02-08 18:49:26 -05001329 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001330 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001331
James Smart2e0fef82007-06-17 19:56:36 -05001332 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001333 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1334 /* The new_ndlp is replacing ndlp totally, so we need
1335 * to put ndlp on UNUSED list and try to free it.
1336 */
James Smart0ff10d42008-01-11 01:52:36 -05001337
1338 /* Fix up the rport accordingly */
1339 rport = ndlp->rport;
1340 if (rport) {
1341 rdata = rport->dd_data;
1342 if (rdata->pnode == ndlp) {
1343 lpfc_nlp_put(ndlp);
1344 ndlp->rport = NULL;
1345 rdata->pnode = lpfc_nlp_get(new_ndlp);
1346 new_ndlp->rport = rport;
1347 }
1348 new_ndlp->nlp_type = ndlp->nlp_type;
1349 }
James Smart58da1ff2008-04-07 10:15:56 -04001350 /* We shall actually free the ndlp with both nlp_DID and
1351 * nlp_portname fields equals 0 to avoid any ndlp on the
1352 * nodelist never to be used.
1353 */
1354 if (ndlp->nlp_DID == 0) {
1355 spin_lock_irq(&phba->ndlp_lock);
1356 NLP_SET_FREE_REQ(ndlp);
1357 spin_unlock_irq(&phba->ndlp_lock);
1358 }
James Smart0ff10d42008-01-11 01:52:36 -05001359
James Smart58da1ff2008-04-07 10:15:56 -04001360 /* Two ndlps cannot have the same did on the nodelist */
1361 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001362 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001363 }
James Smart92795652006-07-06 15:50:02 -04001364 else {
James Smart2e0fef82007-06-17 19:56:36 -05001365 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001366 /* Two ndlps cannot have the same did */
1367 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001368 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001369 /* Since we are swapping the ndlp passed in with the new one
1370 * and the did has already been swapped, copy over the
1371 * state and names.
1372 */
1373 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1374 sizeof(struct lpfc_name));
1375 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1376 sizeof(struct lpfc_name));
1377 new_ndlp->nlp_state = ndlp->nlp_state;
1378 /* Fix up the rport accordingly */
1379 rport = ndlp->rport;
1380 if (rport) {
1381 rdata = rport->dd_data;
1382 put_node = rdata->pnode != NULL;
1383 put_rport = ndlp->rport != NULL;
1384 rdata->pnode = NULL;
1385 ndlp->rport = NULL;
1386 if (put_node)
1387 lpfc_nlp_put(ndlp);
1388 if (put_rport)
1389 put_device(&rport->dev);
1390 }
James Smart92795652006-07-06 15:50:02 -04001391 }
James Smart488d1462006-03-07 15:02:37 -05001392 return new_ndlp;
1393}
1394
James Smarte59058c2008-08-24 21:49:00 -04001395/**
James Smart3621a712009-04-06 18:47:14 -04001396 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001397 * @vport: pointer to a host virtual N_Port data structure.
1398 *
1399 * This routine checks whether more Registration State Change
1400 * Notifications (RSCNs) came in while the discovery state machine was in
1401 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1402 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1403 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1404 * handling the RSCNs.
1405 **/
James Smart87af33f2007-10-27 13:37:43 -04001406void
1407lpfc_end_rscn(struct lpfc_vport *vport)
1408{
1409 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1410
1411 if (vport->fc_flag & FC_RSCN_MODE) {
1412 /*
1413 * Check to see if more RSCNs came in while we were
1414 * processing this one.
1415 */
1416 if (vport->fc_rscn_id_cnt ||
1417 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1418 lpfc_els_handle_rscn(vport);
1419 else {
1420 spin_lock_irq(shost->host_lock);
1421 vport->fc_flag &= ~FC_RSCN_MODE;
1422 spin_unlock_irq(shost->host_lock);
1423 }
1424 }
1425}
1426
James Smarte59058c2008-08-24 21:49:00 -04001427/**
James Smart3621a712009-04-06 18:47:14 -04001428 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001429 * @phba: pointer to lpfc hba data structure.
1430 * @cmdiocb: pointer to lpfc command iocb data structure.
1431 * @rspiocb: pointer to lpfc response iocb data structure.
1432 *
1433 * This routine is the completion callback function for issuing the Port
1434 * Login (PLOGI) command. For PLOGI completion, there must be an active
1435 * ndlp on the vport node list that matches the remote node ID from the
1436 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1437 * ignored and command IOCB released. The PLOGI response IOCB status is
1438 * checked for error conditons. If there is error status reported, PLOGI
1439 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1440 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1441 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1442 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1443 * there are additional N_Port nodes with the vport that need to perform
1444 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1445 * PLOGIs.
1446 **/
dea31012005-04-17 16:05:31 -05001447static void
James Smart2e0fef82007-06-17 19:56:36 -05001448lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1449 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001450{
James Smart2e0fef82007-06-17 19:56:36 -05001451 struct lpfc_vport *vport = cmdiocb->vport;
1452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001453 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001454 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001455 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001456 int disc, rc, did, type;
1457
dea31012005-04-17 16:05:31 -05001458 /* we pass cmdiocb to state machine which needs rspiocb as well */
1459 cmdiocb->context_un.rsp_iocb = rspiocb;
1460
1461 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1463 "PLOGI cmpl: status:x%x/x%x did:x%x",
1464 irsp->ulpStatus, irsp->un.ulpWord[4],
1465 irsp->un.elsreq64.remoteID);
1466
James Smart2e0fef82007-06-17 19:56:36 -05001467 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001468 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001469 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1470 "0136 PLOGI completes to NPort x%x "
1471 "with no ndlp. Data: x%x x%x x%x\n",
1472 irsp->un.elsreq64.remoteID,
1473 irsp->ulpStatus, irsp->un.ulpWord[4],
1474 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001475 goto out;
James Smarted957682007-06-17 19:56:37 -05001476 }
dea31012005-04-17 16:05:31 -05001477
1478 /* Since ndlp can be freed in the disc state machine, note if this node
1479 * is being used during discovery.
1480 */
James Smart2e0fef82007-06-17 19:56:36 -05001481 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001482 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001483 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001484 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001485 rc = 0;
1486
1487 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001488 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1489 "0102 PLOGI completes to NPort x%x "
1490 "Data: x%x x%x x%x x%x x%x\n",
1491 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1492 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001493 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001494 if (lpfc_els_chk_latt(vport)) {
1495 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001496 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001497 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001498 goto out;
1499 }
1500
1501 /* ndlp could be freed in DSM, save these values now */
1502 type = ndlp->nlp_type;
1503 did = ndlp->nlp_DID;
1504
1505 if (irsp->ulpStatus) {
1506 /* Check for retry */
1507 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1508 /* ELS command is being retried */
1509 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001510 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -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 }
1514 goto out;
1515 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001516 /* PLOGI failed Don't print the vport to vport rjts */
1517 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1518 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1519 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1520 (phba)->pport->cfg_log_verbose & LOG_ELS)
1521 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001522 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1523 ndlp->nlp_DID, irsp->ulpStatus,
1524 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001525 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001526 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001527 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001528 else
James Smart2e0fef82007-06-17 19:56:36 -05001529 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001530 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001531 } else {
1532 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001533 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001534 cmdiocb->context2)->list.next,
1535 struct lpfc_dmabuf, list);
1536 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001537 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001538 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001539 }
1540
James Smart2e0fef82007-06-17 19:56:36 -05001541 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001542 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001543 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001544
James Smart2e0fef82007-06-17 19:56:36 -05001545 if (vport->num_disc_nodes == 0) {
1546 spin_lock_irq(shost->host_lock);
1547 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1548 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001549
James Smart2e0fef82007-06-17 19:56:36 -05001550 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001551 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001552 }
1553 }
1554
1555out:
1556 lpfc_els_free_iocb(phba, cmdiocb);
1557 return;
1558}
1559
James Smarte59058c2008-08-24 21:49:00 -04001560/**
James Smart3621a712009-04-06 18:47:14 -04001561 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001562 * @vport: pointer to a host virtual N_Port data structure.
1563 * @did: destination port identifier.
1564 * @retry: number of retries to the command IOCB.
1565 *
1566 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1567 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1568 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1569 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1570 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1571 *
1572 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1573 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1574 * will be stored into the context1 field of the IOCB for the completion
1575 * callback function to the PLOGI ELS command.
1576 *
1577 * Return code
1578 * 0 - Successfully issued a plogi for @vport
1579 * 1 - failed to issue a plogi for @vport
1580 **/
dea31012005-04-17 16:05:31 -05001581int
James Smart2e0fef82007-06-17 19:56:36 -05001582lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001583{
James Smart2e0fef82007-06-17 19:56:36 -05001584 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001585 struct serv_parm *sp;
1586 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001587 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001588 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001589 struct lpfc_sli *psli;
1590 uint8_t *pcmd;
1591 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001592 int ret;
dea31012005-04-17 16:05:31 -05001593
1594 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001595
James Smart98c9ea52007-10-27 13:37:33 -04001596 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001597 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1598 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001599
James Smarte47c9092008-02-08 18:49:26 -05001600 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001601 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001602 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001603 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001604 if (!elsiocb)
1605 return 1;
dea31012005-04-17 16:05:31 -05001606
1607 icmd = &elsiocb->iocb;
1608 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1609
1610 /* For PLOGI request, remainder of payload is service parameters */
1611 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001612 pcmd += sizeof(uint32_t);
1613 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001614 sp = (struct serv_parm *) pcmd;
1615
James Smart5ac6b302010-10-22 11:05:36 -04001616 /*
1617 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1618 * to device on remote loops work.
1619 */
1620 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1621 sp->cmn.altBbCredit = 1;
1622
dea31012005-04-17 16:05:31 -05001623 if (sp->cmn.fcphLow < FC_PH_4_3)
1624 sp->cmn.fcphLow = FC_PH_4_3;
1625
1626 if (sp->cmn.fcphHigh < FC_PH3)
1627 sp->cmn.fcphHigh = FC_PH3;
1628
James Smart858c9f62007-06-17 19:56:39 -05001629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1630 "Issue PLOGI: did:x%x",
1631 did, 0, 0);
1632
dea31012005-04-17 16:05:31 -05001633 phba->fc_stat.elsXmitPLOGI++;
1634 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001635 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001636
1637 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001638 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001639 return 1;
dea31012005-04-17 16:05:31 -05001640 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001641 return 0;
dea31012005-04-17 16:05:31 -05001642}
1643
James Smarte59058c2008-08-24 21:49:00 -04001644/**
James Smart3621a712009-04-06 18:47:14 -04001645 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001646 * @phba: pointer to lpfc hba data structure.
1647 * @cmdiocb: pointer to lpfc command iocb data structure.
1648 * @rspiocb: pointer to lpfc response iocb data structure.
1649 *
1650 * This routine is the completion callback function for a Process Login
1651 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1652 * status. If there is error status reported, PRLI retry shall be attempted
1653 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1654 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1655 * ndlp to mark the PRLI completion.
1656 **/
dea31012005-04-17 16:05:31 -05001657static void
James Smart2e0fef82007-06-17 19:56:36 -05001658lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1659 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001660{
James Smart2e0fef82007-06-17 19:56:36 -05001661 struct lpfc_vport *vport = cmdiocb->vport;
1662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001663 IOCB_t *irsp;
1664 struct lpfc_sli *psli;
1665 struct lpfc_nodelist *ndlp;
1666
1667 psli = &phba->sli;
1668 /* we pass cmdiocb to state machine which needs rspiocb as well */
1669 cmdiocb->context_un.rsp_iocb = rspiocb;
1670
1671 irsp = &(rspiocb->iocb);
1672 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001673 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001674 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001675 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001676
James Smart858c9f62007-06-17 19:56:39 -05001677 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1678 "PRLI cmpl: status:x%x/x%x did:x%x",
1679 irsp->ulpStatus, irsp->un.ulpWord[4],
1680 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001681 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001682 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1683 "0103 PRLI completes to NPort x%x "
1684 "Data: x%x x%x x%x x%x\n",
1685 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1686 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001687
James Smart2e0fef82007-06-17 19:56:36 -05001688 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001689 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001690 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001691 goto out;
1692
1693 if (irsp->ulpStatus) {
1694 /* Check for retry */
1695 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1696 /* ELS command is being retried */
1697 goto out;
1698 }
1699 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001700 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1701 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1702 ndlp->nlp_DID, irsp->ulpStatus,
1703 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001704 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001705 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001706 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001707 else
James Smart2e0fef82007-06-17 19:56:36 -05001708 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001709 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001710 } else
dea31012005-04-17 16:05:31 -05001711 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001712 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001713 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001714out:
1715 lpfc_els_free_iocb(phba, cmdiocb);
1716 return;
1717}
1718
James Smarte59058c2008-08-24 21:49:00 -04001719/**
James Smart3621a712009-04-06 18:47:14 -04001720 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001721 * @vport: pointer to a host virtual N_Port data structure.
1722 * @ndlp: pointer to a node-list data structure.
1723 * @retry: number of retries to the command IOCB.
1724 *
1725 * This routine issues a Process Login (PRLI) ELS command for the
1726 * @vport. The PRLI service parameters are set up in the payload of the
1727 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1728 * is put to the IOCB completion callback func field before invoking the
1729 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1730 *
1731 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1732 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1733 * will be stored into the context1 field of the IOCB for the completion
1734 * callback function to the PRLI ELS command.
1735 *
1736 * Return code
1737 * 0 - successfully issued prli iocb command for @vport
1738 * 1 - failed to issue prli iocb command for @vport
1739 **/
dea31012005-04-17 16:05:31 -05001740int
James Smart2e0fef82007-06-17 19:56:36 -05001741lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001742 uint8_t retry)
1743{
James Smart2e0fef82007-06-17 19:56:36 -05001744 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1745 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001746 PRLI *npr;
1747 IOCB_t *icmd;
1748 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001749 uint8_t *pcmd;
1750 uint16_t cmdsize;
1751
James Smart92d7f7b2007-06-17 19:56:38 -05001752 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001753 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1754 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001755 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001756 return 1;
dea31012005-04-17 16:05:31 -05001757
1758 icmd = &elsiocb->iocb;
1759 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1760
1761 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001762 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001763 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001764 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001765
1766 /* For PRLI, remainder of payload is PRLI parameter page */
1767 npr = (PRLI *) pcmd;
1768 /*
1769 * If our firmware version is 3.20 or later,
1770 * set the following bits for FC-TAPE support.
1771 */
1772 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1773 npr->ConfmComplAllowed = 1;
1774 npr->Retry = 1;
1775 npr->TaskRetryIdReq = 1;
1776 }
1777 npr->estabImagePair = 1;
1778 npr->readXferRdyDis = 1;
1779
1780 /* For FCP support */
1781 npr->prliType = PRLI_FCP_TYPE;
1782 npr->initiatorFunc = 1;
1783
James Smart858c9f62007-06-17 19:56:39 -05001784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1785 "Issue PRLI: did:x%x",
1786 ndlp->nlp_DID, 0, 0);
1787
dea31012005-04-17 16:05:31 -05001788 phba->fc_stat.elsXmitPRLI++;
1789 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001790 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001791 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001792 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001793 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1794 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001795 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001796 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001797 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001798 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001799 return 1;
dea31012005-04-17 16:05:31 -05001800 }
James Smart2e0fef82007-06-17 19:56:36 -05001801 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001802 return 0;
dea31012005-04-17 16:05:31 -05001803}
1804
James Smarte59058c2008-08-24 21:49:00 -04001805/**
James Smart3621a712009-04-06 18:47:14 -04001806 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001807 * @vport: pointer to a host virtual N_Port data structure.
1808 *
1809 * This routine performs Registration State Change Notification (RSCN)
1810 * discovery for a @vport. If the @vport's node port recovery count is not
1811 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1812 * the nodes that need recovery. If none of the PLOGI were needed through
1813 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1814 * invoked to check and handle possible more RSCN came in during the period
1815 * of processing the current ones.
1816 **/
1817static void
1818lpfc_rscn_disc(struct lpfc_vport *vport)
1819{
1820 lpfc_can_disctmo(vport);
1821
1822 /* RSCN discovery */
1823 /* go thru NPR nodes and issue ELS PLOGIs */
1824 if (vport->fc_npr_cnt)
1825 if (lpfc_els_disc_plogi(vport))
1826 return;
1827
1828 lpfc_end_rscn(vport);
1829}
1830
1831/**
James Smart3621a712009-04-06 18:47:14 -04001832 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001833 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1834 *
1835 * This function is called when the final ADISC is completed during discovery.
1836 * This function handles clearing link attention or issuing reg_vpi depending
1837 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1838 * discovery.
1839 * This function is called with no locks held.
1840 **/
1841static void
1842lpfc_adisc_done(struct lpfc_vport *vport)
1843{
1844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1845 struct lpfc_hba *phba = vport->phba;
1846
1847 /*
1848 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1849 * and continue discovery.
1850 */
1851 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001852 !(vport->fc_flag & FC_RSCN_MODE) &&
1853 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001854 lpfc_issue_reg_vpi(phba, vport);
1855 return;
1856 }
1857 /*
1858 * For SLI2, we need to set port_state to READY
1859 * and continue discovery.
1860 */
1861 if (vport->port_state < LPFC_VPORT_READY) {
1862 /* If we get here, there is nothing to ADISC */
1863 if (vport->port_type == LPFC_PHYSICAL_PORT)
1864 lpfc_issue_clear_la(phba, vport);
1865 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1866 vport->num_disc_nodes = 0;
1867 /* go thru NPR list, issue ELS PLOGIs */
1868 if (vport->fc_npr_cnt)
1869 lpfc_els_disc_plogi(vport);
1870 if (!vport->num_disc_nodes) {
1871 spin_lock_irq(shost->host_lock);
1872 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1873 spin_unlock_irq(shost->host_lock);
1874 lpfc_can_disctmo(vport);
1875 lpfc_end_rscn(vport);
1876 }
1877 }
1878 vport->port_state = LPFC_VPORT_READY;
1879 } else
1880 lpfc_rscn_disc(vport);
1881}
1882
1883/**
James Smart3621a712009-04-06 18:47:14 -04001884 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001885 * @vport: pointer to a host virtual N_Port data structure.
1886 *
1887 * This routine determines whether there are more ndlps on a @vport
1888 * node list need to have Address Discover (ADISC) issued. If so, it will
1889 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1890 * remaining nodes which need to have ADISC sent.
1891 **/
James Smart0ff10d42008-01-11 01:52:36 -05001892void
James Smart2e0fef82007-06-17 19:56:36 -05001893lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001894{
1895 int sentadisc;
1896
James Smart2e0fef82007-06-17 19:56:36 -05001897 if (vport->num_disc_nodes)
1898 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001899 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001900 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1901 "0210 Continue discovery with %d ADISCs to go "
1902 "Data: x%x x%x x%x\n",
1903 vport->num_disc_nodes, vport->fc_adisc_cnt,
1904 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001905 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001906 if (vport->fc_flag & FC_NLP_MORE) {
1907 lpfc_set_disctmo(vport);
1908 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1909 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001910 }
James Smart90160e02008-08-24 21:49:45 -04001911 if (!vport->num_disc_nodes)
1912 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001913 return;
1914}
1915
James Smarte59058c2008-08-24 21:49:00 -04001916/**
James Smart3621a712009-04-06 18:47:14 -04001917 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001918 * @phba: pointer to lpfc hba data structure.
1919 * @cmdiocb: pointer to lpfc command iocb data structure.
1920 * @rspiocb: pointer to lpfc response iocb data structure.
1921 *
1922 * This routine is the completion function for issuing the Address Discover
1923 * (ADISC) command. It first checks to see whether link went down during
1924 * the discovery process. If so, the node will be marked as node port
1925 * recovery for issuing discover IOCB by the link attention handler and
1926 * exit. Otherwise, the response status is checked. If error was reported
1927 * in the response status, the ADISC command shall be retried by invoking
1928 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1929 * the response status, the state machine is invoked to set transition
1930 * with respect to NLP_EVT_CMPL_ADISC event.
1931 **/
dea31012005-04-17 16:05:31 -05001932static void
James Smart2e0fef82007-06-17 19:56:36 -05001933lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1934 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001935{
James Smart2e0fef82007-06-17 19:56:36 -05001936 struct lpfc_vport *vport = cmdiocb->vport;
1937 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001938 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001939 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001940 int disc;
dea31012005-04-17 16:05:31 -05001941
1942 /* we pass cmdiocb to state machine which needs rspiocb as well */
1943 cmdiocb->context_un.rsp_iocb = rspiocb;
1944
1945 irsp = &(rspiocb->iocb);
1946 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001947
James Smart858c9f62007-06-17 19:56:39 -05001948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1949 "ADISC cmpl: status:x%x/x%x did:x%x",
1950 irsp->ulpStatus, irsp->un.ulpWord[4],
1951 ndlp->nlp_DID);
1952
dea31012005-04-17 16:05:31 -05001953 /* Since ndlp can be freed in the disc state machine, note if this node
1954 * is being used during discovery.
1955 */
James Smart2e0fef82007-06-17 19:56:36 -05001956 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001957 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001958 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001961 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1962 "0104 ADISC completes to NPort x%x "
1963 "Data: x%x x%x x%x x%x x%x\n",
1964 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1965 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001966 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001967 if (lpfc_els_chk_latt(vport)) {
1968 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001969 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001970 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001971 goto out;
1972 }
1973
1974 if (irsp->ulpStatus) {
1975 /* Check for retry */
1976 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1977 /* ELS command is being retried */
1978 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001979 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001980 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001981 spin_unlock_irq(shost->host_lock);
1982 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001983 }
1984 goto out;
1985 }
1986 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001987 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1988 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1989 ndlp->nlp_DID, irsp->ulpStatus,
1990 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001991 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001992 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001993 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001994 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001995 } else
dea31012005-04-17 16:05:31 -05001996 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001997 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001998 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001999
James Smart90160e02008-08-24 21:49:45 -04002000 /* Check to see if there are more ADISCs to be sent */
2001 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002002 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002003out:
2004 lpfc_els_free_iocb(phba, cmdiocb);
2005 return;
2006}
2007
James Smarte59058c2008-08-24 21:49:00 -04002008/**
James Smart3621a712009-04-06 18:47:14 -04002009 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002010 * @vport: pointer to a virtual N_Port data structure.
2011 * @ndlp: pointer to a node-list data structure.
2012 * @retry: number of retries to the command IOCB.
2013 *
2014 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2015 * @vport. It prepares the payload of the ADISC ELS command, updates the
2016 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2017 * to issue the ADISC ELS command.
2018 *
2019 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2020 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2021 * will be stored into the context1 field of the IOCB for the completion
2022 * callback function to the ADISC ELS command.
2023 *
2024 * Return code
2025 * 0 - successfully issued adisc
2026 * 1 - failed to issue adisc
2027 **/
dea31012005-04-17 16:05:31 -05002028int
James Smart2e0fef82007-06-17 19:56:36 -05002029lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002030 uint8_t retry)
2031{
James Smart2e0fef82007-06-17 19:56:36 -05002032 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2033 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002034 ADISC *ap;
2035 IOCB_t *icmd;
2036 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002037 uint8_t *pcmd;
2038 uint16_t cmdsize;
2039
James Smart92d7f7b2007-06-17 19:56:38 -05002040 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002041 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2042 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002043 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002044 return 1;
dea31012005-04-17 16:05:31 -05002045
2046 icmd = &elsiocb->iocb;
2047 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2048
2049 /* For ADISC request, remainder of payload is service parameters */
2050 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002051 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002052
2053 /* Fill in ADISC payload */
2054 ap = (ADISC *) pcmd;
2055 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002056 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2057 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002058 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002059
James Smart858c9f62007-06-17 19:56:39 -05002060 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2061 "Issue ADISC: did:x%x",
2062 ndlp->nlp_DID, 0, 0);
2063
dea31012005-04-17 16:05:31 -05002064 phba->fc_stat.elsXmitADISC++;
2065 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002066 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002067 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002068 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002069 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2070 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002071 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002072 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002073 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002074 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002075 return 1;
dea31012005-04-17 16:05:31 -05002076 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002077 return 0;
dea31012005-04-17 16:05:31 -05002078}
2079
James Smarte59058c2008-08-24 21:49:00 -04002080/**
James Smart3621a712009-04-06 18:47:14 -04002081 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002082 * @phba: pointer to lpfc hba data structure.
2083 * @cmdiocb: pointer to lpfc command iocb data structure.
2084 * @rspiocb: pointer to lpfc response iocb data structure.
2085 *
2086 * This routine is the completion function for issuing the ELS Logout (LOGO)
2087 * command. If no error status was reported from the LOGO response, the
2088 * state machine of the associated ndlp shall be invoked for transition with
2089 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2090 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2091 **/
dea31012005-04-17 16:05:31 -05002092static void
James Smart2e0fef82007-06-17 19:56:36 -05002093lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2094 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002095{
James Smart2e0fef82007-06-17 19:56:36 -05002096 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2097 struct lpfc_vport *vport = ndlp->vport;
2098 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002099 IOCB_t *irsp;
2100 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002101
2102 psli = &phba->sli;
2103 /* we pass cmdiocb to state machine which needs rspiocb as well */
2104 cmdiocb->context_un.rsp_iocb = rspiocb;
2105
2106 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002107 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002108 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002109 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002110
James Smart858c9f62007-06-17 19:56:39 -05002111 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2112 "LOGO cmpl: status:x%x/x%x did:x%x",
2113 irsp->ulpStatus, irsp->un.ulpWord[4],
2114 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002115 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002116 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2117 "0105 LOGO completes to NPort x%x "
2118 "Data: x%x x%x x%x x%x\n",
2119 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2120 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002121 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002122 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002123 goto out;
2124
James Smart92d7f7b2007-06-17 19:56:38 -05002125 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2126 /* NLP_EVT_DEVICE_RM should unregister the RPI
2127 * which should abort all outstanding IOs.
2128 */
2129 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2130 NLP_EVT_DEVICE_RM);
2131 goto out;
2132 }
2133
dea31012005-04-17 16:05:31 -05002134 if (irsp->ulpStatus) {
2135 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002136 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002137 /* ELS command is being retried */
2138 goto out;
dea31012005-04-17 16:05:31 -05002139 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002140 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2141 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2142 ndlp->nlp_DID, irsp->ulpStatus,
2143 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002144 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002145 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002146 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002147 else
James Smart2e0fef82007-06-17 19:56:36 -05002148 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002149 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002150 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002151 /* Good status, call state machine.
2152 * This will unregister the rpi if needed.
2153 */
James Smart2e0fef82007-06-17 19:56:36 -05002154 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002155 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002156out:
2157 lpfc_els_free_iocb(phba, cmdiocb);
2158 return;
2159}
2160
James Smarte59058c2008-08-24 21:49:00 -04002161/**
James Smart3621a712009-04-06 18:47:14 -04002162 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002163 * @vport: pointer to a virtual N_Port data structure.
2164 * @ndlp: pointer to a node-list data structure.
2165 * @retry: number of retries to the command IOCB.
2166 *
2167 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2168 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2169 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2170 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2171 *
2172 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2173 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2174 * will be stored into the context1 field of the IOCB for the completion
2175 * callback function to the LOGO ELS command.
2176 *
2177 * Return code
2178 * 0 - successfully issued logo
2179 * 1 - failed to issue logo
2180 **/
dea31012005-04-17 16:05:31 -05002181int
James Smart2e0fef82007-06-17 19:56:36 -05002182lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002183 uint8_t retry)
2184{
James Smart2e0fef82007-06-17 19:56:36 -05002185 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2186 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002187 IOCB_t *icmd;
2188 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002189 uint8_t *pcmd;
2190 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002191 int rc;
dea31012005-04-17 16:05:31 -05002192
James Smart98c9ea52007-10-27 13:37:33 -04002193 spin_lock_irq(shost->host_lock);
2194 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2195 spin_unlock_irq(shost->host_lock);
2196 return 0;
2197 }
2198 spin_unlock_irq(shost->host_lock);
2199
James Smart92d7f7b2007-06-17 19:56:38 -05002200 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002201 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2202 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002203 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002204 return 1;
dea31012005-04-17 16:05:31 -05002205
2206 icmd = &elsiocb->iocb;
2207 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2208 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002209 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002210
2211 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002212 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002213 pcmd += sizeof(uint32_t);
2214 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002215
James Smart858c9f62007-06-17 19:56:39 -05002216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2217 "Issue LOGO: did:x%x",
2218 ndlp->nlp_DID, 0, 0);
2219
dea31012005-04-17 16:05:31 -05002220 phba->fc_stat.elsXmitLOGO++;
2221 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002222 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002223 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002224 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002225 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002226
2227 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002228 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002229 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002230 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002231 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002232 return 1;
dea31012005-04-17 16:05:31 -05002233 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002234 return 0;
dea31012005-04-17 16:05:31 -05002235}
2236
James Smarte59058c2008-08-24 21:49:00 -04002237/**
James Smart3621a712009-04-06 18:47:14 -04002238 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002239 * @phba: pointer to lpfc hba data structure.
2240 * @cmdiocb: pointer to lpfc command iocb data structure.
2241 * @rspiocb: pointer to lpfc response iocb data structure.
2242 *
2243 * This routine is a generic completion callback function for ELS commands.
2244 * Specifically, it is the callback function which does not need to perform
2245 * any command specific operations. It is currently used by the ELS command
2246 * issuing routines for the ELS State Change Request (SCR),
2247 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2248 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2249 * certain debug loggings, this callback function simply invokes the
2250 * lpfc_els_chk_latt() routine to check whether link went down during the
2251 * discovery process.
2252 **/
dea31012005-04-17 16:05:31 -05002253static void
James Smart2e0fef82007-06-17 19:56:36 -05002254lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2255 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002256{
James Smart2e0fef82007-06-17 19:56:36 -05002257 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002258 IOCB_t *irsp;
2259
2260 irsp = &rspiocb->iocb;
2261
James Smart858c9f62007-06-17 19:56:39 -05002262 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2263 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2264 irsp->ulpStatus, irsp->un.ulpWord[4],
2265 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002266 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002267 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2268 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2269 irsp->ulpIoTag, irsp->ulpStatus,
2270 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002271 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002272 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002273 lpfc_els_free_iocb(phba, cmdiocb);
2274 return;
2275}
2276
James Smarte59058c2008-08-24 21:49:00 -04002277/**
James Smart3621a712009-04-06 18:47:14 -04002278 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002279 * @vport: pointer to a host virtual N_Port data structure.
2280 * @nportid: N_Port identifier to the remote node.
2281 * @retry: number of retries to the command IOCB.
2282 *
2283 * This routine issues a State Change Request (SCR) to a fabric node
2284 * on a @vport. The remote node @nportid is passed into the function. It
2285 * first search the @vport node list to find the matching ndlp. If no such
2286 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2287 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2288 * routine is invoked to send the SCR IOCB.
2289 *
2290 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2291 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2292 * will be stored into the context1 field of the IOCB for the completion
2293 * callback function to the SCR ELS command.
2294 *
2295 * Return code
2296 * 0 - Successfully issued scr command
2297 * 1 - Failed to issue scr command
2298 **/
dea31012005-04-17 16:05:31 -05002299int
James Smart2e0fef82007-06-17 19:56:36 -05002300lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002301{
James Smart2e0fef82007-06-17 19:56:36 -05002302 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002303 IOCB_t *icmd;
2304 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002305 struct lpfc_sli *psli;
2306 uint8_t *pcmd;
2307 uint16_t cmdsize;
2308 struct lpfc_nodelist *ndlp;
2309
2310 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002311 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002312
James Smarte47c9092008-02-08 18:49:26 -05002313 ndlp = lpfc_findnode_did(vport, nportid);
2314 if (!ndlp) {
2315 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2316 if (!ndlp)
2317 return 1;
2318 lpfc_nlp_init(vport, ndlp, nportid);
2319 lpfc_enqueue_node(vport, ndlp);
2320 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2321 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2322 if (!ndlp)
2323 return 1;
2324 }
dea31012005-04-17 16:05:31 -05002325
James Smart2e0fef82007-06-17 19:56:36 -05002326 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2327 ndlp->nlp_DID, ELS_CMD_SCR);
2328
James Smart488d1462006-03-07 15:02:37 -05002329 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002330 /* This will trigger the release of the node just
2331 * allocated
2332 */
James Smart329f9bc2007-04-25 09:53:01 -04002333 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002334 return 1;
dea31012005-04-17 16:05:31 -05002335 }
2336
2337 icmd = &elsiocb->iocb;
2338 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2339
2340 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002341 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002342
2343 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002344 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002345 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2346
James Smart858c9f62007-06-17 19:56:39 -05002347 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2348 "Issue SCR: did:x%x",
2349 ndlp->nlp_DID, 0, 0);
2350
dea31012005-04-17 16:05:31 -05002351 phba->fc_stat.elsXmitSCR++;
2352 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002353 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2354 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002355 /* The additional lpfc_nlp_put will cause the following
2356 * lpfc_els_free_iocb routine to trigger the rlease of
2357 * the node.
2358 */
James Smart329f9bc2007-04-25 09:53:01 -04002359 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002360 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002361 return 1;
dea31012005-04-17 16:05:31 -05002362 }
James Smartfa4066b2008-01-11 01:53:27 -05002363 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2364 * trigger the release of node.
2365 */
James Smart329f9bc2007-04-25 09:53:01 -04002366 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002367 return 0;
dea31012005-04-17 16:05:31 -05002368}
2369
James Smarte59058c2008-08-24 21:49:00 -04002370/**
James Smart3621a712009-04-06 18:47:14 -04002371 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002372 * @vport: pointer to a host virtual N_Port data structure.
2373 * @nportid: N_Port identifier to the remote node.
2374 * @retry: number of retries to the command IOCB.
2375 *
2376 * This routine issues a Fibre Channel Address Resolution Response
2377 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2378 * is passed into the function. It first search the @vport node list to find
2379 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2380 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2381 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2382 *
2383 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2384 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2385 * will be stored into the context1 field of the IOCB for the completion
2386 * callback function to the PARPR ELS command.
2387 *
2388 * Return code
2389 * 0 - Successfully issued farpr command
2390 * 1 - Failed to issue farpr command
2391 **/
dea31012005-04-17 16:05:31 -05002392static int
James Smart2e0fef82007-06-17 19:56:36 -05002393lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002394{
James Smart2e0fef82007-06-17 19:56:36 -05002395 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002396 IOCB_t *icmd;
2397 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002398 struct lpfc_sli *psli;
2399 FARP *fp;
2400 uint8_t *pcmd;
2401 uint32_t *lp;
2402 uint16_t cmdsize;
2403 struct lpfc_nodelist *ondlp;
2404 struct lpfc_nodelist *ndlp;
2405
2406 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002407 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002408
James Smarte47c9092008-02-08 18:49:26 -05002409 ndlp = lpfc_findnode_did(vport, nportid);
2410 if (!ndlp) {
2411 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2412 if (!ndlp)
2413 return 1;
2414 lpfc_nlp_init(vport, ndlp, nportid);
2415 lpfc_enqueue_node(vport, ndlp);
2416 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2417 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2418 if (!ndlp)
2419 return 1;
2420 }
James Smart2e0fef82007-06-17 19:56:36 -05002421
2422 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2423 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002424 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002425 /* This will trigger the release of the node just
2426 * allocated
2427 */
James Smart329f9bc2007-04-25 09:53:01 -04002428 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002429 return 1;
dea31012005-04-17 16:05:31 -05002430 }
2431
2432 icmd = &elsiocb->iocb;
2433 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2434
2435 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002436 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002437
2438 /* Fill in FARPR payload */
2439 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002440 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002441 lp = (uint32_t *) pcmd;
2442 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002443 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002444 fp->Rflags = 0;
2445 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2446
James Smart92d7f7b2007-06-17 19:56:38 -05002447 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2448 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002449 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002450 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002451 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002452 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002453 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002454 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002455 }
2456
James Smart858c9f62007-06-17 19:56:39 -05002457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2458 "Issue FARPR: did:x%x",
2459 ndlp->nlp_DID, 0, 0);
2460
dea31012005-04-17 16:05:31 -05002461 phba->fc_stat.elsXmitFARPR++;
2462 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002463 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2464 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002465 /* The additional lpfc_nlp_put will cause the following
2466 * lpfc_els_free_iocb routine to trigger the release of
2467 * the node.
2468 */
James Smart329f9bc2007-04-25 09:53:01 -04002469 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002470 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002471 return 1;
dea31012005-04-17 16:05:31 -05002472 }
James Smartfa4066b2008-01-11 01:53:27 -05002473 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2474 * trigger the release of the node.
2475 */
James Smart329f9bc2007-04-25 09:53:01 -04002476 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002477 return 0;
dea31012005-04-17 16:05:31 -05002478}
2479
James Smarte59058c2008-08-24 21:49:00 -04002480/**
James Smart3621a712009-04-06 18:47:14 -04002481 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002482 * @vport: pointer to a host virtual N_Port data structure.
2483 * @nlp: pointer to a node-list data structure.
2484 *
2485 * This routine cancels the timer with a delayed IOCB-command retry for
2486 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2487 * removes the ELS retry event if it presents. In addition, if the
2488 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2489 * commands are sent for the @vport's nodes that require issuing discovery
2490 * ADISC.
2491 **/
dea31012005-04-17 16:05:31 -05002492void
James Smart2e0fef82007-06-17 19:56:36 -05002493lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002494{
James Smart2e0fef82007-06-17 19:56:36 -05002495 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002496 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002497
James Smart0d2b6b82008-06-14 22:52:47 -04002498 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2499 return;
James Smart2e0fef82007-06-17 19:56:36 -05002500 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002501 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002502 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002503 del_timer_sync(&nlp->nlp_delayfunc);
2504 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002505 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002506 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002507 /* Decrement nlp reference count held for the delayed retry */
2508 evtp = &nlp->els_retry_evt;
2509 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2510 }
James Smartfdcebe22006-03-07 15:04:01 -05002511 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002512 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002513 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002514 spin_unlock_irq(shost->host_lock);
2515 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002516 if (vport->port_state < LPFC_VPORT_READY) {
2517 /* Check if there are more ADISCs to be sent */
2518 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002519 } else {
2520 /* Check if there are more PLOGIs to be sent */
2521 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002522 if (vport->num_disc_nodes == 0) {
2523 spin_lock_irq(shost->host_lock);
2524 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2525 spin_unlock_irq(shost->host_lock);
2526 lpfc_can_disctmo(vport);
2527 lpfc_end_rscn(vport);
2528 }
James Smartfdcebe22006-03-07 15:04:01 -05002529 }
2530 }
2531 }
2532 return;
2533}
2534
James Smarte59058c2008-08-24 21:49:00 -04002535/**
James Smart3621a712009-04-06 18:47:14 -04002536 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002537 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2538 *
2539 * This routine is invoked by the ndlp delayed-function timer to check
2540 * whether there is any pending ELS retry event(s) with the node. If not, it
2541 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2542 * adds the delayed events to the HBA work list and invokes the
2543 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2544 * event. Note that lpfc_nlp_get() is called before posting the event to
2545 * the work list to hold reference count of ndlp so that it guarantees the
2546 * reference to ndlp will still be available when the worker thread gets
2547 * to the event associated with the ndlp.
2548 **/
James Smartfdcebe22006-03-07 15:04:01 -05002549void
dea31012005-04-17 16:05:31 -05002550lpfc_els_retry_delay(unsigned long ptr)
2551{
James Smart2e0fef82007-06-17 19:56:36 -05002552 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2553 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002554 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002555 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002556 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002557
James Smart92d7f7b2007-06-17 19:56:38 -05002558 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002559 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002560 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002561 return;
2562 }
2563
James Smartfa4066b2008-01-11 01:53:27 -05002564 /* We need to hold the node by incrementing the reference
2565 * count until the queued work is done
2566 */
2567 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002568 if (evtp->evt_arg1) {
2569 evtp->evt = LPFC_EVT_ELS_RETRY;
2570 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002571 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002572 }
James Smart92d7f7b2007-06-17 19:56:38 -05002573 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002574 return;
2575}
2576
James Smarte59058c2008-08-24 21:49:00 -04002577/**
James Smart3621a712009-04-06 18:47:14 -04002578 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002579 * @ndlp: pointer to a node-list data structure.
2580 *
2581 * This routine is the worker-thread handler for processing the @ndlp delayed
2582 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2583 * the last ELS command from the associated ndlp and invokes the proper ELS
2584 * function according to the delayed ELS command to retry the command.
2585 **/
dea31012005-04-17 16:05:31 -05002586void
2587lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2588{
James Smart2e0fef82007-06-17 19:56:36 -05002589 struct lpfc_vport *vport = ndlp->vport;
2590 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2591 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002592
James Smart2e0fef82007-06-17 19:56:36 -05002593 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002594 did = ndlp->nlp_DID;
2595 cmd = ndlp->nlp_last_elscmd;
2596 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002597
2598 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002599 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002600 return;
2601 }
2602
2603 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002604 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002605 /*
2606 * If a discovery event readded nlp_delayfunc after timer
2607 * firing and before processing the timer, cancel the
2608 * nlp_delayfunc.
2609 */
2610 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002611 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002612 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002613
2614 switch (cmd) {
2615 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002616 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002617 break;
2618 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002619 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002620 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002621 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002622 }
dea31012005-04-17 16:05:31 -05002623 break;
2624 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002625 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002626 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002627 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002628 }
dea31012005-04-17 16:05:31 -05002629 break;
2630 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002631 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002632 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002634 }
dea31012005-04-17 16:05:31 -05002635 break;
2636 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002637 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002638 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002639 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002640 }
dea31012005-04-17 16:05:31 -05002641 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002642 case ELS_CMD_FDISC:
2643 lpfc_issue_els_fdisc(vport, ndlp, retry);
2644 break;
dea31012005-04-17 16:05:31 -05002645 }
2646 return;
2647}
2648
James Smarte59058c2008-08-24 21:49:00 -04002649/**
James Smart3621a712009-04-06 18:47:14 -04002650 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002651 * @phba: pointer to lpfc hba data structure.
2652 * @cmdiocb: pointer to lpfc command iocb data structure.
2653 * @rspiocb: pointer to lpfc response iocb data structure.
2654 *
2655 * This routine makes a retry decision on an ELS command IOCB, which has
2656 * failed. The following ELS IOCBs use this function for retrying the command
2657 * when previously issued command responsed with error status: FLOGI, PLOGI,
2658 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2659 * returned error status, it makes the decision whether a retry shall be
2660 * issued for the command, and whether a retry shall be made immediately or
2661 * delayed. In the former case, the corresponding ELS command issuing-function
2662 * is called to retry the command. In the later case, the ELS command shall
2663 * be posted to the ndlp delayed event and delayed function timer set to the
2664 * ndlp for the delayed command issusing.
2665 *
2666 * Return code
2667 * 0 - No retry of els command is made
2668 * 1 - Immediate or delayed retry of els command is made
2669 **/
dea31012005-04-17 16:05:31 -05002670static int
James Smart2e0fef82007-06-17 19:56:36 -05002671lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2672 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002673{
James Smart2e0fef82007-06-17 19:56:36 -05002674 struct lpfc_vport *vport = cmdiocb->vport;
2675 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2676 IOCB_t *irsp = &rspiocb->iocb;
2677 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2678 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002679 uint32_t *elscmd;
2680 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002681 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002682 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002683 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002684 uint32_t did;
dea31012005-04-17 16:05:31 -05002685
James Smart488d1462006-03-07 15:02:37 -05002686
dea31012005-04-17 16:05:31 -05002687 /* Note: context2 may be 0 for internal driver abort
2688 * of delays ELS command.
2689 */
2690
2691 if (pcmd && pcmd->virt) {
2692 elscmd = (uint32_t *) (pcmd->virt);
2693 cmd = *elscmd++;
2694 }
2695
James Smarte47c9092008-02-08 18:49:26 -05002696 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002697 did = ndlp->nlp_DID;
2698 else {
2699 /* We should only hit this case for retrying PLOGI */
2700 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002701 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002702 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2703 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002704 return 1;
2705 }
2706
James Smart858c9f62007-06-17 19:56:39 -05002707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2708 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2709 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2710
dea31012005-04-17 16:05:31 -05002711 switch (irsp->ulpStatus) {
2712 case IOSTAT_FCP_RSP_ERROR:
2713 case IOSTAT_REMOTE_STOP:
2714 break;
2715
2716 case IOSTAT_LOCAL_REJECT:
2717 switch ((irsp->un.ulpWord[4] & 0xff)) {
2718 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002719 if (cmd == ELS_CMD_FLOGI) {
2720 if (PCI_DEVICE_ID_HORNET ==
2721 phba->pcidev->device) {
2722 phba->fc_topology = TOPOLOGY_LOOP;
2723 phba->pport->fc_myDID = 0;
2724 phba->alpa_map[0] = 0;
2725 phba->alpa_map[1] = 0;
2726 }
2727 }
James Smart2e0fef82007-06-17 19:56:36 -05002728 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002729 delay = 1000;
dea31012005-04-17 16:05:31 -05002730 retry = 1;
2731 break;
2732
James Smart92d7f7b2007-06-17 19:56:38 -05002733 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002734 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2735 "0124 Retry illegal cmd x%x "
2736 "retry:x%x delay:x%x\n",
2737 cmd, cmdiocb->retry, delay);
2738 retry = 1;
2739 /* All command's retry policy */
2740 maxretry = 8;
2741 if (cmdiocb->retry > 2)
2742 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002743 break;
2744
dea31012005-04-17 16:05:31 -05002745 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002746 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002747 retry = 1;
2748 if (cmdiocb->retry > 100)
2749 delay = 100;
2750 maxretry = 250;
2751 break;
2752
2753 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002754 delay = 100;
dea31012005-04-17 16:05:31 -05002755 retry = 1;
2756 break;
2757
James Smart858c9f62007-06-17 19:56:39 -05002758 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002759 case IOERR_INVALID_RPI:
2760 retry = 1;
2761 break;
2762 }
2763 break;
2764
2765 case IOSTAT_NPORT_RJT:
2766 case IOSTAT_FABRIC_RJT:
2767 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2768 retry = 1;
2769 break;
2770 }
2771 break;
2772
2773 case IOSTAT_NPORT_BSY:
2774 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002775 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002776 retry = 1;
2777 break;
2778
2779 case IOSTAT_LS_RJT:
2780 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2781 /* Added for Vendor specifc support
2782 * Just keep retrying for these Rsn / Exp codes
2783 */
2784 switch (stat.un.b.lsRjtRsnCode) {
2785 case LSRJT_UNABLE_TPC:
2786 if (stat.un.b.lsRjtRsnCodeExp ==
2787 LSEXP_CMD_IN_PROGRESS) {
2788 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002789 delay = 1000;
dea31012005-04-17 16:05:31 -05002790 maxretry = 48;
2791 }
2792 retry = 1;
2793 break;
2794 }
James Smartffc95492010-06-07 15:23:17 -04002795 if (stat.un.b.lsRjtRsnCodeExp ==
2796 LSEXP_CANT_GIVE_DATA) {
2797 if (cmd == ELS_CMD_PLOGI) {
2798 delay = 1000;
2799 maxretry = 48;
2800 }
2801 retry = 1;
2802 break;
2803 }
dea31012005-04-17 16:05:31 -05002804 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002805 delay = 1000;
dea31012005-04-17 16:05:31 -05002806 maxretry = lpfc_max_els_tries + 1;
2807 retry = 1;
2808 break;
2809 }
James Smart92d7f7b2007-06-17 19:56:38 -05002810 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2811 (cmd == ELS_CMD_FDISC) &&
2812 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002813 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2814 "0125 FDISC Failed (x%x). "
2815 "Fabric out of resources\n",
2816 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002817 lpfc_vport_set_state(vport,
2818 FC_VPORT_NO_FABRIC_RSCS);
2819 }
dea31012005-04-17 16:05:31 -05002820 break;
2821
2822 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002823 if ((cmd == ELS_CMD_PLOGI) ||
2824 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002825 delay = 1000;
dea31012005-04-17 16:05:31 -05002826 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002827 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002828 /* FDISC retry policy */
2829 maxretry = 48;
2830 if (cmdiocb->retry >= 32)
2831 delay = 1000;
dea31012005-04-17 16:05:31 -05002832 }
2833 retry = 1;
2834 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002835
2836 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002837 /* There are some cases where switches return this
2838 * error when they are not ready and should be returning
2839 * Logical Busy. We should delay every time.
2840 */
2841 if (cmd == ELS_CMD_FDISC &&
2842 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2843 maxretry = 3;
2844 delay = 1000;
2845 retry = 1;
2846 break;
2847 }
James Smart92d7f7b2007-06-17 19:56:38 -05002848 case LSRJT_PROTOCOL_ERR:
2849 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2850 (cmd == ELS_CMD_FDISC) &&
2851 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2852 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2853 ) {
James Smarte8b62012007-08-02 11:10:09 -04002854 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002855 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002856 "Fabric Detected Bad WWN\n",
2857 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002858 lpfc_vport_set_state(vport,
2859 FC_VPORT_FABRIC_REJ_WWN);
2860 }
2861 break;
dea31012005-04-17 16:05:31 -05002862 }
2863 break;
2864
2865 case IOSTAT_INTERMED_RSP:
2866 case IOSTAT_BA_RJT:
2867 break;
2868
2869 default:
2870 break;
2871 }
2872
James Smart488d1462006-03-07 15:02:37 -05002873 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002874 retry = 1;
dea31012005-04-17 16:05:31 -05002875
James Smart695a8142010-01-26 23:08:03 -05002876 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002877 (phba->fc_topology != TOPOLOGY_LOOP) &&
2878 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002879 /* FLOGI retry policy */
2880 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002881 /* retry forever */
2882 maxretry = 0;
2883 if (cmdiocb->retry >= 100)
2884 delay = 5000;
2885 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002886 delay = 1000;
2887 }
2888
James Smart6669f9b2009-10-02 15:16:45 -04002889 cmdiocb->retry++;
2890 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002891 phba->fc_stat.elsRetryExceeded++;
2892 retry = 0;
2893 }
2894
James Smarted957682007-06-17 19:56:37 -05002895 if ((vport->load_flag & FC_UNLOADING) != 0)
2896 retry = 0;
2897
dea31012005-04-17 16:05:31 -05002898 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04002899 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2900 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2901 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2902 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2903 "2849 Stop retry ELS command "
2904 "x%x to remote NPORT x%x, "
2905 "Data: x%x x%x\n", cmd, did,
2906 cmdiocb->retry, delay);
2907 return 0;
2908 }
2909 }
dea31012005-04-17 16:05:31 -05002910
2911 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002912 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2913 "0107 Retry ELS command x%x to remote "
2914 "NPORT x%x Data: x%x x%x\n",
2915 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002916
James Smart858c9f62007-06-17 19:56:39 -05002917 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2918 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2919 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2920 /* Don't reset timer for no resources */
2921
dea31012005-04-17 16:05:31 -05002922 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002923 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002924 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002925 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002926 }
2927
2928 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002929 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002930 phba->fc_stat.elsDelayRetry++;
2931 ndlp->nlp_retry = cmdiocb->retry;
2932
James Smart92d7f7b2007-06-17 19:56:38 -05002933 /* delay is specified in milliseconds */
2934 mod_timer(&ndlp->nlp_delayfunc,
2935 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002936 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002937 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002938 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002939
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002940 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002941 if (cmd == ELS_CMD_PRLI)
2942 lpfc_nlp_set_state(vport, ndlp,
2943 NLP_STE_REG_LOGIN_ISSUE);
2944 else
2945 lpfc_nlp_set_state(vport, ndlp,
2946 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002947 ndlp->nlp_last_elscmd = cmd;
2948
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002949 return 1;
dea31012005-04-17 16:05:31 -05002950 }
2951 switch (cmd) {
2952 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002953 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002954 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002955 case ELS_CMD_FDISC:
2956 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2957 return 1;
dea31012005-04-17 16:05:31 -05002958 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002959 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002960 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002961 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002962 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002963 }
James Smart2e0fef82007-06-17 19:56:36 -05002964 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002965 return 1;
dea31012005-04-17 16:05:31 -05002966 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002967 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002968 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2969 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002970 return 1;
dea31012005-04-17 16:05:31 -05002971 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002972 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002973 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2974 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002975 return 1;
dea31012005-04-17 16:05:31 -05002976 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002977 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002978 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2979 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002980 return 1;
dea31012005-04-17 16:05:31 -05002981 }
2982 }
dea31012005-04-17 16:05:31 -05002983 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002984 if (logerr) {
2985 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2986 "0137 No retry ELS command x%x to remote "
2987 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2988 cmd, did, irsp->ulpStatus,
2989 irsp->un.ulpWord[4]);
2990 }
2991 else {
2992 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002993 "0108 No retry ELS command x%x to remote "
2994 "NPORT x%x Retried:%d Error:x%x/%x\n",
2995 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2996 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002997 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002998 return 0;
dea31012005-04-17 16:05:31 -05002999}
3000
James Smarte59058c2008-08-24 21:49:00 -04003001/**
James Smart3621a712009-04-06 18:47:14 -04003002 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003003 * @phba: pointer to lpfc hba data structure.
3004 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3005 *
3006 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3007 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3008 * checks to see whether there is a lpfc DMA buffer associated with the
3009 * response of the command IOCB. If so, it will be released before releasing
3010 * the lpfc DMA buffer associated with the IOCB itself.
3011 *
3012 * Return code
3013 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3014 **/
James Smart09372822008-01-11 01:52:54 -05003015static int
James Smart87af33f2007-10-27 13:37:43 -04003016lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3017{
3018 struct lpfc_dmabuf *buf_ptr;
3019
James Smarte59058c2008-08-24 21:49:00 -04003020 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003021 if (!list_empty(&buf_ptr1->list)) {
3022 list_remove_head(&buf_ptr1->list, buf_ptr,
3023 struct lpfc_dmabuf,
3024 list);
3025 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3026 kfree(buf_ptr);
3027 }
3028 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3029 kfree(buf_ptr1);
3030 return 0;
3031}
3032
James Smarte59058c2008-08-24 21:49:00 -04003033/**
James Smart3621a712009-04-06 18:47:14 -04003034 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003035 * @phba: pointer to lpfc hba data structure.
3036 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3037 *
3038 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3039 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3040 * pool.
3041 *
3042 * Return code
3043 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3044 **/
James Smart09372822008-01-11 01:52:54 -05003045static int
James Smart87af33f2007-10-27 13:37:43 -04003046lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3047{
3048 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3049 kfree(buf_ptr);
3050 return 0;
3051}
3052
James Smarte59058c2008-08-24 21:49:00 -04003053/**
James Smart3621a712009-04-06 18:47:14 -04003054 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003055 * @phba: pointer to lpfc hba data structure.
3056 * @elsiocb: pointer to lpfc els command iocb data structure.
3057 *
3058 * This routine frees a command IOCB and its associated resources. The
3059 * command IOCB data structure contains the reference to various associated
3060 * resources, these fields must be set to NULL if the associated reference
3061 * not present:
3062 * context1 - reference to ndlp
3063 * context2 - reference to cmd
3064 * context2->next - reference to rsp
3065 * context3 - reference to bpl
3066 *
3067 * It first properly decrements the reference count held on ndlp for the
3068 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3069 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3070 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3071 * adds the DMA buffer the @phba data structure for the delayed release.
3072 * If reference to the Buffer Pointer List (BPL) is present, the
3073 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3074 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3075 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3076 *
3077 * Return code
3078 * 0 - Success (currently, always return 0)
3079 **/
James Smart87af33f2007-10-27 13:37:43 -04003080int
James Smart329f9bc2007-04-25 09:53:01 -04003081lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003082{
3083 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003084 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003085
James Smarta8adb832007-10-27 13:37:53 -04003086 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3087 if (ndlp) {
3088 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3089 lpfc_nlp_put(ndlp);
3090
3091 /* If the ndlp is not being used by another discovery
3092 * thread, free it.
3093 */
3094 if (!lpfc_nlp_not_used(ndlp)) {
3095 /* If ndlp is being used by another discovery
3096 * thread, just clear NLP_DEFER_RM
3097 */
3098 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3099 }
3100 }
3101 else
3102 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003103 elsiocb->context1 = NULL;
3104 }
dea31012005-04-17 16:05:31 -05003105 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3106 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003107 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3108 /* Firmware could still be in progress of DMAing
3109 * payload, so don't free data buffer till after
3110 * a hbeat.
3111 */
3112 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3113 buf_ptr = elsiocb->context2;
3114 elsiocb->context2 = NULL;
3115 if (buf_ptr) {
3116 buf_ptr1 = NULL;
3117 spin_lock_irq(&phba->hbalock);
3118 if (!list_empty(&buf_ptr->list)) {
3119 list_remove_head(&buf_ptr->list,
3120 buf_ptr1, struct lpfc_dmabuf,
3121 list);
3122 INIT_LIST_HEAD(&buf_ptr1->list);
3123 list_add_tail(&buf_ptr1->list,
3124 &phba->elsbuf);
3125 phba->elsbuf_cnt++;
3126 }
3127 INIT_LIST_HEAD(&buf_ptr->list);
3128 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3129 phba->elsbuf_cnt++;
3130 spin_unlock_irq(&phba->hbalock);
3131 }
3132 } else {
3133 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3134 lpfc_els_free_data(phba, buf_ptr1);
3135 }
dea31012005-04-17 16:05:31 -05003136 }
3137
3138 if (elsiocb->context3) {
3139 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003140 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003141 }
James Bottomley604a3e32005-10-29 10:28:33 -05003142 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003143 return 0;
3144}
3145
James Smarte59058c2008-08-24 21:49:00 -04003146/**
James Smart3621a712009-04-06 18:47:14 -04003147 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003148 * @phba: pointer to lpfc hba data structure.
3149 * @cmdiocb: pointer to lpfc command iocb data structure.
3150 * @rspiocb: pointer to lpfc response iocb data structure.
3151 *
3152 * This routine is the completion callback function to the Logout (LOGO)
3153 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3154 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3155 * release the ndlp if it has the last reference remaining (reference count
3156 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3157 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3158 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3159 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3160 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3161 * IOCB data structure.
3162 **/
dea31012005-04-17 16:05:31 -05003163static void
James Smart2e0fef82007-06-17 19:56:36 -05003164lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3165 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003166{
James Smart2e0fef82007-06-17 19:56:36 -05003167 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3168 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003169 IOCB_t *irsp;
3170
3171 irsp = &rspiocb->iocb;
3172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3173 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3174 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003175 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003176 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3177 "0109 ACC to LOGO completes to NPort x%x "
3178 "Data: x%x x%x x%x\n",
3179 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3180 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003181
3182 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3183 /* NPort Recovery mode or node is just allocated */
3184 if (!lpfc_nlp_not_used(ndlp)) {
3185 /* If the ndlp is being used by another discovery
3186 * thread, just unregister the RPI.
3187 */
3188 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003189 } else {
3190 /* Indicate the node has already released, should
3191 * not reference to it from within lpfc_els_free_iocb.
3192 */
3193 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003194 }
dea31012005-04-17 16:05:31 -05003195 }
3196 lpfc_els_free_iocb(phba, cmdiocb);
3197 return;
3198}
3199
James Smarte59058c2008-08-24 21:49:00 -04003200/**
James Smart3621a712009-04-06 18:47:14 -04003201 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003202 * @phba: pointer to lpfc hba data structure.
3203 * @pmb: pointer to the driver internal queue element for mailbox command.
3204 *
3205 * This routine is the completion callback function for unregister default
3206 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3207 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3208 * decrements the ndlp reference count held for this completion callback
3209 * function. After that, it invokes the lpfc_nlp_not_used() to check
3210 * whether there is only one reference left on the ndlp. If so, it will
3211 * perform one more decrement and trigger the release of the ndlp.
3212 **/
James Smart858c9f62007-06-17 19:56:39 -05003213void
3214lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3215{
3216 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3217 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3218
James Smart6fb120a2009-05-22 14:52:59 -04003219 /*
3220 * This routine is used to register and unregister in previous SLI
3221 * modes.
3222 */
3223 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3224 (phba->sli_rev == LPFC_SLI_REV4))
3225 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3226
James Smart858c9f62007-06-17 19:56:39 -05003227 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003228 pmb->context2 = NULL;
3229
James Smart858c9f62007-06-17 19:56:39 -05003230 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3231 kfree(mp);
3232 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003233 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003234 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003235 /* This is the end of the default RPI cleanup logic for this
3236 * ndlp. If no other discovery threads are using this ndlp.
3237 * we should free all resources associated with it.
3238 */
3239 lpfc_nlp_not_used(ndlp);
3240 }
James Smart3772a992009-05-22 14:50:54 -04003241
James Smart858c9f62007-06-17 19:56:39 -05003242 return;
3243}
3244
James Smarte59058c2008-08-24 21:49:00 -04003245/**
James Smart3621a712009-04-06 18:47:14 -04003246 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003247 * @phba: pointer to lpfc hba data structure.
3248 * @cmdiocb: pointer to lpfc command iocb data structure.
3249 * @rspiocb: pointer to lpfc response iocb data structure.
3250 *
3251 * This routine is the completion callback function for ELS Response IOCB
3252 * command. In normal case, this callback function just properly sets the
3253 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3254 * field in the command IOCB is not NULL, the referred mailbox command will
3255 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3256 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3257 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3258 * routine shall be invoked trying to release the ndlp if no other threads
3259 * are currently referring it.
3260 **/
dea31012005-04-17 16:05:31 -05003261static void
James Smart858c9f62007-06-17 19:56:39 -05003262lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003263 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003264{
James Smart2e0fef82007-06-17 19:56:36 -05003265 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3266 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3267 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003268 IOCB_t *irsp;
3269 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003270 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003271 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003272 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003273
James Smart33ccf8d2006-08-17 11:57:58 -04003274 irsp = &rspiocb->iocb;
3275
dea31012005-04-17 16:05:31 -05003276 if (cmdiocb->context_un.mbox)
3277 mbox = cmdiocb->context_un.mbox;
3278
James Smartfa4066b2008-01-11 01:53:27 -05003279 /* First determine if this is a LS_RJT cmpl. Note, this callback
3280 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3281 */
James Smart87af33f2007-10-27 13:37:43 -04003282 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003283 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3284 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003285 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003286 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003287 */
3288 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3289 ls_rjt = 1;
3290 }
3291
dea31012005-04-17 16:05:31 -05003292 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003293 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003294 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003295 mp = (struct lpfc_dmabuf *) mbox->context1;
3296 if (mp) {
3297 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3298 kfree(mp);
3299 }
James Smart329f9bc2007-04-25 09:53:01 -04003300 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003301 }
James Smart58da1ff2008-04-07 10:15:56 -04003302 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3303 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003304 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003305 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003306 /* Indicate the node has already released,
3307 * should not reference to it from within
3308 * the routine lpfc_els_free_iocb.
3309 */
3310 cmdiocb->context1 = NULL;
3311 }
dea31012005-04-17 16:05:31 -05003312 goto out;
3313 }
3314
James Smart858c9f62007-06-17 19:56:39 -05003315 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003316 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003317 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003318 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003319 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003320 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3321 "0110 ELS response tag x%x completes "
3322 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3323 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3324 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3325 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3326 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003327 if (mbox) {
3328 if ((rspiocb->iocb.ulpStatus == 0)
3329 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003330 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003331 /* Increment reference count to ndlp to hold the
3332 * reference to ndlp for the callback function.
3333 */
James Smart329f9bc2007-04-25 09:53:01 -04003334 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003335 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003336 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3337 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3338 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3339 }
3340 else {
3341 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3342 ndlp->nlp_prev_state = ndlp->nlp_state;
3343 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003344 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003345 }
James Smart0b727fe2007-10-27 13:37:25 -04003346 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003347 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003348 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003349 else
3350 /* Decrement the ndlp reference count we
3351 * set for this failed mailbox command.
3352 */
3353 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003354
3355 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3356 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3357 "0138 ELS rsp: Cannot issue reg_login for x%x "
3358 "Data: x%x x%x x%x\n",
3359 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3360 ndlp->nlp_rpi);
3361
James Smartfa4066b2008-01-11 01:53:27 -05003362 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003363 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003364 /* Indicate node has already been released,
3365 * should not reference to it from within
3366 * the routine lpfc_els_free_iocb.
3367 */
3368 cmdiocb->context1 = NULL;
3369 }
dea31012005-04-17 16:05:31 -05003370 } else {
James Smart858c9f62007-06-17 19:56:39 -05003371 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3372 if (!lpfc_error_lost_link(irsp) &&
3373 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003374 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003375 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003376 /* Indicate node has already been
3377 * released, should not reference
3378 * to it from within the routine
3379 * lpfc_els_free_iocb.
3380 */
3381 cmdiocb->context1 = NULL;
3382 }
dea31012005-04-17 16:05:31 -05003383 }
3384 }
James Smart14691152006-12-02 13:34:28 -05003385 mp = (struct lpfc_dmabuf *) mbox->context1;
3386 if (mp) {
3387 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3388 kfree(mp);
3389 }
3390 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003391 }
3392out:
James Smart58da1ff2008-04-07 10:15:56 -04003393 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003394 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003395 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003396 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003397
3398 /* If the node is not being used by another discovery thread,
3399 * and we are sending a reject, we are done with it.
3400 * Release driver reference count here and free associated
3401 * resources.
3402 */
3403 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003404 if (lpfc_nlp_not_used(ndlp))
3405 /* Indicate node has already been released,
3406 * should not reference to it from within
3407 * the routine lpfc_els_free_iocb.
3408 */
3409 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003410 }
James Smart87af33f2007-10-27 13:37:43 -04003411
dea31012005-04-17 16:05:31 -05003412 lpfc_els_free_iocb(phba, cmdiocb);
3413 return;
3414}
3415
James Smarte59058c2008-08-24 21:49:00 -04003416/**
James Smart3621a712009-04-06 18:47:14 -04003417 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003418 * @vport: pointer to a host virtual N_Port data structure.
3419 * @flag: the els command code to be accepted.
3420 * @oldiocb: pointer to the original lpfc command iocb data structure.
3421 * @ndlp: pointer to a node-list data structure.
3422 * @mbox: pointer to the driver internal queue element for mailbox command.
3423 *
3424 * This routine prepares and issues an Accept (ACC) response IOCB
3425 * command. It uses the @flag to properly set up the IOCB field for the
3426 * specific ACC response command to be issued and invokes the
3427 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3428 * @mbox pointer is passed in, it will be put into the context_un.mbox
3429 * field of the IOCB for the completion callback function to issue the
3430 * mailbox command to the HBA later when callback is invoked.
3431 *
3432 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3433 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3434 * will be stored into the context1 field of the IOCB for the completion
3435 * callback function to the corresponding response ELS IOCB command.
3436 *
3437 * Return code
3438 * 0 - Successfully issued acc response
3439 * 1 - Failed to issue acc response
3440 **/
dea31012005-04-17 16:05:31 -05003441int
James Smart2e0fef82007-06-17 19:56:36 -05003442lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3443 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003444 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003445{
James Smart2e0fef82007-06-17 19:56:36 -05003446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3447 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003448 IOCB_t *icmd;
3449 IOCB_t *oldcmd;
3450 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003451 struct lpfc_sli *psli;
3452 uint8_t *pcmd;
3453 uint16_t cmdsize;
3454 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003455 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003456
3457 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003458 oldcmd = &oldiocb->iocb;
3459
3460 switch (flag) {
3461 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003462 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003463 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3464 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003465 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003466 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003467 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003468 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003469 return 1;
dea31012005-04-17 16:05:31 -05003470 }
James Smart2e0fef82007-06-17 19:56:36 -05003471
dea31012005-04-17 16:05:31 -05003472 icmd = &elsiocb->iocb;
3473 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3474 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3475 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003476 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003477
3478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3479 "Issue ACC: did:x%x flg:x%x",
3480 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003481 break;
3482 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003483 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003484 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3485 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003486 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003487 return 1;
James Smart488d1462006-03-07 15:02:37 -05003488
dea31012005-04-17 16:05:31 -05003489 icmd = &elsiocb->iocb;
3490 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3491 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3492
3493 if (mbox)
3494 elsiocb->context_un.mbox = mbox;
3495
3496 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003497 pcmd += sizeof(uint32_t);
3498 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003499
3500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3501 "Issue ACC PLOGI: did:x%x flg:x%x",
3502 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003503 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003504 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003505 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003506 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003507 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3508 if (!elsiocb)
3509 return 1;
3510
3511 icmd = &elsiocb->iocb;
3512 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3513 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3514
3515 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003516 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003517 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3518 els_pkt_ptr = (ELS_PKT *) pcmd;
3519 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003520
3521 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3522 "Issue ACC PRLO: did:x%x flg:x%x",
3523 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003524 break;
dea31012005-04-17 16:05:31 -05003525 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003526 return 1;
dea31012005-04-17 16:05:31 -05003527 }
dea31012005-04-17 16:05:31 -05003528 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003529 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3530 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3531 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3532 elsiocb->iotag, elsiocb->iocb.ulpContext,
3533 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3534 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003535 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003536 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003537 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003538 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003539 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3540 } else {
James Smart858c9f62007-06-17 19:56:39 -05003541 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003542 }
3543
3544 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003545 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003546 if (rc == IOCB_ERROR) {
3547 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003548 return 1;
dea31012005-04-17 16:05:31 -05003549 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003550 return 0;
dea31012005-04-17 16:05:31 -05003551}
3552
James Smarte59058c2008-08-24 21:49:00 -04003553/**
James Smart3621a712009-04-06 18:47:14 -04003554 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003555 * @vport: pointer to a virtual N_Port data structure.
3556 * @rejectError:
3557 * @oldiocb: pointer to the original lpfc command iocb data structure.
3558 * @ndlp: pointer to a node-list data structure.
3559 * @mbox: pointer to the driver internal queue element for mailbox command.
3560 *
3561 * This routine prepares and issue an Reject (RJT) response IOCB
3562 * command. If a @mbox pointer is passed in, it will be put into the
3563 * context_un.mbox field of the IOCB for the completion callback function
3564 * to issue to the HBA later.
3565 *
3566 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3567 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3568 * will be stored into the context1 field of the IOCB for the completion
3569 * callback function to the reject response ELS IOCB command.
3570 *
3571 * Return code
3572 * 0 - Successfully issued reject response
3573 * 1 - Failed to issue reject response
3574 **/
dea31012005-04-17 16:05:31 -05003575int
James Smart2e0fef82007-06-17 19:56:36 -05003576lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003577 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3578 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003579{
James Smart2e0fef82007-06-17 19:56:36 -05003580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003581 IOCB_t *icmd;
3582 IOCB_t *oldcmd;
3583 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003584 struct lpfc_sli *psli;
3585 uint8_t *pcmd;
3586 uint16_t cmdsize;
3587 int rc;
3588
3589 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003590 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003591 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3592 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003593 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003594 return 1;
dea31012005-04-17 16:05:31 -05003595
3596 icmd = &elsiocb->iocb;
3597 oldcmd = &oldiocb->iocb;
3598 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3599 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3600
3601 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003602 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003603 *((uint32_t *) (pcmd)) = rejectError;
3604
James Smart51ef4c22007-08-02 11:10:31 -04003605 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003606 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003607
dea31012005-04-17 16:05:31 -05003608 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003609 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3610 "0129 Xmit ELS RJT x%x response tag x%x "
3611 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3612 "rpi x%x\n",
3613 rejectError, elsiocb->iotag,
3614 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3615 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3617 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3618 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3619
dea31012005-04-17 16:05:31 -05003620 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003621 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003622 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003623
dea31012005-04-17 16:05:31 -05003624 if (rc == IOCB_ERROR) {
3625 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003626 return 1;
dea31012005-04-17 16:05:31 -05003627 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003628 return 0;
dea31012005-04-17 16:05:31 -05003629}
3630
James Smarte59058c2008-08-24 21:49:00 -04003631/**
James Smart3621a712009-04-06 18:47:14 -04003632 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003633 * @vport: pointer to a virtual N_Port data structure.
3634 * @oldiocb: pointer to the original lpfc command iocb data structure.
3635 * @ndlp: pointer to a node-list data structure.
3636 *
3637 * This routine prepares and issues an Accept (ACC) response to Address
3638 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3639 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3640 *
3641 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3642 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3643 * will be stored into the context1 field of the IOCB for the completion
3644 * callback function to the ADISC Accept response ELS IOCB command.
3645 *
3646 * Return code
3647 * 0 - Successfully issued acc adisc response
3648 * 1 - Failed to issue adisc acc response
3649 **/
dea31012005-04-17 16:05:31 -05003650int
James Smart2e0fef82007-06-17 19:56:36 -05003651lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3652 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003653{
James Smart2e0fef82007-06-17 19:56:36 -05003654 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003655 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003656 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003657 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003658 uint8_t *pcmd;
3659 uint16_t cmdsize;
3660 int rc;
3661
James Smart92d7f7b2007-06-17 19:56:38 -05003662 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003663 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3664 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003665 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003666 return 1;
dea31012005-04-17 16:05:31 -05003667
dea31012005-04-17 16:05:31 -05003668 icmd = &elsiocb->iocb;
3669 oldcmd = &oldiocb->iocb;
3670 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003671
3672 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003673 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3674 "0130 Xmit ADISC ACC response iotag x%x xri: "
3675 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3676 elsiocb->iotag, elsiocb->iocb.ulpContext,
3677 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3678 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003679 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3680
3681 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003682 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003683
3684 ap = (ADISC *) (pcmd);
3685 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003686 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3687 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003688 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003689
James Smart858c9f62007-06-17 19:56:39 -05003690 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3691 "Issue ACC ADISC: did:x%x flg:x%x",
3692 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3693
dea31012005-04-17 16:05:31 -05003694 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003695 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003696 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003697 if (rc == IOCB_ERROR) {
3698 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003699 return 1;
dea31012005-04-17 16:05:31 -05003700 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003701 return 0;
dea31012005-04-17 16:05:31 -05003702}
3703
James Smarte59058c2008-08-24 21:49:00 -04003704/**
James Smart3621a712009-04-06 18:47:14 -04003705 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003706 * @vport: pointer to a virtual N_Port data structure.
3707 * @oldiocb: pointer to the original lpfc command iocb data structure.
3708 * @ndlp: pointer to a node-list data structure.
3709 *
3710 * This routine prepares and issues an Accept (ACC) response to Process
3711 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3712 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3713 *
3714 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3715 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3716 * will be stored into the context1 field of the IOCB for the completion
3717 * callback function to the PRLI Accept response ELS IOCB command.
3718 *
3719 * Return code
3720 * 0 - Successfully issued acc prli response
3721 * 1 - Failed to issue acc prli response
3722 **/
dea31012005-04-17 16:05:31 -05003723int
James Smart2e0fef82007-06-17 19:56:36 -05003724lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003725 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003726{
James Smart2e0fef82007-06-17 19:56:36 -05003727 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003728 PRLI *npr;
3729 lpfc_vpd_t *vpd;
3730 IOCB_t *icmd;
3731 IOCB_t *oldcmd;
3732 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003733 struct lpfc_sli *psli;
3734 uint8_t *pcmd;
3735 uint16_t cmdsize;
3736 int rc;
3737
3738 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003739
James Smart92d7f7b2007-06-17 19:56:38 -05003740 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003741 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003742 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003743 if (!elsiocb)
3744 return 1;
dea31012005-04-17 16:05:31 -05003745
dea31012005-04-17 16:05:31 -05003746 icmd = &elsiocb->iocb;
3747 oldcmd = &oldiocb->iocb;
3748 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003749 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003750 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3751 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3752 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3753 elsiocb->iotag, elsiocb->iocb.ulpContext,
3754 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3755 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003756 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3757
3758 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003759 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003760
3761 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003762 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003763
3764 npr = (PRLI *) pcmd;
3765 vpd = &phba->vpd;
3766 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003767 * If the remote port is a target and our firmware version is 3.20 or
3768 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003769 */
James Smart0d2b6b82008-06-14 22:52:47 -04003770 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3771 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003772 npr->ConfmComplAllowed = 1;
3773 npr->Retry = 1;
3774 npr->TaskRetryIdReq = 1;
3775 }
3776
3777 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3778 npr->estabImagePair = 1;
3779 npr->readXferRdyDis = 1;
3780 npr->ConfmComplAllowed = 1;
3781
3782 npr->prliType = PRLI_FCP_TYPE;
3783 npr->initiatorFunc = 1;
3784
James Smart858c9f62007-06-17 19:56:39 -05003785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3786 "Issue ACC PRLI: did:x%x flg:x%x",
3787 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3788
dea31012005-04-17 16:05:31 -05003789 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003790 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003791
James Smart3772a992009-05-22 14:50:54 -04003792 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003793 if (rc == IOCB_ERROR) {
3794 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003795 return 1;
dea31012005-04-17 16:05:31 -05003796 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003797 return 0;
dea31012005-04-17 16:05:31 -05003798}
3799
James Smarte59058c2008-08-24 21:49:00 -04003800/**
James Smart3621a712009-04-06 18:47:14 -04003801 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003802 * @vport: pointer to a virtual N_Port data structure.
3803 * @format: rnid command format.
3804 * @oldiocb: pointer to the original lpfc command iocb data structure.
3805 * @ndlp: pointer to a node-list data structure.
3806 *
3807 * This routine issues a Request Node Identification Data (RNID) Accept
3808 * (ACC) response. It constructs the RNID ACC response command according to
3809 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3810 * issue the response. Note that this command does not need to hold the ndlp
3811 * reference count for the callback. So, the ndlp reference count taken by
3812 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3813 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3814 * there is no ndlp reference available.
3815 *
3816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3818 * will be stored into the context1 field of the IOCB for the completion
3819 * callback function. However, for the RNID Accept Response ELS command,
3820 * this is undone later by this routine after the IOCB is allocated.
3821 *
3822 * Return code
3823 * 0 - Successfully issued acc rnid response
3824 * 1 - Failed to issue acc rnid response
3825 **/
dea31012005-04-17 16:05:31 -05003826static int
James Smart2e0fef82007-06-17 19:56:36 -05003827lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003828 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003829{
James Smart2e0fef82007-06-17 19:56:36 -05003830 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003831 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003832 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003833 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003834 struct lpfc_sli *psli;
3835 uint8_t *pcmd;
3836 uint16_t cmdsize;
3837 int rc;
3838
3839 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003840 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3841 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003842 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003843 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003844
James Smart2e0fef82007-06-17 19:56:36 -05003845 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3846 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003847 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003848 return 1;
dea31012005-04-17 16:05:31 -05003849
dea31012005-04-17 16:05:31 -05003850 icmd = &elsiocb->iocb;
3851 oldcmd = &oldiocb->iocb;
3852 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003853 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003854 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3855 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3856 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003857 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003858 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003859 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003860
James Smart92d7f7b2007-06-17 19:56:38 -05003861 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003862 rn = (RNID *) (pcmd);
3863 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003864 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3865 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3866 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003867 switch (format) {
3868 case 0:
3869 rn->SpecificLen = 0;
3870 break;
3871 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003872 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003873 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003874 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003875 rn->un.topologyDisc.unitType = RNID_HBA;
3876 rn->un.topologyDisc.physPort = 0;
3877 rn->un.topologyDisc.attachedNodes = 0;
3878 break;
3879 default:
3880 rn->CommonLen = 0;
3881 rn->SpecificLen = 0;
3882 break;
3883 }
3884
James Smart858c9f62007-06-17 19:56:39 -05003885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3886 "Issue ACC RNID: did:x%x flg:x%x",
3887 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3888
dea31012005-04-17 16:05:31 -05003889 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003890 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003891 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003892 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3893 * it could be freed */
3894
James Smart3772a992009-05-22 14:50:54 -04003895 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003896 if (rc == IOCB_ERROR) {
3897 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003898 return 1;
dea31012005-04-17 16:05:31 -05003899 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003900 return 0;
dea31012005-04-17 16:05:31 -05003901}
3902
James Smarte59058c2008-08-24 21:49:00 -04003903/**
James Smart12265f62010-10-22 11:05:53 -04003904 * lpfc_els_rsp_echo_acc - Issue echo acc response
3905 * @vport: pointer to a virtual N_Port data structure.
3906 * @data: pointer to echo data to return in the accept.
3907 * @oldiocb: pointer to the original lpfc command iocb data structure.
3908 * @ndlp: pointer to a node-list data structure.
3909 *
3910 * Return code
3911 * 0 - Successfully issued acc echo response
3912 * 1 - Failed to issue acc echo response
3913 **/
3914static int
3915lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3916 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3917{
3918 struct lpfc_hba *phba = vport->phba;
3919 struct lpfc_iocbq *elsiocb;
3920 struct lpfc_sli *psli;
3921 uint8_t *pcmd;
3922 uint16_t cmdsize;
3923 int rc;
3924
3925 psli = &phba->sli;
3926 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3927
3928 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3929 ndlp->nlp_DID, ELS_CMD_ACC);
3930 if (!elsiocb)
3931 return 1;
3932
3933 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3934 /* Xmit ECHO ACC response tag <ulpIoTag> */
3935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3936 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3937 elsiocb->iotag, elsiocb->iocb.ulpContext);
3938 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3939 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3940 pcmd += sizeof(uint32_t);
3941 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3942
3943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3944 "Issue ACC ECHO: did:x%x flg:x%x",
3945 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3946
3947 phba->fc_stat.elsXmitACC++;
3948 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3949 lpfc_nlp_put(ndlp);
3950 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3951 * it could be freed */
3952
3953 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3954 if (rc == IOCB_ERROR) {
3955 lpfc_els_free_iocb(phba, elsiocb);
3956 return 1;
3957 }
3958 return 0;
3959}
3960
3961/**
James Smart3621a712009-04-06 18:47:14 -04003962 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003963 * @vport: pointer to a host virtual N_Port data structure.
3964 *
3965 * This routine issues Address Discover (ADISC) ELS commands to those
3966 * N_Ports which are in node port recovery state and ADISC has not been issued
3967 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3968 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3969 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3970 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3971 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3972 * IOCBs quit for later pick up. On the other hand, after walking through
3973 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3974 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3975 * no more ADISC need to be sent.
3976 *
3977 * Return code
3978 * The number of N_Ports with adisc issued.
3979 **/
dea31012005-04-17 16:05:31 -05003980int
James Smart2e0fef82007-06-17 19:56:36 -05003981lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003982{
James Smart2e0fef82007-06-17 19:56:36 -05003983 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003984 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003985 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003986
James Smart685f0bf2007-04-25 09:53:08 -04003987 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003988 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003989 if (!NLP_CHK_NODE_ACT(ndlp))
3990 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003991 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3992 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3993 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003994 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003995 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003996 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003997 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3999 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004000 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004001 vport->num_disc_nodes++;
4002 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004003 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004004 spin_lock_irq(shost->host_lock);
4005 vport->fc_flag |= FC_NLP_MORE;
4006 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004007 break;
dea31012005-04-17 16:05:31 -05004008 }
4009 }
4010 }
4011 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004012 spin_lock_irq(shost->host_lock);
4013 vport->fc_flag &= ~FC_NLP_MORE;
4014 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004015 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004016 return sentadisc;
dea31012005-04-17 16:05:31 -05004017}
4018
James Smarte59058c2008-08-24 21:49:00 -04004019/**
James Smart3621a712009-04-06 18:47:14 -04004020 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004021 * @vport: pointer to a host virtual N_Port data structure.
4022 *
4023 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4024 * which are in node port recovery state, with a @vport. Each time an ELS
4025 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4026 * the per @vport number of discover count (num_disc_nodes) shall be
4027 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4028 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4029 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4030 * later pick up. On the other hand, after walking through all the ndlps with
4031 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4032 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4033 * PLOGI need to be sent.
4034 *
4035 * Return code
4036 * The number of N_Ports with plogi issued.
4037 **/
dea31012005-04-17 16:05:31 -05004038int
James Smart2e0fef82007-06-17 19:56:36 -05004039lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004040{
James Smart2e0fef82007-06-17 19:56:36 -05004041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004042 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004043 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004044
James Smart2e0fef82007-06-17 19:56:36 -05004045 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4046 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004047 if (!NLP_CHK_NODE_ACT(ndlp))
4048 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004049 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4050 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4051 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4052 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4053 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004054 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4055 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004056 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004057 vport->num_disc_nodes++;
4058 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004059 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004060 spin_lock_irq(shost->host_lock);
4061 vport->fc_flag |= FC_NLP_MORE;
4062 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004063 break;
dea31012005-04-17 16:05:31 -05004064 }
4065 }
4066 }
James Smart87af33f2007-10-27 13:37:43 -04004067 if (sentplogi) {
4068 lpfc_set_disctmo(vport);
4069 }
4070 else {
James Smart2e0fef82007-06-17 19:56:36 -05004071 spin_lock_irq(shost->host_lock);
4072 vport->fc_flag &= ~FC_NLP_MORE;
4073 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004074 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004075 return sentplogi;
dea31012005-04-17 16:05:31 -05004076}
4077
James Smarte59058c2008-08-24 21:49:00 -04004078/**
James Smart3621a712009-04-06 18:47:14 -04004079 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004080 * @vport: pointer to a host virtual N_Port data structure.
4081 *
4082 * This routine cleans up any Registration State Change Notification
4083 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4084 * @vport together with the host_lock is used to prevent multiple thread
4085 * trying to access the RSCN array on a same @vport at the same time.
4086 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004087void
James Smart2e0fef82007-06-17 19:56:36 -05004088lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004089{
James Smart2e0fef82007-06-17 19:56:36 -05004090 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4091 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004092 int i;
4093
James Smart7f5f3d02008-02-08 18:50:14 -05004094 spin_lock_irq(shost->host_lock);
4095 if (vport->fc_rscn_flush) {
4096 /* Another thread is walking fc_rscn_id_list on this vport */
4097 spin_unlock_irq(shost->host_lock);
4098 return;
4099 }
4100 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4101 vport->fc_rscn_flush = 1;
4102 spin_unlock_irq(shost->host_lock);
4103
James Smart2e0fef82007-06-17 19:56:36 -05004104 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004105 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004106 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004107 }
James Smart2e0fef82007-06-17 19:56:36 -05004108 spin_lock_irq(shost->host_lock);
4109 vport->fc_rscn_id_cnt = 0;
4110 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4111 spin_unlock_irq(shost->host_lock);
4112 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004113 /* Indicate we are done walking this fc_rscn_id_list */
4114 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004115}
4116
James Smarte59058c2008-08-24 21:49:00 -04004117/**
James Smart3621a712009-04-06 18:47:14 -04004118 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004119 * @vport: pointer to a host virtual N_Port data structure.
4120 * @did: remote destination port identifier.
4121 *
4122 * This routine checks whether there is any pending Registration State
4123 * Configuration Notification (RSCN) to a @did on @vport.
4124 *
4125 * Return code
4126 * None zero - The @did matched with a pending rscn
4127 * 0 - not able to match @did with a pending rscn
4128 **/
dea31012005-04-17 16:05:31 -05004129int
James Smart2e0fef82007-06-17 19:56:36 -05004130lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004131{
4132 D_ID ns_did;
4133 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004134 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004135 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004137
4138 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004139
4140 /* Never match fabric nodes for RSCNs */
4141 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004142 return 0;
dea31012005-04-17 16:05:31 -05004143
4144 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004145 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004146 return did;
dea31012005-04-17 16:05:31 -05004147
James Smart7f5f3d02008-02-08 18:50:14 -05004148 spin_lock_irq(shost->host_lock);
4149 if (vport->fc_rscn_flush) {
4150 /* Another thread is walking fc_rscn_id_list on this vport */
4151 spin_unlock_irq(shost->host_lock);
4152 return 0;
4153 }
4154 /* Indicate we are walking fc_rscn_id_list on this vport */
4155 vport->fc_rscn_flush = 1;
4156 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004157 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004158 lp = vport->fc_rscn_id_list[i]->virt;
4159 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4160 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004161 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004162 rscn_did.un.word = be32_to_cpu(*lp++);
4163 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004164 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4165 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004166 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4167 && (ns_did.un.b.area == rscn_did.un.b.area)
4168 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004169 goto return_did_out;
dea31012005-04-17 16:05:31 -05004170 break;
James Smarteaf15d52008-12-04 22:39:29 -05004171 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004172 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4173 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004174 goto return_did_out;
dea31012005-04-17 16:05:31 -05004175 break;
James Smarteaf15d52008-12-04 22:39:29 -05004176 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004177 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004178 goto return_did_out;
dea31012005-04-17 16:05:31 -05004179 break;
James Smarteaf15d52008-12-04 22:39:29 -05004180 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004181 goto return_did_out;
dea31012005-04-17 16:05:31 -05004182 }
4183 }
James Smart92d7f7b2007-06-17 19:56:38 -05004184 }
James Smart7f5f3d02008-02-08 18:50:14 -05004185 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4186 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004187 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004188return_did_out:
4189 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4190 vport->fc_rscn_flush = 0;
4191 return did;
dea31012005-04-17 16:05:31 -05004192}
4193
James Smarte59058c2008-08-24 21:49:00 -04004194/**
James Smart3621a712009-04-06 18:47:14 -04004195 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004196 * @vport: pointer to a host virtual N_Port data structure.
4197 *
4198 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4199 * state machine for a @vport's nodes that are with pending RSCN (Registration
4200 * State Change Notification).
4201 *
4202 * Return code
4203 * 0 - Successful (currently alway return 0)
4204 **/
dea31012005-04-17 16:05:31 -05004205static int
James Smart2e0fef82007-06-17 19:56:36 -05004206lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004207{
James Smart685f0bf2007-04-25 09:53:08 -04004208 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004209
James Smart0d2b6b82008-06-14 22:52:47 -04004210 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004211 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004212 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004213 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4214 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004215 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004216 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004217 NLP_EVT_DEVICE_RECOVERY);
4218 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004219 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004220 return 0;
dea31012005-04-17 16:05:31 -05004221}
4222
James Smarte59058c2008-08-24 21:49:00 -04004223/**
James Smart3621a712009-04-06 18:47:14 -04004224 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004225 * @vport: pointer to a host virtual N_Port data structure.
4226 * @cmdiocb: pointer to lpfc command iocb data structure.
4227 *
4228 * lpfc_send_rscn_event sends an RSCN netlink event to management
4229 * applications.
4230 */
4231static void
4232lpfc_send_rscn_event(struct lpfc_vport *vport,
4233 struct lpfc_iocbq *cmdiocb)
4234{
4235 struct lpfc_dmabuf *pcmd;
4236 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4237 uint32_t *payload_ptr;
4238 uint32_t payload_len;
4239 struct lpfc_rscn_event_header *rscn_event_data;
4240
4241 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4242 payload_ptr = (uint32_t *) pcmd->virt;
4243 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4244
4245 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4246 payload_len, GFP_KERNEL);
4247 if (!rscn_event_data) {
4248 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4249 "0147 Failed to allocate memory for RSCN event\n");
4250 return;
4251 }
4252 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4253 rscn_event_data->payload_length = payload_len;
4254 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4255 payload_len);
4256
4257 fc_host_post_vendor_event(shost,
4258 fc_get_event_number(),
4259 sizeof(struct lpfc_els_event_header) + payload_len,
4260 (char *)rscn_event_data,
4261 LPFC_NL_VENDOR_ID);
4262
4263 kfree(rscn_event_data);
4264}
4265
4266/**
James Smart3621a712009-04-06 18:47:14 -04004267 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004268 * @vport: pointer to a host virtual N_Port data structure.
4269 * @cmdiocb: pointer to lpfc command iocb data structure.
4270 * @ndlp: pointer to a node-list data structure.
4271 *
4272 * This routine processes an unsolicited RSCN (Registration State Change
4273 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4274 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4275 * discover state machine is about to begin discovery, it just accepts the
4276 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4277 * contains N_Port IDs for other vports on this HBA, it just accepts the
4278 * RSCN and ignore processing it. If the state machine is in the recovery
4279 * state, the fc_rscn_id_list of this @vport is walked and the
4280 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4281 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4282 * routine is invoked to handle the RSCN event.
4283 *
4284 * Return code
4285 * 0 - Just sent the acc response
4286 * 1 - Sent the acc response and waited for name server completion
4287 **/
dea31012005-04-17 16:05:31 -05004288static int
James Smart2e0fef82007-06-17 19:56:36 -05004289lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004290 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004291{
James Smart2e0fef82007-06-17 19:56:36 -05004292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4293 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004294 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004295 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004296 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004297 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004298 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004299 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004300 int i;
dea31012005-04-17 16:05:31 -05004301
4302 icmd = &cmdiocb->iocb;
4303 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4304 lp = (uint32_t *) pcmd->virt;
4305
James Smart92d7f7b2007-06-17 19:56:38 -05004306 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4307 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004308 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004309 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4310 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004311 vport->fc_flag, payload_len, *lp,
4312 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004313
4314 /* Send an RSCN event to the management application */
4315 lpfc_send_rscn_event(vport, cmdiocb);
4316
James Smartd2873e42006-08-18 17:46:43 -04004317 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004318 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004319 FCH_EVT_RSCN, lp[i]);
4320
dea31012005-04-17 16:05:31 -05004321 /* If we are about to begin discovery, just ACC the RSCN.
4322 * Discovery processing will satisfy it.
4323 */
James Smart2e0fef82007-06-17 19:56:36 -05004324 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4326 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4327 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4328
James Smart51ef4c22007-08-02 11:10:31 -04004329 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004330 return 0;
dea31012005-04-17 16:05:31 -05004331 }
4332
James Smart92d7f7b2007-06-17 19:56:38 -05004333 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4334 * just ACC and ignore it.
4335 */
4336 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004337 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004338 i = payload_len;
4339 datap = lp;
4340 while (i > 0) {
4341 nportid = *datap++;
4342 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4343 i -= sizeof(uint32_t);
4344 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004345 if (lpfc_find_vport_by_did(phba, nportid))
4346 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004347 }
4348 if (rscn_id == hba_id) {
4349 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004350 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004351 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004352 "Data: x%x x%x x%x x%x\n",
4353 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004354 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004355 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4356 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4357 ndlp->nlp_DID, vport->port_state,
4358 ndlp->nlp_flag);
4359
James Smart92d7f7b2007-06-17 19:56:38 -05004360 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004361 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004362 return 0;
4363 }
4364 }
4365
James Smart7f5f3d02008-02-08 18:50:14 -05004366 spin_lock_irq(shost->host_lock);
4367 if (vport->fc_rscn_flush) {
4368 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004369 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004370 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004371 /* Send back ACC */
4372 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004373 return 0;
4374 }
4375 /* Indicate we are walking fc_rscn_id_list on this vport */
4376 vport->fc_rscn_flush = 1;
4377 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004378 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004379 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004380 /* If we are already processing an RSCN, save the received
4381 * RSCN payload buffer, cmdiocb->context2 to process later.
4382 */
James Smart2e0fef82007-06-17 19:56:36 -05004383 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004384 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4385 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4386 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4387
James Smart09372822008-01-11 01:52:54 -05004388 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004389 vport->fc_flag |= FC_RSCN_DEFERRED;
4390 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004391 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004392 vport->fc_flag |= FC_RSCN_MODE;
4393 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004394 if (rscn_cnt) {
4395 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4396 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4397 }
4398 if ((rscn_cnt) &&
4399 (payload_len + length <= LPFC_BPL_SIZE)) {
4400 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004401 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004402 memcpy(((uint8_t *)cmd) + length, lp,
4403 payload_len);
4404 } else {
4405 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4406 vport->fc_rscn_id_cnt++;
4407 /* If we zero, cmdiocb->context2, the calling
4408 * routine will not try to free it.
4409 */
4410 cmdiocb->context2 = NULL;
4411 }
dea31012005-04-17 16:05:31 -05004412 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004413 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4414 "0235 Deferred RSCN "
4415 "Data: x%x x%x x%x\n",
4416 vport->fc_rscn_id_cnt, vport->fc_flag,
4417 vport->port_state);
dea31012005-04-17 16:05:31 -05004418 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004419 vport->fc_flag |= FC_RSCN_DISCOVERY;
4420 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004421 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004422 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4423 "0234 ReDiscovery RSCN "
4424 "Data: x%x x%x x%x\n",
4425 vport->fc_rscn_id_cnt, vport->fc_flag,
4426 vport->port_state);
dea31012005-04-17 16:05:31 -05004427 }
James Smart7f5f3d02008-02-08 18:50:14 -05004428 /* Indicate we are done walking fc_rscn_id_list on this vport */
4429 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004430 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004431 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004432 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004433 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004434 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004435 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004436 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004437 return 0;
dea31012005-04-17 16:05:31 -05004438 }
James Smart858c9f62007-06-17 19:56:39 -05004439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4440 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4441 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4442
James Smart2e0fef82007-06-17 19:56:36 -05004443 spin_lock_irq(shost->host_lock);
4444 vport->fc_flag |= FC_RSCN_MODE;
4445 spin_unlock_irq(shost->host_lock);
4446 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004447 /* Indicate we are done walking fc_rscn_id_list on this vport */
4448 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004449 /*
4450 * If we zero, cmdiocb->context2, the calling routine will
4451 * not try to free it.
4452 */
4453 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004454 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004455 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004456 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004457 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004458 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004459 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004460}
4461
James Smarte59058c2008-08-24 21:49:00 -04004462/**
James Smart3621a712009-04-06 18:47:14 -04004463 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004464 * @vport: pointer to a host virtual N_Port data structure.
4465 *
4466 * This routine handles the Registration State Configuration Notification
4467 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4468 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4469 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4470 * NameServer shall be issued. If CT command to the NameServer fails to be
4471 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4472 * RSCN activities with the @vport.
4473 *
4474 * Return code
4475 * 0 - Cleaned up rscn on the @vport
4476 * 1 - Wait for plogi to name server before proceed
4477 **/
dea31012005-04-17 16:05:31 -05004478int
James Smart2e0fef82007-06-17 19:56:36 -05004479lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004480{
4481 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004482 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004483
James Smart92d7f7b2007-06-17 19:56:38 -05004484 /* Ignore RSCN if the port is being torn down. */
4485 if (vport->load_flag & FC_UNLOADING) {
4486 lpfc_els_flush_rscn(vport);
4487 return 0;
4488 }
4489
dea31012005-04-17 16:05:31 -05004490 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004491 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004492
4493 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004494 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4495 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4496 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4497 vport->port_state);
dea31012005-04-17 16:05:31 -05004498
4499 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004500 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004501 vport->num_disc_nodes = 0;
4502
James Smart2e0fef82007-06-17 19:56:36 -05004503 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004504 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4505 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004506 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004507 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004508 /* Wait for NameServer query cmpl before we can
4509 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004510 return 1;
dea31012005-04-17 16:05:31 -05004511 } else {
4512 /* If login to NameServer does not exist, issue one */
4513 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004514 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004515 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004516 /* Wait for NameServer login cmpl before we can
4517 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004518 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004519
James Smarte47c9092008-02-08 18:49:26 -05004520 if (ndlp) {
4521 ndlp = lpfc_enable_node(vport, ndlp,
4522 NLP_STE_PLOGI_ISSUE);
4523 if (!ndlp) {
4524 lpfc_els_flush_rscn(vport);
4525 return 0;
4526 }
4527 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004528 } else {
James Smarte47c9092008-02-08 18:49:26 -05004529 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4530 if (!ndlp) {
4531 lpfc_els_flush_rscn(vport);
4532 return 0;
4533 }
James Smart2e0fef82007-06-17 19:56:36 -05004534 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004535 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004536 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004537 }
James Smarte47c9092008-02-08 18:49:26 -05004538 ndlp->nlp_type |= NLP_FABRIC;
4539 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4540 /* Wait for NameServer login cmpl before we can
4541 * continue
4542 */
4543 return 1;
dea31012005-04-17 16:05:31 -05004544 }
4545
James Smart2e0fef82007-06-17 19:56:36 -05004546 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004547 return 0;
dea31012005-04-17 16:05:31 -05004548}
4549
James Smarte59058c2008-08-24 21:49:00 -04004550/**
James Smart3621a712009-04-06 18:47:14 -04004551 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004552 * @vport: pointer to a host virtual N_Port data structure.
4553 * @cmdiocb: pointer to lpfc command iocb data structure.
4554 * @ndlp: pointer to a node-list data structure.
4555 *
4556 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4557 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4558 * point topology. As an unsolicited FLOGI should not be received in a loop
4559 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4560 * lpfc_check_sparm() routine is invoked to check the parameters in the
4561 * unsolicited FLOGI. If parameters validation failed, the routine
4562 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4563 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4564 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4565 * will initiate PLOGI. The higher lexicographical value party shall has
4566 * higher priority (as the winning port) and will initiate PLOGI and
4567 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4568 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4569 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4570 *
4571 * Return code
4572 * 0 - Successfully processed the unsolicited flogi
4573 * 1 - Failed to process the unsolicited flogi
4574 **/
dea31012005-04-17 16:05:31 -05004575static int
James Smart2e0fef82007-06-17 19:56:36 -05004576lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004577 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004578{
James Smart2e0fef82007-06-17 19:56:36 -05004579 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004581 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4582 uint32_t *lp = (uint32_t *) pcmd->virt;
4583 IOCB_t *icmd = &cmdiocb->iocb;
4584 struct serv_parm *sp;
4585 LPFC_MBOXQ_t *mbox;
4586 struct ls_rjt stat;
4587 uint32_t cmd, did;
4588 int rc;
4589
4590 cmd = *lp++;
4591 sp = (struct serv_parm *) lp;
4592
4593 /* FLOGI received */
4594
James Smart2e0fef82007-06-17 19:56:36 -05004595 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004596
4597 if (phba->fc_topology == TOPOLOGY_LOOP) {
4598 /* We should never receive a FLOGI in loop mode, ignore it */
4599 did = icmd->un.elsreq64.remoteID;
4600
4601 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4602 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004603 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4604 "0113 An FLOGI ELS command x%x was "
4605 "received from DID x%x in Loop Mode\n",
4606 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004607 return 1;
dea31012005-04-17 16:05:31 -05004608 }
4609
4610 did = Fabric_DID;
4611
James Smart341af102010-01-26 23:07:37 -05004612 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004613 /* For a FLOGI we accept, then if our portname is greater
4614 * then the remote portname we initiate Nport login.
4615 */
4616
James Smart2e0fef82007-06-17 19:56:36 -05004617 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004618 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004619
4620 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004621 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4622 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004623 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004624
dea31012005-04-17 16:05:31 -05004625 lpfc_linkdown(phba);
4626 lpfc_init_link(phba, mbox,
4627 phba->cfg_topology,
4628 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004629 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004630 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004631 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004632 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004633 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004634 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004635 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004636 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004637 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004638 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004639 spin_lock_irq(shost->host_lock);
4640 vport->fc_flag |= FC_PT2PT_PLOGI;
4641 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004642 }
James Smart2e0fef82007-06-17 19:56:36 -05004643 spin_lock_irq(shost->host_lock);
4644 vport->fc_flag |= FC_PT2PT;
4645 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4646 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004647 } else {
4648 /* Reject this request because invalid parameters */
4649 stat.un.b.lsRjtRsvd0 = 0;
4650 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4651 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4652 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004653 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4654 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004655 return 1;
dea31012005-04-17 16:05:31 -05004656 }
4657
4658 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004659 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004660
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004661 return 0;
dea31012005-04-17 16:05:31 -05004662}
4663
James Smarte59058c2008-08-24 21:49:00 -04004664/**
James Smart3621a712009-04-06 18:47:14 -04004665 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004666 * @vport: pointer to a host virtual N_Port data structure.
4667 * @cmdiocb: pointer to lpfc command iocb data structure.
4668 * @ndlp: pointer to a node-list data structure.
4669 *
4670 * This routine processes Request Node Identification Data (RNID) IOCB
4671 * received as an ELS unsolicited event. Only when the RNID specified format
4672 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4673 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4674 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4675 * rejected by invoking the lpfc_els_rsp_reject() routine.
4676 *
4677 * Return code
4678 * 0 - Successfully processed rnid iocb (currently always return 0)
4679 **/
dea31012005-04-17 16:05:31 -05004680static int
James Smart2e0fef82007-06-17 19:56:36 -05004681lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4682 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004683{
4684 struct lpfc_dmabuf *pcmd;
4685 uint32_t *lp;
4686 IOCB_t *icmd;
4687 RNID *rn;
4688 struct ls_rjt stat;
4689 uint32_t cmd, did;
4690
4691 icmd = &cmdiocb->iocb;
4692 did = icmd->un.elsreq64.remoteID;
4693 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4694 lp = (uint32_t *) pcmd->virt;
4695
4696 cmd = *lp++;
4697 rn = (RNID *) lp;
4698
4699 /* RNID received */
4700
4701 switch (rn->Format) {
4702 case 0:
4703 case RNID_TOPOLOGY_DISC:
4704 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004705 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004706 break;
4707 default:
4708 /* Reject this request because format not supported */
4709 stat.un.b.lsRjtRsvd0 = 0;
4710 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4711 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4712 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004713 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4714 NULL);
dea31012005-04-17 16:05:31 -05004715 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004716 return 0;
dea31012005-04-17 16:05:31 -05004717}
4718
James Smarte59058c2008-08-24 21:49:00 -04004719/**
James Smart12265f62010-10-22 11:05:53 -04004720 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4721 * @vport: pointer to a host virtual N_Port data structure.
4722 * @cmdiocb: pointer to lpfc command iocb data structure.
4723 * @ndlp: pointer to a node-list data structure.
4724 *
4725 * Return code
4726 * 0 - Successfully processed echo iocb (currently always return 0)
4727 **/
4728static int
4729lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4730 struct lpfc_nodelist *ndlp)
4731{
4732 uint8_t *pcmd;
4733
4734 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4735
4736 /* skip over first word of echo command to find echo data */
4737 pcmd += sizeof(uint32_t);
4738
4739 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4740 return 0;
4741}
4742
4743/**
James Smart3621a712009-04-06 18:47:14 -04004744 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004745 * @vport: pointer to a host virtual N_Port data structure.
4746 * @cmdiocb: pointer to lpfc command iocb data structure.
4747 * @ndlp: pointer to a node-list data structure.
4748 *
4749 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4750 * received as an ELS unsolicited event. Currently, this function just invokes
4751 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4752 *
4753 * Return code
4754 * 0 - Successfully processed lirr iocb (currently always return 0)
4755 **/
dea31012005-04-17 16:05:31 -05004756static int
James Smart2e0fef82007-06-17 19:56:36 -05004757lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4758 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004759{
4760 struct ls_rjt stat;
4761
4762 /* For now, unconditionally reject this command */
4763 stat.un.b.lsRjtRsvd0 = 0;
4764 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4765 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4766 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004767 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004768 return 0;
4769}
4770
James Smarte59058c2008-08-24 21:49:00 -04004771/**
James Smart5ffc2662009-11-18 15:39:44 -05004772 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4773 * @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 Reinstate Recovery Qualifier (RRQ) IOCB
4778 * received as an ELS unsolicited event. A request to RRQ shall only
4779 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4780 * Nx_Port N_Port_ID of the target Exchange is the same as the
4781 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4782 * not accepted, an LS_RJT with reason code "Unable to perform
4783 * command request" and reason code explanation "Invalid Originator
4784 * S_ID" shall be returned. For now, we just unconditionally accept
4785 * RRQ from the target.
4786 **/
4787static void
4788lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4789 struct lpfc_nodelist *ndlp)
4790{
4791 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4792}
4793
4794/**
James Smart12265f62010-10-22 11:05:53 -04004795 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4796 * @phba: pointer to lpfc hba data structure.
4797 * @pmb: pointer to the driver internal queue element for mailbox command.
4798 *
4799 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4800 * mailbox command. This callback function is to actually send the Accept
4801 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4802 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4803 * mailbox command, constructs the RPS response with the link statistics
4804 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4805 * response to the RPS.
4806 *
4807 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4808 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4809 * will be stored into the context1 field of the IOCB for the completion
4810 * callback function to the RPS Accept Response ELS IOCB command.
4811 *
4812 **/
4813static void
4814lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4815{
4816 MAILBOX_t *mb;
4817 IOCB_t *icmd;
4818 struct RLS_RSP *rls_rsp;
4819 uint8_t *pcmd;
4820 struct lpfc_iocbq *elsiocb;
4821 struct lpfc_nodelist *ndlp;
4822 uint16_t xri;
4823 uint32_t cmdsize;
4824
4825 mb = &pmb->u.mb;
4826
4827 ndlp = (struct lpfc_nodelist *) pmb->context2;
4828 xri = (uint16_t) ((unsigned long)(pmb->context1));
4829 pmb->context1 = NULL;
4830 pmb->context2 = NULL;
4831
4832 if (mb->mbxStatus) {
4833 mempool_free(pmb, phba->mbox_mem_pool);
4834 return;
4835 }
4836
4837 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4838 mempool_free(pmb, phba->mbox_mem_pool);
4839 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4840 lpfc_max_els_tries, ndlp,
4841 ndlp->nlp_DID, ELS_CMD_ACC);
4842
4843 /* Decrement the ndlp reference count from previous mbox command */
4844 lpfc_nlp_put(ndlp);
4845
4846 if (!elsiocb)
4847 return;
4848
4849 icmd = &elsiocb->iocb;
4850 icmd->ulpContext = xri;
4851
4852 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4853 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4854 pcmd += sizeof(uint32_t); /* Skip past command */
4855 rls_rsp = (struct RLS_RSP *)pcmd;
4856
4857 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4858 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4859 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4860 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4861 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4862 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4863
4864 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4865 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4866 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4867 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4868 elsiocb->iotag, elsiocb->iocb.ulpContext,
4869 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4870 ndlp->nlp_rpi);
4871 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4872 phba->fc_stat.elsXmitACC++;
4873 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4874 lpfc_els_free_iocb(phba, elsiocb);
4875}
4876
4877/**
James Smart3621a712009-04-06 18:47:14 -04004878 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004879 * @phba: pointer to lpfc hba data structure.
4880 * @pmb: pointer to the driver internal queue element for mailbox command.
4881 *
4882 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4883 * mailbox command. This callback function is to actually send the Accept
4884 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4885 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4886 * mailbox command, constructs the RPS response with the link statistics
4887 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4888 * response to the RPS.
4889 *
4890 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4891 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4892 * will be stored into the context1 field of the IOCB for the completion
4893 * callback function to the RPS Accept Response ELS IOCB command.
4894 *
4895 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004896static void
James Smart329f9bc2007-04-25 09:53:01 -04004897lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004898{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004899 MAILBOX_t *mb;
4900 IOCB_t *icmd;
4901 RPS_RSP *rps_rsp;
4902 uint8_t *pcmd;
4903 struct lpfc_iocbq *elsiocb;
4904 struct lpfc_nodelist *ndlp;
4905 uint16_t xri, status;
4906 uint32_t cmdsize;
4907
James Smart04c68492009-05-22 14:52:52 -04004908 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004909
4910 ndlp = (struct lpfc_nodelist *) pmb->context2;
4911 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004912 pmb->context1 = NULL;
4913 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004914
4915 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004916 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004917 return;
4918 }
4919
4920 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004921 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004922 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4923 lpfc_max_els_tries, ndlp,
4924 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004925
4926 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004927 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004928
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004929 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004930 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004931
4932 icmd = &elsiocb->iocb;
4933 icmd->ulpContext = xri;
4934
4935 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4936 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004937 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004938 rps_rsp = (RPS_RSP *)pcmd;
4939
4940 if (phba->fc_topology != TOPOLOGY_LOOP)
4941 status = 0x10;
4942 else
4943 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004944 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004945 status |= 0x4;
4946
4947 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004948 rps_rsp->portStatus = cpu_to_be16(status);
4949 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4950 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4951 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4952 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4953 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4954 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004955 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004956 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4957 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4958 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4959 elsiocb->iotag, elsiocb->iocb.ulpContext,
4960 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4961 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004962 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004963 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004964 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004965 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004966 return;
4967}
4968
James Smarte59058c2008-08-24 21:49:00 -04004969/**
James Smart12265f62010-10-22 11:05:53 -04004970 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4971 * @vport: pointer to a host virtual N_Port data structure.
4972 * @cmdiocb: pointer to lpfc command iocb data structure.
4973 * @ndlp: pointer to a node-list data structure.
4974 *
4975 * This routine processes Read Port Status (RPL) IOCB received as an
4976 * ELS unsolicited event. It first checks the remote port state. If the
4977 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4978 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
4979 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4980 * for reading the HBA link statistics. It is for the callback function,
4981 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
4982 * to actually sending out RPL Accept (ACC) response.
4983 *
4984 * Return codes
4985 * 0 - Successfully processed rls iocb (currently always return 0)
4986 **/
4987static int
4988lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4989 struct lpfc_nodelist *ndlp)
4990{
4991 struct lpfc_hba *phba = vport->phba;
4992 LPFC_MBOXQ_t *mbox;
4993 struct lpfc_dmabuf *pcmd;
4994 struct ls_rjt stat;
4995
4996 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4997 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4998 /* reject the unsolicited RPS request and done with it */
4999 goto reject_out;
5000
5001 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5002
5003 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5004 if (mbox) {
5005 lpfc_read_lnk_stat(phba, mbox);
5006 mbox->context1 =
5007 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5008 mbox->context2 = lpfc_nlp_get(ndlp);
5009 mbox->vport = vport;
5010 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5011 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5012 != MBX_NOT_FINISHED)
5013 /* Mbox completion will send ELS Response */
5014 return 0;
5015 /* Decrement reference count used for the failed mbox
5016 * command.
5017 */
5018 lpfc_nlp_put(ndlp);
5019 mempool_free(mbox, phba->mbox_mem_pool);
5020 }
5021reject_out:
5022 /* issue rejection response */
5023 stat.un.b.lsRjtRsvd0 = 0;
5024 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5025 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5026 stat.un.b.vendorUnique = 0;
5027 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5028 return 0;
5029}
5030
5031/**
5032 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5033 * @vport: pointer to a host virtual N_Port data structure.
5034 * @cmdiocb: pointer to lpfc command iocb data structure.
5035 * @ndlp: pointer to a node-list data structure.
5036 *
5037 * This routine processes Read Timout Value (RTV) IOCB received as an
5038 * ELS unsolicited event. It first checks the remote port state. If the
5039 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5040 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5041 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5042 * Value (RTV) unsolicited IOCB event.
5043 *
5044 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5045 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5046 * will be stored into the context1 field of the IOCB for the completion
5047 * callback function to the RPS Accept Response ELS IOCB command.
5048 *
5049 * Return codes
5050 * 0 - Successfully processed rtv iocb (currently always return 0)
5051 **/
5052static int
5053lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5054 struct lpfc_nodelist *ndlp)
5055{
5056 struct lpfc_hba *phba = vport->phba;
5057 struct ls_rjt stat;
5058 struct RTV_RSP *rtv_rsp;
5059 uint8_t *pcmd;
5060 struct lpfc_iocbq *elsiocb;
5061 uint32_t cmdsize;
5062
5063
5064 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5065 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5066 /* reject the unsolicited RPS request and done with it */
5067 goto reject_out;
5068
5069 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5070 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5071 lpfc_max_els_tries, ndlp,
5072 ndlp->nlp_DID, ELS_CMD_ACC);
5073
5074 if (!elsiocb)
5075 return 1;
5076
5077 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5078 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5079 pcmd += sizeof(uint32_t); /* Skip past command */
5080
5081 /* use the command's xri in the response */
5082 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5083
5084 rtv_rsp = (struct RTV_RSP *)pcmd;
5085
5086 /* populate RTV payload */
5087 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5088 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5089 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5090 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5091 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5092
5093 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5094 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5095 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5096 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5097 "Data: x%x x%x x%x\n",
5098 elsiocb->iotag, elsiocb->iocb.ulpContext,
5099 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5100 ndlp->nlp_rpi,
5101 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5102 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5103 phba->fc_stat.elsXmitACC++;
5104 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5105 lpfc_els_free_iocb(phba, elsiocb);
5106 return 0;
5107
5108reject_out:
5109 /* issue rejection response */
5110 stat.un.b.lsRjtRsvd0 = 0;
5111 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5112 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5113 stat.un.b.vendorUnique = 0;
5114 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5115 return 0;
5116}
5117
5118/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005119 * @vport: pointer to a host virtual N_Port data structure.
5120 * @cmdiocb: pointer to lpfc command iocb data structure.
5121 * @ndlp: pointer to a node-list data structure.
5122 *
5123 * This routine processes Read Port Status (RPS) IOCB received as an
5124 * ELS unsolicited event. It first checks the remote port state. If the
5125 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5126 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5127 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5128 * for reading the HBA link statistics. It is for the callback function,
5129 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5130 * to actually sending out RPS Accept (ACC) response.
5131 *
5132 * Return codes
5133 * 0 - Successfully processed rps iocb (currently always return 0)
5134 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005135static int
James Smart2e0fef82007-06-17 19:56:36 -05005136lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5137 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005138{
James Smart2e0fef82007-06-17 19:56:36 -05005139 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005140 uint32_t *lp;
5141 uint8_t flag;
5142 LPFC_MBOXQ_t *mbox;
5143 struct lpfc_dmabuf *pcmd;
5144 RPS *rps;
5145 struct ls_rjt stat;
5146
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005147 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005148 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5149 /* reject the unsolicited RPS request and done with it */
5150 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005151
5152 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5153 lp = (uint32_t *) pcmd->virt;
5154 flag = (be32_to_cpu(*lp++) & 0xf);
5155 rps = (RPS *) lp;
5156
5157 if ((flag == 0) ||
5158 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005159 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005160 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005161
James Smart92d7f7b2007-06-17 19:56:38 -05005162 printk("Fix me....\n");
5163 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005164 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5165 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005166 lpfc_read_lnk_stat(phba, mbox);
5167 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005168 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005169 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005170 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005171 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005172 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005173 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005174 /* Mbox completion will send ELS Response */
5175 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005176 /* Decrement reference count used for the failed mbox
5177 * command.
5178 */
James Smart329f9bc2007-04-25 09:53:01 -04005179 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005180 mempool_free(mbox, phba->mbox_mem_pool);
5181 }
5182 }
James Smart90160e02008-08-24 21:49:45 -04005183
5184reject_out:
5185 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005186 stat.un.b.lsRjtRsvd0 = 0;
5187 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5188 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5189 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005190 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005191 return 0;
5192}
5193
James Smarte59058c2008-08-24 21:49:00 -04005194/**
James Smart3621a712009-04-06 18:47:14 -04005195 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005196 * @vport: pointer to a host virtual N_Port data structure.
5197 * @cmdsize: size of the ELS command.
5198 * @oldiocb: pointer to the original lpfc command iocb data structure.
5199 * @ndlp: pointer to a node-list data structure.
5200 *
5201 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5202 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5203 *
5204 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5205 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5206 * will be stored into the context1 field of the IOCB for the completion
5207 * callback function to the RPL Accept Response ELS command.
5208 *
5209 * Return code
5210 * 0 - Successfully issued ACC RPL ELS command
5211 * 1 - Failed to issue ACC RPL ELS command
5212 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005213static int
James Smart2e0fef82007-06-17 19:56:36 -05005214lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5215 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005216{
James Smart2e0fef82007-06-17 19:56:36 -05005217 struct lpfc_hba *phba = vport->phba;
5218 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005219 RPL_RSP rpl_rsp;
5220 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005221 uint8_t *pcmd;
5222
James Smart2e0fef82007-06-17 19:56:36 -05005223 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5224 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005225
James Smart488d1462006-03-07 15:02:37 -05005226 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005227 return 1;
James Smart488d1462006-03-07 15:02:37 -05005228
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005229 icmd = &elsiocb->iocb;
5230 oldcmd = &oldiocb->iocb;
5231 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5232
5233 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5234 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005235 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005236 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5237 pcmd += sizeof(uint16_t);
5238
5239 /* Setup the RPL ACC payload */
5240 rpl_rsp.listLen = be32_to_cpu(1);
5241 rpl_rsp.index = 0;
5242 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005243 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5244 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005245 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005246 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005247 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005248 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5249 "0120 Xmit ELS RPL ACC response tag x%x "
5250 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5251 "rpi x%x\n",
5252 elsiocb->iotag, elsiocb->iocb.ulpContext,
5253 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5254 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005255 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005256 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005257 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5258 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005259 lpfc_els_free_iocb(phba, elsiocb);
5260 return 1;
5261 }
5262 return 0;
5263}
5264
James Smarte59058c2008-08-24 21:49:00 -04005265/**
James Smart3621a712009-04-06 18:47:14 -04005266 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005267 * @vport: pointer to a host virtual N_Port data structure.
5268 * @cmdiocb: pointer to lpfc command iocb data structure.
5269 * @ndlp: pointer to a node-list data structure.
5270 *
5271 * This routine processes Read Port List (RPL) IOCB received as an ELS
5272 * unsolicited event. It first checks the remote port state. If the remote
5273 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5274 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5275 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5276 * to accept the RPL.
5277 *
5278 * Return code
5279 * 0 - Successfully processed rpl iocb (currently always return 0)
5280 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005281static int
James Smart2e0fef82007-06-17 19:56:36 -05005282lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5283 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005284{
5285 struct lpfc_dmabuf *pcmd;
5286 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005287 uint32_t maxsize;
5288 uint16_t cmdsize;
5289 RPL *rpl;
5290 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005291
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005292 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5293 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005294 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005295 stat.un.b.lsRjtRsvd0 = 0;
5296 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5297 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5298 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005299 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5300 NULL);
James Smart90160e02008-08-24 21:49:45 -04005301 /* rejected the unsolicited RPL request and done with it */
5302 return 0;
dea31012005-04-17 16:05:31 -05005303 }
5304
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005305 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5306 lp = (uint32_t *) pcmd->virt;
5307 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005308 maxsize = be32_to_cpu(rpl->maxsize);
5309
5310 /* We support only one port */
5311 if ((rpl->index == 0) &&
5312 ((maxsize == 0) ||
5313 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5314 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005315 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005316 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5317 }
James Smart2e0fef82007-06-17 19:56:36 -05005318 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005319
5320 return 0;
5321}
5322
James Smarte59058c2008-08-24 21:49:00 -04005323/**
James Smart3621a712009-04-06 18:47:14 -04005324 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005325 * @vport: pointer to a virtual N_Port data structure.
5326 * @cmdiocb: pointer to lpfc command iocb data structure.
5327 * @ndlp: pointer to a node-list data structure.
5328 *
5329 * This routine processes Fibre Channel Address Resolution Protocol
5330 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5331 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5332 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5333 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5334 * remote PortName is compared against the FC PortName stored in the @vport
5335 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5336 * compared against the FC NodeName stored in the @vport data structure.
5337 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5338 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5339 * invoked to send out FARP Response to the remote node. Before sending the
5340 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5341 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5342 * routine is invoked to log into the remote port first.
5343 *
5344 * Return code
5345 * 0 - Either the FARP Match Mode not supported or successfully processed
5346 **/
dea31012005-04-17 16:05:31 -05005347static int
James Smart2e0fef82007-06-17 19:56:36 -05005348lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5349 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005350{
5351 struct lpfc_dmabuf *pcmd;
5352 uint32_t *lp;
5353 IOCB_t *icmd;
5354 FARP *fp;
5355 uint32_t cmd, cnt, did;
5356
5357 icmd = &cmdiocb->iocb;
5358 did = icmd->un.elsreq64.remoteID;
5359 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5360 lp = (uint32_t *) pcmd->virt;
5361
5362 cmd = *lp++;
5363 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005364 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005365 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5366 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005367 /* We will only support match on WWPN or WWNN */
5368 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005369 return 0;
dea31012005-04-17 16:05:31 -05005370 }
5371
5372 cnt = 0;
5373 /* If this FARP command is searching for my portname */
5374 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005375 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005376 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005377 cnt = 1;
5378 }
5379
5380 /* If this FARP command is searching for my nodename */
5381 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005382 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005383 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005384 cnt = 1;
5385 }
5386
5387 if (cnt) {
5388 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5389 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5390 /* Log back into the node before sending the FARP. */
5391 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005392 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005393 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005394 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005395 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005396 }
5397
5398 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005399 if (fp->Rflags & FARP_REQUEST_FARPR)
5400 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005401 }
5402 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005403 return 0;
dea31012005-04-17 16:05:31 -05005404}
5405
James Smarte59058c2008-08-24 21:49:00 -04005406/**
James Smart3621a712009-04-06 18:47:14 -04005407 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005408 * @vport: pointer to a host virtual N_Port data structure.
5409 * @cmdiocb: pointer to lpfc command iocb data structure.
5410 * @ndlp: pointer to a node-list data structure.
5411 *
5412 * This routine processes Fibre Channel Address Resolution Protocol
5413 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5414 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5415 * the FARP response request.
5416 *
5417 * Return code
5418 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5419 **/
dea31012005-04-17 16:05:31 -05005420static int
James Smart2e0fef82007-06-17 19:56:36 -05005421lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5422 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005423{
5424 struct lpfc_dmabuf *pcmd;
5425 uint32_t *lp;
5426 IOCB_t *icmd;
5427 uint32_t cmd, did;
5428
5429 icmd = &cmdiocb->iocb;
5430 did = icmd->un.elsreq64.remoteID;
5431 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5432 lp = (uint32_t *) pcmd->virt;
5433
5434 cmd = *lp++;
5435 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005436 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5437 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005438 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005439 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005440
5441 return 0;
5442}
5443
James Smarte59058c2008-08-24 21:49:00 -04005444/**
James Smart3621a712009-04-06 18:47:14 -04005445 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005446 * @vport: pointer to a host virtual N_Port data structure.
5447 * @cmdiocb: pointer to lpfc command iocb data structure.
5448 * @fan_ndlp: pointer to a node-list data structure.
5449 *
5450 * This routine processes a Fabric Address Notification (FAN) IOCB
5451 * command received as an ELS unsolicited event. The FAN ELS command will
5452 * only be processed on a physical port (i.e., the @vport represents the
5453 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5454 * compared against those in the phba data structure. If any of those is
5455 * different, the lpfc_initial_flogi() routine is invoked to initialize
5456 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5457 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5458 * is invoked to register login to the fabric.
5459 *
5460 * Return code
5461 * 0 - Successfully processed fan iocb (currently always return 0).
5462 **/
dea31012005-04-17 16:05:31 -05005463static int
James Smart2e0fef82007-06-17 19:56:36 -05005464lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5465 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005466{
James Smart2e0fef82007-06-17 19:56:36 -05005467 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005468 uint32_t *lp;
5469 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005470
James Smart0d2b6b82008-06-14 22:52:47 -04005471 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5472 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5473 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005474 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005475 if ((vport == phba->pport) &&
5476 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005477 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005478 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005479 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005480 sizeof(struct lpfc_name)))) {
5481 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005482 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005483 } else {
5484 /* FAN verified - skip FLOGI */
5485 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005486 if (phba->sli_rev < LPFC_SLI_REV4)
5487 lpfc_issue_fabric_reglogin(vport);
5488 else
5489 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005490 }
dea31012005-04-17 16:05:31 -05005491 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005492 return 0;
dea31012005-04-17 16:05:31 -05005493}
5494
James Smarte59058c2008-08-24 21:49:00 -04005495/**
James Smart3621a712009-04-06 18:47:14 -04005496 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005497 * @ptr: holder for the timer function associated data.
5498 *
5499 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5500 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5501 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5502 * up the worker thread. It is for the worker thread to invoke the routine
5503 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5504 **/
dea31012005-04-17 16:05:31 -05005505void
5506lpfc_els_timeout(unsigned long ptr)
5507{
James Smart2e0fef82007-06-17 19:56:36 -05005508 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5509 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005510 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005511 unsigned long iflag;
5512
James Smart2e0fef82007-06-17 19:56:36 -05005513 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005514 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5515 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005516 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005517 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005518
James Smart5e9d9b82008-06-14 22:52:53 -04005519 if (!tmo_posted)
5520 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005521 return;
5522}
5523
James Smart2a9bf3d2010-06-07 15:24:45 -04005524
James Smarte59058c2008-08-24 21:49:00 -04005525/**
James Smart3621a712009-04-06 18:47:14 -04005526 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005527 * @vport: pointer to a virtual N_Port data structure.
5528 *
5529 * This routine is the actual handler function that processes an ELS timeout
5530 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5531 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5532 * invoking the lpfc_sli_issue_abort_iotag() routine.
5533 **/
dea31012005-04-17 16:05:31 -05005534void
James Smart2e0fef82007-06-17 19:56:36 -05005535lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005536{
James Smart2e0fef82007-06-17 19:56:36 -05005537 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005538 struct lpfc_sli_ring *pring;
5539 struct lpfc_iocbq *tmp_iocb, *piocb;
5540 IOCB_t *cmd = NULL;
5541 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005542 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005543 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005544 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005545 LIST_HEAD(txcmplq_completions);
5546 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005547
James Smart2a9bf3d2010-06-07 15:24:45 -04005548
dea31012005-04-17 16:05:31 -05005549 timeout = (uint32_t)(phba->fc_ratov << 1);
5550
5551 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005552
James Smart2a9bf3d2010-06-07 15:24:45 -04005553 spin_lock_irq(&phba->hbalock);
5554 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5555 spin_unlock_irq(&phba->hbalock);
5556
5557 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005558 cmd = &piocb->iocb;
5559
James Smart2e0fef82007-06-17 19:56:36 -05005560 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5561 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5562 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005563 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005564
5565 if (piocb->vport != vport)
5566 continue;
5567
dea31012005-04-17 16:05:31 -05005568 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005569 if (pcmd)
5570 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005571
James Smart92d7f7b2007-06-17 19:56:38 -05005572 if (els_command == ELS_CMD_FARP ||
5573 els_command == ELS_CMD_FARPR ||
5574 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005575 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005576
dea31012005-04-17 16:05:31 -05005577 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005578 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005579 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005580 else
dea31012005-04-17 16:05:31 -05005581 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005582 continue;
5583 }
5584
James Smart2e0fef82007-06-17 19:56:36 -05005585 remote_ID = 0xffffffff;
5586 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005587 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005588 else {
5589 struct lpfc_nodelist *ndlp;
5590 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005591 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005592 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005593 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005594 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005595 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005596 spin_lock_irq(&phba->hbalock);
5597 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005598 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005599
James Smart2a9bf3d2010-06-07 15:24:45 -04005600 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5601 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5602 "0127 ELS timeout Data: x%x x%x x%x "
5603 "x%x\n", els_command,
5604 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5605 spin_lock_irq(&phba->hbalock);
5606 list_del_init(&piocb->dlist);
5607 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5608 spin_unlock_irq(&phba->hbalock);
5609 }
5610
James Smart2e0fef82007-06-17 19:56:36 -05005611 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5612 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005613}
5614
James Smarte59058c2008-08-24 21:49:00 -04005615/**
James Smart3621a712009-04-06 18:47:14 -04005616 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005617 * @vport: pointer to a host virtual N_Port data structure.
5618 *
5619 * This routine is used to clean up all the outstanding ELS commands on a
5620 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5621 * routine. After that, it walks the ELS transmit queue to remove all the
5622 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5623 * the IOCBs with a non-NULL completion callback function, the callback
5624 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5625 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5626 * callback function, the IOCB will simply be released. Finally, it walks
5627 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5628 * completion queue IOCB that is associated with the @vport and is not
5629 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5630 * part of the discovery state machine) out to HBA by invoking the
5631 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5632 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5633 * the IOCBs are aborted when this function returns.
5634 **/
dea31012005-04-17 16:05:31 -05005635void
James Smart2e0fef82007-06-17 19:56:36 -05005636lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005637{
James Smart2534ba72007-04-25 09:52:20 -04005638 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005639 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005640 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005641 struct lpfc_iocbq *tmp_iocb, *piocb;
5642 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005643
5644 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005645
James Smart2e0fef82007-06-17 19:56:36 -05005646 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005647 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5648 cmd = &piocb->iocb;
5649
5650 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5651 continue;
5652 }
5653
5654 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005655 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5656 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5657 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5658 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005659 continue;
dea31012005-04-17 16:05:31 -05005660
James Smart2e0fef82007-06-17 19:56:36 -05005661 if (piocb->vport != vport)
5662 continue;
5663
James Smart2534ba72007-04-25 09:52:20 -04005664 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005665 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005666 }
5667
5668 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005669 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5670 continue;
5671 }
dea31012005-04-17 16:05:31 -05005672
James Smart2e0fef82007-06-17 19:56:36 -05005673 if (piocb->vport != vport)
5674 continue;
5675
James Smart07951072007-04-25 09:51:38 -04005676 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005677 }
James Smart2e0fef82007-06-17 19:56:36 -05005678 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005679
James Smarta257bf92009-04-06 18:48:10 -04005680 /* Cancell all the IOCBs from the completions list */
5681 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5682 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005683
dea31012005-04-17 16:05:31 -05005684 return;
5685}
5686
James Smarte59058c2008-08-24 21:49:00 -04005687/**
James Smart3621a712009-04-06 18:47:14 -04005688 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005689 * @phba: pointer to lpfc hba data structure.
5690 *
5691 * This routine is used to clean up all the outstanding ELS commands on a
5692 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5693 * routine. After that, it walks the ELS transmit queue to remove all the
5694 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5695 * the IOCBs with the completion callback function associated, the callback
5696 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5697 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5698 * callback function associated, the IOCB will simply be released. Finally,
5699 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5700 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5701 * management plane IOCBs that are not part of the discovery state machine)
5702 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5703 **/
James Smart549e55c2007-08-02 11:09:51 -04005704void
5705lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5706{
5707 LIST_HEAD(completions);
5708 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5709 struct lpfc_iocbq *tmp_iocb, *piocb;
5710 IOCB_t *cmd = NULL;
5711
5712 lpfc_fabric_abort_hba(phba);
5713 spin_lock_irq(&phba->hbalock);
5714 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5715 cmd = &piocb->iocb;
5716 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5717 continue;
5718 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5719 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5720 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5721 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5722 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5723 continue;
5724 list_move_tail(&piocb->list, &completions);
5725 pring->txq_cnt--;
5726 }
5727 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5728 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5729 continue;
5730 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5731 }
5732 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005733
5734 /* Cancel all the IOCBs from the completions list */
5735 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5736 IOERR_SLI_ABORTED);
5737
James Smart549e55c2007-08-02 11:09:51 -04005738 return;
5739}
5740
James Smarte59058c2008-08-24 21:49:00 -04005741/**
James Smart3621a712009-04-06 18:47:14 -04005742 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005743 * @phba: Pointer to hba context object.
5744 * @cmdiocbp: Pointer to command iocb which reported error.
5745 * @rspiocbp: Pointer to response iocb which reported error.
5746 *
5747 * This function sends an event when there is an ELS command
5748 * failure.
5749 **/
5750void
5751lpfc_send_els_failure_event(struct lpfc_hba *phba,
5752 struct lpfc_iocbq *cmdiocbp,
5753 struct lpfc_iocbq *rspiocbp)
5754{
5755 struct lpfc_vport *vport = cmdiocbp->vport;
5756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5757 struct lpfc_lsrjt_event lsrjt_event;
5758 struct lpfc_fabric_event_header fabric_event;
5759 struct ls_rjt stat;
5760 struct lpfc_nodelist *ndlp;
5761 uint32_t *pcmd;
5762
5763 ndlp = cmdiocbp->context1;
5764 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5765 return;
5766
5767 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5768 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5769 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5770 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5771 sizeof(struct lpfc_name));
5772 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5773 sizeof(struct lpfc_name));
5774 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5775 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005776 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005777 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5778 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5779 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5780 fc_host_post_vendor_event(shost,
5781 fc_get_event_number(),
5782 sizeof(lsrjt_event),
5783 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005784 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005785 return;
5786 }
5787 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5788 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5789 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5790 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5791 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5792 else
5793 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5794 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5795 sizeof(struct lpfc_name));
5796 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5797 sizeof(struct lpfc_name));
5798 fc_host_post_vendor_event(shost,
5799 fc_get_event_number(),
5800 sizeof(fabric_event),
5801 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005802 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005803 return;
5804 }
5805
5806}
5807
5808/**
James Smart3621a712009-04-06 18:47:14 -04005809 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005810 * @vport: Pointer to vport object.
5811 * @ndlp: Pointer FC node object.
5812 * @cmd: ELS command code.
5813 *
5814 * This function posts an event when there is an incoming
5815 * unsolicited ELS command.
5816 **/
5817static void
5818lpfc_send_els_event(struct lpfc_vport *vport,
5819 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005820 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005821{
James Smartddcc50f2008-12-04 22:38:46 -05005822 struct lpfc_els_event_header *els_data = NULL;
5823 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005824 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5825
James Smartddcc50f2008-12-04 22:38:46 -05005826 if (*payload == ELS_CMD_LOGO) {
5827 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5828 if (!logo_data) {
5829 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5830 "0148 Failed to allocate memory "
5831 "for LOGO event\n");
5832 return;
5833 }
5834 els_data = &logo_data->header;
5835 } else {
5836 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5837 GFP_KERNEL);
5838 if (!els_data) {
5839 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5840 "0149 Failed to allocate memory "
5841 "for ELS event\n");
5842 return;
5843 }
5844 }
5845 els_data->event_type = FC_REG_ELS_EVENT;
5846 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005847 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005848 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005849 break;
5850 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005851 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005852 break;
5853 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005854 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5855 break;
5856 case ELS_CMD_LOGO:
5857 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5858 /* Copy the WWPN in the LOGO payload */
5859 memcpy(logo_data->logo_wwpn, &payload[2],
5860 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005861 break;
5862 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005863 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005864 return;
5865 }
James Smartddcc50f2008-12-04 22:38:46 -05005866 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5867 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5868 if (*payload == ELS_CMD_LOGO) {
5869 fc_host_post_vendor_event(shost,
5870 fc_get_event_number(),
5871 sizeof(struct lpfc_logo_event),
5872 (char *)logo_data,
5873 LPFC_NL_VENDOR_ID);
5874 kfree(logo_data);
5875 } else {
5876 fc_host_post_vendor_event(shost,
5877 fc_get_event_number(),
5878 sizeof(struct lpfc_els_event_header),
5879 (char *)els_data,
5880 LPFC_NL_VENDOR_ID);
5881 kfree(els_data);
5882 }
James Smartea2151b2008-09-07 11:52:10 -04005883
5884 return;
5885}
5886
5887
5888/**
James Smart3621a712009-04-06 18:47:14 -04005889 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005890 * @phba: pointer to lpfc hba data structure.
5891 * @pring: pointer to a SLI ring.
5892 * @vport: pointer to a host virtual N_Port data structure.
5893 * @elsiocb: pointer to lpfc els command iocb data structure.
5894 *
5895 * This routine is used for processing the IOCB associated with a unsolicited
5896 * event. It first determines whether there is an existing ndlp that matches
5897 * the DID from the unsolicited IOCB. If not, it will create a new one with
5898 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5899 * IOCB is then used to invoke the proper routine and to set up proper state
5900 * of the discovery state machine.
5901 **/
James Smarted957682007-06-17 19:56:37 -05005902static void
5903lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005904 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005905{
James Smart87af33f2007-10-27 13:37:43 -04005906 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005907 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005908 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005909 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005910 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005911 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005912
James Smarte47c9092008-02-08 18:49:26 -05005913 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005914 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005915
dea31012005-04-17 16:05:31 -05005916 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005917 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5918 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005919 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005920 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005921
James Smart858c9f62007-06-17 19:56:39 -05005922 did = icmd->un.rcvels.remoteID;
5923 if (icmd->ulpStatus) {
5924 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5925 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5926 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005927 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005928 }
dea31012005-04-17 16:05:31 -05005929
5930 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005931 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005932 goto dropit;
dea31012005-04-17 16:05:31 -05005933
James Smartc8685952009-11-18 15:39:16 -05005934 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005935 if (vport->load_flag & FC_UNLOADING)
5936 goto dropit;
5937
James Smart2e0fef82007-06-17 19:56:36 -05005938 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005939 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005940 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005941 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005942 if (!ndlp)
dea31012005-04-17 16:05:31 -05005943 goto dropit;
dea31012005-04-17 16:05:31 -05005944
James Smart2e0fef82007-06-17 19:56:36 -05005945 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005946 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005947 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005948 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005949 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005950 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5951 ndlp = lpfc_enable_node(vport, ndlp,
5952 NLP_STE_UNUSED_NODE);
5953 if (!ndlp)
5954 goto dropit;
5955 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5956 newnode = 1;
5957 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5958 ndlp->nlp_type |= NLP_FABRIC;
5959 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5960 /* This is similar to the new node path */
5961 ndlp = lpfc_nlp_get(ndlp);
5962 if (!ndlp)
5963 goto dropit;
5964 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5965 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005966 }
dea31012005-04-17 16:05:31 -05005967
5968 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005969
James Smart329f9bc2007-04-25 09:53:01 -04005970 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005971 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005972
5973 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5974 cmd &= ELS_CMD_MASK;
5975 }
5976 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005977 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5978 "0112 ELS command x%x received from NPORT x%x "
5979 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005980 switch (cmd) {
5981 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005982 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5983 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5984 did, vport->port_state, ndlp->nlp_flag);
5985
dea31012005-04-17 16:05:31 -05005986 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005987 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5988
James Smartddcc50f2008-12-04 22:38:46 -05005989 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005990 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005991 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5992 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5993 rjt_err = LSRJT_UNABLE_TPC;
5994 break;
5995 }
5996 /* We get here, and drop thru, if we are PT2PT with
5997 * another NPort and the other side has initiated
5998 * the PLOGI before responding to our FLOGI.
5999 */
dea31012005-04-17 16:05:31 -05006000 }
James Smart87af33f2007-10-27 13:37:43 -04006001
6002 shost = lpfc_shost_from_vport(vport);
6003 spin_lock_irq(shost->host_lock);
6004 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6005 spin_unlock_irq(shost->host_lock);
6006
James Smart2e0fef82007-06-17 19:56:36 -05006007 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6008 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006009
dea31012005-04-17 16:05:31 -05006010 break;
6011 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006012 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6013 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6014 did, vport->port_state, ndlp->nlp_flag);
6015
dea31012005-04-17 16:05:31 -05006016 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006017 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006018 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006019 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006020 break;
6021 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006022 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6023 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6024 did, vport->port_state, ndlp->nlp_flag);
6025
dea31012005-04-17 16:05:31 -05006026 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006027 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006028 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006029 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006030 break;
6031 }
James Smart2e0fef82007-06-17 19:56:36 -05006032 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006033 break;
6034 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006035 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6036 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6037 did, vport->port_state, ndlp->nlp_flag);
6038
dea31012005-04-17 16:05:31 -05006039 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006040 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006041 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006042 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006043 break;
6044 }
James Smart2e0fef82007-06-17 19:56:36 -05006045 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006046 break;
6047 case ELS_CMD_RSCN:
6048 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006049 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006050 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006051 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006052 break;
6053 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006054 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6055 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6056 did, vport->port_state, ndlp->nlp_flag);
6057
James Smartddcc50f2008-12-04 22:38:46 -05006058 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006059 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006060 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006061 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006062 break;
6063 }
James Smart2e0fef82007-06-17 19:56:36 -05006064 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6065 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006066 break;
6067 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6069 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6070 did, vport->port_state, ndlp->nlp_flag);
6071
dea31012005-04-17 16:05:31 -05006072 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006073 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006074 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006075 break;
6076 }
James Smart2e0fef82007-06-17 19:56:36 -05006077 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6078 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006079 break;
6080 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006081 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6082 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6083 did, vport->port_state, ndlp->nlp_flag);
6084
dea31012005-04-17 16:05:31 -05006085 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006086 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006087 break;
6088 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006089 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6090 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6091 did, vport->port_state, ndlp->nlp_flag);
6092
dea31012005-04-17 16:05:31 -05006093 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006094 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006095 break;
6096 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006097 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6098 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6099 did, vport->port_state, ndlp->nlp_flag);
6100
dea31012005-04-17 16:05:31 -05006101 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006102 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006103 break;
dea31012005-04-17 16:05:31 -05006104 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006105 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6106 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6107 did, vport->port_state, ndlp->nlp_flag);
6108
dea31012005-04-17 16:05:31 -05006109 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006110 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006111 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006112 break;
6113 }
James Smart2e0fef82007-06-17 19:56:36 -05006114 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006115 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006116 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6118 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6119 did, vport->port_state, ndlp->nlp_flag);
6120
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006121 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006122 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006123 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006124 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006125 break;
James Smart12265f62010-10-22 11:05:53 -04006126 case ELS_CMD_RLS:
6127 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6128 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6129 did, vport->port_state, ndlp->nlp_flag);
6130
6131 phba->fc_stat.elsRcvRLS++;
6132 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6133 if (newnode)
6134 lpfc_nlp_put(ndlp);
6135 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006136 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6138 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6139 did, vport->port_state, ndlp->nlp_flag);
6140
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006141 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006142 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006143 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006144 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006145 break;
6146 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6148 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6149 did, vport->port_state, ndlp->nlp_flag);
6150
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006151 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006152 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006153 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006154 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006155 break;
dea31012005-04-17 16:05:31 -05006156 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006157 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6158 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6159 did, vport->port_state, ndlp->nlp_flag);
6160
dea31012005-04-17 16:05:31 -05006161 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006162 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006163 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006164 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006165 break;
James Smart12265f62010-10-22 11:05:53 -04006166 case ELS_CMD_RTV:
6167 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6168 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6169 did, vport->port_state, ndlp->nlp_flag);
6170 phba->fc_stat.elsRcvRTV++;
6171 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6172 if (newnode)
6173 lpfc_nlp_put(ndlp);
6174 break;
James Smart5ffc2662009-11-18 15:39:44 -05006175 case ELS_CMD_RRQ:
6176 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6177 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6178 did, vport->port_state, ndlp->nlp_flag);
6179
6180 phba->fc_stat.elsRcvRRQ++;
6181 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6182 if (newnode)
6183 lpfc_nlp_put(ndlp);
6184 break;
James Smart12265f62010-10-22 11:05:53 -04006185 case ELS_CMD_ECHO:
6186 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6187 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6188 did, vport->port_state, ndlp->nlp_flag);
6189
6190 phba->fc_stat.elsRcvECHO++;
6191 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6192 if (newnode)
6193 lpfc_nlp_put(ndlp);
6194 break;
dea31012005-04-17 16:05:31 -05006195 default:
James Smart858c9f62007-06-17 19:56:39 -05006196 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6197 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6198 cmd, did, vport->port_state);
6199
dea31012005-04-17 16:05:31 -05006200 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05006201 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05006202
6203 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006204 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6205 "0115 Unknown ELS command x%x "
6206 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006207 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006208 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006209 break;
6210 }
6211
6212 /* check if need to LS_RJT received ELS cmd */
6213 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006214 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006215 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006216 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006217 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6218 NULL);
dea31012005-04-17 16:05:31 -05006219 }
6220
James Smartd7c255b2008-08-24 21:50:00 -04006221 lpfc_nlp_put(elsiocb->context1);
6222 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006223 return;
6224
6225dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006226 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006227 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6228 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006229 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006230 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006231 phba->fc_stat.elsRcvDrop++;
6232}
6233
James Smarte59058c2008-08-24 21:49:00 -04006234/**
James Smart3621a712009-04-06 18:47:14 -04006235 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006236 * @phba: pointer to lpfc hba data structure.
6237 * @vpi: host virtual N_Port identifier.
6238 *
6239 * This routine finds a vport on a HBA (referred by @phba) through a
6240 * @vpi. The function walks the HBA's vport list and returns the address
6241 * of the vport with the matching @vpi.
6242 *
6243 * Return code
6244 * NULL - No vport with the matching @vpi found
6245 * Otherwise - Address to the vport with the matching @vpi.
6246 **/
James Smart6669f9b2009-10-02 15:16:45 -04006247struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006248lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6249{
6250 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006251 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006252
James Smart549e55c2007-08-02 11:09:51 -04006253 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006254 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006255 if (vport->vpi == vpi) {
6256 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006257 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006258 }
James Smart92d7f7b2007-06-17 19:56:38 -05006259 }
James Smart549e55c2007-08-02 11:09:51 -04006260 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006261 return NULL;
6262}
James Smarted957682007-06-17 19:56:37 -05006263
James Smarte59058c2008-08-24 21:49:00 -04006264/**
James Smart3621a712009-04-06 18:47:14 -04006265 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006266 * @phba: pointer to lpfc hba data structure.
6267 * @pring: pointer to a SLI ring.
6268 * @elsiocb: pointer to lpfc els iocb data structure.
6269 *
6270 * This routine is used to process an unsolicited event received from a SLI
6271 * (Service Level Interface) ring. The actual processing of the data buffer
6272 * associated with the unsolicited event is done by invoking the routine
6273 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6274 * SLI ring on which the unsolicited event was received.
6275 **/
James Smarted957682007-06-17 19:56:37 -05006276void
6277lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6278 struct lpfc_iocbq *elsiocb)
6279{
6280 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006281 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006282 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006283 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6284 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006285
James Smartd7c255b2008-08-24 21:50:00 -04006286 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006287 elsiocb->context2 = NULL;
6288 elsiocb->context3 = NULL;
6289
6290 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6291 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6292 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6293 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006294 phba->fc_stat.NoRcvBuf++;
6295 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006296 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006297 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006298 return;
6299 }
6300
James Smart92d7f7b2007-06-17 19:56:38 -05006301 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6302 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6303 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6304 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6305 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006306 else
6307 vport = lpfc_find_vport_by_vpid(phba,
6308 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006309 }
James Smart7f5f3d02008-02-08 18:50:14 -05006310 /* If there are no BDEs associated
6311 * with this IOCB, there is nothing to do.
6312 */
James Smarted957682007-06-17 19:56:37 -05006313 if (icmd->ulpBdeCount == 0)
6314 return;
6315
James Smart7f5f3d02008-02-08 18:50:14 -05006316 /* type of ELS cmd is first 32bit word
6317 * in packet
6318 */
James Smarted957682007-06-17 19:56:37 -05006319 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006320 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006321 } else {
6322 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6323 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006324 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6325 paddr);
James Smarted957682007-06-17 19:56:37 -05006326 }
6327
James Smart92d7f7b2007-06-17 19:56:38 -05006328 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6329 /*
6330 * The different unsolicited event handlers would tell us
6331 * if they are done with "mp" by setting context2 to NULL.
6332 */
dea31012005-04-17 16:05:31 -05006333 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006334 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6335 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006336 }
James Smarted957682007-06-17 19:56:37 -05006337
6338 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006339 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006340 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006341 elsiocb->context2 = bdeBuf2;
6342 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006343 /* free mp if we are done with it */
6344 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006345 lpfc_in_buf_free(phba, elsiocb->context2);
6346 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006347 }
dea31012005-04-17 16:05:31 -05006348 }
dea31012005-04-17 16:05:31 -05006349}
James Smart92d7f7b2007-06-17 19:56:38 -05006350
James Smarte59058c2008-08-24 21:49:00 -04006351/**
James Smart3621a712009-04-06 18:47:14 -04006352 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006353 * @phba: pointer to lpfc hba data structure.
6354 * @vport: pointer to a virtual N_Port data structure.
6355 *
6356 * This routine issues a Port Login (PLOGI) to the Name Server with
6357 * State Change Request (SCR) for a @vport. This routine will create an
6358 * ndlp for the Name Server associated to the @vport if such node does
6359 * not already exist. The PLOGI to Name Server is issued by invoking the
6360 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6361 * (FDMI) is configured to the @vport, a FDMI node will be created and
6362 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6363 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006364void
6365lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6366{
6367 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6368
6369 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6370 if (!ndlp) {
6371 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6372 if (!ndlp) {
6373 if (phba->fc_topology == TOPOLOGY_LOOP) {
6374 lpfc_disc_start(vport);
6375 return;
6376 }
6377 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006378 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6379 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006380 return;
6381 }
6382 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006383 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6384 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6385 if (!ndlp) {
6386 if (phba->fc_topology == TOPOLOGY_LOOP) {
6387 lpfc_disc_start(vport);
6388 return;
6389 }
6390 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6391 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6392 "0348 NameServer login: node freed\n");
6393 return;
6394 }
James Smart92d7f7b2007-06-17 19:56:38 -05006395 }
James Smart58da1ff2008-04-07 10:15:56 -04006396 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006397
6398 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6399
6400 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6401 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006402 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6403 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006404 return;
6405 }
6406
James Smart3de2a652007-08-02 11:09:59 -04006407 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006408 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6409 GFP_KERNEL);
6410 if (ndlp_fdmi) {
6411 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6412 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006413 lpfc_nlp_set_state(vport, ndlp_fdmi,
6414 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006415 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6416 0);
6417 }
6418 }
6419 return;
6420}
6421
James Smarte59058c2008-08-24 21:49:00 -04006422/**
James Smart3621a712009-04-06 18:47:14 -04006423 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006424 * @phba: pointer to lpfc hba data structure.
6425 * @pmb: pointer to the driver internal queue element for mailbox command.
6426 *
6427 * This routine is the completion callback function to register new vport
6428 * mailbox command. If the new vport mailbox command completes successfully,
6429 * the fabric registration login shall be performed on physical port (the
6430 * new vport created is actually a physical port, with VPI 0) or the port
6431 * login to Name Server for State Change Request (SCR) will be performed
6432 * on virtual port (real virtual port, with VPI greater than 0).
6433 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006434static void
6435lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6436{
6437 struct lpfc_vport *vport = pmb->vport;
6438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6439 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006440 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006441 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006442
James Smart09372822008-01-11 01:52:54 -05006443 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006444 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006445 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006446
6447 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006448 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006449 "0915 Register VPI failed : Status: x%x"
6450 " upd bit: x%x \n", mb->mbxStatus,
6451 mb->un.varRegVpi.upd);
6452 if (phba->sli_rev == LPFC_SLI_REV4 &&
6453 mb->un.varRegVpi.upd)
6454 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006455
6456 switch (mb->mbxStatus) {
6457 case 0x11: /* unsupported feature */
6458 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006459 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006460 /* giving up on vport registration */
6461 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6462 spin_lock_irq(shost->host_lock);
6463 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6464 spin_unlock_irq(shost->host_lock);
6465 lpfc_can_disctmo(vport);
6466 break;
James Smart695a8142010-01-26 23:08:03 -05006467 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6468 case 0x20:
6469 spin_lock_irq(shost->host_lock);
6470 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6471 spin_unlock_irq(shost->host_lock);
6472 lpfc_init_vpi(phba, pmb, vport->vpi);
6473 pmb->vport = vport;
6474 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6475 rc = lpfc_sli_issue_mbox(phba, pmb,
6476 MBX_NOWAIT);
6477 if (rc == MBX_NOT_FINISHED) {
6478 lpfc_printf_vlog(vport,
6479 KERN_ERR, LOG_MBOX,
6480 "2732 Failed to issue INIT_VPI"
6481 " mailbox command\n");
6482 } else {
6483 lpfc_nlp_put(ndlp);
6484 return;
6485 }
6486
James Smart92d7f7b2007-06-17 19:56:38 -05006487 default:
6488 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006489 if (phba->sli_rev == LPFC_SLI_REV4)
6490 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006491 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006492 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006493 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006494 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006495 if (vport->port_type == LPFC_PHYSICAL_PORT
6496 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006497 lpfc_initial_flogi(vport);
6498 else
6499 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006500 break;
6501 }
James Smart92d7f7b2007-06-17 19:56:38 -05006502 } else {
James Smart695a8142010-01-26 23:08:03 -05006503 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006504 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006505 spin_unlock_irq(shost->host_lock);
6506 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006507 if (phba->sli_rev < LPFC_SLI_REV4)
6508 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006509 else {
James Smartfc2b9892010-02-26 14:15:29 -05006510 /*
6511 * If the physical port is instantiated using
6512 * FDISC, do not start vport discovery.
6513 */
6514 if (vport->port_state != LPFC_FDISC)
6515 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006516 lpfc_do_scr_ns_plogi(phba, vport);
6517 }
6518 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006519 lpfc_do_scr_ns_plogi(phba, vport);
6520 }
James Smart38b92ef2010-08-04 16:11:39 -04006521mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006522 /* Now, we decrement the ndlp reference count held for this
6523 * callback function
6524 */
6525 lpfc_nlp_put(ndlp);
6526
James Smart92d7f7b2007-06-17 19:56:38 -05006527 mempool_free(pmb, phba->mbox_mem_pool);
6528 return;
6529}
6530
James Smarte59058c2008-08-24 21:49:00 -04006531/**
James Smart3621a712009-04-06 18:47:14 -04006532 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006533 * @phba: pointer to lpfc hba data structure.
6534 * @vport: pointer to a host virtual N_Port data structure.
6535 * @ndlp: pointer to a node-list data structure.
6536 *
6537 * This routine registers the @vport as a new virtual port with a HBA.
6538 * It is done through a registering vpi mailbox command.
6539 **/
James Smart695a8142010-01-26 23:08:03 -05006540void
James Smart92d7f7b2007-06-17 19:56:38 -05006541lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6542 struct lpfc_nodelist *ndlp)
6543{
James Smart09372822008-01-11 01:52:54 -05006544 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006545 LPFC_MBOXQ_t *mbox;
6546
6547 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6548 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006549 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006550 mbox->vport = vport;
6551 mbox->context2 = lpfc_nlp_get(ndlp);
6552 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006553 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006554 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006555 /* mailbox command not success, decrement ndlp
6556 * reference count for this command
6557 */
6558 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006559 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006560
James Smarte8b62012007-08-02 11:10:09 -04006561 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6562 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006563 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006564 }
6565 } else {
James Smarte8b62012007-08-02 11:10:09 -04006566 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6567 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006568 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006569 }
James Smartfa4066b2008-01-11 01:53:27 -05006570 return;
6571
6572mbox_err_exit:
6573 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6574 spin_lock_irq(shost->host_lock);
6575 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6576 spin_unlock_irq(shost->host_lock);
6577 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006578}
6579
James Smarte59058c2008-08-24 21:49:00 -04006580/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006581 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006582 * @phba: pointer to lpfc hba data structure.
6583 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006584 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006585 **/
6586void
James Smart0c9ab6f2010-02-26 14:15:57 -05006587lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006588{
6589 struct lpfc_vport **vports;
6590 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006591 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006592 int i;
James Smart695a8142010-01-26 23:08:03 -05006593
6594 /* Treat this failure as linkdown for all vports */
6595 link_state = phba->link_state;
6596 lpfc_linkdown(phba);
6597 phba->link_state = link_state;
6598
6599 vports = lpfc_create_vport_work_array(phba);
6600
6601 if (vports) {
6602 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6603 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6604 if (ndlp)
6605 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6606 lpfc_els_flush_cmd(vports[i]);
6607 }
6608 lpfc_destroy_vport_work_array(phba, vports);
6609 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006610}
6611
6612/**
6613 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6614 * @phba: pointer to lpfc hba data structure.
6615 *
6616 * This routine abort all pending discovery commands and
6617 * start a timer to retry FLOGI for the physical port
6618 * discovery.
6619 **/
6620void
6621lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6622{
6623 struct lpfc_nodelist *ndlp;
6624 struct Scsi_Host *shost;
6625
6626 /* Cancel the all vports retry delay retry timers */
6627 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006628
6629 /* If fabric require FLOGI, then re-instantiate physical login */
6630 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6631 if (!ndlp)
6632 return;
6633
James Smart695a8142010-01-26 23:08:03 -05006634 shost = lpfc_shost_from_vport(phba->pport);
6635 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6636 spin_lock_irq(shost->host_lock);
6637 ndlp->nlp_flag |= NLP_DELAY_TMO;
6638 spin_unlock_irq(shost->host_lock);
6639 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6640 phba->pport->port_state = LPFC_FLOGI;
6641 return;
6642}
6643
6644/**
6645 * lpfc_fabric_login_reqd - Check if FLOGI required.
6646 * @phba: pointer to lpfc hba data structure.
6647 * @cmdiocb: pointer to FDISC command iocb.
6648 * @rspiocb: pointer to FDISC response iocb.
6649 *
6650 * This routine checks if a FLOGI is reguired for FDISC
6651 * to succeed.
6652 **/
6653static int
6654lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6655 struct lpfc_iocbq *cmdiocb,
6656 struct lpfc_iocbq *rspiocb)
6657{
6658
6659 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6660 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6661 return 0;
6662 else
6663 return 1;
6664}
6665
6666/**
James Smart3621a712009-04-06 18:47:14 -04006667 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006668 * @phba: pointer to lpfc hba data structure.
6669 * @cmdiocb: pointer to lpfc command iocb data structure.
6670 * @rspiocb: pointer to lpfc response iocb data structure.
6671 *
6672 * This routine is the completion callback function to a Fabric Discover
6673 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6674 * single threaded, each FDISC completion callback function will reset
6675 * the discovery timer for all vports such that the timers will not get
6676 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6677 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6678 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6679 * assigned to the vport has been changed with the completion of the FDISC
6680 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6681 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6682 * routine is invoked to register new vport with the HBA. Otherwise, the
6683 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6684 * Server for State Change Request (SCR).
6685 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006686static void
6687lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6688 struct lpfc_iocbq *rspiocb)
6689{
6690 struct lpfc_vport *vport = cmdiocb->vport;
6691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6692 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6693 struct lpfc_nodelist *np;
6694 struct lpfc_nodelist *next_np;
6695 IOCB_t *irsp = &rspiocb->iocb;
6696 struct lpfc_iocbq *piocb;
6697
James Smarte8b62012007-08-02 11:10:09 -04006698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6699 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6700 irsp->ulpStatus, irsp->un.ulpWord[4],
6701 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006702 /* Since all FDISCs are being single threaded, we
6703 * must reset the discovery timer for ALL vports
6704 * waiting to send FDISC when one completes.
6705 */
6706 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6707 lpfc_set_disctmo(piocb->vport);
6708 }
6709
James Smart858c9f62007-06-17 19:56:39 -05006710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6711 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6712 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6713
James Smart92d7f7b2007-06-17 19:56:38 -05006714 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006715
6716 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6717 lpfc_retry_pport_discovery(phba);
6718 goto out;
6719 }
6720
James Smart92d7f7b2007-06-17 19:56:38 -05006721 /* Check for retry */
6722 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6723 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006724 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006725 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006726 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006727 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006728 goto fdisc_failed;
6729 }
James Smartd7c255b2008-08-24 21:50:00 -04006730 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006731 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006732 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006733 vport->fc_flag |= FC_FABRIC;
6734 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6735 vport->fc_flag |= FC_PUBLIC_LOOP;
6736 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006737
James Smartd7c255b2008-08-24 21:50:00 -04006738 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6739 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6740 if ((vport->fc_prevDID != vport->fc_myDID) &&
6741 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6742 /* If our NportID changed, we need to ensure all
6743 * remaining NPORTs get unreg_login'ed so we can
6744 * issue unreg_vpi.
6745 */
6746 list_for_each_entry_safe(np, next_np,
6747 &vport->fc_nodes, nlp_listp) {
6748 if (!NLP_CHK_NODE_ACT(ndlp) ||
6749 (np->nlp_state != NLP_STE_NPR_NODE) ||
6750 !(np->nlp_flag & NLP_NPR_ADISC))
6751 continue;
James Smart09372822008-01-11 01:52:54 -05006752 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006753 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006754 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006755 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006756 }
James Smart78730cf2010-04-06 15:06:30 -04006757 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04006758
6759 if (phba->sli_rev == LPFC_SLI_REV4)
6760 lpfc_sli4_unreg_all_rpis(vport);
6761
James Smartd7c255b2008-08-24 21:50:00 -04006762 lpfc_mbx_unreg_vpi(vport);
6763 spin_lock_irq(shost->host_lock);
6764 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006765 if (phba->sli_rev == LPFC_SLI_REV4)
6766 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006767 else
6768 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006769 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04006770 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6771 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6772 /*
6773 * Driver needs to re-reg VPI in order for f/w
6774 * to update the MAC address.
6775 */
6776 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04006777 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006778 }
6779
James Smartecfd03c2010-02-12 14:41:27 -05006780 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6781 lpfc_issue_init_vpi(vport);
6782 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006783 lpfc_register_new_vport(phba, vport, ndlp);
6784 else
6785 lpfc_do_scr_ns_plogi(phba, vport);
6786 goto out;
6787fdisc_failed:
6788 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6789 /* Cancel discovery timer */
6790 lpfc_can_disctmo(vport);
6791 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006792out:
6793 lpfc_els_free_iocb(phba, cmdiocb);
6794}
6795
James Smarte59058c2008-08-24 21:49:00 -04006796/**
James Smart3621a712009-04-06 18:47:14 -04006797 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006798 * @vport: pointer to a virtual N_Port data structure.
6799 * @ndlp: pointer to a node-list data structure.
6800 * @retry: number of retries to the command IOCB.
6801 *
6802 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6803 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6804 * routine to issue the IOCB, which makes sure only one outstanding fabric
6805 * IOCB will be sent off HBA at any given time.
6806 *
6807 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6808 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6809 * will be stored into the context1 field of the IOCB for the completion
6810 * callback function to the FDISC ELS command.
6811 *
6812 * Return code
6813 * 0 - Successfully issued fdisc iocb command
6814 * 1 - Failed to issue fdisc iocb command
6815 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006816static int
James Smart92d7f7b2007-06-17 19:56:38 -05006817lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6818 uint8_t retry)
6819{
6820 struct lpfc_hba *phba = vport->phba;
6821 IOCB_t *icmd;
6822 struct lpfc_iocbq *elsiocb;
6823 struct serv_parm *sp;
6824 uint8_t *pcmd;
6825 uint16_t cmdsize;
6826 int did = ndlp->nlp_DID;
6827 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006828
James Smart5ffc2662009-11-18 15:39:44 -05006829 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006830 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6831 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6832 ELS_CMD_FDISC);
6833 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006834 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006835 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6836 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006837 return 1;
6838 }
6839
6840 icmd = &elsiocb->iocb;
6841 icmd->un.elsreq64.myID = 0;
6842 icmd->un.elsreq64.fl = 1;
6843
James Smartf1126682009-06-10 17:22:44 -04006844 if (phba->sli_rev == LPFC_SLI_REV4) {
6845 /* FDISC needs to be 1 for WQE VPI */
6846 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6847 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6848 /* Set the ulpContext to the vpi */
6849 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6850 } else {
6851 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6852 icmd->ulpCt_h = 1;
6853 icmd->ulpCt_l = 0;
6854 }
James Smart92d7f7b2007-06-17 19:56:38 -05006855
6856 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6857 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6858 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6859 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6860 sp = (struct serv_parm *) pcmd;
6861 /* Setup CSPs accordingly for Fabric */
6862 sp->cmn.e_d_tov = 0;
6863 sp->cmn.w2.r_a_tov = 0;
6864 sp->cls1.classValid = 0;
6865 sp->cls2.seqDelivery = 1;
6866 sp->cls3.seqDelivery = 1;
6867
6868 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6869 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6870 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6871 pcmd += sizeof(uint32_t); /* Port Name */
6872 memcpy(pcmd, &vport->fc_portname, 8);
6873 pcmd += sizeof(uint32_t); /* Node Name */
6874 pcmd += sizeof(uint32_t); /* Node Name */
6875 memcpy(pcmd, &vport->fc_nodename, 8);
6876
6877 lpfc_set_disctmo(vport);
6878
6879 phba->fc_stat.elsXmitFDISC++;
6880 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6881
James Smart858c9f62007-06-17 19:56:39 -05006882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6883 "Issue FDISC: did:x%x",
6884 did, 0, 0);
6885
James Smart92d7f7b2007-06-17 19:56:38 -05006886 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6887 if (rc == IOCB_ERROR) {
6888 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006889 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006890 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6891 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006892 return 1;
6893 }
6894 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006895 return 0;
6896}
6897
James Smarte59058c2008-08-24 21:49:00 -04006898/**
James Smart3621a712009-04-06 18:47:14 -04006899 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006900 * @phba: pointer to lpfc hba data structure.
6901 * @cmdiocb: pointer to lpfc command iocb data structure.
6902 * @rspiocb: pointer to lpfc response iocb data structure.
6903 *
6904 * This routine is the completion callback function to the issuing of a LOGO
6905 * ELS command off a vport. It frees the command IOCB and then decrement the
6906 * reference count held on ndlp for this completion function, indicating that
6907 * the reference to the ndlp is no long needed. Note that the
6908 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6909 * callback function and an additional explicit ndlp reference decrementation
6910 * will trigger the actual release of the ndlp.
6911 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006912static void
6913lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6914 struct lpfc_iocbq *rspiocb)
6915{
6916 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006917 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006918 struct lpfc_nodelist *ndlp;
6919 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006920
6921 irsp = &rspiocb->iocb;
6922 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6923 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6924 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006925
6926 lpfc_els_free_iocb(phba, cmdiocb);
6927 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006928
6929 /* Trigger the release of the ndlp after logo */
6930 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006931}
6932
James Smarte59058c2008-08-24 21:49:00 -04006933/**
James Smart3621a712009-04-06 18:47:14 -04006934 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006935 * @vport: pointer to a virtual N_Port data structure.
6936 * @ndlp: pointer to a node-list data structure.
6937 *
6938 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6939 *
6940 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6941 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6942 * will be stored into the context1 field of the IOCB for the completion
6943 * callback function to the LOGO ELS command.
6944 *
6945 * Return codes
6946 * 0 - Successfully issued logo off the @vport
6947 * 1 - Failed to issue logo off the @vport
6948 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006949int
6950lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6951{
6952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6953 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006954 IOCB_t *icmd;
6955 struct lpfc_iocbq *elsiocb;
6956 uint8_t *pcmd;
6957 uint16_t cmdsize;
6958
6959 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6960 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6961 ELS_CMD_LOGO);
6962 if (!elsiocb)
6963 return 1;
6964
6965 icmd = &elsiocb->iocb;
6966 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6967 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6968 pcmd += sizeof(uint32_t);
6969
6970 /* Fill in LOGO payload */
6971 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6972 pcmd += sizeof(uint32_t);
6973 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6974
James Smart858c9f62007-06-17 19:56:39 -05006975 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6976 "Issue LOGO npiv did:x%x flg:x%x",
6977 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6978
James Smart92d7f7b2007-06-17 19:56:38 -05006979 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6980 spin_lock_irq(shost->host_lock);
6981 ndlp->nlp_flag |= NLP_LOGO_SND;
6982 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006983 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6984 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006985 spin_lock_irq(shost->host_lock);
6986 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6987 spin_unlock_irq(shost->host_lock);
6988 lpfc_els_free_iocb(phba, elsiocb);
6989 return 1;
6990 }
6991 return 0;
6992}
6993
James Smarte59058c2008-08-24 21:49:00 -04006994/**
James Smart3621a712009-04-06 18:47:14 -04006995 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006996 * @ptr: holder for the timer function associated data.
6997 *
6998 * This routine is invoked by the fabric iocb block timer after
6999 * timeout. It posts the fabric iocb block timeout event by setting the
7000 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7001 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7002 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7003 * posted event WORKER_FABRIC_BLOCK_TMO.
7004 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007005void
7006lpfc_fabric_block_timeout(unsigned long ptr)
7007{
7008 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7009 unsigned long iflags;
7010 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007011
James Smart92d7f7b2007-06-17 19:56:38 -05007012 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7013 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7014 if (!tmo_posted)
7015 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7016 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7017
James Smart5e9d9b82008-06-14 22:52:53 -04007018 if (!tmo_posted)
7019 lpfc_worker_wake_up(phba);
7020 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007021}
7022
James Smarte59058c2008-08-24 21:49:00 -04007023/**
James Smart3621a712009-04-06 18:47:14 -04007024 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007025 * @phba: pointer to lpfc hba data structure.
7026 *
7027 * This routine issues one fabric iocb from the driver internal list to
7028 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7029 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7030 * remove one pending fabric iocb from the driver internal list and invokes
7031 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7032 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007033static void
7034lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7035{
7036 struct lpfc_iocbq *iocb;
7037 unsigned long iflags;
7038 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007039 IOCB_t *cmd;
7040
7041repeat:
7042 iocb = NULL;
7043 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007044 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007045 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7046 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7047 list);
7048 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007049 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007050 atomic_inc(&phba->fabric_iocb_count);
7051 }
7052 spin_unlock_irqrestore(&phba->hbalock, iflags);
7053 if (iocb) {
7054 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7055 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7056 iocb->iocb_flag |= LPFC_IO_FABRIC;
7057
James Smart858c9f62007-06-17 19:56:39 -05007058 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7059 "Fabric sched1: ste:x%x",
7060 iocb->vport->port_state, 0, 0);
7061
James Smart3772a992009-05-22 14:50:54 -04007062 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007063
7064 if (ret == IOCB_ERROR) {
7065 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7066 iocb->fabric_iocb_cmpl = NULL;
7067 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7068 cmd = &iocb->iocb;
7069 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7070 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7071 iocb->iocb_cmpl(phba, iocb, iocb);
7072
7073 atomic_dec(&phba->fabric_iocb_count);
7074 goto repeat;
7075 }
7076 }
7077
7078 return;
7079}
7080
James Smarte59058c2008-08-24 21:49:00 -04007081/**
James Smart3621a712009-04-06 18:47:14 -04007082 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007083 * @phba: pointer to lpfc hba data structure.
7084 *
7085 * This routine unblocks the issuing fabric iocb command. The function
7086 * will clear the fabric iocb block bit and then invoke the routine
7087 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7088 * from the driver internal fabric iocb list.
7089 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007090void
7091lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7092{
7093 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7094
7095 lpfc_resume_fabric_iocbs(phba);
7096 return;
7097}
7098
James Smarte59058c2008-08-24 21:49:00 -04007099/**
James Smart3621a712009-04-06 18:47:14 -04007100 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007101 * @phba: pointer to lpfc hba data structure.
7102 *
7103 * This routine blocks the issuing fabric iocb for a specified amount of
7104 * time (currently 100 ms). This is done by set the fabric iocb block bit
7105 * and set up a timeout timer for 100ms. When the block bit is set, no more
7106 * fabric iocb will be issued out of the HBA.
7107 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007108static void
7109lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7110{
7111 int blocked;
7112
7113 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007114 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007115 if (!blocked)
7116 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7117
7118 return;
7119}
7120
James Smarte59058c2008-08-24 21:49:00 -04007121/**
James Smart3621a712009-04-06 18:47:14 -04007122 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007123 * @phba: pointer to lpfc hba data structure.
7124 * @cmdiocb: pointer to lpfc command iocb data structure.
7125 * @rspiocb: pointer to lpfc response iocb data structure.
7126 *
7127 * This routine is the callback function that is put to the fabric iocb's
7128 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7129 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7130 * function first restores and invokes the original iocb's callback function
7131 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7132 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7133 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007134static void
7135lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7136 struct lpfc_iocbq *rspiocb)
7137{
7138 struct ls_rjt stat;
7139
7140 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7141 BUG();
7142
7143 switch (rspiocb->iocb.ulpStatus) {
7144 case IOSTAT_NPORT_RJT:
7145 case IOSTAT_FABRIC_RJT:
7146 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7147 lpfc_block_fabric_iocbs(phba);
7148 }
7149 break;
7150
7151 case IOSTAT_NPORT_BSY:
7152 case IOSTAT_FABRIC_BSY:
7153 lpfc_block_fabric_iocbs(phba);
7154 break;
7155
7156 case IOSTAT_LS_RJT:
7157 stat.un.lsRjtError =
7158 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7159 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7160 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7161 lpfc_block_fabric_iocbs(phba);
7162 break;
7163 }
7164
7165 if (atomic_read(&phba->fabric_iocb_count) == 0)
7166 BUG();
7167
7168 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7169 cmdiocb->fabric_iocb_cmpl = NULL;
7170 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7171 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7172
7173 atomic_dec(&phba->fabric_iocb_count);
7174 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007175 /* Post any pending iocbs to HBA */
7176 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007177 }
7178}
7179
James Smarte59058c2008-08-24 21:49:00 -04007180/**
James Smart3621a712009-04-06 18:47:14 -04007181 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007182 * @phba: pointer to lpfc hba data structure.
7183 * @iocb: pointer to lpfc command iocb data structure.
7184 *
7185 * This routine is used as the top-level API for issuing a fabric iocb command
7186 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7187 * function makes sure that only one fabric bound iocb will be outstanding at
7188 * any given time. As such, this function will first check to see whether there
7189 * is already an outstanding fabric iocb on the wire. If so, it will put the
7190 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7191 * issued later. Otherwise, it will issue the iocb on the wire and update the
7192 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7193 *
7194 * Note, this implementation has a potential sending out fabric IOCBs out of
7195 * order. The problem is caused by the construction of the "ready" boolen does
7196 * not include the condition that the internal fabric IOCB list is empty. As
7197 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7198 * ahead of the fabric IOCBs in the internal list.
7199 *
7200 * Return code
7201 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7202 * IOCB_ERROR - failed to issue fabric iocb
7203 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007204static int
James Smart92d7f7b2007-06-17 19:56:38 -05007205lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7206{
7207 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007208 int ready;
7209 int ret;
7210
7211 if (atomic_read(&phba->fabric_iocb_count) > 1)
7212 BUG();
7213
7214 spin_lock_irqsave(&phba->hbalock, iflags);
7215 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7216 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7217
James Smart7f5f3d02008-02-08 18:50:14 -05007218 if (ready)
7219 /* Increment fabric iocb count to hold the position */
7220 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007221 spin_unlock_irqrestore(&phba->hbalock, iflags);
7222 if (ready) {
7223 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7224 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7225 iocb->iocb_flag |= LPFC_IO_FABRIC;
7226
James Smart858c9f62007-06-17 19:56:39 -05007227 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7228 "Fabric sched2: ste:x%x",
7229 iocb->vport->port_state, 0, 0);
7230
James Smart3772a992009-05-22 14:50:54 -04007231 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007232
7233 if (ret == IOCB_ERROR) {
7234 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7235 iocb->fabric_iocb_cmpl = NULL;
7236 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7237 atomic_dec(&phba->fabric_iocb_count);
7238 }
7239 } else {
7240 spin_lock_irqsave(&phba->hbalock, iflags);
7241 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7242 spin_unlock_irqrestore(&phba->hbalock, iflags);
7243 ret = IOCB_SUCCESS;
7244 }
7245 return ret;
7246}
7247
James Smarte59058c2008-08-24 21:49:00 -04007248/**
James Smart3621a712009-04-06 18:47:14 -04007249 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007250 * @vport: pointer to a virtual N_Port data structure.
7251 *
7252 * This routine aborts all the IOCBs associated with a @vport from the
7253 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7254 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7255 * list, removes each IOCB associated with the @vport off the list, set the
7256 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7257 * associated with the IOCB.
7258 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007259static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007260{
7261 LIST_HEAD(completions);
7262 struct lpfc_hba *phba = vport->phba;
7263 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007264
7265 spin_lock_irq(&phba->hbalock);
7266 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7267 list) {
7268
7269 if (piocb->vport != vport)
7270 continue;
7271
7272 list_move_tail(&piocb->list, &completions);
7273 }
7274 spin_unlock_irq(&phba->hbalock);
7275
James Smarta257bf92009-04-06 18:48:10 -04007276 /* Cancel all the IOCBs from the completions list */
7277 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7278 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007279}
7280
James Smarte59058c2008-08-24 21:49:00 -04007281/**
James Smart3621a712009-04-06 18:47:14 -04007282 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007283 * @ndlp: pointer to a node-list data structure.
7284 *
7285 * This routine aborts all the IOCBs associated with an @ndlp from the
7286 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7287 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7288 * list, removes each IOCB associated with the @ndlp off the list, set the
7289 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7290 * associated with the IOCB.
7291 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007292void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7293{
7294 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007295 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007296 struct lpfc_iocbq *tmp_iocb, *piocb;
7297 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007298
7299 spin_lock_irq(&phba->hbalock);
7300 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7301 list) {
7302 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7303
7304 list_move_tail(&piocb->list, &completions);
7305 }
7306 }
7307 spin_unlock_irq(&phba->hbalock);
7308
James Smarta257bf92009-04-06 18:48:10 -04007309 /* Cancel all the IOCBs from the completions list */
7310 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7311 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007312}
7313
James Smarte59058c2008-08-24 21:49:00 -04007314/**
James Smart3621a712009-04-06 18:47:14 -04007315 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007316 * @phba: pointer to lpfc hba data structure.
7317 *
7318 * This routine aborts all the IOCBs currently on the driver internal
7319 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7320 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7321 * list, removes IOCBs off the list, set the status feild to
7322 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7323 * the IOCB.
7324 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007325void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7326{
7327 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007328
7329 spin_lock_irq(&phba->hbalock);
7330 list_splice_init(&phba->fabric_iocb_list, &completions);
7331 spin_unlock_irq(&phba->hbalock);
7332
James Smarta257bf92009-04-06 18:48:10 -04007333 /* Cancel all the IOCBs from the completions list */
7334 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7335 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007336}
James Smart6fb120a2009-05-22 14:52:59 -04007337
7338/**
7339 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7340 * @phba: pointer to lpfc hba data structure.
7341 * @axri: pointer to the els xri abort wcqe structure.
7342 *
7343 * This routine is invoked by the worker thread to process a SLI4 slow-path
7344 * ELS aborted xri.
7345 **/
7346void
7347lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7348 struct sli4_wcqe_xri_aborted *axri)
7349{
7350 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7351 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7352 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04007353 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007354
James Smart0f65ff62010-02-26 14:14:23 -05007355 spin_lock_irqsave(&phba->hbalock, iflag);
7356 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007357 list_for_each_entry_safe(sglq_entry, sglq_next,
7358 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7359 if (sglq_entry->sli4_xritag == xri) {
7360 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007361 list_add_tail(&sglq_entry->list,
7362 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007363 sglq_entry->state = SGL_FREED;
7364 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007365 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04007366
7367 /* Check if TXQ queue needs to be serviced */
7368 if (pring->txq_cnt)
7369 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007370 return;
7371 }
7372 }
James Smart0f65ff62010-02-26 14:14:23 -05007373 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7374 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7375 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7376 spin_unlock_irqrestore(&phba->hbalock, iflag);
7377 return;
7378 }
7379 sglq_entry->state = SGL_XRI_ABORTED;
7380 spin_unlock_irqrestore(&phba->hbalock, iflag);
7381 return;
James Smart6fb120a2009-05-22 14:52:59 -04007382}