blob: 5fbdb22c1899a82be318ff127b28d93ffa1f8285 [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 }
587 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
588 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500589 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500590 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500591 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500592 }
James Smartecfd03c2010-02-12 14:41:27 -0500593 /*
594 * If VPI is unreged, driver need to do INIT_VPI
595 * before re-registering
596 */
597 if (phba->sli_rev == LPFC_SLI_REV4) {
598 spin_lock_irq(shost->host_lock);
599 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
600 spin_unlock_irq(shost->host_lock);
601 }
James Smart92d7f7b2007-06-17 19:56:38 -0500602 }
603
James Smart6fb120a2009-05-22 14:52:59 -0400604 if (phba->sli_rev < LPFC_SLI_REV4) {
605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
606 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
607 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
608 lpfc_register_new_vport(phba, vport, ndlp);
609 else
610 lpfc_issue_fabric_reglogin(vport);
611 } else {
612 ndlp->nlp_type |= NLP_FABRIC;
613 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500614 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
615 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400616 lpfc_start_fdiscs(phba);
617 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500618 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500619 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500620 else
James Smart6fb120a2009-05-22 14:52:59 -0400621 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500622 }
dea31012005-04-17 16:05:31 -0500623 return 0;
dea31012005-04-17 16:05:31 -0500624}
James Smarte59058c2008-08-24 21:49:00 -0400625/**
James Smart3621a712009-04-06 18:47:14 -0400626 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400627 * @vport: pointer to a host virtual N_Port data structure.
628 * @ndlp: pointer to a node-list data structure.
629 * @sp: pointer to service parameter data structure.
630 *
631 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
632 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
633 * in a point-to-point topology. First, the @vport's N_Port Name is compared
634 * with the received N_Port Name: if the @vport's N_Port Name is greater than
635 * the received N_Port Name lexicographically, this node shall assign local
636 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
637 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
638 * this node shall just wait for the remote node to issue PLOGI and assign
639 * N_Port IDs.
640 *
641 * Return code
642 * 0 - Success
643 * -ENXIO - Fail
644 **/
dea31012005-04-17 16:05:31 -0500645static int
James Smart2e0fef82007-06-17 19:56:36 -0500646lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
647 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500648{
James Smart2e0fef82007-06-17 19:56:36 -0500649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
650 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500651 LPFC_MBOXQ_t *mbox;
652 int rc;
653
James Smart2e0fef82007-06-17 19:56:36 -0500654 spin_lock_irq(shost->host_lock);
655 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
656 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500657
658 phba->fc_edtov = FF_DEF_EDTOV;
659 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500660 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500661 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500662 if (rc >= 0) {
663 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_PT2PT_PLOGI;
666 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500667
668 /*
669 * N_Port ID cannot be 0, set our to LocalID the other
670 * side will be RemoteID.
671 */
672
673 /* not equal */
674 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500675 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500676
677 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
678 if (!mbox)
679 goto fail;
680
681 lpfc_config_link(phba, mbox);
682
683 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500684 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400685 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500686 if (rc == MBX_NOT_FINISHED) {
687 mempool_free(mbox, phba->mbox_mem_pool);
688 goto fail;
689 }
James Smarte47c9092008-02-08 18:49:26 -0500690 /* Decrement ndlp reference count indicating that ndlp can be
691 * safely released when other references to it are done.
692 */
James Smart329f9bc2007-04-25 09:53:01 -0400693 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500694
James Smart2e0fef82007-06-17 19:56:36 -0500695 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500696 if (!ndlp) {
697 /*
698 * Cannot find existing Fabric ndlp, so allocate a
699 * new one
700 */
701 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
702 if (!ndlp)
703 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500704 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500705 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
706 ndlp = lpfc_enable_node(vport, ndlp,
707 NLP_STE_UNUSED_NODE);
708 if(!ndlp)
709 goto fail;
dea31012005-04-17 16:05:31 -0500710 }
711
712 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500713 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500714 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500715 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500716 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500717 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
718 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500719 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500720 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500721 } else
722 /* This side will wait for the PLOGI, decrement ndlp reference
723 * count indicating that ndlp can be released when other
724 * references to it are done.
725 */
James Smart329f9bc2007-04-25 09:53:01 -0400726 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500727
James Smart09372822008-01-11 01:52:54 -0500728 /* If we are pt2pt with another NPort, force NPIV off! */
729 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
730
James Smart2e0fef82007-06-17 19:56:36 -0500731 spin_lock_irq(shost->host_lock);
732 vport->fc_flag |= FC_PT2PT;
733 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500734
735 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500736 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500737 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500738fail:
dea31012005-04-17 16:05:31 -0500739 return -ENXIO;
740}
741
James Smarte59058c2008-08-24 21:49:00 -0400742/**
James Smart3621a712009-04-06 18:47:14 -0400743 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400744 * @phba: pointer to lpfc hba data structure.
745 * @cmdiocb: pointer to lpfc command iocb data structure.
746 * @rspiocb: pointer to lpfc response iocb data structure.
747 *
748 * This routine is the top-level completion callback function for issuing
749 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
750 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
751 * retry has been made (either immediately or delayed with lpfc_els_retry()
752 * returning 1), the command IOCB will be released and function returned.
753 * If the retry attempt has been given up (possibly reach the maximum
754 * number of retries), one additional decrement of ndlp reference shall be
755 * invoked before going out after releasing the command IOCB. This will
756 * actually release the remote node (Note, lpfc_els_free_iocb() will also
757 * invoke one decrement of ndlp reference count). If no error reported in
758 * the IOCB status, the command Port ID field is used to determine whether
759 * this is a point-to-point topology or a fabric topology: if the Port ID
760 * field is assigned, it is a fabric topology; otherwise, it is a
761 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
762 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
763 * specific topology completion conditions.
764 **/
dea31012005-04-17 16:05:31 -0500765static void
James Smart329f9bc2007-04-25 09:53:01 -0400766lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
767 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500768{
James Smart2e0fef82007-06-17 19:56:36 -0500769 struct lpfc_vport *vport = cmdiocb->vport;
770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500771 IOCB_t *irsp = &rspiocb->iocb;
772 struct lpfc_nodelist *ndlp = cmdiocb->context1;
773 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
774 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500775 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500776 int rc;
777
778 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500779 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500780 /* One additional decrement on node reference count to
781 * trigger the release of the node
782 */
James Smart329f9bc2007-04-25 09:53:01 -0400783 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500784 goto out;
785 }
786
James Smart858c9f62007-06-17 19:56:39 -0500787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
788 "FLOGI cmpl: status:x%x/x%x state:x%x",
789 irsp->ulpStatus, irsp->un.ulpWord[4],
790 vport->port_state);
791
dea31012005-04-17 16:05:31 -0500792 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500793 /*
794 * In case of FIP mode, perform round robin FCF failover
795 * due to new FCF discovery
796 */
797 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
798 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
799 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
800 "2611 FLOGI failed on registered "
801 "FCF record fcf_index:%d, trying "
802 "to perform round robin failover\n",
803 phba->fcf.current_rec.fcf_indx);
804 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
805 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
806 /*
807 * Exhausted the eligible FCF record list,
808 * fail through to retry FLOGI on current
809 * FCF record.
810 */
811 lpfc_printf_log(phba, KERN_WARNING,
812 LOG_FIP | LOG_ELS,
813 "2760 FLOGI exhausted FCF "
814 "round robin failover list, "
815 "retry FLOGI on the current "
816 "registered FCF index:%d\n",
817 phba->fcf.current_rec.fcf_indx);
818 spin_lock_irq(&phba->hbalock);
819 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
820 spin_unlock_irq(&phba->hbalock);
821 } else {
822 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
823 fcf_index);
824 if (rc) {
825 lpfc_printf_log(phba, KERN_WARNING,
826 LOG_FIP | LOG_ELS,
827 "2761 FLOGI round "
828 "robin FCF failover "
829 "read FCF failed "
830 "rc:x%x, fcf_index:"
831 "%d\n", rc,
832 phba->fcf.current_rec.fcf_indx);
833 spin_lock_irq(&phba->hbalock);
834 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
835 spin_unlock_irq(&phba->hbalock);
836 } else
837 goto out;
838 }
839 }
840
dea31012005-04-17 16:05:31 -0500841 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500842 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500843 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500844
dea31012005-04-17 16:05:31 -0500845 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500846 spin_lock_irq(shost->host_lock);
847 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
848 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500849
James Smart329f9bc2007-04-25 09:53:01 -0400850 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500851 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
852 * alpa map would take too long otherwise.
853 */
854 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400855 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500856 }
857
858 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500859 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
860 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400861 irsp->ulpStatus, irsp->un.ulpWord[4],
862 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500863 goto flogifail;
864 }
James Smart695a8142010-01-26 23:08:03 -0500865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
867 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500868
869 /*
870 * The FLogI succeeded. Sync the data for the CPU before
871 * accessing it.
872 */
873 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
874
875 sp = prsp->virt + sizeof(uint32_t);
876
877 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200879 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400880 "Data: x%x x%x x%x x%x\n",
881 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
882 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500883
James Smart2e0fef82007-06-17 19:56:36 -0500884 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500885 /*
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
888 */
889 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500890 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500891 else
James Smart2e0fef82007-06-17 19:56:36 -0500892 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500893
James Smart0c9ab6f2010-02-26 14:15:57 -0500894 if (!rc) {
895 /* Mark the FCF discovery process done */
896 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | LOG_ELS,
897 "2769 FLOGI successful on FCF record: "
898 "current_fcf_index:x%x, terminate FCF "
899 "round robin failover process\n",
900 phba->fcf.current_rec.fcf_indx);
901 spin_lock_irq(&phba->hbalock);
902 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
903 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500904 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500905 }
dea31012005-04-17 16:05:31 -0500906 }
907
908flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400909 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500910
James Smart858c9f62007-06-17 19:56:39 -0500911 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500912 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500913 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500914
915 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500916 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400917 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
918 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
919 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
920 (phba->link_state != LPFC_CLEAR_LA)) {
921 /* If FLOGI failed enable link interrupt. */
922 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500923 }
dea31012005-04-17 16:05:31 -0500924out:
925 lpfc_els_free_iocb(phba, cmdiocb);
926}
927
James Smarte59058c2008-08-24 21:49:00 -0400928/**
James Smart3621a712009-04-06 18:47:14 -0400929 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400930 * @vport: pointer to a host virtual N_Port data structure.
931 * @ndlp: pointer to a node-list data structure.
932 * @retry: number of retries to the command IOCB.
933 *
934 * This routine issues a Fabric Login (FLOGI) Request ELS command
935 * for a @vport. The initiator service parameters are put into the payload
936 * of the FLOGI Request IOCB and the top-level callback function pointer
937 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
938 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
939 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
940 *
941 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
942 * will be incremented by 1 for holding the ndlp and the reference to ndlp
943 * will be stored into the context1 field of the IOCB for the completion
944 * callback function to the FLOGI ELS command.
945 *
946 * Return code
947 * 0 - successfully issued flogi iocb for @vport
948 * 1 - failed to issue flogi iocb for @vport
949 **/
dea31012005-04-17 16:05:31 -0500950static int
James Smart2e0fef82007-06-17 19:56:36 -0500951lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500952 uint8_t retry)
953{
James Smart2e0fef82007-06-17 19:56:36 -0500954 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500955 struct serv_parm *sp;
956 IOCB_t *icmd;
957 struct lpfc_iocbq *elsiocb;
958 struct lpfc_sli_ring *pring;
959 uint8_t *pcmd;
960 uint16_t cmdsize;
961 uint32_t tmo;
962 int rc;
963
964 pring = &phba->sli.ring[LPFC_ELS_RING];
965
James Smart92d7f7b2007-06-17 19:56:38 -0500966 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500967 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
968 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500969
James Smart488d1462006-03-07 15:02:37 -0500970 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500971 return 1;
dea31012005-04-17 16:05:31 -0500972
973 icmd = &elsiocb->iocb;
974 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
975
976 /* For FLOGI request, remainder of payload is service parameters */
977 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500978 pcmd += sizeof(uint32_t);
979 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500980 sp = (struct serv_parm *) pcmd;
981
982 /* Setup CSPs accordingly for Fabric */
983 sp->cmn.e_d_tov = 0;
984 sp->cmn.w2.r_a_tov = 0;
985 sp->cls1.classValid = 0;
986 sp->cls2.seqDelivery = 1;
987 sp->cls3.seqDelivery = 1;
988 if (sp->cmn.fcphLow < FC_PH3)
989 sp->cmn.fcphLow = FC_PH3;
990 if (sp->cmn.fcphHigh < FC_PH3)
991 sp->cmn.fcphHigh = FC_PH3;
992
James Smart6fb120a2009-05-22 14:52:59 -0400993 if (phba->sli_rev == LPFC_SLI_REV4) {
994 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
995 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
996 /* FLOGI needs to be 3 for WQE FCFI */
997 /* Set the fcfi to the fcfi we registered with */
998 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
999 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001000 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001001 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1002 icmd->ulpCt_h = 1;
1003 icmd->ulpCt_l = 0;
1004 }
1005
James Smart858c9f62007-06-17 19:56:39 -05001006 if (phba->fc_topology != TOPOLOGY_LOOP) {
1007 icmd->un.elsreq64.myID = 0;
1008 icmd->un.elsreq64.fl = 1;
1009 }
1010
dea31012005-04-17 16:05:31 -05001011 tmo = phba->fc_ratov;
1012 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001013 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001014 phba->fc_ratov = tmo;
1015
1016 phba->fc_stat.elsXmitFLOGI++;
1017 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001018
1019 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1020 "Issue FLOGI: opt:x%x",
1021 phba->sli3_options, 0, 0);
1022
James Smart92d7f7b2007-06-17 19:56:38 -05001023 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001024 if (rc == IOCB_ERROR) {
1025 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001026 return 1;
dea31012005-04-17 16:05:31 -05001027 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001028 return 0;
dea31012005-04-17 16:05:31 -05001029}
1030
James Smarte59058c2008-08-24 21:49:00 -04001031/**
James Smart3621a712009-04-06 18:47:14 -04001032 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001033 * @phba: pointer to lpfc hba data structure.
1034 *
1035 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1036 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1037 * list and issues an abort IOCB commond on each outstanding IOCB that
1038 * contains a active Fabric_DID ndlp. Note that this function is to issue
1039 * the abort IOCB command on all the outstanding IOCBs, thus when this
1040 * function returns, it does not guarantee all the IOCBs are actually aborted.
1041 *
1042 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001043 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001044 **/
dea31012005-04-17 16:05:31 -05001045int
James Smart2e0fef82007-06-17 19:56:36 -05001046lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001047{
1048 struct lpfc_sli_ring *pring;
1049 struct lpfc_iocbq *iocb, *next_iocb;
1050 struct lpfc_nodelist *ndlp;
1051 IOCB_t *icmd;
1052
1053 /* Abort outstanding I/O on NPort <nlp_DID> */
1054 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001055 "0201 Abort outstanding I/O on NPort x%x\n",
1056 Fabric_DID);
dea31012005-04-17 16:05:31 -05001057
1058 pring = &phba->sli.ring[LPFC_ELS_RING];
1059
1060 /*
1061 * Check the txcmplq for an iocb that matches the nport the driver is
1062 * searching for.
1063 */
James Smart2e0fef82007-06-17 19:56:36 -05001064 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001065 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1066 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001067 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1068 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001069 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001070 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1071 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001072 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001073 }
1074 }
James Smart2e0fef82007-06-17 19:56:36 -05001075 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001076
1077 return 0;
1078}
1079
James Smarte59058c2008-08-24 21:49:00 -04001080/**
James Smart3621a712009-04-06 18:47:14 -04001081 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001082 * @vport: pointer to a host virtual N_Port data structure.
1083 *
1084 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1085 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1086 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1087 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1088 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1089 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1090 * @vport.
1091 *
1092 * Return code
1093 * 0 - failed to issue initial flogi for @vport
1094 * 1 - successfully issued initial flogi for @vport
1095 **/
dea31012005-04-17 16:05:31 -05001096int
James Smart2e0fef82007-06-17 19:56:36 -05001097lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001098{
James Smart2e0fef82007-06-17 19:56:36 -05001099 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001100 struct lpfc_nodelist *ndlp;
1101
James Smart98c9ea52007-10-27 13:37:33 -04001102 vport->port_state = LPFC_FLOGI;
1103 lpfc_set_disctmo(vport);
1104
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001105 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001106 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001107 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001108 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001109 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1110 if (!ndlp)
1111 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001112 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001113 /* Set the node type */
1114 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001115 /* Put ndlp onto node list */
1116 lpfc_enqueue_node(vport, ndlp);
1117 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1118 /* re-setup ndlp without removing from node list */
1119 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1120 if (!ndlp)
1121 return 0;
dea31012005-04-17 16:05:31 -05001122 }
James Smart87af33f2007-10-27 13:37:43 -04001123
James Smarte47c9092008-02-08 18:49:26 -05001124 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001125 /* This decrement of reference count to node shall kick off
1126 * the release of the node.
1127 */
James Smart329f9bc2007-04-25 09:53:01 -04001128 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001129
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001130 return 1;
dea31012005-04-17 16:05:31 -05001131}
1132
James Smarte59058c2008-08-24 21:49:00 -04001133/**
James Smart3621a712009-04-06 18:47:14 -04001134 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001135 * @vport: pointer to a host virtual N_Port data structure.
1136 *
1137 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1138 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1139 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1140 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1141 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1142 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1143 * @vport.
1144 *
1145 * Return code
1146 * 0 - failed to issue initial fdisc for @vport
1147 * 1 - successfully issued initial fdisc for @vport
1148 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001149int
1150lpfc_initial_fdisc(struct lpfc_vport *vport)
1151{
1152 struct lpfc_hba *phba = vport->phba;
1153 struct lpfc_nodelist *ndlp;
1154
1155 /* First look for the Fabric ndlp */
1156 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1157 if (!ndlp) {
1158 /* Cannot find existing Fabric ndlp, so allocate a new one */
1159 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1160 if (!ndlp)
1161 return 0;
1162 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001163 /* Put ndlp onto node list */
1164 lpfc_enqueue_node(vport, ndlp);
1165 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1166 /* re-setup ndlp without removing from node list */
1167 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1168 if (!ndlp)
1169 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001170 }
James Smarte47c9092008-02-08 18:49:26 -05001171
James Smart92d7f7b2007-06-17 19:56:38 -05001172 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001173 /* decrement node reference count to trigger the release of
1174 * the node.
1175 */
James Smart92d7f7b2007-06-17 19:56:38 -05001176 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001177 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001178 }
1179 return 1;
1180}
James Smart87af33f2007-10-27 13:37:43 -04001181
James Smarte59058c2008-08-24 21:49:00 -04001182/**
James Smart3621a712009-04-06 18:47:14 -04001183 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001184 * @vport: pointer to a host virtual N_Port data structure.
1185 *
1186 * This routine checks whether there are more remaining Port Logins
1187 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1188 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1189 * to issue ELS PLOGIs up to the configured discover threads with the
1190 * @vport (@vport->cfg_discovery_threads). The function also decrement
1191 * the @vport's num_disc_node by 1 if it is not already 0.
1192 **/
James Smart87af33f2007-10-27 13:37:43 -04001193void
James Smart2e0fef82007-06-17 19:56:36 -05001194lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001195{
1196 int sentplogi;
1197
James Smart2e0fef82007-06-17 19:56:36 -05001198 if (vport->num_disc_nodes)
1199 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001200
1201 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001202 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1203 "0232 Continue discovery with %d PLOGIs to go "
1204 "Data: x%x x%x x%x\n",
1205 vport->num_disc_nodes, vport->fc_plogi_cnt,
1206 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001207 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001208 if (vport->fc_flag & FC_NLP_MORE)
1209 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1210 sentplogi = lpfc_els_disc_plogi(vport);
1211
dea31012005-04-17 16:05:31 -05001212 return;
1213}
1214
James Smarte59058c2008-08-24 21:49:00 -04001215/**
James Smart3621a712009-04-06 18:47:14 -04001216 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001217 * @phba: pointer to lpfc hba data structure.
1218 * @prsp: pointer to response IOCB payload.
1219 * @ndlp: pointer to a node-list data structure.
1220 *
1221 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1222 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1223 * The following cases are considered N_Port confirmed:
1224 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1225 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1226 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1227 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1228 * 1) if there is a node on vport list other than the @ndlp with the same
1229 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1230 * on that node to release the RPI associated with the node; 2) if there is
1231 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1232 * into, a new node shall be allocated (or activated). In either case, the
1233 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1234 * be released and the new_ndlp shall be put on to the vport node list and
1235 * its pointer returned as the confirmed node.
1236 *
1237 * Note that before the @ndlp got "released", the keepDID from not-matching
1238 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1239 * of the @ndlp. This is because the release of @ndlp is actually to put it
1240 * into an inactive state on the vport node list and the vport node list
1241 * management algorithm does not allow two node with a same DID.
1242 *
1243 * Return code
1244 * pointer to the PLOGI N_Port @ndlp
1245 **/
James Smart488d1462006-03-07 15:02:37 -05001246static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001247lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001248 struct lpfc_nodelist *ndlp)
1249{
James Smart2e0fef82007-06-17 19:56:36 -05001250 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001251 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001252 struct lpfc_rport_data *rdata;
1253 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001254 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001255 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001256 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001257
James Smart2fb9bd82006-12-02 13:33:57 -05001258 /* Fabric nodes can have the same WWPN so we don't bother searching
1259 * by WWPN. Just return the ndlp that was given to us.
1260 */
1261 if (ndlp->nlp_type & NLP_FABRIC)
1262 return ndlp;
1263
James Smart92d7f7b2007-06-17 19:56:38 -05001264 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001265 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001266
James Smart685f0bf2007-04-25 09:53:08 -04001267 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001268 * we have for that ndlp. If not, we have some work to do.
1269 */
James Smart2e0fef82007-06-17 19:56:36 -05001270 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001271
James Smarte47c9092008-02-08 18:49:26 -05001272 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001273 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001274
1275 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001276 rc = memcmp(&ndlp->nlp_portname, name,
1277 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001278 if (!rc)
1279 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001280 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1281 if (!new_ndlp)
1282 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001283 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001284 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001285 rc = memcmp(&ndlp->nlp_portname, name,
1286 sizeof(struct lpfc_name));
1287 if (!rc)
1288 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001289 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1290 NLP_STE_UNUSED_NODE);
1291 if (!new_ndlp)
1292 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001293 keepDID = new_ndlp->nlp_DID;
1294 } else
1295 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001296
James Smart2e0fef82007-06-17 19:56:36 -05001297 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001298 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001299 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001300
1301 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1302 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1303 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1304
James Smarte47c9092008-02-08 18:49:26 -05001305 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001306 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001307
James Smart2e0fef82007-06-17 19:56:36 -05001308 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001309 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1310 /* The new_ndlp is replacing ndlp totally, so we need
1311 * to put ndlp on UNUSED list and try to free it.
1312 */
James Smart0ff10d42008-01-11 01:52:36 -05001313
1314 /* Fix up the rport accordingly */
1315 rport = ndlp->rport;
1316 if (rport) {
1317 rdata = rport->dd_data;
1318 if (rdata->pnode == ndlp) {
1319 lpfc_nlp_put(ndlp);
1320 ndlp->rport = NULL;
1321 rdata->pnode = lpfc_nlp_get(new_ndlp);
1322 new_ndlp->rport = rport;
1323 }
1324 new_ndlp->nlp_type = ndlp->nlp_type;
1325 }
James Smart58da1ff2008-04-07 10:15:56 -04001326 /* We shall actually free the ndlp with both nlp_DID and
1327 * nlp_portname fields equals 0 to avoid any ndlp on the
1328 * nodelist never to be used.
1329 */
1330 if (ndlp->nlp_DID == 0) {
1331 spin_lock_irq(&phba->ndlp_lock);
1332 NLP_SET_FREE_REQ(ndlp);
1333 spin_unlock_irq(&phba->ndlp_lock);
1334 }
James Smart0ff10d42008-01-11 01:52:36 -05001335
James Smart58da1ff2008-04-07 10:15:56 -04001336 /* Two ndlps cannot have the same did on the nodelist */
1337 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001338 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001339 }
James Smart92795652006-07-06 15:50:02 -04001340 else {
James Smart2e0fef82007-06-17 19:56:36 -05001341 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001342 /* Two ndlps cannot have the same did */
1343 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001344 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001345 }
James Smart488d1462006-03-07 15:02:37 -05001346 return new_ndlp;
1347}
1348
James Smarte59058c2008-08-24 21:49:00 -04001349/**
James Smart3621a712009-04-06 18:47:14 -04001350 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001351 * @vport: pointer to a host virtual N_Port data structure.
1352 *
1353 * This routine checks whether more Registration State Change
1354 * Notifications (RSCNs) came in while the discovery state machine was in
1355 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1356 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1357 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1358 * handling the RSCNs.
1359 **/
James Smart87af33f2007-10-27 13:37:43 -04001360void
1361lpfc_end_rscn(struct lpfc_vport *vport)
1362{
1363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1364
1365 if (vport->fc_flag & FC_RSCN_MODE) {
1366 /*
1367 * Check to see if more RSCNs came in while we were
1368 * processing this one.
1369 */
1370 if (vport->fc_rscn_id_cnt ||
1371 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1372 lpfc_els_handle_rscn(vport);
1373 else {
1374 spin_lock_irq(shost->host_lock);
1375 vport->fc_flag &= ~FC_RSCN_MODE;
1376 spin_unlock_irq(shost->host_lock);
1377 }
1378 }
1379}
1380
James Smarte59058c2008-08-24 21:49:00 -04001381/**
James Smart3621a712009-04-06 18:47:14 -04001382 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001383 * @phba: pointer to lpfc hba data structure.
1384 * @cmdiocb: pointer to lpfc command iocb data structure.
1385 * @rspiocb: pointer to lpfc response iocb data structure.
1386 *
1387 * This routine is the completion callback function for issuing the Port
1388 * Login (PLOGI) command. For PLOGI completion, there must be an active
1389 * ndlp on the vport node list that matches the remote node ID from the
1390 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1391 * ignored and command IOCB released. The PLOGI response IOCB status is
1392 * checked for error conditons. If there is error status reported, PLOGI
1393 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1394 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1395 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1396 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1397 * there are additional N_Port nodes with the vport that need to perform
1398 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1399 * PLOGIs.
1400 **/
dea31012005-04-17 16:05:31 -05001401static void
James Smart2e0fef82007-06-17 19:56:36 -05001402lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1403 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001404{
James Smart2e0fef82007-06-17 19:56:36 -05001405 struct lpfc_vport *vport = cmdiocb->vport;
1406 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001407 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001408 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001409 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001410 int disc, rc, did, type;
1411
dea31012005-04-17 16:05:31 -05001412 /* we pass cmdiocb to state machine which needs rspiocb as well */
1413 cmdiocb->context_un.rsp_iocb = rspiocb;
1414
1415 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001416 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1417 "PLOGI cmpl: status:x%x/x%x did:x%x",
1418 irsp->ulpStatus, irsp->un.ulpWord[4],
1419 irsp->un.elsreq64.remoteID);
1420
James Smart2e0fef82007-06-17 19:56:36 -05001421 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001422 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001423 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1424 "0136 PLOGI completes to NPort x%x "
1425 "with no ndlp. Data: x%x x%x x%x\n",
1426 irsp->un.elsreq64.remoteID,
1427 irsp->ulpStatus, irsp->un.ulpWord[4],
1428 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001429 goto out;
James Smarted957682007-06-17 19:56:37 -05001430 }
dea31012005-04-17 16:05:31 -05001431
1432 /* Since ndlp can be freed in the disc state machine, note if this node
1433 * is being used during discovery.
1434 */
James Smart2e0fef82007-06-17 19:56:36 -05001435 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001436 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001437 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001438 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001439 rc = 0;
1440
1441 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001442 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1443 "0102 PLOGI completes to NPort x%x "
1444 "Data: x%x x%x x%x x%x x%x\n",
1445 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1446 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001447 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001448 if (lpfc_els_chk_latt(vport)) {
1449 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001450 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001451 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001452 goto out;
1453 }
1454
1455 /* ndlp could be freed in DSM, save these values now */
1456 type = ndlp->nlp_type;
1457 did = ndlp->nlp_DID;
1458
1459 if (irsp->ulpStatus) {
1460 /* Check for retry */
1461 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1462 /* ELS command is being retried */
1463 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001464 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001465 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001466 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001467 }
1468 goto out;
1469 }
dea31012005-04-17 16:05:31 -05001470 /* PLOGI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001471 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1472 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1473 ndlp->nlp_DID, irsp->ulpStatus,
1474 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001475 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001476 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001477 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001478 else
James Smart2e0fef82007-06-17 19:56:36 -05001479 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001480 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001481 } else {
1482 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001483 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001484 cmdiocb->context2)->list.next,
1485 struct lpfc_dmabuf, list);
1486 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001487 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001488 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001489 }
1490
James Smart2e0fef82007-06-17 19:56:36 -05001491 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001492 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001493 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001494
James Smart2e0fef82007-06-17 19:56:36 -05001495 if (vport->num_disc_nodes == 0) {
1496 spin_lock_irq(shost->host_lock);
1497 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1498 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001499
James Smart2e0fef82007-06-17 19:56:36 -05001500 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001501 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001502 }
1503 }
1504
1505out:
1506 lpfc_els_free_iocb(phba, cmdiocb);
1507 return;
1508}
1509
James Smarte59058c2008-08-24 21:49:00 -04001510/**
James Smart3621a712009-04-06 18:47:14 -04001511 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001512 * @vport: pointer to a host virtual N_Port data structure.
1513 * @did: destination port identifier.
1514 * @retry: number of retries to the command IOCB.
1515 *
1516 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1517 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1518 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1519 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1520 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1521 *
1522 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1523 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1524 * will be stored into the context1 field of the IOCB for the completion
1525 * callback function to the PLOGI ELS command.
1526 *
1527 * Return code
1528 * 0 - Successfully issued a plogi for @vport
1529 * 1 - failed to issue a plogi for @vport
1530 **/
dea31012005-04-17 16:05:31 -05001531int
James Smart2e0fef82007-06-17 19:56:36 -05001532lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001533{
James Smart2e0fef82007-06-17 19:56:36 -05001534 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001535 struct serv_parm *sp;
1536 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001537 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001538 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001539 struct lpfc_sli *psli;
1540 uint8_t *pcmd;
1541 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001542 int ret;
dea31012005-04-17 16:05:31 -05001543
1544 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001545
James Smart98c9ea52007-10-27 13:37:33 -04001546 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001547 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1548 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001549
James Smarte47c9092008-02-08 18:49:26 -05001550 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001551 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001552 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001553 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001554 if (!elsiocb)
1555 return 1;
dea31012005-04-17 16:05:31 -05001556
1557 icmd = &elsiocb->iocb;
1558 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1559
1560 /* For PLOGI request, remainder of payload is service parameters */
1561 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001562 pcmd += sizeof(uint32_t);
1563 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001564 sp = (struct serv_parm *) pcmd;
1565
1566 if (sp->cmn.fcphLow < FC_PH_4_3)
1567 sp->cmn.fcphLow = FC_PH_4_3;
1568
1569 if (sp->cmn.fcphHigh < FC_PH3)
1570 sp->cmn.fcphHigh = FC_PH3;
1571
James Smart858c9f62007-06-17 19:56:39 -05001572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1573 "Issue PLOGI: did:x%x",
1574 did, 0, 0);
1575
dea31012005-04-17 16:05:31 -05001576 phba->fc_stat.elsXmitPLOGI++;
1577 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001578 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001579
1580 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001581 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001582 return 1;
dea31012005-04-17 16:05:31 -05001583 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001584 return 0;
dea31012005-04-17 16:05:31 -05001585}
1586
James Smarte59058c2008-08-24 21:49:00 -04001587/**
James Smart3621a712009-04-06 18:47:14 -04001588 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001589 * @phba: pointer to lpfc hba data structure.
1590 * @cmdiocb: pointer to lpfc command iocb data structure.
1591 * @rspiocb: pointer to lpfc response iocb data structure.
1592 *
1593 * This routine is the completion callback function for a Process Login
1594 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1595 * status. If there is error status reported, PRLI retry shall be attempted
1596 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1597 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1598 * ndlp to mark the PRLI completion.
1599 **/
dea31012005-04-17 16:05:31 -05001600static void
James Smart2e0fef82007-06-17 19:56:36 -05001601lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1602 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001603{
James Smart2e0fef82007-06-17 19:56:36 -05001604 struct lpfc_vport *vport = cmdiocb->vport;
1605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001606 IOCB_t *irsp;
1607 struct lpfc_sli *psli;
1608 struct lpfc_nodelist *ndlp;
1609
1610 psli = &phba->sli;
1611 /* we pass cmdiocb to state machine which needs rspiocb as well */
1612 cmdiocb->context_un.rsp_iocb = rspiocb;
1613
1614 irsp = &(rspiocb->iocb);
1615 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001616 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001617 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001618 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001619
James Smart858c9f62007-06-17 19:56:39 -05001620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1621 "PRLI cmpl: status:x%x/x%x did:x%x",
1622 irsp->ulpStatus, irsp->un.ulpWord[4],
1623 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001624 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001625 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1626 "0103 PRLI completes to NPort x%x "
1627 "Data: x%x x%x x%x x%x\n",
1628 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1629 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001630
James Smart2e0fef82007-06-17 19:56:36 -05001631 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001632 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001633 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001634 goto out;
1635
1636 if (irsp->ulpStatus) {
1637 /* Check for retry */
1638 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1639 /* ELS command is being retried */
1640 goto out;
1641 }
1642 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001643 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1644 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1645 ndlp->nlp_DID, irsp->ulpStatus,
1646 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001647 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001648 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001649 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001650 else
James Smart2e0fef82007-06-17 19:56:36 -05001651 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001652 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001653 } else
dea31012005-04-17 16:05:31 -05001654 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001655 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001656 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001657out:
1658 lpfc_els_free_iocb(phba, cmdiocb);
1659 return;
1660}
1661
James Smarte59058c2008-08-24 21:49:00 -04001662/**
James Smart3621a712009-04-06 18:47:14 -04001663 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001664 * @vport: pointer to a host virtual N_Port data structure.
1665 * @ndlp: pointer to a node-list data structure.
1666 * @retry: number of retries to the command IOCB.
1667 *
1668 * This routine issues a Process Login (PRLI) ELS command for the
1669 * @vport. The PRLI service parameters are set up in the payload of the
1670 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1671 * is put to the IOCB completion callback func field before invoking the
1672 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1673 *
1674 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1675 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1676 * will be stored into the context1 field of the IOCB for the completion
1677 * callback function to the PRLI ELS command.
1678 *
1679 * Return code
1680 * 0 - successfully issued prli iocb command for @vport
1681 * 1 - failed to issue prli iocb command for @vport
1682 **/
dea31012005-04-17 16:05:31 -05001683int
James Smart2e0fef82007-06-17 19:56:36 -05001684lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001685 uint8_t retry)
1686{
James Smart2e0fef82007-06-17 19:56:36 -05001687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1688 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001689 PRLI *npr;
1690 IOCB_t *icmd;
1691 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001692 uint8_t *pcmd;
1693 uint16_t cmdsize;
1694
James Smart92d7f7b2007-06-17 19:56:38 -05001695 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001696 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1697 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001698 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001699 return 1;
dea31012005-04-17 16:05:31 -05001700
1701 icmd = &elsiocb->iocb;
1702 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1703
1704 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001705 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001706 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001707 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001708
1709 /* For PRLI, remainder of payload is PRLI parameter page */
1710 npr = (PRLI *) pcmd;
1711 /*
1712 * If our firmware version is 3.20 or later,
1713 * set the following bits for FC-TAPE support.
1714 */
1715 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1716 npr->ConfmComplAllowed = 1;
1717 npr->Retry = 1;
1718 npr->TaskRetryIdReq = 1;
1719 }
1720 npr->estabImagePair = 1;
1721 npr->readXferRdyDis = 1;
1722
1723 /* For FCP support */
1724 npr->prliType = PRLI_FCP_TYPE;
1725 npr->initiatorFunc = 1;
1726
James Smart858c9f62007-06-17 19:56:39 -05001727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1728 "Issue PRLI: did:x%x",
1729 ndlp->nlp_DID, 0, 0);
1730
dea31012005-04-17 16:05:31 -05001731 phba->fc_stat.elsXmitPRLI++;
1732 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001733 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001734 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001735 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001736 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1737 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001738 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001739 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001740 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001741 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001742 return 1;
dea31012005-04-17 16:05:31 -05001743 }
James Smart2e0fef82007-06-17 19:56:36 -05001744 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001745 return 0;
dea31012005-04-17 16:05:31 -05001746}
1747
James Smarte59058c2008-08-24 21:49:00 -04001748/**
James Smart3621a712009-04-06 18:47:14 -04001749 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001750 * @vport: pointer to a host virtual N_Port data structure.
1751 *
1752 * This routine performs Registration State Change Notification (RSCN)
1753 * discovery for a @vport. If the @vport's node port recovery count is not
1754 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1755 * the nodes that need recovery. If none of the PLOGI were needed through
1756 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1757 * invoked to check and handle possible more RSCN came in during the period
1758 * of processing the current ones.
1759 **/
1760static void
1761lpfc_rscn_disc(struct lpfc_vport *vport)
1762{
1763 lpfc_can_disctmo(vport);
1764
1765 /* RSCN discovery */
1766 /* go thru NPR nodes and issue ELS PLOGIs */
1767 if (vport->fc_npr_cnt)
1768 if (lpfc_els_disc_plogi(vport))
1769 return;
1770
1771 lpfc_end_rscn(vport);
1772}
1773
1774/**
James Smart3621a712009-04-06 18:47:14 -04001775 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001776 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1777 *
1778 * This function is called when the final ADISC is completed during discovery.
1779 * This function handles clearing link attention or issuing reg_vpi depending
1780 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1781 * discovery.
1782 * This function is called with no locks held.
1783 **/
1784static void
1785lpfc_adisc_done(struct lpfc_vport *vport)
1786{
1787 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1788 struct lpfc_hba *phba = vport->phba;
1789
1790 /*
1791 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1792 * and continue discovery.
1793 */
1794 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001795 !(vport->fc_flag & FC_RSCN_MODE) &&
1796 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001797 lpfc_issue_reg_vpi(phba, vport);
1798 return;
1799 }
1800 /*
1801 * For SLI2, we need to set port_state to READY
1802 * and continue discovery.
1803 */
1804 if (vport->port_state < LPFC_VPORT_READY) {
1805 /* If we get here, there is nothing to ADISC */
1806 if (vport->port_type == LPFC_PHYSICAL_PORT)
1807 lpfc_issue_clear_la(phba, vport);
1808 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1809 vport->num_disc_nodes = 0;
1810 /* go thru NPR list, issue ELS PLOGIs */
1811 if (vport->fc_npr_cnt)
1812 lpfc_els_disc_plogi(vport);
1813 if (!vport->num_disc_nodes) {
1814 spin_lock_irq(shost->host_lock);
1815 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1816 spin_unlock_irq(shost->host_lock);
1817 lpfc_can_disctmo(vport);
1818 lpfc_end_rscn(vport);
1819 }
1820 }
1821 vport->port_state = LPFC_VPORT_READY;
1822 } else
1823 lpfc_rscn_disc(vport);
1824}
1825
1826/**
James Smart3621a712009-04-06 18:47:14 -04001827 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001828 * @vport: pointer to a host virtual N_Port data structure.
1829 *
1830 * This routine determines whether there are more ndlps on a @vport
1831 * node list need to have Address Discover (ADISC) issued. If so, it will
1832 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1833 * remaining nodes which need to have ADISC sent.
1834 **/
James Smart0ff10d42008-01-11 01:52:36 -05001835void
James Smart2e0fef82007-06-17 19:56:36 -05001836lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001837{
1838 int sentadisc;
1839
James Smart2e0fef82007-06-17 19:56:36 -05001840 if (vport->num_disc_nodes)
1841 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001842 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001843 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1844 "0210 Continue discovery with %d ADISCs to go "
1845 "Data: x%x x%x x%x\n",
1846 vport->num_disc_nodes, vport->fc_adisc_cnt,
1847 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001848 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001849 if (vport->fc_flag & FC_NLP_MORE) {
1850 lpfc_set_disctmo(vport);
1851 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1852 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001853 }
James Smart90160e02008-08-24 21:49:45 -04001854 if (!vport->num_disc_nodes)
1855 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001856 return;
1857}
1858
James Smarte59058c2008-08-24 21:49:00 -04001859/**
James Smart3621a712009-04-06 18:47:14 -04001860 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001861 * @phba: pointer to lpfc hba data structure.
1862 * @cmdiocb: pointer to lpfc command iocb data structure.
1863 * @rspiocb: pointer to lpfc response iocb data structure.
1864 *
1865 * This routine is the completion function for issuing the Address Discover
1866 * (ADISC) command. It first checks to see whether link went down during
1867 * the discovery process. If so, the node will be marked as node port
1868 * recovery for issuing discover IOCB by the link attention handler and
1869 * exit. Otherwise, the response status is checked. If error was reported
1870 * in the response status, the ADISC command shall be retried by invoking
1871 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1872 * the response status, the state machine is invoked to set transition
1873 * with respect to NLP_EVT_CMPL_ADISC event.
1874 **/
dea31012005-04-17 16:05:31 -05001875static void
James Smart2e0fef82007-06-17 19:56:36 -05001876lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1877 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001878{
James Smart2e0fef82007-06-17 19:56:36 -05001879 struct lpfc_vport *vport = cmdiocb->vport;
1880 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001881 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001882 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001883 int disc;
dea31012005-04-17 16:05:31 -05001884
1885 /* we pass cmdiocb to state machine which needs rspiocb as well */
1886 cmdiocb->context_un.rsp_iocb = rspiocb;
1887
1888 irsp = &(rspiocb->iocb);
1889 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001890
James Smart858c9f62007-06-17 19:56:39 -05001891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1892 "ADISC cmpl: status:x%x/x%x did:x%x",
1893 irsp->ulpStatus, irsp->un.ulpWord[4],
1894 ndlp->nlp_DID);
1895
dea31012005-04-17 16:05:31 -05001896 /* Since ndlp can be freed in the disc state machine, note if this node
1897 * is being used during discovery.
1898 */
James Smart2e0fef82007-06-17 19:56:36 -05001899 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001900 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001901 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001902 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001903 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001904 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1905 "0104 ADISC completes to NPort x%x "
1906 "Data: x%x x%x x%x x%x x%x\n",
1907 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1908 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001909 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001910 if (lpfc_els_chk_latt(vport)) {
1911 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001912 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001913 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001914 goto out;
1915 }
1916
1917 if (irsp->ulpStatus) {
1918 /* Check for retry */
1919 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1920 /* ELS command is being retried */
1921 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001922 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001923 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001924 spin_unlock_irq(shost->host_lock);
1925 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001926 }
1927 goto out;
1928 }
1929 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001930 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1931 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1932 ndlp->nlp_DID, irsp->ulpStatus,
1933 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001934 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001935 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001936 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001937 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001938 } else
dea31012005-04-17 16:05:31 -05001939 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001940 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001941 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001942
James Smart90160e02008-08-24 21:49:45 -04001943 /* Check to see if there are more ADISCs to be sent */
1944 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001945 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001946out:
1947 lpfc_els_free_iocb(phba, cmdiocb);
1948 return;
1949}
1950
James Smarte59058c2008-08-24 21:49:00 -04001951/**
James Smart3621a712009-04-06 18:47:14 -04001952 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001953 * @vport: pointer to a virtual N_Port data structure.
1954 * @ndlp: pointer to a node-list data structure.
1955 * @retry: number of retries to the command IOCB.
1956 *
1957 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1958 * @vport. It prepares the payload of the ADISC ELS command, updates the
1959 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1960 * to issue the ADISC ELS command.
1961 *
1962 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1963 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1964 * will be stored into the context1 field of the IOCB for the completion
1965 * callback function to the ADISC ELS command.
1966 *
1967 * Return code
1968 * 0 - successfully issued adisc
1969 * 1 - failed to issue adisc
1970 **/
dea31012005-04-17 16:05:31 -05001971int
James Smart2e0fef82007-06-17 19:56:36 -05001972lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001973 uint8_t retry)
1974{
James Smart2e0fef82007-06-17 19:56:36 -05001975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1976 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001977 ADISC *ap;
1978 IOCB_t *icmd;
1979 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001980 uint8_t *pcmd;
1981 uint16_t cmdsize;
1982
James Smart92d7f7b2007-06-17 19:56:38 -05001983 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001984 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1985 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001986 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001987 return 1;
dea31012005-04-17 16:05:31 -05001988
1989 icmd = &elsiocb->iocb;
1990 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1991
1992 /* For ADISC request, remainder of payload is service parameters */
1993 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001994 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001995
1996 /* Fill in ADISC payload */
1997 ap = (ADISC *) pcmd;
1998 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001999 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2000 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002001 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002002
James Smart858c9f62007-06-17 19:56:39 -05002003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2004 "Issue ADISC: did:x%x",
2005 ndlp->nlp_DID, 0, 0);
2006
dea31012005-04-17 16:05:31 -05002007 phba->fc_stat.elsXmitADISC++;
2008 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002009 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002010 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002011 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002012 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2013 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002014 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002015 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002016 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002017 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002018 return 1;
dea31012005-04-17 16:05:31 -05002019 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002020 return 0;
dea31012005-04-17 16:05:31 -05002021}
2022
James Smarte59058c2008-08-24 21:49:00 -04002023/**
James Smart3621a712009-04-06 18:47:14 -04002024 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002025 * @phba: pointer to lpfc hba data structure.
2026 * @cmdiocb: pointer to lpfc command iocb data structure.
2027 * @rspiocb: pointer to lpfc response iocb data structure.
2028 *
2029 * This routine is the completion function for issuing the ELS Logout (LOGO)
2030 * command. If no error status was reported from the LOGO response, the
2031 * state machine of the associated ndlp shall be invoked for transition with
2032 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2033 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2034 **/
dea31012005-04-17 16:05:31 -05002035static void
James Smart2e0fef82007-06-17 19:56:36 -05002036lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2037 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002038{
James Smart2e0fef82007-06-17 19:56:36 -05002039 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2040 struct lpfc_vport *vport = ndlp->vport;
2041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002042 IOCB_t *irsp;
2043 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002044
2045 psli = &phba->sli;
2046 /* we pass cmdiocb to state machine which needs rspiocb as well */
2047 cmdiocb->context_un.rsp_iocb = rspiocb;
2048
2049 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002050 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002051 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002052 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002053
James Smart858c9f62007-06-17 19:56:39 -05002054 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2055 "LOGO cmpl: status:x%x/x%x did:x%x",
2056 irsp->ulpStatus, irsp->un.ulpWord[4],
2057 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002058 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002059 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2060 "0105 LOGO completes to NPort x%x "
2061 "Data: x%x x%x x%x x%x\n",
2062 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2063 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002064 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002065 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002066 goto out;
2067
James Smart92d7f7b2007-06-17 19:56:38 -05002068 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2069 /* NLP_EVT_DEVICE_RM should unregister the RPI
2070 * which should abort all outstanding IOs.
2071 */
2072 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2073 NLP_EVT_DEVICE_RM);
2074 goto out;
2075 }
2076
dea31012005-04-17 16:05:31 -05002077 if (irsp->ulpStatus) {
2078 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002079 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002080 /* ELS command is being retried */
2081 goto out;
dea31012005-04-17 16:05:31 -05002082 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002083 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2084 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2085 ndlp->nlp_DID, irsp->ulpStatus,
2086 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002087 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002088 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002089 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002090 else
James Smart2e0fef82007-06-17 19:56:36 -05002091 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002092 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002093 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002094 /* Good status, call state machine.
2095 * This will unregister the rpi if needed.
2096 */
James Smart2e0fef82007-06-17 19:56:36 -05002097 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002098 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002099out:
2100 lpfc_els_free_iocb(phba, cmdiocb);
2101 return;
2102}
2103
James Smarte59058c2008-08-24 21:49:00 -04002104/**
James Smart3621a712009-04-06 18:47:14 -04002105 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002106 * @vport: pointer to a virtual N_Port data structure.
2107 * @ndlp: pointer to a node-list data structure.
2108 * @retry: number of retries to the command IOCB.
2109 *
2110 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2111 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2112 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2113 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2114 *
2115 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2116 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2117 * will be stored into the context1 field of the IOCB for the completion
2118 * callback function to the LOGO ELS command.
2119 *
2120 * Return code
2121 * 0 - successfully issued logo
2122 * 1 - failed to issue logo
2123 **/
dea31012005-04-17 16:05:31 -05002124int
James Smart2e0fef82007-06-17 19:56:36 -05002125lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002126 uint8_t retry)
2127{
James Smart2e0fef82007-06-17 19:56:36 -05002128 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2129 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002130 IOCB_t *icmd;
2131 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002132 uint8_t *pcmd;
2133 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002134 int rc;
dea31012005-04-17 16:05:31 -05002135
James Smart98c9ea52007-10-27 13:37:33 -04002136 spin_lock_irq(shost->host_lock);
2137 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2138 spin_unlock_irq(shost->host_lock);
2139 return 0;
2140 }
2141 spin_unlock_irq(shost->host_lock);
2142
James Smart92d7f7b2007-06-17 19:56:38 -05002143 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002144 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2145 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002146 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002147 return 1;
dea31012005-04-17 16:05:31 -05002148
2149 icmd = &elsiocb->iocb;
2150 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2151 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002152 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002153
2154 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002155 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002156 pcmd += sizeof(uint32_t);
2157 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002158
James Smart858c9f62007-06-17 19:56:39 -05002159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2160 "Issue LOGO: did:x%x",
2161 ndlp->nlp_DID, 0, 0);
2162
dea31012005-04-17 16:05:31 -05002163 phba->fc_stat.elsXmitLOGO++;
2164 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002165 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002166 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002167 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002168 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002169
2170 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002171 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002172 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002173 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002174 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002175 return 1;
dea31012005-04-17 16:05:31 -05002176 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002177 return 0;
dea31012005-04-17 16:05:31 -05002178}
2179
James Smarte59058c2008-08-24 21:49:00 -04002180/**
James Smart3621a712009-04-06 18:47:14 -04002181 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002182 * @phba: pointer to lpfc hba data structure.
2183 * @cmdiocb: pointer to lpfc command iocb data structure.
2184 * @rspiocb: pointer to lpfc response iocb data structure.
2185 *
2186 * This routine is a generic completion callback function for ELS commands.
2187 * Specifically, it is the callback function which does not need to perform
2188 * any command specific operations. It is currently used by the ELS command
2189 * issuing routines for the ELS State Change Request (SCR),
2190 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2191 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2192 * certain debug loggings, this callback function simply invokes the
2193 * lpfc_els_chk_latt() routine to check whether link went down during the
2194 * discovery process.
2195 **/
dea31012005-04-17 16:05:31 -05002196static void
James Smart2e0fef82007-06-17 19:56:36 -05002197lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2198 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002199{
James Smart2e0fef82007-06-17 19:56:36 -05002200 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002201 IOCB_t *irsp;
2202
2203 irsp = &rspiocb->iocb;
2204
James Smart858c9f62007-06-17 19:56:39 -05002205 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2206 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2207 irsp->ulpStatus, irsp->un.ulpWord[4],
2208 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002209 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002210 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2211 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2212 irsp->ulpIoTag, irsp->ulpStatus,
2213 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002214 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002215 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002216 lpfc_els_free_iocb(phba, cmdiocb);
2217 return;
2218}
2219
James Smarte59058c2008-08-24 21:49:00 -04002220/**
James Smart3621a712009-04-06 18:47:14 -04002221 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002222 * @vport: pointer to a host virtual N_Port data structure.
2223 * @nportid: N_Port identifier to the remote node.
2224 * @retry: number of retries to the command IOCB.
2225 *
2226 * This routine issues a State Change Request (SCR) to a fabric node
2227 * on a @vport. The remote node @nportid is passed into the function. It
2228 * first search the @vport node list to find the matching ndlp. If no such
2229 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2230 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2231 * routine is invoked to send the SCR IOCB.
2232 *
2233 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2234 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2235 * will be stored into the context1 field of the IOCB for the completion
2236 * callback function to the SCR ELS command.
2237 *
2238 * Return code
2239 * 0 - Successfully issued scr command
2240 * 1 - Failed to issue scr command
2241 **/
dea31012005-04-17 16:05:31 -05002242int
James Smart2e0fef82007-06-17 19:56:36 -05002243lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002244{
James Smart2e0fef82007-06-17 19:56:36 -05002245 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002246 IOCB_t *icmd;
2247 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002248 struct lpfc_sli *psli;
2249 uint8_t *pcmd;
2250 uint16_t cmdsize;
2251 struct lpfc_nodelist *ndlp;
2252
2253 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002254 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002255
James Smarte47c9092008-02-08 18:49:26 -05002256 ndlp = lpfc_findnode_did(vport, nportid);
2257 if (!ndlp) {
2258 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2259 if (!ndlp)
2260 return 1;
2261 lpfc_nlp_init(vport, ndlp, nportid);
2262 lpfc_enqueue_node(vport, ndlp);
2263 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2264 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2265 if (!ndlp)
2266 return 1;
2267 }
dea31012005-04-17 16:05:31 -05002268
James Smart2e0fef82007-06-17 19:56:36 -05002269 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2270 ndlp->nlp_DID, ELS_CMD_SCR);
2271
James Smart488d1462006-03-07 15:02:37 -05002272 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002273 /* This will trigger the release of the node just
2274 * allocated
2275 */
James Smart329f9bc2007-04-25 09:53:01 -04002276 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002277 return 1;
dea31012005-04-17 16:05:31 -05002278 }
2279
2280 icmd = &elsiocb->iocb;
2281 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2282
2283 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002284 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002285
2286 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002287 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002288 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2289
James Smart858c9f62007-06-17 19:56:39 -05002290 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2291 "Issue SCR: did:x%x",
2292 ndlp->nlp_DID, 0, 0);
2293
dea31012005-04-17 16:05:31 -05002294 phba->fc_stat.elsXmitSCR++;
2295 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002296 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2297 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002298 /* The additional lpfc_nlp_put will cause the following
2299 * lpfc_els_free_iocb routine to trigger the rlease of
2300 * the node.
2301 */
James Smart329f9bc2007-04-25 09:53:01 -04002302 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002303 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002304 return 1;
dea31012005-04-17 16:05:31 -05002305 }
James Smartfa4066b2008-01-11 01:53:27 -05002306 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2307 * trigger the release of node.
2308 */
James Smart329f9bc2007-04-25 09:53:01 -04002309 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002310 return 0;
dea31012005-04-17 16:05:31 -05002311}
2312
James Smarte59058c2008-08-24 21:49:00 -04002313/**
James Smart3621a712009-04-06 18:47:14 -04002314 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002315 * @vport: pointer to a host virtual N_Port data structure.
2316 * @nportid: N_Port identifier to the remote node.
2317 * @retry: number of retries to the command IOCB.
2318 *
2319 * This routine issues a Fibre Channel Address Resolution Response
2320 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2321 * is passed into the function. It first search the @vport node list to find
2322 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2323 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2324 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2325 *
2326 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2327 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2328 * will be stored into the context1 field of the IOCB for the completion
2329 * callback function to the PARPR ELS command.
2330 *
2331 * Return code
2332 * 0 - Successfully issued farpr command
2333 * 1 - Failed to issue farpr command
2334 **/
dea31012005-04-17 16:05:31 -05002335static int
James Smart2e0fef82007-06-17 19:56:36 -05002336lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002337{
James Smart2e0fef82007-06-17 19:56:36 -05002338 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002339 IOCB_t *icmd;
2340 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002341 struct lpfc_sli *psli;
2342 FARP *fp;
2343 uint8_t *pcmd;
2344 uint32_t *lp;
2345 uint16_t cmdsize;
2346 struct lpfc_nodelist *ondlp;
2347 struct lpfc_nodelist *ndlp;
2348
2349 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002350 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002351
James Smarte47c9092008-02-08 18:49:26 -05002352 ndlp = lpfc_findnode_did(vport, nportid);
2353 if (!ndlp) {
2354 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2355 if (!ndlp)
2356 return 1;
2357 lpfc_nlp_init(vport, ndlp, nportid);
2358 lpfc_enqueue_node(vport, ndlp);
2359 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2360 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2361 if (!ndlp)
2362 return 1;
2363 }
James Smart2e0fef82007-06-17 19:56:36 -05002364
2365 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2366 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002367 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002368 /* This will trigger the release of the node just
2369 * allocated
2370 */
James Smart329f9bc2007-04-25 09:53:01 -04002371 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002372 return 1;
dea31012005-04-17 16:05:31 -05002373 }
2374
2375 icmd = &elsiocb->iocb;
2376 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2377
2378 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002379 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002380
2381 /* Fill in FARPR payload */
2382 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002383 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002384 lp = (uint32_t *) pcmd;
2385 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002386 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002387 fp->Rflags = 0;
2388 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2389
James Smart92d7f7b2007-06-17 19:56:38 -05002390 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2391 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002392 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002393 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002394 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002395 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002396 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002397 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002398 }
2399
James Smart858c9f62007-06-17 19:56:39 -05002400 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2401 "Issue FARPR: did:x%x",
2402 ndlp->nlp_DID, 0, 0);
2403
dea31012005-04-17 16:05:31 -05002404 phba->fc_stat.elsXmitFARPR++;
2405 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002406 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2407 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002408 /* The additional lpfc_nlp_put will cause the following
2409 * lpfc_els_free_iocb routine to trigger the release of
2410 * the node.
2411 */
James Smart329f9bc2007-04-25 09:53:01 -04002412 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002413 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002414 return 1;
dea31012005-04-17 16:05:31 -05002415 }
James Smartfa4066b2008-01-11 01:53:27 -05002416 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2417 * trigger the release of the node.
2418 */
James Smart329f9bc2007-04-25 09:53:01 -04002419 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002420 return 0;
dea31012005-04-17 16:05:31 -05002421}
2422
James Smarte59058c2008-08-24 21:49:00 -04002423/**
James Smart3621a712009-04-06 18:47:14 -04002424 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002425 * @vport: pointer to a host virtual N_Port data structure.
2426 * @nlp: pointer to a node-list data structure.
2427 *
2428 * This routine cancels the timer with a delayed IOCB-command retry for
2429 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2430 * removes the ELS retry event if it presents. In addition, if the
2431 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2432 * commands are sent for the @vport's nodes that require issuing discovery
2433 * ADISC.
2434 **/
dea31012005-04-17 16:05:31 -05002435void
James Smart2e0fef82007-06-17 19:56:36 -05002436lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002437{
James Smart2e0fef82007-06-17 19:56:36 -05002438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002439 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002440
James Smart0d2b6b82008-06-14 22:52:47 -04002441 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2442 return;
James Smart2e0fef82007-06-17 19:56:36 -05002443 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002444 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002445 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002446 del_timer_sync(&nlp->nlp_delayfunc);
2447 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002448 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002449 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002450 /* Decrement nlp reference count held for the delayed retry */
2451 evtp = &nlp->els_retry_evt;
2452 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2453 }
James Smartfdcebe22006-03-07 15:04:01 -05002454 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002455 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002456 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002457 spin_unlock_irq(shost->host_lock);
2458 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002459 if (vport->port_state < LPFC_VPORT_READY) {
2460 /* Check if there are more ADISCs to be sent */
2461 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002462 } else {
2463 /* Check if there are more PLOGIs to be sent */
2464 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002465 if (vport->num_disc_nodes == 0) {
2466 spin_lock_irq(shost->host_lock);
2467 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2468 spin_unlock_irq(shost->host_lock);
2469 lpfc_can_disctmo(vport);
2470 lpfc_end_rscn(vport);
2471 }
James Smartfdcebe22006-03-07 15:04:01 -05002472 }
2473 }
2474 }
2475 return;
2476}
2477
James Smarte59058c2008-08-24 21:49:00 -04002478/**
James Smart3621a712009-04-06 18:47:14 -04002479 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002480 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2481 *
2482 * This routine is invoked by the ndlp delayed-function timer to check
2483 * whether there is any pending ELS retry event(s) with the node. If not, it
2484 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2485 * adds the delayed events to the HBA work list and invokes the
2486 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2487 * event. Note that lpfc_nlp_get() is called before posting the event to
2488 * the work list to hold reference count of ndlp so that it guarantees the
2489 * reference to ndlp will still be available when the worker thread gets
2490 * to the event associated with the ndlp.
2491 **/
James Smartfdcebe22006-03-07 15:04:01 -05002492void
dea31012005-04-17 16:05:31 -05002493lpfc_els_retry_delay(unsigned long ptr)
2494{
James Smart2e0fef82007-06-17 19:56:36 -05002495 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2496 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002497 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002498 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002499 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002500
James Smart92d7f7b2007-06-17 19:56:38 -05002501 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002502 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002503 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002504 return;
2505 }
2506
James Smartfa4066b2008-01-11 01:53:27 -05002507 /* We need to hold the node by incrementing the reference
2508 * count until the queued work is done
2509 */
2510 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002511 if (evtp->evt_arg1) {
2512 evtp->evt = LPFC_EVT_ELS_RETRY;
2513 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002514 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002515 }
James Smart92d7f7b2007-06-17 19:56:38 -05002516 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002517 return;
2518}
2519
James Smarte59058c2008-08-24 21:49:00 -04002520/**
James Smart3621a712009-04-06 18:47:14 -04002521 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002522 * @ndlp: pointer to a node-list data structure.
2523 *
2524 * This routine is the worker-thread handler for processing the @ndlp delayed
2525 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2526 * the last ELS command from the associated ndlp and invokes the proper ELS
2527 * function according to the delayed ELS command to retry the command.
2528 **/
dea31012005-04-17 16:05:31 -05002529void
2530lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2531{
James Smart2e0fef82007-06-17 19:56:36 -05002532 struct lpfc_vport *vport = ndlp->vport;
2533 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2534 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002535
James Smart2e0fef82007-06-17 19:56:36 -05002536 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002537 did = ndlp->nlp_DID;
2538 cmd = ndlp->nlp_last_elscmd;
2539 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002540
2541 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002542 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002543 return;
2544 }
2545
2546 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002547 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002548 /*
2549 * If a discovery event readded nlp_delayfunc after timer
2550 * firing and before processing the timer, cancel the
2551 * nlp_delayfunc.
2552 */
2553 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002554 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002555 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002556
2557 switch (cmd) {
2558 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002559 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002560 break;
2561 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002562 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002563 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002564 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002565 }
dea31012005-04-17 16:05:31 -05002566 break;
2567 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002568 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002569 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002570 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002571 }
dea31012005-04-17 16:05:31 -05002572 break;
2573 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002574 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002575 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002576 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002577 }
dea31012005-04-17 16:05:31 -05002578 break;
2579 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002580 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002581 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002582 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002583 }
dea31012005-04-17 16:05:31 -05002584 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002585 case ELS_CMD_FDISC:
2586 lpfc_issue_els_fdisc(vport, ndlp, retry);
2587 break;
dea31012005-04-17 16:05:31 -05002588 }
2589 return;
2590}
2591
James Smarte59058c2008-08-24 21:49:00 -04002592/**
James Smart3621a712009-04-06 18:47:14 -04002593 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002594 * @phba: pointer to lpfc hba data structure.
2595 * @cmdiocb: pointer to lpfc command iocb data structure.
2596 * @rspiocb: pointer to lpfc response iocb data structure.
2597 *
2598 * This routine makes a retry decision on an ELS command IOCB, which has
2599 * failed. The following ELS IOCBs use this function for retrying the command
2600 * when previously issued command responsed with error status: FLOGI, PLOGI,
2601 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2602 * returned error status, it makes the decision whether a retry shall be
2603 * issued for the command, and whether a retry shall be made immediately or
2604 * delayed. In the former case, the corresponding ELS command issuing-function
2605 * is called to retry the command. In the later case, the ELS command shall
2606 * be posted to the ndlp delayed event and delayed function timer set to the
2607 * ndlp for the delayed command issusing.
2608 *
2609 * Return code
2610 * 0 - No retry of els command is made
2611 * 1 - Immediate or delayed retry of els command is made
2612 **/
dea31012005-04-17 16:05:31 -05002613static int
James Smart2e0fef82007-06-17 19:56:36 -05002614lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2615 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002616{
James Smart2e0fef82007-06-17 19:56:36 -05002617 struct lpfc_vport *vport = cmdiocb->vport;
2618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2619 IOCB_t *irsp = &rspiocb->iocb;
2620 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2621 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002622 uint32_t *elscmd;
2623 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002624 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002625 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002626 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002627 uint32_t did;
dea31012005-04-17 16:05:31 -05002628
James Smart488d1462006-03-07 15:02:37 -05002629
dea31012005-04-17 16:05:31 -05002630 /* Note: context2 may be 0 for internal driver abort
2631 * of delays ELS command.
2632 */
2633
2634 if (pcmd && pcmd->virt) {
2635 elscmd = (uint32_t *) (pcmd->virt);
2636 cmd = *elscmd++;
2637 }
2638
James Smarte47c9092008-02-08 18:49:26 -05002639 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002640 did = ndlp->nlp_DID;
2641 else {
2642 /* We should only hit this case for retrying PLOGI */
2643 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002644 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002645 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2646 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002647 return 1;
2648 }
2649
James Smart858c9f62007-06-17 19:56:39 -05002650 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2651 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2652 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2653
dea31012005-04-17 16:05:31 -05002654 switch (irsp->ulpStatus) {
2655 case IOSTAT_FCP_RSP_ERROR:
2656 case IOSTAT_REMOTE_STOP:
2657 break;
2658
2659 case IOSTAT_LOCAL_REJECT:
2660 switch ((irsp->un.ulpWord[4] & 0xff)) {
2661 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002662 if (cmd == ELS_CMD_FLOGI) {
2663 if (PCI_DEVICE_ID_HORNET ==
2664 phba->pcidev->device) {
2665 phba->fc_topology = TOPOLOGY_LOOP;
2666 phba->pport->fc_myDID = 0;
2667 phba->alpa_map[0] = 0;
2668 phba->alpa_map[1] = 0;
2669 }
2670 }
James Smart2e0fef82007-06-17 19:56:36 -05002671 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002672 delay = 1000;
dea31012005-04-17 16:05:31 -05002673 retry = 1;
2674 break;
2675
James Smart92d7f7b2007-06-17 19:56:38 -05002676 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002677 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2678 "0124 Retry illegal cmd x%x "
2679 "retry:x%x delay:x%x\n",
2680 cmd, cmdiocb->retry, delay);
2681 retry = 1;
2682 /* All command's retry policy */
2683 maxretry = 8;
2684 if (cmdiocb->retry > 2)
2685 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002686 break;
2687
dea31012005-04-17 16:05:31 -05002688 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002689 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002690 retry = 1;
2691 if (cmdiocb->retry > 100)
2692 delay = 100;
2693 maxretry = 250;
2694 break;
2695
2696 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002697 delay = 100;
dea31012005-04-17 16:05:31 -05002698 retry = 1;
2699 break;
2700
James Smart858c9f62007-06-17 19:56:39 -05002701 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002702 case IOERR_INVALID_RPI:
2703 retry = 1;
2704 break;
2705 }
2706 break;
2707
2708 case IOSTAT_NPORT_RJT:
2709 case IOSTAT_FABRIC_RJT:
2710 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2711 retry = 1;
2712 break;
2713 }
2714 break;
2715
2716 case IOSTAT_NPORT_BSY:
2717 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002718 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002719 retry = 1;
2720 break;
2721
2722 case IOSTAT_LS_RJT:
2723 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2724 /* Added for Vendor specifc support
2725 * Just keep retrying for these Rsn / Exp codes
2726 */
2727 switch (stat.un.b.lsRjtRsnCode) {
2728 case LSRJT_UNABLE_TPC:
2729 if (stat.un.b.lsRjtRsnCodeExp ==
2730 LSEXP_CMD_IN_PROGRESS) {
2731 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002732 delay = 1000;
dea31012005-04-17 16:05:31 -05002733 maxretry = 48;
2734 }
2735 retry = 1;
2736 break;
2737 }
2738 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002739 delay = 1000;
dea31012005-04-17 16:05:31 -05002740 maxretry = lpfc_max_els_tries + 1;
2741 retry = 1;
2742 break;
2743 }
James Smart92d7f7b2007-06-17 19:56:38 -05002744 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2745 (cmd == ELS_CMD_FDISC) &&
2746 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002747 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2748 "0125 FDISC Failed (x%x). "
2749 "Fabric out of resources\n",
2750 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002751 lpfc_vport_set_state(vport,
2752 FC_VPORT_NO_FABRIC_RSCS);
2753 }
dea31012005-04-17 16:05:31 -05002754 break;
2755
2756 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002757 if ((cmd == ELS_CMD_PLOGI) ||
2758 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002759 delay = 1000;
dea31012005-04-17 16:05:31 -05002760 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002761 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002762 /* FDISC retry policy */
2763 maxretry = 48;
2764 if (cmdiocb->retry >= 32)
2765 delay = 1000;
dea31012005-04-17 16:05:31 -05002766 }
2767 retry = 1;
2768 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002769
2770 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002771 /* There are some cases where switches return this
2772 * error when they are not ready and should be returning
2773 * Logical Busy. We should delay every time.
2774 */
2775 if (cmd == ELS_CMD_FDISC &&
2776 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2777 maxretry = 3;
2778 delay = 1000;
2779 retry = 1;
2780 break;
2781 }
James Smart92d7f7b2007-06-17 19:56:38 -05002782 case LSRJT_PROTOCOL_ERR:
2783 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2784 (cmd == ELS_CMD_FDISC) &&
2785 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2786 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2787 ) {
James Smarte8b62012007-08-02 11:10:09 -04002788 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002789 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002790 "Fabric Detected Bad WWN\n",
2791 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002792 lpfc_vport_set_state(vport,
2793 FC_VPORT_FABRIC_REJ_WWN);
2794 }
2795 break;
dea31012005-04-17 16:05:31 -05002796 }
2797 break;
2798
2799 case IOSTAT_INTERMED_RSP:
2800 case IOSTAT_BA_RJT:
2801 break;
2802
2803 default:
2804 break;
2805 }
2806
James Smart488d1462006-03-07 15:02:37 -05002807 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002808 retry = 1;
dea31012005-04-17 16:05:31 -05002809
James Smart695a8142010-01-26 23:08:03 -05002810 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002811 (phba->fc_topology != TOPOLOGY_LOOP) &&
2812 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002813 /* FLOGI retry policy */
2814 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002815 /* retry forever */
2816 maxretry = 0;
2817 if (cmdiocb->retry >= 100)
2818 delay = 5000;
2819 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002820 delay = 1000;
2821 }
2822
James Smart6669f9b2009-10-02 15:16:45 -04002823 cmdiocb->retry++;
2824 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002825 phba->fc_stat.elsRetryExceeded++;
2826 retry = 0;
2827 }
2828
James Smarted957682007-06-17 19:56:37 -05002829 if ((vport->load_flag & FC_UNLOADING) != 0)
2830 retry = 0;
2831
dea31012005-04-17 16:05:31 -05002832 if (retry) {
2833
2834 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002835 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2836 "0107 Retry ELS command x%x to remote "
2837 "NPORT x%x Data: x%x x%x\n",
2838 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002839
James Smart858c9f62007-06-17 19:56:39 -05002840 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2841 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2842 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2843 /* Don't reset timer for no resources */
2844
dea31012005-04-17 16:05:31 -05002845 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002846 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002847 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002848 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002849 }
2850
2851 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002852 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002853 phba->fc_stat.elsDelayRetry++;
2854 ndlp->nlp_retry = cmdiocb->retry;
2855
James Smart92d7f7b2007-06-17 19:56:38 -05002856 /* delay is specified in milliseconds */
2857 mod_timer(&ndlp->nlp_delayfunc,
2858 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002859 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002860 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002861 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002862
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002863 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002864 if (cmd == ELS_CMD_PRLI)
2865 lpfc_nlp_set_state(vport, ndlp,
2866 NLP_STE_REG_LOGIN_ISSUE);
2867 else
2868 lpfc_nlp_set_state(vport, ndlp,
2869 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002870 ndlp->nlp_last_elscmd = cmd;
2871
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002872 return 1;
dea31012005-04-17 16:05:31 -05002873 }
2874 switch (cmd) {
2875 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002876 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002877 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002878 case ELS_CMD_FDISC:
2879 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2880 return 1;
dea31012005-04-17 16:05:31 -05002881 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002882 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002883 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002884 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002885 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002886 }
James Smart2e0fef82007-06-17 19:56:36 -05002887 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002888 return 1;
dea31012005-04-17 16:05:31 -05002889 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002890 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002891 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2892 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002893 return 1;
dea31012005-04-17 16:05:31 -05002894 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002895 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002896 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2897 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002898 return 1;
dea31012005-04-17 16:05:31 -05002899 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002900 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002901 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2902 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002903 return 1;
dea31012005-04-17 16:05:31 -05002904 }
2905 }
dea31012005-04-17 16:05:31 -05002906 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002907 if (logerr) {
2908 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2909 "0137 No retry ELS command x%x to remote "
2910 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2911 cmd, did, irsp->ulpStatus,
2912 irsp->un.ulpWord[4]);
2913 }
2914 else {
2915 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002916 "0108 No retry ELS command x%x to remote "
2917 "NPORT x%x Retried:%d Error:x%x/%x\n",
2918 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2919 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002920 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002921 return 0;
dea31012005-04-17 16:05:31 -05002922}
2923
James Smarte59058c2008-08-24 21:49:00 -04002924/**
James Smart3621a712009-04-06 18:47:14 -04002925 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002926 * @phba: pointer to lpfc hba data structure.
2927 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2928 *
2929 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2930 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2931 * checks to see whether there is a lpfc DMA buffer associated with the
2932 * response of the command IOCB. If so, it will be released before releasing
2933 * the lpfc DMA buffer associated with the IOCB itself.
2934 *
2935 * Return code
2936 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2937 **/
James Smart09372822008-01-11 01:52:54 -05002938static int
James Smart87af33f2007-10-27 13:37:43 -04002939lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2940{
2941 struct lpfc_dmabuf *buf_ptr;
2942
James Smarte59058c2008-08-24 21:49:00 -04002943 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002944 if (!list_empty(&buf_ptr1->list)) {
2945 list_remove_head(&buf_ptr1->list, buf_ptr,
2946 struct lpfc_dmabuf,
2947 list);
2948 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2949 kfree(buf_ptr);
2950 }
2951 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2952 kfree(buf_ptr1);
2953 return 0;
2954}
2955
James Smarte59058c2008-08-24 21:49:00 -04002956/**
James Smart3621a712009-04-06 18:47:14 -04002957 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002958 * @phba: pointer to lpfc hba data structure.
2959 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2960 *
2961 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2962 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2963 * pool.
2964 *
2965 * Return code
2966 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2967 **/
James Smart09372822008-01-11 01:52:54 -05002968static int
James Smart87af33f2007-10-27 13:37:43 -04002969lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2970{
2971 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2972 kfree(buf_ptr);
2973 return 0;
2974}
2975
James Smarte59058c2008-08-24 21:49:00 -04002976/**
James Smart3621a712009-04-06 18:47:14 -04002977 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002978 * @phba: pointer to lpfc hba data structure.
2979 * @elsiocb: pointer to lpfc els command iocb data structure.
2980 *
2981 * This routine frees a command IOCB and its associated resources. The
2982 * command IOCB data structure contains the reference to various associated
2983 * resources, these fields must be set to NULL if the associated reference
2984 * not present:
2985 * context1 - reference to ndlp
2986 * context2 - reference to cmd
2987 * context2->next - reference to rsp
2988 * context3 - reference to bpl
2989 *
2990 * It first properly decrements the reference count held on ndlp for the
2991 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2992 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2993 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2994 * adds the DMA buffer the @phba data structure for the delayed release.
2995 * If reference to the Buffer Pointer List (BPL) is present, the
2996 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2997 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2998 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2999 *
3000 * Return code
3001 * 0 - Success (currently, always return 0)
3002 **/
James Smart87af33f2007-10-27 13:37:43 -04003003int
James Smart329f9bc2007-04-25 09:53:01 -04003004lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003005{
3006 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003007 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003008
James Smarta8adb832007-10-27 13:37:53 -04003009 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3010 if (ndlp) {
3011 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3012 lpfc_nlp_put(ndlp);
3013
3014 /* If the ndlp is not being used by another discovery
3015 * thread, free it.
3016 */
3017 if (!lpfc_nlp_not_used(ndlp)) {
3018 /* If ndlp is being used by another discovery
3019 * thread, just clear NLP_DEFER_RM
3020 */
3021 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3022 }
3023 }
3024 else
3025 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003026 elsiocb->context1 = NULL;
3027 }
dea31012005-04-17 16:05:31 -05003028 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3029 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003030 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3031 /* Firmware could still be in progress of DMAing
3032 * payload, so don't free data buffer till after
3033 * a hbeat.
3034 */
3035 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3036 buf_ptr = elsiocb->context2;
3037 elsiocb->context2 = NULL;
3038 if (buf_ptr) {
3039 buf_ptr1 = NULL;
3040 spin_lock_irq(&phba->hbalock);
3041 if (!list_empty(&buf_ptr->list)) {
3042 list_remove_head(&buf_ptr->list,
3043 buf_ptr1, struct lpfc_dmabuf,
3044 list);
3045 INIT_LIST_HEAD(&buf_ptr1->list);
3046 list_add_tail(&buf_ptr1->list,
3047 &phba->elsbuf);
3048 phba->elsbuf_cnt++;
3049 }
3050 INIT_LIST_HEAD(&buf_ptr->list);
3051 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3052 phba->elsbuf_cnt++;
3053 spin_unlock_irq(&phba->hbalock);
3054 }
3055 } else {
3056 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3057 lpfc_els_free_data(phba, buf_ptr1);
3058 }
dea31012005-04-17 16:05:31 -05003059 }
3060
3061 if (elsiocb->context3) {
3062 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003063 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003064 }
James Bottomley604a3e32005-10-29 10:28:33 -05003065 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003066 return 0;
3067}
3068
James Smarte59058c2008-08-24 21:49:00 -04003069/**
James Smart3621a712009-04-06 18:47:14 -04003070 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003071 * @phba: pointer to lpfc hba data structure.
3072 * @cmdiocb: pointer to lpfc command iocb data structure.
3073 * @rspiocb: pointer to lpfc response iocb data structure.
3074 *
3075 * This routine is the completion callback function to the Logout (LOGO)
3076 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3077 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3078 * release the ndlp if it has the last reference remaining (reference count
3079 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3080 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3081 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3082 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3083 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3084 * IOCB data structure.
3085 **/
dea31012005-04-17 16:05:31 -05003086static void
James Smart2e0fef82007-06-17 19:56:36 -05003087lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3088 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003089{
James Smart2e0fef82007-06-17 19:56:36 -05003090 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3091 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003092 IOCB_t *irsp;
3093
3094 irsp = &rspiocb->iocb;
3095 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3096 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3097 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003098 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003099 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3100 "0109 ACC to LOGO completes to NPort x%x "
3101 "Data: x%x x%x x%x\n",
3102 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3103 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003104
3105 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3106 /* NPort Recovery mode or node is just allocated */
3107 if (!lpfc_nlp_not_used(ndlp)) {
3108 /* If the ndlp is being used by another discovery
3109 * thread, just unregister the RPI.
3110 */
3111 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003112 } else {
3113 /* Indicate the node has already released, should
3114 * not reference to it from within lpfc_els_free_iocb.
3115 */
3116 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003117 }
dea31012005-04-17 16:05:31 -05003118 }
3119 lpfc_els_free_iocb(phba, cmdiocb);
3120 return;
3121}
3122
James Smarte59058c2008-08-24 21:49:00 -04003123/**
James Smart3621a712009-04-06 18:47:14 -04003124 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003125 * @phba: pointer to lpfc hba data structure.
3126 * @pmb: pointer to the driver internal queue element for mailbox command.
3127 *
3128 * This routine is the completion callback function for unregister default
3129 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3130 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3131 * decrements the ndlp reference count held for this completion callback
3132 * function. After that, it invokes the lpfc_nlp_not_used() to check
3133 * whether there is only one reference left on the ndlp. If so, it will
3134 * perform one more decrement and trigger the release of the ndlp.
3135 **/
James Smart858c9f62007-06-17 19:56:39 -05003136void
3137lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3138{
3139 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3140 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3141
James Smart6fb120a2009-05-22 14:52:59 -04003142 /*
3143 * This routine is used to register and unregister in previous SLI
3144 * modes.
3145 */
3146 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3147 (phba->sli_rev == LPFC_SLI_REV4))
3148 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3149
James Smart858c9f62007-06-17 19:56:39 -05003150 pmb->context1 = NULL;
3151 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3152 kfree(mp);
3153 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003154 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003155 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003156 /* This is the end of the default RPI cleanup logic for this
3157 * ndlp. If no other discovery threads are using this ndlp.
3158 * we should free all resources associated with it.
3159 */
3160 lpfc_nlp_not_used(ndlp);
3161 }
James Smart3772a992009-05-22 14:50:54 -04003162
James Smart858c9f62007-06-17 19:56:39 -05003163 return;
3164}
3165
James Smarte59058c2008-08-24 21:49:00 -04003166/**
James Smart3621a712009-04-06 18:47:14 -04003167 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003168 * @phba: pointer to lpfc hba data structure.
3169 * @cmdiocb: pointer to lpfc command iocb data structure.
3170 * @rspiocb: pointer to lpfc response iocb data structure.
3171 *
3172 * This routine is the completion callback function for ELS Response IOCB
3173 * command. In normal case, this callback function just properly sets the
3174 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3175 * field in the command IOCB is not NULL, the referred mailbox command will
3176 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3177 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3178 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3179 * routine shall be invoked trying to release the ndlp if no other threads
3180 * are currently referring it.
3181 **/
dea31012005-04-17 16:05:31 -05003182static void
James Smart858c9f62007-06-17 19:56:39 -05003183lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003184 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003185{
James Smart2e0fef82007-06-17 19:56:36 -05003186 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3187 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3188 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003189 IOCB_t *irsp;
3190 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003191 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003192 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003193 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003194
James Smart33ccf8d2006-08-17 11:57:58 -04003195 irsp = &rspiocb->iocb;
3196
dea31012005-04-17 16:05:31 -05003197 if (cmdiocb->context_un.mbox)
3198 mbox = cmdiocb->context_un.mbox;
3199
James Smartfa4066b2008-01-11 01:53:27 -05003200 /* First determine if this is a LS_RJT cmpl. Note, this callback
3201 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3202 */
James Smart87af33f2007-10-27 13:37:43 -04003203 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003204 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3205 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003206 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003207 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003208 */
3209 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3210 ls_rjt = 1;
3211 }
3212
dea31012005-04-17 16:05:31 -05003213 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003214 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003215 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003216 mp = (struct lpfc_dmabuf *) mbox->context1;
3217 if (mp) {
3218 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3219 kfree(mp);
3220 }
James Smart329f9bc2007-04-25 09:53:01 -04003221 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003222 }
James Smart58da1ff2008-04-07 10:15:56 -04003223 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3224 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003225 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003226 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003227 /* Indicate the node has already released,
3228 * should not reference to it from within
3229 * the routine lpfc_els_free_iocb.
3230 */
3231 cmdiocb->context1 = NULL;
3232 }
dea31012005-04-17 16:05:31 -05003233 goto out;
3234 }
3235
James Smart858c9f62007-06-17 19:56:39 -05003236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003237 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003238 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003239 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003240 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003241 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3242 "0110 ELS response tag x%x completes "
3243 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3244 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3245 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3246 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3247 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003248 if (mbox) {
3249 if ((rspiocb->iocb.ulpStatus == 0)
3250 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003251 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003252 /* Increment reference count to ndlp to hold the
3253 * reference to ndlp for the callback function.
3254 */
James Smart329f9bc2007-04-25 09:53:01 -04003255 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003256 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003257 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3258 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3259 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3260 }
3261 else {
3262 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3263 ndlp->nlp_prev_state = ndlp->nlp_state;
3264 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003265 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003266 }
James Smart0b727fe2007-10-27 13:37:25 -04003267 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003268 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003269 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003270 else
3271 /* Decrement the ndlp reference count we
3272 * set for this failed mailbox command.
3273 */
3274 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003275
3276 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3277 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3278 "0138 ELS rsp: Cannot issue reg_login for x%x "
3279 "Data: x%x x%x x%x\n",
3280 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3281 ndlp->nlp_rpi);
3282
James Smartfa4066b2008-01-11 01:53:27 -05003283 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003284 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003285 /* Indicate node has already been released,
3286 * should not reference to it from within
3287 * the routine lpfc_els_free_iocb.
3288 */
3289 cmdiocb->context1 = NULL;
3290 }
dea31012005-04-17 16:05:31 -05003291 } else {
James Smart858c9f62007-06-17 19:56:39 -05003292 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3293 if (!lpfc_error_lost_link(irsp) &&
3294 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003295 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003296 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003297 /* Indicate node has already been
3298 * released, should not reference
3299 * to it from within the routine
3300 * lpfc_els_free_iocb.
3301 */
3302 cmdiocb->context1 = NULL;
3303 }
dea31012005-04-17 16:05:31 -05003304 }
3305 }
James Smart14691152006-12-02 13:34:28 -05003306 mp = (struct lpfc_dmabuf *) mbox->context1;
3307 if (mp) {
3308 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3309 kfree(mp);
3310 }
3311 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003312 }
3313out:
James Smart58da1ff2008-04-07 10:15:56 -04003314 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003315 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003316 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003317 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003318
3319 /* If the node is not being used by another discovery thread,
3320 * and we are sending a reject, we are done with it.
3321 * Release driver reference count here and free associated
3322 * resources.
3323 */
3324 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003325 if (lpfc_nlp_not_used(ndlp))
3326 /* Indicate node has already been released,
3327 * should not reference to it from within
3328 * the routine lpfc_els_free_iocb.
3329 */
3330 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003331 }
James Smart87af33f2007-10-27 13:37:43 -04003332
dea31012005-04-17 16:05:31 -05003333 lpfc_els_free_iocb(phba, cmdiocb);
3334 return;
3335}
3336
James Smarte59058c2008-08-24 21:49:00 -04003337/**
James Smart3621a712009-04-06 18:47:14 -04003338 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003339 * @vport: pointer to a host virtual N_Port data structure.
3340 * @flag: the els command code to be accepted.
3341 * @oldiocb: pointer to the original lpfc command iocb data structure.
3342 * @ndlp: pointer to a node-list data structure.
3343 * @mbox: pointer to the driver internal queue element for mailbox command.
3344 *
3345 * This routine prepares and issues an Accept (ACC) response IOCB
3346 * command. It uses the @flag to properly set up the IOCB field for the
3347 * specific ACC response command to be issued and invokes the
3348 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3349 * @mbox pointer is passed in, it will be put into the context_un.mbox
3350 * field of the IOCB for the completion callback function to issue the
3351 * mailbox command to the HBA later when callback is invoked.
3352 *
3353 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3354 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3355 * will be stored into the context1 field of the IOCB for the completion
3356 * callback function to the corresponding response ELS IOCB command.
3357 *
3358 * Return code
3359 * 0 - Successfully issued acc response
3360 * 1 - Failed to issue acc response
3361 **/
dea31012005-04-17 16:05:31 -05003362int
James Smart2e0fef82007-06-17 19:56:36 -05003363lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3364 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003365 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003366{
James Smart2e0fef82007-06-17 19:56:36 -05003367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3368 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003369 IOCB_t *icmd;
3370 IOCB_t *oldcmd;
3371 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003372 struct lpfc_sli *psli;
3373 uint8_t *pcmd;
3374 uint16_t cmdsize;
3375 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003376 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003377
3378 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003379 oldcmd = &oldiocb->iocb;
3380
3381 switch (flag) {
3382 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003383 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003384 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3385 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003386 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003387 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003388 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003389 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003390 return 1;
dea31012005-04-17 16:05:31 -05003391 }
James Smart2e0fef82007-06-17 19:56:36 -05003392
dea31012005-04-17 16:05:31 -05003393 icmd = &elsiocb->iocb;
3394 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3395 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3396 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003397 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003398
3399 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3400 "Issue ACC: did:x%x flg:x%x",
3401 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003402 break;
3403 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003404 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003405 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3406 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003407 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003408 return 1;
James Smart488d1462006-03-07 15:02:37 -05003409
dea31012005-04-17 16:05:31 -05003410 icmd = &elsiocb->iocb;
3411 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3412 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3413
3414 if (mbox)
3415 elsiocb->context_un.mbox = mbox;
3416
3417 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003418 pcmd += sizeof(uint32_t);
3419 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003420
3421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3422 "Issue ACC PLOGI: did:x%x flg:x%x",
3423 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003424 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003425 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003426 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003427 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003428 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3429 if (!elsiocb)
3430 return 1;
3431
3432 icmd = &elsiocb->iocb;
3433 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3434 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3435
3436 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003437 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003438 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3439 els_pkt_ptr = (ELS_PKT *) pcmd;
3440 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003441
3442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3443 "Issue ACC PRLO: did:x%x flg:x%x",
3444 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003445 break;
dea31012005-04-17 16:05:31 -05003446 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003447 return 1;
dea31012005-04-17 16:05:31 -05003448 }
dea31012005-04-17 16:05:31 -05003449 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003450 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3451 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3452 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3453 elsiocb->iotag, elsiocb->iocb.ulpContext,
3454 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3455 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003456 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003457 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003458 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003459 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003460 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3461 } else {
James Smart858c9f62007-06-17 19:56:39 -05003462 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003463 }
3464
3465 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003466 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003467 if (rc == IOCB_ERROR) {
3468 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003469 return 1;
dea31012005-04-17 16:05:31 -05003470 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003471 return 0;
dea31012005-04-17 16:05:31 -05003472}
3473
James Smarte59058c2008-08-24 21:49:00 -04003474/**
James Smart3621a712009-04-06 18:47:14 -04003475 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003476 * @vport: pointer to a virtual N_Port data structure.
3477 * @rejectError:
3478 * @oldiocb: pointer to the original lpfc command iocb data structure.
3479 * @ndlp: pointer to a node-list data structure.
3480 * @mbox: pointer to the driver internal queue element for mailbox command.
3481 *
3482 * This routine prepares and issue an Reject (RJT) response IOCB
3483 * command. If a @mbox pointer is passed in, it will be put into the
3484 * context_un.mbox field of the IOCB for the completion callback function
3485 * to issue to the HBA later.
3486 *
3487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3489 * will be stored into the context1 field of the IOCB for the completion
3490 * callback function to the reject response ELS IOCB command.
3491 *
3492 * Return code
3493 * 0 - Successfully issued reject response
3494 * 1 - Failed to issue reject response
3495 **/
dea31012005-04-17 16:05:31 -05003496int
James Smart2e0fef82007-06-17 19:56:36 -05003497lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003498 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3499 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003500{
James Smart2e0fef82007-06-17 19:56:36 -05003501 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003502 IOCB_t *icmd;
3503 IOCB_t *oldcmd;
3504 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003505 struct lpfc_sli *psli;
3506 uint8_t *pcmd;
3507 uint16_t cmdsize;
3508 int rc;
3509
3510 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003511 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003512 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3513 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003514 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003515 return 1;
dea31012005-04-17 16:05:31 -05003516
3517 icmd = &elsiocb->iocb;
3518 oldcmd = &oldiocb->iocb;
3519 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3520 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3521
3522 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003523 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003524 *((uint32_t *) (pcmd)) = rejectError;
3525
James Smart51ef4c22007-08-02 11:10:31 -04003526 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003527 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003528
dea31012005-04-17 16:05:31 -05003529 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003530 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3531 "0129 Xmit ELS RJT x%x response tag x%x "
3532 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3533 "rpi x%x\n",
3534 rejectError, elsiocb->iotag,
3535 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3536 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3538 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3539 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3540
dea31012005-04-17 16:05:31 -05003541 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003542 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003543 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003544
dea31012005-04-17 16:05:31 -05003545 if (rc == IOCB_ERROR) {
3546 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003547 return 1;
dea31012005-04-17 16:05:31 -05003548 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003549 return 0;
dea31012005-04-17 16:05:31 -05003550}
3551
James Smarte59058c2008-08-24 21:49:00 -04003552/**
James Smart3621a712009-04-06 18:47:14 -04003553 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003554 * @vport: pointer to a virtual N_Port data structure.
3555 * @oldiocb: pointer to the original lpfc command iocb data structure.
3556 * @ndlp: pointer to a node-list data structure.
3557 *
3558 * This routine prepares and issues an Accept (ACC) response to Address
3559 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3560 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3561 *
3562 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3563 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3564 * will be stored into the context1 field of the IOCB for the completion
3565 * callback function to the ADISC Accept response ELS IOCB command.
3566 *
3567 * Return code
3568 * 0 - Successfully issued acc adisc response
3569 * 1 - Failed to issue adisc acc response
3570 **/
dea31012005-04-17 16:05:31 -05003571int
James Smart2e0fef82007-06-17 19:56:36 -05003572lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3573 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003574{
James Smart2e0fef82007-06-17 19:56:36 -05003575 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003576 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003577 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003578 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003579 uint8_t *pcmd;
3580 uint16_t cmdsize;
3581 int rc;
3582
James Smart92d7f7b2007-06-17 19:56:38 -05003583 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003584 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3585 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003586 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003587 return 1;
dea31012005-04-17 16:05:31 -05003588
dea31012005-04-17 16:05:31 -05003589 icmd = &elsiocb->iocb;
3590 oldcmd = &oldiocb->iocb;
3591 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003592
3593 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003594 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3595 "0130 Xmit ADISC ACC response iotag x%x xri: "
3596 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3597 elsiocb->iotag, elsiocb->iocb.ulpContext,
3598 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3599 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003600 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3601
3602 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003603 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003604
3605 ap = (ADISC *) (pcmd);
3606 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003607 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3608 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003609 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003610
James Smart858c9f62007-06-17 19:56:39 -05003611 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3612 "Issue ACC ADISC: did:x%x flg:x%x",
3613 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3614
dea31012005-04-17 16:05:31 -05003615 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003616 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003617 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003618 if (rc == IOCB_ERROR) {
3619 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003620 return 1;
dea31012005-04-17 16:05:31 -05003621 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003622 return 0;
dea31012005-04-17 16:05:31 -05003623}
3624
James Smarte59058c2008-08-24 21:49:00 -04003625/**
James Smart3621a712009-04-06 18:47:14 -04003626 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003627 * @vport: pointer to a virtual N_Port data structure.
3628 * @oldiocb: pointer to the original lpfc command iocb data structure.
3629 * @ndlp: pointer to a node-list data structure.
3630 *
3631 * This routine prepares and issues an Accept (ACC) response to Process
3632 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3633 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3634 *
3635 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3636 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3637 * will be stored into the context1 field of the IOCB for the completion
3638 * callback function to the PRLI Accept response ELS IOCB command.
3639 *
3640 * Return code
3641 * 0 - Successfully issued acc prli response
3642 * 1 - Failed to issue acc prli response
3643 **/
dea31012005-04-17 16:05:31 -05003644int
James Smart2e0fef82007-06-17 19:56:36 -05003645lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003646 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003647{
James Smart2e0fef82007-06-17 19:56:36 -05003648 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003649 PRLI *npr;
3650 lpfc_vpd_t *vpd;
3651 IOCB_t *icmd;
3652 IOCB_t *oldcmd;
3653 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003654 struct lpfc_sli *psli;
3655 uint8_t *pcmd;
3656 uint16_t cmdsize;
3657 int rc;
3658
3659 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003660
James Smart92d7f7b2007-06-17 19:56:38 -05003661 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003662 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003663 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003664 if (!elsiocb)
3665 return 1;
dea31012005-04-17 16:05:31 -05003666
dea31012005-04-17 16:05:31 -05003667 icmd = &elsiocb->iocb;
3668 oldcmd = &oldiocb->iocb;
3669 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003670 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3672 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3673 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3674 elsiocb->iotag, elsiocb->iocb.ulpContext,
3675 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3676 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003677 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3678
3679 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003680 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003681
3682 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003683 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003684
3685 npr = (PRLI *) pcmd;
3686 vpd = &phba->vpd;
3687 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003688 * If the remote port is a target and our firmware version is 3.20 or
3689 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003690 */
James Smart0d2b6b82008-06-14 22:52:47 -04003691 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3692 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003693 npr->ConfmComplAllowed = 1;
3694 npr->Retry = 1;
3695 npr->TaskRetryIdReq = 1;
3696 }
3697
3698 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3699 npr->estabImagePair = 1;
3700 npr->readXferRdyDis = 1;
3701 npr->ConfmComplAllowed = 1;
3702
3703 npr->prliType = PRLI_FCP_TYPE;
3704 npr->initiatorFunc = 1;
3705
James Smart858c9f62007-06-17 19:56:39 -05003706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3707 "Issue ACC PRLI: did:x%x flg:x%x",
3708 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3709
dea31012005-04-17 16:05:31 -05003710 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003711 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003712
James Smart3772a992009-05-22 14:50:54 -04003713 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003714 if (rc == IOCB_ERROR) {
3715 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003716 return 1;
dea31012005-04-17 16:05:31 -05003717 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003718 return 0;
dea31012005-04-17 16:05:31 -05003719}
3720
James Smarte59058c2008-08-24 21:49:00 -04003721/**
James Smart3621a712009-04-06 18:47:14 -04003722 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003723 * @vport: pointer to a virtual N_Port data structure.
3724 * @format: rnid command format.
3725 * @oldiocb: pointer to the original lpfc command iocb data structure.
3726 * @ndlp: pointer to a node-list data structure.
3727 *
3728 * This routine issues a Request Node Identification Data (RNID) Accept
3729 * (ACC) response. It constructs the RNID ACC response command according to
3730 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3731 * issue the response. Note that this command does not need to hold the ndlp
3732 * reference count for the callback. So, the ndlp reference count taken by
3733 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3734 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3735 * there is no ndlp reference available.
3736 *
3737 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3738 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3739 * will be stored into the context1 field of the IOCB for the completion
3740 * callback function. However, for the RNID Accept Response ELS command,
3741 * this is undone later by this routine after the IOCB is allocated.
3742 *
3743 * Return code
3744 * 0 - Successfully issued acc rnid response
3745 * 1 - Failed to issue acc rnid response
3746 **/
dea31012005-04-17 16:05:31 -05003747static int
James Smart2e0fef82007-06-17 19:56:36 -05003748lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003749 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003750{
James Smart2e0fef82007-06-17 19:56:36 -05003751 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003752 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003753 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003754 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003755 struct lpfc_sli *psli;
3756 uint8_t *pcmd;
3757 uint16_t cmdsize;
3758 int rc;
3759
3760 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003761 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3762 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003763 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003764 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003765
James Smart2e0fef82007-06-17 19:56:36 -05003766 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3767 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003768 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003769 return 1;
dea31012005-04-17 16:05:31 -05003770
dea31012005-04-17 16:05:31 -05003771 icmd = &elsiocb->iocb;
3772 oldcmd = &oldiocb->iocb;
3773 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003774 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003775 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3776 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3777 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003778 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003779 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003780 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003781
James Smart92d7f7b2007-06-17 19:56:38 -05003782 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003783 rn = (RNID *) (pcmd);
3784 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003785 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3786 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3787 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003788 switch (format) {
3789 case 0:
3790 rn->SpecificLen = 0;
3791 break;
3792 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003793 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003794 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003795 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003796 rn->un.topologyDisc.unitType = RNID_HBA;
3797 rn->un.topologyDisc.physPort = 0;
3798 rn->un.topologyDisc.attachedNodes = 0;
3799 break;
3800 default:
3801 rn->CommonLen = 0;
3802 rn->SpecificLen = 0;
3803 break;
3804 }
3805
James Smart858c9f62007-06-17 19:56:39 -05003806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3807 "Issue ACC RNID: did:x%x flg:x%x",
3808 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3809
dea31012005-04-17 16:05:31 -05003810 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003811 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003812 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003813 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3814 * it could be freed */
3815
James Smart3772a992009-05-22 14:50:54 -04003816 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003817 if (rc == IOCB_ERROR) {
3818 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003819 return 1;
dea31012005-04-17 16:05:31 -05003820 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003821 return 0;
dea31012005-04-17 16:05:31 -05003822}
3823
James Smarte59058c2008-08-24 21:49:00 -04003824/**
James Smart3621a712009-04-06 18:47:14 -04003825 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003826 * @vport: pointer to a host virtual N_Port data structure.
3827 *
3828 * This routine issues Address Discover (ADISC) ELS commands to those
3829 * N_Ports which are in node port recovery state and ADISC has not been issued
3830 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3831 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3832 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3833 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3834 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3835 * IOCBs quit for later pick up. On the other hand, after walking through
3836 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3837 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3838 * no more ADISC need to be sent.
3839 *
3840 * Return code
3841 * The number of N_Ports with adisc issued.
3842 **/
dea31012005-04-17 16:05:31 -05003843int
James Smart2e0fef82007-06-17 19:56:36 -05003844lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003845{
James Smart2e0fef82007-06-17 19:56:36 -05003846 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003847 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003848 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003849
James Smart685f0bf2007-04-25 09:53:08 -04003850 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003851 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003852 if (!NLP_CHK_NODE_ACT(ndlp))
3853 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003854 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3855 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3856 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003857 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003858 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003859 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003860 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003861 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3862 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003863 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003864 vport->num_disc_nodes++;
3865 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003866 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003867 spin_lock_irq(shost->host_lock);
3868 vport->fc_flag |= FC_NLP_MORE;
3869 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003870 break;
dea31012005-04-17 16:05:31 -05003871 }
3872 }
3873 }
3874 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003875 spin_lock_irq(shost->host_lock);
3876 vport->fc_flag &= ~FC_NLP_MORE;
3877 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003878 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003879 return sentadisc;
dea31012005-04-17 16:05:31 -05003880}
3881
James Smarte59058c2008-08-24 21:49:00 -04003882/**
James Smart3621a712009-04-06 18:47:14 -04003883 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003884 * @vport: pointer to a host virtual N_Port data structure.
3885 *
3886 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3887 * which are in node port recovery state, with a @vport. Each time an ELS
3888 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3889 * the per @vport number of discover count (num_disc_nodes) shall be
3890 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3891 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3892 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3893 * later pick up. On the other hand, after walking through all the ndlps with
3894 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3895 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3896 * PLOGI need to be sent.
3897 *
3898 * Return code
3899 * The number of N_Ports with plogi issued.
3900 **/
dea31012005-04-17 16:05:31 -05003901int
James Smart2e0fef82007-06-17 19:56:36 -05003902lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003903{
James Smart2e0fef82007-06-17 19:56:36 -05003904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003905 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003906 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003907
James Smart2e0fef82007-06-17 19:56:36 -05003908 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3909 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003910 if (!NLP_CHK_NODE_ACT(ndlp))
3911 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003912 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3913 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3914 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3915 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3916 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3918 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003919 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003920 vport->num_disc_nodes++;
3921 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003922 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003923 spin_lock_irq(shost->host_lock);
3924 vport->fc_flag |= FC_NLP_MORE;
3925 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003926 break;
dea31012005-04-17 16:05:31 -05003927 }
3928 }
3929 }
James Smart87af33f2007-10-27 13:37:43 -04003930 if (sentplogi) {
3931 lpfc_set_disctmo(vport);
3932 }
3933 else {
James Smart2e0fef82007-06-17 19:56:36 -05003934 spin_lock_irq(shost->host_lock);
3935 vport->fc_flag &= ~FC_NLP_MORE;
3936 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003937 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003938 return sentplogi;
dea31012005-04-17 16:05:31 -05003939}
3940
James Smarte59058c2008-08-24 21:49:00 -04003941/**
James Smart3621a712009-04-06 18:47:14 -04003942 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003943 * @vport: pointer to a host virtual N_Port data structure.
3944 *
3945 * This routine cleans up any Registration State Change Notification
3946 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3947 * @vport together with the host_lock is used to prevent multiple thread
3948 * trying to access the RSCN array on a same @vport at the same time.
3949 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003950void
James Smart2e0fef82007-06-17 19:56:36 -05003951lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003952{
James Smart2e0fef82007-06-17 19:56:36 -05003953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3954 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003955 int i;
3956
James Smart7f5f3d02008-02-08 18:50:14 -05003957 spin_lock_irq(shost->host_lock);
3958 if (vport->fc_rscn_flush) {
3959 /* Another thread is walking fc_rscn_id_list on this vport */
3960 spin_unlock_irq(shost->host_lock);
3961 return;
3962 }
3963 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3964 vport->fc_rscn_flush = 1;
3965 spin_unlock_irq(shost->host_lock);
3966
James Smart2e0fef82007-06-17 19:56:36 -05003967 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003968 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003969 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003970 }
James Smart2e0fef82007-06-17 19:56:36 -05003971 spin_lock_irq(shost->host_lock);
3972 vport->fc_rscn_id_cnt = 0;
3973 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3974 spin_unlock_irq(shost->host_lock);
3975 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003976 /* Indicate we are done walking this fc_rscn_id_list */
3977 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003978}
3979
James Smarte59058c2008-08-24 21:49:00 -04003980/**
James Smart3621a712009-04-06 18:47:14 -04003981 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003982 * @vport: pointer to a host virtual N_Port data structure.
3983 * @did: remote destination port identifier.
3984 *
3985 * This routine checks whether there is any pending Registration State
3986 * Configuration Notification (RSCN) to a @did on @vport.
3987 *
3988 * Return code
3989 * None zero - The @did matched with a pending rscn
3990 * 0 - not able to match @did with a pending rscn
3991 **/
dea31012005-04-17 16:05:31 -05003992int
James Smart2e0fef82007-06-17 19:56:36 -05003993lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003994{
3995 D_ID ns_did;
3996 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003997 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003998 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003999 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004000
4001 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004002
4003 /* Never match fabric nodes for RSCNs */
4004 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004005 return 0;
dea31012005-04-17 16:05:31 -05004006
4007 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004008 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004009 return did;
dea31012005-04-17 16:05:31 -05004010
James Smart7f5f3d02008-02-08 18:50:14 -05004011 spin_lock_irq(shost->host_lock);
4012 if (vport->fc_rscn_flush) {
4013 /* Another thread is walking fc_rscn_id_list on this vport */
4014 spin_unlock_irq(shost->host_lock);
4015 return 0;
4016 }
4017 /* Indicate we are walking fc_rscn_id_list on this vport */
4018 vport->fc_rscn_flush = 1;
4019 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004020 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004021 lp = vport->fc_rscn_id_list[i]->virt;
4022 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4023 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004024 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004025 rscn_did.un.word = be32_to_cpu(*lp++);
4026 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004027 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4028 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004029 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4030 && (ns_did.un.b.area == rscn_did.un.b.area)
4031 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004032 goto return_did_out;
dea31012005-04-17 16:05:31 -05004033 break;
James Smarteaf15d52008-12-04 22:39:29 -05004034 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004035 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4036 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004037 goto return_did_out;
dea31012005-04-17 16:05:31 -05004038 break;
James Smarteaf15d52008-12-04 22:39:29 -05004039 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004040 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004041 goto return_did_out;
dea31012005-04-17 16:05:31 -05004042 break;
James Smarteaf15d52008-12-04 22:39:29 -05004043 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004044 goto return_did_out;
dea31012005-04-17 16:05:31 -05004045 }
4046 }
James Smart92d7f7b2007-06-17 19:56:38 -05004047 }
James Smart7f5f3d02008-02-08 18:50:14 -05004048 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4049 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004050 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004051return_did_out:
4052 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4053 vport->fc_rscn_flush = 0;
4054 return did;
dea31012005-04-17 16:05:31 -05004055}
4056
James Smarte59058c2008-08-24 21:49:00 -04004057/**
James Smart3621a712009-04-06 18:47:14 -04004058 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004059 * @vport: pointer to a host virtual N_Port data structure.
4060 *
4061 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4062 * state machine for a @vport's nodes that are with pending RSCN (Registration
4063 * State Change Notification).
4064 *
4065 * Return code
4066 * 0 - Successful (currently alway return 0)
4067 **/
dea31012005-04-17 16:05:31 -05004068static int
James Smart2e0fef82007-06-17 19:56:36 -05004069lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004070{
James Smart685f0bf2007-04-25 09:53:08 -04004071 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004072
James Smart0d2b6b82008-06-14 22:52:47 -04004073 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004074 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004075 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004076 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4077 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004078 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004079 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004080 NLP_EVT_DEVICE_RECOVERY);
4081 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004082 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004083 return 0;
dea31012005-04-17 16:05:31 -05004084}
4085
James Smarte59058c2008-08-24 21:49:00 -04004086/**
James Smart3621a712009-04-06 18:47:14 -04004087 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004088 * @vport: pointer to a host virtual N_Port data structure.
4089 * @cmdiocb: pointer to lpfc command iocb data structure.
4090 *
4091 * lpfc_send_rscn_event sends an RSCN netlink event to management
4092 * applications.
4093 */
4094static void
4095lpfc_send_rscn_event(struct lpfc_vport *vport,
4096 struct lpfc_iocbq *cmdiocb)
4097{
4098 struct lpfc_dmabuf *pcmd;
4099 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4100 uint32_t *payload_ptr;
4101 uint32_t payload_len;
4102 struct lpfc_rscn_event_header *rscn_event_data;
4103
4104 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4105 payload_ptr = (uint32_t *) pcmd->virt;
4106 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4107
4108 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4109 payload_len, GFP_KERNEL);
4110 if (!rscn_event_data) {
4111 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4112 "0147 Failed to allocate memory for RSCN event\n");
4113 return;
4114 }
4115 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4116 rscn_event_data->payload_length = payload_len;
4117 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4118 payload_len);
4119
4120 fc_host_post_vendor_event(shost,
4121 fc_get_event_number(),
4122 sizeof(struct lpfc_els_event_header) + payload_len,
4123 (char *)rscn_event_data,
4124 LPFC_NL_VENDOR_ID);
4125
4126 kfree(rscn_event_data);
4127}
4128
4129/**
James Smart3621a712009-04-06 18:47:14 -04004130 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004131 * @vport: pointer to a host virtual N_Port data structure.
4132 * @cmdiocb: pointer to lpfc command iocb data structure.
4133 * @ndlp: pointer to a node-list data structure.
4134 *
4135 * This routine processes an unsolicited RSCN (Registration State Change
4136 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4137 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4138 * discover state machine is about to begin discovery, it just accepts the
4139 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4140 * contains N_Port IDs for other vports on this HBA, it just accepts the
4141 * RSCN and ignore processing it. If the state machine is in the recovery
4142 * state, the fc_rscn_id_list of this @vport is walked and the
4143 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4144 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4145 * routine is invoked to handle the RSCN event.
4146 *
4147 * Return code
4148 * 0 - Just sent the acc response
4149 * 1 - Sent the acc response and waited for name server completion
4150 **/
dea31012005-04-17 16:05:31 -05004151static int
James Smart2e0fef82007-06-17 19:56:36 -05004152lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004153 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004154{
James Smart2e0fef82007-06-17 19:56:36 -05004155 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4156 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004157 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004158 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004159 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004160 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004161 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004162 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004163 int i;
dea31012005-04-17 16:05:31 -05004164
4165 icmd = &cmdiocb->iocb;
4166 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4167 lp = (uint32_t *) pcmd->virt;
4168
James Smart92d7f7b2007-06-17 19:56:38 -05004169 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4170 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004171 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004172 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4173 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004174 vport->fc_flag, payload_len, *lp,
4175 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004176
4177 /* Send an RSCN event to the management application */
4178 lpfc_send_rscn_event(vport, cmdiocb);
4179
James Smartd2873e42006-08-18 17:46:43 -04004180 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004181 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004182 FCH_EVT_RSCN, lp[i]);
4183
dea31012005-04-17 16:05:31 -05004184 /* If we are about to begin discovery, just ACC the RSCN.
4185 * Discovery processing will satisfy it.
4186 */
James Smart2e0fef82007-06-17 19:56:36 -05004187 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4189 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4190 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4191
James Smart51ef4c22007-08-02 11:10:31 -04004192 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004193 return 0;
dea31012005-04-17 16:05:31 -05004194 }
4195
James Smart92d7f7b2007-06-17 19:56:38 -05004196 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4197 * just ACC and ignore it.
4198 */
4199 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004200 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004201 i = payload_len;
4202 datap = lp;
4203 while (i > 0) {
4204 nportid = *datap++;
4205 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4206 i -= sizeof(uint32_t);
4207 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004208 if (lpfc_find_vport_by_did(phba, nportid))
4209 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004210 }
4211 if (rscn_id == hba_id) {
4212 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004213 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004214 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004215 "Data: x%x x%x x%x x%x\n",
4216 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004217 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004218 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4219 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4220 ndlp->nlp_DID, vport->port_state,
4221 ndlp->nlp_flag);
4222
James Smart92d7f7b2007-06-17 19:56:38 -05004223 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004224 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004225 return 0;
4226 }
4227 }
4228
James Smart7f5f3d02008-02-08 18:50:14 -05004229 spin_lock_irq(shost->host_lock);
4230 if (vport->fc_rscn_flush) {
4231 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004232 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004233 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004234 /* Send back ACC */
4235 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004236 return 0;
4237 }
4238 /* Indicate we are walking fc_rscn_id_list on this vport */
4239 vport->fc_rscn_flush = 1;
4240 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004241 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004242 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004243 /* If we are already processing an RSCN, save the received
4244 * RSCN payload buffer, cmdiocb->context2 to process later.
4245 */
James Smart2e0fef82007-06-17 19:56:36 -05004246 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004247 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4248 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4249 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4250
James Smart09372822008-01-11 01:52:54 -05004251 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004252 vport->fc_flag |= FC_RSCN_DEFERRED;
4253 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004254 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004255 vport->fc_flag |= FC_RSCN_MODE;
4256 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004257 if (rscn_cnt) {
4258 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4259 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4260 }
4261 if ((rscn_cnt) &&
4262 (payload_len + length <= LPFC_BPL_SIZE)) {
4263 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004264 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004265 memcpy(((uint8_t *)cmd) + length, lp,
4266 payload_len);
4267 } else {
4268 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4269 vport->fc_rscn_id_cnt++;
4270 /* If we zero, cmdiocb->context2, the calling
4271 * routine will not try to free it.
4272 */
4273 cmdiocb->context2 = NULL;
4274 }
dea31012005-04-17 16:05:31 -05004275 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004276 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4277 "0235 Deferred RSCN "
4278 "Data: x%x x%x x%x\n",
4279 vport->fc_rscn_id_cnt, vport->fc_flag,
4280 vport->port_state);
dea31012005-04-17 16:05:31 -05004281 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004282 vport->fc_flag |= FC_RSCN_DISCOVERY;
4283 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004284 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004285 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4286 "0234 ReDiscovery RSCN "
4287 "Data: x%x x%x x%x\n",
4288 vport->fc_rscn_id_cnt, vport->fc_flag,
4289 vport->port_state);
dea31012005-04-17 16:05:31 -05004290 }
James Smart7f5f3d02008-02-08 18:50:14 -05004291 /* Indicate we are done walking fc_rscn_id_list on this vport */
4292 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004293 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004294 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004295 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004296 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004297 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004298 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004299 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004300 return 0;
dea31012005-04-17 16:05:31 -05004301 }
James Smart858c9f62007-06-17 19:56:39 -05004302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4303 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4304 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4305
James Smart2e0fef82007-06-17 19:56:36 -05004306 spin_lock_irq(shost->host_lock);
4307 vport->fc_flag |= FC_RSCN_MODE;
4308 spin_unlock_irq(shost->host_lock);
4309 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004310 /* Indicate we are done walking fc_rscn_id_list on this vport */
4311 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004312 /*
4313 * If we zero, cmdiocb->context2, the calling routine will
4314 * not try to free it.
4315 */
4316 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004317 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004318 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004319 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004320 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004321 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004322 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004323}
4324
James Smarte59058c2008-08-24 21:49:00 -04004325/**
James Smart3621a712009-04-06 18:47:14 -04004326 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004327 * @vport: pointer to a host virtual N_Port data structure.
4328 *
4329 * This routine handles the Registration State Configuration Notification
4330 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4331 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4332 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4333 * NameServer shall be issued. If CT command to the NameServer fails to be
4334 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4335 * RSCN activities with the @vport.
4336 *
4337 * Return code
4338 * 0 - Cleaned up rscn on the @vport
4339 * 1 - Wait for plogi to name server before proceed
4340 **/
dea31012005-04-17 16:05:31 -05004341int
James Smart2e0fef82007-06-17 19:56:36 -05004342lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004343{
4344 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004346
James Smart92d7f7b2007-06-17 19:56:38 -05004347 /* Ignore RSCN if the port is being torn down. */
4348 if (vport->load_flag & FC_UNLOADING) {
4349 lpfc_els_flush_rscn(vport);
4350 return 0;
4351 }
4352
dea31012005-04-17 16:05:31 -05004353 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004354 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004355
4356 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004357 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4358 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4359 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4360 vport->port_state);
dea31012005-04-17 16:05:31 -05004361
4362 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004363 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004364 vport->num_disc_nodes = 0;
4365
James Smart2e0fef82007-06-17 19:56:36 -05004366 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004367 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4368 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004369 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004370 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004371 /* Wait for NameServer query cmpl before we can
4372 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004373 return 1;
dea31012005-04-17 16:05:31 -05004374 } else {
4375 /* If login to NameServer does not exist, issue one */
4376 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004377 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004378 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004379 /* Wait for NameServer login cmpl before we can
4380 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004381 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004382
James Smarte47c9092008-02-08 18:49:26 -05004383 if (ndlp) {
4384 ndlp = lpfc_enable_node(vport, ndlp,
4385 NLP_STE_PLOGI_ISSUE);
4386 if (!ndlp) {
4387 lpfc_els_flush_rscn(vport);
4388 return 0;
4389 }
4390 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004391 } else {
James Smarte47c9092008-02-08 18:49:26 -05004392 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4393 if (!ndlp) {
4394 lpfc_els_flush_rscn(vport);
4395 return 0;
4396 }
James Smart2e0fef82007-06-17 19:56:36 -05004397 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004398 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004399 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004400 }
James Smarte47c9092008-02-08 18:49:26 -05004401 ndlp->nlp_type |= NLP_FABRIC;
4402 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4403 /* Wait for NameServer login cmpl before we can
4404 * continue
4405 */
4406 return 1;
dea31012005-04-17 16:05:31 -05004407 }
4408
James Smart2e0fef82007-06-17 19:56:36 -05004409 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004410 return 0;
dea31012005-04-17 16:05:31 -05004411}
4412
James Smarte59058c2008-08-24 21:49:00 -04004413/**
James Smart3621a712009-04-06 18:47:14 -04004414 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004415 * @vport: pointer to a host virtual N_Port data structure.
4416 * @cmdiocb: pointer to lpfc command iocb data structure.
4417 * @ndlp: pointer to a node-list data structure.
4418 *
4419 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4420 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4421 * point topology. As an unsolicited FLOGI should not be received in a loop
4422 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4423 * lpfc_check_sparm() routine is invoked to check the parameters in the
4424 * unsolicited FLOGI. If parameters validation failed, the routine
4425 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4426 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4427 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4428 * will initiate PLOGI. The higher lexicographical value party shall has
4429 * higher priority (as the winning port) and will initiate PLOGI and
4430 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4431 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4432 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4433 *
4434 * Return code
4435 * 0 - Successfully processed the unsolicited flogi
4436 * 1 - Failed to process the unsolicited flogi
4437 **/
dea31012005-04-17 16:05:31 -05004438static int
James Smart2e0fef82007-06-17 19:56:36 -05004439lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004440 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004441{
James Smart2e0fef82007-06-17 19:56:36 -05004442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4443 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004444 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4445 uint32_t *lp = (uint32_t *) pcmd->virt;
4446 IOCB_t *icmd = &cmdiocb->iocb;
4447 struct serv_parm *sp;
4448 LPFC_MBOXQ_t *mbox;
4449 struct ls_rjt stat;
4450 uint32_t cmd, did;
4451 int rc;
4452
4453 cmd = *lp++;
4454 sp = (struct serv_parm *) lp;
4455
4456 /* FLOGI received */
4457
James Smart2e0fef82007-06-17 19:56:36 -05004458 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004459
4460 if (phba->fc_topology == TOPOLOGY_LOOP) {
4461 /* We should never receive a FLOGI in loop mode, ignore it */
4462 did = icmd->un.elsreq64.remoteID;
4463
4464 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4465 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004466 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4467 "0113 An FLOGI ELS command x%x was "
4468 "received from DID x%x in Loop Mode\n",
4469 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004470 return 1;
dea31012005-04-17 16:05:31 -05004471 }
4472
4473 did = Fabric_DID;
4474
James Smart341af102010-01-26 23:07:37 -05004475 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004476 /* For a FLOGI we accept, then if our portname is greater
4477 * then the remote portname we initiate Nport login.
4478 */
4479
James Smart2e0fef82007-06-17 19:56:36 -05004480 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004481 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004482
4483 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004484 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4485 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004486 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004487
dea31012005-04-17 16:05:31 -05004488 lpfc_linkdown(phba);
4489 lpfc_init_link(phba, mbox,
4490 phba->cfg_topology,
4491 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004492 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004493 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004494 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004495 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004496 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004497 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004498 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004499 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004500 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004501 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004502 spin_lock_irq(shost->host_lock);
4503 vport->fc_flag |= FC_PT2PT_PLOGI;
4504 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004505 }
James Smart2e0fef82007-06-17 19:56:36 -05004506 spin_lock_irq(shost->host_lock);
4507 vport->fc_flag |= FC_PT2PT;
4508 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4509 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004510 } else {
4511 /* Reject this request because invalid parameters */
4512 stat.un.b.lsRjtRsvd0 = 0;
4513 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4514 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4515 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004516 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4517 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004518 return 1;
dea31012005-04-17 16:05:31 -05004519 }
4520
4521 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004522 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004523
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004524 return 0;
dea31012005-04-17 16:05:31 -05004525}
4526
James Smarte59058c2008-08-24 21:49:00 -04004527/**
James Smart3621a712009-04-06 18:47:14 -04004528 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004529 * @vport: pointer to a host virtual N_Port data structure.
4530 * @cmdiocb: pointer to lpfc command iocb data structure.
4531 * @ndlp: pointer to a node-list data structure.
4532 *
4533 * This routine processes Request Node Identification Data (RNID) IOCB
4534 * received as an ELS unsolicited event. Only when the RNID specified format
4535 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4536 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4537 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4538 * rejected by invoking the lpfc_els_rsp_reject() routine.
4539 *
4540 * Return code
4541 * 0 - Successfully processed rnid iocb (currently always return 0)
4542 **/
dea31012005-04-17 16:05:31 -05004543static int
James Smart2e0fef82007-06-17 19:56:36 -05004544lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4545 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004546{
4547 struct lpfc_dmabuf *pcmd;
4548 uint32_t *lp;
4549 IOCB_t *icmd;
4550 RNID *rn;
4551 struct ls_rjt stat;
4552 uint32_t cmd, did;
4553
4554 icmd = &cmdiocb->iocb;
4555 did = icmd->un.elsreq64.remoteID;
4556 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4557 lp = (uint32_t *) pcmd->virt;
4558
4559 cmd = *lp++;
4560 rn = (RNID *) lp;
4561
4562 /* RNID received */
4563
4564 switch (rn->Format) {
4565 case 0:
4566 case RNID_TOPOLOGY_DISC:
4567 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004568 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004569 break;
4570 default:
4571 /* Reject this request because format not supported */
4572 stat.un.b.lsRjtRsvd0 = 0;
4573 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4574 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4575 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004576 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4577 NULL);
dea31012005-04-17 16:05:31 -05004578 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004579 return 0;
dea31012005-04-17 16:05:31 -05004580}
4581
James Smarte59058c2008-08-24 21:49:00 -04004582/**
James Smart3621a712009-04-06 18:47:14 -04004583 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004584 * @vport: pointer to a host virtual N_Port data structure.
4585 * @cmdiocb: pointer to lpfc command iocb data structure.
4586 * @ndlp: pointer to a node-list data structure.
4587 *
4588 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4589 * received as an ELS unsolicited event. Currently, this function just invokes
4590 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4591 *
4592 * Return code
4593 * 0 - Successfully processed lirr iocb (currently always return 0)
4594 **/
dea31012005-04-17 16:05:31 -05004595static int
James Smart2e0fef82007-06-17 19:56:36 -05004596lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4597 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004598{
4599 struct ls_rjt stat;
4600
4601 /* For now, unconditionally reject this command */
4602 stat.un.b.lsRjtRsvd0 = 0;
4603 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4604 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4605 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004606 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004607 return 0;
4608}
4609
James Smarte59058c2008-08-24 21:49:00 -04004610/**
James Smart5ffc2662009-11-18 15:39:44 -05004611 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4612 * @vport: pointer to a host virtual N_Port data structure.
4613 * @cmdiocb: pointer to lpfc command iocb data structure.
4614 * @ndlp: pointer to a node-list data structure.
4615 *
4616 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4617 * received as an ELS unsolicited event. A request to RRQ shall only
4618 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4619 * Nx_Port N_Port_ID of the target Exchange is the same as the
4620 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4621 * not accepted, an LS_RJT with reason code "Unable to perform
4622 * command request" and reason code explanation "Invalid Originator
4623 * S_ID" shall be returned. For now, we just unconditionally accept
4624 * RRQ from the target.
4625 **/
4626static void
4627lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4628 struct lpfc_nodelist *ndlp)
4629{
4630 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4631}
4632
4633/**
James Smart3621a712009-04-06 18:47:14 -04004634 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004635 * @phba: pointer to lpfc hba data structure.
4636 * @pmb: pointer to the driver internal queue element for mailbox command.
4637 *
4638 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4639 * mailbox command. This callback function is to actually send the Accept
4640 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4641 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4642 * mailbox command, constructs the RPS response with the link statistics
4643 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4644 * response to the RPS.
4645 *
4646 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4647 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4648 * will be stored into the context1 field of the IOCB for the completion
4649 * callback function to the RPS Accept Response ELS IOCB command.
4650 *
4651 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004652static void
James Smart329f9bc2007-04-25 09:53:01 -04004653lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004654{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004655 MAILBOX_t *mb;
4656 IOCB_t *icmd;
4657 RPS_RSP *rps_rsp;
4658 uint8_t *pcmd;
4659 struct lpfc_iocbq *elsiocb;
4660 struct lpfc_nodelist *ndlp;
4661 uint16_t xri, status;
4662 uint32_t cmdsize;
4663
James Smart04c68492009-05-22 14:52:52 -04004664 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004665
4666 ndlp = (struct lpfc_nodelist *) pmb->context2;
4667 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004668 pmb->context1 = NULL;
4669 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004670
4671 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004672 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004673 return;
4674 }
4675
4676 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004677 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004678 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4679 lpfc_max_els_tries, ndlp,
4680 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004681
4682 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004683 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004684
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004685 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004686 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004687
4688 icmd = &elsiocb->iocb;
4689 icmd->ulpContext = xri;
4690
4691 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4692 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004693 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004694 rps_rsp = (RPS_RSP *)pcmd;
4695
4696 if (phba->fc_topology != TOPOLOGY_LOOP)
4697 status = 0x10;
4698 else
4699 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004700 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004701 status |= 0x4;
4702
4703 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004704 rps_rsp->portStatus = cpu_to_be16(status);
4705 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4706 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4707 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4708 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4709 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4710 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004711 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004712 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4713 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4714 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4715 elsiocb->iotag, elsiocb->iocb.ulpContext,
4716 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4717 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004718 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004719 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004720 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004721 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004722 return;
4723}
4724
James Smarte59058c2008-08-24 21:49:00 -04004725/**
James Smart3621a712009-04-06 18:47:14 -04004726 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004727 * @vport: pointer to a host virtual N_Port data structure.
4728 * @cmdiocb: pointer to lpfc command iocb data structure.
4729 * @ndlp: pointer to a node-list data structure.
4730 *
4731 * This routine processes Read Port Status (RPS) IOCB received as an
4732 * ELS unsolicited event. It first checks the remote port state. If the
4733 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4734 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4735 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4736 * for reading the HBA link statistics. It is for the callback function,
4737 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4738 * to actually sending out RPS Accept (ACC) response.
4739 *
4740 * Return codes
4741 * 0 - Successfully processed rps iocb (currently always return 0)
4742 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004743static int
James Smart2e0fef82007-06-17 19:56:36 -05004744lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4745 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004746{
James Smart2e0fef82007-06-17 19:56:36 -05004747 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004748 uint32_t *lp;
4749 uint8_t flag;
4750 LPFC_MBOXQ_t *mbox;
4751 struct lpfc_dmabuf *pcmd;
4752 RPS *rps;
4753 struct ls_rjt stat;
4754
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004755 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004756 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4757 /* reject the unsolicited RPS request and done with it */
4758 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004759
4760 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4761 lp = (uint32_t *) pcmd->virt;
4762 flag = (be32_to_cpu(*lp++) & 0xf);
4763 rps = (RPS *) lp;
4764
4765 if ((flag == 0) ||
4766 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004767 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004768 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004769
James Smart92d7f7b2007-06-17 19:56:38 -05004770 printk("Fix me....\n");
4771 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004772 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4773 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004774 lpfc_read_lnk_stat(phba, mbox);
4775 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004776 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004777 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004778 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004779 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004780 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004781 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004782 /* Mbox completion will send ELS Response */
4783 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004784 /* Decrement reference count used for the failed mbox
4785 * command.
4786 */
James Smart329f9bc2007-04-25 09:53:01 -04004787 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004788 mempool_free(mbox, phba->mbox_mem_pool);
4789 }
4790 }
James Smart90160e02008-08-24 21:49:45 -04004791
4792reject_out:
4793 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004794 stat.un.b.lsRjtRsvd0 = 0;
4795 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4796 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4797 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004798 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004799 return 0;
4800}
4801
James Smarte59058c2008-08-24 21:49:00 -04004802/**
James Smart3621a712009-04-06 18:47:14 -04004803 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004804 * @vport: pointer to a host virtual N_Port data structure.
4805 * @cmdsize: size of the ELS command.
4806 * @oldiocb: pointer to the original lpfc command iocb data structure.
4807 * @ndlp: pointer to a node-list data structure.
4808 *
4809 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4810 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4811 *
4812 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4813 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4814 * will be stored into the context1 field of the IOCB for the completion
4815 * callback function to the RPL Accept Response ELS command.
4816 *
4817 * Return code
4818 * 0 - Successfully issued ACC RPL ELS command
4819 * 1 - Failed to issue ACC RPL ELS command
4820 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004821static int
James Smart2e0fef82007-06-17 19:56:36 -05004822lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4823 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004824{
James Smart2e0fef82007-06-17 19:56:36 -05004825 struct lpfc_hba *phba = vport->phba;
4826 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004827 RPL_RSP rpl_rsp;
4828 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004829 uint8_t *pcmd;
4830
James Smart2e0fef82007-06-17 19:56:36 -05004831 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4832 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004833
James Smart488d1462006-03-07 15:02:37 -05004834 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004835 return 1;
James Smart488d1462006-03-07 15:02:37 -05004836
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004837 icmd = &elsiocb->iocb;
4838 oldcmd = &oldiocb->iocb;
4839 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4840
4841 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4842 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004843 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004844 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4845 pcmd += sizeof(uint16_t);
4846
4847 /* Setup the RPL ACC payload */
4848 rpl_rsp.listLen = be32_to_cpu(1);
4849 rpl_rsp.index = 0;
4850 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004851 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4852 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004853 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004854 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004855 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004856 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4857 "0120 Xmit ELS RPL ACC response tag x%x "
4858 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4859 "rpi x%x\n",
4860 elsiocb->iotag, elsiocb->iocb.ulpContext,
4861 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4862 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004863 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004864 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004865 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4866 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004867 lpfc_els_free_iocb(phba, elsiocb);
4868 return 1;
4869 }
4870 return 0;
4871}
4872
James Smarte59058c2008-08-24 21:49:00 -04004873/**
James Smart3621a712009-04-06 18:47:14 -04004874 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004875 * @vport: pointer to a host virtual N_Port data structure.
4876 * @cmdiocb: pointer to lpfc command iocb data structure.
4877 * @ndlp: pointer to a node-list data structure.
4878 *
4879 * This routine processes Read Port List (RPL) IOCB received as an ELS
4880 * unsolicited event. It first checks the remote port state. If the remote
4881 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4882 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4883 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4884 * to accept the RPL.
4885 *
4886 * Return code
4887 * 0 - Successfully processed rpl iocb (currently always return 0)
4888 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004889static int
James Smart2e0fef82007-06-17 19:56:36 -05004890lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4891 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004892{
4893 struct lpfc_dmabuf *pcmd;
4894 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004895 uint32_t maxsize;
4896 uint16_t cmdsize;
4897 RPL *rpl;
4898 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004899
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004900 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4901 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004902 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004903 stat.un.b.lsRjtRsvd0 = 0;
4904 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4905 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4906 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004907 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4908 NULL);
James Smart90160e02008-08-24 21:49:45 -04004909 /* rejected the unsolicited RPL request and done with it */
4910 return 0;
dea31012005-04-17 16:05:31 -05004911 }
4912
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004913 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4914 lp = (uint32_t *) pcmd->virt;
4915 rpl = (RPL *) (lp + 1);
4916
4917 maxsize = be32_to_cpu(rpl->maxsize);
4918
4919 /* We support only one port */
4920 if ((rpl->index == 0) &&
4921 ((maxsize == 0) ||
4922 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4923 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004924 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004925 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4926 }
James Smart2e0fef82007-06-17 19:56:36 -05004927 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004928
4929 return 0;
4930}
4931
James Smarte59058c2008-08-24 21:49:00 -04004932/**
James Smart3621a712009-04-06 18:47:14 -04004933 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004934 * @vport: pointer to a virtual N_Port data structure.
4935 * @cmdiocb: pointer to lpfc command iocb data structure.
4936 * @ndlp: pointer to a node-list data structure.
4937 *
4938 * This routine processes Fibre Channel Address Resolution Protocol
4939 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4940 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4941 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4942 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4943 * remote PortName is compared against the FC PortName stored in the @vport
4944 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4945 * compared against the FC NodeName stored in the @vport data structure.
4946 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4947 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4948 * invoked to send out FARP Response to the remote node. Before sending the
4949 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4950 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4951 * routine is invoked to log into the remote port first.
4952 *
4953 * Return code
4954 * 0 - Either the FARP Match Mode not supported or successfully processed
4955 **/
dea31012005-04-17 16:05:31 -05004956static int
James Smart2e0fef82007-06-17 19:56:36 -05004957lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4958 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004959{
4960 struct lpfc_dmabuf *pcmd;
4961 uint32_t *lp;
4962 IOCB_t *icmd;
4963 FARP *fp;
4964 uint32_t cmd, cnt, did;
4965
4966 icmd = &cmdiocb->iocb;
4967 did = icmd->un.elsreq64.remoteID;
4968 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4969 lp = (uint32_t *) pcmd->virt;
4970
4971 cmd = *lp++;
4972 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004973 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004974 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4975 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004976 /* We will only support match on WWPN or WWNN */
4977 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004978 return 0;
dea31012005-04-17 16:05:31 -05004979 }
4980
4981 cnt = 0;
4982 /* If this FARP command is searching for my portname */
4983 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004984 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004985 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004986 cnt = 1;
4987 }
4988
4989 /* If this FARP command is searching for my nodename */
4990 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004991 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004992 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004993 cnt = 1;
4994 }
4995
4996 if (cnt) {
4997 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4998 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4999 /* Log back into the node before sending the FARP. */
5000 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005001 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005002 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005003 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005004 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005005 }
5006
5007 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005008 if (fp->Rflags & FARP_REQUEST_FARPR)
5009 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005010 }
5011 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005012 return 0;
dea31012005-04-17 16:05:31 -05005013}
5014
James Smarte59058c2008-08-24 21:49:00 -04005015/**
James Smart3621a712009-04-06 18:47:14 -04005016 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005017 * @vport: pointer to a host virtual N_Port data structure.
5018 * @cmdiocb: pointer to lpfc command iocb data structure.
5019 * @ndlp: pointer to a node-list data structure.
5020 *
5021 * This routine processes Fibre Channel Address Resolution Protocol
5022 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5023 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5024 * the FARP response request.
5025 *
5026 * Return code
5027 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5028 **/
dea31012005-04-17 16:05:31 -05005029static int
James Smart2e0fef82007-06-17 19:56:36 -05005030lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5031 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005032{
5033 struct lpfc_dmabuf *pcmd;
5034 uint32_t *lp;
5035 IOCB_t *icmd;
5036 uint32_t cmd, did;
5037
5038 icmd = &cmdiocb->iocb;
5039 did = icmd->un.elsreq64.remoteID;
5040 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5041 lp = (uint32_t *) pcmd->virt;
5042
5043 cmd = *lp++;
5044 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005045 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5046 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005047 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005048 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005049
5050 return 0;
5051}
5052
James Smarte59058c2008-08-24 21:49:00 -04005053/**
James Smart3621a712009-04-06 18:47:14 -04005054 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005055 * @vport: pointer to a host virtual N_Port data structure.
5056 * @cmdiocb: pointer to lpfc command iocb data structure.
5057 * @fan_ndlp: pointer to a node-list data structure.
5058 *
5059 * This routine processes a Fabric Address Notification (FAN) IOCB
5060 * command received as an ELS unsolicited event. The FAN ELS command will
5061 * only be processed on a physical port (i.e., the @vport represents the
5062 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5063 * compared against those in the phba data structure. If any of those is
5064 * different, the lpfc_initial_flogi() routine is invoked to initialize
5065 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5066 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5067 * is invoked to register login to the fabric.
5068 *
5069 * Return code
5070 * 0 - Successfully processed fan iocb (currently always return 0).
5071 **/
dea31012005-04-17 16:05:31 -05005072static int
James Smart2e0fef82007-06-17 19:56:36 -05005073lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5074 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005075{
James Smart2e0fef82007-06-17 19:56:36 -05005076 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005077 uint32_t *lp;
5078 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005079
James Smart0d2b6b82008-06-14 22:52:47 -04005080 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5081 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5082 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005083 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005084 if ((vport == phba->pport) &&
5085 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005086 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005087 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005088 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005089 sizeof(struct lpfc_name)))) {
5090 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005091 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005092 } else {
5093 /* FAN verified - skip FLOGI */
5094 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005095 if (phba->sli_rev < LPFC_SLI_REV4)
5096 lpfc_issue_fabric_reglogin(vport);
5097 else
5098 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005099 }
dea31012005-04-17 16:05:31 -05005100 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005101 return 0;
dea31012005-04-17 16:05:31 -05005102}
5103
James Smarte59058c2008-08-24 21:49:00 -04005104/**
James Smart3621a712009-04-06 18:47:14 -04005105 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005106 * @ptr: holder for the timer function associated data.
5107 *
5108 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5109 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5110 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5111 * up the worker thread. It is for the worker thread to invoke the routine
5112 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5113 **/
dea31012005-04-17 16:05:31 -05005114void
5115lpfc_els_timeout(unsigned long ptr)
5116{
James Smart2e0fef82007-06-17 19:56:36 -05005117 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5118 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005119 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005120 unsigned long iflag;
5121
James Smart2e0fef82007-06-17 19:56:36 -05005122 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005123 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5124 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005125 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005126 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005127
James Smart5e9d9b82008-06-14 22:52:53 -04005128 if (!tmo_posted)
5129 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005130 return;
5131}
5132
James Smarte59058c2008-08-24 21:49:00 -04005133/**
James Smart3621a712009-04-06 18:47:14 -04005134 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005135 * @vport: pointer to a virtual N_Port data structure.
5136 *
5137 * This routine is the actual handler function that processes an ELS timeout
5138 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5139 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5140 * invoking the lpfc_sli_issue_abort_iotag() routine.
5141 **/
dea31012005-04-17 16:05:31 -05005142void
James Smart2e0fef82007-06-17 19:56:36 -05005143lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005144{
James Smart2e0fef82007-06-17 19:56:36 -05005145 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005146 struct lpfc_sli_ring *pring;
5147 struct lpfc_iocbq *tmp_iocb, *piocb;
5148 IOCB_t *cmd = NULL;
5149 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005150 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005151 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005152 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005153
James Smart2e0fef82007-06-17 19:56:36 -05005154 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005155 timeout = (uint32_t)(phba->fc_ratov << 1);
5156
5157 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005158
5159 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5160 cmd = &piocb->iocb;
5161
James Smart2e0fef82007-06-17 19:56:36 -05005162 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5163 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5164 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005165 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005166
5167 if (piocb->vport != vport)
5168 continue;
5169
dea31012005-04-17 16:05:31 -05005170 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005171 if (pcmd)
5172 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005173
James Smart92d7f7b2007-06-17 19:56:38 -05005174 if (els_command == ELS_CMD_FARP ||
5175 els_command == ELS_CMD_FARPR ||
5176 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005177 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005178
dea31012005-04-17 16:05:31 -05005179 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005180 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005181 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005182 else
dea31012005-04-17 16:05:31 -05005183 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005184 continue;
5185 }
5186
James Smart2e0fef82007-06-17 19:56:36 -05005187 remote_ID = 0xffffffff;
5188 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005189 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005190 else {
5191 struct lpfc_nodelist *ndlp;
5192 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005193 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005194 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005195 }
James Smarte8b62012007-08-02 11:10:09 -04005196 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5197 "0127 ELS timeout Data: x%x x%x x%x "
5198 "x%x\n", els_command,
5199 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005200 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005201 }
James Smart2e0fef82007-06-17 19:56:36 -05005202 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005203
James Smart2e0fef82007-06-17 19:56:36 -05005204 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5205 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005206}
5207
James Smarte59058c2008-08-24 21:49:00 -04005208/**
James Smart3621a712009-04-06 18:47:14 -04005209 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005210 * @vport: pointer to a host virtual N_Port data structure.
5211 *
5212 * This routine is used to clean up all the outstanding ELS commands on a
5213 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5214 * routine. After that, it walks the ELS transmit queue to remove all the
5215 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5216 * the IOCBs with a non-NULL completion callback function, the callback
5217 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5218 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5219 * callback function, the IOCB will simply be released. Finally, it walks
5220 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5221 * completion queue IOCB that is associated with the @vport and is not
5222 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5223 * part of the discovery state machine) out to HBA by invoking the
5224 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5225 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5226 * the IOCBs are aborted when this function returns.
5227 **/
dea31012005-04-17 16:05:31 -05005228void
James Smart2e0fef82007-06-17 19:56:36 -05005229lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005230{
James Smart2534ba72007-04-25 09:52:20 -04005231 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005232 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005233 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005234 struct lpfc_iocbq *tmp_iocb, *piocb;
5235 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005236
5237 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005238
James Smart2e0fef82007-06-17 19:56:36 -05005239 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005240 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5241 cmd = &piocb->iocb;
5242
5243 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5244 continue;
5245 }
5246
5247 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005248 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5249 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5250 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5251 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005252 continue;
dea31012005-04-17 16:05:31 -05005253
James Smart2e0fef82007-06-17 19:56:36 -05005254 if (piocb->vport != vport)
5255 continue;
5256
James Smart2534ba72007-04-25 09:52:20 -04005257 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005258 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005259 }
5260
5261 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005262 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5263 continue;
5264 }
dea31012005-04-17 16:05:31 -05005265
James Smart2e0fef82007-06-17 19:56:36 -05005266 if (piocb->vport != vport)
5267 continue;
5268
James Smart07951072007-04-25 09:51:38 -04005269 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005270 }
James Smart2e0fef82007-06-17 19:56:36 -05005271 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005272
James Smarta257bf92009-04-06 18:48:10 -04005273 /* Cancell all the IOCBs from the completions list */
5274 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5275 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005276
dea31012005-04-17 16:05:31 -05005277 return;
5278}
5279
James Smarte59058c2008-08-24 21:49:00 -04005280/**
James Smart3621a712009-04-06 18:47:14 -04005281 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005282 * @phba: pointer to lpfc hba data structure.
5283 *
5284 * This routine is used to clean up all the outstanding ELS commands on a
5285 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5286 * routine. After that, it walks the ELS transmit queue to remove all the
5287 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5288 * the IOCBs with the completion callback function associated, the callback
5289 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5290 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5291 * callback function associated, the IOCB will simply be released. Finally,
5292 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5293 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5294 * management plane IOCBs that are not part of the discovery state machine)
5295 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5296 **/
James Smart549e55c2007-08-02 11:09:51 -04005297void
5298lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5299{
5300 LIST_HEAD(completions);
5301 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5302 struct lpfc_iocbq *tmp_iocb, *piocb;
5303 IOCB_t *cmd = NULL;
5304
5305 lpfc_fabric_abort_hba(phba);
5306 spin_lock_irq(&phba->hbalock);
5307 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5308 cmd = &piocb->iocb;
5309 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5310 continue;
5311 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5312 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5313 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5314 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5315 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5316 continue;
5317 list_move_tail(&piocb->list, &completions);
5318 pring->txq_cnt--;
5319 }
5320 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5321 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5322 continue;
5323 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5324 }
5325 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005326
5327 /* Cancel all the IOCBs from the completions list */
5328 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5329 IOERR_SLI_ABORTED);
5330
James Smart549e55c2007-08-02 11:09:51 -04005331 return;
5332}
5333
James Smarte59058c2008-08-24 21:49:00 -04005334/**
James Smart3621a712009-04-06 18:47:14 -04005335 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005336 * @phba: Pointer to hba context object.
5337 * @cmdiocbp: Pointer to command iocb which reported error.
5338 * @rspiocbp: Pointer to response iocb which reported error.
5339 *
5340 * This function sends an event when there is an ELS command
5341 * failure.
5342 **/
5343void
5344lpfc_send_els_failure_event(struct lpfc_hba *phba,
5345 struct lpfc_iocbq *cmdiocbp,
5346 struct lpfc_iocbq *rspiocbp)
5347{
5348 struct lpfc_vport *vport = cmdiocbp->vport;
5349 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5350 struct lpfc_lsrjt_event lsrjt_event;
5351 struct lpfc_fabric_event_header fabric_event;
5352 struct ls_rjt stat;
5353 struct lpfc_nodelist *ndlp;
5354 uint32_t *pcmd;
5355
5356 ndlp = cmdiocbp->context1;
5357 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5358 return;
5359
5360 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5361 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5362 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5363 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5364 sizeof(struct lpfc_name));
5365 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5366 sizeof(struct lpfc_name));
5367 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5368 cmdiocbp->context2)->virt);
5369 lsrjt_event.command = *pcmd;
5370 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5371 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5372 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5373 fc_host_post_vendor_event(shost,
5374 fc_get_event_number(),
5375 sizeof(lsrjt_event),
5376 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005377 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005378 return;
5379 }
5380 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5381 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5382 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5383 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5384 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5385 else
5386 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5387 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5388 sizeof(struct lpfc_name));
5389 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5390 sizeof(struct lpfc_name));
5391 fc_host_post_vendor_event(shost,
5392 fc_get_event_number(),
5393 sizeof(fabric_event),
5394 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005395 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005396 return;
5397 }
5398
5399}
5400
5401/**
James Smart3621a712009-04-06 18:47:14 -04005402 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005403 * @vport: Pointer to vport object.
5404 * @ndlp: Pointer FC node object.
5405 * @cmd: ELS command code.
5406 *
5407 * This function posts an event when there is an incoming
5408 * unsolicited ELS command.
5409 **/
5410static void
5411lpfc_send_els_event(struct lpfc_vport *vport,
5412 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005413 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005414{
James Smartddcc50f2008-12-04 22:38:46 -05005415 struct lpfc_els_event_header *els_data = NULL;
5416 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5418
James Smartddcc50f2008-12-04 22:38:46 -05005419 if (*payload == ELS_CMD_LOGO) {
5420 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5421 if (!logo_data) {
5422 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5423 "0148 Failed to allocate memory "
5424 "for LOGO event\n");
5425 return;
5426 }
5427 els_data = &logo_data->header;
5428 } else {
5429 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5430 GFP_KERNEL);
5431 if (!els_data) {
5432 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5433 "0149 Failed to allocate memory "
5434 "for ELS event\n");
5435 return;
5436 }
5437 }
5438 els_data->event_type = FC_REG_ELS_EVENT;
5439 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005440 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005441 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005442 break;
5443 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005444 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005445 break;
5446 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005447 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5448 break;
5449 case ELS_CMD_LOGO:
5450 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5451 /* Copy the WWPN in the LOGO payload */
5452 memcpy(logo_data->logo_wwpn, &payload[2],
5453 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005454 break;
5455 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005456 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005457 return;
5458 }
James Smartddcc50f2008-12-04 22:38:46 -05005459 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5460 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5461 if (*payload == ELS_CMD_LOGO) {
5462 fc_host_post_vendor_event(shost,
5463 fc_get_event_number(),
5464 sizeof(struct lpfc_logo_event),
5465 (char *)logo_data,
5466 LPFC_NL_VENDOR_ID);
5467 kfree(logo_data);
5468 } else {
5469 fc_host_post_vendor_event(shost,
5470 fc_get_event_number(),
5471 sizeof(struct lpfc_els_event_header),
5472 (char *)els_data,
5473 LPFC_NL_VENDOR_ID);
5474 kfree(els_data);
5475 }
James Smartea2151b2008-09-07 11:52:10 -04005476
5477 return;
5478}
5479
5480
5481/**
James Smart3621a712009-04-06 18:47:14 -04005482 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005483 * @phba: pointer to lpfc hba data structure.
5484 * @pring: pointer to a SLI ring.
5485 * @vport: pointer to a host virtual N_Port data structure.
5486 * @elsiocb: pointer to lpfc els command iocb data structure.
5487 *
5488 * This routine is used for processing the IOCB associated with a unsolicited
5489 * event. It first determines whether there is an existing ndlp that matches
5490 * the DID from the unsolicited IOCB. If not, it will create a new one with
5491 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5492 * IOCB is then used to invoke the proper routine and to set up proper state
5493 * of the discovery state machine.
5494 **/
James Smarted957682007-06-17 19:56:37 -05005495static void
5496lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005497 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005498{
James Smart87af33f2007-10-27 13:37:43 -04005499 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005500 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005501 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005502 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005503 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005504 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005505
James Smarte47c9092008-02-08 18:49:26 -05005506 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005507 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005508
dea31012005-04-17 16:05:31 -05005509 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005510 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5511 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005512 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005513 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005514
James Smart858c9f62007-06-17 19:56:39 -05005515 did = icmd->un.rcvels.remoteID;
5516 if (icmd->ulpStatus) {
5517 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5518 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5519 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005520 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005521 }
dea31012005-04-17 16:05:31 -05005522
5523 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005524 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005525 goto dropit;
dea31012005-04-17 16:05:31 -05005526
James Smartc8685952009-11-18 15:39:16 -05005527 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005528 if (vport->load_flag & FC_UNLOADING)
5529 goto dropit;
5530
James Smart2e0fef82007-06-17 19:56:36 -05005531 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005532 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005533 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005534 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005535 if (!ndlp)
dea31012005-04-17 16:05:31 -05005536 goto dropit;
dea31012005-04-17 16:05:31 -05005537
James Smart2e0fef82007-06-17 19:56:36 -05005538 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005539 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005540 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005541 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005542 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005543 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5544 ndlp = lpfc_enable_node(vport, ndlp,
5545 NLP_STE_UNUSED_NODE);
5546 if (!ndlp)
5547 goto dropit;
5548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5549 newnode = 1;
5550 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5551 ndlp->nlp_type |= NLP_FABRIC;
5552 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5553 /* This is similar to the new node path */
5554 ndlp = lpfc_nlp_get(ndlp);
5555 if (!ndlp)
5556 goto dropit;
5557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5558 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005559 }
dea31012005-04-17 16:05:31 -05005560
5561 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005562
James Smart329f9bc2007-04-25 09:53:01 -04005563 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005564 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005565
5566 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5567 cmd &= ELS_CMD_MASK;
5568 }
5569 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005570 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5571 "0112 ELS command x%x received from NPORT x%x "
5572 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005573 switch (cmd) {
5574 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5576 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5577 did, vport->port_state, ndlp->nlp_flag);
5578
dea31012005-04-17 16:05:31 -05005579 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005580 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5581
James Smartddcc50f2008-12-04 22:38:46 -05005582 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005583 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005584 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5585 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5586 rjt_err = LSRJT_UNABLE_TPC;
5587 break;
5588 }
5589 /* We get here, and drop thru, if we are PT2PT with
5590 * another NPort and the other side has initiated
5591 * the PLOGI before responding to our FLOGI.
5592 */
dea31012005-04-17 16:05:31 -05005593 }
James Smart87af33f2007-10-27 13:37:43 -04005594
5595 shost = lpfc_shost_from_vport(vport);
5596 spin_lock_irq(shost->host_lock);
5597 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5598 spin_unlock_irq(shost->host_lock);
5599
James Smart2e0fef82007-06-17 19:56:36 -05005600 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5601 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005602
dea31012005-04-17 16:05:31 -05005603 break;
5604 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005605 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5606 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5607 did, vport->port_state, ndlp->nlp_flag);
5608
dea31012005-04-17 16:05:31 -05005609 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005610 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005611 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005612 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005613 break;
5614 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5616 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5617 did, vport->port_state, ndlp->nlp_flag);
5618
dea31012005-04-17 16:05:31 -05005619 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005620 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005621 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005622 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005623 break;
5624 }
James Smart2e0fef82007-06-17 19:56:36 -05005625 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005626 break;
5627 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005628 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5629 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5630 did, vport->port_state, ndlp->nlp_flag);
5631
dea31012005-04-17 16:05:31 -05005632 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005633 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005634 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005635 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005636 break;
5637 }
James Smart2e0fef82007-06-17 19:56:36 -05005638 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005639 break;
5640 case ELS_CMD_RSCN:
5641 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005642 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005643 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005644 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005645 break;
5646 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005647 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5648 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5649 did, vport->port_state, ndlp->nlp_flag);
5650
James Smartddcc50f2008-12-04 22:38:46 -05005651 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005652 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005653 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005654 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005655 break;
5656 }
James Smart2e0fef82007-06-17 19:56:36 -05005657 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5658 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005659 break;
5660 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5662 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5663 did, vport->port_state, ndlp->nlp_flag);
5664
dea31012005-04-17 16:05:31 -05005665 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005666 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005667 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005668 break;
5669 }
James Smart2e0fef82007-06-17 19:56:36 -05005670 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5671 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005672 break;
5673 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5675 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5676 did, vport->port_state, ndlp->nlp_flag);
5677
dea31012005-04-17 16:05:31 -05005678 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005679 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005680 break;
5681 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005682 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5683 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5684 did, vport->port_state, ndlp->nlp_flag);
5685
dea31012005-04-17 16:05:31 -05005686 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005687 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005688 break;
5689 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005690 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5691 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5692 did, vport->port_state, ndlp->nlp_flag);
5693
dea31012005-04-17 16:05:31 -05005694 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005695 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005696 break;
dea31012005-04-17 16:05:31 -05005697 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005698 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5699 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5700 did, vport->port_state, ndlp->nlp_flag);
5701
dea31012005-04-17 16:05:31 -05005702 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005703 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005704 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005705 break;
5706 }
James Smart2e0fef82007-06-17 19:56:36 -05005707 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005708 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005709 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5711 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5712 did, vport->port_state, ndlp->nlp_flag);
5713
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005714 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005715 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005716 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005717 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005718 break;
5719 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005720 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5721 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5722 did, vport->port_state, ndlp->nlp_flag);
5723
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005724 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005725 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005726 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005727 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005728 break;
5729 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005730 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5731 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5732 did, vport->port_state, ndlp->nlp_flag);
5733
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005734 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005735 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005736 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005737 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005738 break;
dea31012005-04-17 16:05:31 -05005739 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005740 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5741 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5742 did, vport->port_state, ndlp->nlp_flag);
5743
dea31012005-04-17 16:05:31 -05005744 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005745 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005746 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005747 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005748 break;
James Smart5ffc2662009-11-18 15:39:44 -05005749 case ELS_CMD_RRQ:
5750 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5751 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5752 did, vport->port_state, ndlp->nlp_flag);
5753
5754 phba->fc_stat.elsRcvRRQ++;
5755 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5756 if (newnode)
5757 lpfc_nlp_put(ndlp);
5758 break;
dea31012005-04-17 16:05:31 -05005759 default:
James Smart858c9f62007-06-17 19:56:39 -05005760 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5761 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5762 cmd, did, vport->port_state);
5763
dea31012005-04-17 16:05:31 -05005764 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005765 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005766
5767 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005768 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5769 "0115 Unknown ELS command x%x "
5770 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005771 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005772 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005773 break;
5774 }
5775
5776 /* check if need to LS_RJT received ELS cmd */
5777 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005778 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005779 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005780 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005781 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5782 NULL);
dea31012005-04-17 16:05:31 -05005783 }
5784
James Smartd7c255b2008-08-24 21:50:00 -04005785 lpfc_nlp_put(elsiocb->context1);
5786 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005787 return;
5788
5789dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005790 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005791 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5792 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005793 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005794 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005795 phba->fc_stat.elsRcvDrop++;
5796}
5797
James Smarte59058c2008-08-24 21:49:00 -04005798/**
James Smart3621a712009-04-06 18:47:14 -04005799 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005800 * @phba: pointer to lpfc hba data structure.
5801 * @vpi: host virtual N_Port identifier.
5802 *
5803 * This routine finds a vport on a HBA (referred by @phba) through a
5804 * @vpi. The function walks the HBA's vport list and returns the address
5805 * of the vport with the matching @vpi.
5806 *
5807 * Return code
5808 * NULL - No vport with the matching @vpi found
5809 * Otherwise - Address to the vport with the matching @vpi.
5810 **/
James Smart6669f9b2009-10-02 15:16:45 -04005811struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005812lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5813{
5814 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005815 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005816
James Smart549e55c2007-08-02 11:09:51 -04005817 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005818 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005819 if (vport->vpi == vpi) {
5820 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005821 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005822 }
James Smart92d7f7b2007-06-17 19:56:38 -05005823 }
James Smart549e55c2007-08-02 11:09:51 -04005824 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005825 return NULL;
5826}
James Smarted957682007-06-17 19:56:37 -05005827
James Smarte59058c2008-08-24 21:49:00 -04005828/**
James Smart3621a712009-04-06 18:47:14 -04005829 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005830 * @phba: pointer to lpfc hba data structure.
5831 * @pring: pointer to a SLI ring.
5832 * @elsiocb: pointer to lpfc els iocb data structure.
5833 *
5834 * This routine is used to process an unsolicited event received from a SLI
5835 * (Service Level Interface) ring. The actual processing of the data buffer
5836 * associated with the unsolicited event is done by invoking the routine
5837 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5838 * SLI ring on which the unsolicited event was received.
5839 **/
James Smarted957682007-06-17 19:56:37 -05005840void
5841lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5842 struct lpfc_iocbq *elsiocb)
5843{
5844 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005845 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005846 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005847 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5848 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005849
James Smartd7c255b2008-08-24 21:50:00 -04005850 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005851 elsiocb->context2 = NULL;
5852 elsiocb->context3 = NULL;
5853
5854 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5855 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5856 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5857 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005858 phba->fc_stat.NoRcvBuf++;
5859 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005860 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005861 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005862 return;
5863 }
5864
James Smart92d7f7b2007-06-17 19:56:38 -05005865 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5866 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5867 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5868 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5869 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005870 else
5871 vport = lpfc_find_vport_by_vpid(phba,
5872 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005873 }
James Smart7f5f3d02008-02-08 18:50:14 -05005874 /* If there are no BDEs associated
5875 * with this IOCB, there is nothing to do.
5876 */
James Smarted957682007-06-17 19:56:37 -05005877 if (icmd->ulpBdeCount == 0)
5878 return;
5879
James Smart7f5f3d02008-02-08 18:50:14 -05005880 /* type of ELS cmd is first 32bit word
5881 * in packet
5882 */
James Smarted957682007-06-17 19:56:37 -05005883 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005884 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005885 } else {
5886 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5887 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005888 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5889 paddr);
James Smarted957682007-06-17 19:56:37 -05005890 }
5891
James Smart92d7f7b2007-06-17 19:56:38 -05005892 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5893 /*
5894 * The different unsolicited event handlers would tell us
5895 * if they are done with "mp" by setting context2 to NULL.
5896 */
dea31012005-04-17 16:05:31 -05005897 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005898 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5899 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005900 }
James Smarted957682007-06-17 19:56:37 -05005901
5902 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005903 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005904 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005905 elsiocb->context2 = bdeBuf2;
5906 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005907 /* free mp if we are done with it */
5908 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005909 lpfc_in_buf_free(phba, elsiocb->context2);
5910 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005911 }
dea31012005-04-17 16:05:31 -05005912 }
dea31012005-04-17 16:05:31 -05005913}
James Smart92d7f7b2007-06-17 19:56:38 -05005914
James Smarte59058c2008-08-24 21:49:00 -04005915/**
James Smart3621a712009-04-06 18:47:14 -04005916 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005917 * @phba: pointer to lpfc hba data structure.
5918 * @vport: pointer to a virtual N_Port data structure.
5919 *
5920 * This routine issues a Port Login (PLOGI) to the Name Server with
5921 * State Change Request (SCR) for a @vport. This routine will create an
5922 * ndlp for the Name Server associated to the @vport if such node does
5923 * not already exist. The PLOGI to Name Server is issued by invoking the
5924 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5925 * (FDMI) is configured to the @vport, a FDMI node will be created and
5926 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5927 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005928void
5929lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5930{
5931 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5932
5933 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5934 if (!ndlp) {
5935 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5936 if (!ndlp) {
5937 if (phba->fc_topology == TOPOLOGY_LOOP) {
5938 lpfc_disc_start(vport);
5939 return;
5940 }
5941 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005942 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5943 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005944 return;
5945 }
5946 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005947 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5948 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5949 if (!ndlp) {
5950 if (phba->fc_topology == TOPOLOGY_LOOP) {
5951 lpfc_disc_start(vport);
5952 return;
5953 }
5954 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5955 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5956 "0348 NameServer login: node freed\n");
5957 return;
5958 }
James Smart92d7f7b2007-06-17 19:56:38 -05005959 }
James Smart58da1ff2008-04-07 10:15:56 -04005960 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005961
5962 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5963
5964 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5965 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005966 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5967 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005968 return;
5969 }
5970
James Smart3de2a652007-08-02 11:09:59 -04005971 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005972 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5973 GFP_KERNEL);
5974 if (ndlp_fdmi) {
5975 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5976 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005977 lpfc_nlp_set_state(vport, ndlp_fdmi,
5978 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005979 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5980 0);
5981 }
5982 }
5983 return;
5984}
5985
James Smarte59058c2008-08-24 21:49:00 -04005986/**
James Smart3621a712009-04-06 18:47:14 -04005987 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005988 * @phba: pointer to lpfc hba data structure.
5989 * @pmb: pointer to the driver internal queue element for mailbox command.
5990 *
5991 * This routine is the completion callback function to register new vport
5992 * mailbox command. If the new vport mailbox command completes successfully,
5993 * the fabric registration login shall be performed on physical port (the
5994 * new vport created is actually a physical port, with VPI 0) or the port
5995 * login to Name Server for State Change Request (SCR) will be performed
5996 * on virtual port (real virtual port, with VPI greater than 0).
5997 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005998static void
5999lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6000{
6001 struct lpfc_vport *vport = pmb->vport;
6002 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6003 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006004 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006005 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006006
James Smart09372822008-01-11 01:52:54 -05006007 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006008 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006009 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006010
6011 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006012 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6013 "0915 Register VPI failed: 0x%x\n",
6014 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05006015
6016 switch (mb->mbxStatus) {
6017 case 0x11: /* unsupported feature */
6018 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006019 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006020 /* giving up on vport registration */
6021 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6022 spin_lock_irq(shost->host_lock);
6023 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6024 spin_unlock_irq(shost->host_lock);
6025 lpfc_can_disctmo(vport);
6026 break;
James Smart695a8142010-01-26 23:08:03 -05006027 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6028 case 0x20:
6029 spin_lock_irq(shost->host_lock);
6030 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6031 spin_unlock_irq(shost->host_lock);
6032 lpfc_init_vpi(phba, pmb, vport->vpi);
6033 pmb->vport = vport;
6034 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6035 rc = lpfc_sli_issue_mbox(phba, pmb,
6036 MBX_NOWAIT);
6037 if (rc == MBX_NOT_FINISHED) {
6038 lpfc_printf_vlog(vport,
6039 KERN_ERR, LOG_MBOX,
6040 "2732 Failed to issue INIT_VPI"
6041 " mailbox command\n");
6042 } else {
6043 lpfc_nlp_put(ndlp);
6044 return;
6045 }
6046
James Smart92d7f7b2007-06-17 19:56:38 -05006047 default:
6048 /* Try to recover from this error */
6049 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006050 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006051 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006052 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05006053 if (vport->port_type == LPFC_PHYSICAL_PORT)
6054 lpfc_initial_flogi(vport);
6055 else
6056 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006057 break;
6058 }
James Smart92d7f7b2007-06-17 19:56:38 -05006059 } else {
James Smart695a8142010-01-26 23:08:03 -05006060 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006061 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006062 spin_unlock_irq(shost->host_lock);
6063 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006064 if (phba->sli_rev < LPFC_SLI_REV4)
6065 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006066 else {
James Smartfc2b9892010-02-26 14:15:29 -05006067 /*
6068 * If the physical port is instantiated using
6069 * FDISC, do not start vport discovery.
6070 */
6071 if (vport->port_state != LPFC_FDISC)
6072 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006073 lpfc_do_scr_ns_plogi(phba, vport);
6074 }
6075 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006076 lpfc_do_scr_ns_plogi(phba, vport);
6077 }
James Smartfa4066b2008-01-11 01:53:27 -05006078
6079 /* Now, we decrement the ndlp reference count held for this
6080 * callback function
6081 */
6082 lpfc_nlp_put(ndlp);
6083
James Smart92d7f7b2007-06-17 19:56:38 -05006084 mempool_free(pmb, phba->mbox_mem_pool);
6085 return;
6086}
6087
James Smarte59058c2008-08-24 21:49:00 -04006088/**
James Smart3621a712009-04-06 18:47:14 -04006089 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006090 * @phba: pointer to lpfc hba data structure.
6091 * @vport: pointer to a host virtual N_Port data structure.
6092 * @ndlp: pointer to a node-list data structure.
6093 *
6094 * This routine registers the @vport as a new virtual port with a HBA.
6095 * It is done through a registering vpi mailbox command.
6096 **/
James Smart695a8142010-01-26 23:08:03 -05006097void
James Smart92d7f7b2007-06-17 19:56:38 -05006098lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6099 struct lpfc_nodelist *ndlp)
6100{
James Smart09372822008-01-11 01:52:54 -05006101 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006102 LPFC_MBOXQ_t *mbox;
6103
6104 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6105 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006106 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006107 mbox->vport = vport;
6108 mbox->context2 = lpfc_nlp_get(ndlp);
6109 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006110 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006111 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006112 /* mailbox command not success, decrement ndlp
6113 * reference count for this command
6114 */
6115 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006116 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006117
James Smarte8b62012007-08-02 11:10:09 -04006118 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6119 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006120 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006121 }
6122 } else {
James Smarte8b62012007-08-02 11:10:09 -04006123 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6124 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006125 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006126 }
James Smartfa4066b2008-01-11 01:53:27 -05006127 return;
6128
6129mbox_err_exit:
6130 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6131 spin_lock_irq(shost->host_lock);
6132 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6133 spin_unlock_irq(shost->host_lock);
6134 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006135}
6136
James Smarte59058c2008-08-24 21:49:00 -04006137/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006138 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006139 * @phba: pointer to lpfc hba data structure.
6140 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006141 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006142 **/
6143void
James Smart0c9ab6f2010-02-26 14:15:57 -05006144lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006145{
6146 struct lpfc_vport **vports;
6147 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006148 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006149 int i;
James Smart695a8142010-01-26 23:08:03 -05006150
6151 /* Treat this failure as linkdown for all vports */
6152 link_state = phba->link_state;
6153 lpfc_linkdown(phba);
6154 phba->link_state = link_state;
6155
6156 vports = lpfc_create_vport_work_array(phba);
6157
6158 if (vports) {
6159 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6160 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6161 if (ndlp)
6162 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6163 lpfc_els_flush_cmd(vports[i]);
6164 }
6165 lpfc_destroy_vport_work_array(phba, vports);
6166 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006167}
6168
6169/**
6170 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6171 * @phba: pointer to lpfc hba data structure.
6172 *
6173 * This routine abort all pending discovery commands and
6174 * start a timer to retry FLOGI for the physical port
6175 * discovery.
6176 **/
6177void
6178lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6179{
6180 struct lpfc_nodelist *ndlp;
6181 struct Scsi_Host *shost;
6182
6183 /* Cancel the all vports retry delay retry timers */
6184 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006185
6186 /* If fabric require FLOGI, then re-instantiate physical login */
6187 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6188 if (!ndlp)
6189 return;
6190
James Smart695a8142010-01-26 23:08:03 -05006191 shost = lpfc_shost_from_vport(phba->pport);
6192 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6193 spin_lock_irq(shost->host_lock);
6194 ndlp->nlp_flag |= NLP_DELAY_TMO;
6195 spin_unlock_irq(shost->host_lock);
6196 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6197 phba->pport->port_state = LPFC_FLOGI;
6198 return;
6199}
6200
6201/**
6202 * lpfc_fabric_login_reqd - Check if FLOGI required.
6203 * @phba: pointer to lpfc hba data structure.
6204 * @cmdiocb: pointer to FDISC command iocb.
6205 * @rspiocb: pointer to FDISC response iocb.
6206 *
6207 * This routine checks if a FLOGI is reguired for FDISC
6208 * to succeed.
6209 **/
6210static int
6211lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6212 struct lpfc_iocbq *cmdiocb,
6213 struct lpfc_iocbq *rspiocb)
6214{
6215
6216 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6217 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6218 return 0;
6219 else
6220 return 1;
6221}
6222
6223/**
James Smart3621a712009-04-06 18:47:14 -04006224 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006225 * @phba: pointer to lpfc hba data structure.
6226 * @cmdiocb: pointer to lpfc command iocb data structure.
6227 * @rspiocb: pointer to lpfc response iocb data structure.
6228 *
6229 * This routine is the completion callback function to a Fabric Discover
6230 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6231 * single threaded, each FDISC completion callback function will reset
6232 * the discovery timer for all vports such that the timers will not get
6233 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6234 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6235 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6236 * assigned to the vport has been changed with the completion of the FDISC
6237 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6238 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6239 * routine is invoked to register new vport with the HBA. Otherwise, the
6240 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6241 * Server for State Change Request (SCR).
6242 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006243static void
6244lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6245 struct lpfc_iocbq *rspiocb)
6246{
6247 struct lpfc_vport *vport = cmdiocb->vport;
6248 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6249 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6250 struct lpfc_nodelist *np;
6251 struct lpfc_nodelist *next_np;
6252 IOCB_t *irsp = &rspiocb->iocb;
6253 struct lpfc_iocbq *piocb;
6254
James Smarte8b62012007-08-02 11:10:09 -04006255 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6256 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6257 irsp->ulpStatus, irsp->un.ulpWord[4],
6258 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006259 /* Since all FDISCs are being single threaded, we
6260 * must reset the discovery timer for ALL vports
6261 * waiting to send FDISC when one completes.
6262 */
6263 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6264 lpfc_set_disctmo(piocb->vport);
6265 }
6266
James Smart858c9f62007-06-17 19:56:39 -05006267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6268 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6269 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6270
James Smart92d7f7b2007-06-17 19:56:38 -05006271 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006272
6273 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6274 lpfc_retry_pport_discovery(phba);
6275 goto out;
6276 }
6277
James Smart92d7f7b2007-06-17 19:56:38 -05006278 /* Check for retry */
6279 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6280 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006281 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006282 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006283 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006284 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006285 goto fdisc_failed;
6286 }
James Smartd7c255b2008-08-24 21:50:00 -04006287 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006288 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006289 vport->fc_flag |= FC_FABRIC;
6290 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6291 vport->fc_flag |= FC_PUBLIC_LOOP;
6292 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006293
James Smartd7c255b2008-08-24 21:50:00 -04006294 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6295 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6296 if ((vport->fc_prevDID != vport->fc_myDID) &&
6297 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6298 /* If our NportID changed, we need to ensure all
6299 * remaining NPORTs get unreg_login'ed so we can
6300 * issue unreg_vpi.
6301 */
6302 list_for_each_entry_safe(np, next_np,
6303 &vport->fc_nodes, nlp_listp) {
6304 if (!NLP_CHK_NODE_ACT(ndlp) ||
6305 (np->nlp_state != NLP_STE_NPR_NODE) ||
6306 !(np->nlp_flag & NLP_NPR_ADISC))
6307 continue;
James Smart09372822008-01-11 01:52:54 -05006308 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006309 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006310 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006311 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006312 }
James Smartd7c255b2008-08-24 21:50:00 -04006313 lpfc_mbx_unreg_vpi(vport);
6314 spin_lock_irq(shost->host_lock);
6315 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006316 if (phba->sli_rev == LPFC_SLI_REV4)
6317 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartd7c255b2008-08-24 21:50:00 -04006318 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006319 }
6320
James Smartecfd03c2010-02-12 14:41:27 -05006321 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6322 lpfc_issue_init_vpi(vport);
6323 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006324 lpfc_register_new_vport(phba, vport, ndlp);
6325 else
6326 lpfc_do_scr_ns_plogi(phba, vport);
6327 goto out;
6328fdisc_failed:
6329 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6330 /* Cancel discovery timer */
6331 lpfc_can_disctmo(vport);
6332 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006333out:
6334 lpfc_els_free_iocb(phba, cmdiocb);
6335}
6336
James Smarte59058c2008-08-24 21:49:00 -04006337/**
James Smart3621a712009-04-06 18:47:14 -04006338 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006339 * @vport: pointer to a virtual N_Port data structure.
6340 * @ndlp: pointer to a node-list data structure.
6341 * @retry: number of retries to the command IOCB.
6342 *
6343 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6344 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6345 * routine to issue the IOCB, which makes sure only one outstanding fabric
6346 * IOCB will be sent off HBA at any given time.
6347 *
6348 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6349 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6350 * will be stored into the context1 field of the IOCB for the completion
6351 * callback function to the FDISC ELS command.
6352 *
6353 * Return code
6354 * 0 - Successfully issued fdisc iocb command
6355 * 1 - Failed to issue fdisc iocb command
6356 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006357static int
James Smart92d7f7b2007-06-17 19:56:38 -05006358lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6359 uint8_t retry)
6360{
6361 struct lpfc_hba *phba = vport->phba;
6362 IOCB_t *icmd;
6363 struct lpfc_iocbq *elsiocb;
6364 struct serv_parm *sp;
6365 uint8_t *pcmd;
6366 uint16_t cmdsize;
6367 int did = ndlp->nlp_DID;
6368 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006369
James Smart5ffc2662009-11-18 15:39:44 -05006370 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006371 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6372 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6373 ELS_CMD_FDISC);
6374 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006375 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006376 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6377 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006378 return 1;
6379 }
6380
6381 icmd = &elsiocb->iocb;
6382 icmd->un.elsreq64.myID = 0;
6383 icmd->un.elsreq64.fl = 1;
6384
James Smartf1126682009-06-10 17:22:44 -04006385 if (phba->sli_rev == LPFC_SLI_REV4) {
6386 /* FDISC needs to be 1 for WQE VPI */
6387 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6388 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6389 /* Set the ulpContext to the vpi */
6390 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6391 } else {
6392 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6393 icmd->ulpCt_h = 1;
6394 icmd->ulpCt_l = 0;
6395 }
James Smart92d7f7b2007-06-17 19:56:38 -05006396
6397 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6398 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6399 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6400 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6401 sp = (struct serv_parm *) pcmd;
6402 /* Setup CSPs accordingly for Fabric */
6403 sp->cmn.e_d_tov = 0;
6404 sp->cmn.w2.r_a_tov = 0;
6405 sp->cls1.classValid = 0;
6406 sp->cls2.seqDelivery = 1;
6407 sp->cls3.seqDelivery = 1;
6408
6409 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6410 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6411 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6412 pcmd += sizeof(uint32_t); /* Port Name */
6413 memcpy(pcmd, &vport->fc_portname, 8);
6414 pcmd += sizeof(uint32_t); /* Node Name */
6415 pcmd += sizeof(uint32_t); /* Node Name */
6416 memcpy(pcmd, &vport->fc_nodename, 8);
6417
6418 lpfc_set_disctmo(vport);
6419
6420 phba->fc_stat.elsXmitFDISC++;
6421 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6422
James Smart858c9f62007-06-17 19:56:39 -05006423 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6424 "Issue FDISC: did:x%x",
6425 did, 0, 0);
6426
James Smart92d7f7b2007-06-17 19:56:38 -05006427 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6428 if (rc == IOCB_ERROR) {
6429 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006430 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006431 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6432 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006433 return 1;
6434 }
6435 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006436 return 0;
6437}
6438
James Smarte59058c2008-08-24 21:49:00 -04006439/**
James Smart3621a712009-04-06 18:47:14 -04006440 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006441 * @phba: pointer to lpfc hba data structure.
6442 * @cmdiocb: pointer to lpfc command iocb data structure.
6443 * @rspiocb: pointer to lpfc response iocb data structure.
6444 *
6445 * This routine is the completion callback function to the issuing of a LOGO
6446 * ELS command off a vport. It frees the command IOCB and then decrement the
6447 * reference count held on ndlp for this completion function, indicating that
6448 * the reference to the ndlp is no long needed. Note that the
6449 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6450 * callback function and an additional explicit ndlp reference decrementation
6451 * will trigger the actual release of the ndlp.
6452 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006453static void
6454lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6455 struct lpfc_iocbq *rspiocb)
6456{
6457 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006458 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006459 struct lpfc_nodelist *ndlp;
6460 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006461
6462 irsp = &rspiocb->iocb;
6463 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6464 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6465 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006466
6467 lpfc_els_free_iocb(phba, cmdiocb);
6468 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006469
6470 /* Trigger the release of the ndlp after logo */
6471 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006472}
6473
James Smarte59058c2008-08-24 21:49:00 -04006474/**
James Smart3621a712009-04-06 18:47:14 -04006475 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006476 * @vport: pointer to a virtual N_Port data structure.
6477 * @ndlp: pointer to a node-list data structure.
6478 *
6479 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6480 *
6481 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6482 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6483 * will be stored into the context1 field of the IOCB for the completion
6484 * callback function to the LOGO ELS command.
6485 *
6486 * Return codes
6487 * 0 - Successfully issued logo off the @vport
6488 * 1 - Failed to issue logo off the @vport
6489 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006490int
6491lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6492{
6493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6494 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006495 IOCB_t *icmd;
6496 struct lpfc_iocbq *elsiocb;
6497 uint8_t *pcmd;
6498 uint16_t cmdsize;
6499
6500 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6501 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6502 ELS_CMD_LOGO);
6503 if (!elsiocb)
6504 return 1;
6505
6506 icmd = &elsiocb->iocb;
6507 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6508 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6509 pcmd += sizeof(uint32_t);
6510
6511 /* Fill in LOGO payload */
6512 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6513 pcmd += sizeof(uint32_t);
6514 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6515
James Smart858c9f62007-06-17 19:56:39 -05006516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6517 "Issue LOGO npiv did:x%x flg:x%x",
6518 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6519
James Smart92d7f7b2007-06-17 19:56:38 -05006520 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6521 spin_lock_irq(shost->host_lock);
6522 ndlp->nlp_flag |= NLP_LOGO_SND;
6523 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006524 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6525 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006526 spin_lock_irq(shost->host_lock);
6527 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6528 spin_unlock_irq(shost->host_lock);
6529 lpfc_els_free_iocb(phba, elsiocb);
6530 return 1;
6531 }
6532 return 0;
6533}
6534
James Smarte59058c2008-08-24 21:49:00 -04006535/**
James Smart3621a712009-04-06 18:47:14 -04006536 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006537 * @ptr: holder for the timer function associated data.
6538 *
6539 * This routine is invoked by the fabric iocb block timer after
6540 * timeout. It posts the fabric iocb block timeout event by setting the
6541 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6542 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6543 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6544 * posted event WORKER_FABRIC_BLOCK_TMO.
6545 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006546void
6547lpfc_fabric_block_timeout(unsigned long ptr)
6548{
6549 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6550 unsigned long iflags;
6551 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006552
James Smart92d7f7b2007-06-17 19:56:38 -05006553 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6554 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6555 if (!tmo_posted)
6556 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6557 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6558
James Smart5e9d9b82008-06-14 22:52:53 -04006559 if (!tmo_posted)
6560 lpfc_worker_wake_up(phba);
6561 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006562}
6563
James Smarte59058c2008-08-24 21:49:00 -04006564/**
James Smart3621a712009-04-06 18:47:14 -04006565 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006566 * @phba: pointer to lpfc hba data structure.
6567 *
6568 * This routine issues one fabric iocb from the driver internal list to
6569 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6570 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6571 * remove one pending fabric iocb from the driver internal list and invokes
6572 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6573 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006574static void
6575lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6576{
6577 struct lpfc_iocbq *iocb;
6578 unsigned long iflags;
6579 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006580 IOCB_t *cmd;
6581
6582repeat:
6583 iocb = NULL;
6584 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006585 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006586 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6587 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6588 list);
6589 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006590 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006591 atomic_inc(&phba->fabric_iocb_count);
6592 }
6593 spin_unlock_irqrestore(&phba->hbalock, iflags);
6594 if (iocb) {
6595 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6596 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6597 iocb->iocb_flag |= LPFC_IO_FABRIC;
6598
James Smart858c9f62007-06-17 19:56:39 -05006599 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6600 "Fabric sched1: ste:x%x",
6601 iocb->vport->port_state, 0, 0);
6602
James Smart3772a992009-05-22 14:50:54 -04006603 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006604
6605 if (ret == IOCB_ERROR) {
6606 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6607 iocb->fabric_iocb_cmpl = NULL;
6608 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6609 cmd = &iocb->iocb;
6610 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6611 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6612 iocb->iocb_cmpl(phba, iocb, iocb);
6613
6614 atomic_dec(&phba->fabric_iocb_count);
6615 goto repeat;
6616 }
6617 }
6618
6619 return;
6620}
6621
James Smarte59058c2008-08-24 21:49:00 -04006622/**
James Smart3621a712009-04-06 18:47:14 -04006623 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006624 * @phba: pointer to lpfc hba data structure.
6625 *
6626 * This routine unblocks the issuing fabric iocb command. The function
6627 * will clear the fabric iocb block bit and then invoke the routine
6628 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6629 * from the driver internal fabric iocb list.
6630 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006631void
6632lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6633{
6634 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6635
6636 lpfc_resume_fabric_iocbs(phba);
6637 return;
6638}
6639
James Smarte59058c2008-08-24 21:49:00 -04006640/**
James Smart3621a712009-04-06 18:47:14 -04006641 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006642 * @phba: pointer to lpfc hba data structure.
6643 *
6644 * This routine blocks the issuing fabric iocb for a specified amount of
6645 * time (currently 100 ms). This is done by set the fabric iocb block bit
6646 * and set up a timeout timer for 100ms. When the block bit is set, no more
6647 * fabric iocb will be issued out of the HBA.
6648 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006649static void
6650lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6651{
6652 int blocked;
6653
6654 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006655 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006656 if (!blocked)
6657 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6658
6659 return;
6660}
6661
James Smarte59058c2008-08-24 21:49:00 -04006662/**
James Smart3621a712009-04-06 18:47:14 -04006663 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006664 * @phba: pointer to lpfc hba data structure.
6665 * @cmdiocb: pointer to lpfc command iocb data structure.
6666 * @rspiocb: pointer to lpfc response iocb data structure.
6667 *
6668 * This routine is the callback function that is put to the fabric iocb's
6669 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6670 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6671 * function first restores and invokes the original iocb's callback function
6672 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6673 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6674 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006675static void
6676lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6677 struct lpfc_iocbq *rspiocb)
6678{
6679 struct ls_rjt stat;
6680
6681 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6682 BUG();
6683
6684 switch (rspiocb->iocb.ulpStatus) {
6685 case IOSTAT_NPORT_RJT:
6686 case IOSTAT_FABRIC_RJT:
6687 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6688 lpfc_block_fabric_iocbs(phba);
6689 }
6690 break;
6691
6692 case IOSTAT_NPORT_BSY:
6693 case IOSTAT_FABRIC_BSY:
6694 lpfc_block_fabric_iocbs(phba);
6695 break;
6696
6697 case IOSTAT_LS_RJT:
6698 stat.un.lsRjtError =
6699 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6700 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6701 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6702 lpfc_block_fabric_iocbs(phba);
6703 break;
6704 }
6705
6706 if (atomic_read(&phba->fabric_iocb_count) == 0)
6707 BUG();
6708
6709 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6710 cmdiocb->fabric_iocb_cmpl = NULL;
6711 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6712 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6713
6714 atomic_dec(&phba->fabric_iocb_count);
6715 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006716 /* Post any pending iocbs to HBA */
6717 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006718 }
6719}
6720
James Smarte59058c2008-08-24 21:49:00 -04006721/**
James Smart3621a712009-04-06 18:47:14 -04006722 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006723 * @phba: pointer to lpfc hba data structure.
6724 * @iocb: pointer to lpfc command iocb data structure.
6725 *
6726 * This routine is used as the top-level API for issuing a fabric iocb command
6727 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6728 * function makes sure that only one fabric bound iocb will be outstanding at
6729 * any given time. As such, this function will first check to see whether there
6730 * is already an outstanding fabric iocb on the wire. If so, it will put the
6731 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6732 * issued later. Otherwise, it will issue the iocb on the wire and update the
6733 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6734 *
6735 * Note, this implementation has a potential sending out fabric IOCBs out of
6736 * order. The problem is caused by the construction of the "ready" boolen does
6737 * not include the condition that the internal fabric IOCB list is empty. As
6738 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6739 * ahead of the fabric IOCBs in the internal list.
6740 *
6741 * Return code
6742 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6743 * IOCB_ERROR - failed to issue fabric iocb
6744 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006745static int
James Smart92d7f7b2007-06-17 19:56:38 -05006746lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6747{
6748 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006749 int ready;
6750 int ret;
6751
6752 if (atomic_read(&phba->fabric_iocb_count) > 1)
6753 BUG();
6754
6755 spin_lock_irqsave(&phba->hbalock, iflags);
6756 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6757 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6758
James Smart7f5f3d02008-02-08 18:50:14 -05006759 if (ready)
6760 /* Increment fabric iocb count to hold the position */
6761 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006762 spin_unlock_irqrestore(&phba->hbalock, iflags);
6763 if (ready) {
6764 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6765 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6766 iocb->iocb_flag |= LPFC_IO_FABRIC;
6767
James Smart858c9f62007-06-17 19:56:39 -05006768 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6769 "Fabric sched2: ste:x%x",
6770 iocb->vport->port_state, 0, 0);
6771
James Smart3772a992009-05-22 14:50:54 -04006772 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006773
6774 if (ret == IOCB_ERROR) {
6775 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6776 iocb->fabric_iocb_cmpl = NULL;
6777 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6778 atomic_dec(&phba->fabric_iocb_count);
6779 }
6780 } else {
6781 spin_lock_irqsave(&phba->hbalock, iflags);
6782 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6783 spin_unlock_irqrestore(&phba->hbalock, iflags);
6784 ret = IOCB_SUCCESS;
6785 }
6786 return ret;
6787}
6788
James Smarte59058c2008-08-24 21:49:00 -04006789/**
James Smart3621a712009-04-06 18:47:14 -04006790 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006791 * @vport: pointer to a virtual N_Port data structure.
6792 *
6793 * This routine aborts all the IOCBs associated with a @vport from the
6794 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6795 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6796 * list, removes each IOCB associated with the @vport off the list, set the
6797 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6798 * associated with the IOCB.
6799 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006800static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006801{
6802 LIST_HEAD(completions);
6803 struct lpfc_hba *phba = vport->phba;
6804 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006805
6806 spin_lock_irq(&phba->hbalock);
6807 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6808 list) {
6809
6810 if (piocb->vport != vport)
6811 continue;
6812
6813 list_move_tail(&piocb->list, &completions);
6814 }
6815 spin_unlock_irq(&phba->hbalock);
6816
James Smarta257bf92009-04-06 18:48:10 -04006817 /* Cancel all the IOCBs from the completions list */
6818 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6819 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006820}
6821
James Smarte59058c2008-08-24 21:49:00 -04006822/**
James Smart3621a712009-04-06 18:47:14 -04006823 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006824 * @ndlp: pointer to a node-list data structure.
6825 *
6826 * This routine aborts all the IOCBs associated with an @ndlp from the
6827 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6828 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6829 * list, removes each IOCB associated with the @ndlp off the list, set the
6830 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6831 * associated with the IOCB.
6832 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006833void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6834{
6835 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006836 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006837 struct lpfc_iocbq *tmp_iocb, *piocb;
6838 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006839
6840 spin_lock_irq(&phba->hbalock);
6841 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6842 list) {
6843 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6844
6845 list_move_tail(&piocb->list, &completions);
6846 }
6847 }
6848 spin_unlock_irq(&phba->hbalock);
6849
James Smarta257bf92009-04-06 18:48:10 -04006850 /* Cancel all the IOCBs from the completions list */
6851 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6852 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006853}
6854
James Smarte59058c2008-08-24 21:49:00 -04006855/**
James Smart3621a712009-04-06 18:47:14 -04006856 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006857 * @phba: pointer to lpfc hba data structure.
6858 *
6859 * This routine aborts all the IOCBs currently on the driver internal
6860 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6861 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6862 * list, removes IOCBs off the list, set the status feild to
6863 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6864 * the IOCB.
6865 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006866void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6867{
6868 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006869
6870 spin_lock_irq(&phba->hbalock);
6871 list_splice_init(&phba->fabric_iocb_list, &completions);
6872 spin_unlock_irq(&phba->hbalock);
6873
James Smarta257bf92009-04-06 18:48:10 -04006874 /* Cancel all the IOCBs from the completions list */
6875 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6876 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006877}
James Smart6fb120a2009-05-22 14:52:59 -04006878
6879/**
6880 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6881 * @phba: pointer to lpfc hba data structure.
6882 * @axri: pointer to the els xri abort wcqe structure.
6883 *
6884 * This routine is invoked by the worker thread to process a SLI4 slow-path
6885 * ELS aborted xri.
6886 **/
6887void
6888lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6889 struct sli4_wcqe_xri_aborted *axri)
6890{
6891 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6892 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6893 unsigned long iflag = 0;
6894
James Smart0f65ff62010-02-26 14:14:23 -05006895 spin_lock_irqsave(&phba->hbalock, iflag);
6896 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006897 list_for_each_entry_safe(sglq_entry, sglq_next,
6898 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6899 if (sglq_entry->sli4_xritag == xri) {
6900 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006901 list_add_tail(&sglq_entry->list,
6902 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05006903 sglq_entry->state = SGL_FREED;
6904 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006905 spin_unlock_irqrestore(&phba->hbalock, iflag);
6906 return;
6907 }
6908 }
James Smart0f65ff62010-02-26 14:14:23 -05006909 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6910 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6911 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6912 spin_unlock_irqrestore(&phba->hbalock, iflag);
6913 return;
6914 }
6915 sglq_entry->state = SGL_XRI_ABORTED;
6916 spin_unlock_irqrestore(&phba->hbalock, iflag);
6917 return;
James Smart6fb120a2009-05-22 14:52:59 -04006918}