blob: 9508661fe82518993518621a9567978c7e1fbc11 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
182 break;
183 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 }
James Smart0c287582009-06-10 17:22:56 -0400192 else
James Smartc8685952009-11-18 15:39:16 -0500193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400194
dea31012005-04-17 16:05:31 -0500195 icmd = &elsiocb->iocb;
196
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 if (pcmd)
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500204
205 INIT_LIST_HEAD(&pcmd->list);
206
207 /* Allocate buffer for response payload */
208 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500210 if (prsp)
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500215 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500216 } else
dea31012005-04-17 16:05:31 -0500217 prsp = NULL;
dea31012005-04-17 16:05:31 -0500218
219 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500221 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500226
227 INIT_LIST_HEAD(&pbuflist->list);
228
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500232 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400236 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500237 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 }
dea31012005-04-17 16:05:31 -0500241 icmd->ulpBdeCount = 1;
242 icmd->ulpLe = 1;
243 icmd->ulpClass = CLASS3;
244
James Smart92d7f7b2007-06-17 19:56:38 -0500245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
247
248 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400249 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 else
255 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500256 }
257
dea31012005-04-17 16:05:31 -0500258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264
265 if (expectRsp) {
266 bpl++;
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
272 }
273
James Smartfa4066b2008-01-11 01:53:27 -0500274 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400275 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500280 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500281 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
283
284 if (prsp) {
285 list_add(&prsp->list, &pcmd->list);
286 }
dea31012005-04-17 16:05:31 -0500287 if (expectRsp) {
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
293 vport->port_state);
dea31012005-04-17 16:05:31 -0500294 } else {
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
300 cmdSize);
dea31012005-04-17 16:05:31 -0500301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return elsiocb;
dea31012005-04-17 16:05:31 -0500303
James Smartfa4066b2008-01-11 01:53:27 -0500304els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500305 if (expectRsp)
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500307 kfree(pbuflist);
308
309els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
311 kfree(prsp);
312
313els_iocb_free_pcmb_exit:
314 kfree(pcmd);
315 lpfc_sli_release_iocbq(phba, elsiocb);
316 return NULL;
317}
dea31012005-04-17 16:05:31 -0500318
James Smarte59058c2008-08-24 21:49:00 -0400319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400321 * @vport: pointer to a host virtual N_Port data structure.
322 *
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
329 * with the @vport.
330 *
331 * Return code
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
334 **/
James Smart3772a992009-05-22 14:50:54 -0400335int
James Smart92d7f7b2007-06-17 19:56:38 -0500336lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337{
338 struct lpfc_hba *phba = vport->phba;
339 LPFC_MBOXQ_t *mbox;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
343 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400344 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400349 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500350 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400354 if (!mbox) {
355 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500356 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400357 }
James Smart92d7f7b2007-06-17 19:56:38 -0500358
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 mbox->vport = vport;
363
James Smart0b727fe2007-10-27 13:37:25 -0400364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400365 if (rc == MBX_NOT_FINISHED) {
366 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400371 if (!mbox) {
372 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400374 }
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400376 if (rc) {
377 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
385 */
James Smart92d7f7b2007-06-17 19:56:38 -0500386 mbox->context2 = lpfc_nlp_get(ndlp);
387
James Smart0b727fe2007-10-27 13:37:25 -0400388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400389 if (rc == MBX_NOT_FINISHED) {
390 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500391 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400392 }
James Smart92d7f7b2007-06-17 19:56:38 -0500393
394 return 0;
395
396fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
399 */
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_put(ndlp);
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
403 kfree(mp);
404fail_free_mbox:
405 mempool_free(mbox, phba->mbox_mem_pool);
406
407fail:
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return -ENXIO;
412}
413
James Smarte59058c2008-08-24 21:49:00 -0400414/**
James Smart6fb120a2009-05-22 14:52:59 -0400415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
417 *
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
420 *
421 * Return code
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
424 **/
425static int
426lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427{
428 struct lpfc_hba *phba = vport->phba;
429 LPFC_MBOXQ_t *mboxq;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
433 int rc = 0;
434
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
438 rc = -ENODEV;
439 goto fail;
440 }
441
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
443 if (!dmabuf) {
444 rc = -ENOMEM;
445 goto fail;
446 }
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
448 if (!dmabuf->virt) {
449 rc = -ENOMEM;
450 goto fail_free_dmabuf;
451 }
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
453 if (!mboxq) {
454 rc = -ENOMEM;
455 goto fail_free_coherent;
456 }
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
465 rc = -ENXIO;
466 goto fail_free_mbox;
467 }
468 return 0;
469
470fail_free_mbox:
471 mempool_free(mboxq, phba->mbox_mem_pool);
472fail_free_coherent:
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
474fail_free_dmabuf:
475 kfree(dmabuf);
476fail:
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
480 return rc;
481}
482
483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 *
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
499 *
500 * Return code
501 * 0 - Success (currently, always return 0)
502 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500503static int
James Smart2e0fef82007-06-17 19:56:36 -0500504lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521
522 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500526 } else {
527 /*
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
530 */
James Smart2e0fef82007-06-17 19:56:36 -0500531 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500532 }
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500535 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500536 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500537 ndlp->nlp_class_sup = 0;
538 if (sp->cls1.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS1;
540 if (sp->cls2.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS2;
542 if (sp->cls3.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS3;
544 if (sp->cls4.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS4;
546 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
547 sp->cmn.bbRcvSizeLsb;
548 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
549
James Smart92d7f7b2007-06-17 19:56:38 -0500550 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
551 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400552 lpfc_printf_vlog(vport, KERN_WARNING,
553 LOG_ELS | LOG_VPORT,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500557 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500558 } else {
559 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport, KERN_WARNING,
562 LOG_ELS | LOG_VPORT,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500565 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
566 }
567 }
568
569 if ((vport->fc_prevDID != vport->fc_myDID) &&
570 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
571
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
574 */
575 list_for_each_entry_safe(np, next_np,
576 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400577 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500578 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500579 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
580 !(np->nlp_flag & NLP_NPR_ADISC))
581 continue;
582 spin_lock_irq(shost->host_lock);
583 np->nlp_flag &= ~NLP_NPR_ADISC;
584 spin_unlock_irq(shost->host_lock);
585 lpfc_unreg_rpi(vport, np);
586 }
587 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
588 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500589 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500590 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500591 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500592 }
James Smartecfd03c2010-02-12 14:41:27 -0500593 /*
594 * If VPI is unreged, driver need to do INIT_VPI
595 * before re-registering
596 */
597 if (phba->sli_rev == LPFC_SLI_REV4) {
598 spin_lock_irq(shost->host_lock);
599 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
600 spin_unlock_irq(shost->host_lock);
601 }
James Smart92d7f7b2007-06-17 19:56:38 -0500602 }
603
James Smart6fb120a2009-05-22 14:52:59 -0400604 if (phba->sli_rev < LPFC_SLI_REV4) {
605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
606 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
607 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
608 lpfc_register_new_vport(phba, vport, ndlp);
609 else
610 lpfc_issue_fabric_reglogin(vport);
611 } else {
612 ndlp->nlp_type |= NLP_FABRIC;
613 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500614 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
615 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400616 lpfc_start_fdiscs(phba);
617 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500618 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500619 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500620 else
James Smart6fb120a2009-05-22 14:52:59 -0400621 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500622 }
dea31012005-04-17 16:05:31 -0500623 return 0;
dea31012005-04-17 16:05:31 -0500624}
James Smarte59058c2008-08-24 21:49:00 -0400625/**
James Smart3621a712009-04-06 18:47:14 -0400626 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400627 * @vport: pointer to a host virtual N_Port data structure.
628 * @ndlp: pointer to a node-list data structure.
629 * @sp: pointer to service parameter data structure.
630 *
631 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
632 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
633 * in a point-to-point topology. First, the @vport's N_Port Name is compared
634 * with the received N_Port Name: if the @vport's N_Port Name is greater than
635 * the received N_Port Name lexicographically, this node shall assign local
636 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
637 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
638 * this node shall just wait for the remote node to issue PLOGI and assign
639 * N_Port IDs.
640 *
641 * Return code
642 * 0 - Success
643 * -ENXIO - Fail
644 **/
dea31012005-04-17 16:05:31 -0500645static int
James Smart2e0fef82007-06-17 19:56:36 -0500646lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
647 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500648{
James Smart2e0fef82007-06-17 19:56:36 -0500649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
650 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500651 LPFC_MBOXQ_t *mbox;
652 int rc;
653
James Smart2e0fef82007-06-17 19:56:36 -0500654 spin_lock_irq(shost->host_lock);
655 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
656 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500657
658 phba->fc_edtov = FF_DEF_EDTOV;
659 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500660 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500661 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500662 if (rc >= 0) {
663 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_PT2PT_PLOGI;
666 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500667
668 /*
669 * N_Port ID cannot be 0, set our to LocalID the other
670 * side will be RemoteID.
671 */
672
673 /* not equal */
674 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500675 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500676
677 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
678 if (!mbox)
679 goto fail;
680
681 lpfc_config_link(phba, mbox);
682
683 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500684 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400685 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500686 if (rc == MBX_NOT_FINISHED) {
687 mempool_free(mbox, phba->mbox_mem_pool);
688 goto fail;
689 }
James Smarte47c9092008-02-08 18:49:26 -0500690 /* Decrement ndlp reference count indicating that ndlp can be
691 * safely released when other references to it are done.
692 */
James Smart329f9bc2007-04-25 09:53:01 -0400693 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500694
James Smart2e0fef82007-06-17 19:56:36 -0500695 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500696 if (!ndlp) {
697 /*
698 * Cannot find existing Fabric ndlp, so allocate a
699 * new one
700 */
701 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
702 if (!ndlp)
703 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500704 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500705 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
706 ndlp = lpfc_enable_node(vport, ndlp,
707 NLP_STE_UNUSED_NODE);
708 if(!ndlp)
709 goto fail;
dea31012005-04-17 16:05:31 -0500710 }
711
712 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500713 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500714 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500715 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500716 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500717 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
718 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500719 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500720 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500721 } else
722 /* This side will wait for the PLOGI, decrement ndlp reference
723 * count indicating that ndlp can be released when other
724 * references to it are done.
725 */
James Smart329f9bc2007-04-25 09:53:01 -0400726 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500727
James Smart09372822008-01-11 01:52:54 -0500728 /* If we are pt2pt with another NPort, force NPIV off! */
729 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
730
James Smart2e0fef82007-06-17 19:56:36 -0500731 spin_lock_irq(shost->host_lock);
732 vport->fc_flag |= FC_PT2PT;
733 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500734
735 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500736 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500737 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500738fail:
dea31012005-04-17 16:05:31 -0500739 return -ENXIO;
740}
741
James Smarte59058c2008-08-24 21:49:00 -0400742/**
James Smart3621a712009-04-06 18:47:14 -0400743 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400744 * @phba: pointer to lpfc hba data structure.
745 * @cmdiocb: pointer to lpfc command iocb data structure.
746 * @rspiocb: pointer to lpfc response iocb data structure.
747 *
748 * This routine is the top-level completion callback function for issuing
749 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
750 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
751 * retry has been made (either immediately or delayed with lpfc_els_retry()
752 * returning 1), the command IOCB will be released and function returned.
753 * If the retry attempt has been given up (possibly reach the maximum
754 * number of retries), one additional decrement of ndlp reference shall be
755 * invoked before going out after releasing the command IOCB. This will
756 * actually release the remote node (Note, lpfc_els_free_iocb() will also
757 * invoke one decrement of ndlp reference count). If no error reported in
758 * the IOCB status, the command Port ID field is used to determine whether
759 * this is a point-to-point topology or a fabric topology: if the Port ID
760 * field is assigned, it is a fabric topology; otherwise, it is a
761 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
762 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
763 * specific topology completion conditions.
764 **/
dea31012005-04-17 16:05:31 -0500765static void
James Smart329f9bc2007-04-25 09:53:01 -0400766lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
767 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500768{
James Smart2e0fef82007-06-17 19:56:36 -0500769 struct lpfc_vport *vport = cmdiocb->vport;
770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500771 IOCB_t *irsp = &rspiocb->iocb;
772 struct lpfc_nodelist *ndlp = cmdiocb->context1;
773 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
774 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500775 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500776 int rc;
777
778 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500779 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500780 /* One additional decrement on node reference count to
781 * trigger the release of the node
782 */
James Smart329f9bc2007-04-25 09:53:01 -0400783 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500784 goto out;
785 }
786
James Smart858c9f62007-06-17 19:56:39 -0500787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
788 "FLOGI cmpl: status:x%x/x%x state:x%x",
789 irsp->ulpStatus, irsp->un.ulpWord[4],
790 vport->port_state);
791
dea31012005-04-17 16:05:31 -0500792 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500793 /*
794 * In case of FIP mode, perform round robin FCF failover
795 * due to new FCF discovery
796 */
797 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
798 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
799 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
800 "2611 FLOGI failed on registered "
801 "FCF record fcf_index:%d, trying "
802 "to perform round robin failover\n",
803 phba->fcf.current_rec.fcf_indx);
804 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
805 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
806 /*
807 * Exhausted the eligible FCF record list,
808 * fail through to retry FLOGI on current
809 * FCF record.
810 */
811 lpfc_printf_log(phba, KERN_WARNING,
812 LOG_FIP | LOG_ELS,
813 "2760 FLOGI exhausted FCF "
814 "round robin failover list, "
815 "retry FLOGI on the current "
816 "registered FCF index:%d\n",
817 phba->fcf.current_rec.fcf_indx);
818 spin_lock_irq(&phba->hbalock);
819 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
820 spin_unlock_irq(&phba->hbalock);
821 } else {
822 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
823 fcf_index);
824 if (rc) {
825 lpfc_printf_log(phba, KERN_WARNING,
826 LOG_FIP | LOG_ELS,
827 "2761 FLOGI round "
828 "robin FCF failover "
829 "read FCF failed "
830 "rc:x%x, fcf_index:"
831 "%d\n", rc,
832 phba->fcf.current_rec.fcf_indx);
833 spin_lock_irq(&phba->hbalock);
834 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
835 spin_unlock_irq(&phba->hbalock);
836 } else
837 goto out;
838 }
839 }
840
dea31012005-04-17 16:05:31 -0500841 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500842 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500843 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500844
dea31012005-04-17 16:05:31 -0500845 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500846 spin_lock_irq(shost->host_lock);
847 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
848 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500849
James Smart329f9bc2007-04-25 09:53:01 -0400850 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500851 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
852 * alpa map would take too long otherwise.
853 */
854 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400855 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500856 }
857
858 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500859 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
860 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400861 irsp->ulpStatus, irsp->un.ulpWord[4],
862 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500863 goto flogifail;
864 }
James Smart695a8142010-01-26 23:08:03 -0500865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400867 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500868 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500869
870 /*
871 * The FLogI succeeded. Sync the data for the CPU before
872 * accessing it.
873 */
874 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
875
876 sp = prsp->virt + sizeof(uint32_t);
877
878 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400879 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200880 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400881 "Data: x%x x%x x%x x%x\n",
882 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
883 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500884
James Smart2e0fef82007-06-17 19:56:36 -0500885 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500886 /*
887 * If Common Service Parameters indicate Nport
888 * we are point to point, if Fport we are Fabric.
889 */
890 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500891 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500892 else
James Smart2e0fef82007-06-17 19:56:36 -0500893 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500894
James Smart0c9ab6f2010-02-26 14:15:57 -0500895 if (!rc) {
896 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400897 if (phba->hba_flag & HBA_FIP_SUPPORT)
898 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
899 LOG_ELS,
900 "2769 FLOGI successful on FCF "
901 "record: current_fcf_index:"
902 "x%x, terminate FCF round "
903 "robin failover process\n",
904 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500905 spin_lock_irq(&phba->hbalock);
906 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
907 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500908 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500909 }
dea31012005-04-17 16:05:31 -0500910 }
911
912flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400913 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500914
James Smart858c9f62007-06-17 19:56:39 -0500915 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500916 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500917 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500918
919 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500920 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400921 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
922 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
923 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
924 (phba->link_state != LPFC_CLEAR_LA)) {
925 /* If FLOGI failed enable link interrupt. */
926 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500927 }
dea31012005-04-17 16:05:31 -0500928out:
929 lpfc_els_free_iocb(phba, cmdiocb);
930}
931
James Smarte59058c2008-08-24 21:49:00 -0400932/**
James Smart3621a712009-04-06 18:47:14 -0400933 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400934 * @vport: pointer to a host virtual N_Port data structure.
935 * @ndlp: pointer to a node-list data structure.
936 * @retry: number of retries to the command IOCB.
937 *
938 * This routine issues a Fabric Login (FLOGI) Request ELS command
939 * for a @vport. The initiator service parameters are put into the payload
940 * of the FLOGI Request IOCB and the top-level callback function pointer
941 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
942 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
943 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
944 *
945 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
946 * will be incremented by 1 for holding the ndlp and the reference to ndlp
947 * will be stored into the context1 field of the IOCB for the completion
948 * callback function to the FLOGI ELS command.
949 *
950 * Return code
951 * 0 - successfully issued flogi iocb for @vport
952 * 1 - failed to issue flogi iocb for @vport
953 **/
dea31012005-04-17 16:05:31 -0500954static int
James Smart2e0fef82007-06-17 19:56:36 -0500955lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500956 uint8_t retry)
957{
James Smart2e0fef82007-06-17 19:56:36 -0500958 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500959 struct serv_parm *sp;
960 IOCB_t *icmd;
961 struct lpfc_iocbq *elsiocb;
962 struct lpfc_sli_ring *pring;
963 uint8_t *pcmd;
964 uint16_t cmdsize;
965 uint32_t tmo;
966 int rc;
967
968 pring = &phba->sli.ring[LPFC_ELS_RING];
969
James Smart92d7f7b2007-06-17 19:56:38 -0500970 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500971 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
972 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500973
James Smart488d1462006-03-07 15:02:37 -0500974 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500975 return 1;
dea31012005-04-17 16:05:31 -0500976
977 icmd = &elsiocb->iocb;
978 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
979
980 /* For FLOGI request, remainder of payload is service parameters */
981 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500982 pcmd += sizeof(uint32_t);
983 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500984 sp = (struct serv_parm *) pcmd;
985
986 /* Setup CSPs accordingly for Fabric */
987 sp->cmn.e_d_tov = 0;
988 sp->cmn.w2.r_a_tov = 0;
989 sp->cls1.classValid = 0;
990 sp->cls2.seqDelivery = 1;
991 sp->cls3.seqDelivery = 1;
992 if (sp->cmn.fcphLow < FC_PH3)
993 sp->cmn.fcphLow = FC_PH3;
994 if (sp->cmn.fcphHigh < FC_PH3)
995 sp->cmn.fcphHigh = FC_PH3;
996
James Smart6fb120a2009-05-22 14:52:59 -0400997 if (phba->sli_rev == LPFC_SLI_REV4) {
998 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
999 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1000 /* FLOGI needs to be 3 for WQE FCFI */
1001 /* Set the fcfi to the fcfi we registered with */
1002 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1003 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001004 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001005 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1006 icmd->ulpCt_h = 1;
1007 icmd->ulpCt_l = 0;
1008 }
1009
James Smart858c9f62007-06-17 19:56:39 -05001010 if (phba->fc_topology != TOPOLOGY_LOOP) {
1011 icmd->un.elsreq64.myID = 0;
1012 icmd->un.elsreq64.fl = 1;
1013 }
1014
dea31012005-04-17 16:05:31 -05001015 tmo = phba->fc_ratov;
1016 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001017 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001018 phba->fc_ratov = tmo;
1019
1020 phba->fc_stat.elsXmitFLOGI++;
1021 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001022
1023 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1024 "Issue FLOGI: opt:x%x",
1025 phba->sli3_options, 0, 0);
1026
James Smart92d7f7b2007-06-17 19:56:38 -05001027 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001028 if (rc == IOCB_ERROR) {
1029 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001030 return 1;
dea31012005-04-17 16:05:31 -05001031 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001032 return 0;
dea31012005-04-17 16:05:31 -05001033}
1034
James Smarte59058c2008-08-24 21:49:00 -04001035/**
James Smart3621a712009-04-06 18:47:14 -04001036 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001037 * @phba: pointer to lpfc hba data structure.
1038 *
1039 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1040 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1041 * list and issues an abort IOCB commond on each outstanding IOCB that
1042 * contains a active Fabric_DID ndlp. Note that this function is to issue
1043 * the abort IOCB command on all the outstanding IOCBs, thus when this
1044 * function returns, it does not guarantee all the IOCBs are actually aborted.
1045 *
1046 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001047 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001048 **/
dea31012005-04-17 16:05:31 -05001049int
James Smart2e0fef82007-06-17 19:56:36 -05001050lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001051{
1052 struct lpfc_sli_ring *pring;
1053 struct lpfc_iocbq *iocb, *next_iocb;
1054 struct lpfc_nodelist *ndlp;
1055 IOCB_t *icmd;
1056
1057 /* Abort outstanding I/O on NPort <nlp_DID> */
1058 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001059 "0201 Abort outstanding I/O on NPort x%x\n",
1060 Fabric_DID);
dea31012005-04-17 16:05:31 -05001061
1062 pring = &phba->sli.ring[LPFC_ELS_RING];
1063
1064 /*
1065 * Check the txcmplq for an iocb that matches the nport the driver is
1066 * searching for.
1067 */
James Smart2e0fef82007-06-17 19:56:36 -05001068 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001069 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1070 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001071 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1072 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001073 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001074 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1075 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001076 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001077 }
1078 }
James Smart2e0fef82007-06-17 19:56:36 -05001079 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001080
1081 return 0;
1082}
1083
James Smarte59058c2008-08-24 21:49:00 -04001084/**
James Smart3621a712009-04-06 18:47:14 -04001085 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001086 * @vport: pointer to a host virtual N_Port data structure.
1087 *
1088 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1089 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1090 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1091 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1092 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1093 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1094 * @vport.
1095 *
1096 * Return code
1097 * 0 - failed to issue initial flogi for @vport
1098 * 1 - successfully issued initial flogi for @vport
1099 **/
dea31012005-04-17 16:05:31 -05001100int
James Smart2e0fef82007-06-17 19:56:36 -05001101lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001102{
James Smart2e0fef82007-06-17 19:56:36 -05001103 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001104 struct lpfc_nodelist *ndlp;
1105
James Smart98c9ea52007-10-27 13:37:33 -04001106 vport->port_state = LPFC_FLOGI;
1107 lpfc_set_disctmo(vport);
1108
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001109 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001110 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001111 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001112 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001113 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1114 if (!ndlp)
1115 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001116 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001117 /* Set the node type */
1118 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001119 /* Put ndlp onto node list */
1120 lpfc_enqueue_node(vport, ndlp);
1121 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1122 /* re-setup ndlp without removing from node list */
1123 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1124 if (!ndlp)
1125 return 0;
dea31012005-04-17 16:05:31 -05001126 }
James Smart87af33f2007-10-27 13:37:43 -04001127
James Smarte47c9092008-02-08 18:49:26 -05001128 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001129 /* This decrement of reference count to node shall kick off
1130 * the release of the node.
1131 */
James Smart329f9bc2007-04-25 09:53:01 -04001132 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001133
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001134 return 1;
dea31012005-04-17 16:05:31 -05001135}
1136
James Smarte59058c2008-08-24 21:49:00 -04001137/**
James Smart3621a712009-04-06 18:47:14 -04001138 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001139 * @vport: pointer to a host virtual N_Port data structure.
1140 *
1141 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1142 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1143 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1144 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1145 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1146 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1147 * @vport.
1148 *
1149 * Return code
1150 * 0 - failed to issue initial fdisc for @vport
1151 * 1 - successfully issued initial fdisc for @vport
1152 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001153int
1154lpfc_initial_fdisc(struct lpfc_vport *vport)
1155{
1156 struct lpfc_hba *phba = vport->phba;
1157 struct lpfc_nodelist *ndlp;
1158
1159 /* First look for the Fabric ndlp */
1160 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1161 if (!ndlp) {
1162 /* Cannot find existing Fabric ndlp, so allocate a new one */
1163 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1164 if (!ndlp)
1165 return 0;
1166 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001167 /* Put ndlp onto node list */
1168 lpfc_enqueue_node(vport, ndlp);
1169 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1170 /* re-setup ndlp without removing from node list */
1171 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1172 if (!ndlp)
1173 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001174 }
James Smarte47c9092008-02-08 18:49:26 -05001175
James Smart92d7f7b2007-06-17 19:56:38 -05001176 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001177 /* decrement node reference count to trigger the release of
1178 * the node.
1179 */
James Smart92d7f7b2007-06-17 19:56:38 -05001180 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001181 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001182 }
1183 return 1;
1184}
James Smart87af33f2007-10-27 13:37:43 -04001185
James Smarte59058c2008-08-24 21:49:00 -04001186/**
James Smart3621a712009-04-06 18:47:14 -04001187 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001188 * @vport: pointer to a host virtual N_Port data structure.
1189 *
1190 * This routine checks whether there are more remaining Port Logins
1191 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1192 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1193 * to issue ELS PLOGIs up to the configured discover threads with the
1194 * @vport (@vport->cfg_discovery_threads). The function also decrement
1195 * the @vport's num_disc_node by 1 if it is not already 0.
1196 **/
James Smart87af33f2007-10-27 13:37:43 -04001197void
James Smart2e0fef82007-06-17 19:56:36 -05001198lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001199{
1200 int sentplogi;
1201
James Smart2e0fef82007-06-17 19:56:36 -05001202 if (vport->num_disc_nodes)
1203 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001204
1205 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001206 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1207 "0232 Continue discovery with %d PLOGIs to go "
1208 "Data: x%x x%x x%x\n",
1209 vport->num_disc_nodes, vport->fc_plogi_cnt,
1210 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001211 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001212 if (vport->fc_flag & FC_NLP_MORE)
1213 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1214 sentplogi = lpfc_els_disc_plogi(vport);
1215
dea31012005-04-17 16:05:31 -05001216 return;
1217}
1218
James Smarte59058c2008-08-24 21:49:00 -04001219/**
James Smart3621a712009-04-06 18:47:14 -04001220 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001221 * @phba: pointer to lpfc hba data structure.
1222 * @prsp: pointer to response IOCB payload.
1223 * @ndlp: pointer to a node-list data structure.
1224 *
1225 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1226 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1227 * The following cases are considered N_Port confirmed:
1228 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1229 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1230 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1231 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1232 * 1) if there is a node on vport list other than the @ndlp with the same
1233 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1234 * on that node to release the RPI associated with the node; 2) if there is
1235 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1236 * into, a new node shall be allocated (or activated). In either case, the
1237 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1238 * be released and the new_ndlp shall be put on to the vport node list and
1239 * its pointer returned as the confirmed node.
1240 *
1241 * Note that before the @ndlp got "released", the keepDID from not-matching
1242 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1243 * of the @ndlp. This is because the release of @ndlp is actually to put it
1244 * into an inactive state on the vport node list and the vport node list
1245 * management algorithm does not allow two node with a same DID.
1246 *
1247 * Return code
1248 * pointer to the PLOGI N_Port @ndlp
1249 **/
James Smart488d1462006-03-07 15:02:37 -05001250static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001251lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001252 struct lpfc_nodelist *ndlp)
1253{
James Smart2e0fef82007-06-17 19:56:36 -05001254 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001255 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001256 struct lpfc_rport_data *rdata;
1257 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001258 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001259 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001260 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001261
James Smart2fb9bd82006-12-02 13:33:57 -05001262 /* Fabric nodes can have the same WWPN so we don't bother searching
1263 * by WWPN. Just return the ndlp that was given to us.
1264 */
1265 if (ndlp->nlp_type & NLP_FABRIC)
1266 return ndlp;
1267
James Smart92d7f7b2007-06-17 19:56:38 -05001268 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001269 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001270
James Smart685f0bf2007-04-25 09:53:08 -04001271 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001272 * we have for that ndlp. If not, we have some work to do.
1273 */
James Smart2e0fef82007-06-17 19:56:36 -05001274 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001275
James Smarte47c9092008-02-08 18:49:26 -05001276 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001277 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001278
1279 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001280 rc = memcmp(&ndlp->nlp_portname, name,
1281 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001282 if (!rc)
1283 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001284 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1285 if (!new_ndlp)
1286 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001287 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001288 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001289 rc = memcmp(&ndlp->nlp_portname, name,
1290 sizeof(struct lpfc_name));
1291 if (!rc)
1292 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001293 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1294 NLP_STE_UNUSED_NODE);
1295 if (!new_ndlp)
1296 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001297 keepDID = new_ndlp->nlp_DID;
1298 } else
1299 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001300
James Smart2e0fef82007-06-17 19:56:36 -05001301 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001302 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001303 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001304
1305 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1306 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1307 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1308
James Smarte47c9092008-02-08 18:49:26 -05001309 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001310 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001311
James Smart2e0fef82007-06-17 19:56:36 -05001312 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001313 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1314 /* The new_ndlp is replacing ndlp totally, so we need
1315 * to put ndlp on UNUSED list and try to free it.
1316 */
James Smart0ff10d42008-01-11 01:52:36 -05001317
1318 /* Fix up the rport accordingly */
1319 rport = ndlp->rport;
1320 if (rport) {
1321 rdata = rport->dd_data;
1322 if (rdata->pnode == ndlp) {
1323 lpfc_nlp_put(ndlp);
1324 ndlp->rport = NULL;
1325 rdata->pnode = lpfc_nlp_get(new_ndlp);
1326 new_ndlp->rport = rport;
1327 }
1328 new_ndlp->nlp_type = ndlp->nlp_type;
1329 }
James Smart58da1ff2008-04-07 10:15:56 -04001330 /* We shall actually free the ndlp with both nlp_DID and
1331 * nlp_portname fields equals 0 to avoid any ndlp on the
1332 * nodelist never to be used.
1333 */
1334 if (ndlp->nlp_DID == 0) {
1335 spin_lock_irq(&phba->ndlp_lock);
1336 NLP_SET_FREE_REQ(ndlp);
1337 spin_unlock_irq(&phba->ndlp_lock);
1338 }
James Smart0ff10d42008-01-11 01:52:36 -05001339
James Smart58da1ff2008-04-07 10:15:56 -04001340 /* Two ndlps cannot have the same did on the nodelist */
1341 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001342 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001343 }
James Smart92795652006-07-06 15:50:02 -04001344 else {
James Smart2e0fef82007-06-17 19:56:36 -05001345 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001346 /* Two ndlps cannot have the same did */
1347 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001348 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001349 }
James Smart488d1462006-03-07 15:02:37 -05001350 return new_ndlp;
1351}
1352
James Smarte59058c2008-08-24 21:49:00 -04001353/**
James Smart3621a712009-04-06 18:47:14 -04001354 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001355 * @vport: pointer to a host virtual N_Port data structure.
1356 *
1357 * This routine checks whether more Registration State Change
1358 * Notifications (RSCNs) came in while the discovery state machine was in
1359 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1360 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1361 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1362 * handling the RSCNs.
1363 **/
James Smart87af33f2007-10-27 13:37:43 -04001364void
1365lpfc_end_rscn(struct lpfc_vport *vport)
1366{
1367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1368
1369 if (vport->fc_flag & FC_RSCN_MODE) {
1370 /*
1371 * Check to see if more RSCNs came in while we were
1372 * processing this one.
1373 */
1374 if (vport->fc_rscn_id_cnt ||
1375 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1376 lpfc_els_handle_rscn(vport);
1377 else {
1378 spin_lock_irq(shost->host_lock);
1379 vport->fc_flag &= ~FC_RSCN_MODE;
1380 spin_unlock_irq(shost->host_lock);
1381 }
1382 }
1383}
1384
James Smarte59058c2008-08-24 21:49:00 -04001385/**
James Smart3621a712009-04-06 18:47:14 -04001386 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001387 * @phba: pointer to lpfc hba data structure.
1388 * @cmdiocb: pointer to lpfc command iocb data structure.
1389 * @rspiocb: pointer to lpfc response iocb data structure.
1390 *
1391 * This routine is the completion callback function for issuing the Port
1392 * Login (PLOGI) command. For PLOGI completion, there must be an active
1393 * ndlp on the vport node list that matches the remote node ID from the
1394 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1395 * ignored and command IOCB released. The PLOGI response IOCB status is
1396 * checked for error conditons. If there is error status reported, PLOGI
1397 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1398 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1399 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1400 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1401 * there are additional N_Port nodes with the vport that need to perform
1402 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1403 * PLOGIs.
1404 **/
dea31012005-04-17 16:05:31 -05001405static void
James Smart2e0fef82007-06-17 19:56:36 -05001406lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1407 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001408{
James Smart2e0fef82007-06-17 19:56:36 -05001409 struct lpfc_vport *vport = cmdiocb->vport;
1410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001411 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001412 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001413 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001414 int disc, rc, did, type;
1415
dea31012005-04-17 16:05:31 -05001416 /* we pass cmdiocb to state machine which needs rspiocb as well */
1417 cmdiocb->context_un.rsp_iocb = rspiocb;
1418
1419 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001420 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1421 "PLOGI cmpl: status:x%x/x%x did:x%x",
1422 irsp->ulpStatus, irsp->un.ulpWord[4],
1423 irsp->un.elsreq64.remoteID);
1424
James Smart2e0fef82007-06-17 19:56:36 -05001425 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001426 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001427 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1428 "0136 PLOGI completes to NPort x%x "
1429 "with no ndlp. Data: x%x x%x x%x\n",
1430 irsp->un.elsreq64.remoteID,
1431 irsp->ulpStatus, irsp->un.ulpWord[4],
1432 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001433 goto out;
James Smarted957682007-06-17 19:56:37 -05001434 }
dea31012005-04-17 16:05:31 -05001435
1436 /* Since ndlp can be freed in the disc state machine, note if this node
1437 * is being used during discovery.
1438 */
James Smart2e0fef82007-06-17 19:56:36 -05001439 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001440 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001441 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001442 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001443 rc = 0;
1444
1445 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001446 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1447 "0102 PLOGI completes to NPort x%x "
1448 "Data: x%x x%x x%x x%x x%x\n",
1449 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1450 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001451 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001452 if (lpfc_els_chk_latt(vport)) {
1453 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001454 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001455 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001456 goto out;
1457 }
1458
1459 /* ndlp could be freed in DSM, save these values now */
1460 type = ndlp->nlp_type;
1461 did = ndlp->nlp_DID;
1462
1463 if (irsp->ulpStatus) {
1464 /* Check for retry */
1465 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1466 /* ELS command is being retried */
1467 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001468 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001469 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001470 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001471 }
1472 goto out;
1473 }
dea31012005-04-17 16:05:31 -05001474 /* PLOGI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001475 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1476 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1477 ndlp->nlp_DID, irsp->ulpStatus,
1478 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001479 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001480 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001481 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001482 else
James Smart2e0fef82007-06-17 19:56:36 -05001483 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001484 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001485 } else {
1486 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001487 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001488 cmdiocb->context2)->list.next,
1489 struct lpfc_dmabuf, list);
1490 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001491 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001492 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001493 }
1494
James Smart2e0fef82007-06-17 19:56:36 -05001495 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001496 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001497 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001498
James Smart2e0fef82007-06-17 19:56:36 -05001499 if (vport->num_disc_nodes == 0) {
1500 spin_lock_irq(shost->host_lock);
1501 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1502 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001503
James Smart2e0fef82007-06-17 19:56:36 -05001504 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001505 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001506 }
1507 }
1508
1509out:
1510 lpfc_els_free_iocb(phba, cmdiocb);
1511 return;
1512}
1513
James Smarte59058c2008-08-24 21:49:00 -04001514/**
James Smart3621a712009-04-06 18:47:14 -04001515 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001516 * @vport: pointer to a host virtual N_Port data structure.
1517 * @did: destination port identifier.
1518 * @retry: number of retries to the command IOCB.
1519 *
1520 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1521 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1522 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1523 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1524 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1525 *
1526 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1527 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1528 * will be stored into the context1 field of the IOCB for the completion
1529 * callback function to the PLOGI ELS command.
1530 *
1531 * Return code
1532 * 0 - Successfully issued a plogi for @vport
1533 * 1 - failed to issue a plogi for @vport
1534 **/
dea31012005-04-17 16:05:31 -05001535int
James Smart2e0fef82007-06-17 19:56:36 -05001536lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001537{
James Smart2e0fef82007-06-17 19:56:36 -05001538 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001539 struct serv_parm *sp;
1540 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001541 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001542 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001543 struct lpfc_sli *psli;
1544 uint8_t *pcmd;
1545 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001546 int ret;
dea31012005-04-17 16:05:31 -05001547
1548 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001549
James Smart98c9ea52007-10-27 13:37:33 -04001550 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001551 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1552 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001553
James Smarte47c9092008-02-08 18:49:26 -05001554 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001555 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001556 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001557 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001558 if (!elsiocb)
1559 return 1;
dea31012005-04-17 16:05:31 -05001560
1561 icmd = &elsiocb->iocb;
1562 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1563
1564 /* For PLOGI request, remainder of payload is service parameters */
1565 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001566 pcmd += sizeof(uint32_t);
1567 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001568 sp = (struct serv_parm *) pcmd;
1569
1570 if (sp->cmn.fcphLow < FC_PH_4_3)
1571 sp->cmn.fcphLow = FC_PH_4_3;
1572
1573 if (sp->cmn.fcphHigh < FC_PH3)
1574 sp->cmn.fcphHigh = FC_PH3;
1575
James Smart858c9f62007-06-17 19:56:39 -05001576 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1577 "Issue PLOGI: did:x%x",
1578 did, 0, 0);
1579
dea31012005-04-17 16:05:31 -05001580 phba->fc_stat.elsXmitPLOGI++;
1581 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001582 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001583
1584 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001585 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001586 return 1;
dea31012005-04-17 16:05:31 -05001587 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001588 return 0;
dea31012005-04-17 16:05:31 -05001589}
1590
James Smarte59058c2008-08-24 21:49:00 -04001591/**
James Smart3621a712009-04-06 18:47:14 -04001592 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001593 * @phba: pointer to lpfc hba data structure.
1594 * @cmdiocb: pointer to lpfc command iocb data structure.
1595 * @rspiocb: pointer to lpfc response iocb data structure.
1596 *
1597 * This routine is the completion callback function for a Process Login
1598 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1599 * status. If there is error status reported, PRLI retry shall be attempted
1600 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1601 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1602 * ndlp to mark the PRLI completion.
1603 **/
dea31012005-04-17 16:05:31 -05001604static void
James Smart2e0fef82007-06-17 19:56:36 -05001605lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1606 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001607{
James Smart2e0fef82007-06-17 19:56:36 -05001608 struct lpfc_vport *vport = cmdiocb->vport;
1609 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001610 IOCB_t *irsp;
1611 struct lpfc_sli *psli;
1612 struct lpfc_nodelist *ndlp;
1613
1614 psli = &phba->sli;
1615 /* we pass cmdiocb to state machine which needs rspiocb as well */
1616 cmdiocb->context_un.rsp_iocb = rspiocb;
1617
1618 irsp = &(rspiocb->iocb);
1619 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001620 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001621 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001622 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001623
James Smart858c9f62007-06-17 19:56:39 -05001624 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1625 "PRLI cmpl: status:x%x/x%x did:x%x",
1626 irsp->ulpStatus, irsp->un.ulpWord[4],
1627 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001628 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001629 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1630 "0103 PRLI completes to NPort x%x "
1631 "Data: x%x x%x x%x x%x\n",
1632 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1633 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001634
James Smart2e0fef82007-06-17 19:56:36 -05001635 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001636 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001637 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001638 goto out;
1639
1640 if (irsp->ulpStatus) {
1641 /* Check for retry */
1642 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1643 /* ELS command is being retried */
1644 goto out;
1645 }
1646 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001647 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1648 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1649 ndlp->nlp_DID, irsp->ulpStatus,
1650 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001651 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001652 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001653 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001654 else
James Smart2e0fef82007-06-17 19:56:36 -05001655 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001656 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001657 } else
dea31012005-04-17 16:05:31 -05001658 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001659 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001660 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001661out:
1662 lpfc_els_free_iocb(phba, cmdiocb);
1663 return;
1664}
1665
James Smarte59058c2008-08-24 21:49:00 -04001666/**
James Smart3621a712009-04-06 18:47:14 -04001667 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001668 * @vport: pointer to a host virtual N_Port data structure.
1669 * @ndlp: pointer to a node-list data structure.
1670 * @retry: number of retries to the command IOCB.
1671 *
1672 * This routine issues a Process Login (PRLI) ELS command for the
1673 * @vport. The PRLI service parameters are set up in the payload of the
1674 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1675 * is put to the IOCB completion callback func field before invoking the
1676 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1677 *
1678 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1679 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1680 * will be stored into the context1 field of the IOCB for the completion
1681 * callback function to the PRLI ELS command.
1682 *
1683 * Return code
1684 * 0 - successfully issued prli iocb command for @vport
1685 * 1 - failed to issue prli iocb command for @vport
1686 **/
dea31012005-04-17 16:05:31 -05001687int
James Smart2e0fef82007-06-17 19:56:36 -05001688lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001689 uint8_t retry)
1690{
James Smart2e0fef82007-06-17 19:56:36 -05001691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1692 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001693 PRLI *npr;
1694 IOCB_t *icmd;
1695 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001696 uint8_t *pcmd;
1697 uint16_t cmdsize;
1698
James Smart92d7f7b2007-06-17 19:56:38 -05001699 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001700 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1701 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001702 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001703 return 1;
dea31012005-04-17 16:05:31 -05001704
1705 icmd = &elsiocb->iocb;
1706 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1707
1708 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001709 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001710 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001711 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001712
1713 /* For PRLI, remainder of payload is PRLI parameter page */
1714 npr = (PRLI *) pcmd;
1715 /*
1716 * If our firmware version is 3.20 or later,
1717 * set the following bits for FC-TAPE support.
1718 */
1719 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1720 npr->ConfmComplAllowed = 1;
1721 npr->Retry = 1;
1722 npr->TaskRetryIdReq = 1;
1723 }
1724 npr->estabImagePair = 1;
1725 npr->readXferRdyDis = 1;
1726
1727 /* For FCP support */
1728 npr->prliType = PRLI_FCP_TYPE;
1729 npr->initiatorFunc = 1;
1730
James Smart858c9f62007-06-17 19:56:39 -05001731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1732 "Issue PRLI: did:x%x",
1733 ndlp->nlp_DID, 0, 0);
1734
dea31012005-04-17 16:05:31 -05001735 phba->fc_stat.elsXmitPRLI++;
1736 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001737 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001738 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001739 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001740 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1741 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001742 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001743 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001744 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001745 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001746 return 1;
dea31012005-04-17 16:05:31 -05001747 }
James Smart2e0fef82007-06-17 19:56:36 -05001748 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001749 return 0;
dea31012005-04-17 16:05:31 -05001750}
1751
James Smarte59058c2008-08-24 21:49:00 -04001752/**
James Smart3621a712009-04-06 18:47:14 -04001753 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001754 * @vport: pointer to a host virtual N_Port data structure.
1755 *
1756 * This routine performs Registration State Change Notification (RSCN)
1757 * discovery for a @vport. If the @vport's node port recovery count is not
1758 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1759 * the nodes that need recovery. If none of the PLOGI were needed through
1760 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1761 * invoked to check and handle possible more RSCN came in during the period
1762 * of processing the current ones.
1763 **/
1764static void
1765lpfc_rscn_disc(struct lpfc_vport *vport)
1766{
1767 lpfc_can_disctmo(vport);
1768
1769 /* RSCN discovery */
1770 /* go thru NPR nodes and issue ELS PLOGIs */
1771 if (vport->fc_npr_cnt)
1772 if (lpfc_els_disc_plogi(vport))
1773 return;
1774
1775 lpfc_end_rscn(vport);
1776}
1777
1778/**
James Smart3621a712009-04-06 18:47:14 -04001779 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001780 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1781 *
1782 * This function is called when the final ADISC is completed during discovery.
1783 * This function handles clearing link attention or issuing reg_vpi depending
1784 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1785 * discovery.
1786 * This function is called with no locks held.
1787 **/
1788static void
1789lpfc_adisc_done(struct lpfc_vport *vport)
1790{
1791 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1792 struct lpfc_hba *phba = vport->phba;
1793
1794 /*
1795 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1796 * and continue discovery.
1797 */
1798 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001799 !(vport->fc_flag & FC_RSCN_MODE) &&
1800 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001801 lpfc_issue_reg_vpi(phba, vport);
1802 return;
1803 }
1804 /*
1805 * For SLI2, we need to set port_state to READY
1806 * and continue discovery.
1807 */
1808 if (vport->port_state < LPFC_VPORT_READY) {
1809 /* If we get here, there is nothing to ADISC */
1810 if (vport->port_type == LPFC_PHYSICAL_PORT)
1811 lpfc_issue_clear_la(phba, vport);
1812 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1813 vport->num_disc_nodes = 0;
1814 /* go thru NPR list, issue ELS PLOGIs */
1815 if (vport->fc_npr_cnt)
1816 lpfc_els_disc_plogi(vport);
1817 if (!vport->num_disc_nodes) {
1818 spin_lock_irq(shost->host_lock);
1819 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1820 spin_unlock_irq(shost->host_lock);
1821 lpfc_can_disctmo(vport);
1822 lpfc_end_rscn(vport);
1823 }
1824 }
1825 vport->port_state = LPFC_VPORT_READY;
1826 } else
1827 lpfc_rscn_disc(vport);
1828}
1829
1830/**
James Smart3621a712009-04-06 18:47:14 -04001831 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001832 * @vport: pointer to a host virtual N_Port data structure.
1833 *
1834 * This routine determines whether there are more ndlps on a @vport
1835 * node list need to have Address Discover (ADISC) issued. If so, it will
1836 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1837 * remaining nodes which need to have ADISC sent.
1838 **/
James Smart0ff10d42008-01-11 01:52:36 -05001839void
James Smart2e0fef82007-06-17 19:56:36 -05001840lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001841{
1842 int sentadisc;
1843
James Smart2e0fef82007-06-17 19:56:36 -05001844 if (vport->num_disc_nodes)
1845 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001846 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001847 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1848 "0210 Continue discovery with %d ADISCs to go "
1849 "Data: x%x x%x x%x\n",
1850 vport->num_disc_nodes, vport->fc_adisc_cnt,
1851 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001852 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001853 if (vport->fc_flag & FC_NLP_MORE) {
1854 lpfc_set_disctmo(vport);
1855 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1856 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001857 }
James Smart90160e02008-08-24 21:49:45 -04001858 if (!vport->num_disc_nodes)
1859 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001860 return;
1861}
1862
James Smarte59058c2008-08-24 21:49:00 -04001863/**
James Smart3621a712009-04-06 18:47:14 -04001864 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001865 * @phba: pointer to lpfc hba data structure.
1866 * @cmdiocb: pointer to lpfc command iocb data structure.
1867 * @rspiocb: pointer to lpfc response iocb data structure.
1868 *
1869 * This routine is the completion function for issuing the Address Discover
1870 * (ADISC) command. It first checks to see whether link went down during
1871 * the discovery process. If so, the node will be marked as node port
1872 * recovery for issuing discover IOCB by the link attention handler and
1873 * exit. Otherwise, the response status is checked. If error was reported
1874 * in the response status, the ADISC command shall be retried by invoking
1875 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1876 * the response status, the state machine is invoked to set transition
1877 * with respect to NLP_EVT_CMPL_ADISC event.
1878 **/
dea31012005-04-17 16:05:31 -05001879static void
James Smart2e0fef82007-06-17 19:56:36 -05001880lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1881 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001882{
James Smart2e0fef82007-06-17 19:56:36 -05001883 struct lpfc_vport *vport = cmdiocb->vport;
1884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001885 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001886 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001887 int disc;
dea31012005-04-17 16:05:31 -05001888
1889 /* we pass cmdiocb to state machine which needs rspiocb as well */
1890 cmdiocb->context_un.rsp_iocb = rspiocb;
1891
1892 irsp = &(rspiocb->iocb);
1893 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001894
James Smart858c9f62007-06-17 19:56:39 -05001895 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1896 "ADISC cmpl: status:x%x/x%x did:x%x",
1897 irsp->ulpStatus, irsp->un.ulpWord[4],
1898 ndlp->nlp_DID);
1899
dea31012005-04-17 16:05:31 -05001900 /* Since ndlp can be freed in the disc state machine, note if this node
1901 * is being used during discovery.
1902 */
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001904 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001905 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001906 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001907 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001908 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1909 "0104 ADISC completes to NPort x%x "
1910 "Data: x%x x%x x%x x%x x%x\n",
1911 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1912 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001913 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001914 if (lpfc_els_chk_latt(vport)) {
1915 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001916 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001917 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001918 goto out;
1919 }
1920
1921 if (irsp->ulpStatus) {
1922 /* Check for retry */
1923 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1924 /* ELS command is being retried */
1925 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001926 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001927 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001928 spin_unlock_irq(shost->host_lock);
1929 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001930 }
1931 goto out;
1932 }
1933 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001934 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1935 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1936 ndlp->nlp_DID, irsp->ulpStatus,
1937 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001938 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001939 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001940 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001941 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001942 } else
dea31012005-04-17 16:05:31 -05001943 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001944 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001945 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001946
James Smart90160e02008-08-24 21:49:45 -04001947 /* Check to see if there are more ADISCs to be sent */
1948 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001949 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001950out:
1951 lpfc_els_free_iocb(phba, cmdiocb);
1952 return;
1953}
1954
James Smarte59058c2008-08-24 21:49:00 -04001955/**
James Smart3621a712009-04-06 18:47:14 -04001956 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001957 * @vport: pointer to a virtual N_Port data structure.
1958 * @ndlp: pointer to a node-list data structure.
1959 * @retry: number of retries to the command IOCB.
1960 *
1961 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1962 * @vport. It prepares the payload of the ADISC ELS command, updates the
1963 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1964 * to issue the ADISC ELS command.
1965 *
1966 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1967 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1968 * will be stored into the context1 field of the IOCB for the completion
1969 * callback function to the ADISC ELS command.
1970 *
1971 * Return code
1972 * 0 - successfully issued adisc
1973 * 1 - failed to issue adisc
1974 **/
dea31012005-04-17 16:05:31 -05001975int
James Smart2e0fef82007-06-17 19:56:36 -05001976lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001977 uint8_t retry)
1978{
James Smart2e0fef82007-06-17 19:56:36 -05001979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1980 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001981 ADISC *ap;
1982 IOCB_t *icmd;
1983 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001984 uint8_t *pcmd;
1985 uint16_t cmdsize;
1986
James Smart92d7f7b2007-06-17 19:56:38 -05001987 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001988 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1989 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001990 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001991 return 1;
dea31012005-04-17 16:05:31 -05001992
1993 icmd = &elsiocb->iocb;
1994 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1995
1996 /* For ADISC request, remainder of payload is service parameters */
1997 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001998 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001999
2000 /* Fill in ADISC payload */
2001 ap = (ADISC *) pcmd;
2002 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002003 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2004 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002005 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002006
James Smart858c9f62007-06-17 19:56:39 -05002007 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2008 "Issue ADISC: did:x%x",
2009 ndlp->nlp_DID, 0, 0);
2010
dea31012005-04-17 16:05:31 -05002011 phba->fc_stat.elsXmitADISC++;
2012 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002013 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002014 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002015 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002016 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2017 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002018 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002019 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002020 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002021 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002022 return 1;
dea31012005-04-17 16:05:31 -05002023 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002024 return 0;
dea31012005-04-17 16:05:31 -05002025}
2026
James Smarte59058c2008-08-24 21:49:00 -04002027/**
James Smart3621a712009-04-06 18:47:14 -04002028 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002029 * @phba: pointer to lpfc hba data structure.
2030 * @cmdiocb: pointer to lpfc command iocb data structure.
2031 * @rspiocb: pointer to lpfc response iocb data structure.
2032 *
2033 * This routine is the completion function for issuing the ELS Logout (LOGO)
2034 * command. If no error status was reported from the LOGO response, the
2035 * state machine of the associated ndlp shall be invoked for transition with
2036 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2037 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2038 **/
dea31012005-04-17 16:05:31 -05002039static void
James Smart2e0fef82007-06-17 19:56:36 -05002040lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2041 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002042{
James Smart2e0fef82007-06-17 19:56:36 -05002043 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2044 struct lpfc_vport *vport = ndlp->vport;
2045 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002046 IOCB_t *irsp;
2047 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002048
2049 psli = &phba->sli;
2050 /* we pass cmdiocb to state machine which needs rspiocb as well */
2051 cmdiocb->context_un.rsp_iocb = rspiocb;
2052
2053 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002054 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002055 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002056 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002057
James Smart858c9f62007-06-17 19:56:39 -05002058 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2059 "LOGO cmpl: status:x%x/x%x did:x%x",
2060 irsp->ulpStatus, irsp->un.ulpWord[4],
2061 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002062 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2064 "0105 LOGO completes to NPort x%x "
2065 "Data: x%x x%x x%x x%x\n",
2066 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2067 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002068 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002069 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002070 goto out;
2071
James Smart92d7f7b2007-06-17 19:56:38 -05002072 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2073 /* NLP_EVT_DEVICE_RM should unregister the RPI
2074 * which should abort all outstanding IOs.
2075 */
2076 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2077 NLP_EVT_DEVICE_RM);
2078 goto out;
2079 }
2080
dea31012005-04-17 16:05:31 -05002081 if (irsp->ulpStatus) {
2082 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002083 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002084 /* ELS command is being retried */
2085 goto out;
dea31012005-04-17 16:05:31 -05002086 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002087 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2088 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2089 ndlp->nlp_DID, irsp->ulpStatus,
2090 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002091 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002092 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002093 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002094 else
James Smart2e0fef82007-06-17 19:56:36 -05002095 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002096 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002097 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002098 /* Good status, call state machine.
2099 * This will unregister the rpi if needed.
2100 */
James Smart2e0fef82007-06-17 19:56:36 -05002101 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002102 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002103out:
2104 lpfc_els_free_iocb(phba, cmdiocb);
2105 return;
2106}
2107
James Smarte59058c2008-08-24 21:49:00 -04002108/**
James Smart3621a712009-04-06 18:47:14 -04002109 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002110 * @vport: pointer to a virtual N_Port data structure.
2111 * @ndlp: pointer to a node-list data structure.
2112 * @retry: number of retries to the command IOCB.
2113 *
2114 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2115 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2116 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2117 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2118 *
2119 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2120 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2121 * will be stored into the context1 field of the IOCB for the completion
2122 * callback function to the LOGO ELS command.
2123 *
2124 * Return code
2125 * 0 - successfully issued logo
2126 * 1 - failed to issue logo
2127 **/
dea31012005-04-17 16:05:31 -05002128int
James Smart2e0fef82007-06-17 19:56:36 -05002129lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002130 uint8_t retry)
2131{
James Smart2e0fef82007-06-17 19:56:36 -05002132 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2133 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002134 IOCB_t *icmd;
2135 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002136 uint8_t *pcmd;
2137 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002138 int rc;
dea31012005-04-17 16:05:31 -05002139
James Smart98c9ea52007-10-27 13:37:33 -04002140 spin_lock_irq(shost->host_lock);
2141 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2142 spin_unlock_irq(shost->host_lock);
2143 return 0;
2144 }
2145 spin_unlock_irq(shost->host_lock);
2146
James Smart92d7f7b2007-06-17 19:56:38 -05002147 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002148 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2149 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002150 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002151 return 1;
dea31012005-04-17 16:05:31 -05002152
2153 icmd = &elsiocb->iocb;
2154 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2155 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002156 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002157
2158 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002159 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002160 pcmd += sizeof(uint32_t);
2161 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002162
James Smart858c9f62007-06-17 19:56:39 -05002163 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2164 "Issue LOGO: did:x%x",
2165 ndlp->nlp_DID, 0, 0);
2166
dea31012005-04-17 16:05:31 -05002167 phba->fc_stat.elsXmitLOGO++;
2168 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002169 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002170 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002171 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002172 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002173
2174 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002175 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002176 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002177 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002178 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002179 return 1;
dea31012005-04-17 16:05:31 -05002180 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002181 return 0;
dea31012005-04-17 16:05:31 -05002182}
2183
James Smarte59058c2008-08-24 21:49:00 -04002184/**
James Smart3621a712009-04-06 18:47:14 -04002185 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002186 * @phba: pointer to lpfc hba data structure.
2187 * @cmdiocb: pointer to lpfc command iocb data structure.
2188 * @rspiocb: pointer to lpfc response iocb data structure.
2189 *
2190 * This routine is a generic completion callback function for ELS commands.
2191 * Specifically, it is the callback function which does not need to perform
2192 * any command specific operations. It is currently used by the ELS command
2193 * issuing routines for the ELS State Change Request (SCR),
2194 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2195 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2196 * certain debug loggings, this callback function simply invokes the
2197 * lpfc_els_chk_latt() routine to check whether link went down during the
2198 * discovery process.
2199 **/
dea31012005-04-17 16:05:31 -05002200static void
James Smart2e0fef82007-06-17 19:56:36 -05002201lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2202 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002203{
James Smart2e0fef82007-06-17 19:56:36 -05002204 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002205 IOCB_t *irsp;
2206
2207 irsp = &rspiocb->iocb;
2208
James Smart858c9f62007-06-17 19:56:39 -05002209 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2210 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2211 irsp->ulpStatus, irsp->un.ulpWord[4],
2212 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002213 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002214 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2215 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2216 irsp->ulpIoTag, irsp->ulpStatus,
2217 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002218 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002219 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002220 lpfc_els_free_iocb(phba, cmdiocb);
2221 return;
2222}
2223
James Smarte59058c2008-08-24 21:49:00 -04002224/**
James Smart3621a712009-04-06 18:47:14 -04002225 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002226 * @vport: pointer to a host virtual N_Port data structure.
2227 * @nportid: N_Port identifier to the remote node.
2228 * @retry: number of retries to the command IOCB.
2229 *
2230 * This routine issues a State Change Request (SCR) to a fabric node
2231 * on a @vport. The remote node @nportid is passed into the function. It
2232 * first search the @vport node list to find the matching ndlp. If no such
2233 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2234 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2235 * routine is invoked to send the SCR IOCB.
2236 *
2237 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2238 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2239 * will be stored into the context1 field of the IOCB for the completion
2240 * callback function to the SCR ELS command.
2241 *
2242 * Return code
2243 * 0 - Successfully issued scr command
2244 * 1 - Failed to issue scr command
2245 **/
dea31012005-04-17 16:05:31 -05002246int
James Smart2e0fef82007-06-17 19:56:36 -05002247lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002248{
James Smart2e0fef82007-06-17 19:56:36 -05002249 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002250 IOCB_t *icmd;
2251 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002252 struct lpfc_sli *psli;
2253 uint8_t *pcmd;
2254 uint16_t cmdsize;
2255 struct lpfc_nodelist *ndlp;
2256
2257 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002258 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002259
James Smarte47c9092008-02-08 18:49:26 -05002260 ndlp = lpfc_findnode_did(vport, nportid);
2261 if (!ndlp) {
2262 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2263 if (!ndlp)
2264 return 1;
2265 lpfc_nlp_init(vport, ndlp, nportid);
2266 lpfc_enqueue_node(vport, ndlp);
2267 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2268 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2269 if (!ndlp)
2270 return 1;
2271 }
dea31012005-04-17 16:05:31 -05002272
James Smart2e0fef82007-06-17 19:56:36 -05002273 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2274 ndlp->nlp_DID, ELS_CMD_SCR);
2275
James Smart488d1462006-03-07 15:02:37 -05002276 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002277 /* This will trigger the release of the node just
2278 * allocated
2279 */
James Smart329f9bc2007-04-25 09:53:01 -04002280 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002281 return 1;
dea31012005-04-17 16:05:31 -05002282 }
2283
2284 icmd = &elsiocb->iocb;
2285 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2286
2287 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002288 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002289
2290 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002291 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002292 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2293
James Smart858c9f62007-06-17 19:56:39 -05002294 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2295 "Issue SCR: did:x%x",
2296 ndlp->nlp_DID, 0, 0);
2297
dea31012005-04-17 16:05:31 -05002298 phba->fc_stat.elsXmitSCR++;
2299 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002300 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2301 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002302 /* The additional lpfc_nlp_put will cause the following
2303 * lpfc_els_free_iocb routine to trigger the rlease of
2304 * the node.
2305 */
James Smart329f9bc2007-04-25 09:53:01 -04002306 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002307 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002308 return 1;
dea31012005-04-17 16:05:31 -05002309 }
James Smartfa4066b2008-01-11 01:53:27 -05002310 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2311 * trigger the release of node.
2312 */
James Smart329f9bc2007-04-25 09:53:01 -04002313 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002314 return 0;
dea31012005-04-17 16:05:31 -05002315}
2316
James Smarte59058c2008-08-24 21:49:00 -04002317/**
James Smart3621a712009-04-06 18:47:14 -04002318 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002319 * @vport: pointer to a host virtual N_Port data structure.
2320 * @nportid: N_Port identifier to the remote node.
2321 * @retry: number of retries to the command IOCB.
2322 *
2323 * This routine issues a Fibre Channel Address Resolution Response
2324 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2325 * is passed into the function. It first search the @vport node list to find
2326 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2327 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2328 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2329 *
2330 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2331 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2332 * will be stored into the context1 field of the IOCB for the completion
2333 * callback function to the PARPR ELS command.
2334 *
2335 * Return code
2336 * 0 - Successfully issued farpr command
2337 * 1 - Failed to issue farpr command
2338 **/
dea31012005-04-17 16:05:31 -05002339static int
James Smart2e0fef82007-06-17 19:56:36 -05002340lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002341{
James Smart2e0fef82007-06-17 19:56:36 -05002342 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002343 IOCB_t *icmd;
2344 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002345 struct lpfc_sli *psli;
2346 FARP *fp;
2347 uint8_t *pcmd;
2348 uint32_t *lp;
2349 uint16_t cmdsize;
2350 struct lpfc_nodelist *ondlp;
2351 struct lpfc_nodelist *ndlp;
2352
2353 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002354 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002355
James Smarte47c9092008-02-08 18:49:26 -05002356 ndlp = lpfc_findnode_did(vport, nportid);
2357 if (!ndlp) {
2358 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2359 if (!ndlp)
2360 return 1;
2361 lpfc_nlp_init(vport, ndlp, nportid);
2362 lpfc_enqueue_node(vport, ndlp);
2363 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2364 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2365 if (!ndlp)
2366 return 1;
2367 }
James Smart2e0fef82007-06-17 19:56:36 -05002368
2369 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2370 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002371 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002372 /* This will trigger the release of the node just
2373 * allocated
2374 */
James Smart329f9bc2007-04-25 09:53:01 -04002375 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002376 return 1;
dea31012005-04-17 16:05:31 -05002377 }
2378
2379 icmd = &elsiocb->iocb;
2380 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2381
2382 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002383 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002384
2385 /* Fill in FARPR payload */
2386 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002387 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002388 lp = (uint32_t *) pcmd;
2389 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002390 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002391 fp->Rflags = 0;
2392 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2393
James Smart92d7f7b2007-06-17 19:56:38 -05002394 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2395 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002396 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002397 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002398 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002399 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002400 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002401 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002402 }
2403
James Smart858c9f62007-06-17 19:56:39 -05002404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2405 "Issue FARPR: did:x%x",
2406 ndlp->nlp_DID, 0, 0);
2407
dea31012005-04-17 16:05:31 -05002408 phba->fc_stat.elsXmitFARPR++;
2409 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002410 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2411 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002412 /* The additional lpfc_nlp_put will cause the following
2413 * lpfc_els_free_iocb routine to trigger the release of
2414 * the node.
2415 */
James Smart329f9bc2007-04-25 09:53:01 -04002416 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002417 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002418 return 1;
dea31012005-04-17 16:05:31 -05002419 }
James Smartfa4066b2008-01-11 01:53:27 -05002420 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2421 * trigger the release of the node.
2422 */
James Smart329f9bc2007-04-25 09:53:01 -04002423 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002424 return 0;
dea31012005-04-17 16:05:31 -05002425}
2426
James Smarte59058c2008-08-24 21:49:00 -04002427/**
James Smart3621a712009-04-06 18:47:14 -04002428 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002429 * @vport: pointer to a host virtual N_Port data structure.
2430 * @nlp: pointer to a node-list data structure.
2431 *
2432 * This routine cancels the timer with a delayed IOCB-command retry for
2433 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2434 * removes the ELS retry event if it presents. In addition, if the
2435 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2436 * commands are sent for the @vport's nodes that require issuing discovery
2437 * ADISC.
2438 **/
dea31012005-04-17 16:05:31 -05002439void
James Smart2e0fef82007-06-17 19:56:36 -05002440lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002441{
James Smart2e0fef82007-06-17 19:56:36 -05002442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002443 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002444
James Smart0d2b6b82008-06-14 22:52:47 -04002445 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2446 return;
James Smart2e0fef82007-06-17 19:56:36 -05002447 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002448 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002449 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002450 del_timer_sync(&nlp->nlp_delayfunc);
2451 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002452 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002453 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002454 /* Decrement nlp reference count held for the delayed retry */
2455 evtp = &nlp->els_retry_evt;
2456 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2457 }
James Smartfdcebe22006-03-07 15:04:01 -05002458 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002459 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002460 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002461 spin_unlock_irq(shost->host_lock);
2462 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002463 if (vport->port_state < LPFC_VPORT_READY) {
2464 /* Check if there are more ADISCs to be sent */
2465 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002466 } else {
2467 /* Check if there are more PLOGIs to be sent */
2468 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002469 if (vport->num_disc_nodes == 0) {
2470 spin_lock_irq(shost->host_lock);
2471 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2472 spin_unlock_irq(shost->host_lock);
2473 lpfc_can_disctmo(vport);
2474 lpfc_end_rscn(vport);
2475 }
James Smartfdcebe22006-03-07 15:04:01 -05002476 }
2477 }
2478 }
2479 return;
2480}
2481
James Smarte59058c2008-08-24 21:49:00 -04002482/**
James Smart3621a712009-04-06 18:47:14 -04002483 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002484 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2485 *
2486 * This routine is invoked by the ndlp delayed-function timer to check
2487 * whether there is any pending ELS retry event(s) with the node. If not, it
2488 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2489 * adds the delayed events to the HBA work list and invokes the
2490 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2491 * event. Note that lpfc_nlp_get() is called before posting the event to
2492 * the work list to hold reference count of ndlp so that it guarantees the
2493 * reference to ndlp will still be available when the worker thread gets
2494 * to the event associated with the ndlp.
2495 **/
James Smartfdcebe22006-03-07 15:04:01 -05002496void
dea31012005-04-17 16:05:31 -05002497lpfc_els_retry_delay(unsigned long ptr)
2498{
James Smart2e0fef82007-06-17 19:56:36 -05002499 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2500 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002501 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002502 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002503 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002504
James Smart92d7f7b2007-06-17 19:56:38 -05002505 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002506 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002507 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002508 return;
2509 }
2510
James Smartfa4066b2008-01-11 01:53:27 -05002511 /* We need to hold the node by incrementing the reference
2512 * count until the queued work is done
2513 */
2514 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002515 if (evtp->evt_arg1) {
2516 evtp->evt = LPFC_EVT_ELS_RETRY;
2517 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002518 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002519 }
James Smart92d7f7b2007-06-17 19:56:38 -05002520 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002521 return;
2522}
2523
James Smarte59058c2008-08-24 21:49:00 -04002524/**
James Smart3621a712009-04-06 18:47:14 -04002525 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002526 * @ndlp: pointer to a node-list data structure.
2527 *
2528 * This routine is the worker-thread handler for processing the @ndlp delayed
2529 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2530 * the last ELS command from the associated ndlp and invokes the proper ELS
2531 * function according to the delayed ELS command to retry the command.
2532 **/
dea31012005-04-17 16:05:31 -05002533void
2534lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2535{
James Smart2e0fef82007-06-17 19:56:36 -05002536 struct lpfc_vport *vport = ndlp->vport;
2537 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2538 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002539
James Smart2e0fef82007-06-17 19:56:36 -05002540 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002541 did = ndlp->nlp_DID;
2542 cmd = ndlp->nlp_last_elscmd;
2543 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002544
2545 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002546 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002547 return;
2548 }
2549
2550 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002551 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002552 /*
2553 * If a discovery event readded nlp_delayfunc after timer
2554 * firing and before processing the timer, cancel the
2555 * nlp_delayfunc.
2556 */
2557 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002558 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002559 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002560
2561 switch (cmd) {
2562 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002563 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002564 break;
2565 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002566 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002567 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002568 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002569 }
dea31012005-04-17 16:05:31 -05002570 break;
2571 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002572 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002573 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002574 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002575 }
dea31012005-04-17 16:05:31 -05002576 break;
2577 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002578 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002579 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002580 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002581 }
dea31012005-04-17 16:05:31 -05002582 break;
2583 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002584 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002585 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002586 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002587 }
dea31012005-04-17 16:05:31 -05002588 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002589 case ELS_CMD_FDISC:
2590 lpfc_issue_els_fdisc(vport, ndlp, retry);
2591 break;
dea31012005-04-17 16:05:31 -05002592 }
2593 return;
2594}
2595
James Smarte59058c2008-08-24 21:49:00 -04002596/**
James Smart3621a712009-04-06 18:47:14 -04002597 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002598 * @phba: pointer to lpfc hba data structure.
2599 * @cmdiocb: pointer to lpfc command iocb data structure.
2600 * @rspiocb: pointer to lpfc response iocb data structure.
2601 *
2602 * This routine makes a retry decision on an ELS command IOCB, which has
2603 * failed. The following ELS IOCBs use this function for retrying the command
2604 * when previously issued command responsed with error status: FLOGI, PLOGI,
2605 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2606 * returned error status, it makes the decision whether a retry shall be
2607 * issued for the command, and whether a retry shall be made immediately or
2608 * delayed. In the former case, the corresponding ELS command issuing-function
2609 * is called to retry the command. In the later case, the ELS command shall
2610 * be posted to the ndlp delayed event and delayed function timer set to the
2611 * ndlp for the delayed command issusing.
2612 *
2613 * Return code
2614 * 0 - No retry of els command is made
2615 * 1 - Immediate or delayed retry of els command is made
2616 **/
dea31012005-04-17 16:05:31 -05002617static int
James Smart2e0fef82007-06-17 19:56:36 -05002618lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2619 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002620{
James Smart2e0fef82007-06-17 19:56:36 -05002621 struct lpfc_vport *vport = cmdiocb->vport;
2622 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2623 IOCB_t *irsp = &rspiocb->iocb;
2624 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2625 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002626 uint32_t *elscmd;
2627 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002628 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002629 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002630 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002631 uint32_t did;
dea31012005-04-17 16:05:31 -05002632
James Smart488d1462006-03-07 15:02:37 -05002633
dea31012005-04-17 16:05:31 -05002634 /* Note: context2 may be 0 for internal driver abort
2635 * of delays ELS command.
2636 */
2637
2638 if (pcmd && pcmd->virt) {
2639 elscmd = (uint32_t *) (pcmd->virt);
2640 cmd = *elscmd++;
2641 }
2642
James Smarte47c9092008-02-08 18:49:26 -05002643 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002644 did = ndlp->nlp_DID;
2645 else {
2646 /* We should only hit this case for retrying PLOGI */
2647 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002648 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002649 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2650 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002651 return 1;
2652 }
2653
James Smart858c9f62007-06-17 19:56:39 -05002654 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2655 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2656 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2657
dea31012005-04-17 16:05:31 -05002658 switch (irsp->ulpStatus) {
2659 case IOSTAT_FCP_RSP_ERROR:
2660 case IOSTAT_REMOTE_STOP:
2661 break;
2662
2663 case IOSTAT_LOCAL_REJECT:
2664 switch ((irsp->un.ulpWord[4] & 0xff)) {
2665 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002666 if (cmd == ELS_CMD_FLOGI) {
2667 if (PCI_DEVICE_ID_HORNET ==
2668 phba->pcidev->device) {
2669 phba->fc_topology = TOPOLOGY_LOOP;
2670 phba->pport->fc_myDID = 0;
2671 phba->alpa_map[0] = 0;
2672 phba->alpa_map[1] = 0;
2673 }
2674 }
James Smart2e0fef82007-06-17 19:56:36 -05002675 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002676 delay = 1000;
dea31012005-04-17 16:05:31 -05002677 retry = 1;
2678 break;
2679
James Smart92d7f7b2007-06-17 19:56:38 -05002680 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002681 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2682 "0124 Retry illegal cmd x%x "
2683 "retry:x%x delay:x%x\n",
2684 cmd, cmdiocb->retry, delay);
2685 retry = 1;
2686 /* All command's retry policy */
2687 maxretry = 8;
2688 if (cmdiocb->retry > 2)
2689 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002690 break;
2691
dea31012005-04-17 16:05:31 -05002692 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002693 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002694 retry = 1;
2695 if (cmdiocb->retry > 100)
2696 delay = 100;
2697 maxretry = 250;
2698 break;
2699
2700 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002701 delay = 100;
dea31012005-04-17 16:05:31 -05002702 retry = 1;
2703 break;
2704
James Smart858c9f62007-06-17 19:56:39 -05002705 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002706 case IOERR_INVALID_RPI:
2707 retry = 1;
2708 break;
2709 }
2710 break;
2711
2712 case IOSTAT_NPORT_RJT:
2713 case IOSTAT_FABRIC_RJT:
2714 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2715 retry = 1;
2716 break;
2717 }
2718 break;
2719
2720 case IOSTAT_NPORT_BSY:
2721 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002722 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002723 retry = 1;
2724 break;
2725
2726 case IOSTAT_LS_RJT:
2727 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2728 /* Added for Vendor specifc support
2729 * Just keep retrying for these Rsn / Exp codes
2730 */
2731 switch (stat.un.b.lsRjtRsnCode) {
2732 case LSRJT_UNABLE_TPC:
2733 if (stat.un.b.lsRjtRsnCodeExp ==
2734 LSEXP_CMD_IN_PROGRESS) {
2735 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002736 delay = 1000;
dea31012005-04-17 16:05:31 -05002737 maxretry = 48;
2738 }
2739 retry = 1;
2740 break;
2741 }
2742 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002743 delay = 1000;
dea31012005-04-17 16:05:31 -05002744 maxretry = lpfc_max_els_tries + 1;
2745 retry = 1;
2746 break;
2747 }
James Smart92d7f7b2007-06-17 19:56:38 -05002748 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2749 (cmd == ELS_CMD_FDISC) &&
2750 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2752 "0125 FDISC Failed (x%x). "
2753 "Fabric out of resources\n",
2754 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002755 lpfc_vport_set_state(vport,
2756 FC_VPORT_NO_FABRIC_RSCS);
2757 }
dea31012005-04-17 16:05:31 -05002758 break;
2759
2760 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002761 if ((cmd == ELS_CMD_PLOGI) ||
2762 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002763 delay = 1000;
dea31012005-04-17 16:05:31 -05002764 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002765 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002766 /* FDISC retry policy */
2767 maxretry = 48;
2768 if (cmdiocb->retry >= 32)
2769 delay = 1000;
dea31012005-04-17 16:05:31 -05002770 }
2771 retry = 1;
2772 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002773
2774 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002775 /* There are some cases where switches return this
2776 * error when they are not ready and should be returning
2777 * Logical Busy. We should delay every time.
2778 */
2779 if (cmd == ELS_CMD_FDISC &&
2780 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2781 maxretry = 3;
2782 delay = 1000;
2783 retry = 1;
2784 break;
2785 }
James Smart92d7f7b2007-06-17 19:56:38 -05002786 case LSRJT_PROTOCOL_ERR:
2787 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2788 (cmd == ELS_CMD_FDISC) &&
2789 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2790 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2791 ) {
James Smarte8b62012007-08-02 11:10:09 -04002792 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002793 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002794 "Fabric Detected Bad WWN\n",
2795 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002796 lpfc_vport_set_state(vport,
2797 FC_VPORT_FABRIC_REJ_WWN);
2798 }
2799 break;
dea31012005-04-17 16:05:31 -05002800 }
2801 break;
2802
2803 case IOSTAT_INTERMED_RSP:
2804 case IOSTAT_BA_RJT:
2805 break;
2806
2807 default:
2808 break;
2809 }
2810
James Smart488d1462006-03-07 15:02:37 -05002811 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002812 retry = 1;
dea31012005-04-17 16:05:31 -05002813
James Smart695a8142010-01-26 23:08:03 -05002814 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002815 (phba->fc_topology != TOPOLOGY_LOOP) &&
2816 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002817 /* FLOGI retry policy */
2818 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002819 /* retry forever */
2820 maxretry = 0;
2821 if (cmdiocb->retry >= 100)
2822 delay = 5000;
2823 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002824 delay = 1000;
2825 }
2826
James Smart6669f9b2009-10-02 15:16:45 -04002827 cmdiocb->retry++;
2828 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002829 phba->fc_stat.elsRetryExceeded++;
2830 retry = 0;
2831 }
2832
James Smarted957682007-06-17 19:56:37 -05002833 if ((vport->load_flag & FC_UNLOADING) != 0)
2834 retry = 0;
2835
dea31012005-04-17 16:05:31 -05002836 if (retry) {
2837
2838 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002839 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2840 "0107 Retry ELS command x%x to remote "
2841 "NPORT x%x Data: x%x x%x\n",
2842 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002843
James Smart858c9f62007-06-17 19:56:39 -05002844 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2845 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2846 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2847 /* Don't reset timer for no resources */
2848
dea31012005-04-17 16:05:31 -05002849 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002850 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002851 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002852 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002853 }
2854
2855 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002856 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002857 phba->fc_stat.elsDelayRetry++;
2858 ndlp->nlp_retry = cmdiocb->retry;
2859
James Smart92d7f7b2007-06-17 19:56:38 -05002860 /* delay is specified in milliseconds */
2861 mod_timer(&ndlp->nlp_delayfunc,
2862 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002863 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002864 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002865 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002866
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002867 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002868 if (cmd == ELS_CMD_PRLI)
2869 lpfc_nlp_set_state(vport, ndlp,
2870 NLP_STE_REG_LOGIN_ISSUE);
2871 else
2872 lpfc_nlp_set_state(vport, ndlp,
2873 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002874 ndlp->nlp_last_elscmd = cmd;
2875
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002876 return 1;
dea31012005-04-17 16:05:31 -05002877 }
2878 switch (cmd) {
2879 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002880 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002881 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002882 case ELS_CMD_FDISC:
2883 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2884 return 1;
dea31012005-04-17 16:05:31 -05002885 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002886 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002887 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002888 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002889 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002890 }
James Smart2e0fef82007-06-17 19:56:36 -05002891 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002892 return 1;
dea31012005-04-17 16:05:31 -05002893 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002894 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002895 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2896 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002897 return 1;
dea31012005-04-17 16:05:31 -05002898 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002899 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002900 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2901 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002902 return 1;
dea31012005-04-17 16:05:31 -05002903 case ELS_CMD_LOGO:
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_NPR_NODE);
2906 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002907 return 1;
dea31012005-04-17 16:05:31 -05002908 }
2909 }
dea31012005-04-17 16:05:31 -05002910 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002911 if (logerr) {
2912 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2913 "0137 No retry ELS command x%x to remote "
2914 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2915 cmd, did, irsp->ulpStatus,
2916 irsp->un.ulpWord[4]);
2917 }
2918 else {
2919 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002920 "0108 No retry ELS command x%x to remote "
2921 "NPORT x%x Retried:%d Error:x%x/%x\n",
2922 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2923 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002924 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002925 return 0;
dea31012005-04-17 16:05:31 -05002926}
2927
James Smarte59058c2008-08-24 21:49:00 -04002928/**
James Smart3621a712009-04-06 18:47:14 -04002929 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002930 * @phba: pointer to lpfc hba data structure.
2931 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2932 *
2933 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2934 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2935 * checks to see whether there is a lpfc DMA buffer associated with the
2936 * response of the command IOCB. If so, it will be released before releasing
2937 * the lpfc DMA buffer associated with the IOCB itself.
2938 *
2939 * Return code
2940 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2941 **/
James Smart09372822008-01-11 01:52:54 -05002942static int
James Smart87af33f2007-10-27 13:37:43 -04002943lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2944{
2945 struct lpfc_dmabuf *buf_ptr;
2946
James Smarte59058c2008-08-24 21:49:00 -04002947 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002948 if (!list_empty(&buf_ptr1->list)) {
2949 list_remove_head(&buf_ptr1->list, buf_ptr,
2950 struct lpfc_dmabuf,
2951 list);
2952 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2953 kfree(buf_ptr);
2954 }
2955 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2956 kfree(buf_ptr1);
2957 return 0;
2958}
2959
James Smarte59058c2008-08-24 21:49:00 -04002960/**
James Smart3621a712009-04-06 18:47:14 -04002961 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002962 * @phba: pointer to lpfc hba data structure.
2963 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2964 *
2965 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2966 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2967 * pool.
2968 *
2969 * Return code
2970 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2971 **/
James Smart09372822008-01-11 01:52:54 -05002972static int
James Smart87af33f2007-10-27 13:37:43 -04002973lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2974{
2975 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2976 kfree(buf_ptr);
2977 return 0;
2978}
2979
James Smarte59058c2008-08-24 21:49:00 -04002980/**
James Smart3621a712009-04-06 18:47:14 -04002981 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002982 * @phba: pointer to lpfc hba data structure.
2983 * @elsiocb: pointer to lpfc els command iocb data structure.
2984 *
2985 * This routine frees a command IOCB and its associated resources. The
2986 * command IOCB data structure contains the reference to various associated
2987 * resources, these fields must be set to NULL if the associated reference
2988 * not present:
2989 * context1 - reference to ndlp
2990 * context2 - reference to cmd
2991 * context2->next - reference to rsp
2992 * context3 - reference to bpl
2993 *
2994 * It first properly decrements the reference count held on ndlp for the
2995 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2996 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2997 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2998 * adds the DMA buffer the @phba data structure for the delayed release.
2999 * If reference to the Buffer Pointer List (BPL) is present, the
3000 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3001 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3002 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3003 *
3004 * Return code
3005 * 0 - Success (currently, always return 0)
3006 **/
James Smart87af33f2007-10-27 13:37:43 -04003007int
James Smart329f9bc2007-04-25 09:53:01 -04003008lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003009{
3010 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003011 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003012
James Smarta8adb832007-10-27 13:37:53 -04003013 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3014 if (ndlp) {
3015 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3016 lpfc_nlp_put(ndlp);
3017
3018 /* If the ndlp is not being used by another discovery
3019 * thread, free it.
3020 */
3021 if (!lpfc_nlp_not_used(ndlp)) {
3022 /* If ndlp is being used by another discovery
3023 * thread, just clear NLP_DEFER_RM
3024 */
3025 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3026 }
3027 }
3028 else
3029 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003030 elsiocb->context1 = NULL;
3031 }
dea31012005-04-17 16:05:31 -05003032 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3033 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003034 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3035 /* Firmware could still be in progress of DMAing
3036 * payload, so don't free data buffer till after
3037 * a hbeat.
3038 */
3039 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3040 buf_ptr = elsiocb->context2;
3041 elsiocb->context2 = NULL;
3042 if (buf_ptr) {
3043 buf_ptr1 = NULL;
3044 spin_lock_irq(&phba->hbalock);
3045 if (!list_empty(&buf_ptr->list)) {
3046 list_remove_head(&buf_ptr->list,
3047 buf_ptr1, struct lpfc_dmabuf,
3048 list);
3049 INIT_LIST_HEAD(&buf_ptr1->list);
3050 list_add_tail(&buf_ptr1->list,
3051 &phba->elsbuf);
3052 phba->elsbuf_cnt++;
3053 }
3054 INIT_LIST_HEAD(&buf_ptr->list);
3055 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3056 phba->elsbuf_cnt++;
3057 spin_unlock_irq(&phba->hbalock);
3058 }
3059 } else {
3060 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3061 lpfc_els_free_data(phba, buf_ptr1);
3062 }
dea31012005-04-17 16:05:31 -05003063 }
3064
3065 if (elsiocb->context3) {
3066 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003067 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003068 }
James Bottomley604a3e32005-10-29 10:28:33 -05003069 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003070 return 0;
3071}
3072
James Smarte59058c2008-08-24 21:49:00 -04003073/**
James Smart3621a712009-04-06 18:47:14 -04003074 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003075 * @phba: pointer to lpfc hba data structure.
3076 * @cmdiocb: pointer to lpfc command iocb data structure.
3077 * @rspiocb: pointer to lpfc response iocb data structure.
3078 *
3079 * This routine is the completion callback function to the Logout (LOGO)
3080 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3081 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3082 * release the ndlp if it has the last reference remaining (reference count
3083 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3084 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3085 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3086 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3087 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3088 * IOCB data structure.
3089 **/
dea31012005-04-17 16:05:31 -05003090static void
James Smart2e0fef82007-06-17 19:56:36 -05003091lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3092 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003093{
James Smart2e0fef82007-06-17 19:56:36 -05003094 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3095 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003096 IOCB_t *irsp;
3097
3098 irsp = &rspiocb->iocb;
3099 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3100 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3101 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003102 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003103 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3104 "0109 ACC to LOGO completes to NPort x%x "
3105 "Data: x%x x%x x%x\n",
3106 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3107 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003108
3109 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3110 /* NPort Recovery mode or node is just allocated */
3111 if (!lpfc_nlp_not_used(ndlp)) {
3112 /* If the ndlp is being used by another discovery
3113 * thread, just unregister the RPI.
3114 */
3115 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003116 } else {
3117 /* Indicate the node has already released, should
3118 * not reference to it from within lpfc_els_free_iocb.
3119 */
3120 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003121 }
dea31012005-04-17 16:05:31 -05003122 }
3123 lpfc_els_free_iocb(phba, cmdiocb);
3124 return;
3125}
3126
James Smarte59058c2008-08-24 21:49:00 -04003127/**
James Smart3621a712009-04-06 18:47:14 -04003128 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003129 * @phba: pointer to lpfc hba data structure.
3130 * @pmb: pointer to the driver internal queue element for mailbox command.
3131 *
3132 * This routine is the completion callback function for unregister default
3133 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3134 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3135 * decrements the ndlp reference count held for this completion callback
3136 * function. After that, it invokes the lpfc_nlp_not_used() to check
3137 * whether there is only one reference left on the ndlp. If so, it will
3138 * perform one more decrement and trigger the release of the ndlp.
3139 **/
James Smart858c9f62007-06-17 19:56:39 -05003140void
3141lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3142{
3143 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3144 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3145
James Smart6fb120a2009-05-22 14:52:59 -04003146 /*
3147 * This routine is used to register and unregister in previous SLI
3148 * modes.
3149 */
3150 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3151 (phba->sli_rev == LPFC_SLI_REV4))
3152 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3153
James Smart858c9f62007-06-17 19:56:39 -05003154 pmb->context1 = NULL;
3155 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3156 kfree(mp);
3157 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003158 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003159 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003160 /* This is the end of the default RPI cleanup logic for this
3161 * ndlp. If no other discovery threads are using this ndlp.
3162 * we should free all resources associated with it.
3163 */
3164 lpfc_nlp_not_used(ndlp);
3165 }
James Smart3772a992009-05-22 14:50:54 -04003166
James Smart858c9f62007-06-17 19:56:39 -05003167 return;
3168}
3169
James Smarte59058c2008-08-24 21:49:00 -04003170/**
James Smart3621a712009-04-06 18:47:14 -04003171 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003172 * @phba: pointer to lpfc hba data structure.
3173 * @cmdiocb: pointer to lpfc command iocb data structure.
3174 * @rspiocb: pointer to lpfc response iocb data structure.
3175 *
3176 * This routine is the completion callback function for ELS Response IOCB
3177 * command. In normal case, this callback function just properly sets the
3178 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3179 * field in the command IOCB is not NULL, the referred mailbox command will
3180 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3181 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3182 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3183 * routine shall be invoked trying to release the ndlp if no other threads
3184 * are currently referring it.
3185 **/
dea31012005-04-17 16:05:31 -05003186static void
James Smart858c9f62007-06-17 19:56:39 -05003187lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003188 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003189{
James Smart2e0fef82007-06-17 19:56:36 -05003190 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3191 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3192 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003193 IOCB_t *irsp;
3194 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003195 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003196 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003197 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003198
James Smart33ccf8d2006-08-17 11:57:58 -04003199 irsp = &rspiocb->iocb;
3200
dea31012005-04-17 16:05:31 -05003201 if (cmdiocb->context_un.mbox)
3202 mbox = cmdiocb->context_un.mbox;
3203
James Smartfa4066b2008-01-11 01:53:27 -05003204 /* First determine if this is a LS_RJT cmpl. Note, this callback
3205 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3206 */
James Smart87af33f2007-10-27 13:37:43 -04003207 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003208 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3209 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003210 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003211 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003212 */
3213 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3214 ls_rjt = 1;
3215 }
3216
dea31012005-04-17 16:05:31 -05003217 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003218 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003219 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003220 mp = (struct lpfc_dmabuf *) mbox->context1;
3221 if (mp) {
3222 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3223 kfree(mp);
3224 }
James Smart329f9bc2007-04-25 09:53:01 -04003225 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003226 }
James Smart58da1ff2008-04-07 10:15:56 -04003227 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3228 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003229 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003230 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003231 /* Indicate the node has already released,
3232 * should not reference to it from within
3233 * the routine lpfc_els_free_iocb.
3234 */
3235 cmdiocb->context1 = NULL;
3236 }
dea31012005-04-17 16:05:31 -05003237 goto out;
3238 }
3239
James Smart858c9f62007-06-17 19:56:39 -05003240 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003241 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003242 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003243 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003244 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003245 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3246 "0110 ELS response tag x%x completes "
3247 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3248 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3249 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3250 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3251 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003252 if (mbox) {
3253 if ((rspiocb->iocb.ulpStatus == 0)
3254 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003255 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003256 /* Increment reference count to ndlp to hold the
3257 * reference to ndlp for the callback function.
3258 */
James Smart329f9bc2007-04-25 09:53:01 -04003259 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003260 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003261 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3262 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3263 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3264 }
3265 else {
3266 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3267 ndlp->nlp_prev_state = ndlp->nlp_state;
3268 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003269 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003270 }
James Smart0b727fe2007-10-27 13:37:25 -04003271 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003272 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003273 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003274 else
3275 /* Decrement the ndlp reference count we
3276 * set for this failed mailbox command.
3277 */
3278 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003279
3280 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3281 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3282 "0138 ELS rsp: Cannot issue reg_login for x%x "
3283 "Data: x%x x%x x%x\n",
3284 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3285 ndlp->nlp_rpi);
3286
James Smartfa4066b2008-01-11 01:53:27 -05003287 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003288 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003289 /* Indicate node has already been released,
3290 * should not reference to it from within
3291 * the routine lpfc_els_free_iocb.
3292 */
3293 cmdiocb->context1 = NULL;
3294 }
dea31012005-04-17 16:05:31 -05003295 } else {
James Smart858c9f62007-06-17 19:56:39 -05003296 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3297 if (!lpfc_error_lost_link(irsp) &&
3298 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003299 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003300 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003301 /* Indicate node has already been
3302 * released, should not reference
3303 * to it from within the routine
3304 * lpfc_els_free_iocb.
3305 */
3306 cmdiocb->context1 = NULL;
3307 }
dea31012005-04-17 16:05:31 -05003308 }
3309 }
James Smart14691152006-12-02 13:34:28 -05003310 mp = (struct lpfc_dmabuf *) mbox->context1;
3311 if (mp) {
3312 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3313 kfree(mp);
3314 }
3315 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003316 }
3317out:
James Smart58da1ff2008-04-07 10:15:56 -04003318 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003319 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003320 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003321 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003322
3323 /* If the node is not being used by another discovery thread,
3324 * and we are sending a reject, we are done with it.
3325 * Release driver reference count here and free associated
3326 * resources.
3327 */
3328 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003329 if (lpfc_nlp_not_used(ndlp))
3330 /* Indicate node has already been released,
3331 * should not reference to it from within
3332 * the routine lpfc_els_free_iocb.
3333 */
3334 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003335 }
James Smart87af33f2007-10-27 13:37:43 -04003336
dea31012005-04-17 16:05:31 -05003337 lpfc_els_free_iocb(phba, cmdiocb);
3338 return;
3339}
3340
James Smarte59058c2008-08-24 21:49:00 -04003341/**
James Smart3621a712009-04-06 18:47:14 -04003342 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003343 * @vport: pointer to a host virtual N_Port data structure.
3344 * @flag: the els command code to be accepted.
3345 * @oldiocb: pointer to the original lpfc command iocb data structure.
3346 * @ndlp: pointer to a node-list data structure.
3347 * @mbox: pointer to the driver internal queue element for mailbox command.
3348 *
3349 * This routine prepares and issues an Accept (ACC) response IOCB
3350 * command. It uses the @flag to properly set up the IOCB field for the
3351 * specific ACC response command to be issued and invokes the
3352 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3353 * @mbox pointer is passed in, it will be put into the context_un.mbox
3354 * field of the IOCB for the completion callback function to issue the
3355 * mailbox command to the HBA later when callback is invoked.
3356 *
3357 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3358 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3359 * will be stored into the context1 field of the IOCB for the completion
3360 * callback function to the corresponding response ELS IOCB command.
3361 *
3362 * Return code
3363 * 0 - Successfully issued acc response
3364 * 1 - Failed to issue acc response
3365 **/
dea31012005-04-17 16:05:31 -05003366int
James Smart2e0fef82007-06-17 19:56:36 -05003367lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3368 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003369 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003370{
James Smart2e0fef82007-06-17 19:56:36 -05003371 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3372 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003373 IOCB_t *icmd;
3374 IOCB_t *oldcmd;
3375 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003376 struct lpfc_sli *psli;
3377 uint8_t *pcmd;
3378 uint16_t cmdsize;
3379 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003380 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003381
3382 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003383 oldcmd = &oldiocb->iocb;
3384
3385 switch (flag) {
3386 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003387 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003388 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3389 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003390 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003391 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003392 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003393 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003394 return 1;
dea31012005-04-17 16:05:31 -05003395 }
James Smart2e0fef82007-06-17 19:56:36 -05003396
dea31012005-04-17 16:05:31 -05003397 icmd = &elsiocb->iocb;
3398 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3399 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3400 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003401 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003402
3403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3404 "Issue ACC: did:x%x flg:x%x",
3405 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003406 break;
3407 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003408 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003409 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3410 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003411 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003412 return 1;
James Smart488d1462006-03-07 15:02:37 -05003413
dea31012005-04-17 16:05:31 -05003414 icmd = &elsiocb->iocb;
3415 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3416 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3417
3418 if (mbox)
3419 elsiocb->context_un.mbox = mbox;
3420
3421 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003422 pcmd += sizeof(uint32_t);
3423 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003424
3425 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3426 "Issue ACC PLOGI: did:x%x flg:x%x",
3427 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003428 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003429 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003430 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003431 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003432 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3433 if (!elsiocb)
3434 return 1;
3435
3436 icmd = &elsiocb->iocb;
3437 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3438 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3439
3440 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003441 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003442 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3443 els_pkt_ptr = (ELS_PKT *) pcmd;
3444 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003445
3446 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3447 "Issue ACC PRLO: did:x%x flg:x%x",
3448 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003449 break;
dea31012005-04-17 16:05:31 -05003450 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003451 return 1;
dea31012005-04-17 16:05:31 -05003452 }
dea31012005-04-17 16:05:31 -05003453 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003454 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3455 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3456 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3457 elsiocb->iotag, elsiocb->iocb.ulpContext,
3458 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3459 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003460 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003461 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003462 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003463 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003464 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3465 } else {
James Smart858c9f62007-06-17 19:56:39 -05003466 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003467 }
3468
3469 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003470 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003471 if (rc == IOCB_ERROR) {
3472 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003473 return 1;
dea31012005-04-17 16:05:31 -05003474 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003475 return 0;
dea31012005-04-17 16:05:31 -05003476}
3477
James Smarte59058c2008-08-24 21:49:00 -04003478/**
James Smart3621a712009-04-06 18:47:14 -04003479 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003480 * @vport: pointer to a virtual N_Port data structure.
3481 * @rejectError:
3482 * @oldiocb: pointer to the original lpfc command iocb data structure.
3483 * @ndlp: pointer to a node-list data structure.
3484 * @mbox: pointer to the driver internal queue element for mailbox command.
3485 *
3486 * This routine prepares and issue an Reject (RJT) response IOCB
3487 * command. If a @mbox pointer is passed in, it will be put into the
3488 * context_un.mbox field of the IOCB for the completion callback function
3489 * to issue to the HBA later.
3490 *
3491 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3492 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3493 * will be stored into the context1 field of the IOCB for the completion
3494 * callback function to the reject response ELS IOCB command.
3495 *
3496 * Return code
3497 * 0 - Successfully issued reject response
3498 * 1 - Failed to issue reject response
3499 **/
dea31012005-04-17 16:05:31 -05003500int
James Smart2e0fef82007-06-17 19:56:36 -05003501lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003502 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3503 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003504{
James Smart2e0fef82007-06-17 19:56:36 -05003505 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003506 IOCB_t *icmd;
3507 IOCB_t *oldcmd;
3508 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003509 struct lpfc_sli *psli;
3510 uint8_t *pcmd;
3511 uint16_t cmdsize;
3512 int rc;
3513
3514 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003515 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003516 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3517 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003518 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003519 return 1;
dea31012005-04-17 16:05:31 -05003520
3521 icmd = &elsiocb->iocb;
3522 oldcmd = &oldiocb->iocb;
3523 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3524 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3525
3526 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003527 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003528 *((uint32_t *) (pcmd)) = rejectError;
3529
James Smart51ef4c22007-08-02 11:10:31 -04003530 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003531 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003532
dea31012005-04-17 16:05:31 -05003533 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003534 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3535 "0129 Xmit ELS RJT x%x response tag x%x "
3536 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3537 "rpi x%x\n",
3538 rejectError, elsiocb->iotag,
3539 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3540 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003541 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3542 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3543 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3544
dea31012005-04-17 16:05:31 -05003545 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003546 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003547 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003548
dea31012005-04-17 16:05:31 -05003549 if (rc == IOCB_ERROR) {
3550 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003551 return 1;
dea31012005-04-17 16:05:31 -05003552 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003553 return 0;
dea31012005-04-17 16:05:31 -05003554}
3555
James Smarte59058c2008-08-24 21:49:00 -04003556/**
James Smart3621a712009-04-06 18:47:14 -04003557 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003558 * @vport: pointer to a virtual N_Port data structure.
3559 * @oldiocb: pointer to the original lpfc command iocb data structure.
3560 * @ndlp: pointer to a node-list data structure.
3561 *
3562 * This routine prepares and issues an Accept (ACC) response to Address
3563 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3564 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3565 *
3566 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3567 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3568 * will be stored into the context1 field of the IOCB for the completion
3569 * callback function to the ADISC Accept response ELS IOCB command.
3570 *
3571 * Return code
3572 * 0 - Successfully issued acc adisc response
3573 * 1 - Failed to issue adisc acc response
3574 **/
dea31012005-04-17 16:05:31 -05003575int
James Smart2e0fef82007-06-17 19:56:36 -05003576lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3577 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003578{
James Smart2e0fef82007-06-17 19:56:36 -05003579 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003580 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003581 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003582 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003583 uint8_t *pcmd;
3584 uint16_t cmdsize;
3585 int rc;
3586
James Smart92d7f7b2007-06-17 19:56:38 -05003587 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003588 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3589 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003590 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003591 return 1;
dea31012005-04-17 16:05:31 -05003592
dea31012005-04-17 16:05:31 -05003593 icmd = &elsiocb->iocb;
3594 oldcmd = &oldiocb->iocb;
3595 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003596
3597 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003598 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3599 "0130 Xmit ADISC ACC response iotag x%x xri: "
3600 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3601 elsiocb->iotag, elsiocb->iocb.ulpContext,
3602 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3603 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003604 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3605
3606 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003607 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003608
3609 ap = (ADISC *) (pcmd);
3610 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003611 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3612 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003613 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003614
James Smart858c9f62007-06-17 19:56:39 -05003615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3616 "Issue ACC ADISC: did:x%x flg:x%x",
3617 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3618
dea31012005-04-17 16:05:31 -05003619 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003620 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003621 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003622 if (rc == IOCB_ERROR) {
3623 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003624 return 1;
dea31012005-04-17 16:05:31 -05003625 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003626 return 0;
dea31012005-04-17 16:05:31 -05003627}
3628
James Smarte59058c2008-08-24 21:49:00 -04003629/**
James Smart3621a712009-04-06 18:47:14 -04003630 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003631 * @vport: pointer to a virtual N_Port data structure.
3632 * @oldiocb: pointer to the original lpfc command iocb data structure.
3633 * @ndlp: pointer to a node-list data structure.
3634 *
3635 * This routine prepares and issues an Accept (ACC) response to Process
3636 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3637 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3638 *
3639 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3640 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3641 * will be stored into the context1 field of the IOCB for the completion
3642 * callback function to the PRLI Accept response ELS IOCB command.
3643 *
3644 * Return code
3645 * 0 - Successfully issued acc prli response
3646 * 1 - Failed to issue acc prli response
3647 **/
dea31012005-04-17 16:05:31 -05003648int
James Smart2e0fef82007-06-17 19:56:36 -05003649lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003650 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003651{
James Smart2e0fef82007-06-17 19:56:36 -05003652 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003653 PRLI *npr;
3654 lpfc_vpd_t *vpd;
3655 IOCB_t *icmd;
3656 IOCB_t *oldcmd;
3657 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003658 struct lpfc_sli *psli;
3659 uint8_t *pcmd;
3660 uint16_t cmdsize;
3661 int rc;
3662
3663 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003664
James Smart92d7f7b2007-06-17 19:56:38 -05003665 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003666 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003667 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003668 if (!elsiocb)
3669 return 1;
dea31012005-04-17 16:05:31 -05003670
dea31012005-04-17 16:05:31 -05003671 icmd = &elsiocb->iocb;
3672 oldcmd = &oldiocb->iocb;
3673 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003674 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003675 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3676 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3677 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3678 elsiocb->iotag, elsiocb->iocb.ulpContext,
3679 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3680 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003681 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3682
3683 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003684 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003685
3686 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003687 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003688
3689 npr = (PRLI *) pcmd;
3690 vpd = &phba->vpd;
3691 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003692 * If the remote port is a target and our firmware version is 3.20 or
3693 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003694 */
James Smart0d2b6b82008-06-14 22:52:47 -04003695 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3696 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003697 npr->ConfmComplAllowed = 1;
3698 npr->Retry = 1;
3699 npr->TaskRetryIdReq = 1;
3700 }
3701
3702 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3703 npr->estabImagePair = 1;
3704 npr->readXferRdyDis = 1;
3705 npr->ConfmComplAllowed = 1;
3706
3707 npr->prliType = PRLI_FCP_TYPE;
3708 npr->initiatorFunc = 1;
3709
James Smart858c9f62007-06-17 19:56:39 -05003710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3711 "Issue ACC PRLI: did:x%x flg:x%x",
3712 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3713
dea31012005-04-17 16:05:31 -05003714 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003715 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003716
James Smart3772a992009-05-22 14:50:54 -04003717 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003718 if (rc == IOCB_ERROR) {
3719 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003720 return 1;
dea31012005-04-17 16:05:31 -05003721 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003722 return 0;
dea31012005-04-17 16:05:31 -05003723}
3724
James Smarte59058c2008-08-24 21:49:00 -04003725/**
James Smart3621a712009-04-06 18:47:14 -04003726 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003727 * @vport: pointer to a virtual N_Port data structure.
3728 * @format: rnid command format.
3729 * @oldiocb: pointer to the original lpfc command iocb data structure.
3730 * @ndlp: pointer to a node-list data structure.
3731 *
3732 * This routine issues a Request Node Identification Data (RNID) Accept
3733 * (ACC) response. It constructs the RNID ACC response command according to
3734 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3735 * issue the response. Note that this command does not need to hold the ndlp
3736 * reference count for the callback. So, the ndlp reference count taken by
3737 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3738 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3739 * there is no ndlp reference available.
3740 *
3741 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3742 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3743 * will be stored into the context1 field of the IOCB for the completion
3744 * callback function. However, for the RNID Accept Response ELS command,
3745 * this is undone later by this routine after the IOCB is allocated.
3746 *
3747 * Return code
3748 * 0 - Successfully issued acc rnid response
3749 * 1 - Failed to issue acc rnid response
3750 **/
dea31012005-04-17 16:05:31 -05003751static int
James Smart2e0fef82007-06-17 19:56:36 -05003752lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003753 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003754{
James Smart2e0fef82007-06-17 19:56:36 -05003755 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003756 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003757 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003758 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003759 struct lpfc_sli *psli;
3760 uint8_t *pcmd;
3761 uint16_t cmdsize;
3762 int rc;
3763
3764 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003765 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3766 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003767 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003768 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003769
James Smart2e0fef82007-06-17 19:56:36 -05003770 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3771 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003772 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003773 return 1;
dea31012005-04-17 16:05:31 -05003774
dea31012005-04-17 16:05:31 -05003775 icmd = &elsiocb->iocb;
3776 oldcmd = &oldiocb->iocb;
3777 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003778 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003779 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3780 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3781 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003782 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003783 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003784 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003785
James Smart92d7f7b2007-06-17 19:56:38 -05003786 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003787 rn = (RNID *) (pcmd);
3788 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003789 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3790 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3791 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003792 switch (format) {
3793 case 0:
3794 rn->SpecificLen = 0;
3795 break;
3796 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003797 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003798 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003799 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003800 rn->un.topologyDisc.unitType = RNID_HBA;
3801 rn->un.topologyDisc.physPort = 0;
3802 rn->un.topologyDisc.attachedNodes = 0;
3803 break;
3804 default:
3805 rn->CommonLen = 0;
3806 rn->SpecificLen = 0;
3807 break;
3808 }
3809
James Smart858c9f62007-06-17 19:56:39 -05003810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3811 "Issue ACC RNID: did:x%x flg:x%x",
3812 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3813
dea31012005-04-17 16:05:31 -05003814 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003815 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003816 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003817 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3818 * it could be freed */
3819
James Smart3772a992009-05-22 14:50:54 -04003820 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003821 if (rc == IOCB_ERROR) {
3822 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003823 return 1;
dea31012005-04-17 16:05:31 -05003824 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003825 return 0;
dea31012005-04-17 16:05:31 -05003826}
3827
James Smarte59058c2008-08-24 21:49:00 -04003828/**
James Smart3621a712009-04-06 18:47:14 -04003829 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003830 * @vport: pointer to a host virtual N_Port data structure.
3831 *
3832 * This routine issues Address Discover (ADISC) ELS commands to those
3833 * N_Ports which are in node port recovery state and ADISC has not been issued
3834 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3835 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3836 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3837 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3838 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3839 * IOCBs quit for later pick up. On the other hand, after walking through
3840 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3841 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3842 * no more ADISC need to be sent.
3843 *
3844 * Return code
3845 * The number of N_Ports with adisc issued.
3846 **/
dea31012005-04-17 16:05:31 -05003847int
James Smart2e0fef82007-06-17 19:56:36 -05003848lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003849{
James Smart2e0fef82007-06-17 19:56:36 -05003850 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003851 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003852 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003853
James Smart685f0bf2007-04-25 09:53:08 -04003854 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003855 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003856 if (!NLP_CHK_NODE_ACT(ndlp))
3857 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003858 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3859 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3860 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003861 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003862 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003863 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003864 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003865 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3866 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003867 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003868 vport->num_disc_nodes++;
3869 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003870 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003871 spin_lock_irq(shost->host_lock);
3872 vport->fc_flag |= FC_NLP_MORE;
3873 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003874 break;
dea31012005-04-17 16:05:31 -05003875 }
3876 }
3877 }
3878 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003879 spin_lock_irq(shost->host_lock);
3880 vport->fc_flag &= ~FC_NLP_MORE;
3881 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003882 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003883 return sentadisc;
dea31012005-04-17 16:05:31 -05003884}
3885
James Smarte59058c2008-08-24 21:49:00 -04003886/**
James Smart3621a712009-04-06 18:47:14 -04003887 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003888 * @vport: pointer to a host virtual N_Port data structure.
3889 *
3890 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3891 * which are in node port recovery state, with a @vport. Each time an ELS
3892 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3893 * the per @vport number of discover count (num_disc_nodes) shall be
3894 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3895 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3896 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3897 * later pick up. On the other hand, after walking through all the ndlps with
3898 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3899 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3900 * PLOGI need to be sent.
3901 *
3902 * Return code
3903 * The number of N_Ports with plogi issued.
3904 **/
dea31012005-04-17 16:05:31 -05003905int
James Smart2e0fef82007-06-17 19:56:36 -05003906lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003907{
James Smart2e0fef82007-06-17 19:56:36 -05003908 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003909 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003910 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003911
James Smart2e0fef82007-06-17 19:56:36 -05003912 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3913 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003914 if (!NLP_CHK_NODE_ACT(ndlp))
3915 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003916 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3917 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3918 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3919 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3920 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003921 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3922 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003923 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003924 vport->num_disc_nodes++;
3925 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003926 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003927 spin_lock_irq(shost->host_lock);
3928 vport->fc_flag |= FC_NLP_MORE;
3929 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003930 break;
dea31012005-04-17 16:05:31 -05003931 }
3932 }
3933 }
James Smart87af33f2007-10-27 13:37:43 -04003934 if (sentplogi) {
3935 lpfc_set_disctmo(vport);
3936 }
3937 else {
James Smart2e0fef82007-06-17 19:56:36 -05003938 spin_lock_irq(shost->host_lock);
3939 vport->fc_flag &= ~FC_NLP_MORE;
3940 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003941 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003942 return sentplogi;
dea31012005-04-17 16:05:31 -05003943}
3944
James Smarte59058c2008-08-24 21:49:00 -04003945/**
James Smart3621a712009-04-06 18:47:14 -04003946 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003947 * @vport: pointer to a host virtual N_Port data structure.
3948 *
3949 * This routine cleans up any Registration State Change Notification
3950 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3951 * @vport together with the host_lock is used to prevent multiple thread
3952 * trying to access the RSCN array on a same @vport at the same time.
3953 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003954void
James Smart2e0fef82007-06-17 19:56:36 -05003955lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003956{
James Smart2e0fef82007-06-17 19:56:36 -05003957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3958 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003959 int i;
3960
James Smart7f5f3d02008-02-08 18:50:14 -05003961 spin_lock_irq(shost->host_lock);
3962 if (vport->fc_rscn_flush) {
3963 /* Another thread is walking fc_rscn_id_list on this vport */
3964 spin_unlock_irq(shost->host_lock);
3965 return;
3966 }
3967 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3968 vport->fc_rscn_flush = 1;
3969 spin_unlock_irq(shost->host_lock);
3970
James Smart2e0fef82007-06-17 19:56:36 -05003971 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003972 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003973 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003974 }
James Smart2e0fef82007-06-17 19:56:36 -05003975 spin_lock_irq(shost->host_lock);
3976 vport->fc_rscn_id_cnt = 0;
3977 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3978 spin_unlock_irq(shost->host_lock);
3979 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003980 /* Indicate we are done walking this fc_rscn_id_list */
3981 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003982}
3983
James Smarte59058c2008-08-24 21:49:00 -04003984/**
James Smart3621a712009-04-06 18:47:14 -04003985 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003986 * @vport: pointer to a host virtual N_Port data structure.
3987 * @did: remote destination port identifier.
3988 *
3989 * This routine checks whether there is any pending Registration State
3990 * Configuration Notification (RSCN) to a @did on @vport.
3991 *
3992 * Return code
3993 * None zero - The @did matched with a pending rscn
3994 * 0 - not able to match @did with a pending rscn
3995 **/
dea31012005-04-17 16:05:31 -05003996int
James Smart2e0fef82007-06-17 19:56:36 -05003997lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003998{
3999 D_ID ns_did;
4000 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004001 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004002 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004003 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004004
4005 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004006
4007 /* Never match fabric nodes for RSCNs */
4008 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004009 return 0;
dea31012005-04-17 16:05:31 -05004010
4011 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004012 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004013 return did;
dea31012005-04-17 16:05:31 -05004014
James Smart7f5f3d02008-02-08 18:50:14 -05004015 spin_lock_irq(shost->host_lock);
4016 if (vport->fc_rscn_flush) {
4017 /* Another thread is walking fc_rscn_id_list on this vport */
4018 spin_unlock_irq(shost->host_lock);
4019 return 0;
4020 }
4021 /* Indicate we are walking fc_rscn_id_list on this vport */
4022 vport->fc_rscn_flush = 1;
4023 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004024 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004025 lp = vport->fc_rscn_id_list[i]->virt;
4026 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4027 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004028 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004029 rscn_did.un.word = be32_to_cpu(*lp++);
4030 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004031 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4032 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004033 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4034 && (ns_did.un.b.area == rscn_did.un.b.area)
4035 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004036 goto return_did_out;
dea31012005-04-17 16:05:31 -05004037 break;
James Smarteaf15d52008-12-04 22:39:29 -05004038 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004039 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4040 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004041 goto return_did_out;
dea31012005-04-17 16:05:31 -05004042 break;
James Smarteaf15d52008-12-04 22:39:29 -05004043 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004044 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004045 goto return_did_out;
dea31012005-04-17 16:05:31 -05004046 break;
James Smarteaf15d52008-12-04 22:39:29 -05004047 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004048 goto return_did_out;
dea31012005-04-17 16:05:31 -05004049 }
4050 }
James Smart92d7f7b2007-06-17 19:56:38 -05004051 }
James Smart7f5f3d02008-02-08 18:50:14 -05004052 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4053 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004054 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004055return_did_out:
4056 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4057 vport->fc_rscn_flush = 0;
4058 return did;
dea31012005-04-17 16:05:31 -05004059}
4060
James Smarte59058c2008-08-24 21:49:00 -04004061/**
James Smart3621a712009-04-06 18:47:14 -04004062 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004063 * @vport: pointer to a host virtual N_Port data structure.
4064 *
4065 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4066 * state machine for a @vport's nodes that are with pending RSCN (Registration
4067 * State Change Notification).
4068 *
4069 * Return code
4070 * 0 - Successful (currently alway return 0)
4071 **/
dea31012005-04-17 16:05:31 -05004072static int
James Smart2e0fef82007-06-17 19:56:36 -05004073lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004074{
James Smart685f0bf2007-04-25 09:53:08 -04004075 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004076
James Smart0d2b6b82008-06-14 22:52:47 -04004077 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004078 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004079 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004080 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4081 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004082 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004083 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004084 NLP_EVT_DEVICE_RECOVERY);
4085 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004086 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004087 return 0;
dea31012005-04-17 16:05:31 -05004088}
4089
James Smarte59058c2008-08-24 21:49:00 -04004090/**
James Smart3621a712009-04-06 18:47:14 -04004091 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004092 * @vport: pointer to a host virtual N_Port data structure.
4093 * @cmdiocb: pointer to lpfc command iocb data structure.
4094 *
4095 * lpfc_send_rscn_event sends an RSCN netlink event to management
4096 * applications.
4097 */
4098static void
4099lpfc_send_rscn_event(struct lpfc_vport *vport,
4100 struct lpfc_iocbq *cmdiocb)
4101{
4102 struct lpfc_dmabuf *pcmd;
4103 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4104 uint32_t *payload_ptr;
4105 uint32_t payload_len;
4106 struct lpfc_rscn_event_header *rscn_event_data;
4107
4108 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4109 payload_ptr = (uint32_t *) pcmd->virt;
4110 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4111
4112 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4113 payload_len, GFP_KERNEL);
4114 if (!rscn_event_data) {
4115 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4116 "0147 Failed to allocate memory for RSCN event\n");
4117 return;
4118 }
4119 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4120 rscn_event_data->payload_length = payload_len;
4121 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4122 payload_len);
4123
4124 fc_host_post_vendor_event(shost,
4125 fc_get_event_number(),
4126 sizeof(struct lpfc_els_event_header) + payload_len,
4127 (char *)rscn_event_data,
4128 LPFC_NL_VENDOR_ID);
4129
4130 kfree(rscn_event_data);
4131}
4132
4133/**
James Smart3621a712009-04-06 18:47:14 -04004134 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004135 * @vport: pointer to a host virtual N_Port data structure.
4136 * @cmdiocb: pointer to lpfc command iocb data structure.
4137 * @ndlp: pointer to a node-list data structure.
4138 *
4139 * This routine processes an unsolicited RSCN (Registration State Change
4140 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4141 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4142 * discover state machine is about to begin discovery, it just accepts the
4143 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4144 * contains N_Port IDs for other vports on this HBA, it just accepts the
4145 * RSCN and ignore processing it. If the state machine is in the recovery
4146 * state, the fc_rscn_id_list of this @vport is walked and the
4147 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4148 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4149 * routine is invoked to handle the RSCN event.
4150 *
4151 * Return code
4152 * 0 - Just sent the acc response
4153 * 1 - Sent the acc response and waited for name server completion
4154 **/
dea31012005-04-17 16:05:31 -05004155static int
James Smart2e0fef82007-06-17 19:56:36 -05004156lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004157 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004158{
James Smart2e0fef82007-06-17 19:56:36 -05004159 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4160 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004161 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004162 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004163 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004164 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004165 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004166 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004167 int i;
dea31012005-04-17 16:05:31 -05004168
4169 icmd = &cmdiocb->iocb;
4170 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4171 lp = (uint32_t *) pcmd->virt;
4172
James Smart92d7f7b2007-06-17 19:56:38 -05004173 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4174 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004175 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004176 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4177 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004178 vport->fc_flag, payload_len, *lp,
4179 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004180
4181 /* Send an RSCN event to the management application */
4182 lpfc_send_rscn_event(vport, cmdiocb);
4183
James Smartd2873e42006-08-18 17:46:43 -04004184 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004185 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004186 FCH_EVT_RSCN, lp[i]);
4187
dea31012005-04-17 16:05:31 -05004188 /* If we are about to begin discovery, just ACC the RSCN.
4189 * Discovery processing will satisfy it.
4190 */
James Smart2e0fef82007-06-17 19:56:36 -05004191 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004192 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4193 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4194 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4195
James Smart51ef4c22007-08-02 11:10:31 -04004196 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004197 return 0;
dea31012005-04-17 16:05:31 -05004198 }
4199
James Smart92d7f7b2007-06-17 19:56:38 -05004200 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4201 * just ACC and ignore it.
4202 */
4203 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004204 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004205 i = payload_len;
4206 datap = lp;
4207 while (i > 0) {
4208 nportid = *datap++;
4209 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4210 i -= sizeof(uint32_t);
4211 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004212 if (lpfc_find_vport_by_did(phba, nportid))
4213 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004214 }
4215 if (rscn_id == hba_id) {
4216 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004217 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004218 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004219 "Data: x%x x%x x%x x%x\n",
4220 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004221 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004222 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4223 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4224 ndlp->nlp_DID, vport->port_state,
4225 ndlp->nlp_flag);
4226
James Smart92d7f7b2007-06-17 19:56:38 -05004227 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004228 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004229 return 0;
4230 }
4231 }
4232
James Smart7f5f3d02008-02-08 18:50:14 -05004233 spin_lock_irq(shost->host_lock);
4234 if (vport->fc_rscn_flush) {
4235 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004236 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004237 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004238 /* Send back ACC */
4239 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004240 return 0;
4241 }
4242 /* Indicate we are walking fc_rscn_id_list on this vport */
4243 vport->fc_rscn_flush = 1;
4244 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004245 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004246 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004247 /* If we are already processing an RSCN, save the received
4248 * RSCN payload buffer, cmdiocb->context2 to process later.
4249 */
James Smart2e0fef82007-06-17 19:56:36 -05004250 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004251 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4252 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4253 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4254
James Smart09372822008-01-11 01:52:54 -05004255 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004256 vport->fc_flag |= FC_RSCN_DEFERRED;
4257 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004258 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004259 vport->fc_flag |= FC_RSCN_MODE;
4260 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004261 if (rscn_cnt) {
4262 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4263 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4264 }
4265 if ((rscn_cnt) &&
4266 (payload_len + length <= LPFC_BPL_SIZE)) {
4267 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004268 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004269 memcpy(((uint8_t *)cmd) + length, lp,
4270 payload_len);
4271 } else {
4272 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4273 vport->fc_rscn_id_cnt++;
4274 /* If we zero, cmdiocb->context2, the calling
4275 * routine will not try to free it.
4276 */
4277 cmdiocb->context2 = NULL;
4278 }
dea31012005-04-17 16:05:31 -05004279 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004280 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4281 "0235 Deferred RSCN "
4282 "Data: x%x x%x x%x\n",
4283 vport->fc_rscn_id_cnt, vport->fc_flag,
4284 vport->port_state);
dea31012005-04-17 16:05:31 -05004285 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004286 vport->fc_flag |= FC_RSCN_DISCOVERY;
4287 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004288 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004289 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4290 "0234 ReDiscovery RSCN "
4291 "Data: x%x x%x x%x\n",
4292 vport->fc_rscn_id_cnt, vport->fc_flag,
4293 vport->port_state);
dea31012005-04-17 16:05:31 -05004294 }
James Smart7f5f3d02008-02-08 18:50:14 -05004295 /* Indicate we are done walking fc_rscn_id_list on this vport */
4296 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004297 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004298 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004299 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004300 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004301 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004302 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004303 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004304 return 0;
dea31012005-04-17 16:05:31 -05004305 }
James Smart858c9f62007-06-17 19:56:39 -05004306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4307 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4308 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4309
James Smart2e0fef82007-06-17 19:56:36 -05004310 spin_lock_irq(shost->host_lock);
4311 vport->fc_flag |= FC_RSCN_MODE;
4312 spin_unlock_irq(shost->host_lock);
4313 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004314 /* Indicate we are done walking fc_rscn_id_list on this vport */
4315 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004316 /*
4317 * If we zero, cmdiocb->context2, the calling routine will
4318 * not try to free it.
4319 */
4320 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004321 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004322 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004323 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004324 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004325 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004326 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004327}
4328
James Smarte59058c2008-08-24 21:49:00 -04004329/**
James Smart3621a712009-04-06 18:47:14 -04004330 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004331 * @vport: pointer to a host virtual N_Port data structure.
4332 *
4333 * This routine handles the Registration State Configuration Notification
4334 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4335 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4336 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4337 * NameServer shall be issued. If CT command to the NameServer fails to be
4338 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4339 * RSCN activities with the @vport.
4340 *
4341 * Return code
4342 * 0 - Cleaned up rscn on the @vport
4343 * 1 - Wait for plogi to name server before proceed
4344 **/
dea31012005-04-17 16:05:31 -05004345int
James Smart2e0fef82007-06-17 19:56:36 -05004346lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004347{
4348 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004349 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004350
James Smart92d7f7b2007-06-17 19:56:38 -05004351 /* Ignore RSCN if the port is being torn down. */
4352 if (vport->load_flag & FC_UNLOADING) {
4353 lpfc_els_flush_rscn(vport);
4354 return 0;
4355 }
4356
dea31012005-04-17 16:05:31 -05004357 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004358 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004359
4360 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004361 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4362 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4363 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4364 vport->port_state);
dea31012005-04-17 16:05:31 -05004365
4366 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004367 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004368 vport->num_disc_nodes = 0;
4369
James Smart2e0fef82007-06-17 19:56:36 -05004370 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004371 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4372 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004373 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004374 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004375 /* Wait for NameServer query cmpl before we can
4376 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004377 return 1;
dea31012005-04-17 16:05:31 -05004378 } else {
4379 /* If login to NameServer does not exist, issue one */
4380 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004381 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004382 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004383 /* Wait for NameServer login cmpl before we can
4384 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004385 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004386
James Smarte47c9092008-02-08 18:49:26 -05004387 if (ndlp) {
4388 ndlp = lpfc_enable_node(vport, ndlp,
4389 NLP_STE_PLOGI_ISSUE);
4390 if (!ndlp) {
4391 lpfc_els_flush_rscn(vport);
4392 return 0;
4393 }
4394 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004395 } else {
James Smarte47c9092008-02-08 18:49:26 -05004396 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4397 if (!ndlp) {
4398 lpfc_els_flush_rscn(vport);
4399 return 0;
4400 }
James Smart2e0fef82007-06-17 19:56:36 -05004401 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004402 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004403 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004404 }
James Smarte47c9092008-02-08 18:49:26 -05004405 ndlp->nlp_type |= NLP_FABRIC;
4406 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4407 /* Wait for NameServer login cmpl before we can
4408 * continue
4409 */
4410 return 1;
dea31012005-04-17 16:05:31 -05004411 }
4412
James Smart2e0fef82007-06-17 19:56:36 -05004413 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004414 return 0;
dea31012005-04-17 16:05:31 -05004415}
4416
James Smarte59058c2008-08-24 21:49:00 -04004417/**
James Smart3621a712009-04-06 18:47:14 -04004418 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004419 * @vport: pointer to a host virtual N_Port data structure.
4420 * @cmdiocb: pointer to lpfc command iocb data structure.
4421 * @ndlp: pointer to a node-list data structure.
4422 *
4423 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4424 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4425 * point topology. As an unsolicited FLOGI should not be received in a loop
4426 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4427 * lpfc_check_sparm() routine is invoked to check the parameters in the
4428 * unsolicited FLOGI. If parameters validation failed, the routine
4429 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4430 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4431 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4432 * will initiate PLOGI. The higher lexicographical value party shall has
4433 * higher priority (as the winning port) and will initiate PLOGI and
4434 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4435 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4436 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4437 *
4438 * Return code
4439 * 0 - Successfully processed the unsolicited flogi
4440 * 1 - Failed to process the unsolicited flogi
4441 **/
dea31012005-04-17 16:05:31 -05004442static int
James Smart2e0fef82007-06-17 19:56:36 -05004443lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004444 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004445{
James Smart2e0fef82007-06-17 19:56:36 -05004446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4447 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004448 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4449 uint32_t *lp = (uint32_t *) pcmd->virt;
4450 IOCB_t *icmd = &cmdiocb->iocb;
4451 struct serv_parm *sp;
4452 LPFC_MBOXQ_t *mbox;
4453 struct ls_rjt stat;
4454 uint32_t cmd, did;
4455 int rc;
4456
4457 cmd = *lp++;
4458 sp = (struct serv_parm *) lp;
4459
4460 /* FLOGI received */
4461
James Smart2e0fef82007-06-17 19:56:36 -05004462 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004463
4464 if (phba->fc_topology == TOPOLOGY_LOOP) {
4465 /* We should never receive a FLOGI in loop mode, ignore it */
4466 did = icmd->un.elsreq64.remoteID;
4467
4468 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4469 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004470 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4471 "0113 An FLOGI ELS command x%x was "
4472 "received from DID x%x in Loop Mode\n",
4473 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004474 return 1;
dea31012005-04-17 16:05:31 -05004475 }
4476
4477 did = Fabric_DID;
4478
James Smart341af102010-01-26 23:07:37 -05004479 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004480 /* For a FLOGI we accept, then if our portname is greater
4481 * then the remote portname we initiate Nport login.
4482 */
4483
James Smart2e0fef82007-06-17 19:56:36 -05004484 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004485 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004486
4487 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004488 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4489 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004490 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004491
dea31012005-04-17 16:05:31 -05004492 lpfc_linkdown(phba);
4493 lpfc_init_link(phba, mbox,
4494 phba->cfg_topology,
4495 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004496 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004497 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004498 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004499 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004500 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004501 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004502 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004503 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004504 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004505 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004506 spin_lock_irq(shost->host_lock);
4507 vport->fc_flag |= FC_PT2PT_PLOGI;
4508 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004509 }
James Smart2e0fef82007-06-17 19:56:36 -05004510 spin_lock_irq(shost->host_lock);
4511 vport->fc_flag |= FC_PT2PT;
4512 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4513 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004514 } else {
4515 /* Reject this request because invalid parameters */
4516 stat.un.b.lsRjtRsvd0 = 0;
4517 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4518 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4519 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004520 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4521 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004522 return 1;
dea31012005-04-17 16:05:31 -05004523 }
4524
4525 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004526 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004527
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004528 return 0;
dea31012005-04-17 16:05:31 -05004529}
4530
James Smarte59058c2008-08-24 21:49:00 -04004531/**
James Smart3621a712009-04-06 18:47:14 -04004532 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004533 * @vport: pointer to a host virtual N_Port data structure.
4534 * @cmdiocb: pointer to lpfc command iocb data structure.
4535 * @ndlp: pointer to a node-list data structure.
4536 *
4537 * This routine processes Request Node Identification Data (RNID) IOCB
4538 * received as an ELS unsolicited event. Only when the RNID specified format
4539 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4540 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4541 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4542 * rejected by invoking the lpfc_els_rsp_reject() routine.
4543 *
4544 * Return code
4545 * 0 - Successfully processed rnid iocb (currently always return 0)
4546 **/
dea31012005-04-17 16:05:31 -05004547static int
James Smart2e0fef82007-06-17 19:56:36 -05004548lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4549 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004550{
4551 struct lpfc_dmabuf *pcmd;
4552 uint32_t *lp;
4553 IOCB_t *icmd;
4554 RNID *rn;
4555 struct ls_rjt stat;
4556 uint32_t cmd, did;
4557
4558 icmd = &cmdiocb->iocb;
4559 did = icmd->un.elsreq64.remoteID;
4560 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4561 lp = (uint32_t *) pcmd->virt;
4562
4563 cmd = *lp++;
4564 rn = (RNID *) lp;
4565
4566 /* RNID received */
4567
4568 switch (rn->Format) {
4569 case 0:
4570 case RNID_TOPOLOGY_DISC:
4571 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004572 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004573 break;
4574 default:
4575 /* Reject this request because format not supported */
4576 stat.un.b.lsRjtRsvd0 = 0;
4577 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4578 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4579 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004580 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4581 NULL);
dea31012005-04-17 16:05:31 -05004582 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004583 return 0;
dea31012005-04-17 16:05:31 -05004584}
4585
James Smarte59058c2008-08-24 21:49:00 -04004586/**
James Smart3621a712009-04-06 18:47:14 -04004587 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004588 * @vport: pointer to a host virtual N_Port data structure.
4589 * @cmdiocb: pointer to lpfc command iocb data structure.
4590 * @ndlp: pointer to a node-list data structure.
4591 *
4592 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4593 * received as an ELS unsolicited event. Currently, this function just invokes
4594 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4595 *
4596 * Return code
4597 * 0 - Successfully processed lirr iocb (currently always return 0)
4598 **/
dea31012005-04-17 16:05:31 -05004599static int
James Smart2e0fef82007-06-17 19:56:36 -05004600lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4601 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004602{
4603 struct ls_rjt stat;
4604
4605 /* For now, unconditionally reject this command */
4606 stat.un.b.lsRjtRsvd0 = 0;
4607 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4608 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4609 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004610 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004611 return 0;
4612}
4613
James Smarte59058c2008-08-24 21:49:00 -04004614/**
James Smart5ffc2662009-11-18 15:39:44 -05004615 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4616 * @vport: pointer to a host virtual N_Port data structure.
4617 * @cmdiocb: pointer to lpfc command iocb data structure.
4618 * @ndlp: pointer to a node-list data structure.
4619 *
4620 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4621 * received as an ELS unsolicited event. A request to RRQ shall only
4622 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4623 * Nx_Port N_Port_ID of the target Exchange is the same as the
4624 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4625 * not accepted, an LS_RJT with reason code "Unable to perform
4626 * command request" and reason code explanation "Invalid Originator
4627 * S_ID" shall be returned. For now, we just unconditionally accept
4628 * RRQ from the target.
4629 **/
4630static void
4631lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4632 struct lpfc_nodelist *ndlp)
4633{
4634 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4635}
4636
4637/**
James Smart3621a712009-04-06 18:47:14 -04004638 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004639 * @phba: pointer to lpfc hba data structure.
4640 * @pmb: pointer to the driver internal queue element for mailbox command.
4641 *
4642 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4643 * mailbox command. This callback function is to actually send the Accept
4644 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4645 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4646 * mailbox command, constructs the RPS response with the link statistics
4647 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4648 * response to the RPS.
4649 *
4650 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4651 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4652 * will be stored into the context1 field of the IOCB for the completion
4653 * callback function to the RPS Accept Response ELS IOCB command.
4654 *
4655 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004656static void
James Smart329f9bc2007-04-25 09:53:01 -04004657lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004658{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004659 MAILBOX_t *mb;
4660 IOCB_t *icmd;
4661 RPS_RSP *rps_rsp;
4662 uint8_t *pcmd;
4663 struct lpfc_iocbq *elsiocb;
4664 struct lpfc_nodelist *ndlp;
4665 uint16_t xri, status;
4666 uint32_t cmdsize;
4667
James Smart04c68492009-05-22 14:52:52 -04004668 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004669
4670 ndlp = (struct lpfc_nodelist *) pmb->context2;
4671 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004672 pmb->context1 = NULL;
4673 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004674
4675 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004676 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004677 return;
4678 }
4679
4680 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004681 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004682 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4683 lpfc_max_els_tries, ndlp,
4684 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004685
4686 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004687 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004688
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004689 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004690 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004691
4692 icmd = &elsiocb->iocb;
4693 icmd->ulpContext = xri;
4694
4695 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4696 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004697 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004698 rps_rsp = (RPS_RSP *)pcmd;
4699
4700 if (phba->fc_topology != TOPOLOGY_LOOP)
4701 status = 0x10;
4702 else
4703 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004704 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004705 status |= 0x4;
4706
4707 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004708 rps_rsp->portStatus = cpu_to_be16(status);
4709 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4710 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4711 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4712 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4713 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4714 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004715 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004716 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4717 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4718 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4719 elsiocb->iotag, elsiocb->iocb.ulpContext,
4720 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4721 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004722 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004723 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004724 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004725 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004726 return;
4727}
4728
James Smarte59058c2008-08-24 21:49:00 -04004729/**
James Smart3621a712009-04-06 18:47:14 -04004730 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004731 * @vport: pointer to a host virtual N_Port data structure.
4732 * @cmdiocb: pointer to lpfc command iocb data structure.
4733 * @ndlp: pointer to a node-list data structure.
4734 *
4735 * This routine processes Read Port Status (RPS) IOCB received as an
4736 * ELS unsolicited event. It first checks the remote port state. If the
4737 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4738 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4739 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4740 * for reading the HBA link statistics. It is for the callback function,
4741 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4742 * to actually sending out RPS Accept (ACC) response.
4743 *
4744 * Return codes
4745 * 0 - Successfully processed rps iocb (currently always return 0)
4746 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004747static int
James Smart2e0fef82007-06-17 19:56:36 -05004748lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4749 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004750{
James Smart2e0fef82007-06-17 19:56:36 -05004751 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004752 uint32_t *lp;
4753 uint8_t flag;
4754 LPFC_MBOXQ_t *mbox;
4755 struct lpfc_dmabuf *pcmd;
4756 RPS *rps;
4757 struct ls_rjt stat;
4758
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004759 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004760 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4761 /* reject the unsolicited RPS request and done with it */
4762 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004763
4764 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4765 lp = (uint32_t *) pcmd->virt;
4766 flag = (be32_to_cpu(*lp++) & 0xf);
4767 rps = (RPS *) lp;
4768
4769 if ((flag == 0) ||
4770 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004771 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004772 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004773
James Smart92d7f7b2007-06-17 19:56:38 -05004774 printk("Fix me....\n");
4775 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004776 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4777 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004778 lpfc_read_lnk_stat(phba, mbox);
4779 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004780 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004781 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004782 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004783 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004784 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004785 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004786 /* Mbox completion will send ELS Response */
4787 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004788 /* Decrement reference count used for the failed mbox
4789 * command.
4790 */
James Smart329f9bc2007-04-25 09:53:01 -04004791 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004792 mempool_free(mbox, phba->mbox_mem_pool);
4793 }
4794 }
James Smart90160e02008-08-24 21:49:45 -04004795
4796reject_out:
4797 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004798 stat.un.b.lsRjtRsvd0 = 0;
4799 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4800 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4801 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004802 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004803 return 0;
4804}
4805
James Smarte59058c2008-08-24 21:49:00 -04004806/**
James Smart3621a712009-04-06 18:47:14 -04004807 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004808 * @vport: pointer to a host virtual N_Port data structure.
4809 * @cmdsize: size of the ELS command.
4810 * @oldiocb: pointer to the original lpfc command iocb data structure.
4811 * @ndlp: pointer to a node-list data structure.
4812 *
4813 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4814 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4815 *
4816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4818 * will be stored into the context1 field of the IOCB for the completion
4819 * callback function to the RPL Accept Response ELS command.
4820 *
4821 * Return code
4822 * 0 - Successfully issued ACC RPL ELS command
4823 * 1 - Failed to issue ACC RPL ELS command
4824 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004825static int
James Smart2e0fef82007-06-17 19:56:36 -05004826lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4827 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004828{
James Smart2e0fef82007-06-17 19:56:36 -05004829 struct lpfc_hba *phba = vport->phba;
4830 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004831 RPL_RSP rpl_rsp;
4832 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004833 uint8_t *pcmd;
4834
James Smart2e0fef82007-06-17 19:56:36 -05004835 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4836 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004837
James Smart488d1462006-03-07 15:02:37 -05004838 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004839 return 1;
James Smart488d1462006-03-07 15:02:37 -05004840
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004841 icmd = &elsiocb->iocb;
4842 oldcmd = &oldiocb->iocb;
4843 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4844
4845 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4846 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004847 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004848 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4849 pcmd += sizeof(uint16_t);
4850
4851 /* Setup the RPL ACC payload */
4852 rpl_rsp.listLen = be32_to_cpu(1);
4853 rpl_rsp.index = 0;
4854 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004855 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4856 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004857 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004858 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004859 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004860 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4861 "0120 Xmit ELS RPL ACC response tag x%x "
4862 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4863 "rpi x%x\n",
4864 elsiocb->iotag, elsiocb->iocb.ulpContext,
4865 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4866 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004867 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004868 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004869 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4870 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004871 lpfc_els_free_iocb(phba, elsiocb);
4872 return 1;
4873 }
4874 return 0;
4875}
4876
James Smarte59058c2008-08-24 21:49:00 -04004877/**
James Smart3621a712009-04-06 18:47:14 -04004878 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004879 * @vport: pointer to a host virtual N_Port data structure.
4880 * @cmdiocb: pointer to lpfc command iocb data structure.
4881 * @ndlp: pointer to a node-list data structure.
4882 *
4883 * This routine processes Read Port List (RPL) IOCB received as an ELS
4884 * unsolicited event. It first checks the remote port state. If the remote
4885 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4886 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4887 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4888 * to accept the RPL.
4889 *
4890 * Return code
4891 * 0 - Successfully processed rpl iocb (currently always return 0)
4892 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004893static int
James Smart2e0fef82007-06-17 19:56:36 -05004894lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4895 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004896{
4897 struct lpfc_dmabuf *pcmd;
4898 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004899 uint32_t maxsize;
4900 uint16_t cmdsize;
4901 RPL *rpl;
4902 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004903
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004904 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4905 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004906 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004907 stat.un.b.lsRjtRsvd0 = 0;
4908 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4909 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4910 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004911 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4912 NULL);
James Smart90160e02008-08-24 21:49:45 -04004913 /* rejected the unsolicited RPL request and done with it */
4914 return 0;
dea31012005-04-17 16:05:31 -05004915 }
4916
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004917 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4918 lp = (uint32_t *) pcmd->virt;
4919 rpl = (RPL *) (lp + 1);
4920
4921 maxsize = be32_to_cpu(rpl->maxsize);
4922
4923 /* We support only one port */
4924 if ((rpl->index == 0) &&
4925 ((maxsize == 0) ||
4926 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4927 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004928 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004929 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4930 }
James Smart2e0fef82007-06-17 19:56:36 -05004931 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004932
4933 return 0;
4934}
4935
James Smarte59058c2008-08-24 21:49:00 -04004936/**
James Smart3621a712009-04-06 18:47:14 -04004937 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004938 * @vport: pointer to a virtual N_Port data structure.
4939 * @cmdiocb: pointer to lpfc command iocb data structure.
4940 * @ndlp: pointer to a node-list data structure.
4941 *
4942 * This routine processes Fibre Channel Address Resolution Protocol
4943 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4944 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4945 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4946 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4947 * remote PortName is compared against the FC PortName stored in the @vport
4948 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4949 * compared against the FC NodeName stored in the @vport data structure.
4950 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4951 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4952 * invoked to send out FARP Response to the remote node. Before sending the
4953 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4954 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4955 * routine is invoked to log into the remote port first.
4956 *
4957 * Return code
4958 * 0 - Either the FARP Match Mode not supported or successfully processed
4959 **/
dea31012005-04-17 16:05:31 -05004960static int
James Smart2e0fef82007-06-17 19:56:36 -05004961lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4962 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004963{
4964 struct lpfc_dmabuf *pcmd;
4965 uint32_t *lp;
4966 IOCB_t *icmd;
4967 FARP *fp;
4968 uint32_t cmd, cnt, did;
4969
4970 icmd = &cmdiocb->iocb;
4971 did = icmd->un.elsreq64.remoteID;
4972 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4973 lp = (uint32_t *) pcmd->virt;
4974
4975 cmd = *lp++;
4976 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004977 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004978 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4979 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004980 /* We will only support match on WWPN or WWNN */
4981 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004982 return 0;
dea31012005-04-17 16:05:31 -05004983 }
4984
4985 cnt = 0;
4986 /* If this FARP command is searching for my portname */
4987 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004988 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004989 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004990 cnt = 1;
4991 }
4992
4993 /* If this FARP command is searching for my nodename */
4994 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004995 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004996 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004997 cnt = 1;
4998 }
4999
5000 if (cnt) {
5001 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5002 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5003 /* Log back into the node before sending the FARP. */
5004 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005005 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005006 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005007 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005008 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005009 }
5010
5011 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005012 if (fp->Rflags & FARP_REQUEST_FARPR)
5013 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005014 }
5015 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005016 return 0;
dea31012005-04-17 16:05:31 -05005017}
5018
James Smarte59058c2008-08-24 21:49:00 -04005019/**
James Smart3621a712009-04-06 18:47:14 -04005020 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005021 * @vport: pointer to a host virtual N_Port data structure.
5022 * @cmdiocb: pointer to lpfc command iocb data structure.
5023 * @ndlp: pointer to a node-list data structure.
5024 *
5025 * This routine processes Fibre Channel Address Resolution Protocol
5026 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5027 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5028 * the FARP response request.
5029 *
5030 * Return code
5031 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5032 **/
dea31012005-04-17 16:05:31 -05005033static int
James Smart2e0fef82007-06-17 19:56:36 -05005034lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5035 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005036{
5037 struct lpfc_dmabuf *pcmd;
5038 uint32_t *lp;
5039 IOCB_t *icmd;
5040 uint32_t cmd, did;
5041
5042 icmd = &cmdiocb->iocb;
5043 did = icmd->un.elsreq64.remoteID;
5044 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5045 lp = (uint32_t *) pcmd->virt;
5046
5047 cmd = *lp++;
5048 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5050 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005051 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005052 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005053
5054 return 0;
5055}
5056
James Smarte59058c2008-08-24 21:49:00 -04005057/**
James Smart3621a712009-04-06 18:47:14 -04005058 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005059 * @vport: pointer to a host virtual N_Port data structure.
5060 * @cmdiocb: pointer to lpfc command iocb data structure.
5061 * @fan_ndlp: pointer to a node-list data structure.
5062 *
5063 * This routine processes a Fabric Address Notification (FAN) IOCB
5064 * command received as an ELS unsolicited event. The FAN ELS command will
5065 * only be processed on a physical port (i.e., the @vport represents the
5066 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5067 * compared against those in the phba data structure. If any of those is
5068 * different, the lpfc_initial_flogi() routine is invoked to initialize
5069 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5070 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5071 * is invoked to register login to the fabric.
5072 *
5073 * Return code
5074 * 0 - Successfully processed fan iocb (currently always return 0).
5075 **/
dea31012005-04-17 16:05:31 -05005076static int
James Smart2e0fef82007-06-17 19:56:36 -05005077lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5078 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005079{
James Smart2e0fef82007-06-17 19:56:36 -05005080 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005081 uint32_t *lp;
5082 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005083
James Smart0d2b6b82008-06-14 22:52:47 -04005084 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5085 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5086 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005087 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005088 if ((vport == phba->pport) &&
5089 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005090 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005091 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005092 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005093 sizeof(struct lpfc_name)))) {
5094 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005095 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005096 } else {
5097 /* FAN verified - skip FLOGI */
5098 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005099 if (phba->sli_rev < LPFC_SLI_REV4)
5100 lpfc_issue_fabric_reglogin(vport);
5101 else
5102 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005103 }
dea31012005-04-17 16:05:31 -05005104 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005105 return 0;
dea31012005-04-17 16:05:31 -05005106}
5107
James Smarte59058c2008-08-24 21:49:00 -04005108/**
James Smart3621a712009-04-06 18:47:14 -04005109 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005110 * @ptr: holder for the timer function associated data.
5111 *
5112 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5113 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5114 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5115 * up the worker thread. It is for the worker thread to invoke the routine
5116 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5117 **/
dea31012005-04-17 16:05:31 -05005118void
5119lpfc_els_timeout(unsigned long ptr)
5120{
James Smart2e0fef82007-06-17 19:56:36 -05005121 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5122 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005123 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005124 unsigned long iflag;
5125
James Smart2e0fef82007-06-17 19:56:36 -05005126 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005127 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5128 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005129 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005130 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005131
James Smart5e9d9b82008-06-14 22:52:53 -04005132 if (!tmo_posted)
5133 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005134 return;
5135}
5136
James Smarte59058c2008-08-24 21:49:00 -04005137/**
James Smart3621a712009-04-06 18:47:14 -04005138 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005139 * @vport: pointer to a virtual N_Port data structure.
5140 *
5141 * This routine is the actual handler function that processes an ELS timeout
5142 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5143 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5144 * invoking the lpfc_sli_issue_abort_iotag() routine.
5145 **/
dea31012005-04-17 16:05:31 -05005146void
James Smart2e0fef82007-06-17 19:56:36 -05005147lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005148{
James Smart2e0fef82007-06-17 19:56:36 -05005149 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005150 struct lpfc_sli_ring *pring;
5151 struct lpfc_iocbq *tmp_iocb, *piocb;
5152 IOCB_t *cmd = NULL;
5153 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005154 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005155 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005156 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005157
James Smart2e0fef82007-06-17 19:56:36 -05005158 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005159 timeout = (uint32_t)(phba->fc_ratov << 1);
5160
5161 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005162
5163 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5164 cmd = &piocb->iocb;
5165
James Smart2e0fef82007-06-17 19:56:36 -05005166 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5167 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5168 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005169 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005170
5171 if (piocb->vport != vport)
5172 continue;
5173
dea31012005-04-17 16:05:31 -05005174 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005175 if (pcmd)
5176 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005177
James Smart92d7f7b2007-06-17 19:56:38 -05005178 if (els_command == ELS_CMD_FARP ||
5179 els_command == ELS_CMD_FARPR ||
5180 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005181 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005182
dea31012005-04-17 16:05:31 -05005183 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005184 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005185 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005186 else
dea31012005-04-17 16:05:31 -05005187 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005188 continue;
5189 }
5190
James Smart2e0fef82007-06-17 19:56:36 -05005191 remote_ID = 0xffffffff;
5192 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005193 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005194 else {
5195 struct lpfc_nodelist *ndlp;
5196 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005197 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005198 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005199 }
James Smarte8b62012007-08-02 11:10:09 -04005200 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5201 "0127 ELS timeout Data: x%x x%x x%x "
5202 "x%x\n", els_command,
5203 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005204 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005205 }
James Smart2e0fef82007-06-17 19:56:36 -05005206 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005207
James Smart2e0fef82007-06-17 19:56:36 -05005208 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5209 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005210}
5211
James Smarte59058c2008-08-24 21:49:00 -04005212/**
James Smart3621a712009-04-06 18:47:14 -04005213 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005214 * @vport: pointer to a host virtual N_Port data structure.
5215 *
5216 * This routine is used to clean up all the outstanding ELS commands on a
5217 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5218 * routine. After that, it walks the ELS transmit queue to remove all the
5219 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5220 * the IOCBs with a non-NULL completion callback function, the callback
5221 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5222 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5223 * callback function, the IOCB will simply be released. Finally, it walks
5224 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5225 * completion queue IOCB that is associated with the @vport and is not
5226 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5227 * part of the discovery state machine) out to HBA by invoking the
5228 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5229 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5230 * the IOCBs are aborted when this function returns.
5231 **/
dea31012005-04-17 16:05:31 -05005232void
James Smart2e0fef82007-06-17 19:56:36 -05005233lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005234{
James Smart2534ba72007-04-25 09:52:20 -04005235 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005236 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005237 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005238 struct lpfc_iocbq *tmp_iocb, *piocb;
5239 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005240
5241 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005242
James Smart2e0fef82007-06-17 19:56:36 -05005243 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005244 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5245 cmd = &piocb->iocb;
5246
5247 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5248 continue;
5249 }
5250
5251 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005252 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5253 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5254 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5255 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005256 continue;
dea31012005-04-17 16:05:31 -05005257
James Smart2e0fef82007-06-17 19:56:36 -05005258 if (piocb->vport != vport)
5259 continue;
5260
James Smart2534ba72007-04-25 09:52:20 -04005261 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005262 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005263 }
5264
5265 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005266 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5267 continue;
5268 }
dea31012005-04-17 16:05:31 -05005269
James Smart2e0fef82007-06-17 19:56:36 -05005270 if (piocb->vport != vport)
5271 continue;
5272
James Smart07951072007-04-25 09:51:38 -04005273 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005274 }
James Smart2e0fef82007-06-17 19:56:36 -05005275 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005276
James Smarta257bf92009-04-06 18:48:10 -04005277 /* Cancell all the IOCBs from the completions list */
5278 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5279 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005280
dea31012005-04-17 16:05:31 -05005281 return;
5282}
5283
James Smarte59058c2008-08-24 21:49:00 -04005284/**
James Smart3621a712009-04-06 18:47:14 -04005285 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005286 * @phba: pointer to lpfc hba data structure.
5287 *
5288 * This routine is used to clean up all the outstanding ELS commands on a
5289 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5290 * routine. After that, it walks the ELS transmit queue to remove all the
5291 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5292 * the IOCBs with the completion callback function associated, the callback
5293 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5294 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5295 * callback function associated, the IOCB will simply be released. Finally,
5296 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5297 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5298 * management plane IOCBs that are not part of the discovery state machine)
5299 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5300 **/
James Smart549e55c2007-08-02 11:09:51 -04005301void
5302lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5303{
5304 LIST_HEAD(completions);
5305 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5306 struct lpfc_iocbq *tmp_iocb, *piocb;
5307 IOCB_t *cmd = NULL;
5308
5309 lpfc_fabric_abort_hba(phba);
5310 spin_lock_irq(&phba->hbalock);
5311 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5312 cmd = &piocb->iocb;
5313 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5314 continue;
5315 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5316 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5317 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5318 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5319 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5320 continue;
5321 list_move_tail(&piocb->list, &completions);
5322 pring->txq_cnt--;
5323 }
5324 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5325 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5326 continue;
5327 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5328 }
5329 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005330
5331 /* Cancel all the IOCBs from the completions list */
5332 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5333 IOERR_SLI_ABORTED);
5334
James Smart549e55c2007-08-02 11:09:51 -04005335 return;
5336}
5337
James Smarte59058c2008-08-24 21:49:00 -04005338/**
James Smart3621a712009-04-06 18:47:14 -04005339 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005340 * @phba: Pointer to hba context object.
5341 * @cmdiocbp: Pointer to command iocb which reported error.
5342 * @rspiocbp: Pointer to response iocb which reported error.
5343 *
5344 * This function sends an event when there is an ELS command
5345 * failure.
5346 **/
5347void
5348lpfc_send_els_failure_event(struct lpfc_hba *phba,
5349 struct lpfc_iocbq *cmdiocbp,
5350 struct lpfc_iocbq *rspiocbp)
5351{
5352 struct lpfc_vport *vport = cmdiocbp->vport;
5353 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5354 struct lpfc_lsrjt_event lsrjt_event;
5355 struct lpfc_fabric_event_header fabric_event;
5356 struct ls_rjt stat;
5357 struct lpfc_nodelist *ndlp;
5358 uint32_t *pcmd;
5359
5360 ndlp = cmdiocbp->context1;
5361 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5362 return;
5363
5364 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5365 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5366 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5367 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5368 sizeof(struct lpfc_name));
5369 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5370 sizeof(struct lpfc_name));
5371 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5372 cmdiocbp->context2)->virt);
5373 lsrjt_event.command = *pcmd;
5374 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5375 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5376 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5377 fc_host_post_vendor_event(shost,
5378 fc_get_event_number(),
5379 sizeof(lsrjt_event),
5380 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005381 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005382 return;
5383 }
5384 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5385 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5386 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5387 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5388 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5389 else
5390 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5391 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5392 sizeof(struct lpfc_name));
5393 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5394 sizeof(struct lpfc_name));
5395 fc_host_post_vendor_event(shost,
5396 fc_get_event_number(),
5397 sizeof(fabric_event),
5398 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005399 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005400 return;
5401 }
5402
5403}
5404
5405/**
James Smart3621a712009-04-06 18:47:14 -04005406 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005407 * @vport: Pointer to vport object.
5408 * @ndlp: Pointer FC node object.
5409 * @cmd: ELS command code.
5410 *
5411 * This function posts an event when there is an incoming
5412 * unsolicited ELS command.
5413 **/
5414static void
5415lpfc_send_els_event(struct lpfc_vport *vport,
5416 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005417 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005418{
James Smartddcc50f2008-12-04 22:38:46 -05005419 struct lpfc_els_event_header *els_data = NULL;
5420 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5422
James Smartddcc50f2008-12-04 22:38:46 -05005423 if (*payload == ELS_CMD_LOGO) {
5424 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5425 if (!logo_data) {
5426 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5427 "0148 Failed to allocate memory "
5428 "for LOGO event\n");
5429 return;
5430 }
5431 els_data = &logo_data->header;
5432 } else {
5433 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5434 GFP_KERNEL);
5435 if (!els_data) {
5436 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5437 "0149 Failed to allocate memory "
5438 "for ELS event\n");
5439 return;
5440 }
5441 }
5442 els_data->event_type = FC_REG_ELS_EVENT;
5443 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005444 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005445 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005446 break;
5447 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005448 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005449 break;
5450 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005451 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5452 break;
5453 case ELS_CMD_LOGO:
5454 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5455 /* Copy the WWPN in the LOGO payload */
5456 memcpy(logo_data->logo_wwpn, &payload[2],
5457 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005458 break;
5459 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005460 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005461 return;
5462 }
James Smartddcc50f2008-12-04 22:38:46 -05005463 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5464 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5465 if (*payload == ELS_CMD_LOGO) {
5466 fc_host_post_vendor_event(shost,
5467 fc_get_event_number(),
5468 sizeof(struct lpfc_logo_event),
5469 (char *)logo_data,
5470 LPFC_NL_VENDOR_ID);
5471 kfree(logo_data);
5472 } else {
5473 fc_host_post_vendor_event(shost,
5474 fc_get_event_number(),
5475 sizeof(struct lpfc_els_event_header),
5476 (char *)els_data,
5477 LPFC_NL_VENDOR_ID);
5478 kfree(els_data);
5479 }
James Smartea2151b2008-09-07 11:52:10 -04005480
5481 return;
5482}
5483
5484
5485/**
James Smart3621a712009-04-06 18:47:14 -04005486 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005487 * @phba: pointer to lpfc hba data structure.
5488 * @pring: pointer to a SLI ring.
5489 * @vport: pointer to a host virtual N_Port data structure.
5490 * @elsiocb: pointer to lpfc els command iocb data structure.
5491 *
5492 * This routine is used for processing the IOCB associated with a unsolicited
5493 * event. It first determines whether there is an existing ndlp that matches
5494 * the DID from the unsolicited IOCB. If not, it will create a new one with
5495 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5496 * IOCB is then used to invoke the proper routine and to set up proper state
5497 * of the discovery state machine.
5498 **/
James Smarted957682007-06-17 19:56:37 -05005499static void
5500lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005501 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005502{
James Smart87af33f2007-10-27 13:37:43 -04005503 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005504 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005505 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005506 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005507 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005508 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005509
James Smarte47c9092008-02-08 18:49:26 -05005510 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005511 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005512
dea31012005-04-17 16:05:31 -05005513 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005514 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5515 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005516 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005517 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005518
James Smart858c9f62007-06-17 19:56:39 -05005519 did = icmd->un.rcvels.remoteID;
5520 if (icmd->ulpStatus) {
5521 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5522 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5523 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005524 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005525 }
dea31012005-04-17 16:05:31 -05005526
5527 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005528 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005529 goto dropit;
dea31012005-04-17 16:05:31 -05005530
James Smartc8685952009-11-18 15:39:16 -05005531 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005532 if (vport->load_flag & FC_UNLOADING)
5533 goto dropit;
5534
James Smart2e0fef82007-06-17 19:56:36 -05005535 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005536 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005537 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005538 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005539 if (!ndlp)
dea31012005-04-17 16:05:31 -05005540 goto dropit;
dea31012005-04-17 16:05:31 -05005541
James Smart2e0fef82007-06-17 19:56:36 -05005542 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005543 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005544 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005545 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005546 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005547 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5548 ndlp = lpfc_enable_node(vport, ndlp,
5549 NLP_STE_UNUSED_NODE);
5550 if (!ndlp)
5551 goto dropit;
5552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5553 newnode = 1;
5554 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5555 ndlp->nlp_type |= NLP_FABRIC;
5556 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5557 /* This is similar to the new node path */
5558 ndlp = lpfc_nlp_get(ndlp);
5559 if (!ndlp)
5560 goto dropit;
5561 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5562 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005563 }
dea31012005-04-17 16:05:31 -05005564
5565 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005566
James Smart329f9bc2007-04-25 09:53:01 -04005567 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005568 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005569
5570 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5571 cmd &= ELS_CMD_MASK;
5572 }
5573 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005574 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5575 "0112 ELS command x%x received from NPORT x%x "
5576 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005577 switch (cmd) {
5578 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005579 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5580 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5581 did, vport->port_state, ndlp->nlp_flag);
5582
dea31012005-04-17 16:05:31 -05005583 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005584 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5585
James Smartddcc50f2008-12-04 22:38:46 -05005586 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005587 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005588 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5589 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5590 rjt_err = LSRJT_UNABLE_TPC;
5591 break;
5592 }
5593 /* We get here, and drop thru, if we are PT2PT with
5594 * another NPort and the other side has initiated
5595 * the PLOGI before responding to our FLOGI.
5596 */
dea31012005-04-17 16:05:31 -05005597 }
James Smart87af33f2007-10-27 13:37:43 -04005598
5599 shost = lpfc_shost_from_vport(vport);
5600 spin_lock_irq(shost->host_lock);
5601 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5602 spin_unlock_irq(shost->host_lock);
5603
James Smart2e0fef82007-06-17 19:56:36 -05005604 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5605 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005606
dea31012005-04-17 16:05:31 -05005607 break;
5608 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005609 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5610 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5611 did, vport->port_state, ndlp->nlp_flag);
5612
dea31012005-04-17 16:05:31 -05005613 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005614 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005615 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005616 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005617 break;
5618 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5620 "RCV LOGO: 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.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005624 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005625 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005626 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005627 break;
5628 }
James Smart2e0fef82007-06-17 19:56:36 -05005629 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005630 break;
5631 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5633 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5634 did, vport->port_state, ndlp->nlp_flag);
5635
dea31012005-04-17 16:05:31 -05005636 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005637 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005638 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005639 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005640 break;
5641 }
James Smart2e0fef82007-06-17 19:56:36 -05005642 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005643 break;
5644 case ELS_CMD_RSCN:
5645 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005646 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005647 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005648 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005649 break;
5650 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005651 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5652 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5653 did, vport->port_state, ndlp->nlp_flag);
5654
James Smartddcc50f2008-12-04 22:38:46 -05005655 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005656 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005657 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005658 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005659 break;
5660 }
James Smart2e0fef82007-06-17 19:56:36 -05005661 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5662 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005663 break;
5664 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5666 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5667 did, vport->port_state, ndlp->nlp_flag);
5668
dea31012005-04-17 16:05:31 -05005669 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005670 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005671 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005672 break;
5673 }
James Smart2e0fef82007-06-17 19:56:36 -05005674 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5675 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005676 break;
5677 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005678 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5679 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5680 did, vport->port_state, ndlp->nlp_flag);
5681
dea31012005-04-17 16:05:31 -05005682 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005683 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005684 break;
5685 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5687 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5688 did, vport->port_state, ndlp->nlp_flag);
5689
dea31012005-04-17 16:05:31 -05005690 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005691 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005692 break;
5693 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5695 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5696 did, vport->port_state, ndlp->nlp_flag);
5697
dea31012005-04-17 16:05:31 -05005698 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005699 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005700 break;
dea31012005-04-17 16:05:31 -05005701 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5703 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5704 did, vport->port_state, ndlp->nlp_flag);
5705
dea31012005-04-17 16:05:31 -05005706 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005707 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005708 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005709 break;
5710 }
James Smart2e0fef82007-06-17 19:56:36 -05005711 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005712 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005713 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005714 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5715 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5716 did, vport->port_state, ndlp->nlp_flag);
5717
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005718 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005719 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005720 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005721 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005722 break;
5723 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005724 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5725 "RCV RPS: 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.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005729 lpfc_els_rcv_rps(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_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5735 "RCV RPL: 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.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005739 lpfc_els_rcv_rpl(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;
dea31012005-04-17 16:05:31 -05005743 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5745 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5746 did, vport->port_state, ndlp->nlp_flag);
5747
dea31012005-04-17 16:05:31 -05005748 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005749 lpfc_els_rcv_rnid(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);
dea31012005-04-17 16:05:31 -05005752 break;
James Smart5ffc2662009-11-18 15:39:44 -05005753 case ELS_CMD_RRQ:
5754 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5755 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5756 did, vport->port_state, ndlp->nlp_flag);
5757
5758 phba->fc_stat.elsRcvRRQ++;
5759 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5760 if (newnode)
5761 lpfc_nlp_put(ndlp);
5762 break;
dea31012005-04-17 16:05:31 -05005763 default:
James Smart858c9f62007-06-17 19:56:39 -05005764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5765 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5766 cmd, did, vport->port_state);
5767
dea31012005-04-17 16:05:31 -05005768 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005769 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005770
5771 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5773 "0115 Unknown ELS command x%x "
5774 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005775 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005776 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005777 break;
5778 }
5779
5780 /* check if need to LS_RJT received ELS cmd */
5781 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005782 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005783 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005784 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005785 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5786 NULL);
dea31012005-04-17 16:05:31 -05005787 }
5788
James Smartd7c255b2008-08-24 21:50:00 -04005789 lpfc_nlp_put(elsiocb->context1);
5790 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005791 return;
5792
5793dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005794 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005795 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5796 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005797 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005798 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005799 phba->fc_stat.elsRcvDrop++;
5800}
5801
James Smarte59058c2008-08-24 21:49:00 -04005802/**
James Smart3621a712009-04-06 18:47:14 -04005803 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005804 * @phba: pointer to lpfc hba data structure.
5805 * @vpi: host virtual N_Port identifier.
5806 *
5807 * This routine finds a vport on a HBA (referred by @phba) through a
5808 * @vpi. The function walks the HBA's vport list and returns the address
5809 * of the vport with the matching @vpi.
5810 *
5811 * Return code
5812 * NULL - No vport with the matching @vpi found
5813 * Otherwise - Address to the vport with the matching @vpi.
5814 **/
James Smart6669f9b2009-10-02 15:16:45 -04005815struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005816lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5817{
5818 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005819 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005820
James Smart549e55c2007-08-02 11:09:51 -04005821 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005822 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005823 if (vport->vpi == vpi) {
5824 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005825 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005826 }
James Smart92d7f7b2007-06-17 19:56:38 -05005827 }
James Smart549e55c2007-08-02 11:09:51 -04005828 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005829 return NULL;
5830}
James Smarted957682007-06-17 19:56:37 -05005831
James Smarte59058c2008-08-24 21:49:00 -04005832/**
James Smart3621a712009-04-06 18:47:14 -04005833 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005834 * @phba: pointer to lpfc hba data structure.
5835 * @pring: pointer to a SLI ring.
5836 * @elsiocb: pointer to lpfc els iocb data structure.
5837 *
5838 * This routine is used to process an unsolicited event received from a SLI
5839 * (Service Level Interface) ring. The actual processing of the data buffer
5840 * associated with the unsolicited event is done by invoking the routine
5841 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5842 * SLI ring on which the unsolicited event was received.
5843 **/
James Smarted957682007-06-17 19:56:37 -05005844void
5845lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5846 struct lpfc_iocbq *elsiocb)
5847{
5848 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005849 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005850 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005851 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5852 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005853
James Smartd7c255b2008-08-24 21:50:00 -04005854 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005855 elsiocb->context2 = NULL;
5856 elsiocb->context3 = NULL;
5857
5858 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5859 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5860 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5861 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005862 phba->fc_stat.NoRcvBuf++;
5863 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005864 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005865 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005866 return;
5867 }
5868
James Smart92d7f7b2007-06-17 19:56:38 -05005869 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5870 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5871 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5872 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5873 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005874 else
5875 vport = lpfc_find_vport_by_vpid(phba,
5876 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005877 }
James Smart7f5f3d02008-02-08 18:50:14 -05005878 /* If there are no BDEs associated
5879 * with this IOCB, there is nothing to do.
5880 */
James Smarted957682007-06-17 19:56:37 -05005881 if (icmd->ulpBdeCount == 0)
5882 return;
5883
James Smart7f5f3d02008-02-08 18:50:14 -05005884 /* type of ELS cmd is first 32bit word
5885 * in packet
5886 */
James Smarted957682007-06-17 19:56:37 -05005887 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005888 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005889 } else {
5890 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5891 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005892 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5893 paddr);
James Smarted957682007-06-17 19:56:37 -05005894 }
5895
James Smart92d7f7b2007-06-17 19:56:38 -05005896 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5897 /*
5898 * The different unsolicited event handlers would tell us
5899 * if they are done with "mp" by setting context2 to NULL.
5900 */
dea31012005-04-17 16:05:31 -05005901 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005902 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5903 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005904 }
James Smarted957682007-06-17 19:56:37 -05005905
5906 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005907 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005908 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005909 elsiocb->context2 = bdeBuf2;
5910 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005911 /* free mp if we are done with it */
5912 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005913 lpfc_in_buf_free(phba, elsiocb->context2);
5914 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005915 }
dea31012005-04-17 16:05:31 -05005916 }
dea31012005-04-17 16:05:31 -05005917}
James Smart92d7f7b2007-06-17 19:56:38 -05005918
James Smarte59058c2008-08-24 21:49:00 -04005919/**
James Smart3621a712009-04-06 18:47:14 -04005920 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005921 * @phba: pointer to lpfc hba data structure.
5922 * @vport: pointer to a virtual N_Port data structure.
5923 *
5924 * This routine issues a Port Login (PLOGI) to the Name Server with
5925 * State Change Request (SCR) for a @vport. This routine will create an
5926 * ndlp for the Name Server associated to the @vport if such node does
5927 * not already exist. The PLOGI to Name Server is issued by invoking the
5928 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5929 * (FDMI) is configured to the @vport, a FDMI node will be created and
5930 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5931 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005932void
5933lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5934{
5935 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5936
5937 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5938 if (!ndlp) {
5939 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5940 if (!ndlp) {
5941 if (phba->fc_topology == TOPOLOGY_LOOP) {
5942 lpfc_disc_start(vport);
5943 return;
5944 }
5945 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005946 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5947 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005948 return;
5949 }
5950 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005951 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5952 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5953 if (!ndlp) {
5954 if (phba->fc_topology == TOPOLOGY_LOOP) {
5955 lpfc_disc_start(vport);
5956 return;
5957 }
5958 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5959 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5960 "0348 NameServer login: node freed\n");
5961 return;
5962 }
James Smart92d7f7b2007-06-17 19:56:38 -05005963 }
James Smart58da1ff2008-04-07 10:15:56 -04005964 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005965
5966 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5967
5968 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5969 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005970 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5971 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005972 return;
5973 }
5974
James Smart3de2a652007-08-02 11:09:59 -04005975 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005976 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5977 GFP_KERNEL);
5978 if (ndlp_fdmi) {
5979 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5980 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005981 lpfc_nlp_set_state(vport, ndlp_fdmi,
5982 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005983 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5984 0);
5985 }
5986 }
5987 return;
5988}
5989
James Smarte59058c2008-08-24 21:49:00 -04005990/**
James Smart3621a712009-04-06 18:47:14 -04005991 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005992 * @phba: pointer to lpfc hba data structure.
5993 * @pmb: pointer to the driver internal queue element for mailbox command.
5994 *
5995 * This routine is the completion callback function to register new vport
5996 * mailbox command. If the new vport mailbox command completes successfully,
5997 * the fabric registration login shall be performed on physical port (the
5998 * new vport created is actually a physical port, with VPI 0) or the port
5999 * login to Name Server for State Change Request (SCR) will be performed
6000 * on virtual port (real virtual port, with VPI greater than 0).
6001 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006002static void
6003lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6004{
6005 struct lpfc_vport *vport = pmb->vport;
6006 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6007 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006008 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006009 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006010
James Smart09372822008-01-11 01:52:54 -05006011 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006012 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006013 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006014
6015 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006016 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6017 "0915 Register VPI failed: 0x%x\n",
6018 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05006019
6020 switch (mb->mbxStatus) {
6021 case 0x11: /* unsupported feature */
6022 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006023 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006024 /* giving up on vport registration */
6025 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6026 spin_lock_irq(shost->host_lock);
6027 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6028 spin_unlock_irq(shost->host_lock);
6029 lpfc_can_disctmo(vport);
6030 break;
James Smart695a8142010-01-26 23:08:03 -05006031 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6032 case 0x20:
6033 spin_lock_irq(shost->host_lock);
6034 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6035 spin_unlock_irq(shost->host_lock);
6036 lpfc_init_vpi(phba, pmb, vport->vpi);
6037 pmb->vport = vport;
6038 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6039 rc = lpfc_sli_issue_mbox(phba, pmb,
6040 MBX_NOWAIT);
6041 if (rc == MBX_NOT_FINISHED) {
6042 lpfc_printf_vlog(vport,
6043 KERN_ERR, LOG_MBOX,
6044 "2732 Failed to issue INIT_VPI"
6045 " mailbox command\n");
6046 } else {
6047 lpfc_nlp_put(ndlp);
6048 return;
6049 }
6050
James Smart92d7f7b2007-06-17 19:56:38 -05006051 default:
6052 /* Try to recover from this error */
6053 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006054 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006055 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006056 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006057 if (vport->port_type == LPFC_PHYSICAL_PORT
6058 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006059 lpfc_initial_flogi(vport);
6060 else
6061 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006062 break;
6063 }
James Smart92d7f7b2007-06-17 19:56:38 -05006064 } else {
James Smart695a8142010-01-26 23:08:03 -05006065 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006066 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006067 spin_unlock_irq(shost->host_lock);
6068 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006069 if (phba->sli_rev < LPFC_SLI_REV4)
6070 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006071 else {
James Smartfc2b9892010-02-26 14:15:29 -05006072 /*
6073 * If the physical port is instantiated using
6074 * FDISC, do not start vport discovery.
6075 */
6076 if (vport->port_state != LPFC_FDISC)
6077 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006078 lpfc_do_scr_ns_plogi(phba, vport);
6079 }
6080 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006081 lpfc_do_scr_ns_plogi(phba, vport);
6082 }
James Smartfa4066b2008-01-11 01:53:27 -05006083
6084 /* Now, we decrement the ndlp reference count held for this
6085 * callback function
6086 */
6087 lpfc_nlp_put(ndlp);
6088
James Smart92d7f7b2007-06-17 19:56:38 -05006089 mempool_free(pmb, phba->mbox_mem_pool);
6090 return;
6091}
6092
James Smarte59058c2008-08-24 21:49:00 -04006093/**
James Smart3621a712009-04-06 18:47:14 -04006094 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006095 * @phba: pointer to lpfc hba data structure.
6096 * @vport: pointer to a host virtual N_Port data structure.
6097 * @ndlp: pointer to a node-list data structure.
6098 *
6099 * This routine registers the @vport as a new virtual port with a HBA.
6100 * It is done through a registering vpi mailbox command.
6101 **/
James Smart695a8142010-01-26 23:08:03 -05006102void
James Smart92d7f7b2007-06-17 19:56:38 -05006103lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6104 struct lpfc_nodelist *ndlp)
6105{
James Smart09372822008-01-11 01:52:54 -05006106 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006107 LPFC_MBOXQ_t *mbox;
6108
6109 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6110 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006111 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006112 mbox->vport = vport;
6113 mbox->context2 = lpfc_nlp_get(ndlp);
6114 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006115 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006116 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006117 /* mailbox command not success, decrement ndlp
6118 * reference count for this command
6119 */
6120 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006121 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006122
James Smarte8b62012007-08-02 11:10:09 -04006123 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6124 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006125 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006126 }
6127 } else {
James Smarte8b62012007-08-02 11:10:09 -04006128 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6129 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006130 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006131 }
James Smartfa4066b2008-01-11 01:53:27 -05006132 return;
6133
6134mbox_err_exit:
6135 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6136 spin_lock_irq(shost->host_lock);
6137 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6138 spin_unlock_irq(shost->host_lock);
6139 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006140}
6141
James Smarte59058c2008-08-24 21:49:00 -04006142/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006143 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006144 * @phba: pointer to lpfc hba data structure.
6145 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006146 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006147 **/
6148void
James Smart0c9ab6f2010-02-26 14:15:57 -05006149lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006150{
6151 struct lpfc_vport **vports;
6152 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006153 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006154 int i;
James Smart695a8142010-01-26 23:08:03 -05006155
6156 /* Treat this failure as linkdown for all vports */
6157 link_state = phba->link_state;
6158 lpfc_linkdown(phba);
6159 phba->link_state = link_state;
6160
6161 vports = lpfc_create_vport_work_array(phba);
6162
6163 if (vports) {
6164 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6165 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6166 if (ndlp)
6167 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6168 lpfc_els_flush_cmd(vports[i]);
6169 }
6170 lpfc_destroy_vport_work_array(phba, vports);
6171 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006172}
6173
6174/**
6175 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6176 * @phba: pointer to lpfc hba data structure.
6177 *
6178 * This routine abort all pending discovery commands and
6179 * start a timer to retry FLOGI for the physical port
6180 * discovery.
6181 **/
6182void
6183lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6184{
6185 struct lpfc_nodelist *ndlp;
6186 struct Scsi_Host *shost;
6187
6188 /* Cancel the all vports retry delay retry timers */
6189 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006190
6191 /* If fabric require FLOGI, then re-instantiate physical login */
6192 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6193 if (!ndlp)
6194 return;
6195
James Smart695a8142010-01-26 23:08:03 -05006196 shost = lpfc_shost_from_vport(phba->pport);
6197 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6198 spin_lock_irq(shost->host_lock);
6199 ndlp->nlp_flag |= NLP_DELAY_TMO;
6200 spin_unlock_irq(shost->host_lock);
6201 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6202 phba->pport->port_state = LPFC_FLOGI;
6203 return;
6204}
6205
6206/**
6207 * lpfc_fabric_login_reqd - Check if FLOGI required.
6208 * @phba: pointer to lpfc hba data structure.
6209 * @cmdiocb: pointer to FDISC command iocb.
6210 * @rspiocb: pointer to FDISC response iocb.
6211 *
6212 * This routine checks if a FLOGI is reguired for FDISC
6213 * to succeed.
6214 **/
6215static int
6216lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6217 struct lpfc_iocbq *cmdiocb,
6218 struct lpfc_iocbq *rspiocb)
6219{
6220
6221 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6222 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6223 return 0;
6224 else
6225 return 1;
6226}
6227
6228/**
James Smart3621a712009-04-06 18:47:14 -04006229 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006230 * @phba: pointer to lpfc hba data structure.
6231 * @cmdiocb: pointer to lpfc command iocb data structure.
6232 * @rspiocb: pointer to lpfc response iocb data structure.
6233 *
6234 * This routine is the completion callback function to a Fabric Discover
6235 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6236 * single threaded, each FDISC completion callback function will reset
6237 * the discovery timer for all vports such that the timers will not get
6238 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6239 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6240 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6241 * assigned to the vport has been changed with the completion of the FDISC
6242 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6243 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6244 * routine is invoked to register new vport with the HBA. Otherwise, the
6245 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6246 * Server for State Change Request (SCR).
6247 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006248static void
6249lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6250 struct lpfc_iocbq *rspiocb)
6251{
6252 struct lpfc_vport *vport = cmdiocb->vport;
6253 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6254 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6255 struct lpfc_nodelist *np;
6256 struct lpfc_nodelist *next_np;
6257 IOCB_t *irsp = &rspiocb->iocb;
6258 struct lpfc_iocbq *piocb;
6259
James Smarte8b62012007-08-02 11:10:09 -04006260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6261 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6262 irsp->ulpStatus, irsp->un.ulpWord[4],
6263 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006264 /* Since all FDISCs are being single threaded, we
6265 * must reset the discovery timer for ALL vports
6266 * waiting to send FDISC when one completes.
6267 */
6268 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6269 lpfc_set_disctmo(piocb->vport);
6270 }
6271
James Smart858c9f62007-06-17 19:56:39 -05006272 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6273 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6274 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6275
James Smart92d7f7b2007-06-17 19:56:38 -05006276 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006277
6278 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6279 lpfc_retry_pport_discovery(phba);
6280 goto out;
6281 }
6282
James Smart92d7f7b2007-06-17 19:56:38 -05006283 /* Check for retry */
6284 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6285 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006286 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006287 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006288 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006289 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006290 goto fdisc_failed;
6291 }
James Smartd7c255b2008-08-24 21:50:00 -04006292 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006293 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006294 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006295 vport->fc_flag |= FC_FABRIC;
6296 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6297 vport->fc_flag |= FC_PUBLIC_LOOP;
6298 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006299
James Smartd7c255b2008-08-24 21:50:00 -04006300 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6301 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6302 if ((vport->fc_prevDID != vport->fc_myDID) &&
6303 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6304 /* If our NportID changed, we need to ensure all
6305 * remaining NPORTs get unreg_login'ed so we can
6306 * issue unreg_vpi.
6307 */
6308 list_for_each_entry_safe(np, next_np,
6309 &vport->fc_nodes, nlp_listp) {
6310 if (!NLP_CHK_NODE_ACT(ndlp) ||
6311 (np->nlp_state != NLP_STE_NPR_NODE) ||
6312 !(np->nlp_flag & NLP_NPR_ADISC))
6313 continue;
James Smart09372822008-01-11 01:52:54 -05006314 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006315 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006316 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006317 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006318 }
James Smartd7c255b2008-08-24 21:50:00 -04006319 lpfc_mbx_unreg_vpi(vport);
6320 spin_lock_irq(shost->host_lock);
6321 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006322 if (phba->sli_rev == LPFC_SLI_REV4)
6323 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006324 else
6325 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006326 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006327 }
6328
James Smartecfd03c2010-02-12 14:41:27 -05006329 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6330 lpfc_issue_init_vpi(vport);
6331 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006332 lpfc_register_new_vport(phba, vport, ndlp);
6333 else
6334 lpfc_do_scr_ns_plogi(phba, vport);
6335 goto out;
6336fdisc_failed:
6337 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6338 /* Cancel discovery timer */
6339 lpfc_can_disctmo(vport);
6340 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006341out:
6342 lpfc_els_free_iocb(phba, cmdiocb);
6343}
6344
James Smarte59058c2008-08-24 21:49:00 -04006345/**
James Smart3621a712009-04-06 18:47:14 -04006346 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006347 * @vport: pointer to a virtual N_Port data structure.
6348 * @ndlp: pointer to a node-list data structure.
6349 * @retry: number of retries to the command IOCB.
6350 *
6351 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6352 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6353 * routine to issue the IOCB, which makes sure only one outstanding fabric
6354 * IOCB will be sent off HBA at any given time.
6355 *
6356 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6357 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6358 * will be stored into the context1 field of the IOCB for the completion
6359 * callback function to the FDISC ELS command.
6360 *
6361 * Return code
6362 * 0 - Successfully issued fdisc iocb command
6363 * 1 - Failed to issue fdisc iocb command
6364 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006365static int
James Smart92d7f7b2007-06-17 19:56:38 -05006366lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6367 uint8_t retry)
6368{
6369 struct lpfc_hba *phba = vport->phba;
6370 IOCB_t *icmd;
6371 struct lpfc_iocbq *elsiocb;
6372 struct serv_parm *sp;
6373 uint8_t *pcmd;
6374 uint16_t cmdsize;
6375 int did = ndlp->nlp_DID;
6376 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006377
James Smart5ffc2662009-11-18 15:39:44 -05006378 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006379 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6380 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6381 ELS_CMD_FDISC);
6382 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006383 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006384 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6385 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006386 return 1;
6387 }
6388
6389 icmd = &elsiocb->iocb;
6390 icmd->un.elsreq64.myID = 0;
6391 icmd->un.elsreq64.fl = 1;
6392
James Smartf1126682009-06-10 17:22:44 -04006393 if (phba->sli_rev == LPFC_SLI_REV4) {
6394 /* FDISC needs to be 1 for WQE VPI */
6395 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6396 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6397 /* Set the ulpContext to the vpi */
6398 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6399 } else {
6400 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6401 icmd->ulpCt_h = 1;
6402 icmd->ulpCt_l = 0;
6403 }
James Smart92d7f7b2007-06-17 19:56:38 -05006404
6405 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6406 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6407 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6408 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6409 sp = (struct serv_parm *) pcmd;
6410 /* Setup CSPs accordingly for Fabric */
6411 sp->cmn.e_d_tov = 0;
6412 sp->cmn.w2.r_a_tov = 0;
6413 sp->cls1.classValid = 0;
6414 sp->cls2.seqDelivery = 1;
6415 sp->cls3.seqDelivery = 1;
6416
6417 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6418 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6419 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6420 pcmd += sizeof(uint32_t); /* Port Name */
6421 memcpy(pcmd, &vport->fc_portname, 8);
6422 pcmd += sizeof(uint32_t); /* Node Name */
6423 pcmd += sizeof(uint32_t); /* Node Name */
6424 memcpy(pcmd, &vport->fc_nodename, 8);
6425
6426 lpfc_set_disctmo(vport);
6427
6428 phba->fc_stat.elsXmitFDISC++;
6429 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6430
James Smart858c9f62007-06-17 19:56:39 -05006431 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6432 "Issue FDISC: did:x%x",
6433 did, 0, 0);
6434
James Smart92d7f7b2007-06-17 19:56:38 -05006435 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6436 if (rc == IOCB_ERROR) {
6437 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006438 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6440 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006441 return 1;
6442 }
6443 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006444 return 0;
6445}
6446
James Smarte59058c2008-08-24 21:49:00 -04006447/**
James Smart3621a712009-04-06 18:47:14 -04006448 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006449 * @phba: pointer to lpfc hba data structure.
6450 * @cmdiocb: pointer to lpfc command iocb data structure.
6451 * @rspiocb: pointer to lpfc response iocb data structure.
6452 *
6453 * This routine is the completion callback function to the issuing of a LOGO
6454 * ELS command off a vport. It frees the command IOCB and then decrement the
6455 * reference count held on ndlp for this completion function, indicating that
6456 * the reference to the ndlp is no long needed. Note that the
6457 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6458 * callback function and an additional explicit ndlp reference decrementation
6459 * will trigger the actual release of the ndlp.
6460 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006461static void
6462lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6463 struct lpfc_iocbq *rspiocb)
6464{
6465 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006466 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006467 struct lpfc_nodelist *ndlp;
6468 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006469
6470 irsp = &rspiocb->iocb;
6471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6472 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6473 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006474
6475 lpfc_els_free_iocb(phba, cmdiocb);
6476 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006477
6478 /* Trigger the release of the ndlp after logo */
6479 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006480}
6481
James Smarte59058c2008-08-24 21:49:00 -04006482/**
James Smart3621a712009-04-06 18:47:14 -04006483 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006484 * @vport: pointer to a virtual N_Port data structure.
6485 * @ndlp: pointer to a node-list data structure.
6486 *
6487 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6488 *
6489 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6490 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6491 * will be stored into the context1 field of the IOCB for the completion
6492 * callback function to the LOGO ELS command.
6493 *
6494 * Return codes
6495 * 0 - Successfully issued logo off the @vport
6496 * 1 - Failed to issue logo off the @vport
6497 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006498int
6499lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6500{
6501 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6502 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006503 IOCB_t *icmd;
6504 struct lpfc_iocbq *elsiocb;
6505 uint8_t *pcmd;
6506 uint16_t cmdsize;
6507
6508 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6509 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6510 ELS_CMD_LOGO);
6511 if (!elsiocb)
6512 return 1;
6513
6514 icmd = &elsiocb->iocb;
6515 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6516 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6517 pcmd += sizeof(uint32_t);
6518
6519 /* Fill in LOGO payload */
6520 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6521 pcmd += sizeof(uint32_t);
6522 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6523
James Smart858c9f62007-06-17 19:56:39 -05006524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6525 "Issue LOGO npiv did:x%x flg:x%x",
6526 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6527
James Smart92d7f7b2007-06-17 19:56:38 -05006528 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6529 spin_lock_irq(shost->host_lock);
6530 ndlp->nlp_flag |= NLP_LOGO_SND;
6531 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006532 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6533 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006534 spin_lock_irq(shost->host_lock);
6535 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6536 spin_unlock_irq(shost->host_lock);
6537 lpfc_els_free_iocb(phba, elsiocb);
6538 return 1;
6539 }
6540 return 0;
6541}
6542
James Smarte59058c2008-08-24 21:49:00 -04006543/**
James Smart3621a712009-04-06 18:47:14 -04006544 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006545 * @ptr: holder for the timer function associated data.
6546 *
6547 * This routine is invoked by the fabric iocb block timer after
6548 * timeout. It posts the fabric iocb block timeout event by setting the
6549 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6550 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6551 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6552 * posted event WORKER_FABRIC_BLOCK_TMO.
6553 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006554void
6555lpfc_fabric_block_timeout(unsigned long ptr)
6556{
6557 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6558 unsigned long iflags;
6559 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006560
James Smart92d7f7b2007-06-17 19:56:38 -05006561 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6562 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6563 if (!tmo_posted)
6564 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6565 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6566
James Smart5e9d9b82008-06-14 22:52:53 -04006567 if (!tmo_posted)
6568 lpfc_worker_wake_up(phba);
6569 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006570}
6571
James Smarte59058c2008-08-24 21:49:00 -04006572/**
James Smart3621a712009-04-06 18:47:14 -04006573 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006574 * @phba: pointer to lpfc hba data structure.
6575 *
6576 * This routine issues one fabric iocb from the driver internal list to
6577 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6578 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6579 * remove one pending fabric iocb from the driver internal list and invokes
6580 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6581 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006582static void
6583lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6584{
6585 struct lpfc_iocbq *iocb;
6586 unsigned long iflags;
6587 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006588 IOCB_t *cmd;
6589
6590repeat:
6591 iocb = NULL;
6592 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006593 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006594 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6595 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6596 list);
6597 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006598 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006599 atomic_inc(&phba->fabric_iocb_count);
6600 }
6601 spin_unlock_irqrestore(&phba->hbalock, iflags);
6602 if (iocb) {
6603 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6604 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6605 iocb->iocb_flag |= LPFC_IO_FABRIC;
6606
James Smart858c9f62007-06-17 19:56:39 -05006607 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6608 "Fabric sched1: ste:x%x",
6609 iocb->vport->port_state, 0, 0);
6610
James Smart3772a992009-05-22 14:50:54 -04006611 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006612
6613 if (ret == IOCB_ERROR) {
6614 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6615 iocb->fabric_iocb_cmpl = NULL;
6616 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6617 cmd = &iocb->iocb;
6618 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6619 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6620 iocb->iocb_cmpl(phba, iocb, iocb);
6621
6622 atomic_dec(&phba->fabric_iocb_count);
6623 goto repeat;
6624 }
6625 }
6626
6627 return;
6628}
6629
James Smarte59058c2008-08-24 21:49:00 -04006630/**
James Smart3621a712009-04-06 18:47:14 -04006631 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006632 * @phba: pointer to lpfc hba data structure.
6633 *
6634 * This routine unblocks the issuing fabric iocb command. The function
6635 * will clear the fabric iocb block bit and then invoke the routine
6636 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6637 * from the driver internal fabric iocb list.
6638 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006639void
6640lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6641{
6642 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6643
6644 lpfc_resume_fabric_iocbs(phba);
6645 return;
6646}
6647
James Smarte59058c2008-08-24 21:49:00 -04006648/**
James Smart3621a712009-04-06 18:47:14 -04006649 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006650 * @phba: pointer to lpfc hba data structure.
6651 *
6652 * This routine blocks the issuing fabric iocb for a specified amount of
6653 * time (currently 100 ms). This is done by set the fabric iocb block bit
6654 * and set up a timeout timer for 100ms. When the block bit is set, no more
6655 * fabric iocb will be issued out of the HBA.
6656 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006657static void
6658lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6659{
6660 int blocked;
6661
6662 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006663 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006664 if (!blocked)
6665 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6666
6667 return;
6668}
6669
James Smarte59058c2008-08-24 21:49:00 -04006670/**
James Smart3621a712009-04-06 18:47:14 -04006671 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006672 * @phba: pointer to lpfc hba data structure.
6673 * @cmdiocb: pointer to lpfc command iocb data structure.
6674 * @rspiocb: pointer to lpfc response iocb data structure.
6675 *
6676 * This routine is the callback function that is put to the fabric iocb's
6677 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6678 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6679 * function first restores and invokes the original iocb's callback function
6680 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6681 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6682 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006683static void
6684lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6685 struct lpfc_iocbq *rspiocb)
6686{
6687 struct ls_rjt stat;
6688
6689 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6690 BUG();
6691
6692 switch (rspiocb->iocb.ulpStatus) {
6693 case IOSTAT_NPORT_RJT:
6694 case IOSTAT_FABRIC_RJT:
6695 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6696 lpfc_block_fabric_iocbs(phba);
6697 }
6698 break;
6699
6700 case IOSTAT_NPORT_BSY:
6701 case IOSTAT_FABRIC_BSY:
6702 lpfc_block_fabric_iocbs(phba);
6703 break;
6704
6705 case IOSTAT_LS_RJT:
6706 stat.un.lsRjtError =
6707 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6708 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6709 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6710 lpfc_block_fabric_iocbs(phba);
6711 break;
6712 }
6713
6714 if (atomic_read(&phba->fabric_iocb_count) == 0)
6715 BUG();
6716
6717 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6718 cmdiocb->fabric_iocb_cmpl = NULL;
6719 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6720 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6721
6722 atomic_dec(&phba->fabric_iocb_count);
6723 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006724 /* Post any pending iocbs to HBA */
6725 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006726 }
6727}
6728
James Smarte59058c2008-08-24 21:49:00 -04006729/**
James Smart3621a712009-04-06 18:47:14 -04006730 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006731 * @phba: pointer to lpfc hba data structure.
6732 * @iocb: pointer to lpfc command iocb data structure.
6733 *
6734 * This routine is used as the top-level API for issuing a fabric iocb command
6735 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6736 * function makes sure that only one fabric bound iocb will be outstanding at
6737 * any given time. As such, this function will first check to see whether there
6738 * is already an outstanding fabric iocb on the wire. If so, it will put the
6739 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6740 * issued later. Otherwise, it will issue the iocb on the wire and update the
6741 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6742 *
6743 * Note, this implementation has a potential sending out fabric IOCBs out of
6744 * order. The problem is caused by the construction of the "ready" boolen does
6745 * not include the condition that the internal fabric IOCB list is empty. As
6746 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6747 * ahead of the fabric IOCBs in the internal list.
6748 *
6749 * Return code
6750 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6751 * IOCB_ERROR - failed to issue fabric iocb
6752 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006753static int
James Smart92d7f7b2007-06-17 19:56:38 -05006754lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6755{
6756 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006757 int ready;
6758 int ret;
6759
6760 if (atomic_read(&phba->fabric_iocb_count) > 1)
6761 BUG();
6762
6763 spin_lock_irqsave(&phba->hbalock, iflags);
6764 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6765 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6766
James Smart7f5f3d02008-02-08 18:50:14 -05006767 if (ready)
6768 /* Increment fabric iocb count to hold the position */
6769 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006770 spin_unlock_irqrestore(&phba->hbalock, iflags);
6771 if (ready) {
6772 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6773 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6774 iocb->iocb_flag |= LPFC_IO_FABRIC;
6775
James Smart858c9f62007-06-17 19:56:39 -05006776 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6777 "Fabric sched2: ste:x%x",
6778 iocb->vport->port_state, 0, 0);
6779
James Smart3772a992009-05-22 14:50:54 -04006780 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006781
6782 if (ret == IOCB_ERROR) {
6783 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6784 iocb->fabric_iocb_cmpl = NULL;
6785 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6786 atomic_dec(&phba->fabric_iocb_count);
6787 }
6788 } else {
6789 spin_lock_irqsave(&phba->hbalock, iflags);
6790 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6791 spin_unlock_irqrestore(&phba->hbalock, iflags);
6792 ret = IOCB_SUCCESS;
6793 }
6794 return ret;
6795}
6796
James Smarte59058c2008-08-24 21:49:00 -04006797/**
James Smart3621a712009-04-06 18:47:14 -04006798 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006799 * @vport: pointer to a virtual N_Port data structure.
6800 *
6801 * This routine aborts all the IOCBs associated with a @vport from the
6802 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6803 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6804 * list, removes each IOCB associated with the @vport off the list, set the
6805 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6806 * associated with the IOCB.
6807 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006808static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006809{
6810 LIST_HEAD(completions);
6811 struct lpfc_hba *phba = vport->phba;
6812 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006813
6814 spin_lock_irq(&phba->hbalock);
6815 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6816 list) {
6817
6818 if (piocb->vport != vport)
6819 continue;
6820
6821 list_move_tail(&piocb->list, &completions);
6822 }
6823 spin_unlock_irq(&phba->hbalock);
6824
James Smarta257bf92009-04-06 18:48:10 -04006825 /* Cancel all the IOCBs from the completions list */
6826 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6827 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006828}
6829
James Smarte59058c2008-08-24 21:49:00 -04006830/**
James Smart3621a712009-04-06 18:47:14 -04006831 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006832 * @ndlp: pointer to a node-list data structure.
6833 *
6834 * This routine aborts all the IOCBs associated with an @ndlp from the
6835 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6836 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6837 * list, removes each IOCB associated with the @ndlp off the list, set the
6838 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6839 * associated with the IOCB.
6840 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006841void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6842{
6843 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006844 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006845 struct lpfc_iocbq *tmp_iocb, *piocb;
6846 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006847
6848 spin_lock_irq(&phba->hbalock);
6849 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6850 list) {
6851 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6852
6853 list_move_tail(&piocb->list, &completions);
6854 }
6855 }
6856 spin_unlock_irq(&phba->hbalock);
6857
James Smarta257bf92009-04-06 18:48:10 -04006858 /* Cancel all the IOCBs from the completions list */
6859 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6860 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006861}
6862
James Smarte59058c2008-08-24 21:49:00 -04006863/**
James Smart3621a712009-04-06 18:47:14 -04006864 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006865 * @phba: pointer to lpfc hba data structure.
6866 *
6867 * This routine aborts all the IOCBs currently on the driver internal
6868 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6869 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6870 * list, removes IOCBs off the list, set the status feild to
6871 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6872 * the IOCB.
6873 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006874void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6875{
6876 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006877
6878 spin_lock_irq(&phba->hbalock);
6879 list_splice_init(&phba->fabric_iocb_list, &completions);
6880 spin_unlock_irq(&phba->hbalock);
6881
James Smarta257bf92009-04-06 18:48:10 -04006882 /* Cancel all the IOCBs from the completions list */
6883 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6884 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006885}
James Smart6fb120a2009-05-22 14:52:59 -04006886
6887/**
6888 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6889 * @phba: pointer to lpfc hba data structure.
6890 * @axri: pointer to the els xri abort wcqe structure.
6891 *
6892 * This routine is invoked by the worker thread to process a SLI4 slow-path
6893 * ELS aborted xri.
6894 **/
6895void
6896lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6897 struct sli4_wcqe_xri_aborted *axri)
6898{
6899 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6900 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6901 unsigned long iflag = 0;
6902
James Smart0f65ff62010-02-26 14:14:23 -05006903 spin_lock_irqsave(&phba->hbalock, iflag);
6904 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006905 list_for_each_entry_safe(sglq_entry, sglq_next,
6906 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6907 if (sglq_entry->sli4_xritag == xri) {
6908 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006909 list_add_tail(&sglq_entry->list,
6910 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05006911 sglq_entry->state = SGL_FREED;
6912 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006913 spin_unlock_irqrestore(&phba->hbalock, iflag);
6914 return;
6915 }
6916 }
James Smart0f65ff62010-02-26 14:14:23 -05006917 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6918 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6919 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6920 spin_unlock_irqrestore(&phba->hbalock, iflag);
6921 return;
6922 }
6923 sglq_entry->state = SGL_XRI_ABORTED;
6924 spin_unlock_irqrestore(&phba->hbalock, iflag);
6925 return;
James Smart6fb120a2009-05-22 14:52:59 -04006926}