blob: 6b1850c9fdff355fda8d507f4c1256b581efa6b6 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
182 break;
183 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 }
James Smart0c287582009-06-10 17:22:56 -0400192 else
James Smartc8685952009-11-18 15:39:16 -0500193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400194
dea31012005-04-17 16:05:31 -0500195 icmd = &elsiocb->iocb;
196
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 if (pcmd)
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500204
205 INIT_LIST_HEAD(&pcmd->list);
206
207 /* Allocate buffer for response payload */
208 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500210 if (prsp)
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500215 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500216 } else
dea31012005-04-17 16:05:31 -0500217 prsp = NULL;
dea31012005-04-17 16:05:31 -0500218
219 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500221 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500226
227 INIT_LIST_HEAD(&pbuflist->list);
228
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500232 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400236 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500237 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 }
dea31012005-04-17 16:05:31 -0500241 icmd->ulpBdeCount = 1;
242 icmd->ulpLe = 1;
243 icmd->ulpClass = CLASS3;
244
James Smart92d7f7b2007-06-17 19:56:38 -0500245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
247
248 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400249 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 else
255 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500256 }
257
dea31012005-04-17 16:05:31 -0500258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264
265 if (expectRsp) {
266 bpl++;
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
272 }
273
James Smartfa4066b2008-01-11 01:53:27 -0500274 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400275 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500280 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500281 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
283
284 if (prsp) {
285 list_add(&prsp->list, &pcmd->list);
286 }
dea31012005-04-17 16:05:31 -0500287 if (expectRsp) {
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
293 vport->port_state);
dea31012005-04-17 16:05:31 -0500294 } else {
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
300 cmdSize);
dea31012005-04-17 16:05:31 -0500301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return elsiocb;
dea31012005-04-17 16:05:31 -0500303
James Smartfa4066b2008-01-11 01:53:27 -0500304els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500305 if (expectRsp)
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500307 kfree(pbuflist);
308
309els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
311 kfree(prsp);
312
313els_iocb_free_pcmb_exit:
314 kfree(pcmd);
315 lpfc_sli_release_iocbq(phba, elsiocb);
316 return NULL;
317}
dea31012005-04-17 16:05:31 -0500318
James Smarte59058c2008-08-24 21:49:00 -0400319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400321 * @vport: pointer to a host virtual N_Port data structure.
322 *
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
329 * with the @vport.
330 *
331 * Return code
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
334 **/
James Smart3772a992009-05-22 14:50:54 -0400335int
James Smart92d7f7b2007-06-17 19:56:38 -0500336lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337{
338 struct lpfc_hba *phba = vport->phba;
339 LPFC_MBOXQ_t *mbox;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
343 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400344 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400349 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500350 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400354 if (!mbox) {
355 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500356 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400357 }
James Smart92d7f7b2007-06-17 19:56:38 -0500358
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 mbox->vport = vport;
363
James Smart0b727fe2007-10-27 13:37:25 -0400364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400365 if (rc == MBX_NOT_FINISHED) {
366 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400371 if (!mbox) {
372 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400374 }
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400376 if (rc) {
377 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
385 */
James Smart92d7f7b2007-06-17 19:56:38 -0500386 mbox->context2 = lpfc_nlp_get(ndlp);
387
James Smart0b727fe2007-10-27 13:37:25 -0400388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400389 if (rc == MBX_NOT_FINISHED) {
390 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500391 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400392 }
James Smart92d7f7b2007-06-17 19:56:38 -0500393
394 return 0;
395
396fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
399 */
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_put(ndlp);
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
403 kfree(mp);
404fail_free_mbox:
405 mempool_free(mbox, phba->mbox_mem_pool);
406
407fail:
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return -ENXIO;
412}
413
James Smarte59058c2008-08-24 21:49:00 -0400414/**
James Smart6fb120a2009-05-22 14:52:59 -0400415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
417 *
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
420 *
421 * Return code
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
424 **/
425static int
426lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427{
428 struct lpfc_hba *phba = vport->phba;
429 LPFC_MBOXQ_t *mboxq;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
433 int rc = 0;
434
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
438 rc = -ENODEV;
439 goto fail;
440 }
441
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
443 if (!dmabuf) {
444 rc = -ENOMEM;
445 goto fail;
446 }
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
448 if (!dmabuf->virt) {
449 rc = -ENOMEM;
450 goto fail_free_dmabuf;
451 }
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
453 if (!mboxq) {
454 rc = -ENOMEM;
455 goto fail_free_coherent;
456 }
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
465 rc = -ENXIO;
466 goto fail_free_mbox;
467 }
468 return 0;
469
470fail_free_mbox:
471 mempool_free(mboxq, phba->mbox_mem_pool);
472fail_free_coherent:
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
474fail_free_dmabuf:
475 kfree(dmabuf);
476fail:
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
480 return rc;
481}
482
483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 *
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
499 *
500 * Return code
501 * 0 - Success (currently, always return 0)
502 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500503static int
James Smart2e0fef82007-06-17 19:56:36 -0500504lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521
522 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500526 } else {
527 /*
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
530 */
James Smart2e0fef82007-06-17 19:56:36 -0500531 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500532 }
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500535 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500536 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500537 ndlp->nlp_class_sup = 0;
538 if (sp->cls1.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS1;
540 if (sp->cls2.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS2;
542 if (sp->cls3.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS3;
544 if (sp->cls4.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS4;
546 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
547 sp->cmn.bbRcvSizeLsb;
548 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
549
James Smart92d7f7b2007-06-17 19:56:38 -0500550 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
551 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400552 lpfc_printf_vlog(vport, KERN_WARNING,
553 LOG_ELS | LOG_VPORT,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500557 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500558 } else {
559 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport, KERN_WARNING,
562 LOG_ELS | LOG_VPORT,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500565 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
566 }
567 }
568
569 if ((vport->fc_prevDID != vport->fc_myDID) &&
570 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
571
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
574 */
575 list_for_each_entry_safe(np, next_np,
576 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400577 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500578 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500579 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
580 !(np->nlp_flag & NLP_NPR_ADISC))
581 continue;
582 spin_lock_irq(shost->host_lock);
583 np->nlp_flag &= ~NLP_NPR_ADISC;
584 spin_unlock_irq(shost->host_lock);
585 lpfc_unreg_rpi(vport, np);
586 }
James Smart78730cf2010-04-06 15:06:30 -0400587 lpfc_cleanup_pending_mbox(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500588 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
589 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500590 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500591 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500592 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500593 }
James Smartecfd03c2010-02-12 14:41:27 -0500594 /*
595 * If VPI is unreged, driver need to do INIT_VPI
596 * before re-registering
597 */
598 if (phba->sli_rev == LPFC_SLI_REV4) {
599 spin_lock_irq(shost->host_lock);
600 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
601 spin_unlock_irq(shost->host_lock);
602 }
James Smart92d7f7b2007-06-17 19:56:38 -0500603 }
604
James Smart6fb120a2009-05-22 14:52:59 -0400605 if (phba->sli_rev < LPFC_SLI_REV4) {
606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
607 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
608 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
609 lpfc_register_new_vport(phba, vport, ndlp);
610 else
611 lpfc_issue_fabric_reglogin(vport);
612 } else {
613 ndlp->nlp_type |= NLP_FABRIC;
614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500615 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
616 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400617 lpfc_start_fdiscs(phba);
618 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500619 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500620 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500621 else
James Smart6fb120a2009-05-22 14:52:59 -0400622 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500623 }
dea31012005-04-17 16:05:31 -0500624 return 0;
dea31012005-04-17 16:05:31 -0500625}
James Smarte59058c2008-08-24 21:49:00 -0400626/**
James Smart3621a712009-04-06 18:47:14 -0400627 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400628 * @vport: pointer to a host virtual N_Port data structure.
629 * @ndlp: pointer to a node-list data structure.
630 * @sp: pointer to service parameter data structure.
631 *
632 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
633 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
634 * in a point-to-point topology. First, the @vport's N_Port Name is compared
635 * with the received N_Port Name: if the @vport's N_Port Name is greater than
636 * the received N_Port Name lexicographically, this node shall assign local
637 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
638 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
639 * this node shall just wait for the remote node to issue PLOGI and assign
640 * N_Port IDs.
641 *
642 * Return code
643 * 0 - Success
644 * -ENXIO - Fail
645 **/
dea31012005-04-17 16:05:31 -0500646static int
James Smart2e0fef82007-06-17 19:56:36 -0500647lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
648 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500649{
James Smart2e0fef82007-06-17 19:56:36 -0500650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500652 LPFC_MBOXQ_t *mbox;
653 int rc;
654
James Smart2e0fef82007-06-17 19:56:36 -0500655 spin_lock_irq(shost->host_lock);
656 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
657 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500658
659 phba->fc_edtov = FF_DEF_EDTOV;
660 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500661 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500662 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500663 if (rc >= 0) {
664 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag |= FC_PT2PT_PLOGI;
667 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500668
669 /*
670 * N_Port ID cannot be 0, set our to LocalID the other
671 * side will be RemoteID.
672 */
673
674 /* not equal */
675 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500676 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500677
678 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
679 if (!mbox)
680 goto fail;
681
682 lpfc_config_link(phba, mbox);
683
684 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500685 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400686 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500687 if (rc == MBX_NOT_FINISHED) {
688 mempool_free(mbox, phba->mbox_mem_pool);
689 goto fail;
690 }
James Smarte47c9092008-02-08 18:49:26 -0500691 /* Decrement ndlp reference count indicating that ndlp can be
692 * safely released when other references to it are done.
693 */
James Smart329f9bc2007-04-25 09:53:01 -0400694 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500695
James Smart2e0fef82007-06-17 19:56:36 -0500696 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500697 if (!ndlp) {
698 /*
699 * Cannot find existing Fabric ndlp, so allocate a
700 * new one
701 */
702 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
703 if (!ndlp)
704 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500705 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500706 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
707 ndlp = lpfc_enable_node(vport, ndlp,
708 NLP_STE_UNUSED_NODE);
709 if(!ndlp)
710 goto fail;
dea31012005-04-17 16:05:31 -0500711 }
712
713 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500714 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500715 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500716 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500717 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500718 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
719 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500720 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500721 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500722 } else
723 /* This side will wait for the PLOGI, decrement ndlp reference
724 * count indicating that ndlp can be released when other
725 * references to it are done.
726 */
James Smart329f9bc2007-04-25 09:53:01 -0400727 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500728
James Smart09372822008-01-11 01:52:54 -0500729 /* If we are pt2pt with another NPort, force NPIV off! */
730 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
731
James Smart2e0fef82007-06-17 19:56:36 -0500732 spin_lock_irq(shost->host_lock);
733 vport->fc_flag |= FC_PT2PT;
734 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500735
736 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500737 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500738 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500739fail:
dea31012005-04-17 16:05:31 -0500740 return -ENXIO;
741}
742
James Smarte59058c2008-08-24 21:49:00 -0400743/**
James Smart3621a712009-04-06 18:47:14 -0400744 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400745 * @phba: pointer to lpfc hba data structure.
746 * @cmdiocb: pointer to lpfc command iocb data structure.
747 * @rspiocb: pointer to lpfc response iocb data structure.
748 *
749 * This routine is the top-level completion callback function for issuing
750 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
751 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
752 * retry has been made (either immediately or delayed with lpfc_els_retry()
753 * returning 1), the command IOCB will be released and function returned.
754 * If the retry attempt has been given up (possibly reach the maximum
755 * number of retries), one additional decrement of ndlp reference shall be
756 * invoked before going out after releasing the command IOCB. This will
757 * actually release the remote node (Note, lpfc_els_free_iocb() will also
758 * invoke one decrement of ndlp reference count). If no error reported in
759 * the IOCB status, the command Port ID field is used to determine whether
760 * this is a point-to-point topology or a fabric topology: if the Port ID
761 * field is assigned, it is a fabric topology; otherwise, it is a
762 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
763 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
764 * specific topology completion conditions.
765 **/
dea31012005-04-17 16:05:31 -0500766static void
James Smart329f9bc2007-04-25 09:53:01 -0400767lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
768 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500769{
James Smart2e0fef82007-06-17 19:56:36 -0500770 struct lpfc_vport *vport = cmdiocb->vport;
771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500772 IOCB_t *irsp = &rspiocb->iocb;
773 struct lpfc_nodelist *ndlp = cmdiocb->context1;
774 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
775 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500776 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500777 int rc;
778
779 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500780 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500781 /* One additional decrement on node reference count to
782 * trigger the release of the node
783 */
James Smart329f9bc2007-04-25 09:53:01 -0400784 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500785 goto out;
786 }
787
James Smart858c9f62007-06-17 19:56:39 -0500788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
789 "FLOGI cmpl: status:x%x/x%x state:x%x",
790 irsp->ulpStatus, irsp->un.ulpWord[4],
791 vport->port_state);
792
dea31012005-04-17 16:05:31 -0500793 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500794 /*
795 * In case of FIP mode, perform round robin FCF failover
796 * due to new FCF discovery
797 */
798 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
799 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
800 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
801 "2611 FLOGI failed on registered "
802 "FCF record fcf_index:%d, trying "
803 "to perform round robin failover\n",
804 phba->fcf.current_rec.fcf_indx);
805 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
806 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
807 /*
808 * Exhausted the eligible FCF record list,
809 * fail through to retry FLOGI on current
810 * FCF record.
811 */
812 lpfc_printf_log(phba, KERN_WARNING,
813 LOG_FIP | LOG_ELS,
814 "2760 FLOGI exhausted FCF "
815 "round robin failover list, "
816 "retry FLOGI on the current "
817 "registered FCF index:%d\n",
818 phba->fcf.current_rec.fcf_indx);
819 spin_lock_irq(&phba->hbalock);
820 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
821 spin_unlock_irq(&phba->hbalock);
822 } else {
823 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
824 fcf_index);
825 if (rc) {
826 lpfc_printf_log(phba, KERN_WARNING,
827 LOG_FIP | LOG_ELS,
828 "2761 FLOGI round "
829 "robin FCF failover "
830 "read FCF failed "
831 "rc:x%x, fcf_index:"
832 "%d\n", rc,
833 phba->fcf.current_rec.fcf_indx);
834 spin_lock_irq(&phba->hbalock);
835 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
836 spin_unlock_irq(&phba->hbalock);
837 } else
838 goto out;
839 }
840 }
841
dea31012005-04-17 16:05:31 -0500842 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500843 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500844 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500845
dea31012005-04-17 16:05:31 -0500846 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500847 spin_lock_irq(shost->host_lock);
848 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
849 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500850
James Smart329f9bc2007-04-25 09:53:01 -0400851 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500852 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
853 * alpa map would take too long otherwise.
854 */
855 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400856 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500857 }
858
859 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500860 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
861 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400862 irsp->ulpStatus, irsp->un.ulpWord[4],
863 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500864 goto flogifail;
865 }
James Smart695a8142010-01-26 23:08:03 -0500866 spin_lock_irq(shost->host_lock);
867 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400868 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500869 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500870
871 /*
872 * The FLogI succeeded. Sync the data for the CPU before
873 * accessing it.
874 */
875 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
876
877 sp = prsp->virt + sizeof(uint32_t);
878
879 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400880 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200881 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400882 "Data: x%x x%x x%x x%x\n",
883 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
884 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500885
James Smart2e0fef82007-06-17 19:56:36 -0500886 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500887 /*
888 * If Common Service Parameters indicate Nport
889 * we are point to point, if Fport we are Fabric.
890 */
891 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500892 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500893 else
James Smart2e0fef82007-06-17 19:56:36 -0500894 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500895
James Smart0c9ab6f2010-02-26 14:15:57 -0500896 if (!rc) {
897 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400898 if (phba->hba_flag & HBA_FIP_SUPPORT)
899 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
900 LOG_ELS,
901 "2769 FLOGI successful on FCF "
902 "record: current_fcf_index:"
903 "x%x, terminate FCF round "
904 "robin failover process\n",
905 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500906 spin_lock_irq(&phba->hbalock);
907 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
908 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500909 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500910 }
dea31012005-04-17 16:05:31 -0500911 }
912
913flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400914 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500915
James Smart858c9f62007-06-17 19:56:39 -0500916 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500917 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500918 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500919
920 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500921 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400922 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
923 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
924 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
925 (phba->link_state != LPFC_CLEAR_LA)) {
926 /* If FLOGI failed enable link interrupt. */
927 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500928 }
dea31012005-04-17 16:05:31 -0500929out:
930 lpfc_els_free_iocb(phba, cmdiocb);
931}
932
James Smarte59058c2008-08-24 21:49:00 -0400933/**
James Smart3621a712009-04-06 18:47:14 -0400934 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400935 * @vport: pointer to a host virtual N_Port data structure.
936 * @ndlp: pointer to a node-list data structure.
937 * @retry: number of retries to the command IOCB.
938 *
939 * This routine issues a Fabric Login (FLOGI) Request ELS command
940 * for a @vport. The initiator service parameters are put into the payload
941 * of the FLOGI Request IOCB and the top-level callback function pointer
942 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
943 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
944 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
945 *
946 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
947 * will be incremented by 1 for holding the ndlp and the reference to ndlp
948 * will be stored into the context1 field of the IOCB for the completion
949 * callback function to the FLOGI ELS command.
950 *
951 * Return code
952 * 0 - successfully issued flogi iocb for @vport
953 * 1 - failed to issue flogi iocb for @vport
954 **/
dea31012005-04-17 16:05:31 -0500955static int
James Smart2e0fef82007-06-17 19:56:36 -0500956lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500957 uint8_t retry)
958{
James Smart2e0fef82007-06-17 19:56:36 -0500959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500960 struct serv_parm *sp;
961 IOCB_t *icmd;
962 struct lpfc_iocbq *elsiocb;
963 struct lpfc_sli_ring *pring;
964 uint8_t *pcmd;
965 uint16_t cmdsize;
966 uint32_t tmo;
967 int rc;
968
969 pring = &phba->sli.ring[LPFC_ELS_RING];
970
James Smart92d7f7b2007-06-17 19:56:38 -0500971 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500972 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
973 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500974
James Smart488d1462006-03-07 15:02:37 -0500975 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500976 return 1;
dea31012005-04-17 16:05:31 -0500977
978 icmd = &elsiocb->iocb;
979 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
980
981 /* For FLOGI request, remainder of payload is service parameters */
982 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500983 pcmd += sizeof(uint32_t);
984 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500985 sp = (struct serv_parm *) pcmd;
986
987 /* Setup CSPs accordingly for Fabric */
988 sp->cmn.e_d_tov = 0;
989 sp->cmn.w2.r_a_tov = 0;
990 sp->cls1.classValid = 0;
991 sp->cls2.seqDelivery = 1;
992 sp->cls3.seqDelivery = 1;
993 if (sp->cmn.fcphLow < FC_PH3)
994 sp->cmn.fcphLow = FC_PH3;
995 if (sp->cmn.fcphHigh < FC_PH3)
996 sp->cmn.fcphHigh = FC_PH3;
997
James Smart6fb120a2009-05-22 14:52:59 -0400998 if (phba->sli_rev == LPFC_SLI_REV4) {
999 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1000 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1001 /* FLOGI needs to be 3 for WQE FCFI */
1002 /* Set the fcfi to the fcfi we registered with */
1003 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1004 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001005 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001006 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1007 icmd->ulpCt_h = 1;
1008 icmd->ulpCt_l = 0;
1009 }
1010
James Smart858c9f62007-06-17 19:56:39 -05001011 if (phba->fc_topology != TOPOLOGY_LOOP) {
1012 icmd->un.elsreq64.myID = 0;
1013 icmd->un.elsreq64.fl = 1;
1014 }
1015
dea31012005-04-17 16:05:31 -05001016 tmo = phba->fc_ratov;
1017 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001018 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001019 phba->fc_ratov = tmo;
1020
1021 phba->fc_stat.elsXmitFLOGI++;
1022 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001023
1024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1025 "Issue FLOGI: opt:x%x",
1026 phba->sli3_options, 0, 0);
1027
James Smart92d7f7b2007-06-17 19:56:38 -05001028 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001029 if (rc == IOCB_ERROR) {
1030 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001031 return 1;
dea31012005-04-17 16:05:31 -05001032 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001033 return 0;
dea31012005-04-17 16:05:31 -05001034}
1035
James Smarte59058c2008-08-24 21:49:00 -04001036/**
James Smart3621a712009-04-06 18:47:14 -04001037 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001038 * @phba: pointer to lpfc hba data structure.
1039 *
1040 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1041 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1042 * list and issues an abort IOCB commond on each outstanding IOCB that
1043 * contains a active Fabric_DID ndlp. Note that this function is to issue
1044 * the abort IOCB command on all the outstanding IOCBs, thus when this
1045 * function returns, it does not guarantee all the IOCBs are actually aborted.
1046 *
1047 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001048 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001049 **/
dea31012005-04-17 16:05:31 -05001050int
James Smart2e0fef82007-06-17 19:56:36 -05001051lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001052{
1053 struct lpfc_sli_ring *pring;
1054 struct lpfc_iocbq *iocb, *next_iocb;
1055 struct lpfc_nodelist *ndlp;
1056 IOCB_t *icmd;
1057
1058 /* Abort outstanding I/O on NPort <nlp_DID> */
1059 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001060 "0201 Abort outstanding I/O on NPort x%x\n",
1061 Fabric_DID);
dea31012005-04-17 16:05:31 -05001062
1063 pring = &phba->sli.ring[LPFC_ELS_RING];
1064
1065 /*
1066 * Check the txcmplq for an iocb that matches the nport the driver is
1067 * searching for.
1068 */
James Smart2e0fef82007-06-17 19:56:36 -05001069 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001070 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1071 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001072 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1073 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001074 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001075 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1076 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001077 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001078 }
1079 }
James Smart2e0fef82007-06-17 19:56:36 -05001080 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001081
1082 return 0;
1083}
1084
James Smarte59058c2008-08-24 21:49:00 -04001085/**
James Smart3621a712009-04-06 18:47:14 -04001086 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001087 * @vport: pointer to a host virtual N_Port data structure.
1088 *
1089 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1090 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1091 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1092 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1093 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1094 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1095 * @vport.
1096 *
1097 * Return code
1098 * 0 - failed to issue initial flogi for @vport
1099 * 1 - successfully issued initial flogi for @vport
1100 **/
dea31012005-04-17 16:05:31 -05001101int
James Smart2e0fef82007-06-17 19:56:36 -05001102lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001103{
James Smart2e0fef82007-06-17 19:56:36 -05001104 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001105 struct lpfc_nodelist *ndlp;
1106
James Smart98c9ea52007-10-27 13:37:33 -04001107 vport->port_state = LPFC_FLOGI;
1108 lpfc_set_disctmo(vport);
1109
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001110 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001111 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001112 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001113 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001114 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1115 if (!ndlp)
1116 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001117 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001118 /* Set the node type */
1119 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001120 /* Put ndlp onto node list */
1121 lpfc_enqueue_node(vport, ndlp);
1122 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1123 /* re-setup ndlp without removing from node list */
1124 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1125 if (!ndlp)
1126 return 0;
dea31012005-04-17 16:05:31 -05001127 }
James Smart87af33f2007-10-27 13:37:43 -04001128
James Smarte47c9092008-02-08 18:49:26 -05001129 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001130 /* This decrement of reference count to node shall kick off
1131 * the release of the node.
1132 */
James Smart329f9bc2007-04-25 09:53:01 -04001133 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001134
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001135 return 1;
dea31012005-04-17 16:05:31 -05001136}
1137
James Smarte59058c2008-08-24 21:49:00 -04001138/**
James Smart3621a712009-04-06 18:47:14 -04001139 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001140 * @vport: pointer to a host virtual N_Port data structure.
1141 *
1142 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1143 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1144 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1145 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1146 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1147 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1148 * @vport.
1149 *
1150 * Return code
1151 * 0 - failed to issue initial fdisc for @vport
1152 * 1 - successfully issued initial fdisc for @vport
1153 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001154int
1155lpfc_initial_fdisc(struct lpfc_vport *vport)
1156{
1157 struct lpfc_hba *phba = vport->phba;
1158 struct lpfc_nodelist *ndlp;
1159
1160 /* First look for the Fabric ndlp */
1161 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1162 if (!ndlp) {
1163 /* Cannot find existing Fabric ndlp, so allocate a new one */
1164 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1165 if (!ndlp)
1166 return 0;
1167 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001168 /* Put ndlp onto node list */
1169 lpfc_enqueue_node(vport, ndlp);
1170 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1171 /* re-setup ndlp without removing from node list */
1172 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1173 if (!ndlp)
1174 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001175 }
James Smarte47c9092008-02-08 18:49:26 -05001176
James Smart92d7f7b2007-06-17 19:56:38 -05001177 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001178 /* decrement node reference count to trigger the release of
1179 * the node.
1180 */
James Smart92d7f7b2007-06-17 19:56:38 -05001181 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001182 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001183 }
1184 return 1;
1185}
James Smart87af33f2007-10-27 13:37:43 -04001186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001189 * @vport: pointer to a host virtual N_Port data structure.
1190 *
1191 * This routine checks whether there are more remaining Port Logins
1192 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1193 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1194 * to issue ELS PLOGIs up to the configured discover threads with the
1195 * @vport (@vport->cfg_discovery_threads). The function also decrement
1196 * the @vport's num_disc_node by 1 if it is not already 0.
1197 **/
James Smart87af33f2007-10-27 13:37:43 -04001198void
James Smart2e0fef82007-06-17 19:56:36 -05001199lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001200{
1201 int sentplogi;
1202
James Smart2e0fef82007-06-17 19:56:36 -05001203 if (vport->num_disc_nodes)
1204 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001205
1206 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001207 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1208 "0232 Continue discovery with %d PLOGIs to go "
1209 "Data: x%x x%x x%x\n",
1210 vport->num_disc_nodes, vport->fc_plogi_cnt,
1211 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001212 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001213 if (vport->fc_flag & FC_NLP_MORE)
1214 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1215 sentplogi = lpfc_els_disc_plogi(vport);
1216
dea31012005-04-17 16:05:31 -05001217 return;
1218}
1219
James Smarte59058c2008-08-24 21:49:00 -04001220/**
James Smart3621a712009-04-06 18:47:14 -04001221 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001222 * @phba: pointer to lpfc hba data structure.
1223 * @prsp: pointer to response IOCB payload.
1224 * @ndlp: pointer to a node-list data structure.
1225 *
1226 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1227 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1228 * The following cases are considered N_Port confirmed:
1229 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1230 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1231 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1232 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1233 * 1) if there is a node on vport list other than the @ndlp with the same
1234 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1235 * on that node to release the RPI associated with the node; 2) if there is
1236 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1237 * into, a new node shall be allocated (or activated). In either case, the
1238 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1239 * be released and the new_ndlp shall be put on to the vport node list and
1240 * its pointer returned as the confirmed node.
1241 *
1242 * Note that before the @ndlp got "released", the keepDID from not-matching
1243 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1244 * of the @ndlp. This is because the release of @ndlp is actually to put it
1245 * into an inactive state on the vport node list and the vport node list
1246 * management algorithm does not allow two node with a same DID.
1247 *
1248 * Return code
1249 * pointer to the PLOGI N_Port @ndlp
1250 **/
James Smart488d1462006-03-07 15:02:37 -05001251static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001252lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001253 struct lpfc_nodelist *ndlp)
1254{
James Smart2e0fef82007-06-17 19:56:36 -05001255 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001256 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001257 struct lpfc_rport_data *rdata;
1258 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001259 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001260 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001261 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001262
James Smart2fb9bd82006-12-02 13:33:57 -05001263 /* Fabric nodes can have the same WWPN so we don't bother searching
1264 * by WWPN. Just return the ndlp that was given to us.
1265 */
1266 if (ndlp->nlp_type & NLP_FABRIC)
1267 return ndlp;
1268
James Smart92d7f7b2007-06-17 19:56:38 -05001269 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001270 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001271
James Smart685f0bf2007-04-25 09:53:08 -04001272 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001273 * we have for that ndlp. If not, we have some work to do.
1274 */
James Smart2e0fef82007-06-17 19:56:36 -05001275 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001276
James Smarte47c9092008-02-08 18:49:26 -05001277 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001278 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001279
1280 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001281 rc = memcmp(&ndlp->nlp_portname, name,
1282 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001283 if (!rc)
1284 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001285 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1286 if (!new_ndlp)
1287 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001288 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001289 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001290 rc = memcmp(&ndlp->nlp_portname, name,
1291 sizeof(struct lpfc_name));
1292 if (!rc)
1293 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001294 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1295 NLP_STE_UNUSED_NODE);
1296 if (!new_ndlp)
1297 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001298 keepDID = new_ndlp->nlp_DID;
1299 } else
1300 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001301
James Smart2e0fef82007-06-17 19:56:36 -05001302 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001303 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001304 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001305
1306 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1307 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1308 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1309
James Smarte47c9092008-02-08 18:49:26 -05001310 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001312
James Smart2e0fef82007-06-17 19:56:36 -05001313 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001314 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1315 /* The new_ndlp is replacing ndlp totally, so we need
1316 * to put ndlp on UNUSED list and try to free it.
1317 */
James Smart0ff10d42008-01-11 01:52:36 -05001318
1319 /* Fix up the rport accordingly */
1320 rport = ndlp->rport;
1321 if (rport) {
1322 rdata = rport->dd_data;
1323 if (rdata->pnode == ndlp) {
1324 lpfc_nlp_put(ndlp);
1325 ndlp->rport = NULL;
1326 rdata->pnode = lpfc_nlp_get(new_ndlp);
1327 new_ndlp->rport = rport;
1328 }
1329 new_ndlp->nlp_type = ndlp->nlp_type;
1330 }
James Smart58da1ff2008-04-07 10:15:56 -04001331 /* We shall actually free the ndlp with both nlp_DID and
1332 * nlp_portname fields equals 0 to avoid any ndlp on the
1333 * nodelist never to be used.
1334 */
1335 if (ndlp->nlp_DID == 0) {
1336 spin_lock_irq(&phba->ndlp_lock);
1337 NLP_SET_FREE_REQ(ndlp);
1338 spin_unlock_irq(&phba->ndlp_lock);
1339 }
James Smart0ff10d42008-01-11 01:52:36 -05001340
James Smart58da1ff2008-04-07 10:15:56 -04001341 /* Two ndlps cannot have the same did on the nodelist */
1342 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001343 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001344 }
James Smart92795652006-07-06 15:50:02 -04001345 else {
James Smart2e0fef82007-06-17 19:56:36 -05001346 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001347 /* Two ndlps cannot have the same did */
1348 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001349 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001350 }
James Smart488d1462006-03-07 15:02:37 -05001351 return new_ndlp;
1352}
1353
James Smarte59058c2008-08-24 21:49:00 -04001354/**
James Smart3621a712009-04-06 18:47:14 -04001355 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001356 * @vport: pointer to a host virtual N_Port data structure.
1357 *
1358 * This routine checks whether more Registration State Change
1359 * Notifications (RSCNs) came in while the discovery state machine was in
1360 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1361 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1362 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1363 * handling the RSCNs.
1364 **/
James Smart87af33f2007-10-27 13:37:43 -04001365void
1366lpfc_end_rscn(struct lpfc_vport *vport)
1367{
1368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1369
1370 if (vport->fc_flag & FC_RSCN_MODE) {
1371 /*
1372 * Check to see if more RSCNs came in while we were
1373 * processing this one.
1374 */
1375 if (vport->fc_rscn_id_cnt ||
1376 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1377 lpfc_els_handle_rscn(vport);
1378 else {
1379 spin_lock_irq(shost->host_lock);
1380 vport->fc_flag &= ~FC_RSCN_MODE;
1381 spin_unlock_irq(shost->host_lock);
1382 }
1383 }
1384}
1385
James Smarte59058c2008-08-24 21:49:00 -04001386/**
James Smart3621a712009-04-06 18:47:14 -04001387 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001388 * @phba: pointer to lpfc hba data structure.
1389 * @cmdiocb: pointer to lpfc command iocb data structure.
1390 * @rspiocb: pointer to lpfc response iocb data structure.
1391 *
1392 * This routine is the completion callback function for issuing the Port
1393 * Login (PLOGI) command. For PLOGI completion, there must be an active
1394 * ndlp on the vport node list that matches the remote node ID from the
1395 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1396 * ignored and command IOCB released. The PLOGI response IOCB status is
1397 * checked for error conditons. If there is error status reported, PLOGI
1398 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1399 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1400 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1401 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1402 * there are additional N_Port nodes with the vport that need to perform
1403 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1404 * PLOGIs.
1405 **/
dea31012005-04-17 16:05:31 -05001406static void
James Smart2e0fef82007-06-17 19:56:36 -05001407lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1408 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001409{
James Smart2e0fef82007-06-17 19:56:36 -05001410 struct lpfc_vport *vport = cmdiocb->vport;
1411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001412 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001413 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001414 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001415 int disc, rc, did, type;
1416
dea31012005-04-17 16:05:31 -05001417 /* we pass cmdiocb to state machine which needs rspiocb as well */
1418 cmdiocb->context_un.rsp_iocb = rspiocb;
1419
1420 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1422 "PLOGI cmpl: status:x%x/x%x did:x%x",
1423 irsp->ulpStatus, irsp->un.ulpWord[4],
1424 irsp->un.elsreq64.remoteID);
1425
James Smart2e0fef82007-06-17 19:56:36 -05001426 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001427 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001428 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1429 "0136 PLOGI completes to NPort x%x "
1430 "with no ndlp. Data: x%x x%x x%x\n",
1431 irsp->un.elsreq64.remoteID,
1432 irsp->ulpStatus, irsp->un.ulpWord[4],
1433 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001434 goto out;
James Smarted957682007-06-17 19:56:37 -05001435 }
dea31012005-04-17 16:05:31 -05001436
1437 /* Since ndlp can be freed in the disc state machine, note if this node
1438 * is being used during discovery.
1439 */
James Smart2e0fef82007-06-17 19:56:36 -05001440 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001441 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001442 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001443 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001444 rc = 0;
1445
1446 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001447 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1448 "0102 PLOGI completes to NPort x%x "
1449 "Data: x%x x%x x%x x%x x%x\n",
1450 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1451 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001452 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001453 if (lpfc_els_chk_latt(vport)) {
1454 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001455 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001456 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001457 goto out;
1458 }
1459
1460 /* ndlp could be freed in DSM, save these values now */
1461 type = ndlp->nlp_type;
1462 did = ndlp->nlp_DID;
1463
1464 if (irsp->ulpStatus) {
1465 /* Check for retry */
1466 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1467 /* ELS command is being retried */
1468 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001469 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001470 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001471 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001472 }
1473 goto out;
1474 }
dea31012005-04-17 16:05:31 -05001475 /* PLOGI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001476 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1477 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1478 ndlp->nlp_DID, irsp->ulpStatus,
1479 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001480 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001481 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001482 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001483 else
James Smart2e0fef82007-06-17 19:56:36 -05001484 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001485 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001486 } else {
1487 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001488 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001489 cmdiocb->context2)->list.next,
1490 struct lpfc_dmabuf, list);
1491 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001492 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001493 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001494 }
1495
James Smart2e0fef82007-06-17 19:56:36 -05001496 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001497 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001498 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001499
James Smart2e0fef82007-06-17 19:56:36 -05001500 if (vport->num_disc_nodes == 0) {
1501 spin_lock_irq(shost->host_lock);
1502 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1503 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001504
James Smart2e0fef82007-06-17 19:56:36 -05001505 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001506 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001507 }
1508 }
1509
1510out:
1511 lpfc_els_free_iocb(phba, cmdiocb);
1512 return;
1513}
1514
James Smarte59058c2008-08-24 21:49:00 -04001515/**
James Smart3621a712009-04-06 18:47:14 -04001516 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001517 * @vport: pointer to a host virtual N_Port data structure.
1518 * @did: destination port identifier.
1519 * @retry: number of retries to the command IOCB.
1520 *
1521 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1522 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1523 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1524 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1525 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1526 *
1527 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1528 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1529 * will be stored into the context1 field of the IOCB for the completion
1530 * callback function to the PLOGI ELS command.
1531 *
1532 * Return code
1533 * 0 - Successfully issued a plogi for @vport
1534 * 1 - failed to issue a plogi for @vport
1535 **/
dea31012005-04-17 16:05:31 -05001536int
James Smart2e0fef82007-06-17 19:56:36 -05001537lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001538{
James Smart2e0fef82007-06-17 19:56:36 -05001539 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001540 struct serv_parm *sp;
1541 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001542 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001543 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001544 struct lpfc_sli *psli;
1545 uint8_t *pcmd;
1546 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001547 int ret;
dea31012005-04-17 16:05:31 -05001548
1549 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001550
James Smart98c9ea52007-10-27 13:37:33 -04001551 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001552 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1553 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001554
James Smarte47c9092008-02-08 18:49:26 -05001555 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001556 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001557 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001558 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001559 if (!elsiocb)
1560 return 1;
dea31012005-04-17 16:05:31 -05001561
1562 icmd = &elsiocb->iocb;
1563 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1564
1565 /* For PLOGI request, remainder of payload is service parameters */
1566 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001567 pcmd += sizeof(uint32_t);
1568 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001569 sp = (struct serv_parm *) pcmd;
1570
1571 if (sp->cmn.fcphLow < FC_PH_4_3)
1572 sp->cmn.fcphLow = FC_PH_4_3;
1573
1574 if (sp->cmn.fcphHigh < FC_PH3)
1575 sp->cmn.fcphHigh = FC_PH3;
1576
James Smart858c9f62007-06-17 19:56:39 -05001577 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1578 "Issue PLOGI: did:x%x",
1579 did, 0, 0);
1580
dea31012005-04-17 16:05:31 -05001581 phba->fc_stat.elsXmitPLOGI++;
1582 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001583 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001584
1585 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001586 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001587 return 1;
dea31012005-04-17 16:05:31 -05001588 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001589 return 0;
dea31012005-04-17 16:05:31 -05001590}
1591
James Smarte59058c2008-08-24 21:49:00 -04001592/**
James Smart3621a712009-04-06 18:47:14 -04001593 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001594 * @phba: pointer to lpfc hba data structure.
1595 * @cmdiocb: pointer to lpfc command iocb data structure.
1596 * @rspiocb: pointer to lpfc response iocb data structure.
1597 *
1598 * This routine is the completion callback function for a Process Login
1599 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1600 * status. If there is error status reported, PRLI retry shall be attempted
1601 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1602 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1603 * ndlp to mark the PRLI completion.
1604 **/
dea31012005-04-17 16:05:31 -05001605static void
James Smart2e0fef82007-06-17 19:56:36 -05001606lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1607 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001608{
James Smart2e0fef82007-06-17 19:56:36 -05001609 struct lpfc_vport *vport = cmdiocb->vport;
1610 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001611 IOCB_t *irsp;
1612 struct lpfc_sli *psli;
1613 struct lpfc_nodelist *ndlp;
1614
1615 psli = &phba->sli;
1616 /* we pass cmdiocb to state machine which needs rspiocb as well */
1617 cmdiocb->context_un.rsp_iocb = rspiocb;
1618
1619 irsp = &(rspiocb->iocb);
1620 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001621 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001622 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001623 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001624
James Smart858c9f62007-06-17 19:56:39 -05001625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1626 "PRLI cmpl: status:x%x/x%x did:x%x",
1627 irsp->ulpStatus, irsp->un.ulpWord[4],
1628 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001629 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001630 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1631 "0103 PRLI completes to NPort x%x "
1632 "Data: x%x x%x x%x x%x\n",
1633 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1634 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001635
James Smart2e0fef82007-06-17 19:56:36 -05001636 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001637 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001638 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001639 goto out;
1640
1641 if (irsp->ulpStatus) {
1642 /* Check for retry */
1643 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1644 /* ELS command is being retried */
1645 goto out;
1646 }
1647 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001648 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1649 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1650 ndlp->nlp_DID, irsp->ulpStatus,
1651 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001652 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001653 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001654 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001655 else
James Smart2e0fef82007-06-17 19:56:36 -05001656 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001657 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001658 } else
dea31012005-04-17 16:05:31 -05001659 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001660 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001661 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001662out:
1663 lpfc_els_free_iocb(phba, cmdiocb);
1664 return;
1665}
1666
James Smarte59058c2008-08-24 21:49:00 -04001667/**
James Smart3621a712009-04-06 18:47:14 -04001668 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001669 * @vport: pointer to a host virtual N_Port data structure.
1670 * @ndlp: pointer to a node-list data structure.
1671 * @retry: number of retries to the command IOCB.
1672 *
1673 * This routine issues a Process Login (PRLI) ELS command for the
1674 * @vport. The PRLI service parameters are set up in the payload of the
1675 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1676 * is put to the IOCB completion callback func field before invoking the
1677 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1678 *
1679 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1680 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1681 * will be stored into the context1 field of the IOCB for the completion
1682 * callback function to the PRLI ELS command.
1683 *
1684 * Return code
1685 * 0 - successfully issued prli iocb command for @vport
1686 * 1 - failed to issue prli iocb command for @vport
1687 **/
dea31012005-04-17 16:05:31 -05001688int
James Smart2e0fef82007-06-17 19:56:36 -05001689lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001690 uint8_t retry)
1691{
James Smart2e0fef82007-06-17 19:56:36 -05001692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1693 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001694 PRLI *npr;
1695 IOCB_t *icmd;
1696 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001697 uint8_t *pcmd;
1698 uint16_t cmdsize;
1699
James Smart92d7f7b2007-06-17 19:56:38 -05001700 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001701 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1702 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001703 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001704 return 1;
dea31012005-04-17 16:05:31 -05001705
1706 icmd = &elsiocb->iocb;
1707 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1708
1709 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001710 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001711 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001712 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001713
1714 /* For PRLI, remainder of payload is PRLI parameter page */
1715 npr = (PRLI *) pcmd;
1716 /*
1717 * If our firmware version is 3.20 or later,
1718 * set the following bits for FC-TAPE support.
1719 */
1720 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1721 npr->ConfmComplAllowed = 1;
1722 npr->Retry = 1;
1723 npr->TaskRetryIdReq = 1;
1724 }
1725 npr->estabImagePair = 1;
1726 npr->readXferRdyDis = 1;
1727
1728 /* For FCP support */
1729 npr->prliType = PRLI_FCP_TYPE;
1730 npr->initiatorFunc = 1;
1731
James Smart858c9f62007-06-17 19:56:39 -05001732 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1733 "Issue PRLI: did:x%x",
1734 ndlp->nlp_DID, 0, 0);
1735
dea31012005-04-17 16:05:31 -05001736 phba->fc_stat.elsXmitPRLI++;
1737 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001738 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001739 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001740 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001741 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1742 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001743 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001744 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001745 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001746 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001747 return 1;
dea31012005-04-17 16:05:31 -05001748 }
James Smart2e0fef82007-06-17 19:56:36 -05001749 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001750 return 0;
dea31012005-04-17 16:05:31 -05001751}
1752
James Smarte59058c2008-08-24 21:49:00 -04001753/**
James Smart3621a712009-04-06 18:47:14 -04001754 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001755 * @vport: pointer to a host virtual N_Port data structure.
1756 *
1757 * This routine performs Registration State Change Notification (RSCN)
1758 * discovery for a @vport. If the @vport's node port recovery count is not
1759 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1760 * the nodes that need recovery. If none of the PLOGI were needed through
1761 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1762 * invoked to check and handle possible more RSCN came in during the period
1763 * of processing the current ones.
1764 **/
1765static void
1766lpfc_rscn_disc(struct lpfc_vport *vport)
1767{
1768 lpfc_can_disctmo(vport);
1769
1770 /* RSCN discovery */
1771 /* go thru NPR nodes and issue ELS PLOGIs */
1772 if (vport->fc_npr_cnt)
1773 if (lpfc_els_disc_plogi(vport))
1774 return;
1775
1776 lpfc_end_rscn(vport);
1777}
1778
1779/**
James Smart3621a712009-04-06 18:47:14 -04001780 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001781 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1782 *
1783 * This function is called when the final ADISC is completed during discovery.
1784 * This function handles clearing link attention or issuing reg_vpi depending
1785 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1786 * discovery.
1787 * This function is called with no locks held.
1788 **/
1789static void
1790lpfc_adisc_done(struct lpfc_vport *vport)
1791{
1792 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1793 struct lpfc_hba *phba = vport->phba;
1794
1795 /*
1796 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1797 * and continue discovery.
1798 */
1799 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001800 !(vport->fc_flag & FC_RSCN_MODE) &&
1801 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001802 lpfc_issue_reg_vpi(phba, vport);
1803 return;
1804 }
1805 /*
1806 * For SLI2, we need to set port_state to READY
1807 * and continue discovery.
1808 */
1809 if (vport->port_state < LPFC_VPORT_READY) {
1810 /* If we get here, there is nothing to ADISC */
1811 if (vport->port_type == LPFC_PHYSICAL_PORT)
1812 lpfc_issue_clear_la(phba, vport);
1813 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1814 vport->num_disc_nodes = 0;
1815 /* go thru NPR list, issue ELS PLOGIs */
1816 if (vport->fc_npr_cnt)
1817 lpfc_els_disc_plogi(vport);
1818 if (!vport->num_disc_nodes) {
1819 spin_lock_irq(shost->host_lock);
1820 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1821 spin_unlock_irq(shost->host_lock);
1822 lpfc_can_disctmo(vport);
1823 lpfc_end_rscn(vport);
1824 }
1825 }
1826 vport->port_state = LPFC_VPORT_READY;
1827 } else
1828 lpfc_rscn_disc(vport);
1829}
1830
1831/**
James Smart3621a712009-04-06 18:47:14 -04001832 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001833 * @vport: pointer to a host virtual N_Port data structure.
1834 *
1835 * This routine determines whether there are more ndlps on a @vport
1836 * node list need to have Address Discover (ADISC) issued. If so, it will
1837 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1838 * remaining nodes which need to have ADISC sent.
1839 **/
James Smart0ff10d42008-01-11 01:52:36 -05001840void
James Smart2e0fef82007-06-17 19:56:36 -05001841lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001842{
1843 int sentadisc;
1844
James Smart2e0fef82007-06-17 19:56:36 -05001845 if (vport->num_disc_nodes)
1846 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001847 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001848 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1849 "0210 Continue discovery with %d ADISCs to go "
1850 "Data: x%x x%x x%x\n",
1851 vport->num_disc_nodes, vport->fc_adisc_cnt,
1852 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001853 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001854 if (vport->fc_flag & FC_NLP_MORE) {
1855 lpfc_set_disctmo(vport);
1856 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1857 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001858 }
James Smart90160e02008-08-24 21:49:45 -04001859 if (!vport->num_disc_nodes)
1860 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001861 return;
1862}
1863
James Smarte59058c2008-08-24 21:49:00 -04001864/**
James Smart3621a712009-04-06 18:47:14 -04001865 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001866 * @phba: pointer to lpfc hba data structure.
1867 * @cmdiocb: pointer to lpfc command iocb data structure.
1868 * @rspiocb: pointer to lpfc response iocb data structure.
1869 *
1870 * This routine is the completion function for issuing the Address Discover
1871 * (ADISC) command. It first checks to see whether link went down during
1872 * the discovery process. If so, the node will be marked as node port
1873 * recovery for issuing discover IOCB by the link attention handler and
1874 * exit. Otherwise, the response status is checked. If error was reported
1875 * in the response status, the ADISC command shall be retried by invoking
1876 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1877 * the response status, the state machine is invoked to set transition
1878 * with respect to NLP_EVT_CMPL_ADISC event.
1879 **/
dea31012005-04-17 16:05:31 -05001880static void
James Smart2e0fef82007-06-17 19:56:36 -05001881lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1882 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001883{
James Smart2e0fef82007-06-17 19:56:36 -05001884 struct lpfc_vport *vport = cmdiocb->vport;
1885 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001886 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001887 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001888 int disc;
dea31012005-04-17 16:05:31 -05001889
1890 /* we pass cmdiocb to state machine which needs rspiocb as well */
1891 cmdiocb->context_un.rsp_iocb = rspiocb;
1892
1893 irsp = &(rspiocb->iocb);
1894 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001895
James Smart858c9f62007-06-17 19:56:39 -05001896 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1897 "ADISC cmpl: status:x%x/x%x did:x%x",
1898 irsp->ulpStatus, irsp->un.ulpWord[4],
1899 ndlp->nlp_DID);
1900
dea31012005-04-17 16:05:31 -05001901 /* Since ndlp can be freed in the disc state machine, note if this node
1902 * is being used during discovery.
1903 */
James Smart2e0fef82007-06-17 19:56:36 -05001904 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001905 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001906 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001907 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001908 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001909 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1910 "0104 ADISC completes to NPort x%x "
1911 "Data: x%x x%x x%x x%x x%x\n",
1912 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1913 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001914 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001915 if (lpfc_els_chk_latt(vport)) {
1916 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001917 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001918 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001919 goto out;
1920 }
1921
1922 if (irsp->ulpStatus) {
1923 /* Check for retry */
1924 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1925 /* ELS command is being retried */
1926 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001927 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001928 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001929 spin_unlock_irq(shost->host_lock);
1930 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001931 }
1932 goto out;
1933 }
1934 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001935 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1936 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1937 ndlp->nlp_DID, irsp->ulpStatus,
1938 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001939 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001940 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001941 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001942 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001943 } else
dea31012005-04-17 16:05:31 -05001944 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001945 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001946 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001947
James Smart90160e02008-08-24 21:49:45 -04001948 /* Check to see if there are more ADISCs to be sent */
1949 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001950 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001951out:
1952 lpfc_els_free_iocb(phba, cmdiocb);
1953 return;
1954}
1955
James Smarte59058c2008-08-24 21:49:00 -04001956/**
James Smart3621a712009-04-06 18:47:14 -04001957 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001958 * @vport: pointer to a virtual N_Port data structure.
1959 * @ndlp: pointer to a node-list data structure.
1960 * @retry: number of retries to the command IOCB.
1961 *
1962 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1963 * @vport. It prepares the payload of the ADISC ELS command, updates the
1964 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1965 * to issue the ADISC ELS command.
1966 *
1967 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1968 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1969 * will be stored into the context1 field of the IOCB for the completion
1970 * callback function to the ADISC ELS command.
1971 *
1972 * Return code
1973 * 0 - successfully issued adisc
1974 * 1 - failed to issue adisc
1975 **/
dea31012005-04-17 16:05:31 -05001976int
James Smart2e0fef82007-06-17 19:56:36 -05001977lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001978 uint8_t retry)
1979{
James Smart2e0fef82007-06-17 19:56:36 -05001980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1981 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001982 ADISC *ap;
1983 IOCB_t *icmd;
1984 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001985 uint8_t *pcmd;
1986 uint16_t cmdsize;
1987
James Smart92d7f7b2007-06-17 19:56:38 -05001988 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001989 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1990 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001991 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001992 return 1;
dea31012005-04-17 16:05:31 -05001993
1994 icmd = &elsiocb->iocb;
1995 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1996
1997 /* For ADISC request, remainder of payload is service parameters */
1998 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001999 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002000
2001 /* Fill in ADISC payload */
2002 ap = (ADISC *) pcmd;
2003 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002004 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2005 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002006 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002007
James Smart858c9f62007-06-17 19:56:39 -05002008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2009 "Issue ADISC: did:x%x",
2010 ndlp->nlp_DID, 0, 0);
2011
dea31012005-04-17 16:05:31 -05002012 phba->fc_stat.elsXmitADISC++;
2013 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002014 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002015 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002016 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002017 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2018 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002019 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002020 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002021 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002022 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002023 return 1;
dea31012005-04-17 16:05:31 -05002024 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002025 return 0;
dea31012005-04-17 16:05:31 -05002026}
2027
James Smarte59058c2008-08-24 21:49:00 -04002028/**
James Smart3621a712009-04-06 18:47:14 -04002029 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002030 * @phba: pointer to lpfc hba data structure.
2031 * @cmdiocb: pointer to lpfc command iocb data structure.
2032 * @rspiocb: pointer to lpfc response iocb data structure.
2033 *
2034 * This routine is the completion function for issuing the ELS Logout (LOGO)
2035 * command. If no error status was reported from the LOGO response, the
2036 * state machine of the associated ndlp shall be invoked for transition with
2037 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2038 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2039 **/
dea31012005-04-17 16:05:31 -05002040static void
James Smart2e0fef82007-06-17 19:56:36 -05002041lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2042 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002043{
James Smart2e0fef82007-06-17 19:56:36 -05002044 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2045 struct lpfc_vport *vport = ndlp->vport;
2046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002047 IOCB_t *irsp;
2048 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002049
2050 psli = &phba->sli;
2051 /* we pass cmdiocb to state machine which needs rspiocb as well */
2052 cmdiocb->context_un.rsp_iocb = rspiocb;
2053
2054 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002055 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002056 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002057 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002058
James Smart858c9f62007-06-17 19:56:39 -05002059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2060 "LOGO cmpl: status:x%x/x%x did:x%x",
2061 irsp->ulpStatus, irsp->un.ulpWord[4],
2062 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002063 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002064 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2065 "0105 LOGO completes to NPort x%x "
2066 "Data: x%x x%x x%x x%x\n",
2067 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2068 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002069 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002070 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002071 goto out;
2072
James Smart92d7f7b2007-06-17 19:56:38 -05002073 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2074 /* NLP_EVT_DEVICE_RM should unregister the RPI
2075 * which should abort all outstanding IOs.
2076 */
2077 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2078 NLP_EVT_DEVICE_RM);
2079 goto out;
2080 }
2081
dea31012005-04-17 16:05:31 -05002082 if (irsp->ulpStatus) {
2083 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002084 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002085 /* ELS command is being retried */
2086 goto out;
dea31012005-04-17 16:05:31 -05002087 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002088 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2089 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2090 ndlp->nlp_DID, irsp->ulpStatus,
2091 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002092 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002093 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002094 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002095 else
James Smart2e0fef82007-06-17 19:56:36 -05002096 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002097 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002098 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002099 /* Good status, call state machine.
2100 * This will unregister the rpi if needed.
2101 */
James Smart2e0fef82007-06-17 19:56:36 -05002102 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002103 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002104out:
2105 lpfc_els_free_iocb(phba, cmdiocb);
2106 return;
2107}
2108
James Smarte59058c2008-08-24 21:49:00 -04002109/**
James Smart3621a712009-04-06 18:47:14 -04002110 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002111 * @vport: pointer to a virtual N_Port data structure.
2112 * @ndlp: pointer to a node-list data structure.
2113 * @retry: number of retries to the command IOCB.
2114 *
2115 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2116 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2117 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2118 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2119 *
2120 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2121 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2122 * will be stored into the context1 field of the IOCB for the completion
2123 * callback function to the LOGO ELS command.
2124 *
2125 * Return code
2126 * 0 - successfully issued logo
2127 * 1 - failed to issue logo
2128 **/
dea31012005-04-17 16:05:31 -05002129int
James Smart2e0fef82007-06-17 19:56:36 -05002130lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002131 uint8_t retry)
2132{
James Smart2e0fef82007-06-17 19:56:36 -05002133 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2134 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002135 IOCB_t *icmd;
2136 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002137 uint8_t *pcmd;
2138 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002139 int rc;
dea31012005-04-17 16:05:31 -05002140
James Smart98c9ea52007-10-27 13:37:33 -04002141 spin_lock_irq(shost->host_lock);
2142 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2143 spin_unlock_irq(shost->host_lock);
2144 return 0;
2145 }
2146 spin_unlock_irq(shost->host_lock);
2147
James Smart92d7f7b2007-06-17 19:56:38 -05002148 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002149 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2150 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002151 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002152 return 1;
dea31012005-04-17 16:05:31 -05002153
2154 icmd = &elsiocb->iocb;
2155 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2156 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002157 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002158
2159 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002160 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002161 pcmd += sizeof(uint32_t);
2162 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002163
James Smart858c9f62007-06-17 19:56:39 -05002164 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2165 "Issue LOGO: did:x%x",
2166 ndlp->nlp_DID, 0, 0);
2167
dea31012005-04-17 16:05:31 -05002168 phba->fc_stat.elsXmitLOGO++;
2169 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002170 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002171 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002172 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002173 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002174
2175 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002176 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002177 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002178 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002179 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002180 return 1;
dea31012005-04-17 16:05:31 -05002181 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002182 return 0;
dea31012005-04-17 16:05:31 -05002183}
2184
James Smarte59058c2008-08-24 21:49:00 -04002185/**
James Smart3621a712009-04-06 18:47:14 -04002186 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002187 * @phba: pointer to lpfc hba data structure.
2188 * @cmdiocb: pointer to lpfc command iocb data structure.
2189 * @rspiocb: pointer to lpfc response iocb data structure.
2190 *
2191 * This routine is a generic completion callback function for ELS commands.
2192 * Specifically, it is the callback function which does not need to perform
2193 * any command specific operations. It is currently used by the ELS command
2194 * issuing routines for the ELS State Change Request (SCR),
2195 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2196 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2197 * certain debug loggings, this callback function simply invokes the
2198 * lpfc_els_chk_latt() routine to check whether link went down during the
2199 * discovery process.
2200 **/
dea31012005-04-17 16:05:31 -05002201static void
James Smart2e0fef82007-06-17 19:56:36 -05002202lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2203 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002204{
James Smart2e0fef82007-06-17 19:56:36 -05002205 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002206 IOCB_t *irsp;
2207
2208 irsp = &rspiocb->iocb;
2209
James Smart858c9f62007-06-17 19:56:39 -05002210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2211 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2212 irsp->ulpStatus, irsp->un.ulpWord[4],
2213 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002214 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002215 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2216 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2217 irsp->ulpIoTag, irsp->ulpStatus,
2218 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002219 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002220 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002221 lpfc_els_free_iocb(phba, cmdiocb);
2222 return;
2223}
2224
James Smarte59058c2008-08-24 21:49:00 -04002225/**
James Smart3621a712009-04-06 18:47:14 -04002226 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002227 * @vport: pointer to a host virtual N_Port data structure.
2228 * @nportid: N_Port identifier to the remote node.
2229 * @retry: number of retries to the command IOCB.
2230 *
2231 * This routine issues a State Change Request (SCR) to a fabric node
2232 * on a @vport. The remote node @nportid is passed into the function. It
2233 * first search the @vport node list to find the matching ndlp. If no such
2234 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2235 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2236 * routine is invoked to send the SCR IOCB.
2237 *
2238 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2239 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2240 * will be stored into the context1 field of the IOCB for the completion
2241 * callback function to the SCR ELS command.
2242 *
2243 * Return code
2244 * 0 - Successfully issued scr command
2245 * 1 - Failed to issue scr command
2246 **/
dea31012005-04-17 16:05:31 -05002247int
James Smart2e0fef82007-06-17 19:56:36 -05002248lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002249{
James Smart2e0fef82007-06-17 19:56:36 -05002250 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002251 IOCB_t *icmd;
2252 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002253 struct lpfc_sli *psli;
2254 uint8_t *pcmd;
2255 uint16_t cmdsize;
2256 struct lpfc_nodelist *ndlp;
2257
2258 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002259 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002260
James Smarte47c9092008-02-08 18:49:26 -05002261 ndlp = lpfc_findnode_did(vport, nportid);
2262 if (!ndlp) {
2263 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2264 if (!ndlp)
2265 return 1;
2266 lpfc_nlp_init(vport, ndlp, nportid);
2267 lpfc_enqueue_node(vport, ndlp);
2268 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2269 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2270 if (!ndlp)
2271 return 1;
2272 }
dea31012005-04-17 16:05:31 -05002273
James Smart2e0fef82007-06-17 19:56:36 -05002274 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2275 ndlp->nlp_DID, ELS_CMD_SCR);
2276
James Smart488d1462006-03-07 15:02:37 -05002277 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002278 /* This will trigger the release of the node just
2279 * allocated
2280 */
James Smart329f9bc2007-04-25 09:53:01 -04002281 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002282 return 1;
dea31012005-04-17 16:05:31 -05002283 }
2284
2285 icmd = &elsiocb->iocb;
2286 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2287
2288 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002289 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002290
2291 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002292 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002293 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2294
James Smart858c9f62007-06-17 19:56:39 -05002295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2296 "Issue SCR: did:x%x",
2297 ndlp->nlp_DID, 0, 0);
2298
dea31012005-04-17 16:05:31 -05002299 phba->fc_stat.elsXmitSCR++;
2300 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002301 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2302 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002303 /* The additional lpfc_nlp_put will cause the following
2304 * lpfc_els_free_iocb routine to trigger the rlease of
2305 * the node.
2306 */
James Smart329f9bc2007-04-25 09:53:01 -04002307 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002308 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002309 return 1;
dea31012005-04-17 16:05:31 -05002310 }
James Smartfa4066b2008-01-11 01:53:27 -05002311 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2312 * trigger the release of node.
2313 */
James Smart329f9bc2007-04-25 09:53:01 -04002314 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002315 return 0;
dea31012005-04-17 16:05:31 -05002316}
2317
James Smarte59058c2008-08-24 21:49:00 -04002318/**
James Smart3621a712009-04-06 18:47:14 -04002319 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002320 * @vport: pointer to a host virtual N_Port data structure.
2321 * @nportid: N_Port identifier to the remote node.
2322 * @retry: number of retries to the command IOCB.
2323 *
2324 * This routine issues a Fibre Channel Address Resolution Response
2325 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2326 * is passed into the function. It first search the @vport node list to find
2327 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2328 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2329 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2330 *
2331 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2332 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2333 * will be stored into the context1 field of the IOCB for the completion
2334 * callback function to the PARPR ELS command.
2335 *
2336 * Return code
2337 * 0 - Successfully issued farpr command
2338 * 1 - Failed to issue farpr command
2339 **/
dea31012005-04-17 16:05:31 -05002340static int
James Smart2e0fef82007-06-17 19:56:36 -05002341lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002342{
James Smart2e0fef82007-06-17 19:56:36 -05002343 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002344 IOCB_t *icmd;
2345 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002346 struct lpfc_sli *psli;
2347 FARP *fp;
2348 uint8_t *pcmd;
2349 uint32_t *lp;
2350 uint16_t cmdsize;
2351 struct lpfc_nodelist *ondlp;
2352 struct lpfc_nodelist *ndlp;
2353
2354 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002355 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002356
James Smarte47c9092008-02-08 18:49:26 -05002357 ndlp = lpfc_findnode_did(vport, nportid);
2358 if (!ndlp) {
2359 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2360 if (!ndlp)
2361 return 1;
2362 lpfc_nlp_init(vport, ndlp, nportid);
2363 lpfc_enqueue_node(vport, ndlp);
2364 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2365 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2366 if (!ndlp)
2367 return 1;
2368 }
James Smart2e0fef82007-06-17 19:56:36 -05002369
2370 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2371 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002372 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002373 /* This will trigger the release of the node just
2374 * allocated
2375 */
James Smart329f9bc2007-04-25 09:53:01 -04002376 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002377 return 1;
dea31012005-04-17 16:05:31 -05002378 }
2379
2380 icmd = &elsiocb->iocb;
2381 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2382
2383 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002384 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002385
2386 /* Fill in FARPR payload */
2387 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002388 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002389 lp = (uint32_t *) pcmd;
2390 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002391 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002392 fp->Rflags = 0;
2393 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2394
James Smart92d7f7b2007-06-17 19:56:38 -05002395 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2396 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002397 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002398 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002399 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002400 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002401 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002402 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002403 }
2404
James Smart858c9f62007-06-17 19:56:39 -05002405 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2406 "Issue FARPR: did:x%x",
2407 ndlp->nlp_DID, 0, 0);
2408
dea31012005-04-17 16:05:31 -05002409 phba->fc_stat.elsXmitFARPR++;
2410 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002411 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2412 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002413 /* The additional lpfc_nlp_put will cause the following
2414 * lpfc_els_free_iocb routine to trigger the release of
2415 * the node.
2416 */
James Smart329f9bc2007-04-25 09:53:01 -04002417 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002418 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002419 return 1;
dea31012005-04-17 16:05:31 -05002420 }
James Smartfa4066b2008-01-11 01:53:27 -05002421 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2422 * trigger the release of the node.
2423 */
James Smart329f9bc2007-04-25 09:53:01 -04002424 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002425 return 0;
dea31012005-04-17 16:05:31 -05002426}
2427
James Smarte59058c2008-08-24 21:49:00 -04002428/**
James Smart3621a712009-04-06 18:47:14 -04002429 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002430 * @vport: pointer to a host virtual N_Port data structure.
2431 * @nlp: pointer to a node-list data structure.
2432 *
2433 * This routine cancels the timer with a delayed IOCB-command retry for
2434 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2435 * removes the ELS retry event if it presents. In addition, if the
2436 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2437 * commands are sent for the @vport's nodes that require issuing discovery
2438 * ADISC.
2439 **/
dea31012005-04-17 16:05:31 -05002440void
James Smart2e0fef82007-06-17 19:56:36 -05002441lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002442{
James Smart2e0fef82007-06-17 19:56:36 -05002443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002444 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002445
James Smart0d2b6b82008-06-14 22:52:47 -04002446 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2447 return;
James Smart2e0fef82007-06-17 19:56:36 -05002448 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002449 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002450 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002451 del_timer_sync(&nlp->nlp_delayfunc);
2452 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002453 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002454 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002455 /* Decrement nlp reference count held for the delayed retry */
2456 evtp = &nlp->els_retry_evt;
2457 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2458 }
James Smartfdcebe22006-03-07 15:04:01 -05002459 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002460 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002461 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002462 spin_unlock_irq(shost->host_lock);
2463 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002464 if (vport->port_state < LPFC_VPORT_READY) {
2465 /* Check if there are more ADISCs to be sent */
2466 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002467 } else {
2468 /* Check if there are more PLOGIs to be sent */
2469 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002470 if (vport->num_disc_nodes == 0) {
2471 spin_lock_irq(shost->host_lock);
2472 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2473 spin_unlock_irq(shost->host_lock);
2474 lpfc_can_disctmo(vport);
2475 lpfc_end_rscn(vport);
2476 }
James Smartfdcebe22006-03-07 15:04:01 -05002477 }
2478 }
2479 }
2480 return;
2481}
2482
James Smarte59058c2008-08-24 21:49:00 -04002483/**
James Smart3621a712009-04-06 18:47:14 -04002484 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002485 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2486 *
2487 * This routine is invoked by the ndlp delayed-function timer to check
2488 * whether there is any pending ELS retry event(s) with the node. If not, it
2489 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2490 * adds the delayed events to the HBA work list and invokes the
2491 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2492 * event. Note that lpfc_nlp_get() is called before posting the event to
2493 * the work list to hold reference count of ndlp so that it guarantees the
2494 * reference to ndlp will still be available when the worker thread gets
2495 * to the event associated with the ndlp.
2496 **/
James Smartfdcebe22006-03-07 15:04:01 -05002497void
dea31012005-04-17 16:05:31 -05002498lpfc_els_retry_delay(unsigned long ptr)
2499{
James Smart2e0fef82007-06-17 19:56:36 -05002500 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2501 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002502 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002503 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002504 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002505
James Smart92d7f7b2007-06-17 19:56:38 -05002506 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002507 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002508 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002509 return;
2510 }
2511
James Smartfa4066b2008-01-11 01:53:27 -05002512 /* We need to hold the node by incrementing the reference
2513 * count until the queued work is done
2514 */
2515 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002516 if (evtp->evt_arg1) {
2517 evtp->evt = LPFC_EVT_ELS_RETRY;
2518 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002519 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002520 }
James Smart92d7f7b2007-06-17 19:56:38 -05002521 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002522 return;
2523}
2524
James Smarte59058c2008-08-24 21:49:00 -04002525/**
James Smart3621a712009-04-06 18:47:14 -04002526 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002527 * @ndlp: pointer to a node-list data structure.
2528 *
2529 * This routine is the worker-thread handler for processing the @ndlp delayed
2530 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2531 * the last ELS command from the associated ndlp and invokes the proper ELS
2532 * function according to the delayed ELS command to retry the command.
2533 **/
dea31012005-04-17 16:05:31 -05002534void
2535lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2536{
James Smart2e0fef82007-06-17 19:56:36 -05002537 struct lpfc_vport *vport = ndlp->vport;
2538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2539 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002540
James Smart2e0fef82007-06-17 19:56:36 -05002541 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002542 did = ndlp->nlp_DID;
2543 cmd = ndlp->nlp_last_elscmd;
2544 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002545
2546 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002547 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002548 return;
2549 }
2550
2551 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002552 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002553 /*
2554 * If a discovery event readded nlp_delayfunc after timer
2555 * firing and before processing the timer, cancel the
2556 * nlp_delayfunc.
2557 */
2558 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002559 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002560 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002561
2562 switch (cmd) {
2563 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002564 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002565 break;
2566 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002567 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002568 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002569 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002570 }
dea31012005-04-17 16:05:31 -05002571 break;
2572 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002573 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002574 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002575 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002576 }
dea31012005-04-17 16:05:31 -05002577 break;
2578 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002579 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002580 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002581 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002582 }
dea31012005-04-17 16:05:31 -05002583 break;
2584 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002585 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002586 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002587 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002588 }
dea31012005-04-17 16:05:31 -05002589 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002590 case ELS_CMD_FDISC:
2591 lpfc_issue_els_fdisc(vport, ndlp, retry);
2592 break;
dea31012005-04-17 16:05:31 -05002593 }
2594 return;
2595}
2596
James Smarte59058c2008-08-24 21:49:00 -04002597/**
James Smart3621a712009-04-06 18:47:14 -04002598 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002599 * @phba: pointer to lpfc hba data structure.
2600 * @cmdiocb: pointer to lpfc command iocb data structure.
2601 * @rspiocb: pointer to lpfc response iocb data structure.
2602 *
2603 * This routine makes a retry decision on an ELS command IOCB, which has
2604 * failed. The following ELS IOCBs use this function for retrying the command
2605 * when previously issued command responsed with error status: FLOGI, PLOGI,
2606 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2607 * returned error status, it makes the decision whether a retry shall be
2608 * issued for the command, and whether a retry shall be made immediately or
2609 * delayed. In the former case, the corresponding ELS command issuing-function
2610 * is called to retry the command. In the later case, the ELS command shall
2611 * be posted to the ndlp delayed event and delayed function timer set to the
2612 * ndlp for the delayed command issusing.
2613 *
2614 * Return code
2615 * 0 - No retry of els command is made
2616 * 1 - Immediate or delayed retry of els command is made
2617 **/
dea31012005-04-17 16:05:31 -05002618static int
James Smart2e0fef82007-06-17 19:56:36 -05002619lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2620 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002621{
James Smart2e0fef82007-06-17 19:56:36 -05002622 struct lpfc_vport *vport = cmdiocb->vport;
2623 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2624 IOCB_t *irsp = &rspiocb->iocb;
2625 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2626 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002627 uint32_t *elscmd;
2628 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002629 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002630 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002631 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002632 uint32_t did;
dea31012005-04-17 16:05:31 -05002633
James Smart488d1462006-03-07 15:02:37 -05002634
dea31012005-04-17 16:05:31 -05002635 /* Note: context2 may be 0 for internal driver abort
2636 * of delays ELS command.
2637 */
2638
2639 if (pcmd && pcmd->virt) {
2640 elscmd = (uint32_t *) (pcmd->virt);
2641 cmd = *elscmd++;
2642 }
2643
James Smarte47c9092008-02-08 18:49:26 -05002644 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002645 did = ndlp->nlp_DID;
2646 else {
2647 /* We should only hit this case for retrying PLOGI */
2648 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002649 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002650 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2651 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002652 return 1;
2653 }
2654
James Smart858c9f62007-06-17 19:56:39 -05002655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2656 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2657 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2658
dea31012005-04-17 16:05:31 -05002659 switch (irsp->ulpStatus) {
2660 case IOSTAT_FCP_RSP_ERROR:
2661 case IOSTAT_REMOTE_STOP:
2662 break;
2663
2664 case IOSTAT_LOCAL_REJECT:
2665 switch ((irsp->un.ulpWord[4] & 0xff)) {
2666 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002667 if (cmd == ELS_CMD_FLOGI) {
2668 if (PCI_DEVICE_ID_HORNET ==
2669 phba->pcidev->device) {
2670 phba->fc_topology = TOPOLOGY_LOOP;
2671 phba->pport->fc_myDID = 0;
2672 phba->alpa_map[0] = 0;
2673 phba->alpa_map[1] = 0;
2674 }
2675 }
James Smart2e0fef82007-06-17 19:56:36 -05002676 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002677 delay = 1000;
dea31012005-04-17 16:05:31 -05002678 retry = 1;
2679 break;
2680
James Smart92d7f7b2007-06-17 19:56:38 -05002681 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002682 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2683 "0124 Retry illegal cmd x%x "
2684 "retry:x%x delay:x%x\n",
2685 cmd, cmdiocb->retry, delay);
2686 retry = 1;
2687 /* All command's retry policy */
2688 maxretry = 8;
2689 if (cmdiocb->retry > 2)
2690 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002691 break;
2692
dea31012005-04-17 16:05:31 -05002693 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002694 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002695 retry = 1;
2696 if (cmdiocb->retry > 100)
2697 delay = 100;
2698 maxretry = 250;
2699 break;
2700
2701 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002702 delay = 100;
dea31012005-04-17 16:05:31 -05002703 retry = 1;
2704 break;
2705
James Smart858c9f62007-06-17 19:56:39 -05002706 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002707 case IOERR_INVALID_RPI:
2708 retry = 1;
2709 break;
2710 }
2711 break;
2712
2713 case IOSTAT_NPORT_RJT:
2714 case IOSTAT_FABRIC_RJT:
2715 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2716 retry = 1;
2717 break;
2718 }
2719 break;
2720
2721 case IOSTAT_NPORT_BSY:
2722 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002723 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002724 retry = 1;
2725 break;
2726
2727 case IOSTAT_LS_RJT:
2728 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2729 /* Added for Vendor specifc support
2730 * Just keep retrying for these Rsn / Exp codes
2731 */
2732 switch (stat.un.b.lsRjtRsnCode) {
2733 case LSRJT_UNABLE_TPC:
2734 if (stat.un.b.lsRjtRsnCodeExp ==
2735 LSEXP_CMD_IN_PROGRESS) {
2736 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002737 delay = 1000;
dea31012005-04-17 16:05:31 -05002738 maxretry = 48;
2739 }
2740 retry = 1;
2741 break;
2742 }
James Smartffc95492010-06-07 15:23:17 -04002743 if (stat.un.b.lsRjtRsnCodeExp ==
2744 LSEXP_CANT_GIVE_DATA) {
2745 if (cmd == ELS_CMD_PLOGI) {
2746 delay = 1000;
2747 maxretry = 48;
2748 }
2749 retry = 1;
2750 break;
2751 }
dea31012005-04-17 16:05:31 -05002752 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002753 delay = 1000;
dea31012005-04-17 16:05:31 -05002754 maxretry = lpfc_max_els_tries + 1;
2755 retry = 1;
2756 break;
2757 }
James Smart92d7f7b2007-06-17 19:56:38 -05002758 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2759 (cmd == ELS_CMD_FDISC) &&
2760 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002761 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2762 "0125 FDISC Failed (x%x). "
2763 "Fabric out of resources\n",
2764 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002765 lpfc_vport_set_state(vport,
2766 FC_VPORT_NO_FABRIC_RSCS);
2767 }
dea31012005-04-17 16:05:31 -05002768 break;
2769
2770 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002771 if ((cmd == ELS_CMD_PLOGI) ||
2772 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002773 delay = 1000;
dea31012005-04-17 16:05:31 -05002774 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002775 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002776 /* FDISC retry policy */
2777 maxretry = 48;
2778 if (cmdiocb->retry >= 32)
2779 delay = 1000;
dea31012005-04-17 16:05:31 -05002780 }
2781 retry = 1;
2782 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002783
2784 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002785 /* There are some cases where switches return this
2786 * error when they are not ready and should be returning
2787 * Logical Busy. We should delay every time.
2788 */
2789 if (cmd == ELS_CMD_FDISC &&
2790 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2791 maxretry = 3;
2792 delay = 1000;
2793 retry = 1;
2794 break;
2795 }
James Smart92d7f7b2007-06-17 19:56:38 -05002796 case LSRJT_PROTOCOL_ERR:
2797 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2798 (cmd == ELS_CMD_FDISC) &&
2799 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2800 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2801 ) {
James Smarte8b62012007-08-02 11:10:09 -04002802 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002803 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002804 "Fabric Detected Bad WWN\n",
2805 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002806 lpfc_vport_set_state(vport,
2807 FC_VPORT_FABRIC_REJ_WWN);
2808 }
2809 break;
dea31012005-04-17 16:05:31 -05002810 }
2811 break;
2812
2813 case IOSTAT_INTERMED_RSP:
2814 case IOSTAT_BA_RJT:
2815 break;
2816
2817 default:
2818 break;
2819 }
2820
James Smart488d1462006-03-07 15:02:37 -05002821 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002822 retry = 1;
dea31012005-04-17 16:05:31 -05002823
James Smart695a8142010-01-26 23:08:03 -05002824 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002825 (phba->fc_topology != TOPOLOGY_LOOP) &&
2826 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002827 /* FLOGI retry policy */
2828 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002829 /* retry forever */
2830 maxretry = 0;
2831 if (cmdiocb->retry >= 100)
2832 delay = 5000;
2833 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002834 delay = 1000;
2835 }
2836
James Smart6669f9b2009-10-02 15:16:45 -04002837 cmdiocb->retry++;
2838 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002839 phba->fc_stat.elsRetryExceeded++;
2840 retry = 0;
2841 }
2842
James Smarted957682007-06-17 19:56:37 -05002843 if ((vport->load_flag & FC_UNLOADING) != 0)
2844 retry = 0;
2845
dea31012005-04-17 16:05:31 -05002846 if (retry) {
2847
2848 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002849 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2850 "0107 Retry ELS command x%x to remote "
2851 "NPORT x%x Data: x%x x%x\n",
2852 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002853
James Smart858c9f62007-06-17 19:56:39 -05002854 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2855 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2856 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2857 /* Don't reset timer for no resources */
2858
dea31012005-04-17 16:05:31 -05002859 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002860 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002861 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002862 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002863 }
2864
2865 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002866 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002867 phba->fc_stat.elsDelayRetry++;
2868 ndlp->nlp_retry = cmdiocb->retry;
2869
James Smart92d7f7b2007-06-17 19:56:38 -05002870 /* delay is specified in milliseconds */
2871 mod_timer(&ndlp->nlp_delayfunc,
2872 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002873 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002874 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002875 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002876
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002877 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002878 if (cmd == ELS_CMD_PRLI)
2879 lpfc_nlp_set_state(vport, ndlp,
2880 NLP_STE_REG_LOGIN_ISSUE);
2881 else
2882 lpfc_nlp_set_state(vport, ndlp,
2883 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002884 ndlp->nlp_last_elscmd = cmd;
2885
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002886 return 1;
dea31012005-04-17 16:05:31 -05002887 }
2888 switch (cmd) {
2889 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002890 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002891 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002892 case ELS_CMD_FDISC:
2893 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2894 return 1;
dea31012005-04-17 16:05:31 -05002895 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002896 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002897 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002898 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002899 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002900 }
James Smart2e0fef82007-06-17 19:56:36 -05002901 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002902 return 1;
dea31012005-04-17 16:05:31 -05002903 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002904 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002905 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2906 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002907 return 1;
dea31012005-04-17 16:05:31 -05002908 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002909 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002910 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2911 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002912 return 1;
dea31012005-04-17 16:05:31 -05002913 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002914 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002915 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2916 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002917 return 1;
dea31012005-04-17 16:05:31 -05002918 }
2919 }
dea31012005-04-17 16:05:31 -05002920 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002921 if (logerr) {
2922 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2923 "0137 No retry ELS command x%x to remote "
2924 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2925 cmd, did, irsp->ulpStatus,
2926 irsp->un.ulpWord[4]);
2927 }
2928 else {
2929 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002930 "0108 No retry ELS command x%x to remote "
2931 "NPORT x%x Retried:%d Error:x%x/%x\n",
2932 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2933 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002934 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002935 return 0;
dea31012005-04-17 16:05:31 -05002936}
2937
James Smarte59058c2008-08-24 21:49:00 -04002938/**
James Smart3621a712009-04-06 18:47:14 -04002939 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002940 * @phba: pointer to lpfc hba data structure.
2941 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2942 *
2943 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2944 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2945 * checks to see whether there is a lpfc DMA buffer associated with the
2946 * response of the command IOCB. If so, it will be released before releasing
2947 * the lpfc DMA buffer associated with the IOCB itself.
2948 *
2949 * Return code
2950 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2951 **/
James Smart09372822008-01-11 01:52:54 -05002952static int
James Smart87af33f2007-10-27 13:37:43 -04002953lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2954{
2955 struct lpfc_dmabuf *buf_ptr;
2956
James Smarte59058c2008-08-24 21:49:00 -04002957 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002958 if (!list_empty(&buf_ptr1->list)) {
2959 list_remove_head(&buf_ptr1->list, buf_ptr,
2960 struct lpfc_dmabuf,
2961 list);
2962 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2963 kfree(buf_ptr);
2964 }
2965 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2966 kfree(buf_ptr1);
2967 return 0;
2968}
2969
James Smarte59058c2008-08-24 21:49:00 -04002970/**
James Smart3621a712009-04-06 18:47:14 -04002971 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002972 * @phba: pointer to lpfc hba data structure.
2973 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2974 *
2975 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2976 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2977 * pool.
2978 *
2979 * Return code
2980 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2981 **/
James Smart09372822008-01-11 01:52:54 -05002982static int
James Smart87af33f2007-10-27 13:37:43 -04002983lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2984{
2985 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2986 kfree(buf_ptr);
2987 return 0;
2988}
2989
James Smarte59058c2008-08-24 21:49:00 -04002990/**
James Smart3621a712009-04-06 18:47:14 -04002991 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002992 * @phba: pointer to lpfc hba data structure.
2993 * @elsiocb: pointer to lpfc els command iocb data structure.
2994 *
2995 * This routine frees a command IOCB and its associated resources. The
2996 * command IOCB data structure contains the reference to various associated
2997 * resources, these fields must be set to NULL if the associated reference
2998 * not present:
2999 * context1 - reference to ndlp
3000 * context2 - reference to cmd
3001 * context2->next - reference to rsp
3002 * context3 - reference to bpl
3003 *
3004 * It first properly decrements the reference count held on ndlp for the
3005 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3006 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3007 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3008 * adds the DMA buffer the @phba data structure for the delayed release.
3009 * If reference to the Buffer Pointer List (BPL) is present, the
3010 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3011 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3012 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3013 *
3014 * Return code
3015 * 0 - Success (currently, always return 0)
3016 **/
James Smart87af33f2007-10-27 13:37:43 -04003017int
James Smart329f9bc2007-04-25 09:53:01 -04003018lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003019{
3020 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003021 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003022
James Smarta8adb832007-10-27 13:37:53 -04003023 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3024 if (ndlp) {
3025 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3026 lpfc_nlp_put(ndlp);
3027
3028 /* If the ndlp is not being used by another discovery
3029 * thread, free it.
3030 */
3031 if (!lpfc_nlp_not_used(ndlp)) {
3032 /* If ndlp is being used by another discovery
3033 * thread, just clear NLP_DEFER_RM
3034 */
3035 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3036 }
3037 }
3038 else
3039 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003040 elsiocb->context1 = NULL;
3041 }
dea31012005-04-17 16:05:31 -05003042 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3043 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003044 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3045 /* Firmware could still be in progress of DMAing
3046 * payload, so don't free data buffer till after
3047 * a hbeat.
3048 */
3049 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3050 buf_ptr = elsiocb->context2;
3051 elsiocb->context2 = NULL;
3052 if (buf_ptr) {
3053 buf_ptr1 = NULL;
3054 spin_lock_irq(&phba->hbalock);
3055 if (!list_empty(&buf_ptr->list)) {
3056 list_remove_head(&buf_ptr->list,
3057 buf_ptr1, struct lpfc_dmabuf,
3058 list);
3059 INIT_LIST_HEAD(&buf_ptr1->list);
3060 list_add_tail(&buf_ptr1->list,
3061 &phba->elsbuf);
3062 phba->elsbuf_cnt++;
3063 }
3064 INIT_LIST_HEAD(&buf_ptr->list);
3065 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3066 phba->elsbuf_cnt++;
3067 spin_unlock_irq(&phba->hbalock);
3068 }
3069 } else {
3070 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3071 lpfc_els_free_data(phba, buf_ptr1);
3072 }
dea31012005-04-17 16:05:31 -05003073 }
3074
3075 if (elsiocb->context3) {
3076 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003077 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003078 }
James Bottomley604a3e32005-10-29 10:28:33 -05003079 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003080 return 0;
3081}
3082
James Smarte59058c2008-08-24 21:49:00 -04003083/**
James Smart3621a712009-04-06 18:47:14 -04003084 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003085 * @phba: pointer to lpfc hba data structure.
3086 * @cmdiocb: pointer to lpfc command iocb data structure.
3087 * @rspiocb: pointer to lpfc response iocb data structure.
3088 *
3089 * This routine is the completion callback function to the Logout (LOGO)
3090 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3091 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3092 * release the ndlp if it has the last reference remaining (reference count
3093 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3094 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3095 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3096 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3097 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3098 * IOCB data structure.
3099 **/
dea31012005-04-17 16:05:31 -05003100static void
James Smart2e0fef82007-06-17 19:56:36 -05003101lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3102 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003103{
James Smart2e0fef82007-06-17 19:56:36 -05003104 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3105 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003106 IOCB_t *irsp;
3107
3108 irsp = &rspiocb->iocb;
3109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3110 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3111 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003112 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003113 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3114 "0109 ACC to LOGO completes to NPort x%x "
3115 "Data: x%x x%x x%x\n",
3116 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3117 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003118
3119 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3120 /* NPort Recovery mode or node is just allocated */
3121 if (!lpfc_nlp_not_used(ndlp)) {
3122 /* If the ndlp is being used by another discovery
3123 * thread, just unregister the RPI.
3124 */
3125 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003126 } else {
3127 /* Indicate the node has already released, should
3128 * not reference to it from within lpfc_els_free_iocb.
3129 */
3130 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003131 }
dea31012005-04-17 16:05:31 -05003132 }
3133 lpfc_els_free_iocb(phba, cmdiocb);
3134 return;
3135}
3136
James Smarte59058c2008-08-24 21:49:00 -04003137/**
James Smart3621a712009-04-06 18:47:14 -04003138 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003139 * @phba: pointer to lpfc hba data structure.
3140 * @pmb: pointer to the driver internal queue element for mailbox command.
3141 *
3142 * This routine is the completion callback function for unregister default
3143 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3144 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3145 * decrements the ndlp reference count held for this completion callback
3146 * function. After that, it invokes the lpfc_nlp_not_used() to check
3147 * whether there is only one reference left on the ndlp. If so, it will
3148 * perform one more decrement and trigger the release of the ndlp.
3149 **/
James Smart858c9f62007-06-17 19:56:39 -05003150void
3151lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3152{
3153 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3154 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3155
James Smart6fb120a2009-05-22 14:52:59 -04003156 /*
3157 * This routine is used to register and unregister in previous SLI
3158 * modes.
3159 */
3160 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3161 (phba->sli_rev == LPFC_SLI_REV4))
3162 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3163
James Smart858c9f62007-06-17 19:56:39 -05003164 pmb->context1 = NULL;
3165 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3166 kfree(mp);
3167 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003168 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003169 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003170 /* This is the end of the default RPI cleanup logic for this
3171 * ndlp. If no other discovery threads are using this ndlp.
3172 * we should free all resources associated with it.
3173 */
3174 lpfc_nlp_not_used(ndlp);
3175 }
James Smart3772a992009-05-22 14:50:54 -04003176
James Smart858c9f62007-06-17 19:56:39 -05003177 return;
3178}
3179
James Smarte59058c2008-08-24 21:49:00 -04003180/**
James Smart3621a712009-04-06 18:47:14 -04003181 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003182 * @phba: pointer to lpfc hba data structure.
3183 * @cmdiocb: pointer to lpfc command iocb data structure.
3184 * @rspiocb: pointer to lpfc response iocb data structure.
3185 *
3186 * This routine is the completion callback function for ELS Response IOCB
3187 * command. In normal case, this callback function just properly sets the
3188 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3189 * field in the command IOCB is not NULL, the referred mailbox command will
3190 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3191 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3192 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3193 * routine shall be invoked trying to release the ndlp if no other threads
3194 * are currently referring it.
3195 **/
dea31012005-04-17 16:05:31 -05003196static void
James Smart858c9f62007-06-17 19:56:39 -05003197lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003198 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003199{
James Smart2e0fef82007-06-17 19:56:36 -05003200 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3201 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3202 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003203 IOCB_t *irsp;
3204 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003205 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003206 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003207 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003208
James Smart33ccf8d2006-08-17 11:57:58 -04003209 irsp = &rspiocb->iocb;
3210
dea31012005-04-17 16:05:31 -05003211 if (cmdiocb->context_un.mbox)
3212 mbox = cmdiocb->context_un.mbox;
3213
James Smartfa4066b2008-01-11 01:53:27 -05003214 /* First determine if this is a LS_RJT cmpl. Note, this callback
3215 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3216 */
James Smart87af33f2007-10-27 13:37:43 -04003217 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003218 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3219 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003220 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003221 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003222 */
3223 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3224 ls_rjt = 1;
3225 }
3226
dea31012005-04-17 16:05:31 -05003227 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003228 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003229 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003230 mp = (struct lpfc_dmabuf *) mbox->context1;
3231 if (mp) {
3232 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3233 kfree(mp);
3234 }
James Smart329f9bc2007-04-25 09:53:01 -04003235 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003236 }
James Smart58da1ff2008-04-07 10:15:56 -04003237 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3238 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003239 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003240 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003241 /* Indicate the node has already released,
3242 * should not reference to it from within
3243 * the routine lpfc_els_free_iocb.
3244 */
3245 cmdiocb->context1 = NULL;
3246 }
dea31012005-04-17 16:05:31 -05003247 goto out;
3248 }
3249
James Smart858c9f62007-06-17 19:56:39 -05003250 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003251 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003252 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003253 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003254 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003255 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3256 "0110 ELS response tag x%x completes "
3257 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3258 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3259 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3260 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3261 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003262 if (mbox) {
3263 if ((rspiocb->iocb.ulpStatus == 0)
3264 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003265 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003266 /* Increment reference count to ndlp to hold the
3267 * reference to ndlp for the callback function.
3268 */
James Smart329f9bc2007-04-25 09:53:01 -04003269 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003270 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003271 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3272 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3273 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3274 }
3275 else {
3276 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3277 ndlp->nlp_prev_state = ndlp->nlp_state;
3278 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003279 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003280 }
James Smart0b727fe2007-10-27 13:37:25 -04003281 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003282 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003283 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003284 else
3285 /* Decrement the ndlp reference count we
3286 * set for this failed mailbox command.
3287 */
3288 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003289
3290 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3291 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3292 "0138 ELS rsp: Cannot issue reg_login for x%x "
3293 "Data: x%x x%x x%x\n",
3294 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3295 ndlp->nlp_rpi);
3296
James Smartfa4066b2008-01-11 01:53:27 -05003297 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003298 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003299 /* Indicate node has already been released,
3300 * should not reference to it from within
3301 * the routine lpfc_els_free_iocb.
3302 */
3303 cmdiocb->context1 = NULL;
3304 }
dea31012005-04-17 16:05:31 -05003305 } else {
James Smart858c9f62007-06-17 19:56:39 -05003306 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3307 if (!lpfc_error_lost_link(irsp) &&
3308 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003309 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003310 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003311 /* Indicate node has already been
3312 * released, should not reference
3313 * to it from within the routine
3314 * lpfc_els_free_iocb.
3315 */
3316 cmdiocb->context1 = NULL;
3317 }
dea31012005-04-17 16:05:31 -05003318 }
3319 }
James Smart14691152006-12-02 13:34:28 -05003320 mp = (struct lpfc_dmabuf *) mbox->context1;
3321 if (mp) {
3322 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3323 kfree(mp);
3324 }
3325 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003326 }
3327out:
James Smart58da1ff2008-04-07 10:15:56 -04003328 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003329 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003330 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003331 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003332
3333 /* If the node is not being used by another discovery thread,
3334 * and we are sending a reject, we are done with it.
3335 * Release driver reference count here and free associated
3336 * resources.
3337 */
3338 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003339 if (lpfc_nlp_not_used(ndlp))
3340 /* Indicate node has already been released,
3341 * should not reference to it from within
3342 * the routine lpfc_els_free_iocb.
3343 */
3344 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003345 }
James Smart87af33f2007-10-27 13:37:43 -04003346
dea31012005-04-17 16:05:31 -05003347 lpfc_els_free_iocb(phba, cmdiocb);
3348 return;
3349}
3350
James Smarte59058c2008-08-24 21:49:00 -04003351/**
James Smart3621a712009-04-06 18:47:14 -04003352 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003353 * @vport: pointer to a host virtual N_Port data structure.
3354 * @flag: the els command code to be accepted.
3355 * @oldiocb: pointer to the original lpfc command iocb data structure.
3356 * @ndlp: pointer to a node-list data structure.
3357 * @mbox: pointer to the driver internal queue element for mailbox command.
3358 *
3359 * This routine prepares and issues an Accept (ACC) response IOCB
3360 * command. It uses the @flag to properly set up the IOCB field for the
3361 * specific ACC response command to be issued and invokes the
3362 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3363 * @mbox pointer is passed in, it will be put into the context_un.mbox
3364 * field of the IOCB for the completion callback function to issue the
3365 * mailbox command to the HBA later when callback is invoked.
3366 *
3367 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3368 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3369 * will be stored into the context1 field of the IOCB for the completion
3370 * callback function to the corresponding response ELS IOCB command.
3371 *
3372 * Return code
3373 * 0 - Successfully issued acc response
3374 * 1 - Failed to issue acc response
3375 **/
dea31012005-04-17 16:05:31 -05003376int
James Smart2e0fef82007-06-17 19:56:36 -05003377lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3378 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003379 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003380{
James Smart2e0fef82007-06-17 19:56:36 -05003381 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3382 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003383 IOCB_t *icmd;
3384 IOCB_t *oldcmd;
3385 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003386 struct lpfc_sli *psli;
3387 uint8_t *pcmd;
3388 uint16_t cmdsize;
3389 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003390 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003391
3392 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003393 oldcmd = &oldiocb->iocb;
3394
3395 switch (flag) {
3396 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003397 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003398 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3399 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003400 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003401 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003402 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003403 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003404 return 1;
dea31012005-04-17 16:05:31 -05003405 }
James Smart2e0fef82007-06-17 19:56:36 -05003406
dea31012005-04-17 16:05:31 -05003407 icmd = &elsiocb->iocb;
3408 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3409 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3410 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003411 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003412
3413 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3414 "Issue ACC: did:x%x flg:x%x",
3415 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003416 break;
3417 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003418 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003419 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3420 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003421 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003422 return 1;
James Smart488d1462006-03-07 15:02:37 -05003423
dea31012005-04-17 16:05:31 -05003424 icmd = &elsiocb->iocb;
3425 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3426 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3427
3428 if (mbox)
3429 elsiocb->context_un.mbox = mbox;
3430
3431 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003432 pcmd += sizeof(uint32_t);
3433 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003434
3435 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3436 "Issue ACC PLOGI: did:x%x flg:x%x",
3437 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003438 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003439 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003440 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003441 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003442 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3443 if (!elsiocb)
3444 return 1;
3445
3446 icmd = &elsiocb->iocb;
3447 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3448 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3449
3450 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003451 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003452 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3453 els_pkt_ptr = (ELS_PKT *) pcmd;
3454 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003455
3456 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3457 "Issue ACC PRLO: did:x%x flg:x%x",
3458 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003459 break;
dea31012005-04-17 16:05:31 -05003460 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003461 return 1;
dea31012005-04-17 16:05:31 -05003462 }
dea31012005-04-17 16:05:31 -05003463 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003464 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3465 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3466 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3467 elsiocb->iotag, elsiocb->iocb.ulpContext,
3468 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3469 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003470 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003471 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003472 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003473 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003474 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3475 } else {
James Smart858c9f62007-06-17 19:56:39 -05003476 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003477 }
3478
3479 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003480 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003481 if (rc == IOCB_ERROR) {
3482 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003483 return 1;
dea31012005-04-17 16:05:31 -05003484 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003485 return 0;
dea31012005-04-17 16:05:31 -05003486}
3487
James Smarte59058c2008-08-24 21:49:00 -04003488/**
James Smart3621a712009-04-06 18:47:14 -04003489 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003490 * @vport: pointer to a virtual N_Port data structure.
3491 * @rejectError:
3492 * @oldiocb: pointer to the original lpfc command iocb data structure.
3493 * @ndlp: pointer to a node-list data structure.
3494 * @mbox: pointer to the driver internal queue element for mailbox command.
3495 *
3496 * This routine prepares and issue an Reject (RJT) response IOCB
3497 * command. If a @mbox pointer is passed in, it will be put into the
3498 * context_un.mbox field of the IOCB for the completion callback function
3499 * to issue to the HBA later.
3500 *
3501 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3502 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3503 * will be stored into the context1 field of the IOCB for the completion
3504 * callback function to the reject response ELS IOCB command.
3505 *
3506 * Return code
3507 * 0 - Successfully issued reject response
3508 * 1 - Failed to issue reject response
3509 **/
dea31012005-04-17 16:05:31 -05003510int
James Smart2e0fef82007-06-17 19:56:36 -05003511lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003512 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3513 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003514{
James Smart2e0fef82007-06-17 19:56:36 -05003515 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003516 IOCB_t *icmd;
3517 IOCB_t *oldcmd;
3518 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003519 struct lpfc_sli *psli;
3520 uint8_t *pcmd;
3521 uint16_t cmdsize;
3522 int rc;
3523
3524 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003525 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003526 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3527 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003528 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003529 return 1;
dea31012005-04-17 16:05:31 -05003530
3531 icmd = &elsiocb->iocb;
3532 oldcmd = &oldiocb->iocb;
3533 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3534 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3535
3536 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003537 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003538 *((uint32_t *) (pcmd)) = rejectError;
3539
James Smart51ef4c22007-08-02 11:10:31 -04003540 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003541 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003542
dea31012005-04-17 16:05:31 -05003543 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003544 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3545 "0129 Xmit ELS RJT x%x response tag x%x "
3546 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3547 "rpi x%x\n",
3548 rejectError, elsiocb->iotag,
3549 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3550 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3552 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3553 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3554
dea31012005-04-17 16:05:31 -05003555 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003556 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003557 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003558
dea31012005-04-17 16:05:31 -05003559 if (rc == IOCB_ERROR) {
3560 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003561 return 1;
dea31012005-04-17 16:05:31 -05003562 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003563 return 0;
dea31012005-04-17 16:05:31 -05003564}
3565
James Smarte59058c2008-08-24 21:49:00 -04003566/**
James Smart3621a712009-04-06 18:47:14 -04003567 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003568 * @vport: pointer to a virtual N_Port data structure.
3569 * @oldiocb: pointer to the original lpfc command iocb data structure.
3570 * @ndlp: pointer to a node-list data structure.
3571 *
3572 * This routine prepares and issues an Accept (ACC) response to Address
3573 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3574 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3575 *
3576 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3577 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3578 * will be stored into the context1 field of the IOCB for the completion
3579 * callback function to the ADISC Accept response ELS IOCB command.
3580 *
3581 * Return code
3582 * 0 - Successfully issued acc adisc response
3583 * 1 - Failed to issue adisc acc response
3584 **/
dea31012005-04-17 16:05:31 -05003585int
James Smart2e0fef82007-06-17 19:56:36 -05003586lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3587 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003588{
James Smart2e0fef82007-06-17 19:56:36 -05003589 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003590 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003591 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003592 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003593 uint8_t *pcmd;
3594 uint16_t cmdsize;
3595 int rc;
3596
James Smart92d7f7b2007-06-17 19:56:38 -05003597 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003598 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3599 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003600 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003601 return 1;
dea31012005-04-17 16:05:31 -05003602
dea31012005-04-17 16:05:31 -05003603 icmd = &elsiocb->iocb;
3604 oldcmd = &oldiocb->iocb;
3605 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003606
3607 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003608 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3609 "0130 Xmit ADISC ACC response iotag x%x xri: "
3610 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3611 elsiocb->iotag, elsiocb->iocb.ulpContext,
3612 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3613 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003614 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3615
3616 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003617 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003618
3619 ap = (ADISC *) (pcmd);
3620 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003621 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3622 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003623 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003624
James Smart858c9f62007-06-17 19:56:39 -05003625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3626 "Issue ACC ADISC: did:x%x flg:x%x",
3627 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3628
dea31012005-04-17 16:05:31 -05003629 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003630 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003631 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003632 if (rc == IOCB_ERROR) {
3633 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003634 return 1;
dea31012005-04-17 16:05:31 -05003635 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003636 return 0;
dea31012005-04-17 16:05:31 -05003637}
3638
James Smarte59058c2008-08-24 21:49:00 -04003639/**
James Smart3621a712009-04-06 18:47:14 -04003640 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003641 * @vport: pointer to a virtual N_Port data structure.
3642 * @oldiocb: pointer to the original lpfc command iocb data structure.
3643 * @ndlp: pointer to a node-list data structure.
3644 *
3645 * This routine prepares and issues an Accept (ACC) response to Process
3646 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3647 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3648 *
3649 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3650 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3651 * will be stored into the context1 field of the IOCB for the completion
3652 * callback function to the PRLI Accept response ELS IOCB command.
3653 *
3654 * Return code
3655 * 0 - Successfully issued acc prli response
3656 * 1 - Failed to issue acc prli response
3657 **/
dea31012005-04-17 16:05:31 -05003658int
James Smart2e0fef82007-06-17 19:56:36 -05003659lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003660 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003661{
James Smart2e0fef82007-06-17 19:56:36 -05003662 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003663 PRLI *npr;
3664 lpfc_vpd_t *vpd;
3665 IOCB_t *icmd;
3666 IOCB_t *oldcmd;
3667 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003668 struct lpfc_sli *psli;
3669 uint8_t *pcmd;
3670 uint16_t cmdsize;
3671 int rc;
3672
3673 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003674
James Smart92d7f7b2007-06-17 19:56:38 -05003675 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003676 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003677 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003678 if (!elsiocb)
3679 return 1;
dea31012005-04-17 16:05:31 -05003680
dea31012005-04-17 16:05:31 -05003681 icmd = &elsiocb->iocb;
3682 oldcmd = &oldiocb->iocb;
3683 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003684 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003685 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3686 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3687 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3688 elsiocb->iotag, elsiocb->iocb.ulpContext,
3689 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3690 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003691 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3692
3693 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003694 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003695
3696 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003697 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003698
3699 npr = (PRLI *) pcmd;
3700 vpd = &phba->vpd;
3701 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003702 * If the remote port is a target and our firmware version is 3.20 or
3703 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003704 */
James Smart0d2b6b82008-06-14 22:52:47 -04003705 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3706 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003707 npr->ConfmComplAllowed = 1;
3708 npr->Retry = 1;
3709 npr->TaskRetryIdReq = 1;
3710 }
3711
3712 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3713 npr->estabImagePair = 1;
3714 npr->readXferRdyDis = 1;
3715 npr->ConfmComplAllowed = 1;
3716
3717 npr->prliType = PRLI_FCP_TYPE;
3718 npr->initiatorFunc = 1;
3719
James Smart858c9f62007-06-17 19:56:39 -05003720 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3721 "Issue ACC PRLI: did:x%x flg:x%x",
3722 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3723
dea31012005-04-17 16:05:31 -05003724 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003725 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003726
James Smart3772a992009-05-22 14:50:54 -04003727 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003728 if (rc == IOCB_ERROR) {
3729 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003730 return 1;
dea31012005-04-17 16:05:31 -05003731 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003732 return 0;
dea31012005-04-17 16:05:31 -05003733}
3734
James Smarte59058c2008-08-24 21:49:00 -04003735/**
James Smart3621a712009-04-06 18:47:14 -04003736 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003737 * @vport: pointer to a virtual N_Port data structure.
3738 * @format: rnid command format.
3739 * @oldiocb: pointer to the original lpfc command iocb data structure.
3740 * @ndlp: pointer to a node-list data structure.
3741 *
3742 * This routine issues a Request Node Identification Data (RNID) Accept
3743 * (ACC) response. It constructs the RNID ACC response command according to
3744 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3745 * issue the response. Note that this command does not need to hold the ndlp
3746 * reference count for the callback. So, the ndlp reference count taken by
3747 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3748 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3749 * there is no ndlp reference available.
3750 *
3751 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3752 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3753 * will be stored into the context1 field of the IOCB for the completion
3754 * callback function. However, for the RNID Accept Response ELS command,
3755 * this is undone later by this routine after the IOCB is allocated.
3756 *
3757 * Return code
3758 * 0 - Successfully issued acc rnid response
3759 * 1 - Failed to issue acc rnid response
3760 **/
dea31012005-04-17 16:05:31 -05003761static int
James Smart2e0fef82007-06-17 19:56:36 -05003762lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003763 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003764{
James Smart2e0fef82007-06-17 19:56:36 -05003765 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003766 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003767 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003768 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003769 struct lpfc_sli *psli;
3770 uint8_t *pcmd;
3771 uint16_t cmdsize;
3772 int rc;
3773
3774 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003775 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3776 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003777 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003778 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003779
James Smart2e0fef82007-06-17 19:56:36 -05003780 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3781 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003782 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003783 return 1;
dea31012005-04-17 16:05:31 -05003784
dea31012005-04-17 16:05:31 -05003785 icmd = &elsiocb->iocb;
3786 oldcmd = &oldiocb->iocb;
3787 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003788 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003789 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3790 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3791 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003792 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003793 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003794 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003795
James Smart92d7f7b2007-06-17 19:56:38 -05003796 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003797 rn = (RNID *) (pcmd);
3798 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003799 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3800 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3801 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003802 switch (format) {
3803 case 0:
3804 rn->SpecificLen = 0;
3805 break;
3806 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003807 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003808 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003809 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003810 rn->un.topologyDisc.unitType = RNID_HBA;
3811 rn->un.topologyDisc.physPort = 0;
3812 rn->un.topologyDisc.attachedNodes = 0;
3813 break;
3814 default:
3815 rn->CommonLen = 0;
3816 rn->SpecificLen = 0;
3817 break;
3818 }
3819
James Smart858c9f62007-06-17 19:56:39 -05003820 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3821 "Issue ACC RNID: did:x%x flg:x%x",
3822 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3823
dea31012005-04-17 16:05:31 -05003824 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003825 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003826 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003827 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3828 * it could be freed */
3829
James Smart3772a992009-05-22 14:50:54 -04003830 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003831 if (rc == IOCB_ERROR) {
3832 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003833 return 1;
dea31012005-04-17 16:05:31 -05003834 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003835 return 0;
dea31012005-04-17 16:05:31 -05003836}
3837
James Smarte59058c2008-08-24 21:49:00 -04003838/**
James Smart3621a712009-04-06 18:47:14 -04003839 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003840 * @vport: pointer to a host virtual N_Port data structure.
3841 *
3842 * This routine issues Address Discover (ADISC) ELS commands to those
3843 * N_Ports which are in node port recovery state and ADISC has not been issued
3844 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3845 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3846 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3847 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3848 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3849 * IOCBs quit for later pick up. On the other hand, after walking through
3850 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3851 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3852 * no more ADISC need to be sent.
3853 *
3854 * Return code
3855 * The number of N_Ports with adisc issued.
3856 **/
dea31012005-04-17 16:05:31 -05003857int
James Smart2e0fef82007-06-17 19:56:36 -05003858lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003859{
James Smart2e0fef82007-06-17 19:56:36 -05003860 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003861 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003862 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003863
James Smart685f0bf2007-04-25 09:53:08 -04003864 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003865 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003866 if (!NLP_CHK_NODE_ACT(ndlp))
3867 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003868 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3869 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3870 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003871 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003872 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003873 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003874 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003875 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3876 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003877 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003878 vport->num_disc_nodes++;
3879 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003880 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003881 spin_lock_irq(shost->host_lock);
3882 vport->fc_flag |= FC_NLP_MORE;
3883 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003884 break;
dea31012005-04-17 16:05:31 -05003885 }
3886 }
3887 }
3888 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003889 spin_lock_irq(shost->host_lock);
3890 vport->fc_flag &= ~FC_NLP_MORE;
3891 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003892 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003893 return sentadisc;
dea31012005-04-17 16:05:31 -05003894}
3895
James Smarte59058c2008-08-24 21:49:00 -04003896/**
James Smart3621a712009-04-06 18:47:14 -04003897 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003898 * @vport: pointer to a host virtual N_Port data structure.
3899 *
3900 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3901 * which are in node port recovery state, with a @vport. Each time an ELS
3902 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3903 * the per @vport number of discover count (num_disc_nodes) shall be
3904 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3905 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3906 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3907 * later pick up. On the other hand, after walking through all the ndlps with
3908 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3909 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3910 * PLOGI need to be sent.
3911 *
3912 * Return code
3913 * The number of N_Ports with plogi issued.
3914 **/
dea31012005-04-17 16:05:31 -05003915int
James Smart2e0fef82007-06-17 19:56:36 -05003916lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003917{
James Smart2e0fef82007-06-17 19:56:36 -05003918 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003919 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003920 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003921
James Smart2e0fef82007-06-17 19:56:36 -05003922 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3923 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003924 if (!NLP_CHK_NODE_ACT(ndlp))
3925 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003926 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3927 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3928 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3929 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3930 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003931 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3932 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003933 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003934 vport->num_disc_nodes++;
3935 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003936 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003937 spin_lock_irq(shost->host_lock);
3938 vport->fc_flag |= FC_NLP_MORE;
3939 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003940 break;
dea31012005-04-17 16:05:31 -05003941 }
3942 }
3943 }
James Smart87af33f2007-10-27 13:37:43 -04003944 if (sentplogi) {
3945 lpfc_set_disctmo(vport);
3946 }
3947 else {
James Smart2e0fef82007-06-17 19:56:36 -05003948 spin_lock_irq(shost->host_lock);
3949 vport->fc_flag &= ~FC_NLP_MORE;
3950 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003951 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003952 return sentplogi;
dea31012005-04-17 16:05:31 -05003953}
3954
James Smarte59058c2008-08-24 21:49:00 -04003955/**
James Smart3621a712009-04-06 18:47:14 -04003956 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003957 * @vport: pointer to a host virtual N_Port data structure.
3958 *
3959 * This routine cleans up any Registration State Change Notification
3960 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3961 * @vport together with the host_lock is used to prevent multiple thread
3962 * trying to access the RSCN array on a same @vport at the same time.
3963 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003964void
James Smart2e0fef82007-06-17 19:56:36 -05003965lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003966{
James Smart2e0fef82007-06-17 19:56:36 -05003967 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3968 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003969 int i;
3970
James Smart7f5f3d02008-02-08 18:50:14 -05003971 spin_lock_irq(shost->host_lock);
3972 if (vport->fc_rscn_flush) {
3973 /* Another thread is walking fc_rscn_id_list on this vport */
3974 spin_unlock_irq(shost->host_lock);
3975 return;
3976 }
3977 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3978 vport->fc_rscn_flush = 1;
3979 spin_unlock_irq(shost->host_lock);
3980
James Smart2e0fef82007-06-17 19:56:36 -05003981 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003982 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003983 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003984 }
James Smart2e0fef82007-06-17 19:56:36 -05003985 spin_lock_irq(shost->host_lock);
3986 vport->fc_rscn_id_cnt = 0;
3987 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3988 spin_unlock_irq(shost->host_lock);
3989 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003990 /* Indicate we are done walking this fc_rscn_id_list */
3991 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003992}
3993
James Smarte59058c2008-08-24 21:49:00 -04003994/**
James Smart3621a712009-04-06 18:47:14 -04003995 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003996 * @vport: pointer to a host virtual N_Port data structure.
3997 * @did: remote destination port identifier.
3998 *
3999 * This routine checks whether there is any pending Registration State
4000 * Configuration Notification (RSCN) to a @did on @vport.
4001 *
4002 * Return code
4003 * None zero - The @did matched with a pending rscn
4004 * 0 - not able to match @did with a pending rscn
4005 **/
dea31012005-04-17 16:05:31 -05004006int
James Smart2e0fef82007-06-17 19:56:36 -05004007lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004008{
4009 D_ID ns_did;
4010 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004011 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004012 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004013 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004014
4015 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004016
4017 /* Never match fabric nodes for RSCNs */
4018 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004019 return 0;
dea31012005-04-17 16:05:31 -05004020
4021 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004022 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004023 return did;
dea31012005-04-17 16:05:31 -05004024
James Smart7f5f3d02008-02-08 18:50:14 -05004025 spin_lock_irq(shost->host_lock);
4026 if (vport->fc_rscn_flush) {
4027 /* Another thread is walking fc_rscn_id_list on this vport */
4028 spin_unlock_irq(shost->host_lock);
4029 return 0;
4030 }
4031 /* Indicate we are walking fc_rscn_id_list on this vport */
4032 vport->fc_rscn_flush = 1;
4033 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004034 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004035 lp = vport->fc_rscn_id_list[i]->virt;
4036 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4037 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004038 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004039 rscn_did.un.word = be32_to_cpu(*lp++);
4040 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004041 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4042 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004043 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4044 && (ns_did.un.b.area == rscn_did.un.b.area)
4045 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004046 goto return_did_out;
dea31012005-04-17 16:05:31 -05004047 break;
James Smarteaf15d52008-12-04 22:39:29 -05004048 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004049 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4050 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004051 goto return_did_out;
dea31012005-04-17 16:05:31 -05004052 break;
James Smarteaf15d52008-12-04 22:39:29 -05004053 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004054 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004055 goto return_did_out;
dea31012005-04-17 16:05:31 -05004056 break;
James Smarteaf15d52008-12-04 22:39:29 -05004057 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004058 goto return_did_out;
dea31012005-04-17 16:05:31 -05004059 }
4060 }
James Smart92d7f7b2007-06-17 19:56:38 -05004061 }
James Smart7f5f3d02008-02-08 18:50:14 -05004062 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4063 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004064 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004065return_did_out:
4066 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4067 vport->fc_rscn_flush = 0;
4068 return did;
dea31012005-04-17 16:05:31 -05004069}
4070
James Smarte59058c2008-08-24 21:49:00 -04004071/**
James Smart3621a712009-04-06 18:47:14 -04004072 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004073 * @vport: pointer to a host virtual N_Port data structure.
4074 *
4075 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4076 * state machine for a @vport's nodes that are with pending RSCN (Registration
4077 * State Change Notification).
4078 *
4079 * Return code
4080 * 0 - Successful (currently alway return 0)
4081 **/
dea31012005-04-17 16:05:31 -05004082static int
James Smart2e0fef82007-06-17 19:56:36 -05004083lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004084{
James Smart685f0bf2007-04-25 09:53:08 -04004085 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004086
James Smart0d2b6b82008-06-14 22:52:47 -04004087 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004088 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004089 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004090 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4091 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004092 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004093 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004094 NLP_EVT_DEVICE_RECOVERY);
4095 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004096 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004097 return 0;
dea31012005-04-17 16:05:31 -05004098}
4099
James Smarte59058c2008-08-24 21:49:00 -04004100/**
James Smart3621a712009-04-06 18:47:14 -04004101 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004102 * @vport: pointer to a host virtual N_Port data structure.
4103 * @cmdiocb: pointer to lpfc command iocb data structure.
4104 *
4105 * lpfc_send_rscn_event sends an RSCN netlink event to management
4106 * applications.
4107 */
4108static void
4109lpfc_send_rscn_event(struct lpfc_vport *vport,
4110 struct lpfc_iocbq *cmdiocb)
4111{
4112 struct lpfc_dmabuf *pcmd;
4113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4114 uint32_t *payload_ptr;
4115 uint32_t payload_len;
4116 struct lpfc_rscn_event_header *rscn_event_data;
4117
4118 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4119 payload_ptr = (uint32_t *) pcmd->virt;
4120 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4121
4122 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4123 payload_len, GFP_KERNEL);
4124 if (!rscn_event_data) {
4125 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4126 "0147 Failed to allocate memory for RSCN event\n");
4127 return;
4128 }
4129 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4130 rscn_event_data->payload_length = payload_len;
4131 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4132 payload_len);
4133
4134 fc_host_post_vendor_event(shost,
4135 fc_get_event_number(),
4136 sizeof(struct lpfc_els_event_header) + payload_len,
4137 (char *)rscn_event_data,
4138 LPFC_NL_VENDOR_ID);
4139
4140 kfree(rscn_event_data);
4141}
4142
4143/**
James Smart3621a712009-04-06 18:47:14 -04004144 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004145 * @vport: pointer to a host virtual N_Port data structure.
4146 * @cmdiocb: pointer to lpfc command iocb data structure.
4147 * @ndlp: pointer to a node-list data structure.
4148 *
4149 * This routine processes an unsolicited RSCN (Registration State Change
4150 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4151 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4152 * discover state machine is about to begin discovery, it just accepts the
4153 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4154 * contains N_Port IDs for other vports on this HBA, it just accepts the
4155 * RSCN and ignore processing it. If the state machine is in the recovery
4156 * state, the fc_rscn_id_list of this @vport is walked and the
4157 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4158 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4159 * routine is invoked to handle the RSCN event.
4160 *
4161 * Return code
4162 * 0 - Just sent the acc response
4163 * 1 - Sent the acc response and waited for name server completion
4164 **/
dea31012005-04-17 16:05:31 -05004165static int
James Smart2e0fef82007-06-17 19:56:36 -05004166lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004167 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004168{
James Smart2e0fef82007-06-17 19:56:36 -05004169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4170 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004171 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004172 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004173 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004174 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004175 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004176 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004177 int i;
dea31012005-04-17 16:05:31 -05004178
4179 icmd = &cmdiocb->iocb;
4180 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4181 lp = (uint32_t *) pcmd->virt;
4182
James Smart92d7f7b2007-06-17 19:56:38 -05004183 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4184 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004185 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4187 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004188 vport->fc_flag, payload_len, *lp,
4189 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004190
4191 /* Send an RSCN event to the management application */
4192 lpfc_send_rscn_event(vport, cmdiocb);
4193
James Smartd2873e42006-08-18 17:46:43 -04004194 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004195 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004196 FCH_EVT_RSCN, lp[i]);
4197
dea31012005-04-17 16:05:31 -05004198 /* If we are about to begin discovery, just ACC the RSCN.
4199 * Discovery processing will satisfy it.
4200 */
James Smart2e0fef82007-06-17 19:56:36 -05004201 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4203 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4204 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4205
James Smart51ef4c22007-08-02 11:10:31 -04004206 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004207 return 0;
dea31012005-04-17 16:05:31 -05004208 }
4209
James Smart92d7f7b2007-06-17 19:56:38 -05004210 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4211 * just ACC and ignore it.
4212 */
4213 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004214 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004215 i = payload_len;
4216 datap = lp;
4217 while (i > 0) {
4218 nportid = *datap++;
4219 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4220 i -= sizeof(uint32_t);
4221 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004222 if (lpfc_find_vport_by_did(phba, nportid))
4223 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004224 }
4225 if (rscn_id == hba_id) {
4226 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004227 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004228 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004229 "Data: x%x x%x x%x x%x\n",
4230 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004231 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004232 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4233 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4234 ndlp->nlp_DID, vport->port_state,
4235 ndlp->nlp_flag);
4236
James Smart92d7f7b2007-06-17 19:56:38 -05004237 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004238 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004239 return 0;
4240 }
4241 }
4242
James Smart7f5f3d02008-02-08 18:50:14 -05004243 spin_lock_irq(shost->host_lock);
4244 if (vport->fc_rscn_flush) {
4245 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004246 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004247 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004248 /* Send back ACC */
4249 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004250 return 0;
4251 }
4252 /* Indicate we are walking fc_rscn_id_list on this vport */
4253 vport->fc_rscn_flush = 1;
4254 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004255 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004256 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004257 /* If we are already processing an RSCN, save the received
4258 * RSCN payload buffer, cmdiocb->context2 to process later.
4259 */
James Smart2e0fef82007-06-17 19:56:36 -05004260 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004261 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4262 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4263 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4264
James Smart09372822008-01-11 01:52:54 -05004265 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004266 vport->fc_flag |= FC_RSCN_DEFERRED;
4267 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004268 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004269 vport->fc_flag |= FC_RSCN_MODE;
4270 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004271 if (rscn_cnt) {
4272 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4273 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4274 }
4275 if ((rscn_cnt) &&
4276 (payload_len + length <= LPFC_BPL_SIZE)) {
4277 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004278 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004279 memcpy(((uint8_t *)cmd) + length, lp,
4280 payload_len);
4281 } else {
4282 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4283 vport->fc_rscn_id_cnt++;
4284 /* If we zero, cmdiocb->context2, the calling
4285 * routine will not try to free it.
4286 */
4287 cmdiocb->context2 = NULL;
4288 }
dea31012005-04-17 16:05:31 -05004289 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004290 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4291 "0235 Deferred RSCN "
4292 "Data: x%x x%x x%x\n",
4293 vport->fc_rscn_id_cnt, vport->fc_flag,
4294 vport->port_state);
dea31012005-04-17 16:05:31 -05004295 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004296 vport->fc_flag |= FC_RSCN_DISCOVERY;
4297 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004298 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004299 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4300 "0234 ReDiscovery RSCN "
4301 "Data: x%x x%x x%x\n",
4302 vport->fc_rscn_id_cnt, vport->fc_flag,
4303 vport->port_state);
dea31012005-04-17 16:05:31 -05004304 }
James Smart7f5f3d02008-02-08 18:50:14 -05004305 /* Indicate we are done walking fc_rscn_id_list on this vport */
4306 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004307 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004308 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004309 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004310 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004311 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004312 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004313 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004314 return 0;
dea31012005-04-17 16:05:31 -05004315 }
James Smart858c9f62007-06-17 19:56:39 -05004316 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4317 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4318 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4319
James Smart2e0fef82007-06-17 19:56:36 -05004320 spin_lock_irq(shost->host_lock);
4321 vport->fc_flag |= FC_RSCN_MODE;
4322 spin_unlock_irq(shost->host_lock);
4323 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004324 /* Indicate we are done walking fc_rscn_id_list on this vport */
4325 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004326 /*
4327 * If we zero, cmdiocb->context2, the calling routine will
4328 * not try to free it.
4329 */
4330 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004331 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004332 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004333 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004334 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004335 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004336 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004337}
4338
James Smarte59058c2008-08-24 21:49:00 -04004339/**
James Smart3621a712009-04-06 18:47:14 -04004340 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004341 * @vport: pointer to a host virtual N_Port data structure.
4342 *
4343 * This routine handles the Registration State Configuration Notification
4344 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4345 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4346 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4347 * NameServer shall be issued. If CT command to the NameServer fails to be
4348 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4349 * RSCN activities with the @vport.
4350 *
4351 * Return code
4352 * 0 - Cleaned up rscn on the @vport
4353 * 1 - Wait for plogi to name server before proceed
4354 **/
dea31012005-04-17 16:05:31 -05004355int
James Smart2e0fef82007-06-17 19:56:36 -05004356lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004357{
4358 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004359 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004360
James Smart92d7f7b2007-06-17 19:56:38 -05004361 /* Ignore RSCN if the port is being torn down. */
4362 if (vport->load_flag & FC_UNLOADING) {
4363 lpfc_els_flush_rscn(vport);
4364 return 0;
4365 }
4366
dea31012005-04-17 16:05:31 -05004367 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004368 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004369
4370 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004371 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4372 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4373 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4374 vport->port_state);
dea31012005-04-17 16:05:31 -05004375
4376 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004377 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004378 vport->num_disc_nodes = 0;
4379
James Smart2e0fef82007-06-17 19:56:36 -05004380 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004381 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4382 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004383 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004384 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004385 /* Wait for NameServer query cmpl before we can
4386 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004387 return 1;
dea31012005-04-17 16:05:31 -05004388 } else {
4389 /* If login to NameServer does not exist, issue one */
4390 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004391 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004392 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004393 /* Wait for NameServer login cmpl before we can
4394 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004395 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004396
James Smarte47c9092008-02-08 18:49:26 -05004397 if (ndlp) {
4398 ndlp = lpfc_enable_node(vport, ndlp,
4399 NLP_STE_PLOGI_ISSUE);
4400 if (!ndlp) {
4401 lpfc_els_flush_rscn(vport);
4402 return 0;
4403 }
4404 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004405 } else {
James Smarte47c9092008-02-08 18:49:26 -05004406 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4407 if (!ndlp) {
4408 lpfc_els_flush_rscn(vport);
4409 return 0;
4410 }
James Smart2e0fef82007-06-17 19:56:36 -05004411 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004412 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004413 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004414 }
James Smarte47c9092008-02-08 18:49:26 -05004415 ndlp->nlp_type |= NLP_FABRIC;
4416 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4417 /* Wait for NameServer login cmpl before we can
4418 * continue
4419 */
4420 return 1;
dea31012005-04-17 16:05:31 -05004421 }
4422
James Smart2e0fef82007-06-17 19:56:36 -05004423 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004424 return 0;
dea31012005-04-17 16:05:31 -05004425}
4426
James Smarte59058c2008-08-24 21:49:00 -04004427/**
James Smart3621a712009-04-06 18:47:14 -04004428 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004429 * @vport: pointer to a host virtual N_Port data structure.
4430 * @cmdiocb: pointer to lpfc command iocb data structure.
4431 * @ndlp: pointer to a node-list data structure.
4432 *
4433 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4434 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4435 * point topology. As an unsolicited FLOGI should not be received in a loop
4436 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4437 * lpfc_check_sparm() routine is invoked to check the parameters in the
4438 * unsolicited FLOGI. If parameters validation failed, the routine
4439 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4440 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4441 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4442 * will initiate PLOGI. The higher lexicographical value party shall has
4443 * higher priority (as the winning port) and will initiate PLOGI and
4444 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4445 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4446 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4447 *
4448 * Return code
4449 * 0 - Successfully processed the unsolicited flogi
4450 * 1 - Failed to process the unsolicited flogi
4451 **/
dea31012005-04-17 16:05:31 -05004452static int
James Smart2e0fef82007-06-17 19:56:36 -05004453lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004454 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004455{
James Smart2e0fef82007-06-17 19:56:36 -05004456 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4457 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004458 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4459 uint32_t *lp = (uint32_t *) pcmd->virt;
4460 IOCB_t *icmd = &cmdiocb->iocb;
4461 struct serv_parm *sp;
4462 LPFC_MBOXQ_t *mbox;
4463 struct ls_rjt stat;
4464 uint32_t cmd, did;
4465 int rc;
4466
4467 cmd = *lp++;
4468 sp = (struct serv_parm *) lp;
4469
4470 /* FLOGI received */
4471
James Smart2e0fef82007-06-17 19:56:36 -05004472 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004473
4474 if (phba->fc_topology == TOPOLOGY_LOOP) {
4475 /* We should never receive a FLOGI in loop mode, ignore it */
4476 did = icmd->un.elsreq64.remoteID;
4477
4478 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4479 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004480 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4481 "0113 An FLOGI ELS command x%x was "
4482 "received from DID x%x in Loop Mode\n",
4483 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004484 return 1;
dea31012005-04-17 16:05:31 -05004485 }
4486
4487 did = Fabric_DID;
4488
James Smart341af102010-01-26 23:07:37 -05004489 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004490 /* For a FLOGI we accept, then if our portname is greater
4491 * then the remote portname we initiate Nport login.
4492 */
4493
James Smart2e0fef82007-06-17 19:56:36 -05004494 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004495 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004496
4497 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004498 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4499 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004500 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004501
dea31012005-04-17 16:05:31 -05004502 lpfc_linkdown(phba);
4503 lpfc_init_link(phba, mbox,
4504 phba->cfg_topology,
4505 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004506 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004507 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004508 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004509 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004510 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004511 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004512 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004513 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004514 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004515 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004516 spin_lock_irq(shost->host_lock);
4517 vport->fc_flag |= FC_PT2PT_PLOGI;
4518 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004519 }
James Smart2e0fef82007-06-17 19:56:36 -05004520 spin_lock_irq(shost->host_lock);
4521 vport->fc_flag |= FC_PT2PT;
4522 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4523 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004524 } else {
4525 /* Reject this request because invalid parameters */
4526 stat.un.b.lsRjtRsvd0 = 0;
4527 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4528 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4529 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004530 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4531 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004532 return 1;
dea31012005-04-17 16:05:31 -05004533 }
4534
4535 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004536 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004537
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004538 return 0;
dea31012005-04-17 16:05:31 -05004539}
4540
James Smarte59058c2008-08-24 21:49:00 -04004541/**
James Smart3621a712009-04-06 18:47:14 -04004542 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004543 * @vport: pointer to a host virtual N_Port data structure.
4544 * @cmdiocb: pointer to lpfc command iocb data structure.
4545 * @ndlp: pointer to a node-list data structure.
4546 *
4547 * This routine processes Request Node Identification Data (RNID) IOCB
4548 * received as an ELS unsolicited event. Only when the RNID specified format
4549 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4550 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4551 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4552 * rejected by invoking the lpfc_els_rsp_reject() routine.
4553 *
4554 * Return code
4555 * 0 - Successfully processed rnid iocb (currently always return 0)
4556 **/
dea31012005-04-17 16:05:31 -05004557static int
James Smart2e0fef82007-06-17 19:56:36 -05004558lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4559 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004560{
4561 struct lpfc_dmabuf *pcmd;
4562 uint32_t *lp;
4563 IOCB_t *icmd;
4564 RNID *rn;
4565 struct ls_rjt stat;
4566 uint32_t cmd, did;
4567
4568 icmd = &cmdiocb->iocb;
4569 did = icmd->un.elsreq64.remoteID;
4570 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4571 lp = (uint32_t *) pcmd->virt;
4572
4573 cmd = *lp++;
4574 rn = (RNID *) lp;
4575
4576 /* RNID received */
4577
4578 switch (rn->Format) {
4579 case 0:
4580 case RNID_TOPOLOGY_DISC:
4581 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004582 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004583 break;
4584 default:
4585 /* Reject this request because format not supported */
4586 stat.un.b.lsRjtRsvd0 = 0;
4587 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4588 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4589 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004590 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4591 NULL);
dea31012005-04-17 16:05:31 -05004592 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004593 return 0;
dea31012005-04-17 16:05:31 -05004594}
4595
James Smarte59058c2008-08-24 21:49:00 -04004596/**
James Smart3621a712009-04-06 18:47:14 -04004597 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004598 * @vport: pointer to a host virtual N_Port data structure.
4599 * @cmdiocb: pointer to lpfc command iocb data structure.
4600 * @ndlp: pointer to a node-list data structure.
4601 *
4602 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4603 * received as an ELS unsolicited event. Currently, this function just invokes
4604 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4605 *
4606 * Return code
4607 * 0 - Successfully processed lirr iocb (currently always return 0)
4608 **/
dea31012005-04-17 16:05:31 -05004609static int
James Smart2e0fef82007-06-17 19:56:36 -05004610lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4611 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004612{
4613 struct ls_rjt stat;
4614
4615 /* For now, unconditionally reject this command */
4616 stat.un.b.lsRjtRsvd0 = 0;
4617 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4618 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4619 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004620 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004621 return 0;
4622}
4623
James Smarte59058c2008-08-24 21:49:00 -04004624/**
James Smart5ffc2662009-11-18 15:39:44 -05004625 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4626 * @vport: pointer to a host virtual N_Port data structure.
4627 * @cmdiocb: pointer to lpfc command iocb data structure.
4628 * @ndlp: pointer to a node-list data structure.
4629 *
4630 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4631 * received as an ELS unsolicited event. A request to RRQ shall only
4632 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4633 * Nx_Port N_Port_ID of the target Exchange is the same as the
4634 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4635 * not accepted, an LS_RJT with reason code "Unable to perform
4636 * command request" and reason code explanation "Invalid Originator
4637 * S_ID" shall be returned. For now, we just unconditionally accept
4638 * RRQ from the target.
4639 **/
4640static void
4641lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4642 struct lpfc_nodelist *ndlp)
4643{
4644 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4645}
4646
4647/**
James Smart3621a712009-04-06 18:47:14 -04004648 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004649 * @phba: pointer to lpfc hba data structure.
4650 * @pmb: pointer to the driver internal queue element for mailbox command.
4651 *
4652 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4653 * mailbox command. This callback function is to actually send the Accept
4654 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4655 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4656 * mailbox command, constructs the RPS response with the link statistics
4657 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4658 * response to the RPS.
4659 *
4660 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4661 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4662 * will be stored into the context1 field of the IOCB for the completion
4663 * callback function to the RPS Accept Response ELS IOCB command.
4664 *
4665 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004666static void
James Smart329f9bc2007-04-25 09:53:01 -04004667lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004668{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004669 MAILBOX_t *mb;
4670 IOCB_t *icmd;
4671 RPS_RSP *rps_rsp;
4672 uint8_t *pcmd;
4673 struct lpfc_iocbq *elsiocb;
4674 struct lpfc_nodelist *ndlp;
4675 uint16_t xri, status;
4676 uint32_t cmdsize;
4677
James Smart04c68492009-05-22 14:52:52 -04004678 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004679
4680 ndlp = (struct lpfc_nodelist *) pmb->context2;
4681 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004682 pmb->context1 = NULL;
4683 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004684
4685 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004686 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004687 return;
4688 }
4689
4690 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004691 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004692 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4693 lpfc_max_els_tries, ndlp,
4694 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004695
4696 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004697 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004698
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004699 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004700 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004701
4702 icmd = &elsiocb->iocb;
4703 icmd->ulpContext = xri;
4704
4705 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4706 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004707 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004708 rps_rsp = (RPS_RSP *)pcmd;
4709
4710 if (phba->fc_topology != TOPOLOGY_LOOP)
4711 status = 0x10;
4712 else
4713 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004714 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004715 status |= 0x4;
4716
4717 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004718 rps_rsp->portStatus = cpu_to_be16(status);
4719 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4720 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4721 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4722 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4723 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4724 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004725 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004726 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4727 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4728 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4729 elsiocb->iotag, elsiocb->iocb.ulpContext,
4730 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4731 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004732 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004733 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004734 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004735 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004736 return;
4737}
4738
James Smarte59058c2008-08-24 21:49:00 -04004739/**
James Smart3621a712009-04-06 18:47:14 -04004740 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004741 * @vport: pointer to a host virtual N_Port data structure.
4742 * @cmdiocb: pointer to lpfc command iocb data structure.
4743 * @ndlp: pointer to a node-list data structure.
4744 *
4745 * This routine processes Read Port Status (RPS) IOCB received as an
4746 * ELS unsolicited event. It first checks the remote port state. If the
4747 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4748 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4749 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4750 * for reading the HBA link statistics. It is for the callback function,
4751 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4752 * to actually sending out RPS Accept (ACC) response.
4753 *
4754 * Return codes
4755 * 0 - Successfully processed rps iocb (currently always return 0)
4756 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004757static int
James Smart2e0fef82007-06-17 19:56:36 -05004758lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4759 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004760{
James Smart2e0fef82007-06-17 19:56:36 -05004761 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004762 uint32_t *lp;
4763 uint8_t flag;
4764 LPFC_MBOXQ_t *mbox;
4765 struct lpfc_dmabuf *pcmd;
4766 RPS *rps;
4767 struct ls_rjt stat;
4768
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004769 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004770 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4771 /* reject the unsolicited RPS request and done with it */
4772 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004773
4774 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4775 lp = (uint32_t *) pcmd->virt;
4776 flag = (be32_to_cpu(*lp++) & 0xf);
4777 rps = (RPS *) lp;
4778
4779 if ((flag == 0) ||
4780 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004781 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004782 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004783
James Smart92d7f7b2007-06-17 19:56:38 -05004784 printk("Fix me....\n");
4785 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004786 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4787 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004788 lpfc_read_lnk_stat(phba, mbox);
4789 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004790 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004791 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004792 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004793 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004794 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004795 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004796 /* Mbox completion will send ELS Response */
4797 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004798 /* Decrement reference count used for the failed mbox
4799 * command.
4800 */
James Smart329f9bc2007-04-25 09:53:01 -04004801 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004802 mempool_free(mbox, phba->mbox_mem_pool);
4803 }
4804 }
James Smart90160e02008-08-24 21:49:45 -04004805
4806reject_out:
4807 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004808 stat.un.b.lsRjtRsvd0 = 0;
4809 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4810 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4811 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004812 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004813 return 0;
4814}
4815
James Smarte59058c2008-08-24 21:49:00 -04004816/**
James Smart3621a712009-04-06 18:47:14 -04004817 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004818 * @vport: pointer to a host virtual N_Port data structure.
4819 * @cmdsize: size of the ELS command.
4820 * @oldiocb: pointer to the original lpfc command iocb data structure.
4821 * @ndlp: pointer to a node-list data structure.
4822 *
4823 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4824 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4825 *
4826 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4827 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4828 * will be stored into the context1 field of the IOCB for the completion
4829 * callback function to the RPL Accept Response ELS command.
4830 *
4831 * Return code
4832 * 0 - Successfully issued ACC RPL ELS command
4833 * 1 - Failed to issue ACC RPL ELS command
4834 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004835static int
James Smart2e0fef82007-06-17 19:56:36 -05004836lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4837 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004838{
James Smart2e0fef82007-06-17 19:56:36 -05004839 struct lpfc_hba *phba = vport->phba;
4840 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004841 RPL_RSP rpl_rsp;
4842 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004843 uint8_t *pcmd;
4844
James Smart2e0fef82007-06-17 19:56:36 -05004845 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4846 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004847
James Smart488d1462006-03-07 15:02:37 -05004848 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004849 return 1;
James Smart488d1462006-03-07 15:02:37 -05004850
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004851 icmd = &elsiocb->iocb;
4852 oldcmd = &oldiocb->iocb;
4853 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4854
4855 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4856 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004857 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004858 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4859 pcmd += sizeof(uint16_t);
4860
4861 /* Setup the RPL ACC payload */
4862 rpl_rsp.listLen = be32_to_cpu(1);
4863 rpl_rsp.index = 0;
4864 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004865 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4866 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004867 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004868 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004869 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4871 "0120 Xmit ELS RPL ACC response tag x%x "
4872 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4873 "rpi x%x\n",
4874 elsiocb->iotag, elsiocb->iocb.ulpContext,
4875 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4876 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004877 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004878 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004879 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4880 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004881 lpfc_els_free_iocb(phba, elsiocb);
4882 return 1;
4883 }
4884 return 0;
4885}
4886
James Smarte59058c2008-08-24 21:49:00 -04004887/**
James Smart3621a712009-04-06 18:47:14 -04004888 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004889 * @vport: pointer to a host virtual N_Port data structure.
4890 * @cmdiocb: pointer to lpfc command iocb data structure.
4891 * @ndlp: pointer to a node-list data structure.
4892 *
4893 * This routine processes Read Port List (RPL) IOCB received as an ELS
4894 * unsolicited event. It first checks the remote port state. If the remote
4895 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4896 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4897 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4898 * to accept the RPL.
4899 *
4900 * Return code
4901 * 0 - Successfully processed rpl iocb (currently always return 0)
4902 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004903static int
James Smart2e0fef82007-06-17 19:56:36 -05004904lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4905 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004906{
4907 struct lpfc_dmabuf *pcmd;
4908 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004909 uint32_t maxsize;
4910 uint16_t cmdsize;
4911 RPL *rpl;
4912 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004913
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004914 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4915 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004916 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004917 stat.un.b.lsRjtRsvd0 = 0;
4918 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4919 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4920 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004921 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4922 NULL);
James Smart90160e02008-08-24 21:49:45 -04004923 /* rejected the unsolicited RPL request and done with it */
4924 return 0;
dea31012005-04-17 16:05:31 -05004925 }
4926
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004927 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4928 lp = (uint32_t *) pcmd->virt;
4929 rpl = (RPL *) (lp + 1);
4930
4931 maxsize = be32_to_cpu(rpl->maxsize);
4932
4933 /* We support only one port */
4934 if ((rpl->index == 0) &&
4935 ((maxsize == 0) ||
4936 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4937 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004938 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004939 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4940 }
James Smart2e0fef82007-06-17 19:56:36 -05004941 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004942
4943 return 0;
4944}
4945
James Smarte59058c2008-08-24 21:49:00 -04004946/**
James Smart3621a712009-04-06 18:47:14 -04004947 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004948 * @vport: pointer to a virtual N_Port data structure.
4949 * @cmdiocb: pointer to lpfc command iocb data structure.
4950 * @ndlp: pointer to a node-list data structure.
4951 *
4952 * This routine processes Fibre Channel Address Resolution Protocol
4953 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4954 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4955 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4956 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4957 * remote PortName is compared against the FC PortName stored in the @vport
4958 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4959 * compared against the FC NodeName stored in the @vport data structure.
4960 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4961 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4962 * invoked to send out FARP Response to the remote node. Before sending the
4963 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4964 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4965 * routine is invoked to log into the remote port first.
4966 *
4967 * Return code
4968 * 0 - Either the FARP Match Mode not supported or successfully processed
4969 **/
dea31012005-04-17 16:05:31 -05004970static int
James Smart2e0fef82007-06-17 19:56:36 -05004971lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4972 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004973{
4974 struct lpfc_dmabuf *pcmd;
4975 uint32_t *lp;
4976 IOCB_t *icmd;
4977 FARP *fp;
4978 uint32_t cmd, cnt, did;
4979
4980 icmd = &cmdiocb->iocb;
4981 did = icmd->un.elsreq64.remoteID;
4982 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4983 lp = (uint32_t *) pcmd->virt;
4984
4985 cmd = *lp++;
4986 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004987 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4989 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004990 /* We will only support match on WWPN or WWNN */
4991 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004992 return 0;
dea31012005-04-17 16:05:31 -05004993 }
4994
4995 cnt = 0;
4996 /* If this FARP command is searching for my portname */
4997 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004998 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004999 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005000 cnt = 1;
5001 }
5002
5003 /* If this FARP command is searching for my nodename */
5004 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005005 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005006 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005007 cnt = 1;
5008 }
5009
5010 if (cnt) {
5011 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5012 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5013 /* Log back into the node before sending the FARP. */
5014 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005015 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005016 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005017 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005018 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005019 }
5020
5021 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005022 if (fp->Rflags & FARP_REQUEST_FARPR)
5023 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005024 }
5025 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005026 return 0;
dea31012005-04-17 16:05:31 -05005027}
5028
James Smarte59058c2008-08-24 21:49:00 -04005029/**
James Smart3621a712009-04-06 18:47:14 -04005030 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005031 * @vport: pointer to a host virtual N_Port data structure.
5032 * @cmdiocb: pointer to lpfc command iocb data structure.
5033 * @ndlp: pointer to a node-list data structure.
5034 *
5035 * This routine processes Fibre Channel Address Resolution Protocol
5036 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5037 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5038 * the FARP response request.
5039 *
5040 * Return code
5041 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5042 **/
dea31012005-04-17 16:05:31 -05005043static int
James Smart2e0fef82007-06-17 19:56:36 -05005044lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5045 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005046{
5047 struct lpfc_dmabuf *pcmd;
5048 uint32_t *lp;
5049 IOCB_t *icmd;
5050 uint32_t cmd, did;
5051
5052 icmd = &cmdiocb->iocb;
5053 did = icmd->un.elsreq64.remoteID;
5054 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5055 lp = (uint32_t *) pcmd->virt;
5056
5057 cmd = *lp++;
5058 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005059 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5060 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005061 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005062 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005063
5064 return 0;
5065}
5066
James Smarte59058c2008-08-24 21:49:00 -04005067/**
James Smart3621a712009-04-06 18:47:14 -04005068 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005069 * @vport: pointer to a host virtual N_Port data structure.
5070 * @cmdiocb: pointer to lpfc command iocb data structure.
5071 * @fan_ndlp: pointer to a node-list data structure.
5072 *
5073 * This routine processes a Fabric Address Notification (FAN) IOCB
5074 * command received as an ELS unsolicited event. The FAN ELS command will
5075 * only be processed on a physical port (i.e., the @vport represents the
5076 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5077 * compared against those in the phba data structure. If any of those is
5078 * different, the lpfc_initial_flogi() routine is invoked to initialize
5079 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5080 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5081 * is invoked to register login to the fabric.
5082 *
5083 * Return code
5084 * 0 - Successfully processed fan iocb (currently always return 0).
5085 **/
dea31012005-04-17 16:05:31 -05005086static int
James Smart2e0fef82007-06-17 19:56:36 -05005087lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5088 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005089{
James Smart2e0fef82007-06-17 19:56:36 -05005090 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005091 uint32_t *lp;
5092 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005093
James Smart0d2b6b82008-06-14 22:52:47 -04005094 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5095 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5096 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005097 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005098 if ((vport == phba->pport) &&
5099 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005100 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005101 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005102 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005103 sizeof(struct lpfc_name)))) {
5104 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005105 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005106 } else {
5107 /* FAN verified - skip FLOGI */
5108 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005109 if (phba->sli_rev < LPFC_SLI_REV4)
5110 lpfc_issue_fabric_reglogin(vport);
5111 else
5112 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005113 }
dea31012005-04-17 16:05:31 -05005114 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005115 return 0;
dea31012005-04-17 16:05:31 -05005116}
5117
James Smarte59058c2008-08-24 21:49:00 -04005118/**
James Smart3621a712009-04-06 18:47:14 -04005119 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005120 * @ptr: holder for the timer function associated data.
5121 *
5122 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5123 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5124 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5125 * up the worker thread. It is for the worker thread to invoke the routine
5126 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5127 **/
dea31012005-04-17 16:05:31 -05005128void
5129lpfc_els_timeout(unsigned long ptr)
5130{
James Smart2e0fef82007-06-17 19:56:36 -05005131 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5132 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005133 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005134 unsigned long iflag;
5135
James Smart2e0fef82007-06-17 19:56:36 -05005136 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005137 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5138 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005139 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005140 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005141
James Smart5e9d9b82008-06-14 22:52:53 -04005142 if (!tmo_posted)
5143 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005144 return;
5145}
5146
James Smarte59058c2008-08-24 21:49:00 -04005147/**
James Smart3621a712009-04-06 18:47:14 -04005148 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005149 * @vport: pointer to a virtual N_Port data structure.
5150 *
5151 * This routine is the actual handler function that processes an ELS timeout
5152 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5153 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5154 * invoking the lpfc_sli_issue_abort_iotag() routine.
5155 **/
dea31012005-04-17 16:05:31 -05005156void
James Smart2e0fef82007-06-17 19:56:36 -05005157lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005158{
James Smart2e0fef82007-06-17 19:56:36 -05005159 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005160 struct lpfc_sli_ring *pring;
5161 struct lpfc_iocbq *tmp_iocb, *piocb;
5162 IOCB_t *cmd = NULL;
5163 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005164 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005165 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005166 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005167
James Smart2e0fef82007-06-17 19:56:36 -05005168 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005169 timeout = (uint32_t)(phba->fc_ratov << 1);
5170
5171 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005172
5173 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5174 cmd = &piocb->iocb;
5175
James Smart2e0fef82007-06-17 19:56:36 -05005176 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5177 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5178 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005179 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005180
5181 if (piocb->vport != vport)
5182 continue;
5183
dea31012005-04-17 16:05:31 -05005184 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005185 if (pcmd)
5186 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005187
James Smart92d7f7b2007-06-17 19:56:38 -05005188 if (els_command == ELS_CMD_FARP ||
5189 els_command == ELS_CMD_FARPR ||
5190 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005191 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005192
dea31012005-04-17 16:05:31 -05005193 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005194 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005195 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005196 else
dea31012005-04-17 16:05:31 -05005197 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005198 continue;
5199 }
5200
James Smart2e0fef82007-06-17 19:56:36 -05005201 remote_ID = 0xffffffff;
5202 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005203 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005204 else {
5205 struct lpfc_nodelist *ndlp;
5206 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005207 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005208 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005209 }
James Smarte8b62012007-08-02 11:10:09 -04005210 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5211 "0127 ELS timeout Data: x%x x%x x%x "
5212 "x%x\n", els_command,
5213 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005214 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005215 }
James Smart2e0fef82007-06-17 19:56:36 -05005216 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005217
James Smart2e0fef82007-06-17 19:56:36 -05005218 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5219 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005220}
5221
James Smarte59058c2008-08-24 21:49:00 -04005222/**
James Smart3621a712009-04-06 18:47:14 -04005223 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005224 * @vport: pointer to a host virtual N_Port data structure.
5225 *
5226 * This routine is used to clean up all the outstanding ELS commands on a
5227 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5228 * routine. After that, it walks the ELS transmit queue to remove all the
5229 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5230 * the IOCBs with a non-NULL completion callback function, the callback
5231 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5232 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5233 * callback function, the IOCB will simply be released. Finally, it walks
5234 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5235 * completion queue IOCB that is associated with the @vport and is not
5236 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5237 * part of the discovery state machine) out to HBA by invoking the
5238 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5239 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5240 * the IOCBs are aborted when this function returns.
5241 **/
dea31012005-04-17 16:05:31 -05005242void
James Smart2e0fef82007-06-17 19:56:36 -05005243lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005244{
James Smart2534ba72007-04-25 09:52:20 -04005245 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005246 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005247 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005248 struct lpfc_iocbq *tmp_iocb, *piocb;
5249 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005250
5251 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005252
James Smart2e0fef82007-06-17 19:56:36 -05005253 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005254 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5255 cmd = &piocb->iocb;
5256
5257 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5258 continue;
5259 }
5260
5261 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005262 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5263 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5264 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5265 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005266 continue;
dea31012005-04-17 16:05:31 -05005267
James Smart2e0fef82007-06-17 19:56:36 -05005268 if (piocb->vport != vport)
5269 continue;
5270
James Smart2534ba72007-04-25 09:52:20 -04005271 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005272 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005273 }
5274
5275 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005276 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5277 continue;
5278 }
dea31012005-04-17 16:05:31 -05005279
James Smart2e0fef82007-06-17 19:56:36 -05005280 if (piocb->vport != vport)
5281 continue;
5282
James Smart07951072007-04-25 09:51:38 -04005283 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005284 }
James Smart2e0fef82007-06-17 19:56:36 -05005285 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005286
James Smarta257bf92009-04-06 18:48:10 -04005287 /* Cancell all the IOCBs from the completions list */
5288 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5289 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005290
dea31012005-04-17 16:05:31 -05005291 return;
5292}
5293
James Smarte59058c2008-08-24 21:49:00 -04005294/**
James Smart3621a712009-04-06 18:47:14 -04005295 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005296 * @phba: pointer to lpfc hba data structure.
5297 *
5298 * This routine is used to clean up all the outstanding ELS commands on a
5299 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5300 * routine. After that, it walks the ELS transmit queue to remove all the
5301 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5302 * the IOCBs with the completion callback function associated, the callback
5303 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5304 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5305 * callback function associated, the IOCB will simply be released. Finally,
5306 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5307 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5308 * management plane IOCBs that are not part of the discovery state machine)
5309 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5310 **/
James Smart549e55c2007-08-02 11:09:51 -04005311void
5312lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5313{
5314 LIST_HEAD(completions);
5315 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5316 struct lpfc_iocbq *tmp_iocb, *piocb;
5317 IOCB_t *cmd = NULL;
5318
5319 lpfc_fabric_abort_hba(phba);
5320 spin_lock_irq(&phba->hbalock);
5321 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5322 cmd = &piocb->iocb;
5323 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5324 continue;
5325 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5326 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5327 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5328 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5329 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5330 continue;
5331 list_move_tail(&piocb->list, &completions);
5332 pring->txq_cnt--;
5333 }
5334 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5335 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5336 continue;
5337 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5338 }
5339 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005340
5341 /* Cancel all the IOCBs from the completions list */
5342 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5343 IOERR_SLI_ABORTED);
5344
James Smart549e55c2007-08-02 11:09:51 -04005345 return;
5346}
5347
James Smarte59058c2008-08-24 21:49:00 -04005348/**
James Smart3621a712009-04-06 18:47:14 -04005349 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005350 * @phba: Pointer to hba context object.
5351 * @cmdiocbp: Pointer to command iocb which reported error.
5352 * @rspiocbp: Pointer to response iocb which reported error.
5353 *
5354 * This function sends an event when there is an ELS command
5355 * failure.
5356 **/
5357void
5358lpfc_send_els_failure_event(struct lpfc_hba *phba,
5359 struct lpfc_iocbq *cmdiocbp,
5360 struct lpfc_iocbq *rspiocbp)
5361{
5362 struct lpfc_vport *vport = cmdiocbp->vport;
5363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5364 struct lpfc_lsrjt_event lsrjt_event;
5365 struct lpfc_fabric_event_header fabric_event;
5366 struct ls_rjt stat;
5367 struct lpfc_nodelist *ndlp;
5368 uint32_t *pcmd;
5369
5370 ndlp = cmdiocbp->context1;
5371 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5372 return;
5373
5374 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5375 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5376 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5377 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5378 sizeof(struct lpfc_name));
5379 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5380 sizeof(struct lpfc_name));
5381 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5382 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005383 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005384 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5385 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5386 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5387 fc_host_post_vendor_event(shost,
5388 fc_get_event_number(),
5389 sizeof(lsrjt_event),
5390 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005391 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005392 return;
5393 }
5394 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5395 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5396 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5397 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5398 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5399 else
5400 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5401 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5402 sizeof(struct lpfc_name));
5403 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5404 sizeof(struct lpfc_name));
5405 fc_host_post_vendor_event(shost,
5406 fc_get_event_number(),
5407 sizeof(fabric_event),
5408 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005409 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005410 return;
5411 }
5412
5413}
5414
5415/**
James Smart3621a712009-04-06 18:47:14 -04005416 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005417 * @vport: Pointer to vport object.
5418 * @ndlp: Pointer FC node object.
5419 * @cmd: ELS command code.
5420 *
5421 * This function posts an event when there is an incoming
5422 * unsolicited ELS command.
5423 **/
5424static void
5425lpfc_send_els_event(struct lpfc_vport *vport,
5426 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005427 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005428{
James Smartddcc50f2008-12-04 22:38:46 -05005429 struct lpfc_els_event_header *els_data = NULL;
5430 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005431 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5432
James Smartddcc50f2008-12-04 22:38:46 -05005433 if (*payload == ELS_CMD_LOGO) {
5434 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5435 if (!logo_data) {
5436 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5437 "0148 Failed to allocate memory "
5438 "for LOGO event\n");
5439 return;
5440 }
5441 els_data = &logo_data->header;
5442 } else {
5443 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5444 GFP_KERNEL);
5445 if (!els_data) {
5446 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5447 "0149 Failed to allocate memory "
5448 "for ELS event\n");
5449 return;
5450 }
5451 }
5452 els_data->event_type = FC_REG_ELS_EVENT;
5453 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005454 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005455 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005456 break;
5457 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005458 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005459 break;
5460 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005461 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5462 break;
5463 case ELS_CMD_LOGO:
5464 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5465 /* Copy the WWPN in the LOGO payload */
5466 memcpy(logo_data->logo_wwpn, &payload[2],
5467 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005468 break;
5469 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005470 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005471 return;
5472 }
James Smartddcc50f2008-12-04 22:38:46 -05005473 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5474 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5475 if (*payload == ELS_CMD_LOGO) {
5476 fc_host_post_vendor_event(shost,
5477 fc_get_event_number(),
5478 sizeof(struct lpfc_logo_event),
5479 (char *)logo_data,
5480 LPFC_NL_VENDOR_ID);
5481 kfree(logo_data);
5482 } else {
5483 fc_host_post_vendor_event(shost,
5484 fc_get_event_number(),
5485 sizeof(struct lpfc_els_event_header),
5486 (char *)els_data,
5487 LPFC_NL_VENDOR_ID);
5488 kfree(els_data);
5489 }
James Smartea2151b2008-09-07 11:52:10 -04005490
5491 return;
5492}
5493
5494
5495/**
James Smart3621a712009-04-06 18:47:14 -04005496 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005497 * @phba: pointer to lpfc hba data structure.
5498 * @pring: pointer to a SLI ring.
5499 * @vport: pointer to a host virtual N_Port data structure.
5500 * @elsiocb: pointer to lpfc els command iocb data structure.
5501 *
5502 * This routine is used for processing the IOCB associated with a unsolicited
5503 * event. It first determines whether there is an existing ndlp that matches
5504 * the DID from the unsolicited IOCB. If not, it will create a new one with
5505 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5506 * IOCB is then used to invoke the proper routine and to set up proper state
5507 * of the discovery state machine.
5508 **/
James Smarted957682007-06-17 19:56:37 -05005509static void
5510lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005511 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005512{
James Smart87af33f2007-10-27 13:37:43 -04005513 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005514 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005515 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005516 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005517 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005518 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005519
James Smarte47c9092008-02-08 18:49:26 -05005520 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005521 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005522
dea31012005-04-17 16:05:31 -05005523 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005524 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5525 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005526 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005527 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005528
James Smart858c9f62007-06-17 19:56:39 -05005529 did = icmd->un.rcvels.remoteID;
5530 if (icmd->ulpStatus) {
5531 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5532 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5533 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005534 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005535 }
dea31012005-04-17 16:05:31 -05005536
5537 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005538 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005539 goto dropit;
dea31012005-04-17 16:05:31 -05005540
James Smartc8685952009-11-18 15:39:16 -05005541 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005542 if (vport->load_flag & FC_UNLOADING)
5543 goto dropit;
5544
James Smart2e0fef82007-06-17 19:56:36 -05005545 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005546 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005547 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005548 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005549 if (!ndlp)
dea31012005-04-17 16:05:31 -05005550 goto dropit;
dea31012005-04-17 16:05:31 -05005551
James Smart2e0fef82007-06-17 19:56:36 -05005552 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005553 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005554 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005555 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005556 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005557 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5558 ndlp = lpfc_enable_node(vport, ndlp,
5559 NLP_STE_UNUSED_NODE);
5560 if (!ndlp)
5561 goto dropit;
5562 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5563 newnode = 1;
5564 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5565 ndlp->nlp_type |= NLP_FABRIC;
5566 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5567 /* This is similar to the new node path */
5568 ndlp = lpfc_nlp_get(ndlp);
5569 if (!ndlp)
5570 goto dropit;
5571 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5572 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005573 }
dea31012005-04-17 16:05:31 -05005574
5575 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005576
James Smart329f9bc2007-04-25 09:53:01 -04005577 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005578 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005579
5580 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5581 cmd &= ELS_CMD_MASK;
5582 }
5583 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005584 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5585 "0112 ELS command x%x received from NPORT x%x "
5586 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005587 switch (cmd) {
5588 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005589 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5590 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5591 did, vport->port_state, ndlp->nlp_flag);
5592
dea31012005-04-17 16:05:31 -05005593 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005594 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5595
James Smartddcc50f2008-12-04 22:38:46 -05005596 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005597 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005598 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5599 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5600 rjt_err = LSRJT_UNABLE_TPC;
5601 break;
5602 }
5603 /* We get here, and drop thru, if we are PT2PT with
5604 * another NPort and the other side has initiated
5605 * the PLOGI before responding to our FLOGI.
5606 */
dea31012005-04-17 16:05:31 -05005607 }
James Smart87af33f2007-10-27 13:37:43 -04005608
5609 shost = lpfc_shost_from_vport(vport);
5610 spin_lock_irq(shost->host_lock);
5611 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5612 spin_unlock_irq(shost->host_lock);
5613
James Smart2e0fef82007-06-17 19:56:36 -05005614 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5615 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005616
dea31012005-04-17 16:05:31 -05005617 break;
5618 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5620 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5621 did, vport->port_state, ndlp->nlp_flag);
5622
dea31012005-04-17 16:05:31 -05005623 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005624 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005625 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005626 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005627 break;
5628 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5630 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5631 did, vport->port_state, ndlp->nlp_flag);
5632
dea31012005-04-17 16:05:31 -05005633 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005634 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005635 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005636 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005637 break;
5638 }
James Smart2e0fef82007-06-17 19:56:36 -05005639 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005640 break;
5641 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005642 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5643 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5644 did, vport->port_state, ndlp->nlp_flag);
5645
dea31012005-04-17 16:05:31 -05005646 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005647 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005648 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005649 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005650 break;
5651 }
James Smart2e0fef82007-06-17 19:56:36 -05005652 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005653 break;
5654 case ELS_CMD_RSCN:
5655 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005656 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005657 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005658 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005659 break;
5660 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5662 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5663 did, vport->port_state, ndlp->nlp_flag);
5664
James Smartddcc50f2008-12-04 22:38:46 -05005665 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005666 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005667 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005668 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005669 break;
5670 }
James Smart2e0fef82007-06-17 19:56:36 -05005671 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5672 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005673 break;
5674 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5676 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5677 did, vport->port_state, ndlp->nlp_flag);
5678
dea31012005-04-17 16:05:31 -05005679 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005680 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005681 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005682 break;
5683 }
James Smart2e0fef82007-06-17 19:56:36 -05005684 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5685 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005686 break;
5687 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005688 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5689 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5690 did, vport->port_state, ndlp->nlp_flag);
5691
dea31012005-04-17 16:05:31 -05005692 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005693 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005694 break;
5695 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005696 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5697 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5698 did, vport->port_state, ndlp->nlp_flag);
5699
dea31012005-04-17 16:05:31 -05005700 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005701 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005702 break;
5703 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5705 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5706 did, vport->port_state, ndlp->nlp_flag);
5707
dea31012005-04-17 16:05:31 -05005708 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005709 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005710 break;
dea31012005-04-17 16:05:31 -05005711 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005712 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5713 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5714 did, vport->port_state, ndlp->nlp_flag);
5715
dea31012005-04-17 16:05:31 -05005716 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005717 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005718 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005719 break;
5720 }
James Smart2e0fef82007-06-17 19:56:36 -05005721 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005722 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005723 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005724 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5725 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5726 did, vport->port_state, ndlp->nlp_flag);
5727
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005728 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005729 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005730 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005731 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005732 break;
5733 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5735 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5736 did, vport->port_state, ndlp->nlp_flag);
5737
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005738 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005739 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005740 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005741 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005742 break;
5743 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5745 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5746 did, vport->port_state, ndlp->nlp_flag);
5747
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005748 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005749 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005750 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005751 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005752 break;
dea31012005-04-17 16:05:31 -05005753 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005754 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5755 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5756 did, vport->port_state, ndlp->nlp_flag);
5757
dea31012005-04-17 16:05:31 -05005758 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005759 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005760 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005761 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005762 break;
James Smart5ffc2662009-11-18 15:39:44 -05005763 case ELS_CMD_RRQ:
5764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5765 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5766 did, vport->port_state, ndlp->nlp_flag);
5767
5768 phba->fc_stat.elsRcvRRQ++;
5769 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5770 if (newnode)
5771 lpfc_nlp_put(ndlp);
5772 break;
dea31012005-04-17 16:05:31 -05005773 default:
James Smart858c9f62007-06-17 19:56:39 -05005774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5775 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5776 cmd, did, vport->port_state);
5777
dea31012005-04-17 16:05:31 -05005778 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005779 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005780
5781 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005782 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5783 "0115 Unknown ELS command x%x "
5784 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005785 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005786 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005787 break;
5788 }
5789
5790 /* check if need to LS_RJT received ELS cmd */
5791 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005792 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005793 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005794 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005795 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5796 NULL);
dea31012005-04-17 16:05:31 -05005797 }
5798
James Smartd7c255b2008-08-24 21:50:00 -04005799 lpfc_nlp_put(elsiocb->context1);
5800 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005801 return;
5802
5803dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005804 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005805 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5806 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005807 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005808 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005809 phba->fc_stat.elsRcvDrop++;
5810}
5811
James Smarte59058c2008-08-24 21:49:00 -04005812/**
James Smart3621a712009-04-06 18:47:14 -04005813 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005814 * @phba: pointer to lpfc hba data structure.
5815 * @vpi: host virtual N_Port identifier.
5816 *
5817 * This routine finds a vport on a HBA (referred by @phba) through a
5818 * @vpi. The function walks the HBA's vport list and returns the address
5819 * of the vport with the matching @vpi.
5820 *
5821 * Return code
5822 * NULL - No vport with the matching @vpi found
5823 * Otherwise - Address to the vport with the matching @vpi.
5824 **/
James Smart6669f9b2009-10-02 15:16:45 -04005825struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005826lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5827{
5828 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005829 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005830
James Smart549e55c2007-08-02 11:09:51 -04005831 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005832 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005833 if (vport->vpi == vpi) {
5834 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005835 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005836 }
James Smart92d7f7b2007-06-17 19:56:38 -05005837 }
James Smart549e55c2007-08-02 11:09:51 -04005838 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005839 return NULL;
5840}
James Smarted957682007-06-17 19:56:37 -05005841
James Smarte59058c2008-08-24 21:49:00 -04005842/**
James Smart3621a712009-04-06 18:47:14 -04005843 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005844 * @phba: pointer to lpfc hba data structure.
5845 * @pring: pointer to a SLI ring.
5846 * @elsiocb: pointer to lpfc els iocb data structure.
5847 *
5848 * This routine is used to process an unsolicited event received from a SLI
5849 * (Service Level Interface) ring. The actual processing of the data buffer
5850 * associated with the unsolicited event is done by invoking the routine
5851 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5852 * SLI ring on which the unsolicited event was received.
5853 **/
James Smarted957682007-06-17 19:56:37 -05005854void
5855lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5856 struct lpfc_iocbq *elsiocb)
5857{
5858 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005859 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005860 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005861 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5862 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005863
James Smartd7c255b2008-08-24 21:50:00 -04005864 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005865 elsiocb->context2 = NULL;
5866 elsiocb->context3 = NULL;
5867
5868 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5869 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5870 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5871 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005872 phba->fc_stat.NoRcvBuf++;
5873 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005874 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005875 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005876 return;
5877 }
5878
James Smart92d7f7b2007-06-17 19:56:38 -05005879 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5880 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5881 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5882 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5883 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005884 else
5885 vport = lpfc_find_vport_by_vpid(phba,
5886 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005887 }
James Smart7f5f3d02008-02-08 18:50:14 -05005888 /* If there are no BDEs associated
5889 * with this IOCB, there is nothing to do.
5890 */
James Smarted957682007-06-17 19:56:37 -05005891 if (icmd->ulpBdeCount == 0)
5892 return;
5893
James Smart7f5f3d02008-02-08 18:50:14 -05005894 /* type of ELS cmd is first 32bit word
5895 * in packet
5896 */
James Smarted957682007-06-17 19:56:37 -05005897 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005898 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005899 } else {
5900 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5901 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005902 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5903 paddr);
James Smarted957682007-06-17 19:56:37 -05005904 }
5905
James Smart92d7f7b2007-06-17 19:56:38 -05005906 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5907 /*
5908 * The different unsolicited event handlers would tell us
5909 * if they are done with "mp" by setting context2 to NULL.
5910 */
dea31012005-04-17 16:05:31 -05005911 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005912 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5913 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005914 }
James Smarted957682007-06-17 19:56:37 -05005915
5916 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005917 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005918 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005919 elsiocb->context2 = bdeBuf2;
5920 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005921 /* free mp if we are done with it */
5922 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005923 lpfc_in_buf_free(phba, elsiocb->context2);
5924 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005925 }
dea31012005-04-17 16:05:31 -05005926 }
dea31012005-04-17 16:05:31 -05005927}
James Smart92d7f7b2007-06-17 19:56:38 -05005928
James Smarte59058c2008-08-24 21:49:00 -04005929/**
James Smart3621a712009-04-06 18:47:14 -04005930 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005931 * @phba: pointer to lpfc hba data structure.
5932 * @vport: pointer to a virtual N_Port data structure.
5933 *
5934 * This routine issues a Port Login (PLOGI) to the Name Server with
5935 * State Change Request (SCR) for a @vport. This routine will create an
5936 * ndlp for the Name Server associated to the @vport if such node does
5937 * not already exist. The PLOGI to Name Server is issued by invoking the
5938 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5939 * (FDMI) is configured to the @vport, a FDMI node will be created and
5940 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5941 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005942void
5943lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5944{
5945 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5946
5947 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5948 if (!ndlp) {
5949 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5950 if (!ndlp) {
5951 if (phba->fc_topology == TOPOLOGY_LOOP) {
5952 lpfc_disc_start(vport);
5953 return;
5954 }
5955 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005956 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5957 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005958 return;
5959 }
5960 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005961 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5962 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5963 if (!ndlp) {
5964 if (phba->fc_topology == TOPOLOGY_LOOP) {
5965 lpfc_disc_start(vport);
5966 return;
5967 }
5968 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5969 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5970 "0348 NameServer login: node freed\n");
5971 return;
5972 }
James Smart92d7f7b2007-06-17 19:56:38 -05005973 }
James Smart58da1ff2008-04-07 10:15:56 -04005974 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005975
5976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5977
5978 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5979 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005980 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5981 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005982 return;
5983 }
5984
James Smart3de2a652007-08-02 11:09:59 -04005985 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005986 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5987 GFP_KERNEL);
5988 if (ndlp_fdmi) {
5989 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5990 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005991 lpfc_nlp_set_state(vport, ndlp_fdmi,
5992 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005993 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5994 0);
5995 }
5996 }
5997 return;
5998}
5999
James Smarte59058c2008-08-24 21:49:00 -04006000/**
James Smart3621a712009-04-06 18:47:14 -04006001 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006002 * @phba: pointer to lpfc hba data structure.
6003 * @pmb: pointer to the driver internal queue element for mailbox command.
6004 *
6005 * This routine is the completion callback function to register new vport
6006 * mailbox command. If the new vport mailbox command completes successfully,
6007 * the fabric registration login shall be performed on physical port (the
6008 * new vport created is actually a physical port, with VPI 0) or the port
6009 * login to Name Server for State Change Request (SCR) will be performed
6010 * on virtual port (real virtual port, with VPI greater than 0).
6011 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006012static void
6013lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6014{
6015 struct lpfc_vport *vport = pmb->vport;
6016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6017 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006018 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006019 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006020
James Smart09372822008-01-11 01:52:54 -05006021 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006022 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006023 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006024
6025 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006026 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6027 "0915 Register VPI failed: 0x%x\n",
6028 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05006029
6030 switch (mb->mbxStatus) {
6031 case 0x11: /* unsupported feature */
6032 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006033 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006034 /* giving up on vport registration */
6035 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6036 spin_lock_irq(shost->host_lock);
6037 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6038 spin_unlock_irq(shost->host_lock);
6039 lpfc_can_disctmo(vport);
6040 break;
James Smart695a8142010-01-26 23:08:03 -05006041 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6042 case 0x20:
6043 spin_lock_irq(shost->host_lock);
6044 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6045 spin_unlock_irq(shost->host_lock);
6046 lpfc_init_vpi(phba, pmb, vport->vpi);
6047 pmb->vport = vport;
6048 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6049 rc = lpfc_sli_issue_mbox(phba, pmb,
6050 MBX_NOWAIT);
6051 if (rc == MBX_NOT_FINISHED) {
6052 lpfc_printf_vlog(vport,
6053 KERN_ERR, LOG_MBOX,
6054 "2732 Failed to issue INIT_VPI"
6055 " mailbox command\n");
6056 } else {
6057 lpfc_nlp_put(ndlp);
6058 return;
6059 }
6060
James Smart92d7f7b2007-06-17 19:56:38 -05006061 default:
6062 /* Try to recover from this error */
6063 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006064 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006065 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006066 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006067 if (vport->port_type == LPFC_PHYSICAL_PORT
6068 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006069 lpfc_initial_flogi(vport);
6070 else
6071 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006072 break;
6073 }
James Smart92d7f7b2007-06-17 19:56:38 -05006074 } else {
James Smart695a8142010-01-26 23:08:03 -05006075 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006076 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006077 spin_unlock_irq(shost->host_lock);
6078 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006079 if (phba->sli_rev < LPFC_SLI_REV4)
6080 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006081 else {
James Smartfc2b9892010-02-26 14:15:29 -05006082 /*
6083 * If the physical port is instantiated using
6084 * FDISC, do not start vport discovery.
6085 */
6086 if (vport->port_state != LPFC_FDISC)
6087 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006088 lpfc_do_scr_ns_plogi(phba, vport);
6089 }
6090 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006091 lpfc_do_scr_ns_plogi(phba, vport);
6092 }
James Smartfa4066b2008-01-11 01:53:27 -05006093
6094 /* Now, we decrement the ndlp reference count held for this
6095 * callback function
6096 */
6097 lpfc_nlp_put(ndlp);
6098
James Smart92d7f7b2007-06-17 19:56:38 -05006099 mempool_free(pmb, phba->mbox_mem_pool);
6100 return;
6101}
6102
James Smarte59058c2008-08-24 21:49:00 -04006103/**
James Smart3621a712009-04-06 18:47:14 -04006104 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006105 * @phba: pointer to lpfc hba data structure.
6106 * @vport: pointer to a host virtual N_Port data structure.
6107 * @ndlp: pointer to a node-list data structure.
6108 *
6109 * This routine registers the @vport as a new virtual port with a HBA.
6110 * It is done through a registering vpi mailbox command.
6111 **/
James Smart695a8142010-01-26 23:08:03 -05006112void
James Smart92d7f7b2007-06-17 19:56:38 -05006113lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6114 struct lpfc_nodelist *ndlp)
6115{
James Smart09372822008-01-11 01:52:54 -05006116 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006117 LPFC_MBOXQ_t *mbox;
6118
6119 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6120 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006121 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006122 mbox->vport = vport;
6123 mbox->context2 = lpfc_nlp_get(ndlp);
6124 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006125 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006126 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006127 /* mailbox command not success, decrement ndlp
6128 * reference count for this command
6129 */
6130 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006131 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006132
James Smarte8b62012007-08-02 11:10:09 -04006133 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6134 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006135 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006136 }
6137 } else {
James Smarte8b62012007-08-02 11:10:09 -04006138 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6139 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006140 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006141 }
James Smartfa4066b2008-01-11 01:53:27 -05006142 return;
6143
6144mbox_err_exit:
6145 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6146 spin_lock_irq(shost->host_lock);
6147 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6148 spin_unlock_irq(shost->host_lock);
6149 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006150}
6151
James Smarte59058c2008-08-24 21:49:00 -04006152/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006153 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006154 * @phba: pointer to lpfc hba data structure.
6155 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006156 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006157 **/
6158void
James Smart0c9ab6f2010-02-26 14:15:57 -05006159lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006160{
6161 struct lpfc_vport **vports;
6162 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006163 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006164 int i;
James Smart695a8142010-01-26 23:08:03 -05006165
6166 /* Treat this failure as linkdown for all vports */
6167 link_state = phba->link_state;
6168 lpfc_linkdown(phba);
6169 phba->link_state = link_state;
6170
6171 vports = lpfc_create_vport_work_array(phba);
6172
6173 if (vports) {
6174 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6175 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6176 if (ndlp)
6177 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6178 lpfc_els_flush_cmd(vports[i]);
6179 }
6180 lpfc_destroy_vport_work_array(phba, vports);
6181 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006182}
6183
6184/**
6185 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6186 * @phba: pointer to lpfc hba data structure.
6187 *
6188 * This routine abort all pending discovery commands and
6189 * start a timer to retry FLOGI for the physical port
6190 * discovery.
6191 **/
6192void
6193lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6194{
6195 struct lpfc_nodelist *ndlp;
6196 struct Scsi_Host *shost;
6197
6198 /* Cancel the all vports retry delay retry timers */
6199 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006200
6201 /* If fabric require FLOGI, then re-instantiate physical login */
6202 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6203 if (!ndlp)
6204 return;
6205
James Smart695a8142010-01-26 23:08:03 -05006206 shost = lpfc_shost_from_vport(phba->pport);
6207 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6208 spin_lock_irq(shost->host_lock);
6209 ndlp->nlp_flag |= NLP_DELAY_TMO;
6210 spin_unlock_irq(shost->host_lock);
6211 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6212 phba->pport->port_state = LPFC_FLOGI;
6213 return;
6214}
6215
6216/**
6217 * lpfc_fabric_login_reqd - Check if FLOGI required.
6218 * @phba: pointer to lpfc hba data structure.
6219 * @cmdiocb: pointer to FDISC command iocb.
6220 * @rspiocb: pointer to FDISC response iocb.
6221 *
6222 * This routine checks if a FLOGI is reguired for FDISC
6223 * to succeed.
6224 **/
6225static int
6226lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6227 struct lpfc_iocbq *cmdiocb,
6228 struct lpfc_iocbq *rspiocb)
6229{
6230
6231 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6232 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6233 return 0;
6234 else
6235 return 1;
6236}
6237
6238/**
James Smart3621a712009-04-06 18:47:14 -04006239 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006240 * @phba: pointer to lpfc hba data structure.
6241 * @cmdiocb: pointer to lpfc command iocb data structure.
6242 * @rspiocb: pointer to lpfc response iocb data structure.
6243 *
6244 * This routine is the completion callback function to a Fabric Discover
6245 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6246 * single threaded, each FDISC completion callback function will reset
6247 * the discovery timer for all vports such that the timers will not get
6248 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6249 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6250 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6251 * assigned to the vport has been changed with the completion of the FDISC
6252 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6253 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6254 * routine is invoked to register new vport with the HBA. Otherwise, the
6255 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6256 * Server for State Change Request (SCR).
6257 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006258static void
6259lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6260 struct lpfc_iocbq *rspiocb)
6261{
6262 struct lpfc_vport *vport = cmdiocb->vport;
6263 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6264 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6265 struct lpfc_nodelist *np;
6266 struct lpfc_nodelist *next_np;
6267 IOCB_t *irsp = &rspiocb->iocb;
6268 struct lpfc_iocbq *piocb;
6269
James Smarte8b62012007-08-02 11:10:09 -04006270 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6271 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6272 irsp->ulpStatus, irsp->un.ulpWord[4],
6273 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006274 /* Since all FDISCs are being single threaded, we
6275 * must reset the discovery timer for ALL vports
6276 * waiting to send FDISC when one completes.
6277 */
6278 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6279 lpfc_set_disctmo(piocb->vport);
6280 }
6281
James Smart858c9f62007-06-17 19:56:39 -05006282 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6283 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6284 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6285
James Smart92d7f7b2007-06-17 19:56:38 -05006286 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006287
6288 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6289 lpfc_retry_pport_discovery(phba);
6290 goto out;
6291 }
6292
James Smart92d7f7b2007-06-17 19:56:38 -05006293 /* Check for retry */
6294 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6295 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006296 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006297 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006298 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006299 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006300 goto fdisc_failed;
6301 }
James Smartd7c255b2008-08-24 21:50:00 -04006302 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006303 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006304 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006305 vport->fc_flag |= FC_FABRIC;
6306 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6307 vport->fc_flag |= FC_PUBLIC_LOOP;
6308 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006309
James Smartd7c255b2008-08-24 21:50:00 -04006310 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6311 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6312 if ((vport->fc_prevDID != vport->fc_myDID) &&
6313 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6314 /* If our NportID changed, we need to ensure all
6315 * remaining NPORTs get unreg_login'ed so we can
6316 * issue unreg_vpi.
6317 */
6318 list_for_each_entry_safe(np, next_np,
6319 &vport->fc_nodes, nlp_listp) {
6320 if (!NLP_CHK_NODE_ACT(ndlp) ||
6321 (np->nlp_state != NLP_STE_NPR_NODE) ||
6322 !(np->nlp_flag & NLP_NPR_ADISC))
6323 continue;
James Smart09372822008-01-11 01:52:54 -05006324 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006325 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006326 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006327 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006328 }
James Smart78730cf2010-04-06 15:06:30 -04006329 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006330 lpfc_mbx_unreg_vpi(vport);
6331 spin_lock_irq(shost->host_lock);
6332 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006333 if (phba->sli_rev == LPFC_SLI_REV4)
6334 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006335 else
6336 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006337 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006338 }
6339
James Smartecfd03c2010-02-12 14:41:27 -05006340 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6341 lpfc_issue_init_vpi(vport);
6342 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006343 lpfc_register_new_vport(phba, vport, ndlp);
6344 else
6345 lpfc_do_scr_ns_plogi(phba, vport);
6346 goto out;
6347fdisc_failed:
6348 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6349 /* Cancel discovery timer */
6350 lpfc_can_disctmo(vport);
6351 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006352out:
6353 lpfc_els_free_iocb(phba, cmdiocb);
6354}
6355
James Smarte59058c2008-08-24 21:49:00 -04006356/**
James Smart3621a712009-04-06 18:47:14 -04006357 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006358 * @vport: pointer to a virtual N_Port data structure.
6359 * @ndlp: pointer to a node-list data structure.
6360 * @retry: number of retries to the command IOCB.
6361 *
6362 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6363 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6364 * routine to issue the IOCB, which makes sure only one outstanding fabric
6365 * IOCB will be sent off HBA at any given time.
6366 *
6367 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6368 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6369 * will be stored into the context1 field of the IOCB for the completion
6370 * callback function to the FDISC ELS command.
6371 *
6372 * Return code
6373 * 0 - Successfully issued fdisc iocb command
6374 * 1 - Failed to issue fdisc iocb command
6375 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006376static int
James Smart92d7f7b2007-06-17 19:56:38 -05006377lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6378 uint8_t retry)
6379{
6380 struct lpfc_hba *phba = vport->phba;
6381 IOCB_t *icmd;
6382 struct lpfc_iocbq *elsiocb;
6383 struct serv_parm *sp;
6384 uint8_t *pcmd;
6385 uint16_t cmdsize;
6386 int did = ndlp->nlp_DID;
6387 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006388
James Smart5ffc2662009-11-18 15:39:44 -05006389 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006390 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6391 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6392 ELS_CMD_FDISC);
6393 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006394 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006395 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6396 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006397 return 1;
6398 }
6399
6400 icmd = &elsiocb->iocb;
6401 icmd->un.elsreq64.myID = 0;
6402 icmd->un.elsreq64.fl = 1;
6403
James Smartf1126682009-06-10 17:22:44 -04006404 if (phba->sli_rev == LPFC_SLI_REV4) {
6405 /* FDISC needs to be 1 for WQE VPI */
6406 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6407 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6408 /* Set the ulpContext to the vpi */
6409 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6410 } else {
6411 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6412 icmd->ulpCt_h = 1;
6413 icmd->ulpCt_l = 0;
6414 }
James Smart92d7f7b2007-06-17 19:56:38 -05006415
6416 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6417 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6418 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6419 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6420 sp = (struct serv_parm *) pcmd;
6421 /* Setup CSPs accordingly for Fabric */
6422 sp->cmn.e_d_tov = 0;
6423 sp->cmn.w2.r_a_tov = 0;
6424 sp->cls1.classValid = 0;
6425 sp->cls2.seqDelivery = 1;
6426 sp->cls3.seqDelivery = 1;
6427
6428 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6429 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6430 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6431 pcmd += sizeof(uint32_t); /* Port Name */
6432 memcpy(pcmd, &vport->fc_portname, 8);
6433 pcmd += sizeof(uint32_t); /* Node Name */
6434 pcmd += sizeof(uint32_t); /* Node Name */
6435 memcpy(pcmd, &vport->fc_nodename, 8);
6436
6437 lpfc_set_disctmo(vport);
6438
6439 phba->fc_stat.elsXmitFDISC++;
6440 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6441
James Smart858c9f62007-06-17 19:56:39 -05006442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6443 "Issue FDISC: did:x%x",
6444 did, 0, 0);
6445
James Smart92d7f7b2007-06-17 19:56:38 -05006446 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6447 if (rc == IOCB_ERROR) {
6448 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006449 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006450 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6451 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006452 return 1;
6453 }
6454 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006455 return 0;
6456}
6457
James Smarte59058c2008-08-24 21:49:00 -04006458/**
James Smart3621a712009-04-06 18:47:14 -04006459 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006460 * @phba: pointer to lpfc hba data structure.
6461 * @cmdiocb: pointer to lpfc command iocb data structure.
6462 * @rspiocb: pointer to lpfc response iocb data structure.
6463 *
6464 * This routine is the completion callback function to the issuing of a LOGO
6465 * ELS command off a vport. It frees the command IOCB and then decrement the
6466 * reference count held on ndlp for this completion function, indicating that
6467 * the reference to the ndlp is no long needed. Note that the
6468 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6469 * callback function and an additional explicit ndlp reference decrementation
6470 * will trigger the actual release of the ndlp.
6471 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006472static void
6473lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6474 struct lpfc_iocbq *rspiocb)
6475{
6476 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006477 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006478 struct lpfc_nodelist *ndlp;
6479 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006480
6481 irsp = &rspiocb->iocb;
6482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6483 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6484 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006485
6486 lpfc_els_free_iocb(phba, cmdiocb);
6487 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006488
6489 /* Trigger the release of the ndlp after logo */
6490 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006491}
6492
James Smarte59058c2008-08-24 21:49:00 -04006493/**
James Smart3621a712009-04-06 18:47:14 -04006494 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006495 * @vport: pointer to a virtual N_Port data structure.
6496 * @ndlp: pointer to a node-list data structure.
6497 *
6498 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6499 *
6500 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6501 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6502 * will be stored into the context1 field of the IOCB for the completion
6503 * callback function to the LOGO ELS command.
6504 *
6505 * Return codes
6506 * 0 - Successfully issued logo off the @vport
6507 * 1 - Failed to issue logo off the @vport
6508 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006509int
6510lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6511{
6512 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6513 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006514 IOCB_t *icmd;
6515 struct lpfc_iocbq *elsiocb;
6516 uint8_t *pcmd;
6517 uint16_t cmdsize;
6518
6519 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6520 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6521 ELS_CMD_LOGO);
6522 if (!elsiocb)
6523 return 1;
6524
6525 icmd = &elsiocb->iocb;
6526 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6527 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6528 pcmd += sizeof(uint32_t);
6529
6530 /* Fill in LOGO payload */
6531 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6532 pcmd += sizeof(uint32_t);
6533 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6534
James Smart858c9f62007-06-17 19:56:39 -05006535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6536 "Issue LOGO npiv did:x%x flg:x%x",
6537 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6538
James Smart92d7f7b2007-06-17 19:56:38 -05006539 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6540 spin_lock_irq(shost->host_lock);
6541 ndlp->nlp_flag |= NLP_LOGO_SND;
6542 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006543 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6544 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006545 spin_lock_irq(shost->host_lock);
6546 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6547 spin_unlock_irq(shost->host_lock);
6548 lpfc_els_free_iocb(phba, elsiocb);
6549 return 1;
6550 }
6551 return 0;
6552}
6553
James Smarte59058c2008-08-24 21:49:00 -04006554/**
James Smart3621a712009-04-06 18:47:14 -04006555 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006556 * @ptr: holder for the timer function associated data.
6557 *
6558 * This routine is invoked by the fabric iocb block timer after
6559 * timeout. It posts the fabric iocb block timeout event by setting the
6560 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6561 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6562 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6563 * posted event WORKER_FABRIC_BLOCK_TMO.
6564 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006565void
6566lpfc_fabric_block_timeout(unsigned long ptr)
6567{
6568 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6569 unsigned long iflags;
6570 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006571
James Smart92d7f7b2007-06-17 19:56:38 -05006572 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6573 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6574 if (!tmo_posted)
6575 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6576 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6577
James Smart5e9d9b82008-06-14 22:52:53 -04006578 if (!tmo_posted)
6579 lpfc_worker_wake_up(phba);
6580 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006581}
6582
James Smarte59058c2008-08-24 21:49:00 -04006583/**
James Smart3621a712009-04-06 18:47:14 -04006584 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006585 * @phba: pointer to lpfc hba data structure.
6586 *
6587 * This routine issues one fabric iocb from the driver internal list to
6588 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6589 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6590 * remove one pending fabric iocb from the driver internal list and invokes
6591 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6592 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006593static void
6594lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6595{
6596 struct lpfc_iocbq *iocb;
6597 unsigned long iflags;
6598 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006599 IOCB_t *cmd;
6600
6601repeat:
6602 iocb = NULL;
6603 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006604 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006605 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6606 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6607 list);
6608 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006609 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006610 atomic_inc(&phba->fabric_iocb_count);
6611 }
6612 spin_unlock_irqrestore(&phba->hbalock, iflags);
6613 if (iocb) {
6614 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6615 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6616 iocb->iocb_flag |= LPFC_IO_FABRIC;
6617
James Smart858c9f62007-06-17 19:56:39 -05006618 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6619 "Fabric sched1: ste:x%x",
6620 iocb->vport->port_state, 0, 0);
6621
James Smart3772a992009-05-22 14:50:54 -04006622 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006623
6624 if (ret == IOCB_ERROR) {
6625 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6626 iocb->fabric_iocb_cmpl = NULL;
6627 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6628 cmd = &iocb->iocb;
6629 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6630 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6631 iocb->iocb_cmpl(phba, iocb, iocb);
6632
6633 atomic_dec(&phba->fabric_iocb_count);
6634 goto repeat;
6635 }
6636 }
6637
6638 return;
6639}
6640
James Smarte59058c2008-08-24 21:49:00 -04006641/**
James Smart3621a712009-04-06 18:47:14 -04006642 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006643 * @phba: pointer to lpfc hba data structure.
6644 *
6645 * This routine unblocks the issuing fabric iocb command. The function
6646 * will clear the fabric iocb block bit and then invoke the routine
6647 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6648 * from the driver internal fabric iocb list.
6649 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006650void
6651lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6652{
6653 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6654
6655 lpfc_resume_fabric_iocbs(phba);
6656 return;
6657}
6658
James Smarte59058c2008-08-24 21:49:00 -04006659/**
James Smart3621a712009-04-06 18:47:14 -04006660 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006661 * @phba: pointer to lpfc hba data structure.
6662 *
6663 * This routine blocks the issuing fabric iocb for a specified amount of
6664 * time (currently 100 ms). This is done by set the fabric iocb block bit
6665 * and set up a timeout timer for 100ms. When the block bit is set, no more
6666 * fabric iocb will be issued out of the HBA.
6667 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006668static void
6669lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6670{
6671 int blocked;
6672
6673 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006674 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006675 if (!blocked)
6676 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6677
6678 return;
6679}
6680
James Smarte59058c2008-08-24 21:49:00 -04006681/**
James Smart3621a712009-04-06 18:47:14 -04006682 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006683 * @phba: pointer to lpfc hba data structure.
6684 * @cmdiocb: pointer to lpfc command iocb data structure.
6685 * @rspiocb: pointer to lpfc response iocb data structure.
6686 *
6687 * This routine is the callback function that is put to the fabric iocb's
6688 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6689 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6690 * function first restores and invokes the original iocb's callback function
6691 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6692 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6693 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006694static void
6695lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6696 struct lpfc_iocbq *rspiocb)
6697{
6698 struct ls_rjt stat;
6699
6700 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6701 BUG();
6702
6703 switch (rspiocb->iocb.ulpStatus) {
6704 case IOSTAT_NPORT_RJT:
6705 case IOSTAT_FABRIC_RJT:
6706 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6707 lpfc_block_fabric_iocbs(phba);
6708 }
6709 break;
6710
6711 case IOSTAT_NPORT_BSY:
6712 case IOSTAT_FABRIC_BSY:
6713 lpfc_block_fabric_iocbs(phba);
6714 break;
6715
6716 case IOSTAT_LS_RJT:
6717 stat.un.lsRjtError =
6718 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6719 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6720 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6721 lpfc_block_fabric_iocbs(phba);
6722 break;
6723 }
6724
6725 if (atomic_read(&phba->fabric_iocb_count) == 0)
6726 BUG();
6727
6728 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6729 cmdiocb->fabric_iocb_cmpl = NULL;
6730 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6731 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6732
6733 atomic_dec(&phba->fabric_iocb_count);
6734 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006735 /* Post any pending iocbs to HBA */
6736 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006737 }
6738}
6739
James Smarte59058c2008-08-24 21:49:00 -04006740/**
James Smart3621a712009-04-06 18:47:14 -04006741 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006742 * @phba: pointer to lpfc hba data structure.
6743 * @iocb: pointer to lpfc command iocb data structure.
6744 *
6745 * This routine is used as the top-level API for issuing a fabric iocb command
6746 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6747 * function makes sure that only one fabric bound iocb will be outstanding at
6748 * any given time. As such, this function will first check to see whether there
6749 * is already an outstanding fabric iocb on the wire. If so, it will put the
6750 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6751 * issued later. Otherwise, it will issue the iocb on the wire and update the
6752 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6753 *
6754 * Note, this implementation has a potential sending out fabric IOCBs out of
6755 * order. The problem is caused by the construction of the "ready" boolen does
6756 * not include the condition that the internal fabric IOCB list is empty. As
6757 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6758 * ahead of the fabric IOCBs in the internal list.
6759 *
6760 * Return code
6761 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6762 * IOCB_ERROR - failed to issue fabric iocb
6763 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006764static int
James Smart92d7f7b2007-06-17 19:56:38 -05006765lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6766{
6767 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006768 int ready;
6769 int ret;
6770
6771 if (atomic_read(&phba->fabric_iocb_count) > 1)
6772 BUG();
6773
6774 spin_lock_irqsave(&phba->hbalock, iflags);
6775 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6776 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6777
James Smart7f5f3d02008-02-08 18:50:14 -05006778 if (ready)
6779 /* Increment fabric iocb count to hold the position */
6780 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006781 spin_unlock_irqrestore(&phba->hbalock, iflags);
6782 if (ready) {
6783 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6784 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6785 iocb->iocb_flag |= LPFC_IO_FABRIC;
6786
James Smart858c9f62007-06-17 19:56:39 -05006787 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6788 "Fabric sched2: ste:x%x",
6789 iocb->vport->port_state, 0, 0);
6790
James Smart3772a992009-05-22 14:50:54 -04006791 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006792
6793 if (ret == IOCB_ERROR) {
6794 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6795 iocb->fabric_iocb_cmpl = NULL;
6796 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6797 atomic_dec(&phba->fabric_iocb_count);
6798 }
6799 } else {
6800 spin_lock_irqsave(&phba->hbalock, iflags);
6801 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6802 spin_unlock_irqrestore(&phba->hbalock, iflags);
6803 ret = IOCB_SUCCESS;
6804 }
6805 return ret;
6806}
6807
James Smarte59058c2008-08-24 21:49:00 -04006808/**
James Smart3621a712009-04-06 18:47:14 -04006809 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006810 * @vport: pointer to a virtual N_Port data structure.
6811 *
6812 * This routine aborts all the IOCBs associated with a @vport from the
6813 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6814 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6815 * list, removes each IOCB associated with the @vport off the list, set the
6816 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6817 * associated with the IOCB.
6818 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006819static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006820{
6821 LIST_HEAD(completions);
6822 struct lpfc_hba *phba = vport->phba;
6823 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006824
6825 spin_lock_irq(&phba->hbalock);
6826 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6827 list) {
6828
6829 if (piocb->vport != vport)
6830 continue;
6831
6832 list_move_tail(&piocb->list, &completions);
6833 }
6834 spin_unlock_irq(&phba->hbalock);
6835
James Smarta257bf92009-04-06 18:48:10 -04006836 /* Cancel all the IOCBs from the completions list */
6837 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6838 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006839}
6840
James Smarte59058c2008-08-24 21:49:00 -04006841/**
James Smart3621a712009-04-06 18:47:14 -04006842 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006843 * @ndlp: pointer to a node-list data structure.
6844 *
6845 * This routine aborts all the IOCBs associated with an @ndlp from the
6846 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6847 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6848 * list, removes each IOCB associated with the @ndlp off the list, set the
6849 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6850 * associated with the IOCB.
6851 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006852void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6853{
6854 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006855 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006856 struct lpfc_iocbq *tmp_iocb, *piocb;
6857 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006858
6859 spin_lock_irq(&phba->hbalock);
6860 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6861 list) {
6862 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6863
6864 list_move_tail(&piocb->list, &completions);
6865 }
6866 }
6867 spin_unlock_irq(&phba->hbalock);
6868
James Smarta257bf92009-04-06 18:48:10 -04006869 /* Cancel all the IOCBs from the completions list */
6870 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6871 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006872}
6873
James Smarte59058c2008-08-24 21:49:00 -04006874/**
James Smart3621a712009-04-06 18:47:14 -04006875 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006876 * @phba: pointer to lpfc hba data structure.
6877 *
6878 * This routine aborts all the IOCBs currently on the driver internal
6879 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6880 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6881 * list, removes IOCBs off the list, set the status feild to
6882 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6883 * the IOCB.
6884 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006885void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6886{
6887 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006888
6889 spin_lock_irq(&phba->hbalock);
6890 list_splice_init(&phba->fabric_iocb_list, &completions);
6891 spin_unlock_irq(&phba->hbalock);
6892
James Smarta257bf92009-04-06 18:48:10 -04006893 /* Cancel all the IOCBs from the completions list */
6894 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6895 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006896}
James Smart6fb120a2009-05-22 14:52:59 -04006897
6898/**
6899 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6900 * @phba: pointer to lpfc hba data structure.
6901 * @axri: pointer to the els xri abort wcqe structure.
6902 *
6903 * This routine is invoked by the worker thread to process a SLI4 slow-path
6904 * ELS aborted xri.
6905 **/
6906void
6907lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6908 struct sli4_wcqe_xri_aborted *axri)
6909{
6910 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6911 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6912 unsigned long iflag = 0;
6913
James Smart0f65ff62010-02-26 14:14:23 -05006914 spin_lock_irqsave(&phba->hbalock, iflag);
6915 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006916 list_for_each_entry_safe(sglq_entry, sglq_next,
6917 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6918 if (sglq_entry->sli4_xritag == xri) {
6919 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006920 list_add_tail(&sglq_entry->list,
6921 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05006922 sglq_entry->state = SGL_FREED;
6923 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006924 spin_unlock_irqrestore(&phba->hbalock, iflag);
6925 return;
6926 }
6927 }
James Smart0f65ff62010-02-26 14:14:23 -05006928 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6929 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6930 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6931 spin_unlock_irqrestore(&phba->hbalock, iflag);
6932 return;
6933 }
6934 sglq_entry->state = SGL_XRI_ABORTED;
6935 spin_unlock_irqrestore(&phba->hbalock, iflag);
6936 return;
James Smart6fb120a2009-05-22 14:52:59 -04006937}