blob: f936f8c7efe17e17b59eb826368045047e406a12 [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 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001475 /* PLOGI failed Don't print the vport to vport rjts */
1476 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1477 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1478 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1479 (phba)->pport->cfg_log_verbose & LOG_ELS)
1480 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001481 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1482 ndlp->nlp_DID, irsp->ulpStatus,
1483 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001484 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001485 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001486 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001487 else
James Smart2e0fef82007-06-17 19:56:36 -05001488 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001489 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001490 } else {
1491 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001492 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001493 cmdiocb->context2)->list.next,
1494 struct lpfc_dmabuf, list);
1495 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001496 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001497 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001498 }
1499
James Smart2e0fef82007-06-17 19:56:36 -05001500 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001501 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001502 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001503
James Smart2e0fef82007-06-17 19:56:36 -05001504 if (vport->num_disc_nodes == 0) {
1505 spin_lock_irq(shost->host_lock);
1506 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1507 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001508
James Smart2e0fef82007-06-17 19:56:36 -05001509 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001510 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001511 }
1512 }
1513
1514out:
1515 lpfc_els_free_iocb(phba, cmdiocb);
1516 return;
1517}
1518
James Smarte59058c2008-08-24 21:49:00 -04001519/**
James Smart3621a712009-04-06 18:47:14 -04001520 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001521 * @vport: pointer to a host virtual N_Port data structure.
1522 * @did: destination port identifier.
1523 * @retry: number of retries to the command IOCB.
1524 *
1525 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1526 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1527 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1528 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1529 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1530 *
1531 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1532 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1533 * will be stored into the context1 field of the IOCB for the completion
1534 * callback function to the PLOGI ELS command.
1535 *
1536 * Return code
1537 * 0 - Successfully issued a plogi for @vport
1538 * 1 - failed to issue a plogi for @vport
1539 **/
dea31012005-04-17 16:05:31 -05001540int
James Smart2e0fef82007-06-17 19:56:36 -05001541lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001542{
James Smart2e0fef82007-06-17 19:56:36 -05001543 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001544 struct serv_parm *sp;
1545 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001546 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001547 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001548 struct lpfc_sli *psli;
1549 uint8_t *pcmd;
1550 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001551 int ret;
dea31012005-04-17 16:05:31 -05001552
1553 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001554
James Smart98c9ea52007-10-27 13:37:33 -04001555 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001556 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1557 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001558
James Smarte47c9092008-02-08 18:49:26 -05001559 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001560 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001561 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001562 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001563 if (!elsiocb)
1564 return 1;
dea31012005-04-17 16:05:31 -05001565
1566 icmd = &elsiocb->iocb;
1567 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1568
1569 /* For PLOGI request, remainder of payload is service parameters */
1570 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001571 pcmd += sizeof(uint32_t);
1572 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001573 sp = (struct serv_parm *) pcmd;
1574
1575 if (sp->cmn.fcphLow < FC_PH_4_3)
1576 sp->cmn.fcphLow = FC_PH_4_3;
1577
1578 if (sp->cmn.fcphHigh < FC_PH3)
1579 sp->cmn.fcphHigh = FC_PH3;
1580
James Smart858c9f62007-06-17 19:56:39 -05001581 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1582 "Issue PLOGI: did:x%x",
1583 did, 0, 0);
1584
dea31012005-04-17 16:05:31 -05001585 phba->fc_stat.elsXmitPLOGI++;
1586 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001587 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001588
1589 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001590 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001591 return 1;
dea31012005-04-17 16:05:31 -05001592 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001593 return 0;
dea31012005-04-17 16:05:31 -05001594}
1595
James Smarte59058c2008-08-24 21:49:00 -04001596/**
James Smart3621a712009-04-06 18:47:14 -04001597 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001598 * @phba: pointer to lpfc hba data structure.
1599 * @cmdiocb: pointer to lpfc command iocb data structure.
1600 * @rspiocb: pointer to lpfc response iocb data structure.
1601 *
1602 * This routine is the completion callback function for a Process Login
1603 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1604 * status. If there is error status reported, PRLI retry shall be attempted
1605 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1606 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1607 * ndlp to mark the PRLI completion.
1608 **/
dea31012005-04-17 16:05:31 -05001609static void
James Smart2e0fef82007-06-17 19:56:36 -05001610lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1611 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001612{
James Smart2e0fef82007-06-17 19:56:36 -05001613 struct lpfc_vport *vport = cmdiocb->vport;
1614 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001615 IOCB_t *irsp;
1616 struct lpfc_sli *psli;
1617 struct lpfc_nodelist *ndlp;
1618
1619 psli = &phba->sli;
1620 /* we pass cmdiocb to state machine which needs rspiocb as well */
1621 cmdiocb->context_un.rsp_iocb = rspiocb;
1622
1623 irsp = &(rspiocb->iocb);
1624 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001625 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001626 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001627 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001628
James Smart858c9f62007-06-17 19:56:39 -05001629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1630 "PRLI cmpl: status:x%x/x%x did:x%x",
1631 irsp->ulpStatus, irsp->un.ulpWord[4],
1632 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001633 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001634 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1635 "0103 PRLI completes to NPort x%x "
1636 "Data: x%x x%x x%x x%x\n",
1637 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1638 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001639
James Smart2e0fef82007-06-17 19:56:36 -05001640 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001641 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001642 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001643 goto out;
1644
1645 if (irsp->ulpStatus) {
1646 /* Check for retry */
1647 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1648 /* ELS command is being retried */
1649 goto out;
1650 }
1651 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001652 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1653 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1654 ndlp->nlp_DID, irsp->ulpStatus,
1655 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001656 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001657 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001658 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001659 else
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);
James Smarte47c9092008-02-08 18:49:26 -05001662 } else
dea31012005-04-17 16:05:31 -05001663 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001664 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001665 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001666out:
1667 lpfc_els_free_iocb(phba, cmdiocb);
1668 return;
1669}
1670
James Smarte59058c2008-08-24 21:49:00 -04001671/**
James Smart3621a712009-04-06 18:47:14 -04001672 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001673 * @vport: pointer to a host virtual N_Port data structure.
1674 * @ndlp: pointer to a node-list data structure.
1675 * @retry: number of retries to the command IOCB.
1676 *
1677 * This routine issues a Process Login (PRLI) ELS command for the
1678 * @vport. The PRLI service parameters are set up in the payload of the
1679 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1680 * is put to the IOCB completion callback func field before invoking the
1681 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1682 *
1683 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1684 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1685 * will be stored into the context1 field of the IOCB for the completion
1686 * callback function to the PRLI ELS command.
1687 *
1688 * Return code
1689 * 0 - successfully issued prli iocb command for @vport
1690 * 1 - failed to issue prli iocb command for @vport
1691 **/
dea31012005-04-17 16:05:31 -05001692int
James Smart2e0fef82007-06-17 19:56:36 -05001693lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001694 uint8_t retry)
1695{
James Smart2e0fef82007-06-17 19:56:36 -05001696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1697 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001698 PRLI *npr;
1699 IOCB_t *icmd;
1700 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001701 uint8_t *pcmd;
1702 uint16_t cmdsize;
1703
James Smart92d7f7b2007-06-17 19:56:38 -05001704 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001705 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1706 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001707 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001708 return 1;
dea31012005-04-17 16:05:31 -05001709
1710 icmd = &elsiocb->iocb;
1711 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1712
1713 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001714 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001715 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001716 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001717
1718 /* For PRLI, remainder of payload is PRLI parameter page */
1719 npr = (PRLI *) pcmd;
1720 /*
1721 * If our firmware version is 3.20 or later,
1722 * set the following bits for FC-TAPE support.
1723 */
1724 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1725 npr->ConfmComplAllowed = 1;
1726 npr->Retry = 1;
1727 npr->TaskRetryIdReq = 1;
1728 }
1729 npr->estabImagePair = 1;
1730 npr->readXferRdyDis = 1;
1731
1732 /* For FCP support */
1733 npr->prliType = PRLI_FCP_TYPE;
1734 npr->initiatorFunc = 1;
1735
James Smart858c9f62007-06-17 19:56:39 -05001736 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1737 "Issue PRLI: did:x%x",
1738 ndlp->nlp_DID, 0, 0);
1739
dea31012005-04-17 16:05:31 -05001740 phba->fc_stat.elsXmitPRLI++;
1741 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001742 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001743 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001744 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001745 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1746 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001747 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001748 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001749 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001750 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001751 return 1;
dea31012005-04-17 16:05:31 -05001752 }
James Smart2e0fef82007-06-17 19:56:36 -05001753 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001754 return 0;
dea31012005-04-17 16:05:31 -05001755}
1756
James Smarte59058c2008-08-24 21:49:00 -04001757/**
James Smart3621a712009-04-06 18:47:14 -04001758 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001759 * @vport: pointer to a host virtual N_Port data structure.
1760 *
1761 * This routine performs Registration State Change Notification (RSCN)
1762 * discovery for a @vport. If the @vport's node port recovery count is not
1763 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1764 * the nodes that need recovery. If none of the PLOGI were needed through
1765 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1766 * invoked to check and handle possible more RSCN came in during the period
1767 * of processing the current ones.
1768 **/
1769static void
1770lpfc_rscn_disc(struct lpfc_vport *vport)
1771{
1772 lpfc_can_disctmo(vport);
1773
1774 /* RSCN discovery */
1775 /* go thru NPR nodes and issue ELS PLOGIs */
1776 if (vport->fc_npr_cnt)
1777 if (lpfc_els_disc_plogi(vport))
1778 return;
1779
1780 lpfc_end_rscn(vport);
1781}
1782
1783/**
James Smart3621a712009-04-06 18:47:14 -04001784 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001785 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1786 *
1787 * This function is called when the final ADISC is completed during discovery.
1788 * This function handles clearing link attention or issuing reg_vpi depending
1789 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1790 * discovery.
1791 * This function is called with no locks held.
1792 **/
1793static void
1794lpfc_adisc_done(struct lpfc_vport *vport)
1795{
1796 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1797 struct lpfc_hba *phba = vport->phba;
1798
1799 /*
1800 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1801 * and continue discovery.
1802 */
1803 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001804 !(vport->fc_flag & FC_RSCN_MODE) &&
1805 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001806 lpfc_issue_reg_vpi(phba, vport);
1807 return;
1808 }
1809 /*
1810 * For SLI2, we need to set port_state to READY
1811 * and continue discovery.
1812 */
1813 if (vport->port_state < LPFC_VPORT_READY) {
1814 /* If we get here, there is nothing to ADISC */
1815 if (vport->port_type == LPFC_PHYSICAL_PORT)
1816 lpfc_issue_clear_la(phba, vport);
1817 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1818 vport->num_disc_nodes = 0;
1819 /* go thru NPR list, issue ELS PLOGIs */
1820 if (vport->fc_npr_cnt)
1821 lpfc_els_disc_plogi(vport);
1822 if (!vport->num_disc_nodes) {
1823 spin_lock_irq(shost->host_lock);
1824 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1825 spin_unlock_irq(shost->host_lock);
1826 lpfc_can_disctmo(vport);
1827 lpfc_end_rscn(vport);
1828 }
1829 }
1830 vport->port_state = LPFC_VPORT_READY;
1831 } else
1832 lpfc_rscn_disc(vport);
1833}
1834
1835/**
James Smart3621a712009-04-06 18:47:14 -04001836 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001837 * @vport: pointer to a host virtual N_Port data structure.
1838 *
1839 * This routine determines whether there are more ndlps on a @vport
1840 * node list need to have Address Discover (ADISC) issued. If so, it will
1841 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1842 * remaining nodes which need to have ADISC sent.
1843 **/
James Smart0ff10d42008-01-11 01:52:36 -05001844void
James Smart2e0fef82007-06-17 19:56:36 -05001845lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001846{
1847 int sentadisc;
1848
James Smart2e0fef82007-06-17 19:56:36 -05001849 if (vport->num_disc_nodes)
1850 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001851 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001852 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1853 "0210 Continue discovery with %d ADISCs to go "
1854 "Data: x%x x%x x%x\n",
1855 vport->num_disc_nodes, vport->fc_adisc_cnt,
1856 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001857 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001858 if (vport->fc_flag & FC_NLP_MORE) {
1859 lpfc_set_disctmo(vport);
1860 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1861 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001862 }
James Smart90160e02008-08-24 21:49:45 -04001863 if (!vport->num_disc_nodes)
1864 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001865 return;
1866}
1867
James Smarte59058c2008-08-24 21:49:00 -04001868/**
James Smart3621a712009-04-06 18:47:14 -04001869 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001870 * @phba: pointer to lpfc hba data structure.
1871 * @cmdiocb: pointer to lpfc command iocb data structure.
1872 * @rspiocb: pointer to lpfc response iocb data structure.
1873 *
1874 * This routine is the completion function for issuing the Address Discover
1875 * (ADISC) command. It first checks to see whether link went down during
1876 * the discovery process. If so, the node will be marked as node port
1877 * recovery for issuing discover IOCB by the link attention handler and
1878 * exit. Otherwise, the response status is checked. If error was reported
1879 * in the response status, the ADISC command shall be retried by invoking
1880 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1881 * the response status, the state machine is invoked to set transition
1882 * with respect to NLP_EVT_CMPL_ADISC event.
1883 **/
dea31012005-04-17 16:05:31 -05001884static void
James Smart2e0fef82007-06-17 19:56:36 -05001885lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1886 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001887{
James Smart2e0fef82007-06-17 19:56:36 -05001888 struct lpfc_vport *vport = cmdiocb->vport;
1889 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001890 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001891 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001892 int disc;
dea31012005-04-17 16:05:31 -05001893
1894 /* we pass cmdiocb to state machine which needs rspiocb as well */
1895 cmdiocb->context_un.rsp_iocb = rspiocb;
1896
1897 irsp = &(rspiocb->iocb);
1898 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001899
James Smart858c9f62007-06-17 19:56:39 -05001900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1901 "ADISC cmpl: status:x%x/x%x did:x%x",
1902 irsp->ulpStatus, irsp->un.ulpWord[4],
1903 ndlp->nlp_DID);
1904
dea31012005-04-17 16:05:31 -05001905 /* Since ndlp can be freed in the disc state machine, note if this node
1906 * is being used during discovery.
1907 */
James Smart2e0fef82007-06-17 19:56:36 -05001908 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001909 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001910 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001911 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001912 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001913 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1914 "0104 ADISC completes to NPort x%x "
1915 "Data: x%x x%x x%x x%x x%x\n",
1916 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1917 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001918 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001919 if (lpfc_els_chk_latt(vport)) {
1920 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001921 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001922 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001923 goto out;
1924 }
1925
1926 if (irsp->ulpStatus) {
1927 /* Check for retry */
1928 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1929 /* ELS command is being retried */
1930 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001931 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001932 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001933 spin_unlock_irq(shost->host_lock);
1934 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001935 }
1936 goto out;
1937 }
1938 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001939 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1940 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1941 ndlp->nlp_DID, irsp->ulpStatus,
1942 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001943 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001944 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001945 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001946 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001947 } else
dea31012005-04-17 16:05:31 -05001948 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001949 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001950 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001951
James Smart90160e02008-08-24 21:49:45 -04001952 /* Check to see if there are more ADISCs to be sent */
1953 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001954 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001955out:
1956 lpfc_els_free_iocb(phba, cmdiocb);
1957 return;
1958}
1959
James Smarte59058c2008-08-24 21:49:00 -04001960/**
James Smart3621a712009-04-06 18:47:14 -04001961 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001962 * @vport: pointer to a virtual N_Port data structure.
1963 * @ndlp: pointer to a node-list data structure.
1964 * @retry: number of retries to the command IOCB.
1965 *
1966 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1967 * @vport. It prepares the payload of the ADISC ELS command, updates the
1968 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1969 * to issue the ADISC ELS command.
1970 *
1971 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1972 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1973 * will be stored into the context1 field of the IOCB for the completion
1974 * callback function to the ADISC ELS command.
1975 *
1976 * Return code
1977 * 0 - successfully issued adisc
1978 * 1 - failed to issue adisc
1979 **/
dea31012005-04-17 16:05:31 -05001980int
James Smart2e0fef82007-06-17 19:56:36 -05001981lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001982 uint8_t retry)
1983{
James Smart2e0fef82007-06-17 19:56:36 -05001984 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1985 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001986 ADISC *ap;
1987 IOCB_t *icmd;
1988 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001989 uint8_t *pcmd;
1990 uint16_t cmdsize;
1991
James Smart92d7f7b2007-06-17 19:56:38 -05001992 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001993 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1994 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001995 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001996 return 1;
dea31012005-04-17 16:05:31 -05001997
1998 icmd = &elsiocb->iocb;
1999 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2000
2001 /* For ADISC request, remainder of payload is service parameters */
2002 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002003 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002004
2005 /* Fill in ADISC payload */
2006 ap = (ADISC *) pcmd;
2007 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002008 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2009 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002010 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002011
James Smart858c9f62007-06-17 19:56:39 -05002012 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2013 "Issue ADISC: did:x%x",
2014 ndlp->nlp_DID, 0, 0);
2015
dea31012005-04-17 16:05:31 -05002016 phba->fc_stat.elsXmitADISC++;
2017 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002018 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002019 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002020 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002021 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2022 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002023 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002024 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002025 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002026 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002027 return 1;
dea31012005-04-17 16:05:31 -05002028 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002029 return 0;
dea31012005-04-17 16:05:31 -05002030}
2031
James Smarte59058c2008-08-24 21:49:00 -04002032/**
James Smart3621a712009-04-06 18:47:14 -04002033 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002034 * @phba: pointer to lpfc hba data structure.
2035 * @cmdiocb: pointer to lpfc command iocb data structure.
2036 * @rspiocb: pointer to lpfc response iocb data structure.
2037 *
2038 * This routine is the completion function for issuing the ELS Logout (LOGO)
2039 * command. If no error status was reported from the LOGO response, the
2040 * state machine of the associated ndlp shall be invoked for transition with
2041 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2042 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2043 **/
dea31012005-04-17 16:05:31 -05002044static void
James Smart2e0fef82007-06-17 19:56:36 -05002045lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2046 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002047{
James Smart2e0fef82007-06-17 19:56:36 -05002048 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2049 struct lpfc_vport *vport = ndlp->vport;
2050 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002051 IOCB_t *irsp;
2052 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002053
2054 psli = &phba->sli;
2055 /* we pass cmdiocb to state machine which needs rspiocb as well */
2056 cmdiocb->context_un.rsp_iocb = rspiocb;
2057
2058 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002059 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002060 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002061 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002062
James Smart858c9f62007-06-17 19:56:39 -05002063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2064 "LOGO cmpl: status:x%x/x%x did:x%x",
2065 irsp->ulpStatus, irsp->un.ulpWord[4],
2066 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002067 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002068 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2069 "0105 LOGO completes to NPort x%x "
2070 "Data: x%x x%x x%x x%x\n",
2071 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2072 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002073 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002074 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002075 goto out;
2076
James Smart92d7f7b2007-06-17 19:56:38 -05002077 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2078 /* NLP_EVT_DEVICE_RM should unregister the RPI
2079 * which should abort all outstanding IOs.
2080 */
2081 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2082 NLP_EVT_DEVICE_RM);
2083 goto out;
2084 }
2085
dea31012005-04-17 16:05:31 -05002086 if (irsp->ulpStatus) {
2087 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002088 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002089 /* ELS command is being retried */
2090 goto out;
dea31012005-04-17 16:05:31 -05002091 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002092 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2093 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2094 ndlp->nlp_DID, irsp->ulpStatus,
2095 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002096 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002097 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002098 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002099 else
James Smart2e0fef82007-06-17 19:56:36 -05002100 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002101 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002102 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002103 /* Good status, call state machine.
2104 * This will unregister the rpi if needed.
2105 */
James Smart2e0fef82007-06-17 19:56:36 -05002106 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002107 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002108out:
2109 lpfc_els_free_iocb(phba, cmdiocb);
2110 return;
2111}
2112
James Smarte59058c2008-08-24 21:49:00 -04002113/**
James Smart3621a712009-04-06 18:47:14 -04002114 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002115 * @vport: pointer to a virtual N_Port data structure.
2116 * @ndlp: pointer to a node-list data structure.
2117 * @retry: number of retries to the command IOCB.
2118 *
2119 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2120 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2121 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2122 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2123 *
2124 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2125 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2126 * will be stored into the context1 field of the IOCB for the completion
2127 * callback function to the LOGO ELS command.
2128 *
2129 * Return code
2130 * 0 - successfully issued logo
2131 * 1 - failed to issue logo
2132 **/
dea31012005-04-17 16:05:31 -05002133int
James Smart2e0fef82007-06-17 19:56:36 -05002134lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002135 uint8_t retry)
2136{
James Smart2e0fef82007-06-17 19:56:36 -05002137 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2138 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002139 IOCB_t *icmd;
2140 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002141 uint8_t *pcmd;
2142 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002143 int rc;
dea31012005-04-17 16:05:31 -05002144
James Smart98c9ea52007-10-27 13:37:33 -04002145 spin_lock_irq(shost->host_lock);
2146 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2147 spin_unlock_irq(shost->host_lock);
2148 return 0;
2149 }
2150 spin_unlock_irq(shost->host_lock);
2151
James Smart92d7f7b2007-06-17 19:56:38 -05002152 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002153 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2154 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002155 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002156 return 1;
dea31012005-04-17 16:05:31 -05002157
2158 icmd = &elsiocb->iocb;
2159 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2160 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002161 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002162
2163 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002164 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002165 pcmd += sizeof(uint32_t);
2166 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002167
James Smart858c9f62007-06-17 19:56:39 -05002168 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2169 "Issue LOGO: did:x%x",
2170 ndlp->nlp_DID, 0, 0);
2171
dea31012005-04-17 16:05:31 -05002172 phba->fc_stat.elsXmitLOGO++;
2173 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002174 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002175 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002176 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002177 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002178
2179 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002180 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002181 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002182 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002183 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002184 return 1;
dea31012005-04-17 16:05:31 -05002185 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002186 return 0;
dea31012005-04-17 16:05:31 -05002187}
2188
James Smarte59058c2008-08-24 21:49:00 -04002189/**
James Smart3621a712009-04-06 18:47:14 -04002190 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002191 * @phba: pointer to lpfc hba data structure.
2192 * @cmdiocb: pointer to lpfc command iocb data structure.
2193 * @rspiocb: pointer to lpfc response iocb data structure.
2194 *
2195 * This routine is a generic completion callback function for ELS commands.
2196 * Specifically, it is the callback function which does not need to perform
2197 * any command specific operations. It is currently used by the ELS command
2198 * issuing routines for the ELS State Change Request (SCR),
2199 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2200 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2201 * certain debug loggings, this callback function simply invokes the
2202 * lpfc_els_chk_latt() routine to check whether link went down during the
2203 * discovery process.
2204 **/
dea31012005-04-17 16:05:31 -05002205static void
James Smart2e0fef82007-06-17 19:56:36 -05002206lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2207 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002208{
James Smart2e0fef82007-06-17 19:56:36 -05002209 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002210 IOCB_t *irsp;
2211
2212 irsp = &rspiocb->iocb;
2213
James Smart858c9f62007-06-17 19:56:39 -05002214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2215 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2216 irsp->ulpStatus, irsp->un.ulpWord[4],
2217 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002218 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002219 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2220 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2221 irsp->ulpIoTag, irsp->ulpStatus,
2222 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002223 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002224 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002225 lpfc_els_free_iocb(phba, cmdiocb);
2226 return;
2227}
2228
James Smarte59058c2008-08-24 21:49:00 -04002229/**
James Smart3621a712009-04-06 18:47:14 -04002230 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002231 * @vport: pointer to a host virtual N_Port data structure.
2232 * @nportid: N_Port identifier to the remote node.
2233 * @retry: number of retries to the command IOCB.
2234 *
2235 * This routine issues a State Change Request (SCR) to a fabric node
2236 * on a @vport. The remote node @nportid is passed into the function. It
2237 * first search the @vport node list to find the matching ndlp. If no such
2238 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2239 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2240 * routine is invoked to send the SCR IOCB.
2241 *
2242 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2243 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2244 * will be stored into the context1 field of the IOCB for the completion
2245 * callback function to the SCR ELS command.
2246 *
2247 * Return code
2248 * 0 - Successfully issued scr command
2249 * 1 - Failed to issue scr command
2250 **/
dea31012005-04-17 16:05:31 -05002251int
James Smart2e0fef82007-06-17 19:56:36 -05002252lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002253{
James Smart2e0fef82007-06-17 19:56:36 -05002254 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002255 IOCB_t *icmd;
2256 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002257 struct lpfc_sli *psli;
2258 uint8_t *pcmd;
2259 uint16_t cmdsize;
2260 struct lpfc_nodelist *ndlp;
2261
2262 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002263 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002264
James Smarte47c9092008-02-08 18:49:26 -05002265 ndlp = lpfc_findnode_did(vport, nportid);
2266 if (!ndlp) {
2267 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2268 if (!ndlp)
2269 return 1;
2270 lpfc_nlp_init(vport, ndlp, nportid);
2271 lpfc_enqueue_node(vport, ndlp);
2272 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2273 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2274 if (!ndlp)
2275 return 1;
2276 }
dea31012005-04-17 16:05:31 -05002277
James Smart2e0fef82007-06-17 19:56:36 -05002278 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2279 ndlp->nlp_DID, ELS_CMD_SCR);
2280
James Smart488d1462006-03-07 15:02:37 -05002281 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002282 /* This will trigger the release of the node just
2283 * allocated
2284 */
James Smart329f9bc2007-04-25 09:53:01 -04002285 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002286 return 1;
dea31012005-04-17 16:05:31 -05002287 }
2288
2289 icmd = &elsiocb->iocb;
2290 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2291
2292 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002293 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002294
2295 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002296 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002297 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2298
James Smart858c9f62007-06-17 19:56:39 -05002299 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2300 "Issue SCR: did:x%x",
2301 ndlp->nlp_DID, 0, 0);
2302
dea31012005-04-17 16:05:31 -05002303 phba->fc_stat.elsXmitSCR++;
2304 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002305 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2306 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002307 /* The additional lpfc_nlp_put will cause the following
2308 * lpfc_els_free_iocb routine to trigger the rlease of
2309 * the node.
2310 */
James Smart329f9bc2007-04-25 09:53:01 -04002311 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002312 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002313 return 1;
dea31012005-04-17 16:05:31 -05002314 }
James Smartfa4066b2008-01-11 01:53:27 -05002315 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2316 * trigger the release of node.
2317 */
James Smart329f9bc2007-04-25 09:53:01 -04002318 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002319 return 0;
dea31012005-04-17 16:05:31 -05002320}
2321
James Smarte59058c2008-08-24 21:49:00 -04002322/**
James Smart3621a712009-04-06 18:47:14 -04002323 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002324 * @vport: pointer to a host virtual N_Port data structure.
2325 * @nportid: N_Port identifier to the remote node.
2326 * @retry: number of retries to the command IOCB.
2327 *
2328 * This routine issues a Fibre Channel Address Resolution Response
2329 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2330 * is passed into the function. It first search the @vport node list to find
2331 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2332 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2333 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2334 *
2335 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2336 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2337 * will be stored into the context1 field of the IOCB for the completion
2338 * callback function to the PARPR ELS command.
2339 *
2340 * Return code
2341 * 0 - Successfully issued farpr command
2342 * 1 - Failed to issue farpr command
2343 **/
dea31012005-04-17 16:05:31 -05002344static int
James Smart2e0fef82007-06-17 19:56:36 -05002345lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002346{
James Smart2e0fef82007-06-17 19:56:36 -05002347 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002348 IOCB_t *icmd;
2349 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002350 struct lpfc_sli *psli;
2351 FARP *fp;
2352 uint8_t *pcmd;
2353 uint32_t *lp;
2354 uint16_t cmdsize;
2355 struct lpfc_nodelist *ondlp;
2356 struct lpfc_nodelist *ndlp;
2357
2358 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002359 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002360
James Smarte47c9092008-02-08 18:49:26 -05002361 ndlp = lpfc_findnode_did(vport, nportid);
2362 if (!ndlp) {
2363 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2364 if (!ndlp)
2365 return 1;
2366 lpfc_nlp_init(vport, ndlp, nportid);
2367 lpfc_enqueue_node(vport, ndlp);
2368 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2369 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2370 if (!ndlp)
2371 return 1;
2372 }
James Smart2e0fef82007-06-17 19:56:36 -05002373
2374 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2375 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002376 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002377 /* This will trigger the release of the node just
2378 * allocated
2379 */
James Smart329f9bc2007-04-25 09:53:01 -04002380 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002381 return 1;
dea31012005-04-17 16:05:31 -05002382 }
2383
2384 icmd = &elsiocb->iocb;
2385 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2386
2387 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002388 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002389
2390 /* Fill in FARPR payload */
2391 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002392 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002393 lp = (uint32_t *) pcmd;
2394 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002395 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002396 fp->Rflags = 0;
2397 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2398
James Smart92d7f7b2007-06-17 19:56:38 -05002399 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2400 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002401 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002402 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002403 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002404 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002405 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002406 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002407 }
2408
James Smart858c9f62007-06-17 19:56:39 -05002409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2410 "Issue FARPR: did:x%x",
2411 ndlp->nlp_DID, 0, 0);
2412
dea31012005-04-17 16:05:31 -05002413 phba->fc_stat.elsXmitFARPR++;
2414 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002415 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2416 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002417 /* The additional lpfc_nlp_put will cause the following
2418 * lpfc_els_free_iocb routine to trigger the release of
2419 * the node.
2420 */
James Smart329f9bc2007-04-25 09:53:01 -04002421 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002422 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002423 return 1;
dea31012005-04-17 16:05:31 -05002424 }
James Smartfa4066b2008-01-11 01:53:27 -05002425 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2426 * trigger the release of the node.
2427 */
James Smart329f9bc2007-04-25 09:53:01 -04002428 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002429 return 0;
dea31012005-04-17 16:05:31 -05002430}
2431
James Smarte59058c2008-08-24 21:49:00 -04002432/**
James Smart3621a712009-04-06 18:47:14 -04002433 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002434 * @vport: pointer to a host virtual N_Port data structure.
2435 * @nlp: pointer to a node-list data structure.
2436 *
2437 * This routine cancels the timer with a delayed IOCB-command retry for
2438 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2439 * removes the ELS retry event if it presents. In addition, if the
2440 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2441 * commands are sent for the @vport's nodes that require issuing discovery
2442 * ADISC.
2443 **/
dea31012005-04-17 16:05:31 -05002444void
James Smart2e0fef82007-06-17 19:56:36 -05002445lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002446{
James Smart2e0fef82007-06-17 19:56:36 -05002447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002448 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002449
James Smart0d2b6b82008-06-14 22:52:47 -04002450 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2451 return;
James Smart2e0fef82007-06-17 19:56:36 -05002452 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002453 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002454 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002455 del_timer_sync(&nlp->nlp_delayfunc);
2456 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002457 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002458 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002459 /* Decrement nlp reference count held for the delayed retry */
2460 evtp = &nlp->els_retry_evt;
2461 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2462 }
James Smartfdcebe22006-03-07 15:04:01 -05002463 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002464 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002465 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002466 spin_unlock_irq(shost->host_lock);
2467 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002468 if (vport->port_state < LPFC_VPORT_READY) {
2469 /* Check if there are more ADISCs to be sent */
2470 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002471 } else {
2472 /* Check if there are more PLOGIs to be sent */
2473 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002474 if (vport->num_disc_nodes == 0) {
2475 spin_lock_irq(shost->host_lock);
2476 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2477 spin_unlock_irq(shost->host_lock);
2478 lpfc_can_disctmo(vport);
2479 lpfc_end_rscn(vport);
2480 }
James Smartfdcebe22006-03-07 15:04:01 -05002481 }
2482 }
2483 }
2484 return;
2485}
2486
James Smarte59058c2008-08-24 21:49:00 -04002487/**
James Smart3621a712009-04-06 18:47:14 -04002488 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002489 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2490 *
2491 * This routine is invoked by the ndlp delayed-function timer to check
2492 * whether there is any pending ELS retry event(s) with the node. If not, it
2493 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2494 * adds the delayed events to the HBA work list and invokes the
2495 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2496 * event. Note that lpfc_nlp_get() is called before posting the event to
2497 * the work list to hold reference count of ndlp so that it guarantees the
2498 * reference to ndlp will still be available when the worker thread gets
2499 * to the event associated with the ndlp.
2500 **/
James Smartfdcebe22006-03-07 15:04:01 -05002501void
dea31012005-04-17 16:05:31 -05002502lpfc_els_retry_delay(unsigned long ptr)
2503{
James Smart2e0fef82007-06-17 19:56:36 -05002504 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2505 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002506 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002507 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002508 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002509
James Smart92d7f7b2007-06-17 19:56:38 -05002510 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002511 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002512 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002513 return;
2514 }
2515
James Smartfa4066b2008-01-11 01:53:27 -05002516 /* We need to hold the node by incrementing the reference
2517 * count until the queued work is done
2518 */
2519 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002520 if (evtp->evt_arg1) {
2521 evtp->evt = LPFC_EVT_ELS_RETRY;
2522 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002523 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002524 }
James Smart92d7f7b2007-06-17 19:56:38 -05002525 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002526 return;
2527}
2528
James Smarte59058c2008-08-24 21:49:00 -04002529/**
James Smart3621a712009-04-06 18:47:14 -04002530 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002531 * @ndlp: pointer to a node-list data structure.
2532 *
2533 * This routine is the worker-thread handler for processing the @ndlp delayed
2534 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2535 * the last ELS command from the associated ndlp and invokes the proper ELS
2536 * function according to the delayed ELS command to retry the command.
2537 **/
dea31012005-04-17 16:05:31 -05002538void
2539lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2540{
James Smart2e0fef82007-06-17 19:56:36 -05002541 struct lpfc_vport *vport = ndlp->vport;
2542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2543 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002544
James Smart2e0fef82007-06-17 19:56:36 -05002545 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002546 did = ndlp->nlp_DID;
2547 cmd = ndlp->nlp_last_elscmd;
2548 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002549
2550 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002551 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002552 return;
2553 }
2554
2555 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002556 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002557 /*
2558 * If a discovery event readded nlp_delayfunc after timer
2559 * firing and before processing the timer, cancel the
2560 * nlp_delayfunc.
2561 */
2562 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002563 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002564 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002565
2566 switch (cmd) {
2567 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002568 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002569 break;
2570 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002571 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002572 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002573 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002574 }
dea31012005-04-17 16:05:31 -05002575 break;
2576 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002577 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002578 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002579 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002580 }
dea31012005-04-17 16:05:31 -05002581 break;
2582 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002583 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002584 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002585 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002586 }
dea31012005-04-17 16:05:31 -05002587 break;
2588 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002589 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002590 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002591 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002592 }
dea31012005-04-17 16:05:31 -05002593 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002594 case ELS_CMD_FDISC:
2595 lpfc_issue_els_fdisc(vport, ndlp, retry);
2596 break;
dea31012005-04-17 16:05:31 -05002597 }
2598 return;
2599}
2600
James Smarte59058c2008-08-24 21:49:00 -04002601/**
James Smart3621a712009-04-06 18:47:14 -04002602 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002603 * @phba: pointer to lpfc hba data structure.
2604 * @cmdiocb: pointer to lpfc command iocb data structure.
2605 * @rspiocb: pointer to lpfc response iocb data structure.
2606 *
2607 * This routine makes a retry decision on an ELS command IOCB, which has
2608 * failed. The following ELS IOCBs use this function for retrying the command
2609 * when previously issued command responsed with error status: FLOGI, PLOGI,
2610 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2611 * returned error status, it makes the decision whether a retry shall be
2612 * issued for the command, and whether a retry shall be made immediately or
2613 * delayed. In the former case, the corresponding ELS command issuing-function
2614 * is called to retry the command. In the later case, the ELS command shall
2615 * be posted to the ndlp delayed event and delayed function timer set to the
2616 * ndlp for the delayed command issusing.
2617 *
2618 * Return code
2619 * 0 - No retry of els command is made
2620 * 1 - Immediate or delayed retry of els command is made
2621 **/
dea31012005-04-17 16:05:31 -05002622static int
James Smart2e0fef82007-06-17 19:56:36 -05002623lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2624 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002625{
James Smart2e0fef82007-06-17 19:56:36 -05002626 struct lpfc_vport *vport = cmdiocb->vport;
2627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2628 IOCB_t *irsp = &rspiocb->iocb;
2629 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2630 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002631 uint32_t *elscmd;
2632 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002633 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002634 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002635 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002636 uint32_t did;
dea31012005-04-17 16:05:31 -05002637
James Smart488d1462006-03-07 15:02:37 -05002638
dea31012005-04-17 16:05:31 -05002639 /* Note: context2 may be 0 for internal driver abort
2640 * of delays ELS command.
2641 */
2642
2643 if (pcmd && pcmd->virt) {
2644 elscmd = (uint32_t *) (pcmd->virt);
2645 cmd = *elscmd++;
2646 }
2647
James Smarte47c9092008-02-08 18:49:26 -05002648 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002649 did = ndlp->nlp_DID;
2650 else {
2651 /* We should only hit this case for retrying PLOGI */
2652 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002653 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002654 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2655 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002656 return 1;
2657 }
2658
James Smart858c9f62007-06-17 19:56:39 -05002659 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2660 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2661 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2662
dea31012005-04-17 16:05:31 -05002663 switch (irsp->ulpStatus) {
2664 case IOSTAT_FCP_RSP_ERROR:
2665 case IOSTAT_REMOTE_STOP:
2666 break;
2667
2668 case IOSTAT_LOCAL_REJECT:
2669 switch ((irsp->un.ulpWord[4] & 0xff)) {
2670 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002671 if (cmd == ELS_CMD_FLOGI) {
2672 if (PCI_DEVICE_ID_HORNET ==
2673 phba->pcidev->device) {
2674 phba->fc_topology = TOPOLOGY_LOOP;
2675 phba->pport->fc_myDID = 0;
2676 phba->alpa_map[0] = 0;
2677 phba->alpa_map[1] = 0;
2678 }
2679 }
James Smart2e0fef82007-06-17 19:56:36 -05002680 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002681 delay = 1000;
dea31012005-04-17 16:05:31 -05002682 retry = 1;
2683 break;
2684
James Smart92d7f7b2007-06-17 19:56:38 -05002685 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002686 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2687 "0124 Retry illegal cmd x%x "
2688 "retry:x%x delay:x%x\n",
2689 cmd, cmdiocb->retry, delay);
2690 retry = 1;
2691 /* All command's retry policy */
2692 maxretry = 8;
2693 if (cmdiocb->retry > 2)
2694 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002695 break;
2696
dea31012005-04-17 16:05:31 -05002697 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002698 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002699 retry = 1;
2700 if (cmdiocb->retry > 100)
2701 delay = 100;
2702 maxretry = 250;
2703 break;
2704
2705 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002706 delay = 100;
dea31012005-04-17 16:05:31 -05002707 retry = 1;
2708 break;
2709
James Smart858c9f62007-06-17 19:56:39 -05002710 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002711 case IOERR_INVALID_RPI:
2712 retry = 1;
2713 break;
2714 }
2715 break;
2716
2717 case IOSTAT_NPORT_RJT:
2718 case IOSTAT_FABRIC_RJT:
2719 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2720 retry = 1;
2721 break;
2722 }
2723 break;
2724
2725 case IOSTAT_NPORT_BSY:
2726 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002727 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002728 retry = 1;
2729 break;
2730
2731 case IOSTAT_LS_RJT:
2732 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2733 /* Added for Vendor specifc support
2734 * Just keep retrying for these Rsn / Exp codes
2735 */
2736 switch (stat.un.b.lsRjtRsnCode) {
2737 case LSRJT_UNABLE_TPC:
2738 if (stat.un.b.lsRjtRsnCodeExp ==
2739 LSEXP_CMD_IN_PROGRESS) {
2740 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002741 delay = 1000;
dea31012005-04-17 16:05:31 -05002742 maxretry = 48;
2743 }
2744 retry = 1;
2745 break;
2746 }
James Smartffc95492010-06-07 15:23:17 -04002747 if (stat.un.b.lsRjtRsnCodeExp ==
2748 LSEXP_CANT_GIVE_DATA) {
2749 if (cmd == ELS_CMD_PLOGI) {
2750 delay = 1000;
2751 maxretry = 48;
2752 }
2753 retry = 1;
2754 break;
2755 }
dea31012005-04-17 16:05:31 -05002756 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002757 delay = 1000;
dea31012005-04-17 16:05:31 -05002758 maxretry = lpfc_max_els_tries + 1;
2759 retry = 1;
2760 break;
2761 }
James Smart92d7f7b2007-06-17 19:56:38 -05002762 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2763 (cmd == ELS_CMD_FDISC) &&
2764 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002765 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2766 "0125 FDISC Failed (x%x). "
2767 "Fabric out of resources\n",
2768 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002769 lpfc_vport_set_state(vport,
2770 FC_VPORT_NO_FABRIC_RSCS);
2771 }
dea31012005-04-17 16:05:31 -05002772 break;
2773
2774 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002775 if ((cmd == ELS_CMD_PLOGI) ||
2776 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002777 delay = 1000;
dea31012005-04-17 16:05:31 -05002778 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002779 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002780 /* FDISC retry policy */
2781 maxretry = 48;
2782 if (cmdiocb->retry >= 32)
2783 delay = 1000;
dea31012005-04-17 16:05:31 -05002784 }
2785 retry = 1;
2786 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002787
2788 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002789 /* There are some cases where switches return this
2790 * error when they are not ready and should be returning
2791 * Logical Busy. We should delay every time.
2792 */
2793 if (cmd == ELS_CMD_FDISC &&
2794 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2795 maxretry = 3;
2796 delay = 1000;
2797 retry = 1;
2798 break;
2799 }
James Smart92d7f7b2007-06-17 19:56:38 -05002800 case LSRJT_PROTOCOL_ERR:
2801 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2802 (cmd == ELS_CMD_FDISC) &&
2803 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2804 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2805 ) {
James Smarte8b62012007-08-02 11:10:09 -04002806 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002807 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002808 "Fabric Detected Bad WWN\n",
2809 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002810 lpfc_vport_set_state(vport,
2811 FC_VPORT_FABRIC_REJ_WWN);
2812 }
2813 break;
dea31012005-04-17 16:05:31 -05002814 }
2815 break;
2816
2817 case IOSTAT_INTERMED_RSP:
2818 case IOSTAT_BA_RJT:
2819 break;
2820
2821 default:
2822 break;
2823 }
2824
James Smart488d1462006-03-07 15:02:37 -05002825 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002826 retry = 1;
dea31012005-04-17 16:05:31 -05002827
James Smart695a8142010-01-26 23:08:03 -05002828 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002829 (phba->fc_topology != TOPOLOGY_LOOP) &&
2830 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002831 /* FLOGI retry policy */
2832 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002833 /* retry forever */
2834 maxretry = 0;
2835 if (cmdiocb->retry >= 100)
2836 delay = 5000;
2837 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002838 delay = 1000;
2839 }
2840
James Smart6669f9b2009-10-02 15:16:45 -04002841 cmdiocb->retry++;
2842 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002843 phba->fc_stat.elsRetryExceeded++;
2844 retry = 0;
2845 }
2846
James Smarted957682007-06-17 19:56:37 -05002847 if ((vport->load_flag & FC_UNLOADING) != 0)
2848 retry = 0;
2849
dea31012005-04-17 16:05:31 -05002850 if (retry) {
2851
2852 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002853 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2854 "0107 Retry ELS command x%x to remote "
2855 "NPORT x%x Data: x%x x%x\n",
2856 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002857
James Smart858c9f62007-06-17 19:56:39 -05002858 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2859 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2860 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2861 /* Don't reset timer for no resources */
2862
dea31012005-04-17 16:05:31 -05002863 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002864 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002865 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002866 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002867 }
2868
2869 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002870 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002871 phba->fc_stat.elsDelayRetry++;
2872 ndlp->nlp_retry = cmdiocb->retry;
2873
James Smart92d7f7b2007-06-17 19:56:38 -05002874 /* delay is specified in milliseconds */
2875 mod_timer(&ndlp->nlp_delayfunc,
2876 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002877 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002878 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002879 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002880
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002881 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002882 if (cmd == ELS_CMD_PRLI)
2883 lpfc_nlp_set_state(vport, ndlp,
2884 NLP_STE_REG_LOGIN_ISSUE);
2885 else
2886 lpfc_nlp_set_state(vport, ndlp,
2887 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002888 ndlp->nlp_last_elscmd = cmd;
2889
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002890 return 1;
dea31012005-04-17 16:05:31 -05002891 }
2892 switch (cmd) {
2893 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002894 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002895 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002896 case ELS_CMD_FDISC:
2897 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2898 return 1;
dea31012005-04-17 16:05:31 -05002899 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002900 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002901 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002902 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002903 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002904 }
James Smart2e0fef82007-06-17 19:56:36 -05002905 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002906 return 1;
dea31012005-04-17 16:05:31 -05002907 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002908 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002909 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2910 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002911 return 1;
dea31012005-04-17 16:05:31 -05002912 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002913 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002914 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2915 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002916 return 1;
dea31012005-04-17 16:05:31 -05002917 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002918 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002919 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2920 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002921 return 1;
dea31012005-04-17 16:05:31 -05002922 }
2923 }
dea31012005-04-17 16:05:31 -05002924 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002925 if (logerr) {
2926 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2927 "0137 No retry ELS command x%x to remote "
2928 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2929 cmd, did, irsp->ulpStatus,
2930 irsp->un.ulpWord[4]);
2931 }
2932 else {
2933 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002934 "0108 No retry ELS command x%x to remote "
2935 "NPORT x%x Retried:%d Error:x%x/%x\n",
2936 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2937 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002938 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002939 return 0;
dea31012005-04-17 16:05:31 -05002940}
2941
James Smarte59058c2008-08-24 21:49:00 -04002942/**
James Smart3621a712009-04-06 18:47:14 -04002943 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002944 * @phba: pointer to lpfc hba data structure.
2945 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2946 *
2947 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2948 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2949 * checks to see whether there is a lpfc DMA buffer associated with the
2950 * response of the command IOCB. If so, it will be released before releasing
2951 * the lpfc DMA buffer associated with the IOCB itself.
2952 *
2953 * Return code
2954 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2955 **/
James Smart09372822008-01-11 01:52:54 -05002956static int
James Smart87af33f2007-10-27 13:37:43 -04002957lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2958{
2959 struct lpfc_dmabuf *buf_ptr;
2960
James Smarte59058c2008-08-24 21:49:00 -04002961 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002962 if (!list_empty(&buf_ptr1->list)) {
2963 list_remove_head(&buf_ptr1->list, buf_ptr,
2964 struct lpfc_dmabuf,
2965 list);
2966 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2967 kfree(buf_ptr);
2968 }
2969 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2970 kfree(buf_ptr1);
2971 return 0;
2972}
2973
James Smarte59058c2008-08-24 21:49:00 -04002974/**
James Smart3621a712009-04-06 18:47:14 -04002975 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002976 * @phba: pointer to lpfc hba data structure.
2977 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2978 *
2979 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2980 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2981 * pool.
2982 *
2983 * Return code
2984 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2985 **/
James Smart09372822008-01-11 01:52:54 -05002986static int
James Smart87af33f2007-10-27 13:37:43 -04002987lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2988{
2989 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2990 kfree(buf_ptr);
2991 return 0;
2992}
2993
James Smarte59058c2008-08-24 21:49:00 -04002994/**
James Smart3621a712009-04-06 18:47:14 -04002995 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002996 * @phba: pointer to lpfc hba data structure.
2997 * @elsiocb: pointer to lpfc els command iocb data structure.
2998 *
2999 * This routine frees a command IOCB and its associated resources. The
3000 * command IOCB data structure contains the reference to various associated
3001 * resources, these fields must be set to NULL if the associated reference
3002 * not present:
3003 * context1 - reference to ndlp
3004 * context2 - reference to cmd
3005 * context2->next - reference to rsp
3006 * context3 - reference to bpl
3007 *
3008 * It first properly decrements the reference count held on ndlp for the
3009 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3010 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3011 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3012 * adds the DMA buffer the @phba data structure for the delayed release.
3013 * If reference to the Buffer Pointer List (BPL) is present, the
3014 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3015 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3016 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3017 *
3018 * Return code
3019 * 0 - Success (currently, always return 0)
3020 **/
James Smart87af33f2007-10-27 13:37:43 -04003021int
James Smart329f9bc2007-04-25 09:53:01 -04003022lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003023{
3024 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003025 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003026
James Smarta8adb832007-10-27 13:37:53 -04003027 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3028 if (ndlp) {
3029 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3030 lpfc_nlp_put(ndlp);
3031
3032 /* If the ndlp is not being used by another discovery
3033 * thread, free it.
3034 */
3035 if (!lpfc_nlp_not_used(ndlp)) {
3036 /* If ndlp is being used by another discovery
3037 * thread, just clear NLP_DEFER_RM
3038 */
3039 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3040 }
3041 }
3042 else
3043 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003044 elsiocb->context1 = NULL;
3045 }
dea31012005-04-17 16:05:31 -05003046 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3047 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003048 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3049 /* Firmware could still be in progress of DMAing
3050 * payload, so don't free data buffer till after
3051 * a hbeat.
3052 */
3053 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3054 buf_ptr = elsiocb->context2;
3055 elsiocb->context2 = NULL;
3056 if (buf_ptr) {
3057 buf_ptr1 = NULL;
3058 spin_lock_irq(&phba->hbalock);
3059 if (!list_empty(&buf_ptr->list)) {
3060 list_remove_head(&buf_ptr->list,
3061 buf_ptr1, struct lpfc_dmabuf,
3062 list);
3063 INIT_LIST_HEAD(&buf_ptr1->list);
3064 list_add_tail(&buf_ptr1->list,
3065 &phba->elsbuf);
3066 phba->elsbuf_cnt++;
3067 }
3068 INIT_LIST_HEAD(&buf_ptr->list);
3069 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3070 phba->elsbuf_cnt++;
3071 spin_unlock_irq(&phba->hbalock);
3072 }
3073 } else {
3074 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3075 lpfc_els_free_data(phba, buf_ptr1);
3076 }
dea31012005-04-17 16:05:31 -05003077 }
3078
3079 if (elsiocb->context3) {
3080 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003081 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003082 }
James Bottomley604a3e32005-10-29 10:28:33 -05003083 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003084 return 0;
3085}
3086
James Smarte59058c2008-08-24 21:49:00 -04003087/**
James Smart3621a712009-04-06 18:47:14 -04003088 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003089 * @phba: pointer to lpfc hba data structure.
3090 * @cmdiocb: pointer to lpfc command iocb data structure.
3091 * @rspiocb: pointer to lpfc response iocb data structure.
3092 *
3093 * This routine is the completion callback function to the Logout (LOGO)
3094 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3095 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3096 * release the ndlp if it has the last reference remaining (reference count
3097 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3098 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3099 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3100 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3101 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3102 * IOCB data structure.
3103 **/
dea31012005-04-17 16:05:31 -05003104static void
James Smart2e0fef82007-06-17 19:56:36 -05003105lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3106 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003107{
James Smart2e0fef82007-06-17 19:56:36 -05003108 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3109 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003110 IOCB_t *irsp;
3111
3112 irsp = &rspiocb->iocb;
3113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3114 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3115 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003116 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3118 "0109 ACC to LOGO completes to NPort x%x "
3119 "Data: x%x x%x x%x\n",
3120 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3121 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003122
3123 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3124 /* NPort Recovery mode or node is just allocated */
3125 if (!lpfc_nlp_not_used(ndlp)) {
3126 /* If the ndlp is being used by another discovery
3127 * thread, just unregister the RPI.
3128 */
3129 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003130 } else {
3131 /* Indicate the node has already released, should
3132 * not reference to it from within lpfc_els_free_iocb.
3133 */
3134 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003135 }
dea31012005-04-17 16:05:31 -05003136 }
3137 lpfc_els_free_iocb(phba, cmdiocb);
3138 return;
3139}
3140
James Smarte59058c2008-08-24 21:49:00 -04003141/**
James Smart3621a712009-04-06 18:47:14 -04003142 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003143 * @phba: pointer to lpfc hba data structure.
3144 * @pmb: pointer to the driver internal queue element for mailbox command.
3145 *
3146 * This routine is the completion callback function for unregister default
3147 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3148 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3149 * decrements the ndlp reference count held for this completion callback
3150 * function. After that, it invokes the lpfc_nlp_not_used() to check
3151 * whether there is only one reference left on the ndlp. If so, it will
3152 * perform one more decrement and trigger the release of the ndlp.
3153 **/
James Smart858c9f62007-06-17 19:56:39 -05003154void
3155lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3156{
3157 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3158 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3159
James Smart6fb120a2009-05-22 14:52:59 -04003160 /*
3161 * This routine is used to register and unregister in previous SLI
3162 * modes.
3163 */
3164 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3165 (phba->sli_rev == LPFC_SLI_REV4))
3166 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3167
James Smart858c9f62007-06-17 19:56:39 -05003168 pmb->context1 = NULL;
3169 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3170 kfree(mp);
3171 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003172 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003173 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003174 /* This is the end of the default RPI cleanup logic for this
3175 * ndlp. If no other discovery threads are using this ndlp.
3176 * we should free all resources associated with it.
3177 */
3178 lpfc_nlp_not_used(ndlp);
3179 }
James Smart3772a992009-05-22 14:50:54 -04003180
James Smart858c9f62007-06-17 19:56:39 -05003181 return;
3182}
3183
James Smarte59058c2008-08-24 21:49:00 -04003184/**
James Smart3621a712009-04-06 18:47:14 -04003185 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003186 * @phba: pointer to lpfc hba data structure.
3187 * @cmdiocb: pointer to lpfc command iocb data structure.
3188 * @rspiocb: pointer to lpfc response iocb data structure.
3189 *
3190 * This routine is the completion callback function for ELS Response IOCB
3191 * command. In normal case, this callback function just properly sets the
3192 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3193 * field in the command IOCB is not NULL, the referred mailbox command will
3194 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3195 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3196 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3197 * routine shall be invoked trying to release the ndlp if no other threads
3198 * are currently referring it.
3199 **/
dea31012005-04-17 16:05:31 -05003200static void
James Smart858c9f62007-06-17 19:56:39 -05003201lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003202 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003203{
James Smart2e0fef82007-06-17 19:56:36 -05003204 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3205 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3206 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003207 IOCB_t *irsp;
3208 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003209 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003210 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003211 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003212
James Smart33ccf8d2006-08-17 11:57:58 -04003213 irsp = &rspiocb->iocb;
3214
dea31012005-04-17 16:05:31 -05003215 if (cmdiocb->context_un.mbox)
3216 mbox = cmdiocb->context_un.mbox;
3217
James Smartfa4066b2008-01-11 01:53:27 -05003218 /* First determine if this is a LS_RJT cmpl. Note, this callback
3219 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3220 */
James Smart87af33f2007-10-27 13:37:43 -04003221 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003222 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3223 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003224 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003225 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003226 */
3227 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3228 ls_rjt = 1;
3229 }
3230
dea31012005-04-17 16:05:31 -05003231 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003232 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003233 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003234 mp = (struct lpfc_dmabuf *) mbox->context1;
3235 if (mp) {
3236 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3237 kfree(mp);
3238 }
James Smart329f9bc2007-04-25 09:53:01 -04003239 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003240 }
James Smart58da1ff2008-04-07 10:15:56 -04003241 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3242 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003243 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003244 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003245 /* Indicate the node has already released,
3246 * should not reference to it from within
3247 * the routine lpfc_els_free_iocb.
3248 */
3249 cmdiocb->context1 = NULL;
3250 }
dea31012005-04-17 16:05:31 -05003251 goto out;
3252 }
3253
James Smart858c9f62007-06-17 19:56:39 -05003254 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003255 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003256 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003257 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003258 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003259 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3260 "0110 ELS response tag x%x completes "
3261 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3262 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3263 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3264 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3265 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003266 if (mbox) {
3267 if ((rspiocb->iocb.ulpStatus == 0)
3268 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003269 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003270 /* Increment reference count to ndlp to hold the
3271 * reference to ndlp for the callback function.
3272 */
James Smart329f9bc2007-04-25 09:53:01 -04003273 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003274 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003275 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3276 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3277 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3278 }
3279 else {
3280 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3281 ndlp->nlp_prev_state = ndlp->nlp_state;
3282 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003283 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003284 }
James Smart0b727fe2007-10-27 13:37:25 -04003285 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003286 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003287 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003288 else
3289 /* Decrement the ndlp reference count we
3290 * set for this failed mailbox command.
3291 */
3292 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003293
3294 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3295 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3296 "0138 ELS rsp: Cannot issue reg_login for x%x "
3297 "Data: x%x x%x x%x\n",
3298 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3299 ndlp->nlp_rpi);
3300
James Smartfa4066b2008-01-11 01:53:27 -05003301 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003302 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003303 /* Indicate node has already been released,
3304 * should not reference to it from within
3305 * the routine lpfc_els_free_iocb.
3306 */
3307 cmdiocb->context1 = NULL;
3308 }
dea31012005-04-17 16:05:31 -05003309 } else {
James Smart858c9f62007-06-17 19:56:39 -05003310 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3311 if (!lpfc_error_lost_link(irsp) &&
3312 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003313 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003314 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003315 /* Indicate node has already been
3316 * released, should not reference
3317 * to it from within the routine
3318 * lpfc_els_free_iocb.
3319 */
3320 cmdiocb->context1 = NULL;
3321 }
dea31012005-04-17 16:05:31 -05003322 }
3323 }
James Smart14691152006-12-02 13:34:28 -05003324 mp = (struct lpfc_dmabuf *) mbox->context1;
3325 if (mp) {
3326 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3327 kfree(mp);
3328 }
3329 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003330 }
3331out:
James Smart58da1ff2008-04-07 10:15:56 -04003332 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003333 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003334 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003335 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003336
3337 /* If the node is not being used by another discovery thread,
3338 * and we are sending a reject, we are done with it.
3339 * Release driver reference count here and free associated
3340 * resources.
3341 */
3342 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003343 if (lpfc_nlp_not_used(ndlp))
3344 /* Indicate node has already been released,
3345 * should not reference to it from within
3346 * the routine lpfc_els_free_iocb.
3347 */
3348 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003349 }
James Smart87af33f2007-10-27 13:37:43 -04003350
dea31012005-04-17 16:05:31 -05003351 lpfc_els_free_iocb(phba, cmdiocb);
3352 return;
3353}
3354
James Smarte59058c2008-08-24 21:49:00 -04003355/**
James Smart3621a712009-04-06 18:47:14 -04003356 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003357 * @vport: pointer to a host virtual N_Port data structure.
3358 * @flag: the els command code to be accepted.
3359 * @oldiocb: pointer to the original lpfc command iocb data structure.
3360 * @ndlp: pointer to a node-list data structure.
3361 * @mbox: pointer to the driver internal queue element for mailbox command.
3362 *
3363 * This routine prepares and issues an Accept (ACC) response IOCB
3364 * command. It uses the @flag to properly set up the IOCB field for the
3365 * specific ACC response command to be issued and invokes the
3366 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3367 * @mbox pointer is passed in, it will be put into the context_un.mbox
3368 * field of the IOCB for the completion callback function to issue the
3369 * mailbox command to the HBA later when callback is invoked.
3370 *
3371 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3372 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3373 * will be stored into the context1 field of the IOCB for the completion
3374 * callback function to the corresponding response ELS IOCB command.
3375 *
3376 * Return code
3377 * 0 - Successfully issued acc response
3378 * 1 - Failed to issue acc response
3379 **/
dea31012005-04-17 16:05:31 -05003380int
James Smart2e0fef82007-06-17 19:56:36 -05003381lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3382 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003383 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003384{
James Smart2e0fef82007-06-17 19:56:36 -05003385 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3386 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003387 IOCB_t *icmd;
3388 IOCB_t *oldcmd;
3389 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003390 struct lpfc_sli *psli;
3391 uint8_t *pcmd;
3392 uint16_t cmdsize;
3393 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003394 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003395
3396 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003397 oldcmd = &oldiocb->iocb;
3398
3399 switch (flag) {
3400 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003401 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003402 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3403 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003404 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003405 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003406 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003407 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003408 return 1;
dea31012005-04-17 16:05:31 -05003409 }
James Smart2e0fef82007-06-17 19:56:36 -05003410
dea31012005-04-17 16:05:31 -05003411 icmd = &elsiocb->iocb;
3412 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3413 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3414 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003415 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003416
3417 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3418 "Issue ACC: did:x%x flg:x%x",
3419 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003420 break;
3421 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003422 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003423 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3424 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003425 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003426 return 1;
James Smart488d1462006-03-07 15:02:37 -05003427
dea31012005-04-17 16:05:31 -05003428 icmd = &elsiocb->iocb;
3429 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3430 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3431
3432 if (mbox)
3433 elsiocb->context_un.mbox = mbox;
3434
3435 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003436 pcmd += sizeof(uint32_t);
3437 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003438
3439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3440 "Issue ACC PLOGI: did:x%x flg:x%x",
3441 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003442 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003443 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003444 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003445 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003446 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3447 if (!elsiocb)
3448 return 1;
3449
3450 icmd = &elsiocb->iocb;
3451 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3452 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3453
3454 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003455 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003456 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3457 els_pkt_ptr = (ELS_PKT *) pcmd;
3458 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003459
3460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3461 "Issue ACC PRLO: did:x%x flg:x%x",
3462 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003463 break;
dea31012005-04-17 16:05:31 -05003464 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003465 return 1;
dea31012005-04-17 16:05:31 -05003466 }
dea31012005-04-17 16:05:31 -05003467 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003468 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3469 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3470 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3471 elsiocb->iotag, elsiocb->iocb.ulpContext,
3472 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3473 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003474 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003475 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003476 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003477 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003478 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3479 } else {
James Smart858c9f62007-06-17 19:56:39 -05003480 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003481 }
3482
3483 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003484 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003485 if (rc == IOCB_ERROR) {
3486 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003487 return 1;
dea31012005-04-17 16:05:31 -05003488 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003489 return 0;
dea31012005-04-17 16:05:31 -05003490}
3491
James Smarte59058c2008-08-24 21:49:00 -04003492/**
James Smart3621a712009-04-06 18:47:14 -04003493 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003494 * @vport: pointer to a virtual N_Port data structure.
3495 * @rejectError:
3496 * @oldiocb: pointer to the original lpfc command iocb data structure.
3497 * @ndlp: pointer to a node-list data structure.
3498 * @mbox: pointer to the driver internal queue element for mailbox command.
3499 *
3500 * This routine prepares and issue an Reject (RJT) response IOCB
3501 * command. If a @mbox pointer is passed in, it will be put into the
3502 * context_un.mbox field of the IOCB for the completion callback function
3503 * to issue to the HBA later.
3504 *
3505 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3506 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3507 * will be stored into the context1 field of the IOCB for the completion
3508 * callback function to the reject response ELS IOCB command.
3509 *
3510 * Return code
3511 * 0 - Successfully issued reject response
3512 * 1 - Failed to issue reject response
3513 **/
dea31012005-04-17 16:05:31 -05003514int
James Smart2e0fef82007-06-17 19:56:36 -05003515lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003516 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3517 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003518{
James Smart2e0fef82007-06-17 19:56:36 -05003519 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003520 IOCB_t *icmd;
3521 IOCB_t *oldcmd;
3522 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003523 struct lpfc_sli *psli;
3524 uint8_t *pcmd;
3525 uint16_t cmdsize;
3526 int rc;
3527
3528 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003529 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003530 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3531 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003532 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003533 return 1;
dea31012005-04-17 16:05:31 -05003534
3535 icmd = &elsiocb->iocb;
3536 oldcmd = &oldiocb->iocb;
3537 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3538 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3539
3540 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003541 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003542 *((uint32_t *) (pcmd)) = rejectError;
3543
James Smart51ef4c22007-08-02 11:10:31 -04003544 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003545 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003546
dea31012005-04-17 16:05:31 -05003547 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003548 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3549 "0129 Xmit ELS RJT x%x response tag x%x "
3550 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3551 "rpi x%x\n",
3552 rejectError, elsiocb->iotag,
3553 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3554 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3556 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3557 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3558
dea31012005-04-17 16:05:31 -05003559 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003560 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003561 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003562
dea31012005-04-17 16:05:31 -05003563 if (rc == IOCB_ERROR) {
3564 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003565 return 1;
dea31012005-04-17 16:05:31 -05003566 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003567 return 0;
dea31012005-04-17 16:05:31 -05003568}
3569
James Smarte59058c2008-08-24 21:49:00 -04003570/**
James Smart3621a712009-04-06 18:47:14 -04003571 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003572 * @vport: pointer to a virtual N_Port data structure.
3573 * @oldiocb: pointer to the original lpfc command iocb data structure.
3574 * @ndlp: pointer to a node-list data structure.
3575 *
3576 * This routine prepares and issues an Accept (ACC) response to Address
3577 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3578 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3579 *
3580 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3581 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3582 * will be stored into the context1 field of the IOCB for the completion
3583 * callback function to the ADISC Accept response ELS IOCB command.
3584 *
3585 * Return code
3586 * 0 - Successfully issued acc adisc response
3587 * 1 - Failed to issue adisc acc response
3588 **/
dea31012005-04-17 16:05:31 -05003589int
James Smart2e0fef82007-06-17 19:56:36 -05003590lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3591 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003592{
James Smart2e0fef82007-06-17 19:56:36 -05003593 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003594 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003595 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003596 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003597 uint8_t *pcmd;
3598 uint16_t cmdsize;
3599 int rc;
3600
James Smart92d7f7b2007-06-17 19:56:38 -05003601 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003602 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3603 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003604 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003605 return 1;
dea31012005-04-17 16:05:31 -05003606
dea31012005-04-17 16:05:31 -05003607 icmd = &elsiocb->iocb;
3608 oldcmd = &oldiocb->iocb;
3609 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003610
3611 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003612 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3613 "0130 Xmit ADISC ACC response iotag x%x xri: "
3614 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3615 elsiocb->iotag, elsiocb->iocb.ulpContext,
3616 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3617 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003618 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3619
3620 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003621 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003622
3623 ap = (ADISC *) (pcmd);
3624 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003625 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3626 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003627 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003628
James Smart858c9f62007-06-17 19:56:39 -05003629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3630 "Issue ACC ADISC: did:x%x flg:x%x",
3631 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3632
dea31012005-04-17 16:05:31 -05003633 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003634 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003635 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003636 if (rc == IOCB_ERROR) {
3637 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003638 return 1;
dea31012005-04-17 16:05:31 -05003639 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003640 return 0;
dea31012005-04-17 16:05:31 -05003641}
3642
James Smarte59058c2008-08-24 21:49:00 -04003643/**
James Smart3621a712009-04-06 18:47:14 -04003644 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003645 * @vport: pointer to a virtual N_Port data structure.
3646 * @oldiocb: pointer to the original lpfc command iocb data structure.
3647 * @ndlp: pointer to a node-list data structure.
3648 *
3649 * This routine prepares and issues an Accept (ACC) response to Process
3650 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3651 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3652 *
3653 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3654 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3655 * will be stored into the context1 field of the IOCB for the completion
3656 * callback function to the PRLI Accept response ELS IOCB command.
3657 *
3658 * Return code
3659 * 0 - Successfully issued acc prli response
3660 * 1 - Failed to issue acc prli response
3661 **/
dea31012005-04-17 16:05:31 -05003662int
James Smart2e0fef82007-06-17 19:56:36 -05003663lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003664 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003665{
James Smart2e0fef82007-06-17 19:56:36 -05003666 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003667 PRLI *npr;
3668 lpfc_vpd_t *vpd;
3669 IOCB_t *icmd;
3670 IOCB_t *oldcmd;
3671 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003672 struct lpfc_sli *psli;
3673 uint8_t *pcmd;
3674 uint16_t cmdsize;
3675 int rc;
3676
3677 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003678
James Smart92d7f7b2007-06-17 19:56:38 -05003679 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003680 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003681 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003682 if (!elsiocb)
3683 return 1;
dea31012005-04-17 16:05:31 -05003684
dea31012005-04-17 16:05:31 -05003685 icmd = &elsiocb->iocb;
3686 oldcmd = &oldiocb->iocb;
3687 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003688 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003689 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3690 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3691 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3692 elsiocb->iotag, elsiocb->iocb.ulpContext,
3693 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3694 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003695 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3696
3697 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003698 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003699
3700 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003701 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003702
3703 npr = (PRLI *) pcmd;
3704 vpd = &phba->vpd;
3705 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003706 * If the remote port is a target and our firmware version is 3.20 or
3707 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003708 */
James Smart0d2b6b82008-06-14 22:52:47 -04003709 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3710 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003711 npr->ConfmComplAllowed = 1;
3712 npr->Retry = 1;
3713 npr->TaskRetryIdReq = 1;
3714 }
3715
3716 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3717 npr->estabImagePair = 1;
3718 npr->readXferRdyDis = 1;
3719 npr->ConfmComplAllowed = 1;
3720
3721 npr->prliType = PRLI_FCP_TYPE;
3722 npr->initiatorFunc = 1;
3723
James Smart858c9f62007-06-17 19:56:39 -05003724 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3725 "Issue ACC PRLI: did:x%x flg:x%x",
3726 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3727
dea31012005-04-17 16:05:31 -05003728 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003729 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003730
James Smart3772a992009-05-22 14:50:54 -04003731 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003732 if (rc == IOCB_ERROR) {
3733 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003734 return 1;
dea31012005-04-17 16:05:31 -05003735 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003736 return 0;
dea31012005-04-17 16:05:31 -05003737}
3738
James Smarte59058c2008-08-24 21:49:00 -04003739/**
James Smart3621a712009-04-06 18:47:14 -04003740 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003741 * @vport: pointer to a virtual N_Port data structure.
3742 * @format: rnid command format.
3743 * @oldiocb: pointer to the original lpfc command iocb data structure.
3744 * @ndlp: pointer to a node-list data structure.
3745 *
3746 * This routine issues a Request Node Identification Data (RNID) Accept
3747 * (ACC) response. It constructs the RNID ACC response command according to
3748 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3749 * issue the response. Note that this command does not need to hold the ndlp
3750 * reference count for the callback. So, the ndlp reference count taken by
3751 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3752 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3753 * there is no ndlp reference available.
3754 *
3755 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3756 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3757 * will be stored into the context1 field of the IOCB for the completion
3758 * callback function. However, for the RNID Accept Response ELS command,
3759 * this is undone later by this routine after the IOCB is allocated.
3760 *
3761 * Return code
3762 * 0 - Successfully issued acc rnid response
3763 * 1 - Failed to issue acc rnid response
3764 **/
dea31012005-04-17 16:05:31 -05003765static int
James Smart2e0fef82007-06-17 19:56:36 -05003766lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003767 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003768{
James Smart2e0fef82007-06-17 19:56:36 -05003769 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003770 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003771 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003772 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003773 struct lpfc_sli *psli;
3774 uint8_t *pcmd;
3775 uint16_t cmdsize;
3776 int rc;
3777
3778 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003779 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3780 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003781 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003782 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003783
James Smart2e0fef82007-06-17 19:56:36 -05003784 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3785 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003786 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003787 return 1;
dea31012005-04-17 16:05:31 -05003788
dea31012005-04-17 16:05:31 -05003789 icmd = &elsiocb->iocb;
3790 oldcmd = &oldiocb->iocb;
3791 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003792 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003793 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3794 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3795 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003796 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003797 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003798 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003799
James Smart92d7f7b2007-06-17 19:56:38 -05003800 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003801 rn = (RNID *) (pcmd);
3802 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003803 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3804 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3805 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003806 switch (format) {
3807 case 0:
3808 rn->SpecificLen = 0;
3809 break;
3810 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003811 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003812 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003813 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003814 rn->un.topologyDisc.unitType = RNID_HBA;
3815 rn->un.topologyDisc.physPort = 0;
3816 rn->un.topologyDisc.attachedNodes = 0;
3817 break;
3818 default:
3819 rn->CommonLen = 0;
3820 rn->SpecificLen = 0;
3821 break;
3822 }
3823
James Smart858c9f62007-06-17 19:56:39 -05003824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3825 "Issue ACC RNID: did:x%x flg:x%x",
3826 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3827
dea31012005-04-17 16:05:31 -05003828 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003829 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003830 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003831 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3832 * it could be freed */
3833
James Smart3772a992009-05-22 14:50:54 -04003834 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003835 if (rc == IOCB_ERROR) {
3836 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003837 return 1;
dea31012005-04-17 16:05:31 -05003838 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003839 return 0;
dea31012005-04-17 16:05:31 -05003840}
3841
James Smarte59058c2008-08-24 21:49:00 -04003842/**
James Smart3621a712009-04-06 18:47:14 -04003843 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003844 * @vport: pointer to a host virtual N_Port data structure.
3845 *
3846 * This routine issues Address Discover (ADISC) ELS commands to those
3847 * N_Ports which are in node port recovery state and ADISC has not been issued
3848 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3849 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3850 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3851 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3852 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3853 * IOCBs quit for later pick up. On the other hand, after walking through
3854 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3855 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3856 * no more ADISC need to be sent.
3857 *
3858 * Return code
3859 * The number of N_Ports with adisc issued.
3860 **/
dea31012005-04-17 16:05:31 -05003861int
James Smart2e0fef82007-06-17 19:56:36 -05003862lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003863{
James Smart2e0fef82007-06-17 19:56:36 -05003864 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003865 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003866 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003867
James Smart685f0bf2007-04-25 09:53:08 -04003868 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003869 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003870 if (!NLP_CHK_NODE_ACT(ndlp))
3871 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003872 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3873 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3874 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003875 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003876 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003877 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003878 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003879 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3880 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003881 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003882 vport->num_disc_nodes++;
3883 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003884 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003885 spin_lock_irq(shost->host_lock);
3886 vport->fc_flag |= FC_NLP_MORE;
3887 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003888 break;
dea31012005-04-17 16:05:31 -05003889 }
3890 }
3891 }
3892 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003893 spin_lock_irq(shost->host_lock);
3894 vport->fc_flag &= ~FC_NLP_MORE;
3895 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003896 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003897 return sentadisc;
dea31012005-04-17 16:05:31 -05003898}
3899
James Smarte59058c2008-08-24 21:49:00 -04003900/**
James Smart3621a712009-04-06 18:47:14 -04003901 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003902 * @vport: pointer to a host virtual N_Port data structure.
3903 *
3904 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3905 * which are in node port recovery state, with a @vport. Each time an ELS
3906 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3907 * the per @vport number of discover count (num_disc_nodes) shall be
3908 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3909 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3910 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3911 * later pick up. On the other hand, after walking through all the ndlps with
3912 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3913 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3914 * PLOGI need to be sent.
3915 *
3916 * Return code
3917 * The number of N_Ports with plogi issued.
3918 **/
dea31012005-04-17 16:05:31 -05003919int
James Smart2e0fef82007-06-17 19:56:36 -05003920lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003921{
James Smart2e0fef82007-06-17 19:56:36 -05003922 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003923 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003924 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003925
James Smart2e0fef82007-06-17 19:56:36 -05003926 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3927 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003928 if (!NLP_CHK_NODE_ACT(ndlp))
3929 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003930 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3931 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3932 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3933 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3934 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003935 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3936 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003937 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003938 vport->num_disc_nodes++;
3939 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003940 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003941 spin_lock_irq(shost->host_lock);
3942 vport->fc_flag |= FC_NLP_MORE;
3943 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003944 break;
dea31012005-04-17 16:05:31 -05003945 }
3946 }
3947 }
James Smart87af33f2007-10-27 13:37:43 -04003948 if (sentplogi) {
3949 lpfc_set_disctmo(vport);
3950 }
3951 else {
James Smart2e0fef82007-06-17 19:56:36 -05003952 spin_lock_irq(shost->host_lock);
3953 vport->fc_flag &= ~FC_NLP_MORE;
3954 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003955 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003956 return sentplogi;
dea31012005-04-17 16:05:31 -05003957}
3958
James Smarte59058c2008-08-24 21:49:00 -04003959/**
James Smart3621a712009-04-06 18:47:14 -04003960 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003961 * @vport: pointer to a host virtual N_Port data structure.
3962 *
3963 * This routine cleans up any Registration State Change Notification
3964 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3965 * @vport together with the host_lock is used to prevent multiple thread
3966 * trying to access the RSCN array on a same @vport at the same time.
3967 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003968void
James Smart2e0fef82007-06-17 19:56:36 -05003969lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003970{
James Smart2e0fef82007-06-17 19:56:36 -05003971 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3972 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003973 int i;
3974
James Smart7f5f3d02008-02-08 18:50:14 -05003975 spin_lock_irq(shost->host_lock);
3976 if (vport->fc_rscn_flush) {
3977 /* Another thread is walking fc_rscn_id_list on this vport */
3978 spin_unlock_irq(shost->host_lock);
3979 return;
3980 }
3981 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3982 vport->fc_rscn_flush = 1;
3983 spin_unlock_irq(shost->host_lock);
3984
James Smart2e0fef82007-06-17 19:56:36 -05003985 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003986 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003987 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003988 }
James Smart2e0fef82007-06-17 19:56:36 -05003989 spin_lock_irq(shost->host_lock);
3990 vport->fc_rscn_id_cnt = 0;
3991 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3992 spin_unlock_irq(shost->host_lock);
3993 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003994 /* Indicate we are done walking this fc_rscn_id_list */
3995 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003996}
3997
James Smarte59058c2008-08-24 21:49:00 -04003998/**
James Smart3621a712009-04-06 18:47:14 -04003999 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004000 * @vport: pointer to a host virtual N_Port data structure.
4001 * @did: remote destination port identifier.
4002 *
4003 * This routine checks whether there is any pending Registration State
4004 * Configuration Notification (RSCN) to a @did on @vport.
4005 *
4006 * Return code
4007 * None zero - The @did matched with a pending rscn
4008 * 0 - not able to match @did with a pending rscn
4009 **/
dea31012005-04-17 16:05:31 -05004010int
James Smart2e0fef82007-06-17 19:56:36 -05004011lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004012{
4013 D_ID ns_did;
4014 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004015 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004016 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004017 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004018
4019 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004020
4021 /* Never match fabric nodes for RSCNs */
4022 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004023 return 0;
dea31012005-04-17 16:05:31 -05004024
4025 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004026 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004027 return did;
dea31012005-04-17 16:05:31 -05004028
James Smart7f5f3d02008-02-08 18:50:14 -05004029 spin_lock_irq(shost->host_lock);
4030 if (vport->fc_rscn_flush) {
4031 /* Another thread is walking fc_rscn_id_list on this vport */
4032 spin_unlock_irq(shost->host_lock);
4033 return 0;
4034 }
4035 /* Indicate we are walking fc_rscn_id_list on this vport */
4036 vport->fc_rscn_flush = 1;
4037 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004038 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004039 lp = vport->fc_rscn_id_list[i]->virt;
4040 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4041 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004042 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004043 rscn_did.un.word = be32_to_cpu(*lp++);
4044 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004045 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4046 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004047 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4048 && (ns_did.un.b.area == rscn_did.un.b.area)
4049 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004050 goto return_did_out;
dea31012005-04-17 16:05:31 -05004051 break;
James Smarteaf15d52008-12-04 22:39:29 -05004052 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004053 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4054 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004055 goto return_did_out;
dea31012005-04-17 16:05:31 -05004056 break;
James Smarteaf15d52008-12-04 22:39:29 -05004057 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004058 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004059 goto return_did_out;
dea31012005-04-17 16:05:31 -05004060 break;
James Smarteaf15d52008-12-04 22:39:29 -05004061 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004062 goto return_did_out;
dea31012005-04-17 16:05:31 -05004063 }
4064 }
James Smart92d7f7b2007-06-17 19:56:38 -05004065 }
James Smart7f5f3d02008-02-08 18:50:14 -05004066 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4067 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004068 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004069return_did_out:
4070 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4071 vport->fc_rscn_flush = 0;
4072 return did;
dea31012005-04-17 16:05:31 -05004073}
4074
James Smarte59058c2008-08-24 21:49:00 -04004075/**
James Smart3621a712009-04-06 18:47:14 -04004076 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004077 * @vport: pointer to a host virtual N_Port data structure.
4078 *
4079 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4080 * state machine for a @vport's nodes that are with pending RSCN (Registration
4081 * State Change Notification).
4082 *
4083 * Return code
4084 * 0 - Successful (currently alway return 0)
4085 **/
dea31012005-04-17 16:05:31 -05004086static int
James Smart2e0fef82007-06-17 19:56:36 -05004087lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004088{
James Smart685f0bf2007-04-25 09:53:08 -04004089 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004090
James Smart0d2b6b82008-06-14 22:52:47 -04004091 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004092 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004093 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004094 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4095 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004096 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004097 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004098 NLP_EVT_DEVICE_RECOVERY);
4099 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004100 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004101 return 0;
dea31012005-04-17 16:05:31 -05004102}
4103
James Smarte59058c2008-08-24 21:49:00 -04004104/**
James Smart3621a712009-04-06 18:47:14 -04004105 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004106 * @vport: pointer to a host virtual N_Port data structure.
4107 * @cmdiocb: pointer to lpfc command iocb data structure.
4108 *
4109 * lpfc_send_rscn_event sends an RSCN netlink event to management
4110 * applications.
4111 */
4112static void
4113lpfc_send_rscn_event(struct lpfc_vport *vport,
4114 struct lpfc_iocbq *cmdiocb)
4115{
4116 struct lpfc_dmabuf *pcmd;
4117 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4118 uint32_t *payload_ptr;
4119 uint32_t payload_len;
4120 struct lpfc_rscn_event_header *rscn_event_data;
4121
4122 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4123 payload_ptr = (uint32_t *) pcmd->virt;
4124 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4125
4126 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4127 payload_len, GFP_KERNEL);
4128 if (!rscn_event_data) {
4129 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4130 "0147 Failed to allocate memory for RSCN event\n");
4131 return;
4132 }
4133 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4134 rscn_event_data->payload_length = payload_len;
4135 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4136 payload_len);
4137
4138 fc_host_post_vendor_event(shost,
4139 fc_get_event_number(),
4140 sizeof(struct lpfc_els_event_header) + payload_len,
4141 (char *)rscn_event_data,
4142 LPFC_NL_VENDOR_ID);
4143
4144 kfree(rscn_event_data);
4145}
4146
4147/**
James Smart3621a712009-04-06 18:47:14 -04004148 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004149 * @vport: pointer to a host virtual N_Port data structure.
4150 * @cmdiocb: pointer to lpfc command iocb data structure.
4151 * @ndlp: pointer to a node-list data structure.
4152 *
4153 * This routine processes an unsolicited RSCN (Registration State Change
4154 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4155 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4156 * discover state machine is about to begin discovery, it just accepts the
4157 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4158 * contains N_Port IDs for other vports on this HBA, it just accepts the
4159 * RSCN and ignore processing it. If the state machine is in the recovery
4160 * state, the fc_rscn_id_list of this @vport is walked and the
4161 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4162 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4163 * routine is invoked to handle the RSCN event.
4164 *
4165 * Return code
4166 * 0 - Just sent the acc response
4167 * 1 - Sent the acc response and waited for name server completion
4168 **/
dea31012005-04-17 16:05:31 -05004169static int
James Smart2e0fef82007-06-17 19:56:36 -05004170lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004171 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004172{
James Smart2e0fef82007-06-17 19:56:36 -05004173 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4174 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004175 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004176 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004177 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004178 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004179 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004180 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004181 int i;
dea31012005-04-17 16:05:31 -05004182
4183 icmd = &cmdiocb->iocb;
4184 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4185 lp = (uint32_t *) pcmd->virt;
4186
James Smart92d7f7b2007-06-17 19:56:38 -05004187 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4188 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004189 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004190 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4191 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004192 vport->fc_flag, payload_len, *lp,
4193 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004194
4195 /* Send an RSCN event to the management application */
4196 lpfc_send_rscn_event(vport, cmdiocb);
4197
James Smartd2873e42006-08-18 17:46:43 -04004198 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004199 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004200 FCH_EVT_RSCN, lp[i]);
4201
dea31012005-04-17 16:05:31 -05004202 /* If we are about to begin discovery, just ACC the RSCN.
4203 * Discovery processing will satisfy it.
4204 */
James Smart2e0fef82007-06-17 19:56:36 -05004205 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004206 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4207 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4208 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4209
James Smart51ef4c22007-08-02 11:10:31 -04004210 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004211 return 0;
dea31012005-04-17 16:05:31 -05004212 }
4213
James Smart92d7f7b2007-06-17 19:56:38 -05004214 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4215 * just ACC and ignore it.
4216 */
4217 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004218 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004219 i = payload_len;
4220 datap = lp;
4221 while (i > 0) {
4222 nportid = *datap++;
4223 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4224 i -= sizeof(uint32_t);
4225 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004226 if (lpfc_find_vport_by_did(phba, nportid))
4227 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004228 }
4229 if (rscn_id == hba_id) {
4230 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004231 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004232 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004233 "Data: x%x x%x x%x x%x\n",
4234 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004235 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4237 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4238 ndlp->nlp_DID, vport->port_state,
4239 ndlp->nlp_flag);
4240
James Smart92d7f7b2007-06-17 19:56:38 -05004241 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004242 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004243 return 0;
4244 }
4245 }
4246
James Smart7f5f3d02008-02-08 18:50:14 -05004247 spin_lock_irq(shost->host_lock);
4248 if (vport->fc_rscn_flush) {
4249 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004250 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004251 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004252 /* Send back ACC */
4253 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004254 return 0;
4255 }
4256 /* Indicate we are walking fc_rscn_id_list on this vport */
4257 vport->fc_rscn_flush = 1;
4258 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004259 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004260 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004261 /* If we are already processing an RSCN, save the received
4262 * RSCN payload buffer, cmdiocb->context2 to process later.
4263 */
James Smart2e0fef82007-06-17 19:56:36 -05004264 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4266 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4267 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4268
James Smart09372822008-01-11 01:52:54 -05004269 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004270 vport->fc_flag |= FC_RSCN_DEFERRED;
4271 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004272 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004273 vport->fc_flag |= FC_RSCN_MODE;
4274 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004275 if (rscn_cnt) {
4276 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4277 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4278 }
4279 if ((rscn_cnt) &&
4280 (payload_len + length <= LPFC_BPL_SIZE)) {
4281 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004282 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004283 memcpy(((uint8_t *)cmd) + length, lp,
4284 payload_len);
4285 } else {
4286 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4287 vport->fc_rscn_id_cnt++;
4288 /* If we zero, cmdiocb->context2, the calling
4289 * routine will not try to free it.
4290 */
4291 cmdiocb->context2 = NULL;
4292 }
dea31012005-04-17 16:05:31 -05004293 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004294 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4295 "0235 Deferred RSCN "
4296 "Data: x%x x%x x%x\n",
4297 vport->fc_rscn_id_cnt, vport->fc_flag,
4298 vport->port_state);
dea31012005-04-17 16:05:31 -05004299 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004300 vport->fc_flag |= FC_RSCN_DISCOVERY;
4301 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004302 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004303 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4304 "0234 ReDiscovery RSCN "
4305 "Data: x%x x%x x%x\n",
4306 vport->fc_rscn_id_cnt, vport->fc_flag,
4307 vport->port_state);
dea31012005-04-17 16:05:31 -05004308 }
James Smart7f5f3d02008-02-08 18:50:14 -05004309 /* Indicate we are done walking fc_rscn_id_list on this vport */
4310 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004311 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004312 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004313 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004314 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004315 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004316 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004317 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004318 return 0;
dea31012005-04-17 16:05:31 -05004319 }
James Smart858c9f62007-06-17 19:56:39 -05004320 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4321 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4322 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4323
James Smart2e0fef82007-06-17 19:56:36 -05004324 spin_lock_irq(shost->host_lock);
4325 vport->fc_flag |= FC_RSCN_MODE;
4326 spin_unlock_irq(shost->host_lock);
4327 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004328 /* Indicate we are done walking fc_rscn_id_list on this vport */
4329 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004330 /*
4331 * If we zero, cmdiocb->context2, the calling routine will
4332 * not try to free it.
4333 */
4334 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004335 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004336 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004337 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004338 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004339 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004340 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004341}
4342
James Smarte59058c2008-08-24 21:49:00 -04004343/**
James Smart3621a712009-04-06 18:47:14 -04004344 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004345 * @vport: pointer to a host virtual N_Port data structure.
4346 *
4347 * This routine handles the Registration State Configuration Notification
4348 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4349 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4350 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4351 * NameServer shall be issued. If CT command to the NameServer fails to be
4352 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4353 * RSCN activities with the @vport.
4354 *
4355 * Return code
4356 * 0 - Cleaned up rscn on the @vport
4357 * 1 - Wait for plogi to name server before proceed
4358 **/
dea31012005-04-17 16:05:31 -05004359int
James Smart2e0fef82007-06-17 19:56:36 -05004360lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004361{
4362 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004363 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004364
James Smart92d7f7b2007-06-17 19:56:38 -05004365 /* Ignore RSCN if the port is being torn down. */
4366 if (vport->load_flag & FC_UNLOADING) {
4367 lpfc_els_flush_rscn(vport);
4368 return 0;
4369 }
4370
dea31012005-04-17 16:05:31 -05004371 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004372 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004373
4374 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004375 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4376 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4377 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4378 vport->port_state);
dea31012005-04-17 16:05:31 -05004379
4380 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004381 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004382 vport->num_disc_nodes = 0;
4383
James Smart2e0fef82007-06-17 19:56:36 -05004384 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004385 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4386 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004387 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004388 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004389 /* Wait for NameServer query cmpl before we can
4390 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004391 return 1;
dea31012005-04-17 16:05:31 -05004392 } else {
4393 /* If login to NameServer does not exist, issue one */
4394 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004395 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004396 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004397 /* Wait for NameServer login cmpl before we can
4398 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004399 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004400
James Smarte47c9092008-02-08 18:49:26 -05004401 if (ndlp) {
4402 ndlp = lpfc_enable_node(vport, ndlp,
4403 NLP_STE_PLOGI_ISSUE);
4404 if (!ndlp) {
4405 lpfc_els_flush_rscn(vport);
4406 return 0;
4407 }
4408 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004409 } else {
James Smarte47c9092008-02-08 18:49:26 -05004410 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4411 if (!ndlp) {
4412 lpfc_els_flush_rscn(vport);
4413 return 0;
4414 }
James Smart2e0fef82007-06-17 19:56:36 -05004415 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004416 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004417 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004418 }
James Smarte47c9092008-02-08 18:49:26 -05004419 ndlp->nlp_type |= NLP_FABRIC;
4420 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4421 /* Wait for NameServer login cmpl before we can
4422 * continue
4423 */
4424 return 1;
dea31012005-04-17 16:05:31 -05004425 }
4426
James Smart2e0fef82007-06-17 19:56:36 -05004427 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004428 return 0;
dea31012005-04-17 16:05:31 -05004429}
4430
James Smarte59058c2008-08-24 21:49:00 -04004431/**
James Smart3621a712009-04-06 18:47:14 -04004432 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004433 * @vport: pointer to a host virtual N_Port data structure.
4434 * @cmdiocb: pointer to lpfc command iocb data structure.
4435 * @ndlp: pointer to a node-list data structure.
4436 *
4437 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4438 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4439 * point topology. As an unsolicited FLOGI should not be received in a loop
4440 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4441 * lpfc_check_sparm() routine is invoked to check the parameters in the
4442 * unsolicited FLOGI. If parameters validation failed, the routine
4443 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4444 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4445 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4446 * will initiate PLOGI. The higher lexicographical value party shall has
4447 * higher priority (as the winning port) and will initiate PLOGI and
4448 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4449 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4450 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4451 *
4452 * Return code
4453 * 0 - Successfully processed the unsolicited flogi
4454 * 1 - Failed to process the unsolicited flogi
4455 **/
dea31012005-04-17 16:05:31 -05004456static int
James Smart2e0fef82007-06-17 19:56:36 -05004457lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004458 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004459{
James Smart2e0fef82007-06-17 19:56:36 -05004460 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4461 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004462 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4463 uint32_t *lp = (uint32_t *) pcmd->virt;
4464 IOCB_t *icmd = &cmdiocb->iocb;
4465 struct serv_parm *sp;
4466 LPFC_MBOXQ_t *mbox;
4467 struct ls_rjt stat;
4468 uint32_t cmd, did;
4469 int rc;
4470
4471 cmd = *lp++;
4472 sp = (struct serv_parm *) lp;
4473
4474 /* FLOGI received */
4475
James Smart2e0fef82007-06-17 19:56:36 -05004476 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004477
4478 if (phba->fc_topology == TOPOLOGY_LOOP) {
4479 /* We should never receive a FLOGI in loop mode, ignore it */
4480 did = icmd->un.elsreq64.remoteID;
4481
4482 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4483 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004484 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4485 "0113 An FLOGI ELS command x%x was "
4486 "received from DID x%x in Loop Mode\n",
4487 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004488 return 1;
dea31012005-04-17 16:05:31 -05004489 }
4490
4491 did = Fabric_DID;
4492
James Smart341af102010-01-26 23:07:37 -05004493 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004494 /* For a FLOGI we accept, then if our portname is greater
4495 * then the remote portname we initiate Nport login.
4496 */
4497
James Smart2e0fef82007-06-17 19:56:36 -05004498 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004499 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004500
4501 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004502 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4503 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004504 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004505
dea31012005-04-17 16:05:31 -05004506 lpfc_linkdown(phba);
4507 lpfc_init_link(phba, mbox,
4508 phba->cfg_topology,
4509 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004510 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004511 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004512 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004513 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004514 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004515 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004516 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004517 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004518 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004519 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004520 spin_lock_irq(shost->host_lock);
4521 vport->fc_flag |= FC_PT2PT_PLOGI;
4522 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004523 }
James Smart2e0fef82007-06-17 19:56:36 -05004524 spin_lock_irq(shost->host_lock);
4525 vport->fc_flag |= FC_PT2PT;
4526 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4527 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004528 } else {
4529 /* Reject this request because invalid parameters */
4530 stat.un.b.lsRjtRsvd0 = 0;
4531 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4532 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4533 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004534 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4535 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004536 return 1;
dea31012005-04-17 16:05:31 -05004537 }
4538
4539 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004540 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004541
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004542 return 0;
dea31012005-04-17 16:05:31 -05004543}
4544
James Smarte59058c2008-08-24 21:49:00 -04004545/**
James Smart3621a712009-04-06 18:47:14 -04004546 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004547 * @vport: pointer to a host virtual N_Port data structure.
4548 * @cmdiocb: pointer to lpfc command iocb data structure.
4549 * @ndlp: pointer to a node-list data structure.
4550 *
4551 * This routine processes Request Node Identification Data (RNID) IOCB
4552 * received as an ELS unsolicited event. Only when the RNID specified format
4553 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4554 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4555 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4556 * rejected by invoking the lpfc_els_rsp_reject() routine.
4557 *
4558 * Return code
4559 * 0 - Successfully processed rnid iocb (currently always return 0)
4560 **/
dea31012005-04-17 16:05:31 -05004561static int
James Smart2e0fef82007-06-17 19:56:36 -05004562lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4563 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004564{
4565 struct lpfc_dmabuf *pcmd;
4566 uint32_t *lp;
4567 IOCB_t *icmd;
4568 RNID *rn;
4569 struct ls_rjt stat;
4570 uint32_t cmd, did;
4571
4572 icmd = &cmdiocb->iocb;
4573 did = icmd->un.elsreq64.remoteID;
4574 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4575 lp = (uint32_t *) pcmd->virt;
4576
4577 cmd = *lp++;
4578 rn = (RNID *) lp;
4579
4580 /* RNID received */
4581
4582 switch (rn->Format) {
4583 case 0:
4584 case RNID_TOPOLOGY_DISC:
4585 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004586 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004587 break;
4588 default:
4589 /* Reject this request because format not supported */
4590 stat.un.b.lsRjtRsvd0 = 0;
4591 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4592 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4593 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004594 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4595 NULL);
dea31012005-04-17 16:05:31 -05004596 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004597 return 0;
dea31012005-04-17 16:05:31 -05004598}
4599
James Smarte59058c2008-08-24 21:49:00 -04004600/**
James Smart3621a712009-04-06 18:47:14 -04004601 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004602 * @vport: pointer to a host virtual N_Port data structure.
4603 * @cmdiocb: pointer to lpfc command iocb data structure.
4604 * @ndlp: pointer to a node-list data structure.
4605 *
4606 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4607 * received as an ELS unsolicited event. Currently, this function just invokes
4608 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4609 *
4610 * Return code
4611 * 0 - Successfully processed lirr iocb (currently always return 0)
4612 **/
dea31012005-04-17 16:05:31 -05004613static int
James Smart2e0fef82007-06-17 19:56:36 -05004614lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4615 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004616{
4617 struct ls_rjt stat;
4618
4619 /* For now, unconditionally reject this command */
4620 stat.un.b.lsRjtRsvd0 = 0;
4621 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4622 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4623 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004624 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004625 return 0;
4626}
4627
James Smarte59058c2008-08-24 21:49:00 -04004628/**
James Smart5ffc2662009-11-18 15:39:44 -05004629 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4630 * @vport: pointer to a host virtual N_Port data structure.
4631 * @cmdiocb: pointer to lpfc command iocb data structure.
4632 * @ndlp: pointer to a node-list data structure.
4633 *
4634 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4635 * received as an ELS unsolicited event. A request to RRQ shall only
4636 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4637 * Nx_Port N_Port_ID of the target Exchange is the same as the
4638 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4639 * not accepted, an LS_RJT with reason code "Unable to perform
4640 * command request" and reason code explanation "Invalid Originator
4641 * S_ID" shall be returned. For now, we just unconditionally accept
4642 * RRQ from the target.
4643 **/
4644static void
4645lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4646 struct lpfc_nodelist *ndlp)
4647{
4648 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4649}
4650
4651/**
James Smart3621a712009-04-06 18:47:14 -04004652 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004653 * @phba: pointer to lpfc hba data structure.
4654 * @pmb: pointer to the driver internal queue element for mailbox command.
4655 *
4656 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4657 * mailbox command. This callback function is to actually send the Accept
4658 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4659 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4660 * mailbox command, constructs the RPS response with the link statistics
4661 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4662 * response to the RPS.
4663 *
4664 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4665 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4666 * will be stored into the context1 field of the IOCB for the completion
4667 * callback function to the RPS Accept Response ELS IOCB command.
4668 *
4669 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004670static void
James Smart329f9bc2007-04-25 09:53:01 -04004671lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004672{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004673 MAILBOX_t *mb;
4674 IOCB_t *icmd;
4675 RPS_RSP *rps_rsp;
4676 uint8_t *pcmd;
4677 struct lpfc_iocbq *elsiocb;
4678 struct lpfc_nodelist *ndlp;
4679 uint16_t xri, status;
4680 uint32_t cmdsize;
4681
James Smart04c68492009-05-22 14:52:52 -04004682 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004683
4684 ndlp = (struct lpfc_nodelist *) pmb->context2;
4685 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004686 pmb->context1 = NULL;
4687 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004688
4689 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004690 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004691 return;
4692 }
4693
4694 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004695 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004696 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4697 lpfc_max_els_tries, ndlp,
4698 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004699
4700 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004701 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004702
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004703 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004704 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004705
4706 icmd = &elsiocb->iocb;
4707 icmd->ulpContext = xri;
4708
4709 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4710 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004711 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004712 rps_rsp = (RPS_RSP *)pcmd;
4713
4714 if (phba->fc_topology != TOPOLOGY_LOOP)
4715 status = 0x10;
4716 else
4717 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004718 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004719 status |= 0x4;
4720
4721 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004722 rps_rsp->portStatus = cpu_to_be16(status);
4723 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4724 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4725 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4726 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4727 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4728 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004729 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004730 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4731 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4732 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4733 elsiocb->iotag, elsiocb->iocb.ulpContext,
4734 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4735 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004736 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004737 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004738 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004739 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004740 return;
4741}
4742
James Smarte59058c2008-08-24 21:49:00 -04004743/**
James Smart3621a712009-04-06 18:47:14 -04004744 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004745 * @vport: pointer to a host virtual N_Port data structure.
4746 * @cmdiocb: pointer to lpfc command iocb data structure.
4747 * @ndlp: pointer to a node-list data structure.
4748 *
4749 * This routine processes Read Port Status (RPS) IOCB received as an
4750 * ELS unsolicited event. It first checks the remote port state. If the
4751 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4752 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4753 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4754 * for reading the HBA link statistics. It is for the callback function,
4755 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4756 * to actually sending out RPS Accept (ACC) response.
4757 *
4758 * Return codes
4759 * 0 - Successfully processed rps iocb (currently always return 0)
4760 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004761static int
James Smart2e0fef82007-06-17 19:56:36 -05004762lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4763 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004764{
James Smart2e0fef82007-06-17 19:56:36 -05004765 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004766 uint32_t *lp;
4767 uint8_t flag;
4768 LPFC_MBOXQ_t *mbox;
4769 struct lpfc_dmabuf *pcmd;
4770 RPS *rps;
4771 struct ls_rjt stat;
4772
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004773 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004774 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4775 /* reject the unsolicited RPS request and done with it */
4776 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004777
4778 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4779 lp = (uint32_t *) pcmd->virt;
4780 flag = (be32_to_cpu(*lp++) & 0xf);
4781 rps = (RPS *) lp;
4782
4783 if ((flag == 0) ||
4784 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004785 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004786 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004787
James Smart92d7f7b2007-06-17 19:56:38 -05004788 printk("Fix me....\n");
4789 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004790 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4791 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004792 lpfc_read_lnk_stat(phba, mbox);
4793 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004794 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004795 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004796 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004797 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004798 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004799 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004800 /* Mbox completion will send ELS Response */
4801 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004802 /* Decrement reference count used for the failed mbox
4803 * command.
4804 */
James Smart329f9bc2007-04-25 09:53:01 -04004805 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004806 mempool_free(mbox, phba->mbox_mem_pool);
4807 }
4808 }
James Smart90160e02008-08-24 21:49:45 -04004809
4810reject_out:
4811 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004812 stat.un.b.lsRjtRsvd0 = 0;
4813 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4814 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4815 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004816 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004817 return 0;
4818}
4819
James Smarte59058c2008-08-24 21:49:00 -04004820/**
James Smart3621a712009-04-06 18:47:14 -04004821 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004822 * @vport: pointer to a host virtual N_Port data structure.
4823 * @cmdsize: size of the ELS command.
4824 * @oldiocb: pointer to the original lpfc command iocb data structure.
4825 * @ndlp: pointer to a node-list data structure.
4826 *
4827 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4828 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4829 *
4830 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4831 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4832 * will be stored into the context1 field of the IOCB for the completion
4833 * callback function to the RPL Accept Response ELS command.
4834 *
4835 * Return code
4836 * 0 - Successfully issued ACC RPL ELS command
4837 * 1 - Failed to issue ACC RPL ELS command
4838 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004839static int
James Smart2e0fef82007-06-17 19:56:36 -05004840lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4841 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004842{
James Smart2e0fef82007-06-17 19:56:36 -05004843 struct lpfc_hba *phba = vport->phba;
4844 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004845 RPL_RSP rpl_rsp;
4846 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004847 uint8_t *pcmd;
4848
James Smart2e0fef82007-06-17 19:56:36 -05004849 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4850 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004851
James Smart488d1462006-03-07 15:02:37 -05004852 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004853 return 1;
James Smart488d1462006-03-07 15:02:37 -05004854
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004855 icmd = &elsiocb->iocb;
4856 oldcmd = &oldiocb->iocb;
4857 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4858
4859 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4860 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004861 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004862 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4863 pcmd += sizeof(uint16_t);
4864
4865 /* Setup the RPL ACC payload */
4866 rpl_rsp.listLen = be32_to_cpu(1);
4867 rpl_rsp.index = 0;
4868 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004869 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4870 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004871 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004872 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004873 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004874 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4875 "0120 Xmit ELS RPL ACC response tag x%x "
4876 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4877 "rpi x%x\n",
4878 elsiocb->iotag, elsiocb->iocb.ulpContext,
4879 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4880 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004881 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004882 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004883 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4884 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004885 lpfc_els_free_iocb(phba, elsiocb);
4886 return 1;
4887 }
4888 return 0;
4889}
4890
James Smarte59058c2008-08-24 21:49:00 -04004891/**
James Smart3621a712009-04-06 18:47:14 -04004892 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004893 * @vport: pointer to a host virtual N_Port data structure.
4894 * @cmdiocb: pointer to lpfc command iocb data structure.
4895 * @ndlp: pointer to a node-list data structure.
4896 *
4897 * This routine processes Read Port List (RPL) IOCB received as an ELS
4898 * unsolicited event. It first checks the remote port state. If the remote
4899 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4900 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4901 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4902 * to accept the RPL.
4903 *
4904 * Return code
4905 * 0 - Successfully processed rpl iocb (currently always return 0)
4906 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004907static int
James Smart2e0fef82007-06-17 19:56:36 -05004908lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4909 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004910{
4911 struct lpfc_dmabuf *pcmd;
4912 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004913 uint32_t maxsize;
4914 uint16_t cmdsize;
4915 RPL *rpl;
4916 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004917
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004918 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4919 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004920 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004921 stat.un.b.lsRjtRsvd0 = 0;
4922 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4923 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4924 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004925 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4926 NULL);
James Smart90160e02008-08-24 21:49:45 -04004927 /* rejected the unsolicited RPL request and done with it */
4928 return 0;
dea31012005-04-17 16:05:31 -05004929 }
4930
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004931 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4932 lp = (uint32_t *) pcmd->virt;
4933 rpl = (RPL *) (lp + 1);
4934
4935 maxsize = be32_to_cpu(rpl->maxsize);
4936
4937 /* We support only one port */
4938 if ((rpl->index == 0) &&
4939 ((maxsize == 0) ||
4940 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4941 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004942 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004943 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4944 }
James Smart2e0fef82007-06-17 19:56:36 -05004945 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004946
4947 return 0;
4948}
4949
James Smarte59058c2008-08-24 21:49:00 -04004950/**
James Smart3621a712009-04-06 18:47:14 -04004951 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004952 * @vport: pointer to a virtual N_Port data structure.
4953 * @cmdiocb: pointer to lpfc command iocb data structure.
4954 * @ndlp: pointer to a node-list data structure.
4955 *
4956 * This routine processes Fibre Channel Address Resolution Protocol
4957 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4958 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4959 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4960 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4961 * remote PortName is compared against the FC PortName stored in the @vport
4962 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4963 * compared against the FC NodeName stored in the @vport data structure.
4964 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4965 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4966 * invoked to send out FARP Response to the remote node. Before sending the
4967 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4968 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4969 * routine is invoked to log into the remote port first.
4970 *
4971 * Return code
4972 * 0 - Either the FARP Match Mode not supported or successfully processed
4973 **/
dea31012005-04-17 16:05:31 -05004974static int
James Smart2e0fef82007-06-17 19:56:36 -05004975lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4976 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004977{
4978 struct lpfc_dmabuf *pcmd;
4979 uint32_t *lp;
4980 IOCB_t *icmd;
4981 FARP *fp;
4982 uint32_t cmd, cnt, did;
4983
4984 icmd = &cmdiocb->iocb;
4985 did = icmd->un.elsreq64.remoteID;
4986 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4987 lp = (uint32_t *) pcmd->virt;
4988
4989 cmd = *lp++;
4990 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004991 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004992 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4993 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004994 /* We will only support match on WWPN or WWNN */
4995 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004996 return 0;
dea31012005-04-17 16:05:31 -05004997 }
4998
4999 cnt = 0;
5000 /* If this FARP command is searching for my portname */
5001 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005002 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005003 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005004 cnt = 1;
5005 }
5006
5007 /* If this FARP command is searching for my nodename */
5008 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005009 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005010 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005011 cnt = 1;
5012 }
5013
5014 if (cnt) {
5015 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5016 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5017 /* Log back into the node before sending the FARP. */
5018 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005019 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005020 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005021 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005022 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005023 }
5024
5025 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005026 if (fp->Rflags & FARP_REQUEST_FARPR)
5027 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005028 }
5029 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005030 return 0;
dea31012005-04-17 16:05:31 -05005031}
5032
James Smarte59058c2008-08-24 21:49:00 -04005033/**
James Smart3621a712009-04-06 18:47:14 -04005034 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005035 * @vport: pointer to a host virtual N_Port data structure.
5036 * @cmdiocb: pointer to lpfc command iocb data structure.
5037 * @ndlp: pointer to a node-list data structure.
5038 *
5039 * This routine processes Fibre Channel Address Resolution Protocol
5040 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5041 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5042 * the FARP response request.
5043 *
5044 * Return code
5045 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5046 **/
dea31012005-04-17 16:05:31 -05005047static int
James Smart2e0fef82007-06-17 19:56:36 -05005048lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5049 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005050{
5051 struct lpfc_dmabuf *pcmd;
5052 uint32_t *lp;
5053 IOCB_t *icmd;
5054 uint32_t cmd, did;
5055
5056 icmd = &cmdiocb->iocb;
5057 did = icmd->un.elsreq64.remoteID;
5058 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5059 lp = (uint32_t *) pcmd->virt;
5060
5061 cmd = *lp++;
5062 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5064 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005065 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005066 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005067
5068 return 0;
5069}
5070
James Smarte59058c2008-08-24 21:49:00 -04005071/**
James Smart3621a712009-04-06 18:47:14 -04005072 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005073 * @vport: pointer to a host virtual N_Port data structure.
5074 * @cmdiocb: pointer to lpfc command iocb data structure.
5075 * @fan_ndlp: pointer to a node-list data structure.
5076 *
5077 * This routine processes a Fabric Address Notification (FAN) IOCB
5078 * command received as an ELS unsolicited event. The FAN ELS command will
5079 * only be processed on a physical port (i.e., the @vport represents the
5080 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5081 * compared against those in the phba data structure. If any of those is
5082 * different, the lpfc_initial_flogi() routine is invoked to initialize
5083 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5084 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5085 * is invoked to register login to the fabric.
5086 *
5087 * Return code
5088 * 0 - Successfully processed fan iocb (currently always return 0).
5089 **/
dea31012005-04-17 16:05:31 -05005090static int
James Smart2e0fef82007-06-17 19:56:36 -05005091lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5092 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005093{
James Smart2e0fef82007-06-17 19:56:36 -05005094 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005095 uint32_t *lp;
5096 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005097
James Smart0d2b6b82008-06-14 22:52:47 -04005098 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5099 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5100 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005101 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005102 if ((vport == phba->pport) &&
5103 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005104 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005105 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005106 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005107 sizeof(struct lpfc_name)))) {
5108 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005109 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005110 } else {
5111 /* FAN verified - skip FLOGI */
5112 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005113 if (phba->sli_rev < LPFC_SLI_REV4)
5114 lpfc_issue_fabric_reglogin(vport);
5115 else
5116 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005117 }
dea31012005-04-17 16:05:31 -05005118 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005119 return 0;
dea31012005-04-17 16:05:31 -05005120}
5121
James Smarte59058c2008-08-24 21:49:00 -04005122/**
James Smart3621a712009-04-06 18:47:14 -04005123 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005124 * @ptr: holder for the timer function associated data.
5125 *
5126 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5127 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5128 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5129 * up the worker thread. It is for the worker thread to invoke the routine
5130 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5131 **/
dea31012005-04-17 16:05:31 -05005132void
5133lpfc_els_timeout(unsigned long ptr)
5134{
James Smart2e0fef82007-06-17 19:56:36 -05005135 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5136 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005137 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005138 unsigned long iflag;
5139
James Smart2e0fef82007-06-17 19:56:36 -05005140 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005141 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5142 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005143 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005144 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005145
James Smart5e9d9b82008-06-14 22:52:53 -04005146 if (!tmo_posted)
5147 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005148 return;
5149}
5150
James Smart2a9bf3d2010-06-07 15:24:45 -04005151
James Smarte59058c2008-08-24 21:49:00 -04005152/**
James Smart3621a712009-04-06 18:47:14 -04005153 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005154 * @vport: pointer to a virtual N_Port data structure.
5155 *
5156 * This routine is the actual handler function that processes an ELS timeout
5157 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5158 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5159 * invoking the lpfc_sli_issue_abort_iotag() routine.
5160 **/
dea31012005-04-17 16:05:31 -05005161void
James Smart2e0fef82007-06-17 19:56:36 -05005162lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005163{
James Smart2e0fef82007-06-17 19:56:36 -05005164 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005165 struct lpfc_sli_ring *pring;
5166 struct lpfc_iocbq *tmp_iocb, *piocb;
5167 IOCB_t *cmd = NULL;
5168 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005169 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005170 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005171 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005172 LIST_HEAD(txcmplq_completions);
5173 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005174
James Smart2a9bf3d2010-06-07 15:24:45 -04005175
dea31012005-04-17 16:05:31 -05005176 timeout = (uint32_t)(phba->fc_ratov << 1);
5177
5178 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005179
James Smart2a9bf3d2010-06-07 15:24:45 -04005180 spin_lock_irq(&phba->hbalock);
5181 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5182 spin_unlock_irq(&phba->hbalock);
5183
5184 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005185 cmd = &piocb->iocb;
5186
James Smart2e0fef82007-06-17 19:56:36 -05005187 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5188 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5189 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005190 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005191
5192 if (piocb->vport != vport)
5193 continue;
5194
dea31012005-04-17 16:05:31 -05005195 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005196 if (pcmd)
5197 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005198
James Smart92d7f7b2007-06-17 19:56:38 -05005199 if (els_command == ELS_CMD_FARP ||
5200 els_command == ELS_CMD_FARPR ||
5201 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005202 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005203
dea31012005-04-17 16:05:31 -05005204 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005205 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005206 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005207 else
dea31012005-04-17 16:05:31 -05005208 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005209 continue;
5210 }
5211
James Smart2e0fef82007-06-17 19:56:36 -05005212 remote_ID = 0xffffffff;
5213 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005214 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005215 else {
5216 struct lpfc_nodelist *ndlp;
5217 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005218 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005219 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005220 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005221 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005222 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005223 spin_lock_irq(&phba->hbalock);
5224 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005225 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005226
James Smart2a9bf3d2010-06-07 15:24:45 -04005227 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5228 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5229 "0127 ELS timeout Data: x%x x%x x%x "
5230 "x%x\n", els_command,
5231 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5232 spin_lock_irq(&phba->hbalock);
5233 list_del_init(&piocb->dlist);
5234 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5235 spin_unlock_irq(&phba->hbalock);
5236 }
5237
James Smart2e0fef82007-06-17 19:56:36 -05005238 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5239 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005240}
5241
James Smarte59058c2008-08-24 21:49:00 -04005242/**
James Smart3621a712009-04-06 18:47:14 -04005243 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005244 * @vport: pointer to a host virtual N_Port data structure.
5245 *
5246 * This routine is used to clean up all the outstanding ELS commands on a
5247 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5248 * routine. After that, it walks the ELS transmit queue to remove all the
5249 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5250 * the IOCBs with a non-NULL completion callback function, the callback
5251 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5252 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5253 * callback function, the IOCB will simply be released. Finally, it walks
5254 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5255 * completion queue IOCB that is associated with the @vport and is not
5256 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5257 * part of the discovery state machine) out to HBA by invoking the
5258 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5259 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5260 * the IOCBs are aborted when this function returns.
5261 **/
dea31012005-04-17 16:05:31 -05005262void
James Smart2e0fef82007-06-17 19:56:36 -05005263lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005264{
James Smart2534ba72007-04-25 09:52:20 -04005265 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005266 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005267 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005268 struct lpfc_iocbq *tmp_iocb, *piocb;
5269 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005270
5271 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005272
James Smart2e0fef82007-06-17 19:56:36 -05005273 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005274 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5275 cmd = &piocb->iocb;
5276
5277 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5278 continue;
5279 }
5280
5281 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005282 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5283 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5284 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5285 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005286 continue;
dea31012005-04-17 16:05:31 -05005287
James Smart2e0fef82007-06-17 19:56:36 -05005288 if (piocb->vport != vport)
5289 continue;
5290
James Smart2534ba72007-04-25 09:52:20 -04005291 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005292 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005293 }
5294
5295 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005296 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5297 continue;
5298 }
dea31012005-04-17 16:05:31 -05005299
James Smart2e0fef82007-06-17 19:56:36 -05005300 if (piocb->vport != vport)
5301 continue;
5302
James Smart07951072007-04-25 09:51:38 -04005303 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005304 }
James Smart2e0fef82007-06-17 19:56:36 -05005305 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005306
James Smarta257bf92009-04-06 18:48:10 -04005307 /* Cancell all the IOCBs from the completions list */
5308 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5309 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005310
dea31012005-04-17 16:05:31 -05005311 return;
5312}
5313
James Smarte59058c2008-08-24 21:49:00 -04005314/**
James Smart3621a712009-04-06 18:47:14 -04005315 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005316 * @phba: pointer to lpfc hba data structure.
5317 *
5318 * This routine is used to clean up all the outstanding ELS commands on a
5319 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5320 * routine. After that, it walks the ELS transmit queue to remove all the
5321 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5322 * the IOCBs with the completion callback function associated, the callback
5323 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5324 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5325 * callback function associated, the IOCB will simply be released. Finally,
5326 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5327 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5328 * management plane IOCBs that are not part of the discovery state machine)
5329 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5330 **/
James Smart549e55c2007-08-02 11:09:51 -04005331void
5332lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5333{
5334 LIST_HEAD(completions);
5335 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5336 struct lpfc_iocbq *tmp_iocb, *piocb;
5337 IOCB_t *cmd = NULL;
5338
5339 lpfc_fabric_abort_hba(phba);
5340 spin_lock_irq(&phba->hbalock);
5341 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5342 cmd = &piocb->iocb;
5343 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5344 continue;
5345 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5346 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5347 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5348 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5349 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5350 continue;
5351 list_move_tail(&piocb->list, &completions);
5352 pring->txq_cnt--;
5353 }
5354 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5355 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5356 continue;
5357 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5358 }
5359 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005360
5361 /* Cancel all the IOCBs from the completions list */
5362 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5363 IOERR_SLI_ABORTED);
5364
James Smart549e55c2007-08-02 11:09:51 -04005365 return;
5366}
5367
James Smarte59058c2008-08-24 21:49:00 -04005368/**
James Smart3621a712009-04-06 18:47:14 -04005369 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005370 * @phba: Pointer to hba context object.
5371 * @cmdiocbp: Pointer to command iocb which reported error.
5372 * @rspiocbp: Pointer to response iocb which reported error.
5373 *
5374 * This function sends an event when there is an ELS command
5375 * failure.
5376 **/
5377void
5378lpfc_send_els_failure_event(struct lpfc_hba *phba,
5379 struct lpfc_iocbq *cmdiocbp,
5380 struct lpfc_iocbq *rspiocbp)
5381{
5382 struct lpfc_vport *vport = cmdiocbp->vport;
5383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5384 struct lpfc_lsrjt_event lsrjt_event;
5385 struct lpfc_fabric_event_header fabric_event;
5386 struct ls_rjt stat;
5387 struct lpfc_nodelist *ndlp;
5388 uint32_t *pcmd;
5389
5390 ndlp = cmdiocbp->context1;
5391 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5392 return;
5393
5394 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5395 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5396 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5397 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5398 sizeof(struct lpfc_name));
5399 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5400 sizeof(struct lpfc_name));
5401 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5402 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005403 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005404 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5405 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5406 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5407 fc_host_post_vendor_event(shost,
5408 fc_get_event_number(),
5409 sizeof(lsrjt_event),
5410 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005411 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005412 return;
5413 }
5414 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5415 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5416 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5417 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5418 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5419 else
5420 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5421 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5422 sizeof(struct lpfc_name));
5423 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5424 sizeof(struct lpfc_name));
5425 fc_host_post_vendor_event(shost,
5426 fc_get_event_number(),
5427 sizeof(fabric_event),
5428 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005429 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005430 return;
5431 }
5432
5433}
5434
5435/**
James Smart3621a712009-04-06 18:47:14 -04005436 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005437 * @vport: Pointer to vport object.
5438 * @ndlp: Pointer FC node object.
5439 * @cmd: ELS command code.
5440 *
5441 * This function posts an event when there is an incoming
5442 * unsolicited ELS command.
5443 **/
5444static void
5445lpfc_send_els_event(struct lpfc_vport *vport,
5446 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005447 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005448{
James Smartddcc50f2008-12-04 22:38:46 -05005449 struct lpfc_els_event_header *els_data = NULL;
5450 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005451 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5452
James Smartddcc50f2008-12-04 22:38:46 -05005453 if (*payload == ELS_CMD_LOGO) {
5454 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5455 if (!logo_data) {
5456 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5457 "0148 Failed to allocate memory "
5458 "for LOGO event\n");
5459 return;
5460 }
5461 els_data = &logo_data->header;
5462 } else {
5463 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5464 GFP_KERNEL);
5465 if (!els_data) {
5466 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5467 "0149 Failed to allocate memory "
5468 "for ELS event\n");
5469 return;
5470 }
5471 }
5472 els_data->event_type = FC_REG_ELS_EVENT;
5473 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005474 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005475 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005476 break;
5477 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005478 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005479 break;
5480 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005481 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5482 break;
5483 case ELS_CMD_LOGO:
5484 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5485 /* Copy the WWPN in the LOGO payload */
5486 memcpy(logo_data->logo_wwpn, &payload[2],
5487 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005488 break;
5489 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005490 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005491 return;
5492 }
James Smartddcc50f2008-12-04 22:38:46 -05005493 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5494 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5495 if (*payload == ELS_CMD_LOGO) {
5496 fc_host_post_vendor_event(shost,
5497 fc_get_event_number(),
5498 sizeof(struct lpfc_logo_event),
5499 (char *)logo_data,
5500 LPFC_NL_VENDOR_ID);
5501 kfree(logo_data);
5502 } else {
5503 fc_host_post_vendor_event(shost,
5504 fc_get_event_number(),
5505 sizeof(struct lpfc_els_event_header),
5506 (char *)els_data,
5507 LPFC_NL_VENDOR_ID);
5508 kfree(els_data);
5509 }
James Smartea2151b2008-09-07 11:52:10 -04005510
5511 return;
5512}
5513
5514
5515/**
James Smart3621a712009-04-06 18:47:14 -04005516 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005517 * @phba: pointer to lpfc hba data structure.
5518 * @pring: pointer to a SLI ring.
5519 * @vport: pointer to a host virtual N_Port data structure.
5520 * @elsiocb: pointer to lpfc els command iocb data structure.
5521 *
5522 * This routine is used for processing the IOCB associated with a unsolicited
5523 * event. It first determines whether there is an existing ndlp that matches
5524 * the DID from the unsolicited IOCB. If not, it will create a new one with
5525 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5526 * IOCB is then used to invoke the proper routine and to set up proper state
5527 * of the discovery state machine.
5528 **/
James Smarted957682007-06-17 19:56:37 -05005529static void
5530lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005531 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005532{
James Smart87af33f2007-10-27 13:37:43 -04005533 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005534 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005535 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005536 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005537 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005538 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005539
James Smarte47c9092008-02-08 18:49:26 -05005540 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005541 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005542
dea31012005-04-17 16:05:31 -05005543 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005544 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5545 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005546 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005547 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005548
James Smart858c9f62007-06-17 19:56:39 -05005549 did = icmd->un.rcvels.remoteID;
5550 if (icmd->ulpStatus) {
5551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5552 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5553 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005554 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005555 }
dea31012005-04-17 16:05:31 -05005556
5557 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005558 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005559 goto dropit;
dea31012005-04-17 16:05:31 -05005560
James Smartc8685952009-11-18 15:39:16 -05005561 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005562 if (vport->load_flag & FC_UNLOADING)
5563 goto dropit;
5564
James Smart2e0fef82007-06-17 19:56:36 -05005565 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005566 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005567 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005568 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005569 if (!ndlp)
dea31012005-04-17 16:05:31 -05005570 goto dropit;
dea31012005-04-17 16:05:31 -05005571
James Smart2e0fef82007-06-17 19:56:36 -05005572 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005573 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005574 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005575 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005576 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005577 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5578 ndlp = lpfc_enable_node(vport, ndlp,
5579 NLP_STE_UNUSED_NODE);
5580 if (!ndlp)
5581 goto dropit;
5582 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5583 newnode = 1;
5584 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5585 ndlp->nlp_type |= NLP_FABRIC;
5586 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5587 /* This is similar to the new node path */
5588 ndlp = lpfc_nlp_get(ndlp);
5589 if (!ndlp)
5590 goto dropit;
5591 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5592 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005593 }
dea31012005-04-17 16:05:31 -05005594
5595 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005596
James Smart329f9bc2007-04-25 09:53:01 -04005597 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005598 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005599
5600 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5601 cmd &= ELS_CMD_MASK;
5602 }
5603 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005604 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5605 "0112 ELS command x%x received from NPORT x%x "
5606 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005607 switch (cmd) {
5608 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005609 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5610 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5611 did, vport->port_state, ndlp->nlp_flag);
5612
dea31012005-04-17 16:05:31 -05005613 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005614 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5615
James Smartddcc50f2008-12-04 22:38:46 -05005616 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005617 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005618 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5619 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5620 rjt_err = LSRJT_UNABLE_TPC;
5621 break;
5622 }
5623 /* We get here, and drop thru, if we are PT2PT with
5624 * another NPort and the other side has initiated
5625 * the PLOGI before responding to our FLOGI.
5626 */
dea31012005-04-17 16:05:31 -05005627 }
James Smart87af33f2007-10-27 13:37:43 -04005628
5629 shost = lpfc_shost_from_vport(vport);
5630 spin_lock_irq(shost->host_lock);
5631 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5632 spin_unlock_irq(shost->host_lock);
5633
James Smart2e0fef82007-06-17 19:56:36 -05005634 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5635 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005636
dea31012005-04-17 16:05:31 -05005637 break;
5638 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5640 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5641 did, vport->port_state, ndlp->nlp_flag);
5642
dea31012005-04-17 16:05:31 -05005643 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005644 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005645 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005646 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005647 break;
5648 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005649 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5650 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5651 did, vport->port_state, ndlp->nlp_flag);
5652
dea31012005-04-17 16:05:31 -05005653 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005654 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005655 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005656 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005657 break;
5658 }
James Smart2e0fef82007-06-17 19:56:36 -05005659 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005660 break;
5661 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5663 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5664 did, vport->port_state, ndlp->nlp_flag);
5665
dea31012005-04-17 16:05:31 -05005666 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005667 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005668 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005669 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005670 break;
5671 }
James Smart2e0fef82007-06-17 19:56:36 -05005672 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005673 break;
5674 case ELS_CMD_RSCN:
5675 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005676 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005677 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005678 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005679 break;
5680 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5682 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5683 did, vport->port_state, ndlp->nlp_flag);
5684
James Smartddcc50f2008-12-04 22:38:46 -05005685 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005686 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005687 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005688 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005689 break;
5690 }
James Smart2e0fef82007-06-17 19:56:36 -05005691 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5692 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005693 break;
5694 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005695 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5696 "RCV PDISC: 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.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005700 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005701 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005702 break;
5703 }
James Smart2e0fef82007-06-17 19:56:36 -05005704 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5705 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005706 break;
5707 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005708 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5709 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5710 did, vport->port_state, ndlp->nlp_flag);
5711
dea31012005-04-17 16:05:31 -05005712 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005713 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005714 break;
5715 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005716 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5717 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5718 did, vport->port_state, ndlp->nlp_flag);
5719
dea31012005-04-17 16:05:31 -05005720 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005721 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005722 break;
5723 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005724 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5725 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5726 did, vport->port_state, ndlp->nlp_flag);
5727
dea31012005-04-17 16:05:31 -05005728 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005729 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005730 break;
dea31012005-04-17 16:05:31 -05005731 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005732 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5733 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5734 did, vport->port_state, ndlp->nlp_flag);
5735
dea31012005-04-17 16:05:31 -05005736 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005737 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005738 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005739 break;
5740 }
James Smart2e0fef82007-06-17 19:56:36 -05005741 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005742 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005743 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5745 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5746 did, vport->port_state, ndlp->nlp_flag);
5747
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005748 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005749 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005750 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005751 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005752 break;
5753 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005754 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5755 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5756 did, vport->port_state, ndlp->nlp_flag);
5757
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005758 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005759 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005760 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005761 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005762 break;
5763 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5765 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5766 did, vport->port_state, ndlp->nlp_flag);
5767
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005768 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005769 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005770 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005771 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005772 break;
dea31012005-04-17 16:05:31 -05005773 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5775 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5776 did, vport->port_state, ndlp->nlp_flag);
5777
dea31012005-04-17 16:05:31 -05005778 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005779 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005780 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005781 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005782 break;
James Smart5ffc2662009-11-18 15:39:44 -05005783 case ELS_CMD_RRQ:
5784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5785 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5786 did, vport->port_state, ndlp->nlp_flag);
5787
5788 phba->fc_stat.elsRcvRRQ++;
5789 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5790 if (newnode)
5791 lpfc_nlp_put(ndlp);
5792 break;
dea31012005-04-17 16:05:31 -05005793 default:
James Smart858c9f62007-06-17 19:56:39 -05005794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5795 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5796 cmd, did, vport->port_state);
5797
dea31012005-04-17 16:05:31 -05005798 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005799 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005800
5801 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005802 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5803 "0115 Unknown ELS command x%x "
5804 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005805 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005806 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005807 break;
5808 }
5809
5810 /* check if need to LS_RJT received ELS cmd */
5811 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005812 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005813 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005814 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005815 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5816 NULL);
dea31012005-04-17 16:05:31 -05005817 }
5818
James Smartd7c255b2008-08-24 21:50:00 -04005819 lpfc_nlp_put(elsiocb->context1);
5820 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005821 return;
5822
5823dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005824 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005825 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5826 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005827 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005828 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005829 phba->fc_stat.elsRcvDrop++;
5830}
5831
James Smarte59058c2008-08-24 21:49:00 -04005832/**
James Smart3621a712009-04-06 18:47:14 -04005833 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005834 * @phba: pointer to lpfc hba data structure.
5835 * @vpi: host virtual N_Port identifier.
5836 *
5837 * This routine finds a vport on a HBA (referred by @phba) through a
5838 * @vpi. The function walks the HBA's vport list and returns the address
5839 * of the vport with the matching @vpi.
5840 *
5841 * Return code
5842 * NULL - No vport with the matching @vpi found
5843 * Otherwise - Address to the vport with the matching @vpi.
5844 **/
James Smart6669f9b2009-10-02 15:16:45 -04005845struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005846lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5847{
5848 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005849 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005850
James Smart549e55c2007-08-02 11:09:51 -04005851 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005852 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005853 if (vport->vpi == vpi) {
5854 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005855 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005856 }
James Smart92d7f7b2007-06-17 19:56:38 -05005857 }
James Smart549e55c2007-08-02 11:09:51 -04005858 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005859 return NULL;
5860}
James Smarted957682007-06-17 19:56:37 -05005861
James Smarte59058c2008-08-24 21:49:00 -04005862/**
James Smart3621a712009-04-06 18:47:14 -04005863 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005864 * @phba: pointer to lpfc hba data structure.
5865 * @pring: pointer to a SLI ring.
5866 * @elsiocb: pointer to lpfc els iocb data structure.
5867 *
5868 * This routine is used to process an unsolicited event received from a SLI
5869 * (Service Level Interface) ring. The actual processing of the data buffer
5870 * associated with the unsolicited event is done by invoking the routine
5871 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5872 * SLI ring on which the unsolicited event was received.
5873 **/
James Smarted957682007-06-17 19:56:37 -05005874void
5875lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5876 struct lpfc_iocbq *elsiocb)
5877{
5878 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005879 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005880 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005881 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5882 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005883
James Smartd7c255b2008-08-24 21:50:00 -04005884 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005885 elsiocb->context2 = NULL;
5886 elsiocb->context3 = NULL;
5887
5888 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5889 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5890 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5891 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005892 phba->fc_stat.NoRcvBuf++;
5893 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005894 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005895 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005896 return;
5897 }
5898
James Smart92d7f7b2007-06-17 19:56:38 -05005899 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5900 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5901 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5902 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5903 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005904 else
5905 vport = lpfc_find_vport_by_vpid(phba,
5906 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005907 }
James Smart7f5f3d02008-02-08 18:50:14 -05005908 /* If there are no BDEs associated
5909 * with this IOCB, there is nothing to do.
5910 */
James Smarted957682007-06-17 19:56:37 -05005911 if (icmd->ulpBdeCount == 0)
5912 return;
5913
James Smart7f5f3d02008-02-08 18:50:14 -05005914 /* type of ELS cmd is first 32bit word
5915 * in packet
5916 */
James Smarted957682007-06-17 19:56:37 -05005917 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005918 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005919 } else {
5920 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5921 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005922 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5923 paddr);
James Smarted957682007-06-17 19:56:37 -05005924 }
5925
James Smart92d7f7b2007-06-17 19:56:38 -05005926 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5927 /*
5928 * The different unsolicited event handlers would tell us
5929 * if they are done with "mp" by setting context2 to NULL.
5930 */
dea31012005-04-17 16:05:31 -05005931 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005932 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5933 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005934 }
James Smarted957682007-06-17 19:56:37 -05005935
5936 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005937 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005938 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005939 elsiocb->context2 = bdeBuf2;
5940 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005941 /* free mp if we are done with it */
5942 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005943 lpfc_in_buf_free(phba, elsiocb->context2);
5944 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005945 }
dea31012005-04-17 16:05:31 -05005946 }
dea31012005-04-17 16:05:31 -05005947}
James Smart92d7f7b2007-06-17 19:56:38 -05005948
James Smarte59058c2008-08-24 21:49:00 -04005949/**
James Smart3621a712009-04-06 18:47:14 -04005950 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005951 * @phba: pointer to lpfc hba data structure.
5952 * @vport: pointer to a virtual N_Port data structure.
5953 *
5954 * This routine issues a Port Login (PLOGI) to the Name Server with
5955 * State Change Request (SCR) for a @vport. This routine will create an
5956 * ndlp for the Name Server associated to the @vport if such node does
5957 * not already exist. The PLOGI to Name Server is issued by invoking the
5958 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5959 * (FDMI) is configured to the @vport, a FDMI node will be created and
5960 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5961 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005962void
5963lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5964{
5965 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5966
5967 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5968 if (!ndlp) {
5969 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5970 if (!ndlp) {
5971 if (phba->fc_topology == TOPOLOGY_LOOP) {
5972 lpfc_disc_start(vport);
5973 return;
5974 }
5975 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005976 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5977 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005978 return;
5979 }
5980 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005981 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5982 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5983 if (!ndlp) {
5984 if (phba->fc_topology == TOPOLOGY_LOOP) {
5985 lpfc_disc_start(vport);
5986 return;
5987 }
5988 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5989 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5990 "0348 NameServer login: node freed\n");
5991 return;
5992 }
James Smart92d7f7b2007-06-17 19:56:38 -05005993 }
James Smart58da1ff2008-04-07 10:15:56 -04005994 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005995
5996 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5997
5998 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5999 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006000 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6001 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006002 return;
6003 }
6004
James Smart3de2a652007-08-02 11:09:59 -04006005 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006006 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6007 GFP_KERNEL);
6008 if (ndlp_fdmi) {
6009 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6010 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006011 lpfc_nlp_set_state(vport, ndlp_fdmi,
6012 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006013 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6014 0);
6015 }
6016 }
6017 return;
6018}
6019
James Smarte59058c2008-08-24 21:49:00 -04006020/**
James Smart3621a712009-04-06 18:47:14 -04006021 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006022 * @phba: pointer to lpfc hba data structure.
6023 * @pmb: pointer to the driver internal queue element for mailbox command.
6024 *
6025 * This routine is the completion callback function to register new vport
6026 * mailbox command. If the new vport mailbox command completes successfully,
6027 * the fabric registration login shall be performed on physical port (the
6028 * new vport created is actually a physical port, with VPI 0) or the port
6029 * login to Name Server for State Change Request (SCR) will be performed
6030 * on virtual port (real virtual port, with VPI greater than 0).
6031 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006032static void
6033lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6034{
6035 struct lpfc_vport *vport = pmb->vport;
6036 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6037 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006038 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006039 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006040
James Smart09372822008-01-11 01:52:54 -05006041 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006042 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006043 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006044
6045 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006046 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6047 "0915 Register VPI failed: 0x%x\n",
6048 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05006049
6050 switch (mb->mbxStatus) {
6051 case 0x11: /* unsupported feature */
6052 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006053 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006054 /* giving up on vport registration */
6055 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6056 spin_lock_irq(shost->host_lock);
6057 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6058 spin_unlock_irq(shost->host_lock);
6059 lpfc_can_disctmo(vport);
6060 break;
James Smart695a8142010-01-26 23:08:03 -05006061 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6062 case 0x20:
6063 spin_lock_irq(shost->host_lock);
6064 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6065 spin_unlock_irq(shost->host_lock);
6066 lpfc_init_vpi(phba, pmb, vport->vpi);
6067 pmb->vport = vport;
6068 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6069 rc = lpfc_sli_issue_mbox(phba, pmb,
6070 MBX_NOWAIT);
6071 if (rc == MBX_NOT_FINISHED) {
6072 lpfc_printf_vlog(vport,
6073 KERN_ERR, LOG_MBOX,
6074 "2732 Failed to issue INIT_VPI"
6075 " mailbox command\n");
6076 } else {
6077 lpfc_nlp_put(ndlp);
6078 return;
6079 }
6080
James Smart92d7f7b2007-06-17 19:56:38 -05006081 default:
6082 /* Try to recover from this error */
6083 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006084 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006085 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006086 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006087 if (vport->port_type == LPFC_PHYSICAL_PORT
6088 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006089 lpfc_initial_flogi(vport);
6090 else
6091 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006092 break;
6093 }
James Smart92d7f7b2007-06-17 19:56:38 -05006094 } else {
James Smart695a8142010-01-26 23:08:03 -05006095 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006096 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006097 spin_unlock_irq(shost->host_lock);
6098 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006099 if (phba->sli_rev < LPFC_SLI_REV4)
6100 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006101 else {
James Smartfc2b9892010-02-26 14:15:29 -05006102 /*
6103 * If the physical port is instantiated using
6104 * FDISC, do not start vport discovery.
6105 */
6106 if (vport->port_state != LPFC_FDISC)
6107 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006108 lpfc_do_scr_ns_plogi(phba, vport);
6109 }
6110 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006111 lpfc_do_scr_ns_plogi(phba, vport);
6112 }
James Smartfa4066b2008-01-11 01:53:27 -05006113
6114 /* Now, we decrement the ndlp reference count held for this
6115 * callback function
6116 */
6117 lpfc_nlp_put(ndlp);
6118
James Smart92d7f7b2007-06-17 19:56:38 -05006119 mempool_free(pmb, phba->mbox_mem_pool);
6120 return;
6121}
6122
James Smarte59058c2008-08-24 21:49:00 -04006123/**
James Smart3621a712009-04-06 18:47:14 -04006124 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006125 * @phba: pointer to lpfc hba data structure.
6126 * @vport: pointer to a host virtual N_Port data structure.
6127 * @ndlp: pointer to a node-list data structure.
6128 *
6129 * This routine registers the @vport as a new virtual port with a HBA.
6130 * It is done through a registering vpi mailbox command.
6131 **/
James Smart695a8142010-01-26 23:08:03 -05006132void
James Smart92d7f7b2007-06-17 19:56:38 -05006133lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6134 struct lpfc_nodelist *ndlp)
6135{
James Smart09372822008-01-11 01:52:54 -05006136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006137 LPFC_MBOXQ_t *mbox;
6138
6139 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6140 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006141 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006142 mbox->vport = vport;
6143 mbox->context2 = lpfc_nlp_get(ndlp);
6144 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006145 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006146 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006147 /* mailbox command not success, decrement ndlp
6148 * reference count for this command
6149 */
6150 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006151 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006152
James Smarte8b62012007-08-02 11:10:09 -04006153 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6154 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006155 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006156 }
6157 } else {
James Smarte8b62012007-08-02 11:10:09 -04006158 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6159 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006160 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006161 }
James Smartfa4066b2008-01-11 01:53:27 -05006162 return;
6163
6164mbox_err_exit:
6165 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6166 spin_lock_irq(shost->host_lock);
6167 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6168 spin_unlock_irq(shost->host_lock);
6169 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006170}
6171
James Smarte59058c2008-08-24 21:49:00 -04006172/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006173 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006174 * @phba: pointer to lpfc hba data structure.
6175 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006176 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006177 **/
6178void
James Smart0c9ab6f2010-02-26 14:15:57 -05006179lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006180{
6181 struct lpfc_vport **vports;
6182 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006183 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006184 int i;
James Smart695a8142010-01-26 23:08:03 -05006185
6186 /* Treat this failure as linkdown for all vports */
6187 link_state = phba->link_state;
6188 lpfc_linkdown(phba);
6189 phba->link_state = link_state;
6190
6191 vports = lpfc_create_vport_work_array(phba);
6192
6193 if (vports) {
6194 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6195 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6196 if (ndlp)
6197 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6198 lpfc_els_flush_cmd(vports[i]);
6199 }
6200 lpfc_destroy_vport_work_array(phba, vports);
6201 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006202}
6203
6204/**
6205 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6206 * @phba: pointer to lpfc hba data structure.
6207 *
6208 * This routine abort all pending discovery commands and
6209 * start a timer to retry FLOGI for the physical port
6210 * discovery.
6211 **/
6212void
6213lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6214{
6215 struct lpfc_nodelist *ndlp;
6216 struct Scsi_Host *shost;
6217
6218 /* Cancel the all vports retry delay retry timers */
6219 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006220
6221 /* If fabric require FLOGI, then re-instantiate physical login */
6222 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6223 if (!ndlp)
6224 return;
6225
James Smart695a8142010-01-26 23:08:03 -05006226 shost = lpfc_shost_from_vport(phba->pport);
6227 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6228 spin_lock_irq(shost->host_lock);
6229 ndlp->nlp_flag |= NLP_DELAY_TMO;
6230 spin_unlock_irq(shost->host_lock);
6231 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6232 phba->pport->port_state = LPFC_FLOGI;
6233 return;
6234}
6235
6236/**
6237 * lpfc_fabric_login_reqd - Check if FLOGI required.
6238 * @phba: pointer to lpfc hba data structure.
6239 * @cmdiocb: pointer to FDISC command iocb.
6240 * @rspiocb: pointer to FDISC response iocb.
6241 *
6242 * This routine checks if a FLOGI is reguired for FDISC
6243 * to succeed.
6244 **/
6245static int
6246lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6247 struct lpfc_iocbq *cmdiocb,
6248 struct lpfc_iocbq *rspiocb)
6249{
6250
6251 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6252 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6253 return 0;
6254 else
6255 return 1;
6256}
6257
6258/**
James Smart3621a712009-04-06 18:47:14 -04006259 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006260 * @phba: pointer to lpfc hba data structure.
6261 * @cmdiocb: pointer to lpfc command iocb data structure.
6262 * @rspiocb: pointer to lpfc response iocb data structure.
6263 *
6264 * This routine is the completion callback function to a Fabric Discover
6265 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6266 * single threaded, each FDISC completion callback function will reset
6267 * the discovery timer for all vports such that the timers will not get
6268 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6269 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6270 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6271 * assigned to the vport has been changed with the completion of the FDISC
6272 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6273 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6274 * routine is invoked to register new vport with the HBA. Otherwise, the
6275 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6276 * Server for State Change Request (SCR).
6277 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006278static void
6279lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6280 struct lpfc_iocbq *rspiocb)
6281{
6282 struct lpfc_vport *vport = cmdiocb->vport;
6283 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6284 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6285 struct lpfc_nodelist *np;
6286 struct lpfc_nodelist *next_np;
6287 IOCB_t *irsp = &rspiocb->iocb;
6288 struct lpfc_iocbq *piocb;
6289
James Smarte8b62012007-08-02 11:10:09 -04006290 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6291 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6292 irsp->ulpStatus, irsp->un.ulpWord[4],
6293 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006294 /* Since all FDISCs are being single threaded, we
6295 * must reset the discovery timer for ALL vports
6296 * waiting to send FDISC when one completes.
6297 */
6298 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6299 lpfc_set_disctmo(piocb->vport);
6300 }
6301
James Smart858c9f62007-06-17 19:56:39 -05006302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6303 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6304 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6305
James Smart92d7f7b2007-06-17 19:56:38 -05006306 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006307
6308 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6309 lpfc_retry_pport_discovery(phba);
6310 goto out;
6311 }
6312
James Smart92d7f7b2007-06-17 19:56:38 -05006313 /* Check for retry */
6314 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6315 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006316 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006317 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006318 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006319 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006320 goto fdisc_failed;
6321 }
James Smartd7c255b2008-08-24 21:50:00 -04006322 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006323 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006324 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006325 vport->fc_flag |= FC_FABRIC;
6326 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6327 vport->fc_flag |= FC_PUBLIC_LOOP;
6328 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006329
James Smartd7c255b2008-08-24 21:50:00 -04006330 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6331 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6332 if ((vport->fc_prevDID != vport->fc_myDID) &&
6333 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6334 /* If our NportID changed, we need to ensure all
6335 * remaining NPORTs get unreg_login'ed so we can
6336 * issue unreg_vpi.
6337 */
6338 list_for_each_entry_safe(np, next_np,
6339 &vport->fc_nodes, nlp_listp) {
6340 if (!NLP_CHK_NODE_ACT(ndlp) ||
6341 (np->nlp_state != NLP_STE_NPR_NODE) ||
6342 !(np->nlp_flag & NLP_NPR_ADISC))
6343 continue;
James Smart09372822008-01-11 01:52:54 -05006344 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006345 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006346 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006347 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006348 }
James Smart78730cf2010-04-06 15:06:30 -04006349 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006350 lpfc_mbx_unreg_vpi(vport);
6351 spin_lock_irq(shost->host_lock);
6352 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006353 if (phba->sli_rev == LPFC_SLI_REV4)
6354 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006355 else
6356 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006357 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006358 }
6359
James Smartecfd03c2010-02-12 14:41:27 -05006360 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6361 lpfc_issue_init_vpi(vport);
6362 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006363 lpfc_register_new_vport(phba, vport, ndlp);
6364 else
6365 lpfc_do_scr_ns_plogi(phba, vport);
6366 goto out;
6367fdisc_failed:
6368 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6369 /* Cancel discovery timer */
6370 lpfc_can_disctmo(vport);
6371 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006372out:
6373 lpfc_els_free_iocb(phba, cmdiocb);
6374}
6375
James Smarte59058c2008-08-24 21:49:00 -04006376/**
James Smart3621a712009-04-06 18:47:14 -04006377 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006378 * @vport: pointer to a virtual N_Port data structure.
6379 * @ndlp: pointer to a node-list data structure.
6380 * @retry: number of retries to the command IOCB.
6381 *
6382 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6383 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6384 * routine to issue the IOCB, which makes sure only one outstanding fabric
6385 * IOCB will be sent off HBA at any given time.
6386 *
6387 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6388 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6389 * will be stored into the context1 field of the IOCB for the completion
6390 * callback function to the FDISC ELS command.
6391 *
6392 * Return code
6393 * 0 - Successfully issued fdisc iocb command
6394 * 1 - Failed to issue fdisc iocb command
6395 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006396static int
James Smart92d7f7b2007-06-17 19:56:38 -05006397lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6398 uint8_t retry)
6399{
6400 struct lpfc_hba *phba = vport->phba;
6401 IOCB_t *icmd;
6402 struct lpfc_iocbq *elsiocb;
6403 struct serv_parm *sp;
6404 uint8_t *pcmd;
6405 uint16_t cmdsize;
6406 int did = ndlp->nlp_DID;
6407 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006408
James Smart5ffc2662009-11-18 15:39:44 -05006409 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006410 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6411 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6412 ELS_CMD_FDISC);
6413 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006414 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006415 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6416 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006417 return 1;
6418 }
6419
6420 icmd = &elsiocb->iocb;
6421 icmd->un.elsreq64.myID = 0;
6422 icmd->un.elsreq64.fl = 1;
6423
James Smartf1126682009-06-10 17:22:44 -04006424 if (phba->sli_rev == LPFC_SLI_REV4) {
6425 /* FDISC needs to be 1 for WQE VPI */
6426 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6427 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6428 /* Set the ulpContext to the vpi */
6429 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6430 } else {
6431 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6432 icmd->ulpCt_h = 1;
6433 icmd->ulpCt_l = 0;
6434 }
James Smart92d7f7b2007-06-17 19:56:38 -05006435
6436 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6437 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6438 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6439 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6440 sp = (struct serv_parm *) pcmd;
6441 /* Setup CSPs accordingly for Fabric */
6442 sp->cmn.e_d_tov = 0;
6443 sp->cmn.w2.r_a_tov = 0;
6444 sp->cls1.classValid = 0;
6445 sp->cls2.seqDelivery = 1;
6446 sp->cls3.seqDelivery = 1;
6447
6448 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6449 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6450 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6451 pcmd += sizeof(uint32_t); /* Port Name */
6452 memcpy(pcmd, &vport->fc_portname, 8);
6453 pcmd += sizeof(uint32_t); /* Node Name */
6454 pcmd += sizeof(uint32_t); /* Node Name */
6455 memcpy(pcmd, &vport->fc_nodename, 8);
6456
6457 lpfc_set_disctmo(vport);
6458
6459 phba->fc_stat.elsXmitFDISC++;
6460 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6461
James Smart858c9f62007-06-17 19:56:39 -05006462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6463 "Issue FDISC: did:x%x",
6464 did, 0, 0);
6465
James Smart92d7f7b2007-06-17 19:56:38 -05006466 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6467 if (rc == IOCB_ERROR) {
6468 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006469 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006470 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6471 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006472 return 1;
6473 }
6474 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006475 return 0;
6476}
6477
James Smarte59058c2008-08-24 21:49:00 -04006478/**
James Smart3621a712009-04-06 18:47:14 -04006479 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006480 * @phba: pointer to lpfc hba data structure.
6481 * @cmdiocb: pointer to lpfc command iocb data structure.
6482 * @rspiocb: pointer to lpfc response iocb data structure.
6483 *
6484 * This routine is the completion callback function to the issuing of a LOGO
6485 * ELS command off a vport. It frees the command IOCB and then decrement the
6486 * reference count held on ndlp for this completion function, indicating that
6487 * the reference to the ndlp is no long needed. Note that the
6488 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6489 * callback function and an additional explicit ndlp reference decrementation
6490 * will trigger the actual release of the ndlp.
6491 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006492static void
6493lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6494 struct lpfc_iocbq *rspiocb)
6495{
6496 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006497 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006498 struct lpfc_nodelist *ndlp;
6499 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006500
6501 irsp = &rspiocb->iocb;
6502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6503 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6504 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006505
6506 lpfc_els_free_iocb(phba, cmdiocb);
6507 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006508
6509 /* Trigger the release of the ndlp after logo */
6510 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006511}
6512
James Smarte59058c2008-08-24 21:49:00 -04006513/**
James Smart3621a712009-04-06 18:47:14 -04006514 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006515 * @vport: pointer to a virtual N_Port data structure.
6516 * @ndlp: pointer to a node-list data structure.
6517 *
6518 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6519 *
6520 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6521 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6522 * will be stored into the context1 field of the IOCB for the completion
6523 * callback function to the LOGO ELS command.
6524 *
6525 * Return codes
6526 * 0 - Successfully issued logo off the @vport
6527 * 1 - Failed to issue logo off the @vport
6528 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006529int
6530lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6531{
6532 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6533 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006534 IOCB_t *icmd;
6535 struct lpfc_iocbq *elsiocb;
6536 uint8_t *pcmd;
6537 uint16_t cmdsize;
6538
6539 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6540 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6541 ELS_CMD_LOGO);
6542 if (!elsiocb)
6543 return 1;
6544
6545 icmd = &elsiocb->iocb;
6546 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6547 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6548 pcmd += sizeof(uint32_t);
6549
6550 /* Fill in LOGO payload */
6551 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6552 pcmd += sizeof(uint32_t);
6553 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6554
James Smart858c9f62007-06-17 19:56:39 -05006555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6556 "Issue LOGO npiv did:x%x flg:x%x",
6557 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6558
James Smart92d7f7b2007-06-17 19:56:38 -05006559 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6560 spin_lock_irq(shost->host_lock);
6561 ndlp->nlp_flag |= NLP_LOGO_SND;
6562 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006563 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6564 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006565 spin_lock_irq(shost->host_lock);
6566 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6567 spin_unlock_irq(shost->host_lock);
6568 lpfc_els_free_iocb(phba, elsiocb);
6569 return 1;
6570 }
6571 return 0;
6572}
6573
James Smarte59058c2008-08-24 21:49:00 -04006574/**
James Smart3621a712009-04-06 18:47:14 -04006575 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006576 * @ptr: holder for the timer function associated data.
6577 *
6578 * This routine is invoked by the fabric iocb block timer after
6579 * timeout. It posts the fabric iocb block timeout event by setting the
6580 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6581 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6582 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6583 * posted event WORKER_FABRIC_BLOCK_TMO.
6584 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006585void
6586lpfc_fabric_block_timeout(unsigned long ptr)
6587{
6588 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6589 unsigned long iflags;
6590 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006591
James Smart92d7f7b2007-06-17 19:56:38 -05006592 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6593 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6594 if (!tmo_posted)
6595 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6596 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6597
James Smart5e9d9b82008-06-14 22:52:53 -04006598 if (!tmo_posted)
6599 lpfc_worker_wake_up(phba);
6600 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006601}
6602
James Smarte59058c2008-08-24 21:49:00 -04006603/**
James Smart3621a712009-04-06 18:47:14 -04006604 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006605 * @phba: pointer to lpfc hba data structure.
6606 *
6607 * This routine issues one fabric iocb from the driver internal list to
6608 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6609 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6610 * remove one pending fabric iocb from the driver internal list and invokes
6611 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6612 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006613static void
6614lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6615{
6616 struct lpfc_iocbq *iocb;
6617 unsigned long iflags;
6618 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006619 IOCB_t *cmd;
6620
6621repeat:
6622 iocb = NULL;
6623 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006624 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006625 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6626 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6627 list);
6628 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006629 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006630 atomic_inc(&phba->fabric_iocb_count);
6631 }
6632 spin_unlock_irqrestore(&phba->hbalock, iflags);
6633 if (iocb) {
6634 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6635 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6636 iocb->iocb_flag |= LPFC_IO_FABRIC;
6637
James Smart858c9f62007-06-17 19:56:39 -05006638 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6639 "Fabric sched1: ste:x%x",
6640 iocb->vport->port_state, 0, 0);
6641
James Smart3772a992009-05-22 14:50:54 -04006642 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006643
6644 if (ret == IOCB_ERROR) {
6645 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6646 iocb->fabric_iocb_cmpl = NULL;
6647 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6648 cmd = &iocb->iocb;
6649 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6650 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6651 iocb->iocb_cmpl(phba, iocb, iocb);
6652
6653 atomic_dec(&phba->fabric_iocb_count);
6654 goto repeat;
6655 }
6656 }
6657
6658 return;
6659}
6660
James Smarte59058c2008-08-24 21:49:00 -04006661/**
James Smart3621a712009-04-06 18:47:14 -04006662 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006663 * @phba: pointer to lpfc hba data structure.
6664 *
6665 * This routine unblocks the issuing fabric iocb command. The function
6666 * will clear the fabric iocb block bit and then invoke the routine
6667 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6668 * from the driver internal fabric iocb list.
6669 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006670void
6671lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6672{
6673 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6674
6675 lpfc_resume_fabric_iocbs(phba);
6676 return;
6677}
6678
James Smarte59058c2008-08-24 21:49:00 -04006679/**
James Smart3621a712009-04-06 18:47:14 -04006680 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006681 * @phba: pointer to lpfc hba data structure.
6682 *
6683 * This routine blocks the issuing fabric iocb for a specified amount of
6684 * time (currently 100 ms). This is done by set the fabric iocb block bit
6685 * and set up a timeout timer for 100ms. When the block bit is set, no more
6686 * fabric iocb will be issued out of the HBA.
6687 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006688static void
6689lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6690{
6691 int blocked;
6692
6693 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006694 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006695 if (!blocked)
6696 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6697
6698 return;
6699}
6700
James Smarte59058c2008-08-24 21:49:00 -04006701/**
James Smart3621a712009-04-06 18:47:14 -04006702 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006703 * @phba: pointer to lpfc hba data structure.
6704 * @cmdiocb: pointer to lpfc command iocb data structure.
6705 * @rspiocb: pointer to lpfc response iocb data structure.
6706 *
6707 * This routine is the callback function that is put to the fabric iocb's
6708 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6709 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6710 * function first restores and invokes the original iocb's callback function
6711 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6712 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6713 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006714static void
6715lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6716 struct lpfc_iocbq *rspiocb)
6717{
6718 struct ls_rjt stat;
6719
6720 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6721 BUG();
6722
6723 switch (rspiocb->iocb.ulpStatus) {
6724 case IOSTAT_NPORT_RJT:
6725 case IOSTAT_FABRIC_RJT:
6726 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6727 lpfc_block_fabric_iocbs(phba);
6728 }
6729 break;
6730
6731 case IOSTAT_NPORT_BSY:
6732 case IOSTAT_FABRIC_BSY:
6733 lpfc_block_fabric_iocbs(phba);
6734 break;
6735
6736 case IOSTAT_LS_RJT:
6737 stat.un.lsRjtError =
6738 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6739 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6740 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6741 lpfc_block_fabric_iocbs(phba);
6742 break;
6743 }
6744
6745 if (atomic_read(&phba->fabric_iocb_count) == 0)
6746 BUG();
6747
6748 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6749 cmdiocb->fabric_iocb_cmpl = NULL;
6750 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6751 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6752
6753 atomic_dec(&phba->fabric_iocb_count);
6754 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006755 /* Post any pending iocbs to HBA */
6756 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006757 }
6758}
6759
James Smarte59058c2008-08-24 21:49:00 -04006760/**
James Smart3621a712009-04-06 18:47:14 -04006761 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006762 * @phba: pointer to lpfc hba data structure.
6763 * @iocb: pointer to lpfc command iocb data structure.
6764 *
6765 * This routine is used as the top-level API for issuing a fabric iocb command
6766 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6767 * function makes sure that only one fabric bound iocb will be outstanding at
6768 * any given time. As such, this function will first check to see whether there
6769 * is already an outstanding fabric iocb on the wire. If so, it will put the
6770 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6771 * issued later. Otherwise, it will issue the iocb on the wire and update the
6772 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6773 *
6774 * Note, this implementation has a potential sending out fabric IOCBs out of
6775 * order. The problem is caused by the construction of the "ready" boolen does
6776 * not include the condition that the internal fabric IOCB list is empty. As
6777 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6778 * ahead of the fabric IOCBs in the internal list.
6779 *
6780 * Return code
6781 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6782 * IOCB_ERROR - failed to issue fabric iocb
6783 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006784static int
James Smart92d7f7b2007-06-17 19:56:38 -05006785lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6786{
6787 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006788 int ready;
6789 int ret;
6790
6791 if (atomic_read(&phba->fabric_iocb_count) > 1)
6792 BUG();
6793
6794 spin_lock_irqsave(&phba->hbalock, iflags);
6795 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6796 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6797
James Smart7f5f3d02008-02-08 18:50:14 -05006798 if (ready)
6799 /* Increment fabric iocb count to hold the position */
6800 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006801 spin_unlock_irqrestore(&phba->hbalock, iflags);
6802 if (ready) {
6803 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6804 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6805 iocb->iocb_flag |= LPFC_IO_FABRIC;
6806
James Smart858c9f62007-06-17 19:56:39 -05006807 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6808 "Fabric sched2: ste:x%x",
6809 iocb->vport->port_state, 0, 0);
6810
James Smart3772a992009-05-22 14:50:54 -04006811 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006812
6813 if (ret == IOCB_ERROR) {
6814 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6815 iocb->fabric_iocb_cmpl = NULL;
6816 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6817 atomic_dec(&phba->fabric_iocb_count);
6818 }
6819 } else {
6820 spin_lock_irqsave(&phba->hbalock, iflags);
6821 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6822 spin_unlock_irqrestore(&phba->hbalock, iflags);
6823 ret = IOCB_SUCCESS;
6824 }
6825 return ret;
6826}
6827
James Smarte59058c2008-08-24 21:49:00 -04006828/**
James Smart3621a712009-04-06 18:47:14 -04006829 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006830 * @vport: pointer to a virtual N_Port data structure.
6831 *
6832 * This routine aborts all the IOCBs associated with a @vport from the
6833 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6834 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6835 * list, removes each IOCB associated with the @vport off the list, set the
6836 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6837 * associated with the IOCB.
6838 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006839static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006840{
6841 LIST_HEAD(completions);
6842 struct lpfc_hba *phba = vport->phba;
6843 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006844
6845 spin_lock_irq(&phba->hbalock);
6846 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6847 list) {
6848
6849 if (piocb->vport != vport)
6850 continue;
6851
6852 list_move_tail(&piocb->list, &completions);
6853 }
6854 spin_unlock_irq(&phba->hbalock);
6855
James Smarta257bf92009-04-06 18:48:10 -04006856 /* Cancel all the IOCBs from the completions list */
6857 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6858 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006859}
6860
James Smarte59058c2008-08-24 21:49:00 -04006861/**
James Smart3621a712009-04-06 18:47:14 -04006862 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006863 * @ndlp: pointer to a node-list data structure.
6864 *
6865 * This routine aborts all the IOCBs associated with an @ndlp from the
6866 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6867 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6868 * list, removes each IOCB associated with the @ndlp off the list, set the
6869 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6870 * associated with the IOCB.
6871 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006872void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6873{
6874 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006875 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006876 struct lpfc_iocbq *tmp_iocb, *piocb;
6877 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006878
6879 spin_lock_irq(&phba->hbalock);
6880 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6881 list) {
6882 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6883
6884 list_move_tail(&piocb->list, &completions);
6885 }
6886 }
6887 spin_unlock_irq(&phba->hbalock);
6888
James Smarta257bf92009-04-06 18:48:10 -04006889 /* Cancel all the IOCBs from the completions list */
6890 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6891 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006892}
6893
James Smarte59058c2008-08-24 21:49:00 -04006894/**
James Smart3621a712009-04-06 18:47:14 -04006895 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006896 * @phba: pointer to lpfc hba data structure.
6897 *
6898 * This routine aborts all the IOCBs currently on the driver internal
6899 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6900 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6901 * list, removes IOCBs off the list, set the status feild to
6902 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6903 * the IOCB.
6904 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006905void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6906{
6907 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006908
6909 spin_lock_irq(&phba->hbalock);
6910 list_splice_init(&phba->fabric_iocb_list, &completions);
6911 spin_unlock_irq(&phba->hbalock);
6912
James Smarta257bf92009-04-06 18:48:10 -04006913 /* Cancel all the IOCBs from the completions list */
6914 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6915 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006916}
James Smart6fb120a2009-05-22 14:52:59 -04006917
6918/**
6919 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6920 * @phba: pointer to lpfc hba data structure.
6921 * @axri: pointer to the els xri abort wcqe structure.
6922 *
6923 * This routine is invoked by the worker thread to process a SLI4 slow-path
6924 * ELS aborted xri.
6925 **/
6926void
6927lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6928 struct sli4_wcqe_xri_aborted *axri)
6929{
6930 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6931 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6932 unsigned long iflag = 0;
6933
James Smart0f65ff62010-02-26 14:14:23 -05006934 spin_lock_irqsave(&phba->hbalock, iflag);
6935 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006936 list_for_each_entry_safe(sglq_entry, sglq_next,
6937 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6938 if (sglq_entry->sli4_xritag == xri) {
6939 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006940 list_add_tail(&sglq_entry->list,
6941 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05006942 sglq_entry->state = SGL_FREED;
6943 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006944 spin_unlock_irqrestore(&phba->hbalock, iflag);
6945 return;
6946 }
6947 }
James Smart0f65ff62010-02-26 14:14:23 -05006948 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6949 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6950 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6951 spin_unlock_irqrestore(&phba->hbalock, iflag);
6952 return;
6953 }
6954 sglq_entry->state = SGL_XRI_ABORTED;
6955 spin_unlock_irqrestore(&phba->hbalock, iflag);
6956 return;
James Smart6fb120a2009-05-22 14:52:59 -04006957}