blob: c4c7f0ad746818b7c97db3580caf2d20c50a1d85 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
182 break;
183 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 }
James Smart0c287582009-06-10 17:22:56 -0400192 else
James Smartc8685952009-11-18 15:39:16 -0500193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400194
dea31012005-04-17 16:05:31 -0500195 icmd = &elsiocb->iocb;
196
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 if (pcmd)
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500204
205 INIT_LIST_HEAD(&pcmd->list);
206
207 /* Allocate buffer for response payload */
208 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500210 if (prsp)
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500215 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500216 } else
dea31012005-04-17 16:05:31 -0500217 prsp = NULL;
dea31012005-04-17 16:05:31 -0500218
219 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500221 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500226
227 INIT_LIST_HEAD(&pbuflist->list);
228
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500232 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400236 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500237 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 }
dea31012005-04-17 16:05:31 -0500241 icmd->ulpBdeCount = 1;
242 icmd->ulpLe = 1;
243 icmd->ulpClass = CLASS3;
244
James Smart92d7f7b2007-06-17 19:56:38 -0500245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
247
248 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400249 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 else
255 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500256 }
257
dea31012005-04-17 16:05:31 -0500258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264
265 if (expectRsp) {
266 bpl++;
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
272 }
273
James Smartfa4066b2008-01-11 01:53:27 -0500274 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400275 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500280 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500281 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
283
284 if (prsp) {
285 list_add(&prsp->list, &pcmd->list);
286 }
dea31012005-04-17 16:05:31 -0500287 if (expectRsp) {
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
293 vport->port_state);
dea31012005-04-17 16:05:31 -0500294 } else {
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
300 cmdSize);
dea31012005-04-17 16:05:31 -0500301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return elsiocb;
dea31012005-04-17 16:05:31 -0500303
James Smartfa4066b2008-01-11 01:53:27 -0500304els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500305 if (expectRsp)
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500307 kfree(pbuflist);
308
309els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
311 kfree(prsp);
312
313els_iocb_free_pcmb_exit:
314 kfree(pcmd);
315 lpfc_sli_release_iocbq(phba, elsiocb);
316 return NULL;
317}
dea31012005-04-17 16:05:31 -0500318
James Smarte59058c2008-08-24 21:49:00 -0400319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400321 * @vport: pointer to a host virtual N_Port data structure.
322 *
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
329 * with the @vport.
330 *
331 * Return code
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
334 **/
James Smart3772a992009-05-22 14:50:54 -0400335int
James Smart92d7f7b2007-06-17 19:56:38 -0500336lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337{
338 struct lpfc_hba *phba = vport->phba;
339 LPFC_MBOXQ_t *mbox;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
343 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400344 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400349 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500350 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400354 if (!mbox) {
355 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500356 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400357 }
James Smart92d7f7b2007-06-17 19:56:38 -0500358
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 mbox->vport = vport;
363
James Smart0b727fe2007-10-27 13:37:25 -0400364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400365 if (rc == MBX_NOT_FINISHED) {
366 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400371 if (!mbox) {
372 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400374 }
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400376 if (rc) {
377 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
385 */
James Smart92d7f7b2007-06-17 19:56:38 -0500386 mbox->context2 = lpfc_nlp_get(ndlp);
387
James Smart0b727fe2007-10-27 13:37:25 -0400388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400389 if (rc == MBX_NOT_FINISHED) {
390 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500391 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400392 }
James Smart92d7f7b2007-06-17 19:56:38 -0500393
394 return 0;
395
396fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
399 */
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_put(ndlp);
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
403 kfree(mp);
404fail_free_mbox:
405 mempool_free(mbox, phba->mbox_mem_pool);
406
407fail:
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return -ENXIO;
412}
413
James Smarte59058c2008-08-24 21:49:00 -0400414/**
James Smart6fb120a2009-05-22 14:52:59 -0400415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
417 *
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
420 *
421 * Return code
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
424 **/
425static int
426lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427{
428 struct lpfc_hba *phba = vport->phba;
429 LPFC_MBOXQ_t *mboxq;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
433 int rc = 0;
434
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
438 rc = -ENODEV;
439 goto fail;
440 }
441
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
443 if (!dmabuf) {
444 rc = -ENOMEM;
445 goto fail;
446 }
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
448 if (!dmabuf->virt) {
449 rc = -ENOMEM;
450 goto fail_free_dmabuf;
451 }
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
453 if (!mboxq) {
454 rc = -ENOMEM;
455 goto fail_free_coherent;
456 }
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
465 rc = -ENXIO;
466 goto fail_free_mbox;
467 }
468 return 0;
469
470fail_free_mbox:
471 mempool_free(mboxq, phba->mbox_mem_pool);
472fail_free_coherent:
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
474fail_free_dmabuf:
475 kfree(dmabuf);
476fail:
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
480 return rc;
481}
482
483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 *
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
499 *
500 * Return code
501 * 0 - Success (currently, always return 0)
502 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500503static int
James Smart2e0fef82007-06-17 19:56:36 -0500504lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521
522 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500526 } else {
527 /*
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
530 */
James Smart2e0fef82007-06-17 19:56:36 -0500531 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500532 }
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500535 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500536 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500537 ndlp->nlp_class_sup = 0;
538 if (sp->cls1.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS1;
540 if (sp->cls2.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS2;
542 if (sp->cls3.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS3;
544 if (sp->cls4.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS4;
546 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
547 sp->cmn.bbRcvSizeLsb;
548 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
549
James Smart92d7f7b2007-06-17 19:56:38 -0500550 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
551 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400552 lpfc_printf_vlog(vport, KERN_WARNING,
553 LOG_ELS | LOG_VPORT,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500557 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500558 } else {
559 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport, KERN_WARNING,
562 LOG_ELS | LOG_VPORT,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500565 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
566 }
567 }
568
569 if ((vport->fc_prevDID != vport->fc_myDID) &&
570 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
571
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
574 */
575 list_for_each_entry_safe(np, next_np,
576 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400577 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500578 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500579 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
580 !(np->nlp_flag & NLP_NPR_ADISC))
581 continue;
582 spin_lock_irq(shost->host_lock);
583 np->nlp_flag &= ~NLP_NPR_ADISC;
584 spin_unlock_irq(shost->host_lock);
585 lpfc_unreg_rpi(vport, np);
586 }
James Smart78730cf2010-04-06 15:06:30 -0400587 lpfc_cleanup_pending_mbox(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500588 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
589 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500590 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500591 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500592 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500593 }
James Smartecfd03c2010-02-12 14:41:27 -0500594 /*
595 * If VPI is unreged, driver need to do INIT_VPI
596 * before re-registering
597 */
598 if (phba->sli_rev == LPFC_SLI_REV4) {
599 spin_lock_irq(shost->host_lock);
600 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
601 spin_unlock_irq(shost->host_lock);
602 }
James Smart92d7f7b2007-06-17 19:56:38 -0500603 }
604
James Smart6fb120a2009-05-22 14:52:59 -0400605 if (phba->sli_rev < LPFC_SLI_REV4) {
606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
607 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
608 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
609 lpfc_register_new_vport(phba, vport, ndlp);
610 else
611 lpfc_issue_fabric_reglogin(vport);
612 } else {
613 ndlp->nlp_type |= NLP_FABRIC;
614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500615 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
616 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400617 lpfc_start_fdiscs(phba);
618 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500619 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500620 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500621 else
James Smart6fb120a2009-05-22 14:52:59 -0400622 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500623 }
dea31012005-04-17 16:05:31 -0500624 return 0;
dea31012005-04-17 16:05:31 -0500625}
James Smarte59058c2008-08-24 21:49:00 -0400626/**
James Smart3621a712009-04-06 18:47:14 -0400627 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400628 * @vport: pointer to a host virtual N_Port data structure.
629 * @ndlp: pointer to a node-list data structure.
630 * @sp: pointer to service parameter data structure.
631 *
632 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
633 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
634 * in a point-to-point topology. First, the @vport's N_Port Name is compared
635 * with the received N_Port Name: if the @vport's N_Port Name is greater than
636 * the received N_Port Name lexicographically, this node shall assign local
637 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
638 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
639 * this node shall just wait for the remote node to issue PLOGI and assign
640 * N_Port IDs.
641 *
642 * Return code
643 * 0 - Success
644 * -ENXIO - Fail
645 **/
dea31012005-04-17 16:05:31 -0500646static int
James Smart2e0fef82007-06-17 19:56:36 -0500647lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
648 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500649{
James Smart2e0fef82007-06-17 19:56:36 -0500650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500652 LPFC_MBOXQ_t *mbox;
653 int rc;
654
James Smart2e0fef82007-06-17 19:56:36 -0500655 spin_lock_irq(shost->host_lock);
656 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
657 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500658
659 phba->fc_edtov = FF_DEF_EDTOV;
660 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500661 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500662 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500663 if (rc >= 0) {
664 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag |= FC_PT2PT_PLOGI;
667 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500668
669 /*
670 * N_Port ID cannot be 0, set our to LocalID the other
671 * side will be RemoteID.
672 */
673
674 /* not equal */
675 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500676 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500677
678 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
679 if (!mbox)
680 goto fail;
681
682 lpfc_config_link(phba, mbox);
683
684 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500685 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400686 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500687 if (rc == MBX_NOT_FINISHED) {
688 mempool_free(mbox, phba->mbox_mem_pool);
689 goto fail;
690 }
James Smarte47c9092008-02-08 18:49:26 -0500691 /* Decrement ndlp reference count indicating that ndlp can be
692 * safely released when other references to it are done.
693 */
James Smart329f9bc2007-04-25 09:53:01 -0400694 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500695
James Smart2e0fef82007-06-17 19:56:36 -0500696 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500697 if (!ndlp) {
698 /*
699 * Cannot find existing Fabric ndlp, so allocate a
700 * new one
701 */
702 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
703 if (!ndlp)
704 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500705 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500706 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
707 ndlp = lpfc_enable_node(vport, ndlp,
708 NLP_STE_UNUSED_NODE);
709 if(!ndlp)
710 goto fail;
dea31012005-04-17 16:05:31 -0500711 }
712
713 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500714 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500715 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500716 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500717 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500718 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
719 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500720 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500721 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500722 } else
723 /* This side will wait for the PLOGI, decrement ndlp reference
724 * count indicating that ndlp can be released when other
725 * references to it are done.
726 */
James Smart329f9bc2007-04-25 09:53:01 -0400727 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500728
James Smart09372822008-01-11 01:52:54 -0500729 /* If we are pt2pt with another NPort, force NPIV off! */
730 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
731
James Smart2e0fef82007-06-17 19:56:36 -0500732 spin_lock_irq(shost->host_lock);
733 vport->fc_flag |= FC_PT2PT;
734 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500735
736 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500737 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500738 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500739fail:
dea31012005-04-17 16:05:31 -0500740 return -ENXIO;
741}
742
James Smarte59058c2008-08-24 21:49:00 -0400743/**
James Smart3621a712009-04-06 18:47:14 -0400744 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400745 * @phba: pointer to lpfc hba data structure.
746 * @cmdiocb: pointer to lpfc command iocb data structure.
747 * @rspiocb: pointer to lpfc response iocb data structure.
748 *
749 * This routine is the top-level completion callback function for issuing
750 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
751 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
752 * retry has been made (either immediately or delayed with lpfc_els_retry()
753 * returning 1), the command IOCB will be released and function returned.
754 * If the retry attempt has been given up (possibly reach the maximum
755 * number of retries), one additional decrement of ndlp reference shall be
756 * invoked before going out after releasing the command IOCB. This will
757 * actually release the remote node (Note, lpfc_els_free_iocb() will also
758 * invoke one decrement of ndlp reference count). If no error reported in
759 * the IOCB status, the command Port ID field is used to determine whether
760 * this is a point-to-point topology or a fabric topology: if the Port ID
761 * field is assigned, it is a fabric topology; otherwise, it is a
762 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
763 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
764 * specific topology completion conditions.
765 **/
dea31012005-04-17 16:05:31 -0500766static void
James Smart329f9bc2007-04-25 09:53:01 -0400767lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
768 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500769{
James Smart2e0fef82007-06-17 19:56:36 -0500770 struct lpfc_vport *vport = cmdiocb->vport;
771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500772 IOCB_t *irsp = &rspiocb->iocb;
773 struct lpfc_nodelist *ndlp = cmdiocb->context1;
774 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
775 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500776 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500777 int rc;
778
779 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500780 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500781 /* One additional decrement on node reference count to
782 * trigger the release of the node
783 */
James Smart329f9bc2007-04-25 09:53:01 -0400784 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500785 goto out;
786 }
787
James Smart858c9f62007-06-17 19:56:39 -0500788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
789 "FLOGI cmpl: status:x%x/x%x state:x%x",
790 irsp->ulpStatus, irsp->un.ulpWord[4],
791 vport->port_state);
792
dea31012005-04-17 16:05:31 -0500793 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500794 /*
795 * In case of FIP mode, perform round robin FCF failover
796 * due to new FCF discovery
797 */
798 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
799 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
800 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
801 "2611 FLOGI failed on registered "
802 "FCF record fcf_index:%d, trying "
803 "to perform round robin failover\n",
804 phba->fcf.current_rec.fcf_indx);
805 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
806 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
807 /*
808 * Exhausted the eligible FCF record list,
809 * fail through to retry FLOGI on current
810 * FCF record.
811 */
812 lpfc_printf_log(phba, KERN_WARNING,
813 LOG_FIP | LOG_ELS,
814 "2760 FLOGI exhausted FCF "
815 "round robin failover list, "
816 "retry FLOGI on the current "
817 "registered FCF index:%d\n",
818 phba->fcf.current_rec.fcf_indx);
819 spin_lock_irq(&phba->hbalock);
820 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
821 spin_unlock_irq(&phba->hbalock);
822 } else {
823 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
824 fcf_index);
825 if (rc) {
826 lpfc_printf_log(phba, KERN_WARNING,
827 LOG_FIP | LOG_ELS,
828 "2761 FLOGI round "
829 "robin FCF failover "
830 "read FCF failed "
831 "rc:x%x, fcf_index:"
832 "%d\n", rc,
833 phba->fcf.current_rec.fcf_indx);
834 spin_lock_irq(&phba->hbalock);
835 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
836 spin_unlock_irq(&phba->hbalock);
837 } else
838 goto out;
839 }
840 }
841
dea31012005-04-17 16:05:31 -0500842 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500843 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500844 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500845
dea31012005-04-17 16:05:31 -0500846 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500847 spin_lock_irq(shost->host_lock);
848 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
849 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500850
James Smart329f9bc2007-04-25 09:53:01 -0400851 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500852 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
853 * alpa map would take too long otherwise.
854 */
855 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400856 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500857 }
858
859 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500860 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
861 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400862 irsp->ulpStatus, irsp->un.ulpWord[4],
863 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500864 goto flogifail;
865 }
James Smart695a8142010-01-26 23:08:03 -0500866 spin_lock_irq(shost->host_lock);
867 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400868 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500869 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500870
871 /*
872 * The FLogI succeeded. Sync the data for the CPU before
873 * accessing it.
874 */
875 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
876
877 sp = prsp->virt + sizeof(uint32_t);
878
879 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400880 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200881 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400882 "Data: x%x x%x x%x x%x\n",
883 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
884 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500885
James Smart2e0fef82007-06-17 19:56:36 -0500886 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500887 /*
888 * If Common Service Parameters indicate Nport
889 * we are point to point, if Fport we are Fabric.
890 */
891 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500892 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500893 else
James Smart2e0fef82007-06-17 19:56:36 -0500894 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500895
James Smart0c9ab6f2010-02-26 14:15:57 -0500896 if (!rc) {
897 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400898 if (phba->hba_flag & HBA_FIP_SUPPORT)
899 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
900 LOG_ELS,
901 "2769 FLOGI successful on FCF "
902 "record: current_fcf_index:"
903 "x%x, terminate FCF round "
904 "robin failover process\n",
905 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500906 spin_lock_irq(&phba->hbalock);
907 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
908 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500909 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500910 }
dea31012005-04-17 16:05:31 -0500911 }
912
913flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400914 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500915
James Smart858c9f62007-06-17 19:56:39 -0500916 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500917 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500918 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500919
920 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500921 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400922 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
923 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
924 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
925 (phba->link_state != LPFC_CLEAR_LA)) {
926 /* If FLOGI failed enable link interrupt. */
927 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500928 }
dea31012005-04-17 16:05:31 -0500929out:
930 lpfc_els_free_iocb(phba, cmdiocb);
931}
932
James Smarte59058c2008-08-24 21:49:00 -0400933/**
James Smart3621a712009-04-06 18:47:14 -0400934 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400935 * @vport: pointer to a host virtual N_Port data structure.
936 * @ndlp: pointer to a node-list data structure.
937 * @retry: number of retries to the command IOCB.
938 *
939 * This routine issues a Fabric Login (FLOGI) Request ELS command
940 * for a @vport. The initiator service parameters are put into the payload
941 * of the FLOGI Request IOCB and the top-level callback function pointer
942 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
943 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
944 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
945 *
946 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
947 * will be incremented by 1 for holding the ndlp and the reference to ndlp
948 * will be stored into the context1 field of the IOCB for the completion
949 * callback function to the FLOGI ELS command.
950 *
951 * Return code
952 * 0 - successfully issued flogi iocb for @vport
953 * 1 - failed to issue flogi iocb for @vport
954 **/
dea31012005-04-17 16:05:31 -0500955static int
James Smart2e0fef82007-06-17 19:56:36 -0500956lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500957 uint8_t retry)
958{
James Smart2e0fef82007-06-17 19:56:36 -0500959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500960 struct serv_parm *sp;
961 IOCB_t *icmd;
962 struct lpfc_iocbq *elsiocb;
963 struct lpfc_sli_ring *pring;
964 uint8_t *pcmd;
965 uint16_t cmdsize;
966 uint32_t tmo;
967 int rc;
968
969 pring = &phba->sli.ring[LPFC_ELS_RING];
970
James Smart92d7f7b2007-06-17 19:56:38 -0500971 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500972 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
973 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500974
James Smart488d1462006-03-07 15:02:37 -0500975 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500976 return 1;
dea31012005-04-17 16:05:31 -0500977
978 icmd = &elsiocb->iocb;
979 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
980
981 /* For FLOGI request, remainder of payload is service parameters */
982 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500983 pcmd += sizeof(uint32_t);
984 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500985 sp = (struct serv_parm *) pcmd;
986
987 /* Setup CSPs accordingly for Fabric */
988 sp->cmn.e_d_tov = 0;
989 sp->cmn.w2.r_a_tov = 0;
990 sp->cls1.classValid = 0;
991 sp->cls2.seqDelivery = 1;
992 sp->cls3.seqDelivery = 1;
993 if (sp->cmn.fcphLow < FC_PH3)
994 sp->cmn.fcphLow = FC_PH3;
995 if (sp->cmn.fcphHigh < FC_PH3)
996 sp->cmn.fcphHigh = FC_PH3;
997
James Smart6fb120a2009-05-22 14:52:59 -0400998 if (phba->sli_rev == LPFC_SLI_REV4) {
999 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1000 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1001 /* FLOGI needs to be 3 for WQE FCFI */
1002 /* Set the fcfi to the fcfi we registered with */
1003 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1004 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001005 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001006 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1007 icmd->ulpCt_h = 1;
1008 icmd->ulpCt_l = 0;
1009 }
1010
James Smart858c9f62007-06-17 19:56:39 -05001011 if (phba->fc_topology != TOPOLOGY_LOOP) {
1012 icmd->un.elsreq64.myID = 0;
1013 icmd->un.elsreq64.fl = 1;
1014 }
1015
dea31012005-04-17 16:05:31 -05001016 tmo = phba->fc_ratov;
1017 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001018 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001019 phba->fc_ratov = tmo;
1020
1021 phba->fc_stat.elsXmitFLOGI++;
1022 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001023
1024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1025 "Issue FLOGI: opt:x%x",
1026 phba->sli3_options, 0, 0);
1027
James Smart92d7f7b2007-06-17 19:56:38 -05001028 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001029 if (rc == IOCB_ERROR) {
1030 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001031 return 1;
dea31012005-04-17 16:05:31 -05001032 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001033 return 0;
dea31012005-04-17 16:05:31 -05001034}
1035
James Smarte59058c2008-08-24 21:49:00 -04001036/**
James Smart3621a712009-04-06 18:47:14 -04001037 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001038 * @phba: pointer to lpfc hba data structure.
1039 *
1040 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1041 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1042 * list and issues an abort IOCB commond on each outstanding IOCB that
1043 * contains a active Fabric_DID ndlp. Note that this function is to issue
1044 * the abort IOCB command on all the outstanding IOCBs, thus when this
1045 * function returns, it does not guarantee all the IOCBs are actually aborted.
1046 *
1047 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001048 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001049 **/
dea31012005-04-17 16:05:31 -05001050int
James Smart2e0fef82007-06-17 19:56:36 -05001051lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001052{
1053 struct lpfc_sli_ring *pring;
1054 struct lpfc_iocbq *iocb, *next_iocb;
1055 struct lpfc_nodelist *ndlp;
1056 IOCB_t *icmd;
1057
1058 /* Abort outstanding I/O on NPort <nlp_DID> */
1059 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001060 "0201 Abort outstanding I/O on NPort x%x\n",
1061 Fabric_DID);
dea31012005-04-17 16:05:31 -05001062
1063 pring = &phba->sli.ring[LPFC_ELS_RING];
1064
1065 /*
1066 * Check the txcmplq for an iocb that matches the nport the driver is
1067 * searching for.
1068 */
James Smart2e0fef82007-06-17 19:56:36 -05001069 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001070 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1071 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001072 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1073 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001074 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001075 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1076 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001077 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001078 }
1079 }
James Smart2e0fef82007-06-17 19:56:36 -05001080 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001081
1082 return 0;
1083}
1084
James Smarte59058c2008-08-24 21:49:00 -04001085/**
James Smart3621a712009-04-06 18:47:14 -04001086 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001087 * @vport: pointer to a host virtual N_Port data structure.
1088 *
1089 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1090 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1091 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1092 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1093 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1094 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1095 * @vport.
1096 *
1097 * Return code
1098 * 0 - failed to issue initial flogi for @vport
1099 * 1 - successfully issued initial flogi for @vport
1100 **/
dea31012005-04-17 16:05:31 -05001101int
James Smart2e0fef82007-06-17 19:56:36 -05001102lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001103{
James Smart2e0fef82007-06-17 19:56:36 -05001104 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001105 struct lpfc_nodelist *ndlp;
1106
James Smart98c9ea52007-10-27 13:37:33 -04001107 vport->port_state = LPFC_FLOGI;
1108 lpfc_set_disctmo(vport);
1109
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001110 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001111 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001112 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001113 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001114 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1115 if (!ndlp)
1116 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001117 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001118 /* Set the node type */
1119 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001120 /* Put ndlp onto node list */
1121 lpfc_enqueue_node(vport, ndlp);
1122 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1123 /* re-setup ndlp without removing from node list */
1124 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1125 if (!ndlp)
1126 return 0;
dea31012005-04-17 16:05:31 -05001127 }
James Smart87af33f2007-10-27 13:37:43 -04001128
James Smarte47c9092008-02-08 18:49:26 -05001129 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001130 /* This decrement of reference count to node shall kick off
1131 * the release of the node.
1132 */
James Smart329f9bc2007-04-25 09:53:01 -04001133 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001134
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001135 return 1;
dea31012005-04-17 16:05:31 -05001136}
1137
James Smarte59058c2008-08-24 21:49:00 -04001138/**
James Smart3621a712009-04-06 18:47:14 -04001139 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001140 * @vport: pointer to a host virtual N_Port data structure.
1141 *
1142 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1143 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1144 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1145 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1146 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1147 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1148 * @vport.
1149 *
1150 * Return code
1151 * 0 - failed to issue initial fdisc for @vport
1152 * 1 - successfully issued initial fdisc for @vport
1153 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001154int
1155lpfc_initial_fdisc(struct lpfc_vport *vport)
1156{
1157 struct lpfc_hba *phba = vport->phba;
1158 struct lpfc_nodelist *ndlp;
1159
1160 /* First look for the Fabric ndlp */
1161 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1162 if (!ndlp) {
1163 /* Cannot find existing Fabric ndlp, so allocate a new one */
1164 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1165 if (!ndlp)
1166 return 0;
1167 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001168 /* Put ndlp onto node list */
1169 lpfc_enqueue_node(vport, ndlp);
1170 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1171 /* re-setup ndlp without removing from node list */
1172 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1173 if (!ndlp)
1174 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001175 }
James Smarte47c9092008-02-08 18:49:26 -05001176
James Smart92d7f7b2007-06-17 19:56:38 -05001177 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001178 /* decrement node reference count to trigger the release of
1179 * the node.
1180 */
James Smart92d7f7b2007-06-17 19:56:38 -05001181 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001182 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001183 }
1184 return 1;
1185}
James Smart87af33f2007-10-27 13:37:43 -04001186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001189 * @vport: pointer to a host virtual N_Port data structure.
1190 *
1191 * This routine checks whether there are more remaining Port Logins
1192 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1193 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1194 * to issue ELS PLOGIs up to the configured discover threads with the
1195 * @vport (@vport->cfg_discovery_threads). The function also decrement
1196 * the @vport's num_disc_node by 1 if it is not already 0.
1197 **/
James Smart87af33f2007-10-27 13:37:43 -04001198void
James Smart2e0fef82007-06-17 19:56:36 -05001199lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001200{
1201 int sentplogi;
1202
James Smart2e0fef82007-06-17 19:56:36 -05001203 if (vport->num_disc_nodes)
1204 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001205
1206 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001207 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1208 "0232 Continue discovery with %d PLOGIs to go "
1209 "Data: x%x x%x x%x\n",
1210 vport->num_disc_nodes, vport->fc_plogi_cnt,
1211 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001212 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001213 if (vport->fc_flag & FC_NLP_MORE)
1214 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1215 sentplogi = lpfc_els_disc_plogi(vport);
1216
dea31012005-04-17 16:05:31 -05001217 return;
1218}
1219
James Smarte59058c2008-08-24 21:49:00 -04001220/**
James Smart3621a712009-04-06 18:47:14 -04001221 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001222 * @phba: pointer to lpfc hba data structure.
1223 * @prsp: pointer to response IOCB payload.
1224 * @ndlp: pointer to a node-list data structure.
1225 *
1226 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1227 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1228 * The following cases are considered N_Port confirmed:
1229 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1230 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1231 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1232 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1233 * 1) if there is a node on vport list other than the @ndlp with the same
1234 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1235 * on that node to release the RPI associated with the node; 2) if there is
1236 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1237 * into, a new node shall be allocated (or activated). In either case, the
1238 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1239 * be released and the new_ndlp shall be put on to the vport node list and
1240 * its pointer returned as the confirmed node.
1241 *
1242 * Note that before the @ndlp got "released", the keepDID from not-matching
1243 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1244 * of the @ndlp. This is because the release of @ndlp is actually to put it
1245 * into an inactive state on the vport node list and the vport node list
1246 * management algorithm does not allow two node with a same DID.
1247 *
1248 * Return code
1249 * pointer to the PLOGI N_Port @ndlp
1250 **/
James Smart488d1462006-03-07 15:02:37 -05001251static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001252lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001253 struct lpfc_nodelist *ndlp)
1254{
James Smart2e0fef82007-06-17 19:56:36 -05001255 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001256 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001257 struct lpfc_rport_data *rdata;
1258 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001259 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001260 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001261 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001262
James Smart2fb9bd82006-12-02 13:33:57 -05001263 /* Fabric nodes can have the same WWPN so we don't bother searching
1264 * by WWPN. Just return the ndlp that was given to us.
1265 */
1266 if (ndlp->nlp_type & NLP_FABRIC)
1267 return ndlp;
1268
James Smart92d7f7b2007-06-17 19:56:38 -05001269 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001270 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001271
James Smart685f0bf2007-04-25 09:53:08 -04001272 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001273 * we have for that ndlp. If not, we have some work to do.
1274 */
James Smart2e0fef82007-06-17 19:56:36 -05001275 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001276
James Smarte47c9092008-02-08 18:49:26 -05001277 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001278 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001279
1280 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001281 rc = memcmp(&ndlp->nlp_portname, name,
1282 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001283 if (!rc)
1284 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001285 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1286 if (!new_ndlp)
1287 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001288 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001289 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001290 rc = memcmp(&ndlp->nlp_portname, name,
1291 sizeof(struct lpfc_name));
1292 if (!rc)
1293 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001294 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1295 NLP_STE_UNUSED_NODE);
1296 if (!new_ndlp)
1297 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001298 keepDID = new_ndlp->nlp_DID;
1299 } else
1300 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001301
James Smart2e0fef82007-06-17 19:56:36 -05001302 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001303 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001304 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001305
1306 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1307 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1308 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1309
James Smarte47c9092008-02-08 18:49:26 -05001310 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001312
James Smart2e0fef82007-06-17 19:56:36 -05001313 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001314 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1315 /* The new_ndlp is replacing ndlp totally, so we need
1316 * to put ndlp on UNUSED list and try to free it.
1317 */
James Smart0ff10d42008-01-11 01:52:36 -05001318
1319 /* Fix up the rport accordingly */
1320 rport = ndlp->rport;
1321 if (rport) {
1322 rdata = rport->dd_data;
1323 if (rdata->pnode == ndlp) {
1324 lpfc_nlp_put(ndlp);
1325 ndlp->rport = NULL;
1326 rdata->pnode = lpfc_nlp_get(new_ndlp);
1327 new_ndlp->rport = rport;
1328 }
1329 new_ndlp->nlp_type = ndlp->nlp_type;
1330 }
James Smart58da1ff2008-04-07 10:15:56 -04001331 /* We shall actually free the ndlp with both nlp_DID and
1332 * nlp_portname fields equals 0 to avoid any ndlp on the
1333 * nodelist never to be used.
1334 */
1335 if (ndlp->nlp_DID == 0) {
1336 spin_lock_irq(&phba->ndlp_lock);
1337 NLP_SET_FREE_REQ(ndlp);
1338 spin_unlock_irq(&phba->ndlp_lock);
1339 }
James Smart0ff10d42008-01-11 01:52:36 -05001340
James Smart58da1ff2008-04-07 10:15:56 -04001341 /* Two ndlps cannot have the same did on the nodelist */
1342 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001343 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001344 }
James Smart92795652006-07-06 15:50:02 -04001345 else {
James Smart2e0fef82007-06-17 19:56:36 -05001346 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001347 /* Two ndlps cannot have the same did */
1348 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001349 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001350 }
James Smart488d1462006-03-07 15:02:37 -05001351 return new_ndlp;
1352}
1353
James Smarte59058c2008-08-24 21:49:00 -04001354/**
James Smart3621a712009-04-06 18:47:14 -04001355 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001356 * @vport: pointer to a host virtual N_Port data structure.
1357 *
1358 * This routine checks whether more Registration State Change
1359 * Notifications (RSCNs) came in while the discovery state machine was in
1360 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1361 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1362 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1363 * handling the RSCNs.
1364 **/
James Smart87af33f2007-10-27 13:37:43 -04001365void
1366lpfc_end_rscn(struct lpfc_vport *vport)
1367{
1368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1369
1370 if (vport->fc_flag & FC_RSCN_MODE) {
1371 /*
1372 * Check to see if more RSCNs came in while we were
1373 * processing this one.
1374 */
1375 if (vport->fc_rscn_id_cnt ||
1376 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1377 lpfc_els_handle_rscn(vport);
1378 else {
1379 spin_lock_irq(shost->host_lock);
1380 vport->fc_flag &= ~FC_RSCN_MODE;
1381 spin_unlock_irq(shost->host_lock);
1382 }
1383 }
1384}
1385
James Smarte59058c2008-08-24 21:49:00 -04001386/**
James Smart3621a712009-04-06 18:47:14 -04001387 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001388 * @phba: pointer to lpfc hba data structure.
1389 * @cmdiocb: pointer to lpfc command iocb data structure.
1390 * @rspiocb: pointer to lpfc response iocb data structure.
1391 *
1392 * This routine is the completion callback function for issuing the Port
1393 * Login (PLOGI) command. For PLOGI completion, there must be an active
1394 * ndlp on the vport node list that matches the remote node ID from the
1395 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1396 * ignored and command IOCB released. The PLOGI response IOCB status is
1397 * checked for error conditons. If there is error status reported, PLOGI
1398 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1399 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1400 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1401 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1402 * there are additional N_Port nodes with the vport that need to perform
1403 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1404 * PLOGIs.
1405 **/
dea31012005-04-17 16:05:31 -05001406static void
James Smart2e0fef82007-06-17 19:56:36 -05001407lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1408 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001409{
James Smart2e0fef82007-06-17 19:56:36 -05001410 struct lpfc_vport *vport = cmdiocb->vport;
1411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001412 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001413 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001414 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001415 int disc, rc, did, type;
1416
dea31012005-04-17 16:05:31 -05001417 /* we pass cmdiocb to state machine which needs rspiocb as well */
1418 cmdiocb->context_un.rsp_iocb = rspiocb;
1419
1420 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1422 "PLOGI cmpl: status:x%x/x%x did:x%x",
1423 irsp->ulpStatus, irsp->un.ulpWord[4],
1424 irsp->un.elsreq64.remoteID);
1425
James Smart2e0fef82007-06-17 19:56:36 -05001426 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001427 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001428 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1429 "0136 PLOGI completes to NPort x%x "
1430 "with no ndlp. Data: x%x x%x x%x\n",
1431 irsp->un.elsreq64.remoteID,
1432 irsp->ulpStatus, irsp->un.ulpWord[4],
1433 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001434 goto out;
James Smarted957682007-06-17 19:56:37 -05001435 }
dea31012005-04-17 16:05:31 -05001436
1437 /* Since ndlp can be freed in the disc state machine, note if this node
1438 * is being used during discovery.
1439 */
James Smart2e0fef82007-06-17 19:56:36 -05001440 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001441 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001442 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001443 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001444 rc = 0;
1445
1446 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001447 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1448 "0102 PLOGI completes to NPort x%x "
1449 "Data: x%x x%x x%x x%x x%x\n",
1450 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1451 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001452 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001453 if (lpfc_els_chk_latt(vport)) {
1454 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001455 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001456 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001457 goto out;
1458 }
1459
1460 /* ndlp could be freed in DSM, save these values now */
1461 type = ndlp->nlp_type;
1462 did = ndlp->nlp_DID;
1463
1464 if (irsp->ulpStatus) {
1465 /* Check for retry */
1466 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1467 /* ELS command is being retried */
1468 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001469 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001470 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001471 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001472 }
1473 goto out;
1474 }
dea31012005-04-17 16:05:31 -05001475 /* PLOGI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001476 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1477 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1478 ndlp->nlp_DID, irsp->ulpStatus,
1479 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001480 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001481 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001482 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001483 else
James Smart2e0fef82007-06-17 19:56:36 -05001484 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001485 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001486 } else {
1487 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001488 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001489 cmdiocb->context2)->list.next,
1490 struct lpfc_dmabuf, list);
1491 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001492 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001493 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001494 }
1495
James Smart2e0fef82007-06-17 19:56:36 -05001496 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001497 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001498 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001499
James Smart2e0fef82007-06-17 19:56:36 -05001500 if (vport->num_disc_nodes == 0) {
1501 spin_lock_irq(shost->host_lock);
1502 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1503 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001504
James Smart2e0fef82007-06-17 19:56:36 -05001505 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001506 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001507 }
1508 }
1509
1510out:
1511 lpfc_els_free_iocb(phba, cmdiocb);
1512 return;
1513}
1514
James Smarte59058c2008-08-24 21:49:00 -04001515/**
James Smart3621a712009-04-06 18:47:14 -04001516 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001517 * @vport: pointer to a host virtual N_Port data structure.
1518 * @did: destination port identifier.
1519 * @retry: number of retries to the command IOCB.
1520 *
1521 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1522 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1523 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1524 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1525 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1526 *
1527 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1528 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1529 * will be stored into the context1 field of the IOCB for the completion
1530 * callback function to the PLOGI ELS command.
1531 *
1532 * Return code
1533 * 0 - Successfully issued a plogi for @vport
1534 * 1 - failed to issue a plogi for @vport
1535 **/
dea31012005-04-17 16:05:31 -05001536int
James Smart2e0fef82007-06-17 19:56:36 -05001537lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001538{
James Smart2e0fef82007-06-17 19:56:36 -05001539 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001540 struct serv_parm *sp;
1541 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001542 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001543 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001544 struct lpfc_sli *psli;
1545 uint8_t *pcmd;
1546 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001547 int ret;
dea31012005-04-17 16:05:31 -05001548
1549 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001550
James Smart98c9ea52007-10-27 13:37:33 -04001551 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001552 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1553 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001554
James Smarte47c9092008-02-08 18:49:26 -05001555 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001556 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001557 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001558 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001559 if (!elsiocb)
1560 return 1;
dea31012005-04-17 16:05:31 -05001561
1562 icmd = &elsiocb->iocb;
1563 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1564
1565 /* For PLOGI request, remainder of payload is service parameters */
1566 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001567 pcmd += sizeof(uint32_t);
1568 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001569 sp = (struct serv_parm *) pcmd;
1570
1571 if (sp->cmn.fcphLow < FC_PH_4_3)
1572 sp->cmn.fcphLow = FC_PH_4_3;
1573
1574 if (sp->cmn.fcphHigh < FC_PH3)
1575 sp->cmn.fcphHigh = FC_PH3;
1576
James Smart858c9f62007-06-17 19:56:39 -05001577 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1578 "Issue PLOGI: did:x%x",
1579 did, 0, 0);
1580
dea31012005-04-17 16:05:31 -05001581 phba->fc_stat.elsXmitPLOGI++;
1582 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001583 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001584
1585 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001586 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001587 return 1;
dea31012005-04-17 16:05:31 -05001588 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001589 return 0;
dea31012005-04-17 16:05:31 -05001590}
1591
James Smarte59058c2008-08-24 21:49:00 -04001592/**
James Smart3621a712009-04-06 18:47:14 -04001593 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001594 * @phba: pointer to lpfc hba data structure.
1595 * @cmdiocb: pointer to lpfc command iocb data structure.
1596 * @rspiocb: pointer to lpfc response iocb data structure.
1597 *
1598 * This routine is the completion callback function for a Process Login
1599 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1600 * status. If there is error status reported, PRLI retry shall be attempted
1601 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1602 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1603 * ndlp to mark the PRLI completion.
1604 **/
dea31012005-04-17 16:05:31 -05001605static void
James Smart2e0fef82007-06-17 19:56:36 -05001606lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1607 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001608{
James Smart2e0fef82007-06-17 19:56:36 -05001609 struct lpfc_vport *vport = cmdiocb->vport;
1610 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001611 IOCB_t *irsp;
1612 struct lpfc_sli *psli;
1613 struct lpfc_nodelist *ndlp;
1614
1615 psli = &phba->sli;
1616 /* we pass cmdiocb to state machine which needs rspiocb as well */
1617 cmdiocb->context_un.rsp_iocb = rspiocb;
1618
1619 irsp = &(rspiocb->iocb);
1620 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001621 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001622 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001623 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001624
James Smart858c9f62007-06-17 19:56:39 -05001625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1626 "PRLI cmpl: status:x%x/x%x did:x%x",
1627 irsp->ulpStatus, irsp->un.ulpWord[4],
1628 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001629 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001630 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1631 "0103 PRLI completes to NPort x%x "
1632 "Data: x%x x%x x%x x%x\n",
1633 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1634 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001635
James Smart2e0fef82007-06-17 19:56:36 -05001636 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001637 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001638 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001639 goto out;
1640
1641 if (irsp->ulpStatus) {
1642 /* Check for retry */
1643 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1644 /* ELS command is being retried */
1645 goto out;
1646 }
1647 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001648 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1649 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1650 ndlp->nlp_DID, irsp->ulpStatus,
1651 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001652 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001653 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001654 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001655 else
James Smart2e0fef82007-06-17 19:56:36 -05001656 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001657 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001658 } else
dea31012005-04-17 16:05:31 -05001659 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001660 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001661 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001662out:
1663 lpfc_els_free_iocb(phba, cmdiocb);
1664 return;
1665}
1666
James Smarte59058c2008-08-24 21:49:00 -04001667/**
James Smart3621a712009-04-06 18:47:14 -04001668 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001669 * @vport: pointer to a host virtual N_Port data structure.
1670 * @ndlp: pointer to a node-list data structure.
1671 * @retry: number of retries to the command IOCB.
1672 *
1673 * This routine issues a Process Login (PRLI) ELS command for the
1674 * @vport. The PRLI service parameters are set up in the payload of the
1675 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1676 * is put to the IOCB completion callback func field before invoking the
1677 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1678 *
1679 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1680 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1681 * will be stored into the context1 field of the IOCB for the completion
1682 * callback function to the PRLI ELS command.
1683 *
1684 * Return code
1685 * 0 - successfully issued prli iocb command for @vport
1686 * 1 - failed to issue prli iocb command for @vport
1687 **/
dea31012005-04-17 16:05:31 -05001688int
James Smart2e0fef82007-06-17 19:56:36 -05001689lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001690 uint8_t retry)
1691{
James Smart2e0fef82007-06-17 19:56:36 -05001692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1693 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001694 PRLI *npr;
1695 IOCB_t *icmd;
1696 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001697 uint8_t *pcmd;
1698 uint16_t cmdsize;
1699
James Smart92d7f7b2007-06-17 19:56:38 -05001700 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001701 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1702 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001703 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001704 return 1;
dea31012005-04-17 16:05:31 -05001705
1706 icmd = &elsiocb->iocb;
1707 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1708
1709 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001710 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001711 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001712 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001713
1714 /* For PRLI, remainder of payload is PRLI parameter page */
1715 npr = (PRLI *) pcmd;
1716 /*
1717 * If our firmware version is 3.20 or later,
1718 * set the following bits for FC-TAPE support.
1719 */
1720 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1721 npr->ConfmComplAllowed = 1;
1722 npr->Retry = 1;
1723 npr->TaskRetryIdReq = 1;
1724 }
1725 npr->estabImagePair = 1;
1726 npr->readXferRdyDis = 1;
1727
1728 /* For FCP support */
1729 npr->prliType = PRLI_FCP_TYPE;
1730 npr->initiatorFunc = 1;
1731
James Smart858c9f62007-06-17 19:56:39 -05001732 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1733 "Issue PRLI: did:x%x",
1734 ndlp->nlp_DID, 0, 0);
1735
dea31012005-04-17 16:05:31 -05001736 phba->fc_stat.elsXmitPRLI++;
1737 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001738 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001739 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001740 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001741 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1742 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001743 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001744 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001745 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001746 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001747 return 1;
dea31012005-04-17 16:05:31 -05001748 }
James Smart2e0fef82007-06-17 19:56:36 -05001749 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001750 return 0;
dea31012005-04-17 16:05:31 -05001751}
1752
James Smarte59058c2008-08-24 21:49:00 -04001753/**
James Smart3621a712009-04-06 18:47:14 -04001754 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001755 * @vport: pointer to a host virtual N_Port data structure.
1756 *
1757 * This routine performs Registration State Change Notification (RSCN)
1758 * discovery for a @vport. If the @vport's node port recovery count is not
1759 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1760 * the nodes that need recovery. If none of the PLOGI were needed through
1761 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1762 * invoked to check and handle possible more RSCN came in during the period
1763 * of processing the current ones.
1764 **/
1765static void
1766lpfc_rscn_disc(struct lpfc_vport *vport)
1767{
1768 lpfc_can_disctmo(vport);
1769
1770 /* RSCN discovery */
1771 /* go thru NPR nodes and issue ELS PLOGIs */
1772 if (vport->fc_npr_cnt)
1773 if (lpfc_els_disc_plogi(vport))
1774 return;
1775
1776 lpfc_end_rscn(vport);
1777}
1778
1779/**
James Smart3621a712009-04-06 18:47:14 -04001780 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001781 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1782 *
1783 * This function is called when the final ADISC is completed during discovery.
1784 * This function handles clearing link attention or issuing reg_vpi depending
1785 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1786 * discovery.
1787 * This function is called with no locks held.
1788 **/
1789static void
1790lpfc_adisc_done(struct lpfc_vport *vport)
1791{
1792 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1793 struct lpfc_hba *phba = vport->phba;
1794
1795 /*
1796 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1797 * and continue discovery.
1798 */
1799 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001800 !(vport->fc_flag & FC_RSCN_MODE) &&
1801 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001802 lpfc_issue_reg_vpi(phba, vport);
1803 return;
1804 }
1805 /*
1806 * For SLI2, we need to set port_state to READY
1807 * and continue discovery.
1808 */
1809 if (vport->port_state < LPFC_VPORT_READY) {
1810 /* If we get here, there is nothing to ADISC */
1811 if (vport->port_type == LPFC_PHYSICAL_PORT)
1812 lpfc_issue_clear_la(phba, vport);
1813 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1814 vport->num_disc_nodes = 0;
1815 /* go thru NPR list, issue ELS PLOGIs */
1816 if (vport->fc_npr_cnt)
1817 lpfc_els_disc_plogi(vport);
1818 if (!vport->num_disc_nodes) {
1819 spin_lock_irq(shost->host_lock);
1820 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1821 spin_unlock_irq(shost->host_lock);
1822 lpfc_can_disctmo(vport);
1823 lpfc_end_rscn(vport);
1824 }
1825 }
1826 vport->port_state = LPFC_VPORT_READY;
1827 } else
1828 lpfc_rscn_disc(vport);
1829}
1830
1831/**
James Smart3621a712009-04-06 18:47:14 -04001832 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001833 * @vport: pointer to a host virtual N_Port data structure.
1834 *
1835 * This routine determines whether there are more ndlps on a @vport
1836 * node list need to have Address Discover (ADISC) issued. If so, it will
1837 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1838 * remaining nodes which need to have ADISC sent.
1839 **/
James Smart0ff10d42008-01-11 01:52:36 -05001840void
James Smart2e0fef82007-06-17 19:56:36 -05001841lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001842{
1843 int sentadisc;
1844
James Smart2e0fef82007-06-17 19:56:36 -05001845 if (vport->num_disc_nodes)
1846 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001847 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001848 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1849 "0210 Continue discovery with %d ADISCs to go "
1850 "Data: x%x x%x x%x\n",
1851 vport->num_disc_nodes, vport->fc_adisc_cnt,
1852 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001853 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001854 if (vport->fc_flag & FC_NLP_MORE) {
1855 lpfc_set_disctmo(vport);
1856 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1857 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001858 }
James Smart90160e02008-08-24 21:49:45 -04001859 if (!vport->num_disc_nodes)
1860 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001861 return;
1862}
1863
James Smarte59058c2008-08-24 21:49:00 -04001864/**
James Smart3621a712009-04-06 18:47:14 -04001865 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001866 * @phba: pointer to lpfc hba data structure.
1867 * @cmdiocb: pointer to lpfc command iocb data structure.
1868 * @rspiocb: pointer to lpfc response iocb data structure.
1869 *
1870 * This routine is the completion function for issuing the Address Discover
1871 * (ADISC) command. It first checks to see whether link went down during
1872 * the discovery process. If so, the node will be marked as node port
1873 * recovery for issuing discover IOCB by the link attention handler and
1874 * exit. Otherwise, the response status is checked. If error was reported
1875 * in the response status, the ADISC command shall be retried by invoking
1876 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1877 * the response status, the state machine is invoked to set transition
1878 * with respect to NLP_EVT_CMPL_ADISC event.
1879 **/
dea31012005-04-17 16:05:31 -05001880static void
James Smart2e0fef82007-06-17 19:56:36 -05001881lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1882 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001883{
James Smart2e0fef82007-06-17 19:56:36 -05001884 struct lpfc_vport *vport = cmdiocb->vport;
1885 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001886 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001887 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001888 int disc;
dea31012005-04-17 16:05:31 -05001889
1890 /* we pass cmdiocb to state machine which needs rspiocb as well */
1891 cmdiocb->context_un.rsp_iocb = rspiocb;
1892
1893 irsp = &(rspiocb->iocb);
1894 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001895
James Smart858c9f62007-06-17 19:56:39 -05001896 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1897 "ADISC cmpl: status:x%x/x%x did:x%x",
1898 irsp->ulpStatus, irsp->un.ulpWord[4],
1899 ndlp->nlp_DID);
1900
dea31012005-04-17 16:05:31 -05001901 /* Since ndlp can be freed in the disc state machine, note if this node
1902 * is being used during discovery.
1903 */
James Smart2e0fef82007-06-17 19:56:36 -05001904 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001905 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001906 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001907 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001908 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001909 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1910 "0104 ADISC completes to NPort x%x "
1911 "Data: x%x x%x x%x x%x x%x\n",
1912 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1913 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001914 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001915 if (lpfc_els_chk_latt(vport)) {
1916 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001917 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001918 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001919 goto out;
1920 }
1921
1922 if (irsp->ulpStatus) {
1923 /* Check for retry */
1924 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1925 /* ELS command is being retried */
1926 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001927 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001928 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001929 spin_unlock_irq(shost->host_lock);
1930 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001931 }
1932 goto out;
1933 }
1934 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001935 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1936 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1937 ndlp->nlp_DID, irsp->ulpStatus,
1938 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001939 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001940 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001941 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001942 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001943 } else
dea31012005-04-17 16:05:31 -05001944 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001945 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001946 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001947
James Smart90160e02008-08-24 21:49:45 -04001948 /* Check to see if there are more ADISCs to be sent */
1949 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001950 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001951out:
1952 lpfc_els_free_iocb(phba, cmdiocb);
1953 return;
1954}
1955
James Smarte59058c2008-08-24 21:49:00 -04001956/**
James Smart3621a712009-04-06 18:47:14 -04001957 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001958 * @vport: pointer to a virtual N_Port data structure.
1959 * @ndlp: pointer to a node-list data structure.
1960 * @retry: number of retries to the command IOCB.
1961 *
1962 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1963 * @vport. It prepares the payload of the ADISC ELS command, updates the
1964 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1965 * to issue the ADISC ELS command.
1966 *
1967 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1968 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1969 * will be stored into the context1 field of the IOCB for the completion
1970 * callback function to the ADISC ELS command.
1971 *
1972 * Return code
1973 * 0 - successfully issued adisc
1974 * 1 - failed to issue adisc
1975 **/
dea31012005-04-17 16:05:31 -05001976int
James Smart2e0fef82007-06-17 19:56:36 -05001977lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001978 uint8_t retry)
1979{
James Smart2e0fef82007-06-17 19:56:36 -05001980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1981 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001982 ADISC *ap;
1983 IOCB_t *icmd;
1984 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001985 uint8_t *pcmd;
1986 uint16_t cmdsize;
1987
James Smart92d7f7b2007-06-17 19:56:38 -05001988 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001989 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1990 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001991 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001992 return 1;
dea31012005-04-17 16:05:31 -05001993
1994 icmd = &elsiocb->iocb;
1995 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1996
1997 /* For ADISC request, remainder of payload is service parameters */
1998 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001999 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002000
2001 /* Fill in ADISC payload */
2002 ap = (ADISC *) pcmd;
2003 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002004 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2005 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002006 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002007
James Smart858c9f62007-06-17 19:56:39 -05002008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2009 "Issue ADISC: did:x%x",
2010 ndlp->nlp_DID, 0, 0);
2011
dea31012005-04-17 16:05:31 -05002012 phba->fc_stat.elsXmitADISC++;
2013 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002014 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002015 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002016 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002017 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2018 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002019 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002020 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002021 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002022 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002023 return 1;
dea31012005-04-17 16:05:31 -05002024 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002025 return 0;
dea31012005-04-17 16:05:31 -05002026}
2027
James Smarte59058c2008-08-24 21:49:00 -04002028/**
James Smart3621a712009-04-06 18:47:14 -04002029 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002030 * @phba: pointer to lpfc hba data structure.
2031 * @cmdiocb: pointer to lpfc command iocb data structure.
2032 * @rspiocb: pointer to lpfc response iocb data structure.
2033 *
2034 * This routine is the completion function for issuing the ELS Logout (LOGO)
2035 * command. If no error status was reported from the LOGO response, the
2036 * state machine of the associated ndlp shall be invoked for transition with
2037 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2038 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2039 **/
dea31012005-04-17 16:05:31 -05002040static void
James Smart2e0fef82007-06-17 19:56:36 -05002041lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2042 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002043{
James Smart2e0fef82007-06-17 19:56:36 -05002044 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2045 struct lpfc_vport *vport = ndlp->vport;
2046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002047 IOCB_t *irsp;
2048 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002049
2050 psli = &phba->sli;
2051 /* we pass cmdiocb to state machine which needs rspiocb as well */
2052 cmdiocb->context_un.rsp_iocb = rspiocb;
2053
2054 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002055 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002056 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002057 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002058
James Smart858c9f62007-06-17 19:56:39 -05002059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2060 "LOGO cmpl: status:x%x/x%x did:x%x",
2061 irsp->ulpStatus, irsp->un.ulpWord[4],
2062 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002063 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002064 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2065 "0105 LOGO completes to NPort x%x "
2066 "Data: x%x x%x x%x x%x\n",
2067 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2068 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002069 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002070 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002071 goto out;
2072
James Smart92d7f7b2007-06-17 19:56:38 -05002073 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2074 /* NLP_EVT_DEVICE_RM should unregister the RPI
2075 * which should abort all outstanding IOs.
2076 */
2077 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2078 NLP_EVT_DEVICE_RM);
2079 goto out;
2080 }
2081
dea31012005-04-17 16:05:31 -05002082 if (irsp->ulpStatus) {
2083 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002084 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002085 /* ELS command is being retried */
2086 goto out;
dea31012005-04-17 16:05:31 -05002087 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002088 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2089 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2090 ndlp->nlp_DID, irsp->ulpStatus,
2091 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002092 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002093 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002094 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002095 else
James Smart2e0fef82007-06-17 19:56:36 -05002096 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002097 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002098 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002099 /* Good status, call state machine.
2100 * This will unregister the rpi if needed.
2101 */
James Smart2e0fef82007-06-17 19:56:36 -05002102 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002103 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002104out:
2105 lpfc_els_free_iocb(phba, cmdiocb);
2106 return;
2107}
2108
James Smarte59058c2008-08-24 21:49:00 -04002109/**
James Smart3621a712009-04-06 18:47:14 -04002110 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002111 * @vport: pointer to a virtual N_Port data structure.
2112 * @ndlp: pointer to a node-list data structure.
2113 * @retry: number of retries to the command IOCB.
2114 *
2115 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2116 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2117 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2118 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2119 *
2120 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2121 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2122 * will be stored into the context1 field of the IOCB for the completion
2123 * callback function to the LOGO ELS command.
2124 *
2125 * Return code
2126 * 0 - successfully issued logo
2127 * 1 - failed to issue logo
2128 **/
dea31012005-04-17 16:05:31 -05002129int
James Smart2e0fef82007-06-17 19:56:36 -05002130lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002131 uint8_t retry)
2132{
James Smart2e0fef82007-06-17 19:56:36 -05002133 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2134 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002135 IOCB_t *icmd;
2136 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002137 uint8_t *pcmd;
2138 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002139 int rc;
dea31012005-04-17 16:05:31 -05002140
James Smart98c9ea52007-10-27 13:37:33 -04002141 spin_lock_irq(shost->host_lock);
2142 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2143 spin_unlock_irq(shost->host_lock);
2144 return 0;
2145 }
2146 spin_unlock_irq(shost->host_lock);
2147
James Smart92d7f7b2007-06-17 19:56:38 -05002148 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002149 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2150 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002151 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002152 return 1;
dea31012005-04-17 16:05:31 -05002153
2154 icmd = &elsiocb->iocb;
2155 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2156 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002157 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002158
2159 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002160 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002161 pcmd += sizeof(uint32_t);
2162 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002163
James Smart858c9f62007-06-17 19:56:39 -05002164 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2165 "Issue LOGO: did:x%x",
2166 ndlp->nlp_DID, 0, 0);
2167
dea31012005-04-17 16:05:31 -05002168 phba->fc_stat.elsXmitLOGO++;
2169 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002170 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002171 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002172 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002173 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002174
2175 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002176 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002177 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002178 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002179 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002180 return 1;
dea31012005-04-17 16:05:31 -05002181 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002182 return 0;
dea31012005-04-17 16:05:31 -05002183}
2184
James Smarte59058c2008-08-24 21:49:00 -04002185/**
James Smart3621a712009-04-06 18:47:14 -04002186 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002187 * @phba: pointer to lpfc hba data structure.
2188 * @cmdiocb: pointer to lpfc command iocb data structure.
2189 * @rspiocb: pointer to lpfc response iocb data structure.
2190 *
2191 * This routine is a generic completion callback function for ELS commands.
2192 * Specifically, it is the callback function which does not need to perform
2193 * any command specific operations. It is currently used by the ELS command
2194 * issuing routines for the ELS State Change Request (SCR),
2195 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2196 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2197 * certain debug loggings, this callback function simply invokes the
2198 * lpfc_els_chk_latt() routine to check whether link went down during the
2199 * discovery process.
2200 **/
dea31012005-04-17 16:05:31 -05002201static void
James Smart2e0fef82007-06-17 19:56:36 -05002202lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2203 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002204{
James Smart2e0fef82007-06-17 19:56:36 -05002205 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002206 IOCB_t *irsp;
2207
2208 irsp = &rspiocb->iocb;
2209
James Smart858c9f62007-06-17 19:56:39 -05002210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2211 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2212 irsp->ulpStatus, irsp->un.ulpWord[4],
2213 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002214 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002215 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2216 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2217 irsp->ulpIoTag, irsp->ulpStatus,
2218 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002219 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002220 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002221 lpfc_els_free_iocb(phba, cmdiocb);
2222 return;
2223}
2224
James Smarte59058c2008-08-24 21:49:00 -04002225/**
James Smart3621a712009-04-06 18:47:14 -04002226 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002227 * @vport: pointer to a host virtual N_Port data structure.
2228 * @nportid: N_Port identifier to the remote node.
2229 * @retry: number of retries to the command IOCB.
2230 *
2231 * This routine issues a State Change Request (SCR) to a fabric node
2232 * on a @vport. The remote node @nportid is passed into the function. It
2233 * first search the @vport node list to find the matching ndlp. If no such
2234 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2235 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2236 * routine is invoked to send the SCR IOCB.
2237 *
2238 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2239 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2240 * will be stored into the context1 field of the IOCB for the completion
2241 * callback function to the SCR ELS command.
2242 *
2243 * Return code
2244 * 0 - Successfully issued scr command
2245 * 1 - Failed to issue scr command
2246 **/
dea31012005-04-17 16:05:31 -05002247int
James Smart2e0fef82007-06-17 19:56:36 -05002248lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002249{
James Smart2e0fef82007-06-17 19:56:36 -05002250 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002251 IOCB_t *icmd;
2252 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002253 struct lpfc_sli *psli;
2254 uint8_t *pcmd;
2255 uint16_t cmdsize;
2256 struct lpfc_nodelist *ndlp;
2257
2258 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002259 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002260
James Smarte47c9092008-02-08 18:49:26 -05002261 ndlp = lpfc_findnode_did(vport, nportid);
2262 if (!ndlp) {
2263 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2264 if (!ndlp)
2265 return 1;
2266 lpfc_nlp_init(vport, ndlp, nportid);
2267 lpfc_enqueue_node(vport, ndlp);
2268 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2269 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2270 if (!ndlp)
2271 return 1;
2272 }
dea31012005-04-17 16:05:31 -05002273
James Smart2e0fef82007-06-17 19:56:36 -05002274 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2275 ndlp->nlp_DID, ELS_CMD_SCR);
2276
James Smart488d1462006-03-07 15:02:37 -05002277 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002278 /* This will trigger the release of the node just
2279 * allocated
2280 */
James Smart329f9bc2007-04-25 09:53:01 -04002281 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002282 return 1;
dea31012005-04-17 16:05:31 -05002283 }
2284
2285 icmd = &elsiocb->iocb;
2286 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2287
2288 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002289 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002290
2291 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002292 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002293 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2294
James Smart858c9f62007-06-17 19:56:39 -05002295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2296 "Issue SCR: did:x%x",
2297 ndlp->nlp_DID, 0, 0);
2298
dea31012005-04-17 16:05:31 -05002299 phba->fc_stat.elsXmitSCR++;
2300 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002301 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2302 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002303 /* The additional lpfc_nlp_put will cause the following
2304 * lpfc_els_free_iocb routine to trigger the rlease of
2305 * the node.
2306 */
James Smart329f9bc2007-04-25 09:53:01 -04002307 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002308 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002309 return 1;
dea31012005-04-17 16:05:31 -05002310 }
James Smartfa4066b2008-01-11 01:53:27 -05002311 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2312 * trigger the release of node.
2313 */
James Smart329f9bc2007-04-25 09:53:01 -04002314 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002315 return 0;
dea31012005-04-17 16:05:31 -05002316}
2317
James Smarte59058c2008-08-24 21:49:00 -04002318/**
James Smart3621a712009-04-06 18:47:14 -04002319 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002320 * @vport: pointer to a host virtual N_Port data structure.
2321 * @nportid: N_Port identifier to the remote node.
2322 * @retry: number of retries to the command IOCB.
2323 *
2324 * This routine issues a Fibre Channel Address Resolution Response
2325 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2326 * is passed into the function. It first search the @vport node list to find
2327 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2328 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2329 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2330 *
2331 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2332 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2333 * will be stored into the context1 field of the IOCB for the completion
2334 * callback function to the PARPR ELS command.
2335 *
2336 * Return code
2337 * 0 - Successfully issued farpr command
2338 * 1 - Failed to issue farpr command
2339 **/
dea31012005-04-17 16:05:31 -05002340static int
James Smart2e0fef82007-06-17 19:56:36 -05002341lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002342{
James Smart2e0fef82007-06-17 19:56:36 -05002343 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002344 IOCB_t *icmd;
2345 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002346 struct lpfc_sli *psli;
2347 FARP *fp;
2348 uint8_t *pcmd;
2349 uint32_t *lp;
2350 uint16_t cmdsize;
2351 struct lpfc_nodelist *ondlp;
2352 struct lpfc_nodelist *ndlp;
2353
2354 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002355 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002356
James Smarte47c9092008-02-08 18:49:26 -05002357 ndlp = lpfc_findnode_did(vport, nportid);
2358 if (!ndlp) {
2359 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2360 if (!ndlp)
2361 return 1;
2362 lpfc_nlp_init(vport, ndlp, nportid);
2363 lpfc_enqueue_node(vport, ndlp);
2364 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2365 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2366 if (!ndlp)
2367 return 1;
2368 }
James Smart2e0fef82007-06-17 19:56:36 -05002369
2370 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2371 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002372 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002373 /* This will trigger the release of the node just
2374 * allocated
2375 */
James Smart329f9bc2007-04-25 09:53:01 -04002376 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002377 return 1;
dea31012005-04-17 16:05:31 -05002378 }
2379
2380 icmd = &elsiocb->iocb;
2381 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2382
2383 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002384 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002385
2386 /* Fill in FARPR payload */
2387 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002388 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002389 lp = (uint32_t *) pcmd;
2390 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002391 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002392 fp->Rflags = 0;
2393 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2394
James Smart92d7f7b2007-06-17 19:56:38 -05002395 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2396 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002397 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002398 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002399 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002400 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002401 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002402 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002403 }
2404
James Smart858c9f62007-06-17 19:56:39 -05002405 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2406 "Issue FARPR: did:x%x",
2407 ndlp->nlp_DID, 0, 0);
2408
dea31012005-04-17 16:05:31 -05002409 phba->fc_stat.elsXmitFARPR++;
2410 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002411 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2412 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002413 /* The additional lpfc_nlp_put will cause the following
2414 * lpfc_els_free_iocb routine to trigger the release of
2415 * the node.
2416 */
James Smart329f9bc2007-04-25 09:53:01 -04002417 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002418 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002419 return 1;
dea31012005-04-17 16:05:31 -05002420 }
James Smartfa4066b2008-01-11 01:53:27 -05002421 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2422 * trigger the release of the node.
2423 */
James Smart329f9bc2007-04-25 09:53:01 -04002424 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002425 return 0;
dea31012005-04-17 16:05:31 -05002426}
2427
James Smarte59058c2008-08-24 21:49:00 -04002428/**
James Smart3621a712009-04-06 18:47:14 -04002429 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002430 * @vport: pointer to a host virtual N_Port data structure.
2431 * @nlp: pointer to a node-list data structure.
2432 *
2433 * This routine cancels the timer with a delayed IOCB-command retry for
2434 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2435 * removes the ELS retry event if it presents. In addition, if the
2436 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2437 * commands are sent for the @vport's nodes that require issuing discovery
2438 * ADISC.
2439 **/
dea31012005-04-17 16:05:31 -05002440void
James Smart2e0fef82007-06-17 19:56:36 -05002441lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002442{
James Smart2e0fef82007-06-17 19:56:36 -05002443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002444 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002445
James Smart0d2b6b82008-06-14 22:52:47 -04002446 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2447 return;
James Smart2e0fef82007-06-17 19:56:36 -05002448 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002449 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002450 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002451 del_timer_sync(&nlp->nlp_delayfunc);
2452 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002453 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002454 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002455 /* Decrement nlp reference count held for the delayed retry */
2456 evtp = &nlp->els_retry_evt;
2457 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2458 }
James Smartfdcebe22006-03-07 15:04:01 -05002459 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002460 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002461 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002462 spin_unlock_irq(shost->host_lock);
2463 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002464 if (vport->port_state < LPFC_VPORT_READY) {
2465 /* Check if there are more ADISCs to be sent */
2466 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002467 } else {
2468 /* Check if there are more PLOGIs to be sent */
2469 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002470 if (vport->num_disc_nodes == 0) {
2471 spin_lock_irq(shost->host_lock);
2472 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2473 spin_unlock_irq(shost->host_lock);
2474 lpfc_can_disctmo(vport);
2475 lpfc_end_rscn(vport);
2476 }
James Smartfdcebe22006-03-07 15:04:01 -05002477 }
2478 }
2479 }
2480 return;
2481}
2482
James Smarte59058c2008-08-24 21:49:00 -04002483/**
James Smart3621a712009-04-06 18:47:14 -04002484 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002485 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2486 *
2487 * This routine is invoked by the ndlp delayed-function timer to check
2488 * whether there is any pending ELS retry event(s) with the node. If not, it
2489 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2490 * adds the delayed events to the HBA work list and invokes the
2491 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2492 * event. Note that lpfc_nlp_get() is called before posting the event to
2493 * the work list to hold reference count of ndlp so that it guarantees the
2494 * reference to ndlp will still be available when the worker thread gets
2495 * to the event associated with the ndlp.
2496 **/
James Smartfdcebe22006-03-07 15:04:01 -05002497void
dea31012005-04-17 16:05:31 -05002498lpfc_els_retry_delay(unsigned long ptr)
2499{
James Smart2e0fef82007-06-17 19:56:36 -05002500 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2501 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002502 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002503 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002504 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002505
James Smart92d7f7b2007-06-17 19:56:38 -05002506 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002507 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002508 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002509 return;
2510 }
2511
James Smartfa4066b2008-01-11 01:53:27 -05002512 /* We need to hold the node by incrementing the reference
2513 * count until the queued work is done
2514 */
2515 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002516 if (evtp->evt_arg1) {
2517 evtp->evt = LPFC_EVT_ELS_RETRY;
2518 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002519 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002520 }
James Smart92d7f7b2007-06-17 19:56:38 -05002521 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002522 return;
2523}
2524
James Smarte59058c2008-08-24 21:49:00 -04002525/**
James Smart3621a712009-04-06 18:47:14 -04002526 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002527 * @ndlp: pointer to a node-list data structure.
2528 *
2529 * This routine is the worker-thread handler for processing the @ndlp delayed
2530 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2531 * the last ELS command from the associated ndlp and invokes the proper ELS
2532 * function according to the delayed ELS command to retry the command.
2533 **/
dea31012005-04-17 16:05:31 -05002534void
2535lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2536{
James Smart2e0fef82007-06-17 19:56:36 -05002537 struct lpfc_vport *vport = ndlp->vport;
2538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2539 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002540
James Smart2e0fef82007-06-17 19:56:36 -05002541 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002542 did = ndlp->nlp_DID;
2543 cmd = ndlp->nlp_last_elscmd;
2544 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002545
2546 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002547 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002548 return;
2549 }
2550
2551 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002552 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002553 /*
2554 * If a discovery event readded nlp_delayfunc after timer
2555 * firing and before processing the timer, cancel the
2556 * nlp_delayfunc.
2557 */
2558 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002559 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002560 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002561
2562 switch (cmd) {
2563 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002564 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002565 break;
2566 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002567 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002568 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002569 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002570 }
dea31012005-04-17 16:05:31 -05002571 break;
2572 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002573 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002574 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002575 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002576 }
dea31012005-04-17 16:05:31 -05002577 break;
2578 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002579 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002580 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002581 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002582 }
dea31012005-04-17 16:05:31 -05002583 break;
2584 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002585 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002586 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002587 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002588 }
dea31012005-04-17 16:05:31 -05002589 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002590 case ELS_CMD_FDISC:
2591 lpfc_issue_els_fdisc(vport, ndlp, retry);
2592 break;
dea31012005-04-17 16:05:31 -05002593 }
2594 return;
2595}
2596
James Smarte59058c2008-08-24 21:49:00 -04002597/**
James Smart3621a712009-04-06 18:47:14 -04002598 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002599 * @phba: pointer to lpfc hba data structure.
2600 * @cmdiocb: pointer to lpfc command iocb data structure.
2601 * @rspiocb: pointer to lpfc response iocb data structure.
2602 *
2603 * This routine makes a retry decision on an ELS command IOCB, which has
2604 * failed. The following ELS IOCBs use this function for retrying the command
2605 * when previously issued command responsed with error status: FLOGI, PLOGI,
2606 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2607 * returned error status, it makes the decision whether a retry shall be
2608 * issued for the command, and whether a retry shall be made immediately or
2609 * delayed. In the former case, the corresponding ELS command issuing-function
2610 * is called to retry the command. In the later case, the ELS command shall
2611 * be posted to the ndlp delayed event and delayed function timer set to the
2612 * ndlp for the delayed command issusing.
2613 *
2614 * Return code
2615 * 0 - No retry of els command is made
2616 * 1 - Immediate or delayed retry of els command is made
2617 **/
dea31012005-04-17 16:05:31 -05002618static int
James Smart2e0fef82007-06-17 19:56:36 -05002619lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2620 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002621{
James Smart2e0fef82007-06-17 19:56:36 -05002622 struct lpfc_vport *vport = cmdiocb->vport;
2623 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2624 IOCB_t *irsp = &rspiocb->iocb;
2625 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2626 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002627 uint32_t *elscmd;
2628 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002629 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002630 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002631 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002632 uint32_t did;
dea31012005-04-17 16:05:31 -05002633
James Smart488d1462006-03-07 15:02:37 -05002634
dea31012005-04-17 16:05:31 -05002635 /* Note: context2 may be 0 for internal driver abort
2636 * of delays ELS command.
2637 */
2638
2639 if (pcmd && pcmd->virt) {
2640 elscmd = (uint32_t *) (pcmd->virt);
2641 cmd = *elscmd++;
2642 }
2643
James Smarte47c9092008-02-08 18:49:26 -05002644 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002645 did = ndlp->nlp_DID;
2646 else {
2647 /* We should only hit this case for retrying PLOGI */
2648 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002649 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002650 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2651 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002652 return 1;
2653 }
2654
James Smart858c9f62007-06-17 19:56:39 -05002655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2656 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2657 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2658
dea31012005-04-17 16:05:31 -05002659 switch (irsp->ulpStatus) {
2660 case IOSTAT_FCP_RSP_ERROR:
2661 case IOSTAT_REMOTE_STOP:
2662 break;
2663
2664 case IOSTAT_LOCAL_REJECT:
2665 switch ((irsp->un.ulpWord[4] & 0xff)) {
2666 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002667 if (cmd == ELS_CMD_FLOGI) {
2668 if (PCI_DEVICE_ID_HORNET ==
2669 phba->pcidev->device) {
2670 phba->fc_topology = TOPOLOGY_LOOP;
2671 phba->pport->fc_myDID = 0;
2672 phba->alpa_map[0] = 0;
2673 phba->alpa_map[1] = 0;
2674 }
2675 }
James Smart2e0fef82007-06-17 19:56:36 -05002676 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002677 delay = 1000;
dea31012005-04-17 16:05:31 -05002678 retry = 1;
2679 break;
2680
James Smart92d7f7b2007-06-17 19:56:38 -05002681 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002682 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2683 "0124 Retry illegal cmd x%x "
2684 "retry:x%x delay:x%x\n",
2685 cmd, cmdiocb->retry, delay);
2686 retry = 1;
2687 /* All command's retry policy */
2688 maxretry = 8;
2689 if (cmdiocb->retry > 2)
2690 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002691 break;
2692
dea31012005-04-17 16:05:31 -05002693 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002694 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002695 retry = 1;
2696 if (cmdiocb->retry > 100)
2697 delay = 100;
2698 maxretry = 250;
2699 break;
2700
2701 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002702 delay = 100;
dea31012005-04-17 16:05:31 -05002703 retry = 1;
2704 break;
2705
James Smart858c9f62007-06-17 19:56:39 -05002706 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002707 case IOERR_INVALID_RPI:
2708 retry = 1;
2709 break;
2710 }
2711 break;
2712
2713 case IOSTAT_NPORT_RJT:
2714 case IOSTAT_FABRIC_RJT:
2715 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2716 retry = 1;
2717 break;
2718 }
2719 break;
2720
2721 case IOSTAT_NPORT_BSY:
2722 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002723 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002724 retry = 1;
2725 break;
2726
2727 case IOSTAT_LS_RJT:
2728 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2729 /* Added for Vendor specifc support
2730 * Just keep retrying for these Rsn / Exp codes
2731 */
2732 switch (stat.un.b.lsRjtRsnCode) {
2733 case LSRJT_UNABLE_TPC:
2734 if (stat.un.b.lsRjtRsnCodeExp ==
2735 LSEXP_CMD_IN_PROGRESS) {
2736 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002737 delay = 1000;
dea31012005-04-17 16:05:31 -05002738 maxretry = 48;
2739 }
2740 retry = 1;
2741 break;
2742 }
2743 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002744 delay = 1000;
dea31012005-04-17 16:05:31 -05002745 maxretry = lpfc_max_els_tries + 1;
2746 retry = 1;
2747 break;
2748 }
James Smart92d7f7b2007-06-17 19:56:38 -05002749 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2750 (cmd == ELS_CMD_FDISC) &&
2751 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002752 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2753 "0125 FDISC Failed (x%x). "
2754 "Fabric out of resources\n",
2755 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002756 lpfc_vport_set_state(vport,
2757 FC_VPORT_NO_FABRIC_RSCS);
2758 }
dea31012005-04-17 16:05:31 -05002759 break;
2760
2761 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002762 if ((cmd == ELS_CMD_PLOGI) ||
2763 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002764 delay = 1000;
dea31012005-04-17 16:05:31 -05002765 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002766 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002767 /* FDISC retry policy */
2768 maxretry = 48;
2769 if (cmdiocb->retry >= 32)
2770 delay = 1000;
dea31012005-04-17 16:05:31 -05002771 }
2772 retry = 1;
2773 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002774
2775 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002776 /* There are some cases where switches return this
2777 * error when they are not ready and should be returning
2778 * Logical Busy. We should delay every time.
2779 */
2780 if (cmd == ELS_CMD_FDISC &&
2781 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2782 maxretry = 3;
2783 delay = 1000;
2784 retry = 1;
2785 break;
2786 }
James Smart92d7f7b2007-06-17 19:56:38 -05002787 case LSRJT_PROTOCOL_ERR:
2788 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2789 (cmd == ELS_CMD_FDISC) &&
2790 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2791 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2792 ) {
James Smarte8b62012007-08-02 11:10:09 -04002793 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002794 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002795 "Fabric Detected Bad WWN\n",
2796 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002797 lpfc_vport_set_state(vport,
2798 FC_VPORT_FABRIC_REJ_WWN);
2799 }
2800 break;
dea31012005-04-17 16:05:31 -05002801 }
2802 break;
2803
2804 case IOSTAT_INTERMED_RSP:
2805 case IOSTAT_BA_RJT:
2806 break;
2807
2808 default:
2809 break;
2810 }
2811
James Smart488d1462006-03-07 15:02:37 -05002812 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002813 retry = 1;
dea31012005-04-17 16:05:31 -05002814
James Smart695a8142010-01-26 23:08:03 -05002815 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002816 (phba->fc_topology != TOPOLOGY_LOOP) &&
2817 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002818 /* FLOGI retry policy */
2819 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002820 /* retry forever */
2821 maxretry = 0;
2822 if (cmdiocb->retry >= 100)
2823 delay = 5000;
2824 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002825 delay = 1000;
2826 }
2827
James Smart6669f9b2009-10-02 15:16:45 -04002828 cmdiocb->retry++;
2829 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002830 phba->fc_stat.elsRetryExceeded++;
2831 retry = 0;
2832 }
2833
James Smarted957682007-06-17 19:56:37 -05002834 if ((vport->load_flag & FC_UNLOADING) != 0)
2835 retry = 0;
2836
dea31012005-04-17 16:05:31 -05002837 if (retry) {
2838
2839 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002840 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2841 "0107 Retry ELS command x%x to remote "
2842 "NPORT x%x Data: x%x x%x\n",
2843 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002844
James Smart858c9f62007-06-17 19:56:39 -05002845 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2846 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2847 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2848 /* Don't reset timer for no resources */
2849
dea31012005-04-17 16:05:31 -05002850 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002851 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002852 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002853 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002854 }
2855
2856 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002857 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002858 phba->fc_stat.elsDelayRetry++;
2859 ndlp->nlp_retry = cmdiocb->retry;
2860
James Smart92d7f7b2007-06-17 19:56:38 -05002861 /* delay is specified in milliseconds */
2862 mod_timer(&ndlp->nlp_delayfunc,
2863 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002864 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002865 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002866 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002867
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002868 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002869 if (cmd == ELS_CMD_PRLI)
2870 lpfc_nlp_set_state(vport, ndlp,
2871 NLP_STE_REG_LOGIN_ISSUE);
2872 else
2873 lpfc_nlp_set_state(vport, ndlp,
2874 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002875 ndlp->nlp_last_elscmd = cmd;
2876
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002877 return 1;
dea31012005-04-17 16:05:31 -05002878 }
2879 switch (cmd) {
2880 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002881 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002882 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002883 case ELS_CMD_FDISC:
2884 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2885 return 1;
dea31012005-04-17 16:05:31 -05002886 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002887 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002888 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002889 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002890 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002891 }
James Smart2e0fef82007-06-17 19:56:36 -05002892 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002893 return 1;
dea31012005-04-17 16:05:31 -05002894 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002895 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002896 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2897 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002898 return 1;
dea31012005-04-17 16:05:31 -05002899 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002900 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002901 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2902 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002903 return 1;
dea31012005-04-17 16:05:31 -05002904 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002905 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002906 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2907 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002908 return 1;
dea31012005-04-17 16:05:31 -05002909 }
2910 }
dea31012005-04-17 16:05:31 -05002911 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002912 if (logerr) {
2913 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2914 "0137 No retry ELS command x%x to remote "
2915 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2916 cmd, did, irsp->ulpStatus,
2917 irsp->un.ulpWord[4]);
2918 }
2919 else {
2920 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002921 "0108 No retry ELS command x%x to remote "
2922 "NPORT x%x Retried:%d Error:x%x/%x\n",
2923 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2924 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002925 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002926 return 0;
dea31012005-04-17 16:05:31 -05002927}
2928
James Smarte59058c2008-08-24 21:49:00 -04002929/**
James Smart3621a712009-04-06 18:47:14 -04002930 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002931 * @phba: pointer to lpfc hba data structure.
2932 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2933 *
2934 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2935 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2936 * checks to see whether there is a lpfc DMA buffer associated with the
2937 * response of the command IOCB. If so, it will be released before releasing
2938 * the lpfc DMA buffer associated with the IOCB itself.
2939 *
2940 * Return code
2941 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2942 **/
James Smart09372822008-01-11 01:52:54 -05002943static int
James Smart87af33f2007-10-27 13:37:43 -04002944lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2945{
2946 struct lpfc_dmabuf *buf_ptr;
2947
James Smarte59058c2008-08-24 21:49:00 -04002948 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002949 if (!list_empty(&buf_ptr1->list)) {
2950 list_remove_head(&buf_ptr1->list, buf_ptr,
2951 struct lpfc_dmabuf,
2952 list);
2953 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2954 kfree(buf_ptr);
2955 }
2956 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2957 kfree(buf_ptr1);
2958 return 0;
2959}
2960
James Smarte59058c2008-08-24 21:49:00 -04002961/**
James Smart3621a712009-04-06 18:47:14 -04002962 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002963 * @phba: pointer to lpfc hba data structure.
2964 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2965 *
2966 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2967 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2968 * pool.
2969 *
2970 * Return code
2971 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2972 **/
James Smart09372822008-01-11 01:52:54 -05002973static int
James Smart87af33f2007-10-27 13:37:43 -04002974lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2975{
2976 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2977 kfree(buf_ptr);
2978 return 0;
2979}
2980
James Smarte59058c2008-08-24 21:49:00 -04002981/**
James Smart3621a712009-04-06 18:47:14 -04002982 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002983 * @phba: pointer to lpfc hba data structure.
2984 * @elsiocb: pointer to lpfc els command iocb data structure.
2985 *
2986 * This routine frees a command IOCB and its associated resources. The
2987 * command IOCB data structure contains the reference to various associated
2988 * resources, these fields must be set to NULL if the associated reference
2989 * not present:
2990 * context1 - reference to ndlp
2991 * context2 - reference to cmd
2992 * context2->next - reference to rsp
2993 * context3 - reference to bpl
2994 *
2995 * It first properly decrements the reference count held on ndlp for the
2996 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2997 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2998 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2999 * adds the DMA buffer the @phba data structure for the delayed release.
3000 * If reference to the Buffer Pointer List (BPL) is present, the
3001 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3002 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3003 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3004 *
3005 * Return code
3006 * 0 - Success (currently, always return 0)
3007 **/
James Smart87af33f2007-10-27 13:37:43 -04003008int
James Smart329f9bc2007-04-25 09:53:01 -04003009lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003010{
3011 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003012 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003013
James Smarta8adb832007-10-27 13:37:53 -04003014 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3015 if (ndlp) {
3016 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3017 lpfc_nlp_put(ndlp);
3018
3019 /* If the ndlp is not being used by another discovery
3020 * thread, free it.
3021 */
3022 if (!lpfc_nlp_not_used(ndlp)) {
3023 /* If ndlp is being used by another discovery
3024 * thread, just clear NLP_DEFER_RM
3025 */
3026 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3027 }
3028 }
3029 else
3030 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003031 elsiocb->context1 = NULL;
3032 }
dea31012005-04-17 16:05:31 -05003033 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3034 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003035 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3036 /* Firmware could still be in progress of DMAing
3037 * payload, so don't free data buffer till after
3038 * a hbeat.
3039 */
3040 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3041 buf_ptr = elsiocb->context2;
3042 elsiocb->context2 = NULL;
3043 if (buf_ptr) {
3044 buf_ptr1 = NULL;
3045 spin_lock_irq(&phba->hbalock);
3046 if (!list_empty(&buf_ptr->list)) {
3047 list_remove_head(&buf_ptr->list,
3048 buf_ptr1, struct lpfc_dmabuf,
3049 list);
3050 INIT_LIST_HEAD(&buf_ptr1->list);
3051 list_add_tail(&buf_ptr1->list,
3052 &phba->elsbuf);
3053 phba->elsbuf_cnt++;
3054 }
3055 INIT_LIST_HEAD(&buf_ptr->list);
3056 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3057 phba->elsbuf_cnt++;
3058 spin_unlock_irq(&phba->hbalock);
3059 }
3060 } else {
3061 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3062 lpfc_els_free_data(phba, buf_ptr1);
3063 }
dea31012005-04-17 16:05:31 -05003064 }
3065
3066 if (elsiocb->context3) {
3067 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003068 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003069 }
James Bottomley604a3e32005-10-29 10:28:33 -05003070 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003071 return 0;
3072}
3073
James Smarte59058c2008-08-24 21:49:00 -04003074/**
James Smart3621a712009-04-06 18:47:14 -04003075 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003076 * @phba: pointer to lpfc hba data structure.
3077 * @cmdiocb: pointer to lpfc command iocb data structure.
3078 * @rspiocb: pointer to lpfc response iocb data structure.
3079 *
3080 * This routine is the completion callback function to the Logout (LOGO)
3081 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3082 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3083 * release the ndlp if it has the last reference remaining (reference count
3084 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3085 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3086 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3087 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3088 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3089 * IOCB data structure.
3090 **/
dea31012005-04-17 16:05:31 -05003091static void
James Smart2e0fef82007-06-17 19:56:36 -05003092lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3093 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003094{
James Smart2e0fef82007-06-17 19:56:36 -05003095 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3096 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003097 IOCB_t *irsp;
3098
3099 irsp = &rspiocb->iocb;
3100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3101 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3102 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003103 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003104 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3105 "0109 ACC to LOGO completes to NPort x%x "
3106 "Data: x%x x%x x%x\n",
3107 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3108 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003109
3110 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3111 /* NPort Recovery mode or node is just allocated */
3112 if (!lpfc_nlp_not_used(ndlp)) {
3113 /* If the ndlp is being used by another discovery
3114 * thread, just unregister the RPI.
3115 */
3116 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003117 } else {
3118 /* Indicate the node has already released, should
3119 * not reference to it from within lpfc_els_free_iocb.
3120 */
3121 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003122 }
dea31012005-04-17 16:05:31 -05003123 }
3124 lpfc_els_free_iocb(phba, cmdiocb);
3125 return;
3126}
3127
James Smarte59058c2008-08-24 21:49:00 -04003128/**
James Smart3621a712009-04-06 18:47:14 -04003129 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003130 * @phba: pointer to lpfc hba data structure.
3131 * @pmb: pointer to the driver internal queue element for mailbox command.
3132 *
3133 * This routine is the completion callback function for unregister default
3134 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3135 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3136 * decrements the ndlp reference count held for this completion callback
3137 * function. After that, it invokes the lpfc_nlp_not_used() to check
3138 * whether there is only one reference left on the ndlp. If so, it will
3139 * perform one more decrement and trigger the release of the ndlp.
3140 **/
James Smart858c9f62007-06-17 19:56:39 -05003141void
3142lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3143{
3144 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3145 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3146
James Smart6fb120a2009-05-22 14:52:59 -04003147 /*
3148 * This routine is used to register and unregister in previous SLI
3149 * modes.
3150 */
3151 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3152 (phba->sli_rev == LPFC_SLI_REV4))
3153 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3154
James Smart858c9f62007-06-17 19:56:39 -05003155 pmb->context1 = NULL;
3156 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3157 kfree(mp);
3158 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003159 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003160 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003161 /* This is the end of the default RPI cleanup logic for this
3162 * ndlp. If no other discovery threads are using this ndlp.
3163 * we should free all resources associated with it.
3164 */
3165 lpfc_nlp_not_used(ndlp);
3166 }
James Smart3772a992009-05-22 14:50:54 -04003167
James Smart858c9f62007-06-17 19:56:39 -05003168 return;
3169}
3170
James Smarte59058c2008-08-24 21:49:00 -04003171/**
James Smart3621a712009-04-06 18:47:14 -04003172 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003173 * @phba: pointer to lpfc hba data structure.
3174 * @cmdiocb: pointer to lpfc command iocb data structure.
3175 * @rspiocb: pointer to lpfc response iocb data structure.
3176 *
3177 * This routine is the completion callback function for ELS Response IOCB
3178 * command. In normal case, this callback function just properly sets the
3179 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3180 * field in the command IOCB is not NULL, the referred mailbox command will
3181 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3182 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3183 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3184 * routine shall be invoked trying to release the ndlp if no other threads
3185 * are currently referring it.
3186 **/
dea31012005-04-17 16:05:31 -05003187static void
James Smart858c9f62007-06-17 19:56:39 -05003188lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003189 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003190{
James Smart2e0fef82007-06-17 19:56:36 -05003191 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3192 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3193 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003194 IOCB_t *irsp;
3195 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003196 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003197 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003198 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003199
James Smart33ccf8d2006-08-17 11:57:58 -04003200 irsp = &rspiocb->iocb;
3201
dea31012005-04-17 16:05:31 -05003202 if (cmdiocb->context_un.mbox)
3203 mbox = cmdiocb->context_un.mbox;
3204
James Smartfa4066b2008-01-11 01:53:27 -05003205 /* First determine if this is a LS_RJT cmpl. Note, this callback
3206 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3207 */
James Smart87af33f2007-10-27 13:37:43 -04003208 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003209 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3210 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003211 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003212 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003213 */
3214 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3215 ls_rjt = 1;
3216 }
3217
dea31012005-04-17 16:05:31 -05003218 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003219 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003220 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003221 mp = (struct lpfc_dmabuf *) mbox->context1;
3222 if (mp) {
3223 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3224 kfree(mp);
3225 }
James Smart329f9bc2007-04-25 09:53:01 -04003226 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003227 }
James Smart58da1ff2008-04-07 10:15:56 -04003228 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3229 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003230 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003231 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003232 /* Indicate the node has already released,
3233 * should not reference to it from within
3234 * the routine lpfc_els_free_iocb.
3235 */
3236 cmdiocb->context1 = NULL;
3237 }
dea31012005-04-17 16:05:31 -05003238 goto out;
3239 }
3240
James Smart858c9f62007-06-17 19:56:39 -05003241 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003242 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003243 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003244 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003245 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003246 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3247 "0110 ELS response tag x%x completes "
3248 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3249 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3250 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3251 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3252 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003253 if (mbox) {
3254 if ((rspiocb->iocb.ulpStatus == 0)
3255 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003256 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003257 /* Increment reference count to ndlp to hold the
3258 * reference to ndlp for the callback function.
3259 */
James Smart329f9bc2007-04-25 09:53:01 -04003260 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003261 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003262 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3263 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3264 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3265 }
3266 else {
3267 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3268 ndlp->nlp_prev_state = ndlp->nlp_state;
3269 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003270 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003271 }
James Smart0b727fe2007-10-27 13:37:25 -04003272 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003273 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003274 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003275 else
3276 /* Decrement the ndlp reference count we
3277 * set for this failed mailbox command.
3278 */
3279 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003280
3281 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3282 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3283 "0138 ELS rsp: Cannot issue reg_login for x%x "
3284 "Data: x%x x%x x%x\n",
3285 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3286 ndlp->nlp_rpi);
3287
James Smartfa4066b2008-01-11 01:53:27 -05003288 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003289 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003290 /* Indicate node has already been released,
3291 * should not reference to it from within
3292 * the routine lpfc_els_free_iocb.
3293 */
3294 cmdiocb->context1 = NULL;
3295 }
dea31012005-04-17 16:05:31 -05003296 } else {
James Smart858c9f62007-06-17 19:56:39 -05003297 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3298 if (!lpfc_error_lost_link(irsp) &&
3299 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003300 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003301 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003302 /* Indicate node has already been
3303 * released, should not reference
3304 * to it from within the routine
3305 * lpfc_els_free_iocb.
3306 */
3307 cmdiocb->context1 = NULL;
3308 }
dea31012005-04-17 16:05:31 -05003309 }
3310 }
James Smart14691152006-12-02 13:34:28 -05003311 mp = (struct lpfc_dmabuf *) mbox->context1;
3312 if (mp) {
3313 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3314 kfree(mp);
3315 }
3316 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003317 }
3318out:
James Smart58da1ff2008-04-07 10:15:56 -04003319 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003320 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003321 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003322 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003323
3324 /* If the node is not being used by another discovery thread,
3325 * and we are sending a reject, we are done with it.
3326 * Release driver reference count here and free associated
3327 * resources.
3328 */
3329 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003330 if (lpfc_nlp_not_used(ndlp))
3331 /* Indicate node has already been released,
3332 * should not reference to it from within
3333 * the routine lpfc_els_free_iocb.
3334 */
3335 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003336 }
James Smart87af33f2007-10-27 13:37:43 -04003337
dea31012005-04-17 16:05:31 -05003338 lpfc_els_free_iocb(phba, cmdiocb);
3339 return;
3340}
3341
James Smarte59058c2008-08-24 21:49:00 -04003342/**
James Smart3621a712009-04-06 18:47:14 -04003343 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003344 * @vport: pointer to a host virtual N_Port data structure.
3345 * @flag: the els command code to be accepted.
3346 * @oldiocb: pointer to the original lpfc command iocb data structure.
3347 * @ndlp: pointer to a node-list data structure.
3348 * @mbox: pointer to the driver internal queue element for mailbox command.
3349 *
3350 * This routine prepares and issues an Accept (ACC) response IOCB
3351 * command. It uses the @flag to properly set up the IOCB field for the
3352 * specific ACC response command to be issued and invokes the
3353 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3354 * @mbox pointer is passed in, it will be put into the context_un.mbox
3355 * field of the IOCB for the completion callback function to issue the
3356 * mailbox command to the HBA later when callback is invoked.
3357 *
3358 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3359 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3360 * will be stored into the context1 field of the IOCB for the completion
3361 * callback function to the corresponding response ELS IOCB command.
3362 *
3363 * Return code
3364 * 0 - Successfully issued acc response
3365 * 1 - Failed to issue acc response
3366 **/
dea31012005-04-17 16:05:31 -05003367int
James Smart2e0fef82007-06-17 19:56:36 -05003368lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3369 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003370 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003371{
James Smart2e0fef82007-06-17 19:56:36 -05003372 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3373 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003374 IOCB_t *icmd;
3375 IOCB_t *oldcmd;
3376 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003377 struct lpfc_sli *psli;
3378 uint8_t *pcmd;
3379 uint16_t cmdsize;
3380 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003381 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003382
3383 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003384 oldcmd = &oldiocb->iocb;
3385
3386 switch (flag) {
3387 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003388 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003389 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3390 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003391 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003392 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003393 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003394 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003395 return 1;
dea31012005-04-17 16:05:31 -05003396 }
James Smart2e0fef82007-06-17 19:56:36 -05003397
dea31012005-04-17 16:05:31 -05003398 icmd = &elsiocb->iocb;
3399 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3400 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3401 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003402 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003403
3404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3405 "Issue ACC: did:x%x flg:x%x",
3406 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003407 break;
3408 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003409 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003410 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3411 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003412 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003413 return 1;
James Smart488d1462006-03-07 15:02:37 -05003414
dea31012005-04-17 16:05:31 -05003415 icmd = &elsiocb->iocb;
3416 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3417 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3418
3419 if (mbox)
3420 elsiocb->context_un.mbox = mbox;
3421
3422 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003423 pcmd += sizeof(uint32_t);
3424 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003425
3426 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3427 "Issue ACC PLOGI: did:x%x flg:x%x",
3428 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003429 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003430 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003431 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003432 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003433 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3434 if (!elsiocb)
3435 return 1;
3436
3437 icmd = &elsiocb->iocb;
3438 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3439 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3440
3441 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003442 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003443 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3444 els_pkt_ptr = (ELS_PKT *) pcmd;
3445 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003446
3447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3448 "Issue ACC PRLO: did:x%x flg:x%x",
3449 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003450 break;
dea31012005-04-17 16:05:31 -05003451 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003452 return 1;
dea31012005-04-17 16:05:31 -05003453 }
dea31012005-04-17 16:05:31 -05003454 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003455 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3456 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3457 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3458 elsiocb->iotag, elsiocb->iocb.ulpContext,
3459 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3460 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003461 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003462 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003463 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003464 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003465 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3466 } else {
James Smart858c9f62007-06-17 19:56:39 -05003467 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003468 }
3469
3470 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003471 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003472 if (rc == IOCB_ERROR) {
3473 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003474 return 1;
dea31012005-04-17 16:05:31 -05003475 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003476 return 0;
dea31012005-04-17 16:05:31 -05003477}
3478
James Smarte59058c2008-08-24 21:49:00 -04003479/**
James Smart3621a712009-04-06 18:47:14 -04003480 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003481 * @vport: pointer to a virtual N_Port data structure.
3482 * @rejectError:
3483 * @oldiocb: pointer to the original lpfc command iocb data structure.
3484 * @ndlp: pointer to a node-list data structure.
3485 * @mbox: pointer to the driver internal queue element for mailbox command.
3486 *
3487 * This routine prepares and issue an Reject (RJT) response IOCB
3488 * command. If a @mbox pointer is passed in, it will be put into the
3489 * context_un.mbox field of the IOCB for the completion callback function
3490 * to issue to the HBA later.
3491 *
3492 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3493 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3494 * will be stored into the context1 field of the IOCB for the completion
3495 * callback function to the reject response ELS IOCB command.
3496 *
3497 * Return code
3498 * 0 - Successfully issued reject response
3499 * 1 - Failed to issue reject response
3500 **/
dea31012005-04-17 16:05:31 -05003501int
James Smart2e0fef82007-06-17 19:56:36 -05003502lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003503 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3504 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003505{
James Smart2e0fef82007-06-17 19:56:36 -05003506 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003507 IOCB_t *icmd;
3508 IOCB_t *oldcmd;
3509 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003510 struct lpfc_sli *psli;
3511 uint8_t *pcmd;
3512 uint16_t cmdsize;
3513 int rc;
3514
3515 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003516 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003517 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3518 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003519 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003520 return 1;
dea31012005-04-17 16:05:31 -05003521
3522 icmd = &elsiocb->iocb;
3523 oldcmd = &oldiocb->iocb;
3524 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3525 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3526
3527 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003528 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003529 *((uint32_t *) (pcmd)) = rejectError;
3530
James Smart51ef4c22007-08-02 11:10:31 -04003531 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003532 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003533
dea31012005-04-17 16:05:31 -05003534 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003535 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3536 "0129 Xmit ELS RJT x%x response tag x%x "
3537 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3538 "rpi x%x\n",
3539 rejectError, elsiocb->iotag,
3540 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3541 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003542 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3543 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3544 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3545
dea31012005-04-17 16:05:31 -05003546 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003547 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003548 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003549
dea31012005-04-17 16:05:31 -05003550 if (rc == IOCB_ERROR) {
3551 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003552 return 1;
dea31012005-04-17 16:05:31 -05003553 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003554 return 0;
dea31012005-04-17 16:05:31 -05003555}
3556
James Smarte59058c2008-08-24 21:49:00 -04003557/**
James Smart3621a712009-04-06 18:47:14 -04003558 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003559 * @vport: pointer to a virtual N_Port data structure.
3560 * @oldiocb: pointer to the original lpfc command iocb data structure.
3561 * @ndlp: pointer to a node-list data structure.
3562 *
3563 * This routine prepares and issues an Accept (ACC) response to Address
3564 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3565 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3566 *
3567 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3568 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3569 * will be stored into the context1 field of the IOCB for the completion
3570 * callback function to the ADISC Accept response ELS IOCB command.
3571 *
3572 * Return code
3573 * 0 - Successfully issued acc adisc response
3574 * 1 - Failed to issue adisc acc response
3575 **/
dea31012005-04-17 16:05:31 -05003576int
James Smart2e0fef82007-06-17 19:56:36 -05003577lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3578 struct lpfc_nodelist *ndlp)
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 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003582 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003583 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003584 uint8_t *pcmd;
3585 uint16_t cmdsize;
3586 int rc;
3587
James Smart92d7f7b2007-06-17 19:56:38 -05003588 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003589 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3590 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003591 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003592 return 1;
dea31012005-04-17 16:05:31 -05003593
dea31012005-04-17 16:05:31 -05003594 icmd = &elsiocb->iocb;
3595 oldcmd = &oldiocb->iocb;
3596 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003597
3598 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003599 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3600 "0130 Xmit ADISC ACC response iotag x%x xri: "
3601 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3602 elsiocb->iotag, elsiocb->iocb.ulpContext,
3603 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3604 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003605 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3606
3607 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003608 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003609
3610 ap = (ADISC *) (pcmd);
3611 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003612 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3613 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003614 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003615
James Smart858c9f62007-06-17 19:56:39 -05003616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3617 "Issue ACC ADISC: did:x%x flg:x%x",
3618 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3619
dea31012005-04-17 16:05:31 -05003620 phba->fc_stat.elsXmitACC++;
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);
dea31012005-04-17 16:05:31 -05003623 if (rc == IOCB_ERROR) {
3624 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003625 return 1;
dea31012005-04-17 16:05:31 -05003626 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003627 return 0;
dea31012005-04-17 16:05:31 -05003628}
3629
James Smarte59058c2008-08-24 21:49:00 -04003630/**
James Smart3621a712009-04-06 18:47:14 -04003631 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003632 * @vport: pointer to a virtual N_Port data structure.
3633 * @oldiocb: pointer to the original lpfc command iocb data structure.
3634 * @ndlp: pointer to a node-list data structure.
3635 *
3636 * This routine prepares and issues an Accept (ACC) response to Process
3637 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3638 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3639 *
3640 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3641 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3642 * will be stored into the context1 field of the IOCB for the completion
3643 * callback function to the PRLI Accept response ELS IOCB command.
3644 *
3645 * Return code
3646 * 0 - Successfully issued acc prli response
3647 * 1 - Failed to issue acc prli response
3648 **/
dea31012005-04-17 16:05:31 -05003649int
James Smart2e0fef82007-06-17 19:56:36 -05003650lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003651 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003652{
James Smart2e0fef82007-06-17 19:56:36 -05003653 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003654 PRLI *npr;
3655 lpfc_vpd_t *vpd;
3656 IOCB_t *icmd;
3657 IOCB_t *oldcmd;
3658 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003659 struct lpfc_sli *psli;
3660 uint8_t *pcmd;
3661 uint16_t cmdsize;
3662 int rc;
3663
3664 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003665
James Smart92d7f7b2007-06-17 19:56:38 -05003666 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003667 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003668 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003669 if (!elsiocb)
3670 return 1;
dea31012005-04-17 16:05:31 -05003671
dea31012005-04-17 16:05:31 -05003672 icmd = &elsiocb->iocb;
3673 oldcmd = &oldiocb->iocb;
3674 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003675 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003676 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3677 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3678 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3679 elsiocb->iotag, elsiocb->iocb.ulpContext,
3680 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3681 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003682 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3683
3684 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003685 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003686
3687 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003688 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003689
3690 npr = (PRLI *) pcmd;
3691 vpd = &phba->vpd;
3692 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003693 * If the remote port is a target and our firmware version is 3.20 or
3694 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003695 */
James Smart0d2b6b82008-06-14 22:52:47 -04003696 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3697 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003698 npr->ConfmComplAllowed = 1;
3699 npr->Retry = 1;
3700 npr->TaskRetryIdReq = 1;
3701 }
3702
3703 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3704 npr->estabImagePair = 1;
3705 npr->readXferRdyDis = 1;
3706 npr->ConfmComplAllowed = 1;
3707
3708 npr->prliType = PRLI_FCP_TYPE;
3709 npr->initiatorFunc = 1;
3710
James Smart858c9f62007-06-17 19:56:39 -05003711 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3712 "Issue ACC PRLI: did:x%x flg:x%x",
3713 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3714
dea31012005-04-17 16:05:31 -05003715 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003716 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003717
James Smart3772a992009-05-22 14:50:54 -04003718 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003719 if (rc == IOCB_ERROR) {
3720 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003721 return 1;
dea31012005-04-17 16:05:31 -05003722 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003723 return 0;
dea31012005-04-17 16:05:31 -05003724}
3725
James Smarte59058c2008-08-24 21:49:00 -04003726/**
James Smart3621a712009-04-06 18:47:14 -04003727 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003728 * @vport: pointer to a virtual N_Port data structure.
3729 * @format: rnid command format.
3730 * @oldiocb: pointer to the original lpfc command iocb data structure.
3731 * @ndlp: pointer to a node-list data structure.
3732 *
3733 * This routine issues a Request Node Identification Data (RNID) Accept
3734 * (ACC) response. It constructs the RNID ACC response command according to
3735 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3736 * issue the response. Note that this command does not need to hold the ndlp
3737 * reference count for the callback. So, the ndlp reference count taken by
3738 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3739 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3740 * there is no ndlp reference available.
3741 *
3742 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3743 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3744 * will be stored into the context1 field of the IOCB for the completion
3745 * callback function. However, for the RNID Accept Response ELS command,
3746 * this is undone later by this routine after the IOCB is allocated.
3747 *
3748 * Return code
3749 * 0 - Successfully issued acc rnid response
3750 * 1 - Failed to issue acc rnid response
3751 **/
dea31012005-04-17 16:05:31 -05003752static int
James Smart2e0fef82007-06-17 19:56:36 -05003753lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003754 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003755{
James Smart2e0fef82007-06-17 19:56:36 -05003756 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003757 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003758 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003759 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003760 struct lpfc_sli *psli;
3761 uint8_t *pcmd;
3762 uint16_t cmdsize;
3763 int rc;
3764
3765 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003766 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3767 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003768 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003769 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003770
James Smart2e0fef82007-06-17 19:56:36 -05003771 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3772 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003773 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003774 return 1;
dea31012005-04-17 16:05:31 -05003775
dea31012005-04-17 16:05:31 -05003776 icmd = &elsiocb->iocb;
3777 oldcmd = &oldiocb->iocb;
3778 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003779 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003780 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3781 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3782 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003783 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003784 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003785 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003786
James Smart92d7f7b2007-06-17 19:56:38 -05003787 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003788 rn = (RNID *) (pcmd);
3789 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003790 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3791 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3792 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003793 switch (format) {
3794 case 0:
3795 rn->SpecificLen = 0;
3796 break;
3797 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003798 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003799 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003800 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003801 rn->un.topologyDisc.unitType = RNID_HBA;
3802 rn->un.topologyDisc.physPort = 0;
3803 rn->un.topologyDisc.attachedNodes = 0;
3804 break;
3805 default:
3806 rn->CommonLen = 0;
3807 rn->SpecificLen = 0;
3808 break;
3809 }
3810
James Smart858c9f62007-06-17 19:56:39 -05003811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3812 "Issue ACC RNID: did:x%x flg:x%x",
3813 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3814
dea31012005-04-17 16:05:31 -05003815 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003816 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003817 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003818 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3819 * it could be freed */
3820
James Smart3772a992009-05-22 14:50:54 -04003821 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003822 if (rc == IOCB_ERROR) {
3823 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003824 return 1;
dea31012005-04-17 16:05:31 -05003825 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003826 return 0;
dea31012005-04-17 16:05:31 -05003827}
3828
James Smarte59058c2008-08-24 21:49:00 -04003829/**
James Smart3621a712009-04-06 18:47:14 -04003830 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003831 * @vport: pointer to a host virtual N_Port data structure.
3832 *
3833 * This routine issues Address Discover (ADISC) ELS commands to those
3834 * N_Ports which are in node port recovery state and ADISC has not been issued
3835 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3836 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3837 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3838 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3839 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3840 * IOCBs quit for later pick up. On the other hand, after walking through
3841 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3842 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3843 * no more ADISC need to be sent.
3844 *
3845 * Return code
3846 * The number of N_Ports with adisc issued.
3847 **/
dea31012005-04-17 16:05:31 -05003848int
James Smart2e0fef82007-06-17 19:56:36 -05003849lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003850{
James Smart2e0fef82007-06-17 19:56:36 -05003851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003852 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003853 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003854
James Smart685f0bf2007-04-25 09:53:08 -04003855 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003856 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003857 if (!NLP_CHK_NODE_ACT(ndlp))
3858 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003859 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3860 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3861 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003862 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003863 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003864 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003865 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003866 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3867 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003868 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003869 vport->num_disc_nodes++;
3870 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003871 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003872 spin_lock_irq(shost->host_lock);
3873 vport->fc_flag |= FC_NLP_MORE;
3874 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003875 break;
dea31012005-04-17 16:05:31 -05003876 }
3877 }
3878 }
3879 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003880 spin_lock_irq(shost->host_lock);
3881 vport->fc_flag &= ~FC_NLP_MORE;
3882 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003883 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003884 return sentadisc;
dea31012005-04-17 16:05:31 -05003885}
3886
James Smarte59058c2008-08-24 21:49:00 -04003887/**
James Smart3621a712009-04-06 18:47:14 -04003888 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003889 * @vport: pointer to a host virtual N_Port data structure.
3890 *
3891 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3892 * which are in node port recovery state, with a @vport. Each time an ELS
3893 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3894 * the per @vport number of discover count (num_disc_nodes) shall be
3895 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3896 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3897 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3898 * later pick up. On the other hand, after walking through all the ndlps with
3899 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3900 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3901 * PLOGI need to be sent.
3902 *
3903 * Return code
3904 * The number of N_Ports with plogi issued.
3905 **/
dea31012005-04-17 16:05:31 -05003906int
James Smart2e0fef82007-06-17 19:56:36 -05003907lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003908{
James Smart2e0fef82007-06-17 19:56:36 -05003909 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003910 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003911 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003912
James Smart2e0fef82007-06-17 19:56:36 -05003913 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3914 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003915 if (!NLP_CHK_NODE_ACT(ndlp))
3916 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003917 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3918 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3919 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3920 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3921 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003922 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3923 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003924 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003925 vport->num_disc_nodes++;
3926 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003927 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003928 spin_lock_irq(shost->host_lock);
3929 vport->fc_flag |= FC_NLP_MORE;
3930 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003931 break;
dea31012005-04-17 16:05:31 -05003932 }
3933 }
3934 }
James Smart87af33f2007-10-27 13:37:43 -04003935 if (sentplogi) {
3936 lpfc_set_disctmo(vport);
3937 }
3938 else {
James Smart2e0fef82007-06-17 19:56:36 -05003939 spin_lock_irq(shost->host_lock);
3940 vport->fc_flag &= ~FC_NLP_MORE;
3941 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003942 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003943 return sentplogi;
dea31012005-04-17 16:05:31 -05003944}
3945
James Smarte59058c2008-08-24 21:49:00 -04003946/**
James Smart3621a712009-04-06 18:47:14 -04003947 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003948 * @vport: pointer to a host virtual N_Port data structure.
3949 *
3950 * This routine cleans up any Registration State Change Notification
3951 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3952 * @vport together with the host_lock is used to prevent multiple thread
3953 * trying to access the RSCN array on a same @vport at the same time.
3954 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003955void
James Smart2e0fef82007-06-17 19:56:36 -05003956lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003957{
James Smart2e0fef82007-06-17 19:56:36 -05003958 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003960 int i;
3961
James Smart7f5f3d02008-02-08 18:50:14 -05003962 spin_lock_irq(shost->host_lock);
3963 if (vport->fc_rscn_flush) {
3964 /* Another thread is walking fc_rscn_id_list on this vport */
3965 spin_unlock_irq(shost->host_lock);
3966 return;
3967 }
3968 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3969 vport->fc_rscn_flush = 1;
3970 spin_unlock_irq(shost->host_lock);
3971
James Smart2e0fef82007-06-17 19:56:36 -05003972 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003973 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003974 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003975 }
James Smart2e0fef82007-06-17 19:56:36 -05003976 spin_lock_irq(shost->host_lock);
3977 vport->fc_rscn_id_cnt = 0;
3978 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3979 spin_unlock_irq(shost->host_lock);
3980 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003981 /* Indicate we are done walking this fc_rscn_id_list */
3982 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003983}
3984
James Smarte59058c2008-08-24 21:49:00 -04003985/**
James Smart3621a712009-04-06 18:47:14 -04003986 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003987 * @vport: pointer to a host virtual N_Port data structure.
3988 * @did: remote destination port identifier.
3989 *
3990 * This routine checks whether there is any pending Registration State
3991 * Configuration Notification (RSCN) to a @did on @vport.
3992 *
3993 * Return code
3994 * None zero - The @did matched with a pending rscn
3995 * 0 - not able to match @did with a pending rscn
3996 **/
dea31012005-04-17 16:05:31 -05003997int
James Smart2e0fef82007-06-17 19:56:36 -05003998lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003999{
4000 D_ID ns_did;
4001 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004002 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004003 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004004 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004005
4006 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004007
4008 /* Never match fabric nodes for RSCNs */
4009 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004010 return 0;
dea31012005-04-17 16:05:31 -05004011
4012 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004013 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004014 return did;
dea31012005-04-17 16:05:31 -05004015
James Smart7f5f3d02008-02-08 18:50:14 -05004016 spin_lock_irq(shost->host_lock);
4017 if (vport->fc_rscn_flush) {
4018 /* Another thread is walking fc_rscn_id_list on this vport */
4019 spin_unlock_irq(shost->host_lock);
4020 return 0;
4021 }
4022 /* Indicate we are walking fc_rscn_id_list on this vport */
4023 vport->fc_rscn_flush = 1;
4024 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004025 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004026 lp = vport->fc_rscn_id_list[i]->virt;
4027 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4028 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004029 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004030 rscn_did.un.word = be32_to_cpu(*lp++);
4031 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004032 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4033 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004034 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4035 && (ns_did.un.b.area == rscn_did.un.b.area)
4036 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004037 goto return_did_out;
dea31012005-04-17 16:05:31 -05004038 break;
James Smarteaf15d52008-12-04 22:39:29 -05004039 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004040 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4041 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004042 goto return_did_out;
dea31012005-04-17 16:05:31 -05004043 break;
James Smarteaf15d52008-12-04 22:39:29 -05004044 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004045 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004046 goto return_did_out;
dea31012005-04-17 16:05:31 -05004047 break;
James Smarteaf15d52008-12-04 22:39:29 -05004048 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004049 goto return_did_out;
dea31012005-04-17 16:05:31 -05004050 }
4051 }
James Smart92d7f7b2007-06-17 19:56:38 -05004052 }
James Smart7f5f3d02008-02-08 18:50:14 -05004053 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4054 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004055 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004056return_did_out:
4057 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4058 vport->fc_rscn_flush = 0;
4059 return did;
dea31012005-04-17 16:05:31 -05004060}
4061
James Smarte59058c2008-08-24 21:49:00 -04004062/**
James Smart3621a712009-04-06 18:47:14 -04004063 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004064 * @vport: pointer to a host virtual N_Port data structure.
4065 *
4066 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4067 * state machine for a @vport's nodes that are with pending RSCN (Registration
4068 * State Change Notification).
4069 *
4070 * Return code
4071 * 0 - Successful (currently alway return 0)
4072 **/
dea31012005-04-17 16:05:31 -05004073static int
James Smart2e0fef82007-06-17 19:56:36 -05004074lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004075{
James Smart685f0bf2007-04-25 09:53:08 -04004076 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004077
James Smart0d2b6b82008-06-14 22:52:47 -04004078 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004079 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004080 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004081 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4082 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004083 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004084 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004085 NLP_EVT_DEVICE_RECOVERY);
4086 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004087 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004088 return 0;
dea31012005-04-17 16:05:31 -05004089}
4090
James Smarte59058c2008-08-24 21:49:00 -04004091/**
James Smart3621a712009-04-06 18:47:14 -04004092 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004093 * @vport: pointer to a host virtual N_Port data structure.
4094 * @cmdiocb: pointer to lpfc command iocb data structure.
4095 *
4096 * lpfc_send_rscn_event sends an RSCN netlink event to management
4097 * applications.
4098 */
4099static void
4100lpfc_send_rscn_event(struct lpfc_vport *vport,
4101 struct lpfc_iocbq *cmdiocb)
4102{
4103 struct lpfc_dmabuf *pcmd;
4104 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4105 uint32_t *payload_ptr;
4106 uint32_t payload_len;
4107 struct lpfc_rscn_event_header *rscn_event_data;
4108
4109 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4110 payload_ptr = (uint32_t *) pcmd->virt;
4111 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4112
4113 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4114 payload_len, GFP_KERNEL);
4115 if (!rscn_event_data) {
4116 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4117 "0147 Failed to allocate memory for RSCN event\n");
4118 return;
4119 }
4120 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4121 rscn_event_data->payload_length = payload_len;
4122 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4123 payload_len);
4124
4125 fc_host_post_vendor_event(shost,
4126 fc_get_event_number(),
4127 sizeof(struct lpfc_els_event_header) + payload_len,
4128 (char *)rscn_event_data,
4129 LPFC_NL_VENDOR_ID);
4130
4131 kfree(rscn_event_data);
4132}
4133
4134/**
James Smart3621a712009-04-06 18:47:14 -04004135 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004136 * @vport: pointer to a host virtual N_Port data structure.
4137 * @cmdiocb: pointer to lpfc command iocb data structure.
4138 * @ndlp: pointer to a node-list data structure.
4139 *
4140 * This routine processes an unsolicited RSCN (Registration State Change
4141 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4142 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4143 * discover state machine is about to begin discovery, it just accepts the
4144 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4145 * contains N_Port IDs for other vports on this HBA, it just accepts the
4146 * RSCN and ignore processing it. If the state machine is in the recovery
4147 * state, the fc_rscn_id_list of this @vport is walked and the
4148 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4149 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4150 * routine is invoked to handle the RSCN event.
4151 *
4152 * Return code
4153 * 0 - Just sent the acc response
4154 * 1 - Sent the acc response and waited for name server completion
4155 **/
dea31012005-04-17 16:05:31 -05004156static int
James Smart2e0fef82007-06-17 19:56:36 -05004157lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004158 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004159{
James Smart2e0fef82007-06-17 19:56:36 -05004160 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4161 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004162 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004163 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004164 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004165 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004166 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004167 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004168 int i;
dea31012005-04-17 16:05:31 -05004169
4170 icmd = &cmdiocb->iocb;
4171 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4172 lp = (uint32_t *) pcmd->virt;
4173
James Smart92d7f7b2007-06-17 19:56:38 -05004174 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4175 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004176 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004177 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4178 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004179 vport->fc_flag, payload_len, *lp,
4180 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004181
4182 /* Send an RSCN event to the management application */
4183 lpfc_send_rscn_event(vport, cmdiocb);
4184
James Smartd2873e42006-08-18 17:46:43 -04004185 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004186 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004187 FCH_EVT_RSCN, lp[i]);
4188
dea31012005-04-17 16:05:31 -05004189 /* If we are about to begin discovery, just ACC the RSCN.
4190 * Discovery processing will satisfy it.
4191 */
James Smart2e0fef82007-06-17 19:56:36 -05004192 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004193 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4194 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4195 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4196
James Smart51ef4c22007-08-02 11:10:31 -04004197 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004198 return 0;
dea31012005-04-17 16:05:31 -05004199 }
4200
James Smart92d7f7b2007-06-17 19:56:38 -05004201 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4202 * just ACC and ignore it.
4203 */
4204 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004205 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004206 i = payload_len;
4207 datap = lp;
4208 while (i > 0) {
4209 nportid = *datap++;
4210 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4211 i -= sizeof(uint32_t);
4212 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004213 if (lpfc_find_vport_by_did(phba, nportid))
4214 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004215 }
4216 if (rscn_id == hba_id) {
4217 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004218 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004219 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004220 "Data: x%x x%x x%x x%x\n",
4221 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004222 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004223 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4224 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4225 ndlp->nlp_DID, vport->port_state,
4226 ndlp->nlp_flag);
4227
James Smart92d7f7b2007-06-17 19:56:38 -05004228 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004229 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004230 return 0;
4231 }
4232 }
4233
James Smart7f5f3d02008-02-08 18:50:14 -05004234 spin_lock_irq(shost->host_lock);
4235 if (vport->fc_rscn_flush) {
4236 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004237 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004238 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004239 /* Send back ACC */
4240 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004241 return 0;
4242 }
4243 /* Indicate we are walking fc_rscn_id_list on this vport */
4244 vport->fc_rscn_flush = 1;
4245 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004246 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004247 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004248 /* If we are already processing an RSCN, save the received
4249 * RSCN payload buffer, cmdiocb->context2 to process later.
4250 */
James Smart2e0fef82007-06-17 19:56:36 -05004251 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004252 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4253 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4254 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4255
James Smart09372822008-01-11 01:52:54 -05004256 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004257 vport->fc_flag |= FC_RSCN_DEFERRED;
4258 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004259 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004260 vport->fc_flag |= FC_RSCN_MODE;
4261 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004262 if (rscn_cnt) {
4263 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4264 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4265 }
4266 if ((rscn_cnt) &&
4267 (payload_len + length <= LPFC_BPL_SIZE)) {
4268 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004269 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004270 memcpy(((uint8_t *)cmd) + length, lp,
4271 payload_len);
4272 } else {
4273 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4274 vport->fc_rscn_id_cnt++;
4275 /* If we zero, cmdiocb->context2, the calling
4276 * routine will not try to free it.
4277 */
4278 cmdiocb->context2 = NULL;
4279 }
dea31012005-04-17 16:05:31 -05004280 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004281 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4282 "0235 Deferred RSCN "
4283 "Data: x%x x%x x%x\n",
4284 vport->fc_rscn_id_cnt, vport->fc_flag,
4285 vport->port_state);
dea31012005-04-17 16:05:31 -05004286 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004287 vport->fc_flag |= FC_RSCN_DISCOVERY;
4288 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004289 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004290 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4291 "0234 ReDiscovery RSCN "
4292 "Data: x%x x%x x%x\n",
4293 vport->fc_rscn_id_cnt, vport->fc_flag,
4294 vport->port_state);
dea31012005-04-17 16:05:31 -05004295 }
James Smart7f5f3d02008-02-08 18:50:14 -05004296 /* Indicate we are done walking fc_rscn_id_list on this vport */
4297 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004298 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004299 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004300 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004301 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004302 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004303 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004304 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004305 return 0;
dea31012005-04-17 16:05:31 -05004306 }
James Smart858c9f62007-06-17 19:56:39 -05004307 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4308 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4309 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4310
James Smart2e0fef82007-06-17 19:56:36 -05004311 spin_lock_irq(shost->host_lock);
4312 vport->fc_flag |= FC_RSCN_MODE;
4313 spin_unlock_irq(shost->host_lock);
4314 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004315 /* Indicate we are done walking fc_rscn_id_list on this vport */
4316 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004317 /*
4318 * If we zero, cmdiocb->context2, the calling routine will
4319 * not try to free it.
4320 */
4321 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004322 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004323 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004324 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004325 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004326 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004327 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004328}
4329
James Smarte59058c2008-08-24 21:49:00 -04004330/**
James Smart3621a712009-04-06 18:47:14 -04004331 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004332 * @vport: pointer to a host virtual N_Port data structure.
4333 *
4334 * This routine handles the Registration State Configuration Notification
4335 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4336 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4337 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4338 * NameServer shall be issued. If CT command to the NameServer fails to be
4339 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4340 * RSCN activities with the @vport.
4341 *
4342 * Return code
4343 * 0 - Cleaned up rscn on the @vport
4344 * 1 - Wait for plogi to name server before proceed
4345 **/
dea31012005-04-17 16:05:31 -05004346int
James Smart2e0fef82007-06-17 19:56:36 -05004347lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004348{
4349 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004350 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004351
James Smart92d7f7b2007-06-17 19:56:38 -05004352 /* Ignore RSCN if the port is being torn down. */
4353 if (vport->load_flag & FC_UNLOADING) {
4354 lpfc_els_flush_rscn(vport);
4355 return 0;
4356 }
4357
dea31012005-04-17 16:05:31 -05004358 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004359 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004360
4361 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004362 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4363 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4364 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4365 vport->port_state);
dea31012005-04-17 16:05:31 -05004366
4367 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004368 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004369 vport->num_disc_nodes = 0;
4370
James Smart2e0fef82007-06-17 19:56:36 -05004371 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004372 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4373 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004374 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004375 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004376 /* Wait for NameServer query cmpl before we can
4377 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004378 return 1;
dea31012005-04-17 16:05:31 -05004379 } else {
4380 /* If login to NameServer does not exist, issue one */
4381 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004382 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004383 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004384 /* Wait for NameServer login cmpl before we can
4385 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004386 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004387
James Smarte47c9092008-02-08 18:49:26 -05004388 if (ndlp) {
4389 ndlp = lpfc_enable_node(vport, ndlp,
4390 NLP_STE_PLOGI_ISSUE);
4391 if (!ndlp) {
4392 lpfc_els_flush_rscn(vport);
4393 return 0;
4394 }
4395 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004396 } else {
James Smarte47c9092008-02-08 18:49:26 -05004397 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4398 if (!ndlp) {
4399 lpfc_els_flush_rscn(vport);
4400 return 0;
4401 }
James Smart2e0fef82007-06-17 19:56:36 -05004402 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004403 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004404 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004405 }
James Smarte47c9092008-02-08 18:49:26 -05004406 ndlp->nlp_type |= NLP_FABRIC;
4407 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4408 /* Wait for NameServer login cmpl before we can
4409 * continue
4410 */
4411 return 1;
dea31012005-04-17 16:05:31 -05004412 }
4413
James Smart2e0fef82007-06-17 19:56:36 -05004414 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004415 return 0;
dea31012005-04-17 16:05:31 -05004416}
4417
James Smarte59058c2008-08-24 21:49:00 -04004418/**
James Smart3621a712009-04-06 18:47:14 -04004419 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004420 * @vport: pointer to a host virtual N_Port data structure.
4421 * @cmdiocb: pointer to lpfc command iocb data structure.
4422 * @ndlp: pointer to a node-list data structure.
4423 *
4424 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4425 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4426 * point topology. As an unsolicited FLOGI should not be received in a loop
4427 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4428 * lpfc_check_sparm() routine is invoked to check the parameters in the
4429 * unsolicited FLOGI. If parameters validation failed, the routine
4430 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4431 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4432 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4433 * will initiate PLOGI. The higher lexicographical value party shall has
4434 * higher priority (as the winning port) and will initiate PLOGI and
4435 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4436 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4437 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4438 *
4439 * Return code
4440 * 0 - Successfully processed the unsolicited flogi
4441 * 1 - Failed to process the unsolicited flogi
4442 **/
dea31012005-04-17 16:05:31 -05004443static int
James Smart2e0fef82007-06-17 19:56:36 -05004444lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004445 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004446{
James Smart2e0fef82007-06-17 19:56:36 -05004447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4448 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004449 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4450 uint32_t *lp = (uint32_t *) pcmd->virt;
4451 IOCB_t *icmd = &cmdiocb->iocb;
4452 struct serv_parm *sp;
4453 LPFC_MBOXQ_t *mbox;
4454 struct ls_rjt stat;
4455 uint32_t cmd, did;
4456 int rc;
4457
4458 cmd = *lp++;
4459 sp = (struct serv_parm *) lp;
4460
4461 /* FLOGI received */
4462
James Smart2e0fef82007-06-17 19:56:36 -05004463 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004464
4465 if (phba->fc_topology == TOPOLOGY_LOOP) {
4466 /* We should never receive a FLOGI in loop mode, ignore it */
4467 did = icmd->un.elsreq64.remoteID;
4468
4469 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4470 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004471 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4472 "0113 An FLOGI ELS command x%x was "
4473 "received from DID x%x in Loop Mode\n",
4474 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004475 return 1;
dea31012005-04-17 16:05:31 -05004476 }
4477
4478 did = Fabric_DID;
4479
James Smart341af102010-01-26 23:07:37 -05004480 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004481 /* For a FLOGI we accept, then if our portname is greater
4482 * then the remote portname we initiate Nport login.
4483 */
4484
James Smart2e0fef82007-06-17 19:56:36 -05004485 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004486 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004487
4488 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004489 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4490 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004491 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004492
dea31012005-04-17 16:05:31 -05004493 lpfc_linkdown(phba);
4494 lpfc_init_link(phba, mbox,
4495 phba->cfg_topology,
4496 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004497 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004498 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004499 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004500 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004501 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004502 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004503 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004504 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004505 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004506 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004507 spin_lock_irq(shost->host_lock);
4508 vport->fc_flag |= FC_PT2PT_PLOGI;
4509 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004510 }
James Smart2e0fef82007-06-17 19:56:36 -05004511 spin_lock_irq(shost->host_lock);
4512 vport->fc_flag |= FC_PT2PT;
4513 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004515 } else {
4516 /* Reject this request because invalid parameters */
4517 stat.un.b.lsRjtRsvd0 = 0;
4518 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4519 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4520 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004521 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4522 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004523 return 1;
dea31012005-04-17 16:05:31 -05004524 }
4525
4526 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004527 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004528
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004529 return 0;
dea31012005-04-17 16:05:31 -05004530}
4531
James Smarte59058c2008-08-24 21:49:00 -04004532/**
James Smart3621a712009-04-06 18:47:14 -04004533 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004534 * @vport: pointer to a host virtual N_Port data structure.
4535 * @cmdiocb: pointer to lpfc command iocb data structure.
4536 * @ndlp: pointer to a node-list data structure.
4537 *
4538 * This routine processes Request Node Identification Data (RNID) IOCB
4539 * received as an ELS unsolicited event. Only when the RNID specified format
4540 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4541 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4542 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4543 * rejected by invoking the lpfc_els_rsp_reject() routine.
4544 *
4545 * Return code
4546 * 0 - Successfully processed rnid iocb (currently always return 0)
4547 **/
dea31012005-04-17 16:05:31 -05004548static int
James Smart2e0fef82007-06-17 19:56:36 -05004549lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4550 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004551{
4552 struct lpfc_dmabuf *pcmd;
4553 uint32_t *lp;
4554 IOCB_t *icmd;
4555 RNID *rn;
4556 struct ls_rjt stat;
4557 uint32_t cmd, did;
4558
4559 icmd = &cmdiocb->iocb;
4560 did = icmd->un.elsreq64.remoteID;
4561 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4562 lp = (uint32_t *) pcmd->virt;
4563
4564 cmd = *lp++;
4565 rn = (RNID *) lp;
4566
4567 /* RNID received */
4568
4569 switch (rn->Format) {
4570 case 0:
4571 case RNID_TOPOLOGY_DISC:
4572 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004573 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004574 break;
4575 default:
4576 /* Reject this request because format not supported */
4577 stat.un.b.lsRjtRsvd0 = 0;
4578 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4579 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4580 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004581 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4582 NULL);
dea31012005-04-17 16:05:31 -05004583 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004584 return 0;
dea31012005-04-17 16:05:31 -05004585}
4586
James Smarte59058c2008-08-24 21:49:00 -04004587/**
James Smart3621a712009-04-06 18:47:14 -04004588 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004589 * @vport: pointer to a host virtual N_Port data structure.
4590 * @cmdiocb: pointer to lpfc command iocb data structure.
4591 * @ndlp: pointer to a node-list data structure.
4592 *
4593 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4594 * received as an ELS unsolicited event. Currently, this function just invokes
4595 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4596 *
4597 * Return code
4598 * 0 - Successfully processed lirr iocb (currently always return 0)
4599 **/
dea31012005-04-17 16:05:31 -05004600static int
James Smart2e0fef82007-06-17 19:56:36 -05004601lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4602 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004603{
4604 struct ls_rjt stat;
4605
4606 /* For now, unconditionally reject this command */
4607 stat.un.b.lsRjtRsvd0 = 0;
4608 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4609 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4610 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004611 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004612 return 0;
4613}
4614
James Smarte59058c2008-08-24 21:49:00 -04004615/**
James Smart5ffc2662009-11-18 15:39:44 -05004616 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4617 * @vport: pointer to a host virtual N_Port data structure.
4618 * @cmdiocb: pointer to lpfc command iocb data structure.
4619 * @ndlp: pointer to a node-list data structure.
4620 *
4621 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4622 * received as an ELS unsolicited event. A request to RRQ shall only
4623 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4624 * Nx_Port N_Port_ID of the target Exchange is the same as the
4625 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4626 * not accepted, an LS_RJT with reason code "Unable to perform
4627 * command request" and reason code explanation "Invalid Originator
4628 * S_ID" shall be returned. For now, we just unconditionally accept
4629 * RRQ from the target.
4630 **/
4631static void
4632lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4633 struct lpfc_nodelist *ndlp)
4634{
4635 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4636}
4637
4638/**
James Smart3621a712009-04-06 18:47:14 -04004639 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004640 * @phba: pointer to lpfc hba data structure.
4641 * @pmb: pointer to the driver internal queue element for mailbox command.
4642 *
4643 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4644 * mailbox command. This callback function is to actually send the Accept
4645 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4646 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4647 * mailbox command, constructs the RPS response with the link statistics
4648 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4649 * response to the RPS.
4650 *
4651 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4652 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4653 * will be stored into the context1 field of the IOCB for the completion
4654 * callback function to the RPS Accept Response ELS IOCB command.
4655 *
4656 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004657static void
James Smart329f9bc2007-04-25 09:53:01 -04004658lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004659{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004660 MAILBOX_t *mb;
4661 IOCB_t *icmd;
4662 RPS_RSP *rps_rsp;
4663 uint8_t *pcmd;
4664 struct lpfc_iocbq *elsiocb;
4665 struct lpfc_nodelist *ndlp;
4666 uint16_t xri, status;
4667 uint32_t cmdsize;
4668
James Smart04c68492009-05-22 14:52:52 -04004669 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004670
4671 ndlp = (struct lpfc_nodelist *) pmb->context2;
4672 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004673 pmb->context1 = NULL;
4674 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004675
4676 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004677 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004678 return;
4679 }
4680
4681 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004682 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004683 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4684 lpfc_max_els_tries, ndlp,
4685 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004686
4687 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004688 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004689
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004690 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004691 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004692
4693 icmd = &elsiocb->iocb;
4694 icmd->ulpContext = xri;
4695
4696 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4697 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004698 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004699 rps_rsp = (RPS_RSP *)pcmd;
4700
4701 if (phba->fc_topology != TOPOLOGY_LOOP)
4702 status = 0x10;
4703 else
4704 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004705 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004706 status |= 0x4;
4707
4708 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004709 rps_rsp->portStatus = cpu_to_be16(status);
4710 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4711 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4712 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4713 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4714 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4715 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004716 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004717 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4718 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4719 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4720 elsiocb->iotag, elsiocb->iocb.ulpContext,
4721 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4722 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004723 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004724 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004725 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004726 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004727 return;
4728}
4729
James Smarte59058c2008-08-24 21:49:00 -04004730/**
James Smart3621a712009-04-06 18:47:14 -04004731 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004732 * @vport: pointer to a host virtual N_Port data structure.
4733 * @cmdiocb: pointer to lpfc command iocb data structure.
4734 * @ndlp: pointer to a node-list data structure.
4735 *
4736 * This routine processes Read Port Status (RPS) IOCB received as an
4737 * ELS unsolicited event. It first checks the remote port state. If the
4738 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4739 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4740 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4741 * for reading the HBA link statistics. It is for the callback function,
4742 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4743 * to actually sending out RPS Accept (ACC) response.
4744 *
4745 * Return codes
4746 * 0 - Successfully processed rps iocb (currently always return 0)
4747 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004748static int
James Smart2e0fef82007-06-17 19:56:36 -05004749lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4750 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004751{
James Smart2e0fef82007-06-17 19:56:36 -05004752 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004753 uint32_t *lp;
4754 uint8_t flag;
4755 LPFC_MBOXQ_t *mbox;
4756 struct lpfc_dmabuf *pcmd;
4757 RPS *rps;
4758 struct ls_rjt stat;
4759
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004760 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004761 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4762 /* reject the unsolicited RPS request and done with it */
4763 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004764
4765 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4766 lp = (uint32_t *) pcmd->virt;
4767 flag = (be32_to_cpu(*lp++) & 0xf);
4768 rps = (RPS *) lp;
4769
4770 if ((flag == 0) ||
4771 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004772 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004773 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004774
James Smart92d7f7b2007-06-17 19:56:38 -05004775 printk("Fix me....\n");
4776 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004777 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4778 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004779 lpfc_read_lnk_stat(phba, mbox);
4780 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004781 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004782 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004783 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004784 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004785 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004786 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004787 /* Mbox completion will send ELS Response */
4788 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004789 /* Decrement reference count used for the failed mbox
4790 * command.
4791 */
James Smart329f9bc2007-04-25 09:53:01 -04004792 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004793 mempool_free(mbox, phba->mbox_mem_pool);
4794 }
4795 }
James Smart90160e02008-08-24 21:49:45 -04004796
4797reject_out:
4798 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004799 stat.un.b.lsRjtRsvd0 = 0;
4800 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4801 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4802 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004803 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004804 return 0;
4805}
4806
James Smarte59058c2008-08-24 21:49:00 -04004807/**
James Smart3621a712009-04-06 18:47:14 -04004808 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004809 * @vport: pointer to a host virtual N_Port data structure.
4810 * @cmdsize: size of the ELS command.
4811 * @oldiocb: pointer to the original lpfc command iocb data structure.
4812 * @ndlp: pointer to a node-list data structure.
4813 *
4814 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4815 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4816 *
4817 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4818 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4819 * will be stored into the context1 field of the IOCB for the completion
4820 * callback function to the RPL Accept Response ELS command.
4821 *
4822 * Return code
4823 * 0 - Successfully issued ACC RPL ELS command
4824 * 1 - Failed to issue ACC RPL ELS command
4825 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004826static int
James Smart2e0fef82007-06-17 19:56:36 -05004827lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4828 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004829{
James Smart2e0fef82007-06-17 19:56:36 -05004830 struct lpfc_hba *phba = vport->phba;
4831 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004832 RPL_RSP rpl_rsp;
4833 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004834 uint8_t *pcmd;
4835
James Smart2e0fef82007-06-17 19:56:36 -05004836 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4837 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004838
James Smart488d1462006-03-07 15:02:37 -05004839 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004840 return 1;
James Smart488d1462006-03-07 15:02:37 -05004841
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004842 icmd = &elsiocb->iocb;
4843 oldcmd = &oldiocb->iocb;
4844 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4845
4846 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4847 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004848 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004849 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4850 pcmd += sizeof(uint16_t);
4851
4852 /* Setup the RPL ACC payload */
4853 rpl_rsp.listLen = be32_to_cpu(1);
4854 rpl_rsp.index = 0;
4855 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004856 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4857 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004858 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004859 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004860 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004861 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4862 "0120 Xmit ELS RPL ACC response tag x%x "
4863 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4864 "rpi x%x\n",
4865 elsiocb->iotag, elsiocb->iocb.ulpContext,
4866 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4867 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004868 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004869 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004870 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4871 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004872 lpfc_els_free_iocb(phba, elsiocb);
4873 return 1;
4874 }
4875 return 0;
4876}
4877
James Smarte59058c2008-08-24 21:49:00 -04004878/**
James Smart3621a712009-04-06 18:47:14 -04004879 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004880 * @vport: pointer to a host virtual N_Port data structure.
4881 * @cmdiocb: pointer to lpfc command iocb data structure.
4882 * @ndlp: pointer to a node-list data structure.
4883 *
4884 * This routine processes Read Port List (RPL) IOCB received as an ELS
4885 * unsolicited event. It first checks the remote port state. If the remote
4886 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4887 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4888 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4889 * to accept the RPL.
4890 *
4891 * Return code
4892 * 0 - Successfully processed rpl iocb (currently always return 0)
4893 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004894static int
James Smart2e0fef82007-06-17 19:56:36 -05004895lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4896 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004897{
4898 struct lpfc_dmabuf *pcmd;
4899 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004900 uint32_t maxsize;
4901 uint16_t cmdsize;
4902 RPL *rpl;
4903 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004904
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004905 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4906 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004907 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004908 stat.un.b.lsRjtRsvd0 = 0;
4909 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4910 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4911 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004912 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4913 NULL);
James Smart90160e02008-08-24 21:49:45 -04004914 /* rejected the unsolicited RPL request and done with it */
4915 return 0;
dea31012005-04-17 16:05:31 -05004916 }
4917
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004918 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4919 lp = (uint32_t *) pcmd->virt;
4920 rpl = (RPL *) (lp + 1);
4921
4922 maxsize = be32_to_cpu(rpl->maxsize);
4923
4924 /* We support only one port */
4925 if ((rpl->index == 0) &&
4926 ((maxsize == 0) ||
4927 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4928 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004929 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004930 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4931 }
James Smart2e0fef82007-06-17 19:56:36 -05004932 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004933
4934 return 0;
4935}
4936
James Smarte59058c2008-08-24 21:49:00 -04004937/**
James Smart3621a712009-04-06 18:47:14 -04004938 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004939 * @vport: pointer to a virtual N_Port data structure.
4940 * @cmdiocb: pointer to lpfc command iocb data structure.
4941 * @ndlp: pointer to a node-list data structure.
4942 *
4943 * This routine processes Fibre Channel Address Resolution Protocol
4944 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4945 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4946 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4947 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4948 * remote PortName is compared against the FC PortName stored in the @vport
4949 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4950 * compared against the FC NodeName stored in the @vport data structure.
4951 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4952 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4953 * invoked to send out FARP Response to the remote node. Before sending the
4954 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4955 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4956 * routine is invoked to log into the remote port first.
4957 *
4958 * Return code
4959 * 0 - Either the FARP Match Mode not supported or successfully processed
4960 **/
dea31012005-04-17 16:05:31 -05004961static int
James Smart2e0fef82007-06-17 19:56:36 -05004962lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4963 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004964{
4965 struct lpfc_dmabuf *pcmd;
4966 uint32_t *lp;
4967 IOCB_t *icmd;
4968 FARP *fp;
4969 uint32_t cmd, cnt, did;
4970
4971 icmd = &cmdiocb->iocb;
4972 did = icmd->un.elsreq64.remoteID;
4973 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4974 lp = (uint32_t *) pcmd->virt;
4975
4976 cmd = *lp++;
4977 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004978 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004979 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4980 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004981 /* We will only support match on WWPN or WWNN */
4982 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004983 return 0;
dea31012005-04-17 16:05:31 -05004984 }
4985
4986 cnt = 0;
4987 /* If this FARP command is searching for my portname */
4988 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004989 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004990 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004991 cnt = 1;
4992 }
4993
4994 /* If this FARP command is searching for my nodename */
4995 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004996 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004997 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004998 cnt = 1;
4999 }
5000
5001 if (cnt) {
5002 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5003 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5004 /* Log back into the node before sending the FARP. */
5005 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005006 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005007 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005008 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005009 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005010 }
5011
5012 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005013 if (fp->Rflags & FARP_REQUEST_FARPR)
5014 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005015 }
5016 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005017 return 0;
dea31012005-04-17 16:05:31 -05005018}
5019
James Smarte59058c2008-08-24 21:49:00 -04005020/**
James Smart3621a712009-04-06 18:47:14 -04005021 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005022 * @vport: pointer to a host virtual N_Port data structure.
5023 * @cmdiocb: pointer to lpfc command iocb data structure.
5024 * @ndlp: pointer to a node-list data structure.
5025 *
5026 * This routine processes Fibre Channel Address Resolution Protocol
5027 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5028 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5029 * the FARP response request.
5030 *
5031 * Return code
5032 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5033 **/
dea31012005-04-17 16:05:31 -05005034static int
James Smart2e0fef82007-06-17 19:56:36 -05005035lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5036 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005037{
5038 struct lpfc_dmabuf *pcmd;
5039 uint32_t *lp;
5040 IOCB_t *icmd;
5041 uint32_t cmd, did;
5042
5043 icmd = &cmdiocb->iocb;
5044 did = icmd->un.elsreq64.remoteID;
5045 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5046 lp = (uint32_t *) pcmd->virt;
5047
5048 cmd = *lp++;
5049 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005050 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5051 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005052 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005053 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005054
5055 return 0;
5056}
5057
James Smarte59058c2008-08-24 21:49:00 -04005058/**
James Smart3621a712009-04-06 18:47:14 -04005059 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005060 * @vport: pointer to a host virtual N_Port data structure.
5061 * @cmdiocb: pointer to lpfc command iocb data structure.
5062 * @fan_ndlp: pointer to a node-list data structure.
5063 *
5064 * This routine processes a Fabric Address Notification (FAN) IOCB
5065 * command received as an ELS unsolicited event. The FAN ELS command will
5066 * only be processed on a physical port (i.e., the @vport represents the
5067 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5068 * compared against those in the phba data structure. If any of those is
5069 * different, the lpfc_initial_flogi() routine is invoked to initialize
5070 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5071 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5072 * is invoked to register login to the fabric.
5073 *
5074 * Return code
5075 * 0 - Successfully processed fan iocb (currently always return 0).
5076 **/
dea31012005-04-17 16:05:31 -05005077static int
James Smart2e0fef82007-06-17 19:56:36 -05005078lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5079 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005080{
James Smart2e0fef82007-06-17 19:56:36 -05005081 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005082 uint32_t *lp;
5083 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005084
James Smart0d2b6b82008-06-14 22:52:47 -04005085 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5086 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5087 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005088 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005089 if ((vport == phba->pport) &&
5090 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005091 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005092 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005093 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005094 sizeof(struct lpfc_name)))) {
5095 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005096 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005097 } else {
5098 /* FAN verified - skip FLOGI */
5099 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005100 if (phba->sli_rev < LPFC_SLI_REV4)
5101 lpfc_issue_fabric_reglogin(vport);
5102 else
5103 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005104 }
dea31012005-04-17 16:05:31 -05005105 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005106 return 0;
dea31012005-04-17 16:05:31 -05005107}
5108
James Smarte59058c2008-08-24 21:49:00 -04005109/**
James Smart3621a712009-04-06 18:47:14 -04005110 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005111 * @ptr: holder for the timer function associated data.
5112 *
5113 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5114 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5115 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5116 * up the worker thread. It is for the worker thread to invoke the routine
5117 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5118 **/
dea31012005-04-17 16:05:31 -05005119void
5120lpfc_els_timeout(unsigned long ptr)
5121{
James Smart2e0fef82007-06-17 19:56:36 -05005122 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5123 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005124 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005125 unsigned long iflag;
5126
James Smart2e0fef82007-06-17 19:56:36 -05005127 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005128 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5129 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005130 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005131 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005132
James Smart5e9d9b82008-06-14 22:52:53 -04005133 if (!tmo_posted)
5134 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005135 return;
5136}
5137
James Smarte59058c2008-08-24 21:49:00 -04005138/**
James Smart3621a712009-04-06 18:47:14 -04005139 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005140 * @vport: pointer to a virtual N_Port data structure.
5141 *
5142 * This routine is the actual handler function that processes an ELS timeout
5143 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5144 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5145 * invoking the lpfc_sli_issue_abort_iotag() routine.
5146 **/
dea31012005-04-17 16:05:31 -05005147void
James Smart2e0fef82007-06-17 19:56:36 -05005148lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005149{
James Smart2e0fef82007-06-17 19:56:36 -05005150 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005151 struct lpfc_sli_ring *pring;
5152 struct lpfc_iocbq *tmp_iocb, *piocb;
5153 IOCB_t *cmd = NULL;
5154 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005155 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005156 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005157 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005158
James Smart2e0fef82007-06-17 19:56:36 -05005159 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005160 timeout = (uint32_t)(phba->fc_ratov << 1);
5161
5162 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005163
5164 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5165 cmd = &piocb->iocb;
5166
James Smart2e0fef82007-06-17 19:56:36 -05005167 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5168 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5169 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005170 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005171
5172 if (piocb->vport != vport)
5173 continue;
5174
dea31012005-04-17 16:05:31 -05005175 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005176 if (pcmd)
5177 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005178
James Smart92d7f7b2007-06-17 19:56:38 -05005179 if (els_command == ELS_CMD_FARP ||
5180 els_command == ELS_CMD_FARPR ||
5181 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005182 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005183
dea31012005-04-17 16:05:31 -05005184 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005185 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005186 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005187 else
dea31012005-04-17 16:05:31 -05005188 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005189 continue;
5190 }
5191
James Smart2e0fef82007-06-17 19:56:36 -05005192 remote_ID = 0xffffffff;
5193 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005194 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005195 else {
5196 struct lpfc_nodelist *ndlp;
5197 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005198 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005199 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005200 }
James Smarte8b62012007-08-02 11:10:09 -04005201 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5202 "0127 ELS timeout Data: x%x x%x x%x "
5203 "x%x\n", els_command,
5204 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005205 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005206 }
James Smart2e0fef82007-06-17 19:56:36 -05005207 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005208
James Smart2e0fef82007-06-17 19:56:36 -05005209 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5210 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005211}
5212
James Smarte59058c2008-08-24 21:49:00 -04005213/**
James Smart3621a712009-04-06 18:47:14 -04005214 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005215 * @vport: pointer to a host virtual N_Port data structure.
5216 *
5217 * This routine is used to clean up all the outstanding ELS commands on a
5218 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5219 * routine. After that, it walks the ELS transmit queue to remove all the
5220 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5221 * the IOCBs with a non-NULL completion callback function, the callback
5222 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5223 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5224 * callback function, the IOCB will simply be released. Finally, it walks
5225 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5226 * completion queue IOCB that is associated with the @vport and is not
5227 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5228 * part of the discovery state machine) out to HBA by invoking the
5229 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5230 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5231 * the IOCBs are aborted when this function returns.
5232 **/
dea31012005-04-17 16:05:31 -05005233void
James Smart2e0fef82007-06-17 19:56:36 -05005234lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005235{
James Smart2534ba72007-04-25 09:52:20 -04005236 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005237 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005238 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005239 struct lpfc_iocbq *tmp_iocb, *piocb;
5240 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005241
5242 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005243
James Smart2e0fef82007-06-17 19:56:36 -05005244 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005245 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5246 cmd = &piocb->iocb;
5247
5248 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5249 continue;
5250 }
5251
5252 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005253 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5254 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5255 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5256 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005257 continue;
dea31012005-04-17 16:05:31 -05005258
James Smart2e0fef82007-06-17 19:56:36 -05005259 if (piocb->vport != vport)
5260 continue;
5261
James Smart2534ba72007-04-25 09:52:20 -04005262 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005263 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005264 }
5265
5266 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005267 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5268 continue;
5269 }
dea31012005-04-17 16:05:31 -05005270
James Smart2e0fef82007-06-17 19:56:36 -05005271 if (piocb->vport != vport)
5272 continue;
5273
James Smart07951072007-04-25 09:51:38 -04005274 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005275 }
James Smart2e0fef82007-06-17 19:56:36 -05005276 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005277
James Smarta257bf92009-04-06 18:48:10 -04005278 /* Cancell all the IOCBs from the completions list */
5279 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5280 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005281
dea31012005-04-17 16:05:31 -05005282 return;
5283}
5284
James Smarte59058c2008-08-24 21:49:00 -04005285/**
James Smart3621a712009-04-06 18:47:14 -04005286 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005287 * @phba: pointer to lpfc hba data structure.
5288 *
5289 * This routine is used to clean up all the outstanding ELS commands on a
5290 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5291 * routine. After that, it walks the ELS transmit queue to remove all the
5292 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5293 * the IOCBs with the completion callback function associated, the callback
5294 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5295 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5296 * callback function associated, the IOCB will simply be released. Finally,
5297 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5298 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5299 * management plane IOCBs that are not part of the discovery state machine)
5300 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5301 **/
James Smart549e55c2007-08-02 11:09:51 -04005302void
5303lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5304{
5305 LIST_HEAD(completions);
5306 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5307 struct lpfc_iocbq *tmp_iocb, *piocb;
5308 IOCB_t *cmd = NULL;
5309
5310 lpfc_fabric_abort_hba(phba);
5311 spin_lock_irq(&phba->hbalock);
5312 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5313 cmd = &piocb->iocb;
5314 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5315 continue;
5316 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5317 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5318 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5319 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5320 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5321 continue;
5322 list_move_tail(&piocb->list, &completions);
5323 pring->txq_cnt--;
5324 }
5325 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5326 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5327 continue;
5328 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5329 }
5330 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005331
5332 /* Cancel all the IOCBs from the completions list */
5333 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5334 IOERR_SLI_ABORTED);
5335
James Smart549e55c2007-08-02 11:09:51 -04005336 return;
5337}
5338
James Smarte59058c2008-08-24 21:49:00 -04005339/**
James Smart3621a712009-04-06 18:47:14 -04005340 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005341 * @phba: Pointer to hba context object.
5342 * @cmdiocbp: Pointer to command iocb which reported error.
5343 * @rspiocbp: Pointer to response iocb which reported error.
5344 *
5345 * This function sends an event when there is an ELS command
5346 * failure.
5347 **/
5348void
5349lpfc_send_els_failure_event(struct lpfc_hba *phba,
5350 struct lpfc_iocbq *cmdiocbp,
5351 struct lpfc_iocbq *rspiocbp)
5352{
5353 struct lpfc_vport *vport = cmdiocbp->vport;
5354 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5355 struct lpfc_lsrjt_event lsrjt_event;
5356 struct lpfc_fabric_event_header fabric_event;
5357 struct ls_rjt stat;
5358 struct lpfc_nodelist *ndlp;
5359 uint32_t *pcmd;
5360
5361 ndlp = cmdiocbp->context1;
5362 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5363 return;
5364
5365 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5366 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5367 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5368 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5369 sizeof(struct lpfc_name));
5370 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5371 sizeof(struct lpfc_name));
5372 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5373 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005374 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005375 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5376 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5377 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5378 fc_host_post_vendor_event(shost,
5379 fc_get_event_number(),
5380 sizeof(lsrjt_event),
5381 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005382 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005383 return;
5384 }
5385 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5386 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5387 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5388 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5389 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5390 else
5391 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5392 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5393 sizeof(struct lpfc_name));
5394 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5395 sizeof(struct lpfc_name));
5396 fc_host_post_vendor_event(shost,
5397 fc_get_event_number(),
5398 sizeof(fabric_event),
5399 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005400 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005401 return;
5402 }
5403
5404}
5405
5406/**
James Smart3621a712009-04-06 18:47:14 -04005407 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005408 * @vport: Pointer to vport object.
5409 * @ndlp: Pointer FC node object.
5410 * @cmd: ELS command code.
5411 *
5412 * This function posts an event when there is an incoming
5413 * unsolicited ELS command.
5414 **/
5415static void
5416lpfc_send_els_event(struct lpfc_vport *vport,
5417 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005418 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005419{
James Smartddcc50f2008-12-04 22:38:46 -05005420 struct lpfc_els_event_header *els_data = NULL;
5421 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005422 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5423
James Smartddcc50f2008-12-04 22:38:46 -05005424 if (*payload == ELS_CMD_LOGO) {
5425 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5426 if (!logo_data) {
5427 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5428 "0148 Failed to allocate memory "
5429 "for LOGO event\n");
5430 return;
5431 }
5432 els_data = &logo_data->header;
5433 } else {
5434 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5435 GFP_KERNEL);
5436 if (!els_data) {
5437 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5438 "0149 Failed to allocate memory "
5439 "for ELS event\n");
5440 return;
5441 }
5442 }
5443 els_data->event_type = FC_REG_ELS_EVENT;
5444 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005445 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005446 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005447 break;
5448 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005449 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005450 break;
5451 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005452 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5453 break;
5454 case ELS_CMD_LOGO:
5455 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5456 /* Copy the WWPN in the LOGO payload */
5457 memcpy(logo_data->logo_wwpn, &payload[2],
5458 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005459 break;
5460 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005461 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005462 return;
5463 }
James Smartddcc50f2008-12-04 22:38:46 -05005464 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5465 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5466 if (*payload == ELS_CMD_LOGO) {
5467 fc_host_post_vendor_event(shost,
5468 fc_get_event_number(),
5469 sizeof(struct lpfc_logo_event),
5470 (char *)logo_data,
5471 LPFC_NL_VENDOR_ID);
5472 kfree(logo_data);
5473 } else {
5474 fc_host_post_vendor_event(shost,
5475 fc_get_event_number(),
5476 sizeof(struct lpfc_els_event_header),
5477 (char *)els_data,
5478 LPFC_NL_VENDOR_ID);
5479 kfree(els_data);
5480 }
James Smartea2151b2008-09-07 11:52:10 -04005481
5482 return;
5483}
5484
5485
5486/**
James Smart3621a712009-04-06 18:47:14 -04005487 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005488 * @phba: pointer to lpfc hba data structure.
5489 * @pring: pointer to a SLI ring.
5490 * @vport: pointer to a host virtual N_Port data structure.
5491 * @elsiocb: pointer to lpfc els command iocb data structure.
5492 *
5493 * This routine is used for processing the IOCB associated with a unsolicited
5494 * event. It first determines whether there is an existing ndlp that matches
5495 * the DID from the unsolicited IOCB. If not, it will create a new one with
5496 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5497 * IOCB is then used to invoke the proper routine and to set up proper state
5498 * of the discovery state machine.
5499 **/
James Smarted957682007-06-17 19:56:37 -05005500static void
5501lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005502 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005503{
James Smart87af33f2007-10-27 13:37:43 -04005504 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005505 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005506 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005507 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005508 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005509 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005510
James Smarte47c9092008-02-08 18:49:26 -05005511 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005512 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005513
dea31012005-04-17 16:05:31 -05005514 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005515 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5516 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005517 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005518 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005519
James Smart858c9f62007-06-17 19:56:39 -05005520 did = icmd->un.rcvels.remoteID;
5521 if (icmd->ulpStatus) {
5522 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5523 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5524 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005525 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005526 }
dea31012005-04-17 16:05:31 -05005527
5528 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005529 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005530 goto dropit;
dea31012005-04-17 16:05:31 -05005531
James Smartc8685952009-11-18 15:39:16 -05005532 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005533 if (vport->load_flag & FC_UNLOADING)
5534 goto dropit;
5535
James Smart2e0fef82007-06-17 19:56:36 -05005536 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005537 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005538 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005539 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005540 if (!ndlp)
dea31012005-04-17 16:05:31 -05005541 goto dropit;
dea31012005-04-17 16:05:31 -05005542
James Smart2e0fef82007-06-17 19:56:36 -05005543 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005544 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005545 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005546 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005547 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005548 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5549 ndlp = lpfc_enable_node(vport, ndlp,
5550 NLP_STE_UNUSED_NODE);
5551 if (!ndlp)
5552 goto dropit;
5553 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5554 newnode = 1;
5555 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5556 ndlp->nlp_type |= NLP_FABRIC;
5557 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5558 /* This is similar to the new node path */
5559 ndlp = lpfc_nlp_get(ndlp);
5560 if (!ndlp)
5561 goto dropit;
5562 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5563 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005564 }
dea31012005-04-17 16:05:31 -05005565
5566 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005567
James Smart329f9bc2007-04-25 09:53:01 -04005568 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005569 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005570
5571 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5572 cmd &= ELS_CMD_MASK;
5573 }
5574 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005575 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5576 "0112 ELS command x%x received from NPORT x%x "
5577 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005578 switch (cmd) {
5579 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005580 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5581 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5582 did, vport->port_state, ndlp->nlp_flag);
5583
dea31012005-04-17 16:05:31 -05005584 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005585 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5586
James Smartddcc50f2008-12-04 22:38:46 -05005587 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005588 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005589 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5590 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5591 rjt_err = LSRJT_UNABLE_TPC;
5592 break;
5593 }
5594 /* We get here, and drop thru, if we are PT2PT with
5595 * another NPort and the other side has initiated
5596 * the PLOGI before responding to our FLOGI.
5597 */
dea31012005-04-17 16:05:31 -05005598 }
James Smart87af33f2007-10-27 13:37:43 -04005599
5600 shost = lpfc_shost_from_vport(vport);
5601 spin_lock_irq(shost->host_lock);
5602 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5603 spin_unlock_irq(shost->host_lock);
5604
James Smart2e0fef82007-06-17 19:56:36 -05005605 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5606 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005607
dea31012005-04-17 16:05:31 -05005608 break;
5609 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005610 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5611 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5612 did, vport->port_state, ndlp->nlp_flag);
5613
dea31012005-04-17 16:05:31 -05005614 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005615 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005616 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005617 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005618 break;
5619 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5621 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5622 did, vport->port_state, ndlp->nlp_flag);
5623
dea31012005-04-17 16:05:31 -05005624 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005625 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005626 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005627 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005628 break;
5629 }
James Smart2e0fef82007-06-17 19:56:36 -05005630 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005631 break;
5632 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005633 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5634 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5635 did, vport->port_state, ndlp->nlp_flag);
5636
dea31012005-04-17 16:05:31 -05005637 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005638 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005639 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005640 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005641 break;
5642 }
James Smart2e0fef82007-06-17 19:56:36 -05005643 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005644 break;
5645 case ELS_CMD_RSCN:
5646 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005647 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005648 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005649 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005650 break;
5651 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005652 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5653 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5654 did, vport->port_state, ndlp->nlp_flag);
5655
James Smartddcc50f2008-12-04 22:38:46 -05005656 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005657 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005658 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005659 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005660 break;
5661 }
James Smart2e0fef82007-06-17 19:56:36 -05005662 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5663 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005664 break;
5665 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5667 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5668 did, vport->port_state, ndlp->nlp_flag);
5669
dea31012005-04-17 16:05:31 -05005670 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005671 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005672 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005673 break;
5674 }
James Smart2e0fef82007-06-17 19:56:36 -05005675 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5676 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005677 break;
5678 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005679 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5680 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5681 did, vport->port_state, ndlp->nlp_flag);
5682
dea31012005-04-17 16:05:31 -05005683 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005684 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005685 break;
5686 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005687 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5688 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5689 did, vport->port_state, ndlp->nlp_flag);
5690
dea31012005-04-17 16:05:31 -05005691 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005692 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005693 break;
5694 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005695 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5696 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5697 did, vport->port_state, ndlp->nlp_flag);
5698
dea31012005-04-17 16:05:31 -05005699 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005700 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005701 break;
dea31012005-04-17 16:05:31 -05005702 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5704 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5705 did, vport->port_state, ndlp->nlp_flag);
5706
dea31012005-04-17 16:05:31 -05005707 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005708 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005709 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005710 break;
5711 }
James Smart2e0fef82007-06-17 19:56:36 -05005712 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005713 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005714 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005715 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5716 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5717 did, vport->port_state, ndlp->nlp_flag);
5718
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005719 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005720 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005721 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005722 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005723 break;
5724 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5726 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5727 did, vport->port_state, ndlp->nlp_flag);
5728
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005729 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005730 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005731 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005732 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005733 break;
5734 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5736 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5737 did, vport->port_state, ndlp->nlp_flag);
5738
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005739 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005740 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005741 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005742 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005743 break;
dea31012005-04-17 16:05:31 -05005744 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005745 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5746 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5747 did, vport->port_state, ndlp->nlp_flag);
5748
dea31012005-04-17 16:05:31 -05005749 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005750 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005751 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005752 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005753 break;
James Smart5ffc2662009-11-18 15:39:44 -05005754 case ELS_CMD_RRQ:
5755 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5756 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5757 did, vport->port_state, ndlp->nlp_flag);
5758
5759 phba->fc_stat.elsRcvRRQ++;
5760 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5761 if (newnode)
5762 lpfc_nlp_put(ndlp);
5763 break;
dea31012005-04-17 16:05:31 -05005764 default:
James Smart858c9f62007-06-17 19:56:39 -05005765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5766 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5767 cmd, did, vport->port_state);
5768
dea31012005-04-17 16:05:31 -05005769 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005770 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005771
5772 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005773 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5774 "0115 Unknown ELS command x%x "
5775 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005776 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005777 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005778 break;
5779 }
5780
5781 /* check if need to LS_RJT received ELS cmd */
5782 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005783 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005784 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005785 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005786 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5787 NULL);
dea31012005-04-17 16:05:31 -05005788 }
5789
James Smartd7c255b2008-08-24 21:50:00 -04005790 lpfc_nlp_put(elsiocb->context1);
5791 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005792 return;
5793
5794dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005795 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005796 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5797 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005798 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005799 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005800 phba->fc_stat.elsRcvDrop++;
5801}
5802
James Smarte59058c2008-08-24 21:49:00 -04005803/**
James Smart3621a712009-04-06 18:47:14 -04005804 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005805 * @phba: pointer to lpfc hba data structure.
5806 * @vpi: host virtual N_Port identifier.
5807 *
5808 * This routine finds a vport on a HBA (referred by @phba) through a
5809 * @vpi. The function walks the HBA's vport list and returns the address
5810 * of the vport with the matching @vpi.
5811 *
5812 * Return code
5813 * NULL - No vport with the matching @vpi found
5814 * Otherwise - Address to the vport with the matching @vpi.
5815 **/
James Smart6669f9b2009-10-02 15:16:45 -04005816struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005817lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5818{
5819 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005820 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005821
James Smart549e55c2007-08-02 11:09:51 -04005822 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005823 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005824 if (vport->vpi == vpi) {
5825 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005826 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005827 }
James Smart92d7f7b2007-06-17 19:56:38 -05005828 }
James Smart549e55c2007-08-02 11:09:51 -04005829 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005830 return NULL;
5831}
James Smarted957682007-06-17 19:56:37 -05005832
James Smarte59058c2008-08-24 21:49:00 -04005833/**
James Smart3621a712009-04-06 18:47:14 -04005834 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005835 * @phba: pointer to lpfc hba data structure.
5836 * @pring: pointer to a SLI ring.
5837 * @elsiocb: pointer to lpfc els iocb data structure.
5838 *
5839 * This routine is used to process an unsolicited event received from a SLI
5840 * (Service Level Interface) ring. The actual processing of the data buffer
5841 * associated with the unsolicited event is done by invoking the routine
5842 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5843 * SLI ring on which the unsolicited event was received.
5844 **/
James Smarted957682007-06-17 19:56:37 -05005845void
5846lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5847 struct lpfc_iocbq *elsiocb)
5848{
5849 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005850 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005851 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005852 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5853 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005854
James Smartd7c255b2008-08-24 21:50:00 -04005855 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005856 elsiocb->context2 = NULL;
5857 elsiocb->context3 = NULL;
5858
5859 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5860 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5861 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5862 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005863 phba->fc_stat.NoRcvBuf++;
5864 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005865 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005866 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005867 return;
5868 }
5869
James Smart92d7f7b2007-06-17 19:56:38 -05005870 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5871 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5872 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5873 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5874 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005875 else
5876 vport = lpfc_find_vport_by_vpid(phba,
5877 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005878 }
James Smart7f5f3d02008-02-08 18:50:14 -05005879 /* If there are no BDEs associated
5880 * with this IOCB, there is nothing to do.
5881 */
James Smarted957682007-06-17 19:56:37 -05005882 if (icmd->ulpBdeCount == 0)
5883 return;
5884
James Smart7f5f3d02008-02-08 18:50:14 -05005885 /* type of ELS cmd is first 32bit word
5886 * in packet
5887 */
James Smarted957682007-06-17 19:56:37 -05005888 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005889 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005890 } else {
5891 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5892 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005893 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5894 paddr);
James Smarted957682007-06-17 19:56:37 -05005895 }
5896
James Smart92d7f7b2007-06-17 19:56:38 -05005897 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5898 /*
5899 * The different unsolicited event handlers would tell us
5900 * if they are done with "mp" by setting context2 to NULL.
5901 */
dea31012005-04-17 16:05:31 -05005902 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005903 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5904 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005905 }
James Smarted957682007-06-17 19:56:37 -05005906
5907 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005908 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005909 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005910 elsiocb->context2 = bdeBuf2;
5911 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005912 /* free mp if we are done with it */
5913 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005914 lpfc_in_buf_free(phba, elsiocb->context2);
5915 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005916 }
dea31012005-04-17 16:05:31 -05005917 }
dea31012005-04-17 16:05:31 -05005918}
James Smart92d7f7b2007-06-17 19:56:38 -05005919
James Smarte59058c2008-08-24 21:49:00 -04005920/**
James Smart3621a712009-04-06 18:47:14 -04005921 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005922 * @phba: pointer to lpfc hba data structure.
5923 * @vport: pointer to a virtual N_Port data structure.
5924 *
5925 * This routine issues a Port Login (PLOGI) to the Name Server with
5926 * State Change Request (SCR) for a @vport. This routine will create an
5927 * ndlp for the Name Server associated to the @vport if such node does
5928 * not already exist. The PLOGI to Name Server is issued by invoking the
5929 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5930 * (FDMI) is configured to the @vport, a FDMI node will be created and
5931 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5932 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005933void
5934lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5935{
5936 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5937
5938 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5939 if (!ndlp) {
5940 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5941 if (!ndlp) {
5942 if (phba->fc_topology == TOPOLOGY_LOOP) {
5943 lpfc_disc_start(vport);
5944 return;
5945 }
5946 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005947 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5948 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005949 return;
5950 }
5951 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005952 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5953 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5954 if (!ndlp) {
5955 if (phba->fc_topology == TOPOLOGY_LOOP) {
5956 lpfc_disc_start(vport);
5957 return;
5958 }
5959 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5960 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5961 "0348 NameServer login: node freed\n");
5962 return;
5963 }
James Smart92d7f7b2007-06-17 19:56:38 -05005964 }
James Smart58da1ff2008-04-07 10:15:56 -04005965 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005966
5967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5968
5969 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5970 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005971 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5972 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005973 return;
5974 }
5975
James Smart3de2a652007-08-02 11:09:59 -04005976 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005977 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5978 GFP_KERNEL);
5979 if (ndlp_fdmi) {
5980 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5981 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005982 lpfc_nlp_set_state(vport, ndlp_fdmi,
5983 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005984 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5985 0);
5986 }
5987 }
5988 return;
5989}
5990
James Smarte59058c2008-08-24 21:49:00 -04005991/**
James Smart3621a712009-04-06 18:47:14 -04005992 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005993 * @phba: pointer to lpfc hba data structure.
5994 * @pmb: pointer to the driver internal queue element for mailbox command.
5995 *
5996 * This routine is the completion callback function to register new vport
5997 * mailbox command. If the new vport mailbox command completes successfully,
5998 * the fabric registration login shall be performed on physical port (the
5999 * new vport created is actually a physical port, with VPI 0) or the port
6000 * login to Name Server for State Change Request (SCR) will be performed
6001 * on virtual port (real virtual port, with VPI greater than 0).
6002 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006003static void
6004lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6005{
6006 struct lpfc_vport *vport = pmb->vport;
6007 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6008 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006009 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006010 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006011
James Smart09372822008-01-11 01:52:54 -05006012 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006013 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006014 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006015
6016 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006017 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6018 "0915 Register VPI failed: 0x%x\n",
6019 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05006020
6021 switch (mb->mbxStatus) {
6022 case 0x11: /* unsupported feature */
6023 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006024 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006025 /* giving up on vport registration */
6026 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6027 spin_lock_irq(shost->host_lock);
6028 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6029 spin_unlock_irq(shost->host_lock);
6030 lpfc_can_disctmo(vport);
6031 break;
James Smart695a8142010-01-26 23:08:03 -05006032 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6033 case 0x20:
6034 spin_lock_irq(shost->host_lock);
6035 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6036 spin_unlock_irq(shost->host_lock);
6037 lpfc_init_vpi(phba, pmb, vport->vpi);
6038 pmb->vport = vport;
6039 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6040 rc = lpfc_sli_issue_mbox(phba, pmb,
6041 MBX_NOWAIT);
6042 if (rc == MBX_NOT_FINISHED) {
6043 lpfc_printf_vlog(vport,
6044 KERN_ERR, LOG_MBOX,
6045 "2732 Failed to issue INIT_VPI"
6046 " mailbox command\n");
6047 } else {
6048 lpfc_nlp_put(ndlp);
6049 return;
6050 }
6051
James Smart92d7f7b2007-06-17 19:56:38 -05006052 default:
6053 /* Try to recover from this error */
6054 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006055 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006056 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006057 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006058 if (vport->port_type == LPFC_PHYSICAL_PORT
6059 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006060 lpfc_initial_flogi(vport);
6061 else
6062 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006063 break;
6064 }
James Smart92d7f7b2007-06-17 19:56:38 -05006065 } else {
James Smart695a8142010-01-26 23:08:03 -05006066 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006067 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006068 spin_unlock_irq(shost->host_lock);
6069 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006070 if (phba->sli_rev < LPFC_SLI_REV4)
6071 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006072 else {
James Smartfc2b9892010-02-26 14:15:29 -05006073 /*
6074 * If the physical port is instantiated using
6075 * FDISC, do not start vport discovery.
6076 */
6077 if (vport->port_state != LPFC_FDISC)
6078 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006079 lpfc_do_scr_ns_plogi(phba, vport);
6080 }
6081 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006082 lpfc_do_scr_ns_plogi(phba, vport);
6083 }
James Smartfa4066b2008-01-11 01:53:27 -05006084
6085 /* Now, we decrement the ndlp reference count held for this
6086 * callback function
6087 */
6088 lpfc_nlp_put(ndlp);
6089
James Smart92d7f7b2007-06-17 19:56:38 -05006090 mempool_free(pmb, phba->mbox_mem_pool);
6091 return;
6092}
6093
James Smarte59058c2008-08-24 21:49:00 -04006094/**
James Smart3621a712009-04-06 18:47:14 -04006095 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006096 * @phba: pointer to lpfc hba data structure.
6097 * @vport: pointer to a host virtual N_Port data structure.
6098 * @ndlp: pointer to a node-list data structure.
6099 *
6100 * This routine registers the @vport as a new virtual port with a HBA.
6101 * It is done through a registering vpi mailbox command.
6102 **/
James Smart695a8142010-01-26 23:08:03 -05006103void
James Smart92d7f7b2007-06-17 19:56:38 -05006104lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6105 struct lpfc_nodelist *ndlp)
6106{
James Smart09372822008-01-11 01:52:54 -05006107 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006108 LPFC_MBOXQ_t *mbox;
6109
6110 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6111 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006112 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006113 mbox->vport = vport;
6114 mbox->context2 = lpfc_nlp_get(ndlp);
6115 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006116 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006117 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006118 /* mailbox command not success, decrement ndlp
6119 * reference count for this command
6120 */
6121 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006122 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006123
James Smarte8b62012007-08-02 11:10:09 -04006124 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6125 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006126 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006127 }
6128 } else {
James Smarte8b62012007-08-02 11:10:09 -04006129 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6130 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006131 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006132 }
James Smartfa4066b2008-01-11 01:53:27 -05006133 return;
6134
6135mbox_err_exit:
6136 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6137 spin_lock_irq(shost->host_lock);
6138 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6139 spin_unlock_irq(shost->host_lock);
6140 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006141}
6142
James Smarte59058c2008-08-24 21:49:00 -04006143/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006144 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006145 * @phba: pointer to lpfc hba data structure.
6146 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006147 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006148 **/
6149void
James Smart0c9ab6f2010-02-26 14:15:57 -05006150lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006151{
6152 struct lpfc_vport **vports;
6153 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006154 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006155 int i;
James Smart695a8142010-01-26 23:08:03 -05006156
6157 /* Treat this failure as linkdown for all vports */
6158 link_state = phba->link_state;
6159 lpfc_linkdown(phba);
6160 phba->link_state = link_state;
6161
6162 vports = lpfc_create_vport_work_array(phba);
6163
6164 if (vports) {
6165 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6166 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6167 if (ndlp)
6168 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6169 lpfc_els_flush_cmd(vports[i]);
6170 }
6171 lpfc_destroy_vport_work_array(phba, vports);
6172 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006173}
6174
6175/**
6176 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6177 * @phba: pointer to lpfc hba data structure.
6178 *
6179 * This routine abort all pending discovery commands and
6180 * start a timer to retry FLOGI for the physical port
6181 * discovery.
6182 **/
6183void
6184lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6185{
6186 struct lpfc_nodelist *ndlp;
6187 struct Scsi_Host *shost;
6188
6189 /* Cancel the all vports retry delay retry timers */
6190 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006191
6192 /* If fabric require FLOGI, then re-instantiate physical login */
6193 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6194 if (!ndlp)
6195 return;
6196
James Smart695a8142010-01-26 23:08:03 -05006197 shost = lpfc_shost_from_vport(phba->pport);
6198 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6199 spin_lock_irq(shost->host_lock);
6200 ndlp->nlp_flag |= NLP_DELAY_TMO;
6201 spin_unlock_irq(shost->host_lock);
6202 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6203 phba->pport->port_state = LPFC_FLOGI;
6204 return;
6205}
6206
6207/**
6208 * lpfc_fabric_login_reqd - Check if FLOGI required.
6209 * @phba: pointer to lpfc hba data structure.
6210 * @cmdiocb: pointer to FDISC command iocb.
6211 * @rspiocb: pointer to FDISC response iocb.
6212 *
6213 * This routine checks if a FLOGI is reguired for FDISC
6214 * to succeed.
6215 **/
6216static int
6217lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6218 struct lpfc_iocbq *cmdiocb,
6219 struct lpfc_iocbq *rspiocb)
6220{
6221
6222 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6223 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6224 return 0;
6225 else
6226 return 1;
6227}
6228
6229/**
James Smart3621a712009-04-06 18:47:14 -04006230 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006231 * @phba: pointer to lpfc hba data structure.
6232 * @cmdiocb: pointer to lpfc command iocb data structure.
6233 * @rspiocb: pointer to lpfc response iocb data structure.
6234 *
6235 * This routine is the completion callback function to a Fabric Discover
6236 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6237 * single threaded, each FDISC completion callback function will reset
6238 * the discovery timer for all vports such that the timers will not get
6239 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6240 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6241 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6242 * assigned to the vport has been changed with the completion of the FDISC
6243 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6244 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6245 * routine is invoked to register new vport with the HBA. Otherwise, the
6246 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6247 * Server for State Change Request (SCR).
6248 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006249static void
6250lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6251 struct lpfc_iocbq *rspiocb)
6252{
6253 struct lpfc_vport *vport = cmdiocb->vport;
6254 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6255 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6256 struct lpfc_nodelist *np;
6257 struct lpfc_nodelist *next_np;
6258 IOCB_t *irsp = &rspiocb->iocb;
6259 struct lpfc_iocbq *piocb;
6260
James Smarte8b62012007-08-02 11:10:09 -04006261 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6262 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6263 irsp->ulpStatus, irsp->un.ulpWord[4],
6264 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006265 /* Since all FDISCs are being single threaded, we
6266 * must reset the discovery timer for ALL vports
6267 * waiting to send FDISC when one completes.
6268 */
6269 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6270 lpfc_set_disctmo(piocb->vport);
6271 }
6272
James Smart858c9f62007-06-17 19:56:39 -05006273 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6274 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6275 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6276
James Smart92d7f7b2007-06-17 19:56:38 -05006277 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006278
6279 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6280 lpfc_retry_pport_discovery(phba);
6281 goto out;
6282 }
6283
James Smart92d7f7b2007-06-17 19:56:38 -05006284 /* Check for retry */
6285 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6286 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006287 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006289 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006290 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006291 goto fdisc_failed;
6292 }
James Smartd7c255b2008-08-24 21:50:00 -04006293 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006294 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006295 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006296 vport->fc_flag |= FC_FABRIC;
6297 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6298 vport->fc_flag |= FC_PUBLIC_LOOP;
6299 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006300
James Smartd7c255b2008-08-24 21:50:00 -04006301 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6302 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6303 if ((vport->fc_prevDID != vport->fc_myDID) &&
6304 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6305 /* If our NportID changed, we need to ensure all
6306 * remaining NPORTs get unreg_login'ed so we can
6307 * issue unreg_vpi.
6308 */
6309 list_for_each_entry_safe(np, next_np,
6310 &vport->fc_nodes, nlp_listp) {
6311 if (!NLP_CHK_NODE_ACT(ndlp) ||
6312 (np->nlp_state != NLP_STE_NPR_NODE) ||
6313 !(np->nlp_flag & NLP_NPR_ADISC))
6314 continue;
James Smart09372822008-01-11 01:52:54 -05006315 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006316 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006317 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006318 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006319 }
James Smart78730cf2010-04-06 15:06:30 -04006320 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006321 lpfc_mbx_unreg_vpi(vport);
6322 spin_lock_irq(shost->host_lock);
6323 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006324 if (phba->sli_rev == LPFC_SLI_REV4)
6325 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006326 else
6327 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006328 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006329 }
6330
James Smartecfd03c2010-02-12 14:41:27 -05006331 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6332 lpfc_issue_init_vpi(vport);
6333 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006334 lpfc_register_new_vport(phba, vport, ndlp);
6335 else
6336 lpfc_do_scr_ns_plogi(phba, vport);
6337 goto out;
6338fdisc_failed:
6339 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6340 /* Cancel discovery timer */
6341 lpfc_can_disctmo(vport);
6342 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006343out:
6344 lpfc_els_free_iocb(phba, cmdiocb);
6345}
6346
James Smarte59058c2008-08-24 21:49:00 -04006347/**
James Smart3621a712009-04-06 18:47:14 -04006348 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006349 * @vport: pointer to a virtual N_Port data structure.
6350 * @ndlp: pointer to a node-list data structure.
6351 * @retry: number of retries to the command IOCB.
6352 *
6353 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6354 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6355 * routine to issue the IOCB, which makes sure only one outstanding fabric
6356 * IOCB will be sent off HBA at any given time.
6357 *
6358 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6359 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6360 * will be stored into the context1 field of the IOCB for the completion
6361 * callback function to the FDISC ELS command.
6362 *
6363 * Return code
6364 * 0 - Successfully issued fdisc iocb command
6365 * 1 - Failed to issue fdisc iocb command
6366 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006367static int
James Smart92d7f7b2007-06-17 19:56:38 -05006368lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6369 uint8_t retry)
6370{
6371 struct lpfc_hba *phba = vport->phba;
6372 IOCB_t *icmd;
6373 struct lpfc_iocbq *elsiocb;
6374 struct serv_parm *sp;
6375 uint8_t *pcmd;
6376 uint16_t cmdsize;
6377 int did = ndlp->nlp_DID;
6378 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006379
James Smart5ffc2662009-11-18 15:39:44 -05006380 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006381 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6382 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6383 ELS_CMD_FDISC);
6384 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006385 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006386 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6387 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006388 return 1;
6389 }
6390
6391 icmd = &elsiocb->iocb;
6392 icmd->un.elsreq64.myID = 0;
6393 icmd->un.elsreq64.fl = 1;
6394
James Smartf1126682009-06-10 17:22:44 -04006395 if (phba->sli_rev == LPFC_SLI_REV4) {
6396 /* FDISC needs to be 1 for WQE VPI */
6397 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6398 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6399 /* Set the ulpContext to the vpi */
6400 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6401 } else {
6402 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6403 icmd->ulpCt_h = 1;
6404 icmd->ulpCt_l = 0;
6405 }
James Smart92d7f7b2007-06-17 19:56:38 -05006406
6407 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6408 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6409 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6410 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6411 sp = (struct serv_parm *) pcmd;
6412 /* Setup CSPs accordingly for Fabric */
6413 sp->cmn.e_d_tov = 0;
6414 sp->cmn.w2.r_a_tov = 0;
6415 sp->cls1.classValid = 0;
6416 sp->cls2.seqDelivery = 1;
6417 sp->cls3.seqDelivery = 1;
6418
6419 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6420 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6421 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6422 pcmd += sizeof(uint32_t); /* Port Name */
6423 memcpy(pcmd, &vport->fc_portname, 8);
6424 pcmd += sizeof(uint32_t); /* Node Name */
6425 pcmd += sizeof(uint32_t); /* Node Name */
6426 memcpy(pcmd, &vport->fc_nodename, 8);
6427
6428 lpfc_set_disctmo(vport);
6429
6430 phba->fc_stat.elsXmitFDISC++;
6431 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6432
James Smart858c9f62007-06-17 19:56:39 -05006433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6434 "Issue FDISC: did:x%x",
6435 did, 0, 0);
6436
James Smart92d7f7b2007-06-17 19:56:38 -05006437 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6438 if (rc == IOCB_ERROR) {
6439 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006440 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006441 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6442 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006443 return 1;
6444 }
6445 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006446 return 0;
6447}
6448
James Smarte59058c2008-08-24 21:49:00 -04006449/**
James Smart3621a712009-04-06 18:47:14 -04006450 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006451 * @phba: pointer to lpfc hba data structure.
6452 * @cmdiocb: pointer to lpfc command iocb data structure.
6453 * @rspiocb: pointer to lpfc response iocb data structure.
6454 *
6455 * This routine is the completion callback function to the issuing of a LOGO
6456 * ELS command off a vport. It frees the command IOCB and then decrement the
6457 * reference count held on ndlp for this completion function, indicating that
6458 * the reference to the ndlp is no long needed. Note that the
6459 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6460 * callback function and an additional explicit ndlp reference decrementation
6461 * will trigger the actual release of the ndlp.
6462 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006463static void
6464lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6465 struct lpfc_iocbq *rspiocb)
6466{
6467 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006468 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006469 struct lpfc_nodelist *ndlp;
6470 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006471
6472 irsp = &rspiocb->iocb;
6473 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6474 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6475 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006476
6477 lpfc_els_free_iocb(phba, cmdiocb);
6478 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006479
6480 /* Trigger the release of the ndlp after logo */
6481 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006482}
6483
James Smarte59058c2008-08-24 21:49:00 -04006484/**
James Smart3621a712009-04-06 18:47:14 -04006485 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006486 * @vport: pointer to a virtual N_Port data structure.
6487 * @ndlp: pointer to a node-list data structure.
6488 *
6489 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6490 *
6491 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6492 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6493 * will be stored into the context1 field of the IOCB for the completion
6494 * callback function to the LOGO ELS command.
6495 *
6496 * Return codes
6497 * 0 - Successfully issued logo off the @vport
6498 * 1 - Failed to issue logo off the @vport
6499 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006500int
6501lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6502{
6503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6504 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006505 IOCB_t *icmd;
6506 struct lpfc_iocbq *elsiocb;
6507 uint8_t *pcmd;
6508 uint16_t cmdsize;
6509
6510 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6511 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6512 ELS_CMD_LOGO);
6513 if (!elsiocb)
6514 return 1;
6515
6516 icmd = &elsiocb->iocb;
6517 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6518 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6519 pcmd += sizeof(uint32_t);
6520
6521 /* Fill in LOGO payload */
6522 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6523 pcmd += sizeof(uint32_t);
6524 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6525
James Smart858c9f62007-06-17 19:56:39 -05006526 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6527 "Issue LOGO npiv did:x%x flg:x%x",
6528 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6529
James Smart92d7f7b2007-06-17 19:56:38 -05006530 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6531 spin_lock_irq(shost->host_lock);
6532 ndlp->nlp_flag |= NLP_LOGO_SND;
6533 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006534 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6535 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006536 spin_lock_irq(shost->host_lock);
6537 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6538 spin_unlock_irq(shost->host_lock);
6539 lpfc_els_free_iocb(phba, elsiocb);
6540 return 1;
6541 }
6542 return 0;
6543}
6544
James Smarte59058c2008-08-24 21:49:00 -04006545/**
James Smart3621a712009-04-06 18:47:14 -04006546 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006547 * @ptr: holder for the timer function associated data.
6548 *
6549 * This routine is invoked by the fabric iocb block timer after
6550 * timeout. It posts the fabric iocb block timeout event by setting the
6551 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6552 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6553 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6554 * posted event WORKER_FABRIC_BLOCK_TMO.
6555 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006556void
6557lpfc_fabric_block_timeout(unsigned long ptr)
6558{
6559 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6560 unsigned long iflags;
6561 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006562
James Smart92d7f7b2007-06-17 19:56:38 -05006563 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6564 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6565 if (!tmo_posted)
6566 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6567 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6568
James Smart5e9d9b82008-06-14 22:52:53 -04006569 if (!tmo_posted)
6570 lpfc_worker_wake_up(phba);
6571 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006572}
6573
James Smarte59058c2008-08-24 21:49:00 -04006574/**
James Smart3621a712009-04-06 18:47:14 -04006575 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006576 * @phba: pointer to lpfc hba data structure.
6577 *
6578 * This routine issues one fabric iocb from the driver internal list to
6579 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6580 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6581 * remove one pending fabric iocb from the driver internal list and invokes
6582 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6583 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006584static void
6585lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6586{
6587 struct lpfc_iocbq *iocb;
6588 unsigned long iflags;
6589 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006590 IOCB_t *cmd;
6591
6592repeat:
6593 iocb = NULL;
6594 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006595 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006596 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6597 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6598 list);
6599 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006600 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006601 atomic_inc(&phba->fabric_iocb_count);
6602 }
6603 spin_unlock_irqrestore(&phba->hbalock, iflags);
6604 if (iocb) {
6605 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6606 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6607 iocb->iocb_flag |= LPFC_IO_FABRIC;
6608
James Smart858c9f62007-06-17 19:56:39 -05006609 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6610 "Fabric sched1: ste:x%x",
6611 iocb->vport->port_state, 0, 0);
6612
James Smart3772a992009-05-22 14:50:54 -04006613 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006614
6615 if (ret == IOCB_ERROR) {
6616 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6617 iocb->fabric_iocb_cmpl = NULL;
6618 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6619 cmd = &iocb->iocb;
6620 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6621 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6622 iocb->iocb_cmpl(phba, iocb, iocb);
6623
6624 atomic_dec(&phba->fabric_iocb_count);
6625 goto repeat;
6626 }
6627 }
6628
6629 return;
6630}
6631
James Smarte59058c2008-08-24 21:49:00 -04006632/**
James Smart3621a712009-04-06 18:47:14 -04006633 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006634 * @phba: pointer to lpfc hba data structure.
6635 *
6636 * This routine unblocks the issuing fabric iocb command. The function
6637 * will clear the fabric iocb block bit and then invoke the routine
6638 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6639 * from the driver internal fabric iocb list.
6640 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006641void
6642lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6643{
6644 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6645
6646 lpfc_resume_fabric_iocbs(phba);
6647 return;
6648}
6649
James Smarte59058c2008-08-24 21:49:00 -04006650/**
James Smart3621a712009-04-06 18:47:14 -04006651 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006652 * @phba: pointer to lpfc hba data structure.
6653 *
6654 * This routine blocks the issuing fabric iocb for a specified amount of
6655 * time (currently 100 ms). This is done by set the fabric iocb block bit
6656 * and set up a timeout timer for 100ms. When the block bit is set, no more
6657 * fabric iocb will be issued out of the HBA.
6658 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006659static void
6660lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6661{
6662 int blocked;
6663
6664 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006665 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006666 if (!blocked)
6667 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6668
6669 return;
6670}
6671
James Smarte59058c2008-08-24 21:49:00 -04006672/**
James Smart3621a712009-04-06 18:47:14 -04006673 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006674 * @phba: pointer to lpfc hba data structure.
6675 * @cmdiocb: pointer to lpfc command iocb data structure.
6676 * @rspiocb: pointer to lpfc response iocb data structure.
6677 *
6678 * This routine is the callback function that is put to the fabric iocb's
6679 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6680 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6681 * function first restores and invokes the original iocb's callback function
6682 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6683 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6684 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006685static void
6686lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6687 struct lpfc_iocbq *rspiocb)
6688{
6689 struct ls_rjt stat;
6690
6691 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6692 BUG();
6693
6694 switch (rspiocb->iocb.ulpStatus) {
6695 case IOSTAT_NPORT_RJT:
6696 case IOSTAT_FABRIC_RJT:
6697 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6698 lpfc_block_fabric_iocbs(phba);
6699 }
6700 break;
6701
6702 case IOSTAT_NPORT_BSY:
6703 case IOSTAT_FABRIC_BSY:
6704 lpfc_block_fabric_iocbs(phba);
6705 break;
6706
6707 case IOSTAT_LS_RJT:
6708 stat.un.lsRjtError =
6709 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6710 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6711 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6712 lpfc_block_fabric_iocbs(phba);
6713 break;
6714 }
6715
6716 if (atomic_read(&phba->fabric_iocb_count) == 0)
6717 BUG();
6718
6719 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6720 cmdiocb->fabric_iocb_cmpl = NULL;
6721 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6722 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6723
6724 atomic_dec(&phba->fabric_iocb_count);
6725 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006726 /* Post any pending iocbs to HBA */
6727 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006728 }
6729}
6730
James Smarte59058c2008-08-24 21:49:00 -04006731/**
James Smart3621a712009-04-06 18:47:14 -04006732 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006733 * @phba: pointer to lpfc hba data structure.
6734 * @iocb: pointer to lpfc command iocb data structure.
6735 *
6736 * This routine is used as the top-level API for issuing a fabric iocb command
6737 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6738 * function makes sure that only one fabric bound iocb will be outstanding at
6739 * any given time. As such, this function will first check to see whether there
6740 * is already an outstanding fabric iocb on the wire. If so, it will put the
6741 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6742 * issued later. Otherwise, it will issue the iocb on the wire and update the
6743 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6744 *
6745 * Note, this implementation has a potential sending out fabric IOCBs out of
6746 * order. The problem is caused by the construction of the "ready" boolen does
6747 * not include the condition that the internal fabric IOCB list is empty. As
6748 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6749 * ahead of the fabric IOCBs in the internal list.
6750 *
6751 * Return code
6752 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6753 * IOCB_ERROR - failed to issue fabric iocb
6754 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006755static int
James Smart92d7f7b2007-06-17 19:56:38 -05006756lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6757{
6758 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006759 int ready;
6760 int ret;
6761
6762 if (atomic_read(&phba->fabric_iocb_count) > 1)
6763 BUG();
6764
6765 spin_lock_irqsave(&phba->hbalock, iflags);
6766 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6767 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6768
James Smart7f5f3d02008-02-08 18:50:14 -05006769 if (ready)
6770 /* Increment fabric iocb count to hold the position */
6771 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006772 spin_unlock_irqrestore(&phba->hbalock, iflags);
6773 if (ready) {
6774 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6775 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6776 iocb->iocb_flag |= LPFC_IO_FABRIC;
6777
James Smart858c9f62007-06-17 19:56:39 -05006778 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6779 "Fabric sched2: ste:x%x",
6780 iocb->vport->port_state, 0, 0);
6781
James Smart3772a992009-05-22 14:50:54 -04006782 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006783
6784 if (ret == IOCB_ERROR) {
6785 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6786 iocb->fabric_iocb_cmpl = NULL;
6787 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6788 atomic_dec(&phba->fabric_iocb_count);
6789 }
6790 } else {
6791 spin_lock_irqsave(&phba->hbalock, iflags);
6792 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6793 spin_unlock_irqrestore(&phba->hbalock, iflags);
6794 ret = IOCB_SUCCESS;
6795 }
6796 return ret;
6797}
6798
James Smarte59058c2008-08-24 21:49:00 -04006799/**
James Smart3621a712009-04-06 18:47:14 -04006800 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006801 * @vport: pointer to a virtual N_Port data structure.
6802 *
6803 * This routine aborts all the IOCBs associated with a @vport from the
6804 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6805 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6806 * list, removes each IOCB associated with the @vport off the list, set the
6807 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6808 * associated with the IOCB.
6809 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006810static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006811{
6812 LIST_HEAD(completions);
6813 struct lpfc_hba *phba = vport->phba;
6814 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006815
6816 spin_lock_irq(&phba->hbalock);
6817 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6818 list) {
6819
6820 if (piocb->vport != vport)
6821 continue;
6822
6823 list_move_tail(&piocb->list, &completions);
6824 }
6825 spin_unlock_irq(&phba->hbalock);
6826
James Smarta257bf92009-04-06 18:48:10 -04006827 /* Cancel all the IOCBs from the completions list */
6828 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6829 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006830}
6831
James Smarte59058c2008-08-24 21:49:00 -04006832/**
James Smart3621a712009-04-06 18:47:14 -04006833 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006834 * @ndlp: pointer to a node-list data structure.
6835 *
6836 * This routine aborts all the IOCBs associated with an @ndlp from the
6837 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6838 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6839 * list, removes each IOCB associated with the @ndlp off the list, set the
6840 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6841 * associated with the IOCB.
6842 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006843void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6844{
6845 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006846 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006847 struct lpfc_iocbq *tmp_iocb, *piocb;
6848 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006849
6850 spin_lock_irq(&phba->hbalock);
6851 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6852 list) {
6853 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6854
6855 list_move_tail(&piocb->list, &completions);
6856 }
6857 }
6858 spin_unlock_irq(&phba->hbalock);
6859
James Smarta257bf92009-04-06 18:48:10 -04006860 /* Cancel all the IOCBs from the completions list */
6861 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6862 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006863}
6864
James Smarte59058c2008-08-24 21:49:00 -04006865/**
James Smart3621a712009-04-06 18:47:14 -04006866 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006867 * @phba: pointer to lpfc hba data structure.
6868 *
6869 * This routine aborts all the IOCBs currently on the driver internal
6870 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6871 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6872 * list, removes IOCBs off the list, set the status feild to
6873 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6874 * the IOCB.
6875 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006876void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6877{
6878 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006879
6880 spin_lock_irq(&phba->hbalock);
6881 list_splice_init(&phba->fabric_iocb_list, &completions);
6882 spin_unlock_irq(&phba->hbalock);
6883
James Smarta257bf92009-04-06 18:48:10 -04006884 /* Cancel all the IOCBs from the completions list */
6885 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6886 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006887}
James Smart6fb120a2009-05-22 14:52:59 -04006888
6889/**
6890 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6891 * @phba: pointer to lpfc hba data structure.
6892 * @axri: pointer to the els xri abort wcqe structure.
6893 *
6894 * This routine is invoked by the worker thread to process a SLI4 slow-path
6895 * ELS aborted xri.
6896 **/
6897void
6898lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6899 struct sli4_wcqe_xri_aborted *axri)
6900{
6901 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6902 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6903 unsigned long iflag = 0;
6904
James Smart0f65ff62010-02-26 14:14:23 -05006905 spin_lock_irqsave(&phba->hbalock, iflag);
6906 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006907 list_for_each_entry_safe(sglq_entry, sglq_next,
6908 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6909 if (sglq_entry->sli4_xritag == xri) {
6910 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006911 list_add_tail(&sglq_entry->list,
6912 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05006913 sglq_entry->state = SGL_FREED;
6914 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006915 spin_unlock_irqrestore(&phba->hbalock, iflag);
6916 return;
6917 }
6918 }
James Smart0f65ff62010-02-26 14:14:23 -05006919 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6920 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6921 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6922 spin_unlock_irqrestore(&phba->hbalock, iflag);
6923 return;
6924 }
6925 sglq_entry->state = SGL_XRI_ABORTED;
6926 spin_unlock_irqrestore(&phba->hbalock, iflag);
6927 return;
James Smart6fb120a2009-05-22 14:52:59 -04006928}