blob: 0a337dab211c3cc49c77c8abaabe2e48016f6d42 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
182 break;
183 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 }
James Smart0c287582009-06-10 17:22:56 -0400192 else
James Smartc8685952009-11-18 15:39:16 -0500193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400194
dea31012005-04-17 16:05:31 -0500195 icmd = &elsiocb->iocb;
196
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 if (pcmd)
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500204
205 INIT_LIST_HEAD(&pcmd->list);
206
207 /* Allocate buffer for response payload */
208 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500210 if (prsp)
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500215 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500216 } else
dea31012005-04-17 16:05:31 -0500217 prsp = NULL;
dea31012005-04-17 16:05:31 -0500218
219 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500221 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500226
227 INIT_LIST_HEAD(&pbuflist->list);
228
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500232 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400236 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500237 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 }
dea31012005-04-17 16:05:31 -0500241 icmd->ulpBdeCount = 1;
242 icmd->ulpLe = 1;
243 icmd->ulpClass = CLASS3;
244
James Smart92d7f7b2007-06-17 19:56:38 -0500245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
247
248 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400249 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 else
255 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500256 }
257
dea31012005-04-17 16:05:31 -0500258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264
265 if (expectRsp) {
266 bpl++;
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
272 }
273
James Smartfa4066b2008-01-11 01:53:27 -0500274 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400275 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500280 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500281 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
283
284 if (prsp) {
285 list_add(&prsp->list, &pcmd->list);
286 }
dea31012005-04-17 16:05:31 -0500287 if (expectRsp) {
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
293 vport->port_state);
dea31012005-04-17 16:05:31 -0500294 } else {
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
300 cmdSize);
dea31012005-04-17 16:05:31 -0500301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return elsiocb;
dea31012005-04-17 16:05:31 -0500303
James Smartfa4066b2008-01-11 01:53:27 -0500304els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500305 if (expectRsp)
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500307 kfree(pbuflist);
308
309els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
311 kfree(prsp);
312
313els_iocb_free_pcmb_exit:
314 kfree(pcmd);
315 lpfc_sli_release_iocbq(phba, elsiocb);
316 return NULL;
317}
dea31012005-04-17 16:05:31 -0500318
James Smarte59058c2008-08-24 21:49:00 -0400319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400321 * @vport: pointer to a host virtual N_Port data structure.
322 *
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
329 * with the @vport.
330 *
331 * Return code
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
334 **/
James Smart3772a992009-05-22 14:50:54 -0400335int
James Smart92d7f7b2007-06-17 19:56:38 -0500336lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337{
338 struct lpfc_hba *phba = vport->phba;
339 LPFC_MBOXQ_t *mbox;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
343 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400344 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400349 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500350 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400354 if (!mbox) {
355 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500356 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400357 }
James Smart92d7f7b2007-06-17 19:56:38 -0500358
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 mbox->vport = vport;
363
James Smart0b727fe2007-10-27 13:37:25 -0400364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400365 if (rc == MBX_NOT_FINISHED) {
366 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400371 if (!mbox) {
372 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400374 }
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400376 if (rc) {
377 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
385 */
James Smart92d7f7b2007-06-17 19:56:38 -0500386 mbox->context2 = lpfc_nlp_get(ndlp);
387
James Smart0b727fe2007-10-27 13:37:25 -0400388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400389 if (rc == MBX_NOT_FINISHED) {
390 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500391 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400392 }
James Smart92d7f7b2007-06-17 19:56:38 -0500393
394 return 0;
395
396fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
399 */
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_put(ndlp);
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
403 kfree(mp);
404fail_free_mbox:
405 mempool_free(mbox, phba->mbox_mem_pool);
406
407fail:
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return -ENXIO;
412}
413
James Smarte59058c2008-08-24 21:49:00 -0400414/**
James Smart6fb120a2009-05-22 14:52:59 -0400415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
417 *
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
420 *
421 * Return code
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
424 **/
425static int
426lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427{
428 struct lpfc_hba *phba = vport->phba;
429 LPFC_MBOXQ_t *mboxq;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
433 int rc = 0;
434
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
438 rc = -ENODEV;
439 goto fail;
440 }
441
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
443 if (!dmabuf) {
444 rc = -ENOMEM;
445 goto fail;
446 }
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
448 if (!dmabuf->virt) {
449 rc = -ENOMEM;
450 goto fail_free_dmabuf;
451 }
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
453 if (!mboxq) {
454 rc = -ENOMEM;
455 goto fail_free_coherent;
456 }
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
465 rc = -ENXIO;
466 goto fail_free_mbox;
467 }
468 return 0;
469
470fail_free_mbox:
471 mempool_free(mboxq, phba->mbox_mem_pool);
472fail_free_coherent:
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
474fail_free_dmabuf:
475 kfree(dmabuf);
476fail:
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
480 return rc;
481}
482
483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 *
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
499 *
500 * Return code
501 * 0 - Success (currently, always return 0)
502 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500503static int
James Smart2e0fef82007-06-17 19:56:36 -0500504lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521
522 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500526 } else {
527 /*
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
530 */
James Smart2e0fef82007-06-17 19:56:36 -0500531 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500532 }
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500535 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500536 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500537 ndlp->nlp_class_sup = 0;
538 if (sp->cls1.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS1;
540 if (sp->cls2.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS2;
542 if (sp->cls3.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS3;
544 if (sp->cls4.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS4;
546 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
547 sp->cmn.bbRcvSizeLsb;
548 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
549
James Smart92d7f7b2007-06-17 19:56:38 -0500550 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
551 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400552 lpfc_printf_vlog(vport, KERN_WARNING,
553 LOG_ELS | LOG_VPORT,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500557 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500558 } else {
559 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport, KERN_WARNING,
562 LOG_ELS | LOG_VPORT,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500565 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
566 }
567 }
568
569 if ((vport->fc_prevDID != vport->fc_myDID) &&
570 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
571
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
574 */
575 list_for_each_entry_safe(np, next_np,
576 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400577 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500578 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500579 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
580 !(np->nlp_flag & NLP_NPR_ADISC))
581 continue;
582 spin_lock_irq(shost->host_lock);
583 np->nlp_flag &= ~NLP_NPR_ADISC;
584 spin_unlock_irq(shost->host_lock);
585 lpfc_unreg_rpi(vport, np);
586 }
587 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
588 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500589 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500590 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500591 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500592 }
James Smartecfd03c2010-02-12 14:41:27 -0500593 /*
594 * If VPI is unreged, driver need to do INIT_VPI
595 * before re-registering
596 */
597 if (phba->sli_rev == LPFC_SLI_REV4) {
598 spin_lock_irq(shost->host_lock);
599 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
600 spin_unlock_irq(shost->host_lock);
601 }
James Smart92d7f7b2007-06-17 19:56:38 -0500602 }
603
James Smart6fb120a2009-05-22 14:52:59 -0400604 if (phba->sli_rev < LPFC_SLI_REV4) {
605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
606 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
607 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
608 lpfc_register_new_vport(phba, vport, ndlp);
609 else
610 lpfc_issue_fabric_reglogin(vport);
611 } else {
612 ndlp->nlp_type |= NLP_FABRIC;
613 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500614 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
615 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400616 lpfc_start_fdiscs(phba);
617 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500618 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500619 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500620 else
James Smart6fb120a2009-05-22 14:52:59 -0400621 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500622 }
dea31012005-04-17 16:05:31 -0500623 return 0;
dea31012005-04-17 16:05:31 -0500624}
James Smarte59058c2008-08-24 21:49:00 -0400625/**
James Smart3621a712009-04-06 18:47:14 -0400626 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400627 * @vport: pointer to a host virtual N_Port data structure.
628 * @ndlp: pointer to a node-list data structure.
629 * @sp: pointer to service parameter data structure.
630 *
631 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
632 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
633 * in a point-to-point topology. First, the @vport's N_Port Name is compared
634 * with the received N_Port Name: if the @vport's N_Port Name is greater than
635 * the received N_Port Name lexicographically, this node shall assign local
636 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
637 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
638 * this node shall just wait for the remote node to issue PLOGI and assign
639 * N_Port IDs.
640 *
641 * Return code
642 * 0 - Success
643 * -ENXIO - Fail
644 **/
dea31012005-04-17 16:05:31 -0500645static int
James Smart2e0fef82007-06-17 19:56:36 -0500646lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
647 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500648{
James Smart2e0fef82007-06-17 19:56:36 -0500649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
650 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500651 LPFC_MBOXQ_t *mbox;
652 int rc;
653
James Smart2e0fef82007-06-17 19:56:36 -0500654 spin_lock_irq(shost->host_lock);
655 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
656 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500657
658 phba->fc_edtov = FF_DEF_EDTOV;
659 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500660 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500661 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500662 if (rc >= 0) {
663 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_PT2PT_PLOGI;
666 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500667
668 /*
669 * N_Port ID cannot be 0, set our to LocalID the other
670 * side will be RemoteID.
671 */
672
673 /* not equal */
674 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500675 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500676
677 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
678 if (!mbox)
679 goto fail;
680
681 lpfc_config_link(phba, mbox);
682
683 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500684 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400685 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500686 if (rc == MBX_NOT_FINISHED) {
687 mempool_free(mbox, phba->mbox_mem_pool);
688 goto fail;
689 }
James Smarte47c9092008-02-08 18:49:26 -0500690 /* Decrement ndlp reference count indicating that ndlp can be
691 * safely released when other references to it are done.
692 */
James Smart329f9bc2007-04-25 09:53:01 -0400693 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500694
James Smart2e0fef82007-06-17 19:56:36 -0500695 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500696 if (!ndlp) {
697 /*
698 * Cannot find existing Fabric ndlp, so allocate a
699 * new one
700 */
701 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
702 if (!ndlp)
703 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500704 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500705 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
706 ndlp = lpfc_enable_node(vport, ndlp,
707 NLP_STE_UNUSED_NODE);
708 if(!ndlp)
709 goto fail;
dea31012005-04-17 16:05:31 -0500710 }
711
712 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500713 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500714 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500715 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500716 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500717 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
718 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500719 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500720 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500721 } else
722 /* This side will wait for the PLOGI, decrement ndlp reference
723 * count indicating that ndlp can be released when other
724 * references to it are done.
725 */
James Smart329f9bc2007-04-25 09:53:01 -0400726 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500727
James Smart09372822008-01-11 01:52:54 -0500728 /* If we are pt2pt with another NPort, force NPIV off! */
729 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
730
James Smart2e0fef82007-06-17 19:56:36 -0500731 spin_lock_irq(shost->host_lock);
732 vport->fc_flag |= FC_PT2PT;
733 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500734
735 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500736 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500737 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500738fail:
dea31012005-04-17 16:05:31 -0500739 return -ENXIO;
740}
741
James Smarte59058c2008-08-24 21:49:00 -0400742/**
James Smart3621a712009-04-06 18:47:14 -0400743 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400744 * @phba: pointer to lpfc hba data structure.
745 * @cmdiocb: pointer to lpfc command iocb data structure.
746 * @rspiocb: pointer to lpfc response iocb data structure.
747 *
748 * This routine is the top-level completion callback function for issuing
749 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
750 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
751 * retry has been made (either immediately or delayed with lpfc_els_retry()
752 * returning 1), the command IOCB will be released and function returned.
753 * If the retry attempt has been given up (possibly reach the maximum
754 * number of retries), one additional decrement of ndlp reference shall be
755 * invoked before going out after releasing the command IOCB. This will
756 * actually release the remote node (Note, lpfc_els_free_iocb() will also
757 * invoke one decrement of ndlp reference count). If no error reported in
758 * the IOCB status, the command Port ID field is used to determine whether
759 * this is a point-to-point topology or a fabric topology: if the Port ID
760 * field is assigned, it is a fabric topology; otherwise, it is a
761 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
762 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
763 * specific topology completion conditions.
764 **/
dea31012005-04-17 16:05:31 -0500765static void
James Smart329f9bc2007-04-25 09:53:01 -0400766lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
767 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500768{
James Smart2e0fef82007-06-17 19:56:36 -0500769 struct lpfc_vport *vport = cmdiocb->vport;
770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500771 IOCB_t *irsp = &rspiocb->iocb;
772 struct lpfc_nodelist *ndlp = cmdiocb->context1;
773 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
774 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500775 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500776 int rc;
777
778 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500779 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500780 /* One additional decrement on node reference count to
781 * trigger the release of the node
782 */
James Smart329f9bc2007-04-25 09:53:01 -0400783 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500784 goto out;
785 }
786
James Smart858c9f62007-06-17 19:56:39 -0500787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
788 "FLOGI cmpl: status:x%x/x%x state:x%x",
789 irsp->ulpStatus, irsp->un.ulpWord[4],
790 vport->port_state);
791
dea31012005-04-17 16:05:31 -0500792 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500793 /*
794 * In case of FIP mode, perform round robin FCF failover
795 * due to new FCF discovery
796 */
797 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
798 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
799 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
800 "2611 FLOGI failed on registered "
801 "FCF record fcf_index:%d, trying "
802 "to perform round robin failover\n",
803 phba->fcf.current_rec.fcf_indx);
804 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
805 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
806 /*
807 * Exhausted the eligible FCF record list,
808 * fail through to retry FLOGI on current
809 * FCF record.
810 */
811 lpfc_printf_log(phba, KERN_WARNING,
812 LOG_FIP | LOG_ELS,
813 "2760 FLOGI exhausted FCF "
814 "round robin failover list, "
815 "retry FLOGI on the current "
816 "registered FCF index:%d\n",
817 phba->fcf.current_rec.fcf_indx);
818 spin_lock_irq(&phba->hbalock);
819 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
820 spin_unlock_irq(&phba->hbalock);
821 } else {
822 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
823 fcf_index);
824 if (rc) {
825 lpfc_printf_log(phba, KERN_WARNING,
826 LOG_FIP | LOG_ELS,
827 "2761 FLOGI round "
828 "robin FCF failover "
829 "read FCF failed "
830 "rc:x%x, fcf_index:"
831 "%d\n", rc,
832 phba->fcf.current_rec.fcf_indx);
833 spin_lock_irq(&phba->hbalock);
834 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
835 spin_unlock_irq(&phba->hbalock);
836 } else
837 goto out;
838 }
839 }
840
dea31012005-04-17 16:05:31 -0500841 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500842 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500843 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500844
dea31012005-04-17 16:05:31 -0500845 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500846 spin_lock_irq(shost->host_lock);
847 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
848 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500849
James Smart329f9bc2007-04-25 09:53:01 -0400850 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500851 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
852 * alpa map would take too long otherwise.
853 */
854 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400855 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500856 }
857
858 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500859 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
860 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400861 irsp->ulpStatus, irsp->un.ulpWord[4],
862 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500863 goto flogifail;
864 }
James Smart695a8142010-01-26 23:08:03 -0500865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
867 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500868
869 /*
870 * The FLogI succeeded. Sync the data for the CPU before
871 * accessing it.
872 */
873 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
874
875 sp = prsp->virt + sizeof(uint32_t);
876
877 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200879 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400880 "Data: x%x x%x x%x x%x\n",
881 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
882 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500883
James Smart2e0fef82007-06-17 19:56:36 -0500884 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500885 /*
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
888 */
889 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500890 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500891 else
James Smart2e0fef82007-06-17 19:56:36 -0500892 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500893
James Smart0c9ab6f2010-02-26 14:15:57 -0500894 if (!rc) {
895 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400896 if (phba->hba_flag & HBA_FIP_SUPPORT)
897 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
898 LOG_ELS,
899 "2769 FLOGI successful on FCF "
900 "record: current_fcf_index:"
901 "x%x, terminate FCF round "
902 "robin failover process\n",
903 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500904 spin_lock_irq(&phba->hbalock);
905 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
906 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500907 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500908 }
dea31012005-04-17 16:05:31 -0500909 }
910
911flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400912 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500913
James Smart858c9f62007-06-17 19:56:39 -0500914 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500915 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500916 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500917
918 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500919 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400920 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
921 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
922 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
923 (phba->link_state != LPFC_CLEAR_LA)) {
924 /* If FLOGI failed enable link interrupt. */
925 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500926 }
dea31012005-04-17 16:05:31 -0500927out:
928 lpfc_els_free_iocb(phba, cmdiocb);
929}
930
James Smarte59058c2008-08-24 21:49:00 -0400931/**
James Smart3621a712009-04-06 18:47:14 -0400932 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400933 * @vport: pointer to a host virtual N_Port data structure.
934 * @ndlp: pointer to a node-list data structure.
935 * @retry: number of retries to the command IOCB.
936 *
937 * This routine issues a Fabric Login (FLOGI) Request ELS command
938 * for a @vport. The initiator service parameters are put into the payload
939 * of the FLOGI Request IOCB and the top-level callback function pointer
940 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
941 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
942 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
943 *
944 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
945 * will be incremented by 1 for holding the ndlp and the reference to ndlp
946 * will be stored into the context1 field of the IOCB for the completion
947 * callback function to the FLOGI ELS command.
948 *
949 * Return code
950 * 0 - successfully issued flogi iocb for @vport
951 * 1 - failed to issue flogi iocb for @vport
952 **/
dea31012005-04-17 16:05:31 -0500953static int
James Smart2e0fef82007-06-17 19:56:36 -0500954lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500955 uint8_t retry)
956{
James Smart2e0fef82007-06-17 19:56:36 -0500957 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500958 struct serv_parm *sp;
959 IOCB_t *icmd;
960 struct lpfc_iocbq *elsiocb;
961 struct lpfc_sli_ring *pring;
962 uint8_t *pcmd;
963 uint16_t cmdsize;
964 uint32_t tmo;
965 int rc;
966
967 pring = &phba->sli.ring[LPFC_ELS_RING];
968
James Smart92d7f7b2007-06-17 19:56:38 -0500969 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500970 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
971 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500972
James Smart488d1462006-03-07 15:02:37 -0500973 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500974 return 1;
dea31012005-04-17 16:05:31 -0500975
976 icmd = &elsiocb->iocb;
977 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
978
979 /* For FLOGI request, remainder of payload is service parameters */
980 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500981 pcmd += sizeof(uint32_t);
982 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500983 sp = (struct serv_parm *) pcmd;
984
985 /* Setup CSPs accordingly for Fabric */
986 sp->cmn.e_d_tov = 0;
987 sp->cmn.w2.r_a_tov = 0;
988 sp->cls1.classValid = 0;
989 sp->cls2.seqDelivery = 1;
990 sp->cls3.seqDelivery = 1;
991 if (sp->cmn.fcphLow < FC_PH3)
992 sp->cmn.fcphLow = FC_PH3;
993 if (sp->cmn.fcphHigh < FC_PH3)
994 sp->cmn.fcphHigh = FC_PH3;
995
James Smart6fb120a2009-05-22 14:52:59 -0400996 if (phba->sli_rev == LPFC_SLI_REV4) {
997 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
998 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
999 /* FLOGI needs to be 3 for WQE FCFI */
1000 /* Set the fcfi to the fcfi we registered with */
1001 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1002 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001003 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001004 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1005 icmd->ulpCt_h = 1;
1006 icmd->ulpCt_l = 0;
1007 }
1008
James Smart858c9f62007-06-17 19:56:39 -05001009 if (phba->fc_topology != TOPOLOGY_LOOP) {
1010 icmd->un.elsreq64.myID = 0;
1011 icmd->un.elsreq64.fl = 1;
1012 }
1013
dea31012005-04-17 16:05:31 -05001014 tmo = phba->fc_ratov;
1015 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001016 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001017 phba->fc_ratov = tmo;
1018
1019 phba->fc_stat.elsXmitFLOGI++;
1020 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001021
1022 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1023 "Issue FLOGI: opt:x%x",
1024 phba->sli3_options, 0, 0);
1025
James Smart92d7f7b2007-06-17 19:56:38 -05001026 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001027 if (rc == IOCB_ERROR) {
1028 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001029 return 1;
dea31012005-04-17 16:05:31 -05001030 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001031 return 0;
dea31012005-04-17 16:05:31 -05001032}
1033
James Smarte59058c2008-08-24 21:49:00 -04001034/**
James Smart3621a712009-04-06 18:47:14 -04001035 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001036 * @phba: pointer to lpfc hba data structure.
1037 *
1038 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1039 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1040 * list and issues an abort IOCB commond on each outstanding IOCB that
1041 * contains a active Fabric_DID ndlp. Note that this function is to issue
1042 * the abort IOCB command on all the outstanding IOCBs, thus when this
1043 * function returns, it does not guarantee all the IOCBs are actually aborted.
1044 *
1045 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001046 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001047 **/
dea31012005-04-17 16:05:31 -05001048int
James Smart2e0fef82007-06-17 19:56:36 -05001049lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001050{
1051 struct lpfc_sli_ring *pring;
1052 struct lpfc_iocbq *iocb, *next_iocb;
1053 struct lpfc_nodelist *ndlp;
1054 IOCB_t *icmd;
1055
1056 /* Abort outstanding I/O on NPort <nlp_DID> */
1057 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001058 "0201 Abort outstanding I/O on NPort x%x\n",
1059 Fabric_DID);
dea31012005-04-17 16:05:31 -05001060
1061 pring = &phba->sli.ring[LPFC_ELS_RING];
1062
1063 /*
1064 * Check the txcmplq for an iocb that matches the nport the driver is
1065 * searching for.
1066 */
James Smart2e0fef82007-06-17 19:56:36 -05001067 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001068 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1069 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001070 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1071 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001072 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001073 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1074 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001075 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001076 }
1077 }
James Smart2e0fef82007-06-17 19:56:36 -05001078 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001079
1080 return 0;
1081}
1082
James Smarte59058c2008-08-24 21:49:00 -04001083/**
James Smart3621a712009-04-06 18:47:14 -04001084 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001085 * @vport: pointer to a host virtual N_Port data structure.
1086 *
1087 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1088 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1089 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1090 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1091 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1092 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1093 * @vport.
1094 *
1095 * Return code
1096 * 0 - failed to issue initial flogi for @vport
1097 * 1 - successfully issued initial flogi for @vport
1098 **/
dea31012005-04-17 16:05:31 -05001099int
James Smart2e0fef82007-06-17 19:56:36 -05001100lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001101{
James Smart2e0fef82007-06-17 19:56:36 -05001102 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001103 struct lpfc_nodelist *ndlp;
1104
James Smart98c9ea52007-10-27 13:37:33 -04001105 vport->port_state = LPFC_FLOGI;
1106 lpfc_set_disctmo(vport);
1107
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001108 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001109 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001110 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001111 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001112 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1113 if (!ndlp)
1114 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001115 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001116 /* Set the node type */
1117 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001118 /* Put ndlp onto node list */
1119 lpfc_enqueue_node(vport, ndlp);
1120 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1121 /* re-setup ndlp without removing from node list */
1122 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1123 if (!ndlp)
1124 return 0;
dea31012005-04-17 16:05:31 -05001125 }
James Smart87af33f2007-10-27 13:37:43 -04001126
James Smarte47c9092008-02-08 18:49:26 -05001127 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001128 /* This decrement of reference count to node shall kick off
1129 * the release of the node.
1130 */
James Smart329f9bc2007-04-25 09:53:01 -04001131 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001132
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001133 return 1;
dea31012005-04-17 16:05:31 -05001134}
1135
James Smarte59058c2008-08-24 21:49:00 -04001136/**
James Smart3621a712009-04-06 18:47:14 -04001137 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001138 * @vport: pointer to a host virtual N_Port data structure.
1139 *
1140 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1141 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1142 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1143 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1144 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1145 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1146 * @vport.
1147 *
1148 * Return code
1149 * 0 - failed to issue initial fdisc for @vport
1150 * 1 - successfully issued initial fdisc for @vport
1151 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001152int
1153lpfc_initial_fdisc(struct lpfc_vport *vport)
1154{
1155 struct lpfc_hba *phba = vport->phba;
1156 struct lpfc_nodelist *ndlp;
1157
1158 /* First look for the Fabric ndlp */
1159 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1160 if (!ndlp) {
1161 /* Cannot find existing Fabric ndlp, so allocate a new one */
1162 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1163 if (!ndlp)
1164 return 0;
1165 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001166 /* Put ndlp onto node list */
1167 lpfc_enqueue_node(vport, ndlp);
1168 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1169 /* re-setup ndlp without removing from node list */
1170 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1171 if (!ndlp)
1172 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001173 }
James Smarte47c9092008-02-08 18:49:26 -05001174
James Smart92d7f7b2007-06-17 19:56:38 -05001175 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001176 /* decrement node reference count to trigger the release of
1177 * the node.
1178 */
James Smart92d7f7b2007-06-17 19:56:38 -05001179 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001180 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001181 }
1182 return 1;
1183}
James Smart87af33f2007-10-27 13:37:43 -04001184
James Smarte59058c2008-08-24 21:49:00 -04001185/**
James Smart3621a712009-04-06 18:47:14 -04001186 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001187 * @vport: pointer to a host virtual N_Port data structure.
1188 *
1189 * This routine checks whether there are more remaining Port Logins
1190 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1191 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1192 * to issue ELS PLOGIs up to the configured discover threads with the
1193 * @vport (@vport->cfg_discovery_threads). The function also decrement
1194 * the @vport's num_disc_node by 1 if it is not already 0.
1195 **/
James Smart87af33f2007-10-27 13:37:43 -04001196void
James Smart2e0fef82007-06-17 19:56:36 -05001197lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001198{
1199 int sentplogi;
1200
James Smart2e0fef82007-06-17 19:56:36 -05001201 if (vport->num_disc_nodes)
1202 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001203
1204 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001205 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1206 "0232 Continue discovery with %d PLOGIs to go "
1207 "Data: x%x x%x x%x\n",
1208 vport->num_disc_nodes, vport->fc_plogi_cnt,
1209 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001210 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001211 if (vport->fc_flag & FC_NLP_MORE)
1212 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1213 sentplogi = lpfc_els_disc_plogi(vport);
1214
dea31012005-04-17 16:05:31 -05001215 return;
1216}
1217
James Smarte59058c2008-08-24 21:49:00 -04001218/**
James Smart3621a712009-04-06 18:47:14 -04001219 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001220 * @phba: pointer to lpfc hba data structure.
1221 * @prsp: pointer to response IOCB payload.
1222 * @ndlp: pointer to a node-list data structure.
1223 *
1224 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1225 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1226 * The following cases are considered N_Port confirmed:
1227 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1228 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1229 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1230 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1231 * 1) if there is a node on vport list other than the @ndlp with the same
1232 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1233 * on that node to release the RPI associated with the node; 2) if there is
1234 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1235 * into, a new node shall be allocated (or activated). In either case, the
1236 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1237 * be released and the new_ndlp shall be put on to the vport node list and
1238 * its pointer returned as the confirmed node.
1239 *
1240 * Note that before the @ndlp got "released", the keepDID from not-matching
1241 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1242 * of the @ndlp. This is because the release of @ndlp is actually to put it
1243 * into an inactive state on the vport node list and the vport node list
1244 * management algorithm does not allow two node with a same DID.
1245 *
1246 * Return code
1247 * pointer to the PLOGI N_Port @ndlp
1248 **/
James Smart488d1462006-03-07 15:02:37 -05001249static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001250lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001251 struct lpfc_nodelist *ndlp)
1252{
James Smart2e0fef82007-06-17 19:56:36 -05001253 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001254 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001255 struct lpfc_rport_data *rdata;
1256 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001257 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001258 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001259 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001260
James Smart2fb9bd82006-12-02 13:33:57 -05001261 /* Fabric nodes can have the same WWPN so we don't bother searching
1262 * by WWPN. Just return the ndlp that was given to us.
1263 */
1264 if (ndlp->nlp_type & NLP_FABRIC)
1265 return ndlp;
1266
James Smart92d7f7b2007-06-17 19:56:38 -05001267 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001268 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001269
James Smart685f0bf2007-04-25 09:53:08 -04001270 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001271 * we have for that ndlp. If not, we have some work to do.
1272 */
James Smart2e0fef82007-06-17 19:56:36 -05001273 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001274
James Smarte47c9092008-02-08 18:49:26 -05001275 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001276 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001277
1278 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001279 rc = memcmp(&ndlp->nlp_portname, name,
1280 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001281 if (!rc)
1282 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001283 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1284 if (!new_ndlp)
1285 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001286 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001287 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001288 rc = memcmp(&ndlp->nlp_portname, name,
1289 sizeof(struct lpfc_name));
1290 if (!rc)
1291 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001292 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1293 NLP_STE_UNUSED_NODE);
1294 if (!new_ndlp)
1295 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001296 keepDID = new_ndlp->nlp_DID;
1297 } else
1298 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001299
James Smart2e0fef82007-06-17 19:56:36 -05001300 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001301 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001302 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001303
1304 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1305 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1306 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1307
James Smarte47c9092008-02-08 18:49:26 -05001308 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001309 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001310
James Smart2e0fef82007-06-17 19:56:36 -05001311 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001312 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1313 /* The new_ndlp is replacing ndlp totally, so we need
1314 * to put ndlp on UNUSED list and try to free it.
1315 */
James Smart0ff10d42008-01-11 01:52:36 -05001316
1317 /* Fix up the rport accordingly */
1318 rport = ndlp->rport;
1319 if (rport) {
1320 rdata = rport->dd_data;
1321 if (rdata->pnode == ndlp) {
1322 lpfc_nlp_put(ndlp);
1323 ndlp->rport = NULL;
1324 rdata->pnode = lpfc_nlp_get(new_ndlp);
1325 new_ndlp->rport = rport;
1326 }
1327 new_ndlp->nlp_type = ndlp->nlp_type;
1328 }
James Smart58da1ff2008-04-07 10:15:56 -04001329 /* We shall actually free the ndlp with both nlp_DID and
1330 * nlp_portname fields equals 0 to avoid any ndlp on the
1331 * nodelist never to be used.
1332 */
1333 if (ndlp->nlp_DID == 0) {
1334 spin_lock_irq(&phba->ndlp_lock);
1335 NLP_SET_FREE_REQ(ndlp);
1336 spin_unlock_irq(&phba->ndlp_lock);
1337 }
James Smart0ff10d42008-01-11 01:52:36 -05001338
James Smart58da1ff2008-04-07 10:15:56 -04001339 /* Two ndlps cannot have the same did on the nodelist */
1340 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001341 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001342 }
James Smart92795652006-07-06 15:50:02 -04001343 else {
James Smart2e0fef82007-06-17 19:56:36 -05001344 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001345 /* Two ndlps cannot have the same did */
1346 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001347 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001348 }
James Smart488d1462006-03-07 15:02:37 -05001349 return new_ndlp;
1350}
1351
James Smarte59058c2008-08-24 21:49:00 -04001352/**
James Smart3621a712009-04-06 18:47:14 -04001353 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001354 * @vport: pointer to a host virtual N_Port data structure.
1355 *
1356 * This routine checks whether more Registration State Change
1357 * Notifications (RSCNs) came in while the discovery state machine was in
1358 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1359 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1360 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1361 * handling the RSCNs.
1362 **/
James Smart87af33f2007-10-27 13:37:43 -04001363void
1364lpfc_end_rscn(struct lpfc_vport *vport)
1365{
1366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1367
1368 if (vport->fc_flag & FC_RSCN_MODE) {
1369 /*
1370 * Check to see if more RSCNs came in while we were
1371 * processing this one.
1372 */
1373 if (vport->fc_rscn_id_cnt ||
1374 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1375 lpfc_els_handle_rscn(vport);
1376 else {
1377 spin_lock_irq(shost->host_lock);
1378 vport->fc_flag &= ~FC_RSCN_MODE;
1379 spin_unlock_irq(shost->host_lock);
1380 }
1381 }
1382}
1383
James Smarte59058c2008-08-24 21:49:00 -04001384/**
James Smart3621a712009-04-06 18:47:14 -04001385 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001386 * @phba: pointer to lpfc hba data structure.
1387 * @cmdiocb: pointer to lpfc command iocb data structure.
1388 * @rspiocb: pointer to lpfc response iocb data structure.
1389 *
1390 * This routine is the completion callback function for issuing the Port
1391 * Login (PLOGI) command. For PLOGI completion, there must be an active
1392 * ndlp on the vport node list that matches the remote node ID from the
1393 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1394 * ignored and command IOCB released. The PLOGI response IOCB status is
1395 * checked for error conditons. If there is error status reported, PLOGI
1396 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1397 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1398 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1399 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1400 * there are additional N_Port nodes with the vport that need to perform
1401 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1402 * PLOGIs.
1403 **/
dea31012005-04-17 16:05:31 -05001404static void
James Smart2e0fef82007-06-17 19:56:36 -05001405lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1406 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001407{
James Smart2e0fef82007-06-17 19:56:36 -05001408 struct lpfc_vport *vport = cmdiocb->vport;
1409 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001410 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001411 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001412 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001413 int disc, rc, did, type;
1414
dea31012005-04-17 16:05:31 -05001415 /* we pass cmdiocb to state machine which needs rspiocb as well */
1416 cmdiocb->context_un.rsp_iocb = rspiocb;
1417
1418 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1420 "PLOGI cmpl: status:x%x/x%x did:x%x",
1421 irsp->ulpStatus, irsp->un.ulpWord[4],
1422 irsp->un.elsreq64.remoteID);
1423
James Smart2e0fef82007-06-17 19:56:36 -05001424 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001425 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001426 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1427 "0136 PLOGI completes to NPort x%x "
1428 "with no ndlp. Data: x%x x%x x%x\n",
1429 irsp->un.elsreq64.remoteID,
1430 irsp->ulpStatus, irsp->un.ulpWord[4],
1431 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001432 goto out;
James Smarted957682007-06-17 19:56:37 -05001433 }
dea31012005-04-17 16:05:31 -05001434
1435 /* Since ndlp can be freed in the disc state machine, note if this node
1436 * is being used during discovery.
1437 */
James Smart2e0fef82007-06-17 19:56:36 -05001438 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001439 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001440 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001441 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001442 rc = 0;
1443
1444 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001445 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1446 "0102 PLOGI completes to NPort x%x "
1447 "Data: x%x x%x x%x x%x x%x\n",
1448 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1449 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001450 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001451 if (lpfc_els_chk_latt(vport)) {
1452 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001453 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001454 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001455 goto out;
1456 }
1457
1458 /* ndlp could be freed in DSM, save these values now */
1459 type = ndlp->nlp_type;
1460 did = ndlp->nlp_DID;
1461
1462 if (irsp->ulpStatus) {
1463 /* Check for retry */
1464 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1465 /* ELS command is being retried */
1466 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001467 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001468 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001469 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001470 }
1471 goto out;
1472 }
dea31012005-04-17 16:05:31 -05001473 /* PLOGI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001474 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1475 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1476 ndlp->nlp_DID, irsp->ulpStatus,
1477 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001478 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001479 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001480 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001481 else
James Smart2e0fef82007-06-17 19:56:36 -05001482 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001483 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001484 } else {
1485 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001486 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001487 cmdiocb->context2)->list.next,
1488 struct lpfc_dmabuf, list);
1489 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001490 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001491 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001492 }
1493
James Smart2e0fef82007-06-17 19:56:36 -05001494 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001495 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001496 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001497
James Smart2e0fef82007-06-17 19:56:36 -05001498 if (vport->num_disc_nodes == 0) {
1499 spin_lock_irq(shost->host_lock);
1500 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1501 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001502
James Smart2e0fef82007-06-17 19:56:36 -05001503 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001504 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001505 }
1506 }
1507
1508out:
1509 lpfc_els_free_iocb(phba, cmdiocb);
1510 return;
1511}
1512
James Smarte59058c2008-08-24 21:49:00 -04001513/**
James Smart3621a712009-04-06 18:47:14 -04001514 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001515 * @vport: pointer to a host virtual N_Port data structure.
1516 * @did: destination port identifier.
1517 * @retry: number of retries to the command IOCB.
1518 *
1519 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1520 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1521 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1522 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1523 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1524 *
1525 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1526 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1527 * will be stored into the context1 field of the IOCB for the completion
1528 * callback function to the PLOGI ELS command.
1529 *
1530 * Return code
1531 * 0 - Successfully issued a plogi for @vport
1532 * 1 - failed to issue a plogi for @vport
1533 **/
dea31012005-04-17 16:05:31 -05001534int
James Smart2e0fef82007-06-17 19:56:36 -05001535lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001536{
James Smart2e0fef82007-06-17 19:56:36 -05001537 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001538 struct serv_parm *sp;
1539 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001540 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001541 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001542 struct lpfc_sli *psli;
1543 uint8_t *pcmd;
1544 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001545 int ret;
dea31012005-04-17 16:05:31 -05001546
1547 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001548
James Smart98c9ea52007-10-27 13:37:33 -04001549 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001550 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1551 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001552
James Smarte47c9092008-02-08 18:49:26 -05001553 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001554 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001555 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001556 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001557 if (!elsiocb)
1558 return 1;
dea31012005-04-17 16:05:31 -05001559
1560 icmd = &elsiocb->iocb;
1561 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1562
1563 /* For PLOGI request, remainder of payload is service parameters */
1564 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001565 pcmd += sizeof(uint32_t);
1566 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001567 sp = (struct serv_parm *) pcmd;
1568
1569 if (sp->cmn.fcphLow < FC_PH_4_3)
1570 sp->cmn.fcphLow = FC_PH_4_3;
1571
1572 if (sp->cmn.fcphHigh < FC_PH3)
1573 sp->cmn.fcphHigh = FC_PH3;
1574
James Smart858c9f62007-06-17 19:56:39 -05001575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1576 "Issue PLOGI: did:x%x",
1577 did, 0, 0);
1578
dea31012005-04-17 16:05:31 -05001579 phba->fc_stat.elsXmitPLOGI++;
1580 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001581 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001582
1583 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001584 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001585 return 1;
dea31012005-04-17 16:05:31 -05001586 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001587 return 0;
dea31012005-04-17 16:05:31 -05001588}
1589
James Smarte59058c2008-08-24 21:49:00 -04001590/**
James Smart3621a712009-04-06 18:47:14 -04001591 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001592 * @phba: pointer to lpfc hba data structure.
1593 * @cmdiocb: pointer to lpfc command iocb data structure.
1594 * @rspiocb: pointer to lpfc response iocb data structure.
1595 *
1596 * This routine is the completion callback function for a Process Login
1597 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1598 * status. If there is error status reported, PRLI retry shall be attempted
1599 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1600 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1601 * ndlp to mark the PRLI completion.
1602 **/
dea31012005-04-17 16:05:31 -05001603static void
James Smart2e0fef82007-06-17 19:56:36 -05001604lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1605 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001606{
James Smart2e0fef82007-06-17 19:56:36 -05001607 struct lpfc_vport *vport = cmdiocb->vport;
1608 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001609 IOCB_t *irsp;
1610 struct lpfc_sli *psli;
1611 struct lpfc_nodelist *ndlp;
1612
1613 psli = &phba->sli;
1614 /* we pass cmdiocb to state machine which needs rspiocb as well */
1615 cmdiocb->context_un.rsp_iocb = rspiocb;
1616
1617 irsp = &(rspiocb->iocb);
1618 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001619 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001620 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001621 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001622
James Smart858c9f62007-06-17 19:56:39 -05001623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1624 "PRLI cmpl: status:x%x/x%x did:x%x",
1625 irsp->ulpStatus, irsp->un.ulpWord[4],
1626 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001627 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001628 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1629 "0103 PRLI completes to NPort x%x "
1630 "Data: x%x x%x x%x x%x\n",
1631 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1632 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001633
James Smart2e0fef82007-06-17 19:56:36 -05001634 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001635 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001636 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001637 goto out;
1638
1639 if (irsp->ulpStatus) {
1640 /* Check for retry */
1641 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1642 /* ELS command is being retried */
1643 goto out;
1644 }
1645 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001646 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1647 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1648 ndlp->nlp_DID, irsp->ulpStatus,
1649 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001650 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001651 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001652 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001653 else
James Smart2e0fef82007-06-17 19:56:36 -05001654 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001655 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001656 } else
dea31012005-04-17 16:05:31 -05001657 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001658 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001659 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001660out:
1661 lpfc_els_free_iocb(phba, cmdiocb);
1662 return;
1663}
1664
James Smarte59058c2008-08-24 21:49:00 -04001665/**
James Smart3621a712009-04-06 18:47:14 -04001666 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001667 * @vport: pointer to a host virtual N_Port data structure.
1668 * @ndlp: pointer to a node-list data structure.
1669 * @retry: number of retries to the command IOCB.
1670 *
1671 * This routine issues a Process Login (PRLI) ELS command for the
1672 * @vport. The PRLI service parameters are set up in the payload of the
1673 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1674 * is put to the IOCB completion callback func field before invoking the
1675 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1676 *
1677 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1678 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1679 * will be stored into the context1 field of the IOCB for the completion
1680 * callback function to the PRLI ELS command.
1681 *
1682 * Return code
1683 * 0 - successfully issued prli iocb command for @vport
1684 * 1 - failed to issue prli iocb command for @vport
1685 **/
dea31012005-04-17 16:05:31 -05001686int
James Smart2e0fef82007-06-17 19:56:36 -05001687lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001688 uint8_t retry)
1689{
James Smart2e0fef82007-06-17 19:56:36 -05001690 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1691 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001692 PRLI *npr;
1693 IOCB_t *icmd;
1694 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001695 uint8_t *pcmd;
1696 uint16_t cmdsize;
1697
James Smart92d7f7b2007-06-17 19:56:38 -05001698 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001699 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1700 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001701 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001702 return 1;
dea31012005-04-17 16:05:31 -05001703
1704 icmd = &elsiocb->iocb;
1705 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1706
1707 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001708 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001709 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001710 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001711
1712 /* For PRLI, remainder of payload is PRLI parameter page */
1713 npr = (PRLI *) pcmd;
1714 /*
1715 * If our firmware version is 3.20 or later,
1716 * set the following bits for FC-TAPE support.
1717 */
1718 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1719 npr->ConfmComplAllowed = 1;
1720 npr->Retry = 1;
1721 npr->TaskRetryIdReq = 1;
1722 }
1723 npr->estabImagePair = 1;
1724 npr->readXferRdyDis = 1;
1725
1726 /* For FCP support */
1727 npr->prliType = PRLI_FCP_TYPE;
1728 npr->initiatorFunc = 1;
1729
James Smart858c9f62007-06-17 19:56:39 -05001730 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1731 "Issue PRLI: did:x%x",
1732 ndlp->nlp_DID, 0, 0);
1733
dea31012005-04-17 16:05:31 -05001734 phba->fc_stat.elsXmitPRLI++;
1735 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001736 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001737 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001738 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001739 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1740 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001741 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001742 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001743 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001744 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001745 return 1;
dea31012005-04-17 16:05:31 -05001746 }
James Smart2e0fef82007-06-17 19:56:36 -05001747 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001748 return 0;
dea31012005-04-17 16:05:31 -05001749}
1750
James Smarte59058c2008-08-24 21:49:00 -04001751/**
James Smart3621a712009-04-06 18:47:14 -04001752 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001753 * @vport: pointer to a host virtual N_Port data structure.
1754 *
1755 * This routine performs Registration State Change Notification (RSCN)
1756 * discovery for a @vport. If the @vport's node port recovery count is not
1757 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1758 * the nodes that need recovery. If none of the PLOGI were needed through
1759 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1760 * invoked to check and handle possible more RSCN came in during the period
1761 * of processing the current ones.
1762 **/
1763static void
1764lpfc_rscn_disc(struct lpfc_vport *vport)
1765{
1766 lpfc_can_disctmo(vport);
1767
1768 /* RSCN discovery */
1769 /* go thru NPR nodes and issue ELS PLOGIs */
1770 if (vport->fc_npr_cnt)
1771 if (lpfc_els_disc_plogi(vport))
1772 return;
1773
1774 lpfc_end_rscn(vport);
1775}
1776
1777/**
James Smart3621a712009-04-06 18:47:14 -04001778 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001779 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1780 *
1781 * This function is called when the final ADISC is completed during discovery.
1782 * This function handles clearing link attention or issuing reg_vpi depending
1783 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1784 * discovery.
1785 * This function is called with no locks held.
1786 **/
1787static void
1788lpfc_adisc_done(struct lpfc_vport *vport)
1789{
1790 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1791 struct lpfc_hba *phba = vport->phba;
1792
1793 /*
1794 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1795 * and continue discovery.
1796 */
1797 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001798 !(vport->fc_flag & FC_RSCN_MODE) &&
1799 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001800 lpfc_issue_reg_vpi(phba, vport);
1801 return;
1802 }
1803 /*
1804 * For SLI2, we need to set port_state to READY
1805 * and continue discovery.
1806 */
1807 if (vport->port_state < LPFC_VPORT_READY) {
1808 /* If we get here, there is nothing to ADISC */
1809 if (vport->port_type == LPFC_PHYSICAL_PORT)
1810 lpfc_issue_clear_la(phba, vport);
1811 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1812 vport->num_disc_nodes = 0;
1813 /* go thru NPR list, issue ELS PLOGIs */
1814 if (vport->fc_npr_cnt)
1815 lpfc_els_disc_plogi(vport);
1816 if (!vport->num_disc_nodes) {
1817 spin_lock_irq(shost->host_lock);
1818 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1819 spin_unlock_irq(shost->host_lock);
1820 lpfc_can_disctmo(vport);
1821 lpfc_end_rscn(vport);
1822 }
1823 }
1824 vport->port_state = LPFC_VPORT_READY;
1825 } else
1826 lpfc_rscn_disc(vport);
1827}
1828
1829/**
James Smart3621a712009-04-06 18:47:14 -04001830 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001831 * @vport: pointer to a host virtual N_Port data structure.
1832 *
1833 * This routine determines whether there are more ndlps on a @vport
1834 * node list need to have Address Discover (ADISC) issued. If so, it will
1835 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1836 * remaining nodes which need to have ADISC sent.
1837 **/
James Smart0ff10d42008-01-11 01:52:36 -05001838void
James Smart2e0fef82007-06-17 19:56:36 -05001839lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001840{
1841 int sentadisc;
1842
James Smart2e0fef82007-06-17 19:56:36 -05001843 if (vport->num_disc_nodes)
1844 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001845 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001846 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1847 "0210 Continue discovery with %d ADISCs to go "
1848 "Data: x%x x%x x%x\n",
1849 vport->num_disc_nodes, vport->fc_adisc_cnt,
1850 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001851 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001852 if (vport->fc_flag & FC_NLP_MORE) {
1853 lpfc_set_disctmo(vport);
1854 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1855 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001856 }
James Smart90160e02008-08-24 21:49:45 -04001857 if (!vport->num_disc_nodes)
1858 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001859 return;
1860}
1861
James Smarte59058c2008-08-24 21:49:00 -04001862/**
James Smart3621a712009-04-06 18:47:14 -04001863 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001864 * @phba: pointer to lpfc hba data structure.
1865 * @cmdiocb: pointer to lpfc command iocb data structure.
1866 * @rspiocb: pointer to lpfc response iocb data structure.
1867 *
1868 * This routine is the completion function for issuing the Address Discover
1869 * (ADISC) command. It first checks to see whether link went down during
1870 * the discovery process. If so, the node will be marked as node port
1871 * recovery for issuing discover IOCB by the link attention handler and
1872 * exit. Otherwise, the response status is checked. If error was reported
1873 * in the response status, the ADISC command shall be retried by invoking
1874 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1875 * the response status, the state machine is invoked to set transition
1876 * with respect to NLP_EVT_CMPL_ADISC event.
1877 **/
dea31012005-04-17 16:05:31 -05001878static void
James Smart2e0fef82007-06-17 19:56:36 -05001879lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1880 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001881{
James Smart2e0fef82007-06-17 19:56:36 -05001882 struct lpfc_vport *vport = cmdiocb->vport;
1883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001884 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001885 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001886 int disc;
dea31012005-04-17 16:05:31 -05001887
1888 /* we pass cmdiocb to state machine which needs rspiocb as well */
1889 cmdiocb->context_un.rsp_iocb = rspiocb;
1890
1891 irsp = &(rspiocb->iocb);
1892 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001893
James Smart858c9f62007-06-17 19:56:39 -05001894 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1895 "ADISC cmpl: status:x%x/x%x did:x%x",
1896 irsp->ulpStatus, irsp->un.ulpWord[4],
1897 ndlp->nlp_DID);
1898
dea31012005-04-17 16:05:31 -05001899 /* Since ndlp can be freed in the disc state machine, note if this node
1900 * is being used during discovery.
1901 */
James Smart2e0fef82007-06-17 19:56:36 -05001902 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001903 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001904 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001905 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001906 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001907 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1908 "0104 ADISC completes to NPort x%x "
1909 "Data: x%x x%x x%x x%x x%x\n",
1910 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1911 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001912 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001913 if (lpfc_els_chk_latt(vport)) {
1914 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001915 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001916 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001917 goto out;
1918 }
1919
1920 if (irsp->ulpStatus) {
1921 /* Check for retry */
1922 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1923 /* ELS command is being retried */
1924 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001925 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001926 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001927 spin_unlock_irq(shost->host_lock);
1928 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001929 }
1930 goto out;
1931 }
1932 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001933 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1934 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1935 ndlp->nlp_DID, irsp->ulpStatus,
1936 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001937 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001938 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001939 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001940 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001941 } else
dea31012005-04-17 16:05:31 -05001942 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001943 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001944 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001945
James Smart90160e02008-08-24 21:49:45 -04001946 /* Check to see if there are more ADISCs to be sent */
1947 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001948 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001949out:
1950 lpfc_els_free_iocb(phba, cmdiocb);
1951 return;
1952}
1953
James Smarte59058c2008-08-24 21:49:00 -04001954/**
James Smart3621a712009-04-06 18:47:14 -04001955 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001956 * @vport: pointer to a virtual N_Port data structure.
1957 * @ndlp: pointer to a node-list data structure.
1958 * @retry: number of retries to the command IOCB.
1959 *
1960 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1961 * @vport. It prepares the payload of the ADISC ELS command, updates the
1962 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1963 * to issue the ADISC ELS command.
1964 *
1965 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1966 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1967 * will be stored into the context1 field of the IOCB for the completion
1968 * callback function to the ADISC ELS command.
1969 *
1970 * Return code
1971 * 0 - successfully issued adisc
1972 * 1 - failed to issue adisc
1973 **/
dea31012005-04-17 16:05:31 -05001974int
James Smart2e0fef82007-06-17 19:56:36 -05001975lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001976 uint8_t retry)
1977{
James Smart2e0fef82007-06-17 19:56:36 -05001978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1979 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001980 ADISC *ap;
1981 IOCB_t *icmd;
1982 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001983 uint8_t *pcmd;
1984 uint16_t cmdsize;
1985
James Smart92d7f7b2007-06-17 19:56:38 -05001986 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001987 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1988 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001989 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001990 return 1;
dea31012005-04-17 16:05:31 -05001991
1992 icmd = &elsiocb->iocb;
1993 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1994
1995 /* For ADISC request, remainder of payload is service parameters */
1996 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001997 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001998
1999 /* Fill in ADISC payload */
2000 ap = (ADISC *) pcmd;
2001 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002002 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2003 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002004 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002005
James Smart858c9f62007-06-17 19:56:39 -05002006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2007 "Issue ADISC: did:x%x",
2008 ndlp->nlp_DID, 0, 0);
2009
dea31012005-04-17 16:05:31 -05002010 phba->fc_stat.elsXmitADISC++;
2011 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002012 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002013 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002014 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002015 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2016 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002017 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002018 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002019 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002020 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002021 return 1;
dea31012005-04-17 16:05:31 -05002022 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002023 return 0;
dea31012005-04-17 16:05:31 -05002024}
2025
James Smarte59058c2008-08-24 21:49:00 -04002026/**
James Smart3621a712009-04-06 18:47:14 -04002027 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002028 * @phba: pointer to lpfc hba data structure.
2029 * @cmdiocb: pointer to lpfc command iocb data structure.
2030 * @rspiocb: pointer to lpfc response iocb data structure.
2031 *
2032 * This routine is the completion function for issuing the ELS Logout (LOGO)
2033 * command. If no error status was reported from the LOGO response, the
2034 * state machine of the associated ndlp shall be invoked for transition with
2035 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2036 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2037 **/
dea31012005-04-17 16:05:31 -05002038static void
James Smart2e0fef82007-06-17 19:56:36 -05002039lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2040 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002041{
James Smart2e0fef82007-06-17 19:56:36 -05002042 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2043 struct lpfc_vport *vport = ndlp->vport;
2044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002045 IOCB_t *irsp;
2046 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002047
2048 psli = &phba->sli;
2049 /* we pass cmdiocb to state machine which needs rspiocb as well */
2050 cmdiocb->context_un.rsp_iocb = rspiocb;
2051
2052 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002053 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002054 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002055 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002056
James Smart858c9f62007-06-17 19:56:39 -05002057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2058 "LOGO cmpl: status:x%x/x%x did:x%x",
2059 irsp->ulpStatus, irsp->un.ulpWord[4],
2060 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002061 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002062 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2063 "0105 LOGO completes to NPort x%x "
2064 "Data: x%x x%x x%x x%x\n",
2065 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2066 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002067 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002068 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002069 goto out;
2070
James Smart92d7f7b2007-06-17 19:56:38 -05002071 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2072 /* NLP_EVT_DEVICE_RM should unregister the RPI
2073 * which should abort all outstanding IOs.
2074 */
2075 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2076 NLP_EVT_DEVICE_RM);
2077 goto out;
2078 }
2079
dea31012005-04-17 16:05:31 -05002080 if (irsp->ulpStatus) {
2081 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002082 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002083 /* ELS command is being retried */
2084 goto out;
dea31012005-04-17 16:05:31 -05002085 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002086 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2087 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2088 ndlp->nlp_DID, irsp->ulpStatus,
2089 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002090 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002091 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002092 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002093 else
James Smart2e0fef82007-06-17 19:56:36 -05002094 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002095 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002096 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002097 /* Good status, call state machine.
2098 * This will unregister the rpi if needed.
2099 */
James Smart2e0fef82007-06-17 19:56:36 -05002100 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002101 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002102out:
2103 lpfc_els_free_iocb(phba, cmdiocb);
2104 return;
2105}
2106
James Smarte59058c2008-08-24 21:49:00 -04002107/**
James Smart3621a712009-04-06 18:47:14 -04002108 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002109 * @vport: pointer to a virtual N_Port data structure.
2110 * @ndlp: pointer to a node-list data structure.
2111 * @retry: number of retries to the command IOCB.
2112 *
2113 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2114 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2115 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2116 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2117 *
2118 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2119 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2120 * will be stored into the context1 field of the IOCB for the completion
2121 * callback function to the LOGO ELS command.
2122 *
2123 * Return code
2124 * 0 - successfully issued logo
2125 * 1 - failed to issue logo
2126 **/
dea31012005-04-17 16:05:31 -05002127int
James Smart2e0fef82007-06-17 19:56:36 -05002128lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002129 uint8_t retry)
2130{
James Smart2e0fef82007-06-17 19:56:36 -05002131 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2132 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002133 IOCB_t *icmd;
2134 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002135 uint8_t *pcmd;
2136 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002137 int rc;
dea31012005-04-17 16:05:31 -05002138
James Smart98c9ea52007-10-27 13:37:33 -04002139 spin_lock_irq(shost->host_lock);
2140 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2141 spin_unlock_irq(shost->host_lock);
2142 return 0;
2143 }
2144 spin_unlock_irq(shost->host_lock);
2145
James Smart92d7f7b2007-06-17 19:56:38 -05002146 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002147 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2148 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002149 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002150 return 1;
dea31012005-04-17 16:05:31 -05002151
2152 icmd = &elsiocb->iocb;
2153 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2154 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002155 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002156
2157 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002158 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002159 pcmd += sizeof(uint32_t);
2160 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002161
James Smart858c9f62007-06-17 19:56:39 -05002162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2163 "Issue LOGO: did:x%x",
2164 ndlp->nlp_DID, 0, 0);
2165
dea31012005-04-17 16:05:31 -05002166 phba->fc_stat.elsXmitLOGO++;
2167 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002168 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002169 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002170 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002171 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002172
2173 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002174 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002175 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002176 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002177 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002178 return 1;
dea31012005-04-17 16:05:31 -05002179 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002180 return 0;
dea31012005-04-17 16:05:31 -05002181}
2182
James Smarte59058c2008-08-24 21:49:00 -04002183/**
James Smart3621a712009-04-06 18:47:14 -04002184 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002185 * @phba: pointer to lpfc hba data structure.
2186 * @cmdiocb: pointer to lpfc command iocb data structure.
2187 * @rspiocb: pointer to lpfc response iocb data structure.
2188 *
2189 * This routine is a generic completion callback function for ELS commands.
2190 * Specifically, it is the callback function which does not need to perform
2191 * any command specific operations. It is currently used by the ELS command
2192 * issuing routines for the ELS State Change Request (SCR),
2193 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2194 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2195 * certain debug loggings, this callback function simply invokes the
2196 * lpfc_els_chk_latt() routine to check whether link went down during the
2197 * discovery process.
2198 **/
dea31012005-04-17 16:05:31 -05002199static void
James Smart2e0fef82007-06-17 19:56:36 -05002200lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2201 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002202{
James Smart2e0fef82007-06-17 19:56:36 -05002203 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002204 IOCB_t *irsp;
2205
2206 irsp = &rspiocb->iocb;
2207
James Smart858c9f62007-06-17 19:56:39 -05002208 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2209 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2210 irsp->ulpStatus, irsp->un.ulpWord[4],
2211 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002212 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002213 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2214 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2215 irsp->ulpIoTag, irsp->ulpStatus,
2216 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002217 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002218 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002219 lpfc_els_free_iocb(phba, cmdiocb);
2220 return;
2221}
2222
James Smarte59058c2008-08-24 21:49:00 -04002223/**
James Smart3621a712009-04-06 18:47:14 -04002224 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002225 * @vport: pointer to a host virtual N_Port data structure.
2226 * @nportid: N_Port identifier to the remote node.
2227 * @retry: number of retries to the command IOCB.
2228 *
2229 * This routine issues a State Change Request (SCR) to a fabric node
2230 * on a @vport. The remote node @nportid is passed into the function. It
2231 * first search the @vport node list to find the matching ndlp. If no such
2232 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2233 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2234 * routine is invoked to send the SCR IOCB.
2235 *
2236 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2237 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2238 * will be stored into the context1 field of the IOCB for the completion
2239 * callback function to the SCR ELS command.
2240 *
2241 * Return code
2242 * 0 - Successfully issued scr command
2243 * 1 - Failed to issue scr command
2244 **/
dea31012005-04-17 16:05:31 -05002245int
James Smart2e0fef82007-06-17 19:56:36 -05002246lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002247{
James Smart2e0fef82007-06-17 19:56:36 -05002248 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002249 IOCB_t *icmd;
2250 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002251 struct lpfc_sli *psli;
2252 uint8_t *pcmd;
2253 uint16_t cmdsize;
2254 struct lpfc_nodelist *ndlp;
2255
2256 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002257 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002258
James Smarte47c9092008-02-08 18:49:26 -05002259 ndlp = lpfc_findnode_did(vport, nportid);
2260 if (!ndlp) {
2261 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2262 if (!ndlp)
2263 return 1;
2264 lpfc_nlp_init(vport, ndlp, nportid);
2265 lpfc_enqueue_node(vport, ndlp);
2266 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2267 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2268 if (!ndlp)
2269 return 1;
2270 }
dea31012005-04-17 16:05:31 -05002271
James Smart2e0fef82007-06-17 19:56:36 -05002272 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2273 ndlp->nlp_DID, ELS_CMD_SCR);
2274
James Smart488d1462006-03-07 15:02:37 -05002275 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002276 /* This will trigger the release of the node just
2277 * allocated
2278 */
James Smart329f9bc2007-04-25 09:53:01 -04002279 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002280 return 1;
dea31012005-04-17 16:05:31 -05002281 }
2282
2283 icmd = &elsiocb->iocb;
2284 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2285
2286 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002287 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002288
2289 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002290 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002291 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2292
James Smart858c9f62007-06-17 19:56:39 -05002293 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2294 "Issue SCR: did:x%x",
2295 ndlp->nlp_DID, 0, 0);
2296
dea31012005-04-17 16:05:31 -05002297 phba->fc_stat.elsXmitSCR++;
2298 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002299 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2300 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002301 /* The additional lpfc_nlp_put will cause the following
2302 * lpfc_els_free_iocb routine to trigger the rlease of
2303 * the node.
2304 */
James Smart329f9bc2007-04-25 09:53:01 -04002305 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002306 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002307 return 1;
dea31012005-04-17 16:05:31 -05002308 }
James Smartfa4066b2008-01-11 01:53:27 -05002309 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2310 * trigger the release of node.
2311 */
James Smart329f9bc2007-04-25 09:53:01 -04002312 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002313 return 0;
dea31012005-04-17 16:05:31 -05002314}
2315
James Smarte59058c2008-08-24 21:49:00 -04002316/**
James Smart3621a712009-04-06 18:47:14 -04002317 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002318 * @vport: pointer to a host virtual N_Port data structure.
2319 * @nportid: N_Port identifier to the remote node.
2320 * @retry: number of retries to the command IOCB.
2321 *
2322 * This routine issues a Fibre Channel Address Resolution Response
2323 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2324 * is passed into the function. It first search the @vport node list to find
2325 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2326 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2327 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2328 *
2329 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2330 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2331 * will be stored into the context1 field of the IOCB for the completion
2332 * callback function to the PARPR ELS command.
2333 *
2334 * Return code
2335 * 0 - Successfully issued farpr command
2336 * 1 - Failed to issue farpr command
2337 **/
dea31012005-04-17 16:05:31 -05002338static int
James Smart2e0fef82007-06-17 19:56:36 -05002339lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002340{
James Smart2e0fef82007-06-17 19:56:36 -05002341 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002342 IOCB_t *icmd;
2343 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002344 struct lpfc_sli *psli;
2345 FARP *fp;
2346 uint8_t *pcmd;
2347 uint32_t *lp;
2348 uint16_t cmdsize;
2349 struct lpfc_nodelist *ondlp;
2350 struct lpfc_nodelist *ndlp;
2351
2352 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002353 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002354
James Smarte47c9092008-02-08 18:49:26 -05002355 ndlp = lpfc_findnode_did(vport, nportid);
2356 if (!ndlp) {
2357 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2358 if (!ndlp)
2359 return 1;
2360 lpfc_nlp_init(vport, ndlp, nportid);
2361 lpfc_enqueue_node(vport, ndlp);
2362 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2363 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2364 if (!ndlp)
2365 return 1;
2366 }
James Smart2e0fef82007-06-17 19:56:36 -05002367
2368 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2369 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002370 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002371 /* This will trigger the release of the node just
2372 * allocated
2373 */
James Smart329f9bc2007-04-25 09:53:01 -04002374 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002375 return 1;
dea31012005-04-17 16:05:31 -05002376 }
2377
2378 icmd = &elsiocb->iocb;
2379 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2380
2381 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002382 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002383
2384 /* Fill in FARPR payload */
2385 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002386 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002387 lp = (uint32_t *) pcmd;
2388 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002389 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002390 fp->Rflags = 0;
2391 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2392
James Smart92d7f7b2007-06-17 19:56:38 -05002393 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2394 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002395 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002396 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002397 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002398 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002399 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002400 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002401 }
2402
James Smart858c9f62007-06-17 19:56:39 -05002403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2404 "Issue FARPR: did:x%x",
2405 ndlp->nlp_DID, 0, 0);
2406
dea31012005-04-17 16:05:31 -05002407 phba->fc_stat.elsXmitFARPR++;
2408 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002409 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2410 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002411 /* The additional lpfc_nlp_put will cause the following
2412 * lpfc_els_free_iocb routine to trigger the release of
2413 * the node.
2414 */
James Smart329f9bc2007-04-25 09:53:01 -04002415 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002416 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002417 return 1;
dea31012005-04-17 16:05:31 -05002418 }
James Smartfa4066b2008-01-11 01:53:27 -05002419 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2420 * trigger the release of the node.
2421 */
James Smart329f9bc2007-04-25 09:53:01 -04002422 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002423 return 0;
dea31012005-04-17 16:05:31 -05002424}
2425
James Smarte59058c2008-08-24 21:49:00 -04002426/**
James Smart3621a712009-04-06 18:47:14 -04002427 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002428 * @vport: pointer to a host virtual N_Port data structure.
2429 * @nlp: pointer to a node-list data structure.
2430 *
2431 * This routine cancels the timer with a delayed IOCB-command retry for
2432 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2433 * removes the ELS retry event if it presents. In addition, if the
2434 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2435 * commands are sent for the @vport's nodes that require issuing discovery
2436 * ADISC.
2437 **/
dea31012005-04-17 16:05:31 -05002438void
James Smart2e0fef82007-06-17 19:56:36 -05002439lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002440{
James Smart2e0fef82007-06-17 19:56:36 -05002441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002442 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002443
James Smart0d2b6b82008-06-14 22:52:47 -04002444 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2445 return;
James Smart2e0fef82007-06-17 19:56:36 -05002446 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002447 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002448 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002449 del_timer_sync(&nlp->nlp_delayfunc);
2450 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002451 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002452 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002453 /* Decrement nlp reference count held for the delayed retry */
2454 evtp = &nlp->els_retry_evt;
2455 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2456 }
James Smartfdcebe22006-03-07 15:04:01 -05002457 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002458 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002459 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002460 spin_unlock_irq(shost->host_lock);
2461 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002462 if (vport->port_state < LPFC_VPORT_READY) {
2463 /* Check if there are more ADISCs to be sent */
2464 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002465 } else {
2466 /* Check if there are more PLOGIs to be sent */
2467 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002468 if (vport->num_disc_nodes == 0) {
2469 spin_lock_irq(shost->host_lock);
2470 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2471 spin_unlock_irq(shost->host_lock);
2472 lpfc_can_disctmo(vport);
2473 lpfc_end_rscn(vport);
2474 }
James Smartfdcebe22006-03-07 15:04:01 -05002475 }
2476 }
2477 }
2478 return;
2479}
2480
James Smarte59058c2008-08-24 21:49:00 -04002481/**
James Smart3621a712009-04-06 18:47:14 -04002482 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002483 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2484 *
2485 * This routine is invoked by the ndlp delayed-function timer to check
2486 * whether there is any pending ELS retry event(s) with the node. If not, it
2487 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2488 * adds the delayed events to the HBA work list and invokes the
2489 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2490 * event. Note that lpfc_nlp_get() is called before posting the event to
2491 * the work list to hold reference count of ndlp so that it guarantees the
2492 * reference to ndlp will still be available when the worker thread gets
2493 * to the event associated with the ndlp.
2494 **/
James Smartfdcebe22006-03-07 15:04:01 -05002495void
dea31012005-04-17 16:05:31 -05002496lpfc_els_retry_delay(unsigned long ptr)
2497{
James Smart2e0fef82007-06-17 19:56:36 -05002498 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2499 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002500 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002501 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002502 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002503
James Smart92d7f7b2007-06-17 19:56:38 -05002504 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002505 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002506 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002507 return;
2508 }
2509
James Smartfa4066b2008-01-11 01:53:27 -05002510 /* We need to hold the node by incrementing the reference
2511 * count until the queued work is done
2512 */
2513 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002514 if (evtp->evt_arg1) {
2515 evtp->evt = LPFC_EVT_ELS_RETRY;
2516 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002517 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002518 }
James Smart92d7f7b2007-06-17 19:56:38 -05002519 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002520 return;
2521}
2522
James Smarte59058c2008-08-24 21:49:00 -04002523/**
James Smart3621a712009-04-06 18:47:14 -04002524 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002525 * @ndlp: pointer to a node-list data structure.
2526 *
2527 * This routine is the worker-thread handler for processing the @ndlp delayed
2528 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2529 * the last ELS command from the associated ndlp and invokes the proper ELS
2530 * function according to the delayed ELS command to retry the command.
2531 **/
dea31012005-04-17 16:05:31 -05002532void
2533lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2534{
James Smart2e0fef82007-06-17 19:56:36 -05002535 struct lpfc_vport *vport = ndlp->vport;
2536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2537 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002538
James Smart2e0fef82007-06-17 19:56:36 -05002539 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002540 did = ndlp->nlp_DID;
2541 cmd = ndlp->nlp_last_elscmd;
2542 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002543
2544 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002545 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002546 return;
2547 }
2548
2549 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002550 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002551 /*
2552 * If a discovery event readded nlp_delayfunc after timer
2553 * firing and before processing the timer, cancel the
2554 * nlp_delayfunc.
2555 */
2556 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002557 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002558 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002559
2560 switch (cmd) {
2561 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002562 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002563 break;
2564 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002565 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002566 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002567 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002568 }
dea31012005-04-17 16:05:31 -05002569 break;
2570 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002571 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002572 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002573 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002574 }
dea31012005-04-17 16:05:31 -05002575 break;
2576 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002577 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002578 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002579 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002580 }
dea31012005-04-17 16:05:31 -05002581 break;
2582 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002583 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002584 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002585 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002586 }
dea31012005-04-17 16:05:31 -05002587 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002588 case ELS_CMD_FDISC:
2589 lpfc_issue_els_fdisc(vport, ndlp, retry);
2590 break;
dea31012005-04-17 16:05:31 -05002591 }
2592 return;
2593}
2594
James Smarte59058c2008-08-24 21:49:00 -04002595/**
James Smart3621a712009-04-06 18:47:14 -04002596 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002597 * @phba: pointer to lpfc hba data structure.
2598 * @cmdiocb: pointer to lpfc command iocb data structure.
2599 * @rspiocb: pointer to lpfc response iocb data structure.
2600 *
2601 * This routine makes a retry decision on an ELS command IOCB, which has
2602 * failed. The following ELS IOCBs use this function for retrying the command
2603 * when previously issued command responsed with error status: FLOGI, PLOGI,
2604 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2605 * returned error status, it makes the decision whether a retry shall be
2606 * issued for the command, and whether a retry shall be made immediately or
2607 * delayed. In the former case, the corresponding ELS command issuing-function
2608 * is called to retry the command. In the later case, the ELS command shall
2609 * be posted to the ndlp delayed event and delayed function timer set to the
2610 * ndlp for the delayed command issusing.
2611 *
2612 * Return code
2613 * 0 - No retry of els command is made
2614 * 1 - Immediate or delayed retry of els command is made
2615 **/
dea31012005-04-17 16:05:31 -05002616static int
James Smart2e0fef82007-06-17 19:56:36 -05002617lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2618 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002619{
James Smart2e0fef82007-06-17 19:56:36 -05002620 struct lpfc_vport *vport = cmdiocb->vport;
2621 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2622 IOCB_t *irsp = &rspiocb->iocb;
2623 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2624 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002625 uint32_t *elscmd;
2626 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002627 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002628 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002629 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002630 uint32_t did;
dea31012005-04-17 16:05:31 -05002631
James Smart488d1462006-03-07 15:02:37 -05002632
dea31012005-04-17 16:05:31 -05002633 /* Note: context2 may be 0 for internal driver abort
2634 * of delays ELS command.
2635 */
2636
2637 if (pcmd && pcmd->virt) {
2638 elscmd = (uint32_t *) (pcmd->virt);
2639 cmd = *elscmd++;
2640 }
2641
James Smarte47c9092008-02-08 18:49:26 -05002642 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002643 did = ndlp->nlp_DID;
2644 else {
2645 /* We should only hit this case for retrying PLOGI */
2646 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002647 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002648 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2649 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002650 return 1;
2651 }
2652
James Smart858c9f62007-06-17 19:56:39 -05002653 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2654 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2655 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2656
dea31012005-04-17 16:05:31 -05002657 switch (irsp->ulpStatus) {
2658 case IOSTAT_FCP_RSP_ERROR:
2659 case IOSTAT_REMOTE_STOP:
2660 break;
2661
2662 case IOSTAT_LOCAL_REJECT:
2663 switch ((irsp->un.ulpWord[4] & 0xff)) {
2664 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002665 if (cmd == ELS_CMD_FLOGI) {
2666 if (PCI_DEVICE_ID_HORNET ==
2667 phba->pcidev->device) {
2668 phba->fc_topology = TOPOLOGY_LOOP;
2669 phba->pport->fc_myDID = 0;
2670 phba->alpa_map[0] = 0;
2671 phba->alpa_map[1] = 0;
2672 }
2673 }
James Smart2e0fef82007-06-17 19:56:36 -05002674 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002675 delay = 1000;
dea31012005-04-17 16:05:31 -05002676 retry = 1;
2677 break;
2678
James Smart92d7f7b2007-06-17 19:56:38 -05002679 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002680 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2681 "0124 Retry illegal cmd x%x "
2682 "retry:x%x delay:x%x\n",
2683 cmd, cmdiocb->retry, delay);
2684 retry = 1;
2685 /* All command's retry policy */
2686 maxretry = 8;
2687 if (cmdiocb->retry > 2)
2688 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002689 break;
2690
dea31012005-04-17 16:05:31 -05002691 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002692 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002693 retry = 1;
2694 if (cmdiocb->retry > 100)
2695 delay = 100;
2696 maxretry = 250;
2697 break;
2698
2699 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002700 delay = 100;
dea31012005-04-17 16:05:31 -05002701 retry = 1;
2702 break;
2703
James Smart858c9f62007-06-17 19:56:39 -05002704 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002705 case IOERR_INVALID_RPI:
2706 retry = 1;
2707 break;
2708 }
2709 break;
2710
2711 case IOSTAT_NPORT_RJT:
2712 case IOSTAT_FABRIC_RJT:
2713 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2714 retry = 1;
2715 break;
2716 }
2717 break;
2718
2719 case IOSTAT_NPORT_BSY:
2720 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002721 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002722 retry = 1;
2723 break;
2724
2725 case IOSTAT_LS_RJT:
2726 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2727 /* Added for Vendor specifc support
2728 * Just keep retrying for these Rsn / Exp codes
2729 */
2730 switch (stat.un.b.lsRjtRsnCode) {
2731 case LSRJT_UNABLE_TPC:
2732 if (stat.un.b.lsRjtRsnCodeExp ==
2733 LSEXP_CMD_IN_PROGRESS) {
2734 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002735 delay = 1000;
dea31012005-04-17 16:05:31 -05002736 maxretry = 48;
2737 }
2738 retry = 1;
2739 break;
2740 }
2741 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002742 delay = 1000;
dea31012005-04-17 16:05:31 -05002743 maxretry = lpfc_max_els_tries + 1;
2744 retry = 1;
2745 break;
2746 }
James Smart92d7f7b2007-06-17 19:56:38 -05002747 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2748 (cmd == ELS_CMD_FDISC) &&
2749 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002750 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2751 "0125 FDISC Failed (x%x). "
2752 "Fabric out of resources\n",
2753 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002754 lpfc_vport_set_state(vport,
2755 FC_VPORT_NO_FABRIC_RSCS);
2756 }
dea31012005-04-17 16:05:31 -05002757 break;
2758
2759 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002760 if ((cmd == ELS_CMD_PLOGI) ||
2761 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002762 delay = 1000;
dea31012005-04-17 16:05:31 -05002763 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002764 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002765 /* FDISC retry policy */
2766 maxretry = 48;
2767 if (cmdiocb->retry >= 32)
2768 delay = 1000;
dea31012005-04-17 16:05:31 -05002769 }
2770 retry = 1;
2771 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002772
2773 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002774 /* There are some cases where switches return this
2775 * error when they are not ready and should be returning
2776 * Logical Busy. We should delay every time.
2777 */
2778 if (cmd == ELS_CMD_FDISC &&
2779 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2780 maxretry = 3;
2781 delay = 1000;
2782 retry = 1;
2783 break;
2784 }
James Smart92d7f7b2007-06-17 19:56:38 -05002785 case LSRJT_PROTOCOL_ERR:
2786 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2787 (cmd == ELS_CMD_FDISC) &&
2788 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2789 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2790 ) {
James Smarte8b62012007-08-02 11:10:09 -04002791 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002792 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002793 "Fabric Detected Bad WWN\n",
2794 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002795 lpfc_vport_set_state(vport,
2796 FC_VPORT_FABRIC_REJ_WWN);
2797 }
2798 break;
dea31012005-04-17 16:05:31 -05002799 }
2800 break;
2801
2802 case IOSTAT_INTERMED_RSP:
2803 case IOSTAT_BA_RJT:
2804 break;
2805
2806 default:
2807 break;
2808 }
2809
James Smart488d1462006-03-07 15:02:37 -05002810 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002811 retry = 1;
dea31012005-04-17 16:05:31 -05002812
James Smart695a8142010-01-26 23:08:03 -05002813 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002814 (phba->fc_topology != TOPOLOGY_LOOP) &&
2815 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002816 /* FLOGI retry policy */
2817 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002818 /* retry forever */
2819 maxretry = 0;
2820 if (cmdiocb->retry >= 100)
2821 delay = 5000;
2822 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002823 delay = 1000;
2824 }
2825
James Smart6669f9b2009-10-02 15:16:45 -04002826 cmdiocb->retry++;
2827 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002828 phba->fc_stat.elsRetryExceeded++;
2829 retry = 0;
2830 }
2831
James Smarted957682007-06-17 19:56:37 -05002832 if ((vport->load_flag & FC_UNLOADING) != 0)
2833 retry = 0;
2834
dea31012005-04-17 16:05:31 -05002835 if (retry) {
2836
2837 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002838 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2839 "0107 Retry ELS command x%x to remote "
2840 "NPORT x%x Data: x%x x%x\n",
2841 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002842
James Smart858c9f62007-06-17 19:56:39 -05002843 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2844 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2845 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2846 /* Don't reset timer for no resources */
2847
dea31012005-04-17 16:05:31 -05002848 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002849 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002850 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002851 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002852 }
2853
2854 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002855 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002856 phba->fc_stat.elsDelayRetry++;
2857 ndlp->nlp_retry = cmdiocb->retry;
2858
James Smart92d7f7b2007-06-17 19:56:38 -05002859 /* delay is specified in milliseconds */
2860 mod_timer(&ndlp->nlp_delayfunc,
2861 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002862 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002863 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002864 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002865
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002866 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002867 if (cmd == ELS_CMD_PRLI)
2868 lpfc_nlp_set_state(vport, ndlp,
2869 NLP_STE_REG_LOGIN_ISSUE);
2870 else
2871 lpfc_nlp_set_state(vport, ndlp,
2872 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002873 ndlp->nlp_last_elscmd = cmd;
2874
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002875 return 1;
dea31012005-04-17 16:05:31 -05002876 }
2877 switch (cmd) {
2878 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002879 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002880 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002881 case ELS_CMD_FDISC:
2882 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2883 return 1;
dea31012005-04-17 16:05:31 -05002884 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002885 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002886 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002887 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002888 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002889 }
James Smart2e0fef82007-06-17 19:56:36 -05002890 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002891 return 1;
dea31012005-04-17 16:05:31 -05002892 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002893 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002894 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2895 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002896 return 1;
dea31012005-04-17 16:05:31 -05002897 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002898 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002899 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2900 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002901 return 1;
dea31012005-04-17 16:05:31 -05002902 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002903 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002904 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2905 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002906 return 1;
dea31012005-04-17 16:05:31 -05002907 }
2908 }
dea31012005-04-17 16:05:31 -05002909 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002910 if (logerr) {
2911 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2912 "0137 No retry ELS command x%x to remote "
2913 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2914 cmd, did, irsp->ulpStatus,
2915 irsp->un.ulpWord[4]);
2916 }
2917 else {
2918 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002919 "0108 No retry ELS command x%x to remote "
2920 "NPORT x%x Retried:%d Error:x%x/%x\n",
2921 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2922 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002923 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002924 return 0;
dea31012005-04-17 16:05:31 -05002925}
2926
James Smarte59058c2008-08-24 21:49:00 -04002927/**
James Smart3621a712009-04-06 18:47:14 -04002928 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002929 * @phba: pointer to lpfc hba data structure.
2930 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2931 *
2932 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2933 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2934 * checks to see whether there is a lpfc DMA buffer associated with the
2935 * response of the command IOCB. If so, it will be released before releasing
2936 * the lpfc DMA buffer associated with the IOCB itself.
2937 *
2938 * Return code
2939 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2940 **/
James Smart09372822008-01-11 01:52:54 -05002941static int
James Smart87af33f2007-10-27 13:37:43 -04002942lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2943{
2944 struct lpfc_dmabuf *buf_ptr;
2945
James Smarte59058c2008-08-24 21:49:00 -04002946 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002947 if (!list_empty(&buf_ptr1->list)) {
2948 list_remove_head(&buf_ptr1->list, buf_ptr,
2949 struct lpfc_dmabuf,
2950 list);
2951 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2952 kfree(buf_ptr);
2953 }
2954 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2955 kfree(buf_ptr1);
2956 return 0;
2957}
2958
James Smarte59058c2008-08-24 21:49:00 -04002959/**
James Smart3621a712009-04-06 18:47:14 -04002960 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002961 * @phba: pointer to lpfc hba data structure.
2962 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2963 *
2964 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2965 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2966 * pool.
2967 *
2968 * Return code
2969 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2970 **/
James Smart09372822008-01-11 01:52:54 -05002971static int
James Smart87af33f2007-10-27 13:37:43 -04002972lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2973{
2974 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2975 kfree(buf_ptr);
2976 return 0;
2977}
2978
James Smarte59058c2008-08-24 21:49:00 -04002979/**
James Smart3621a712009-04-06 18:47:14 -04002980 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002981 * @phba: pointer to lpfc hba data structure.
2982 * @elsiocb: pointer to lpfc els command iocb data structure.
2983 *
2984 * This routine frees a command IOCB and its associated resources. The
2985 * command IOCB data structure contains the reference to various associated
2986 * resources, these fields must be set to NULL if the associated reference
2987 * not present:
2988 * context1 - reference to ndlp
2989 * context2 - reference to cmd
2990 * context2->next - reference to rsp
2991 * context3 - reference to bpl
2992 *
2993 * It first properly decrements the reference count held on ndlp for the
2994 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2995 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2996 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2997 * adds the DMA buffer the @phba data structure for the delayed release.
2998 * If reference to the Buffer Pointer List (BPL) is present, the
2999 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3000 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3001 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3002 *
3003 * Return code
3004 * 0 - Success (currently, always return 0)
3005 **/
James Smart87af33f2007-10-27 13:37:43 -04003006int
James Smart329f9bc2007-04-25 09:53:01 -04003007lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003008{
3009 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003010 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003011
James Smarta8adb832007-10-27 13:37:53 -04003012 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3013 if (ndlp) {
3014 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3015 lpfc_nlp_put(ndlp);
3016
3017 /* If the ndlp is not being used by another discovery
3018 * thread, free it.
3019 */
3020 if (!lpfc_nlp_not_used(ndlp)) {
3021 /* If ndlp is being used by another discovery
3022 * thread, just clear NLP_DEFER_RM
3023 */
3024 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3025 }
3026 }
3027 else
3028 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003029 elsiocb->context1 = NULL;
3030 }
dea31012005-04-17 16:05:31 -05003031 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3032 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003033 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3034 /* Firmware could still be in progress of DMAing
3035 * payload, so don't free data buffer till after
3036 * a hbeat.
3037 */
3038 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3039 buf_ptr = elsiocb->context2;
3040 elsiocb->context2 = NULL;
3041 if (buf_ptr) {
3042 buf_ptr1 = NULL;
3043 spin_lock_irq(&phba->hbalock);
3044 if (!list_empty(&buf_ptr->list)) {
3045 list_remove_head(&buf_ptr->list,
3046 buf_ptr1, struct lpfc_dmabuf,
3047 list);
3048 INIT_LIST_HEAD(&buf_ptr1->list);
3049 list_add_tail(&buf_ptr1->list,
3050 &phba->elsbuf);
3051 phba->elsbuf_cnt++;
3052 }
3053 INIT_LIST_HEAD(&buf_ptr->list);
3054 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3055 phba->elsbuf_cnt++;
3056 spin_unlock_irq(&phba->hbalock);
3057 }
3058 } else {
3059 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3060 lpfc_els_free_data(phba, buf_ptr1);
3061 }
dea31012005-04-17 16:05:31 -05003062 }
3063
3064 if (elsiocb->context3) {
3065 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003066 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003067 }
James Bottomley604a3e32005-10-29 10:28:33 -05003068 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003069 return 0;
3070}
3071
James Smarte59058c2008-08-24 21:49:00 -04003072/**
James Smart3621a712009-04-06 18:47:14 -04003073 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003074 * @phba: pointer to lpfc hba data structure.
3075 * @cmdiocb: pointer to lpfc command iocb data structure.
3076 * @rspiocb: pointer to lpfc response iocb data structure.
3077 *
3078 * This routine is the completion callback function to the Logout (LOGO)
3079 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3080 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3081 * release the ndlp if it has the last reference remaining (reference count
3082 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3083 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3084 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3085 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3086 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3087 * IOCB data structure.
3088 **/
dea31012005-04-17 16:05:31 -05003089static void
James Smart2e0fef82007-06-17 19:56:36 -05003090lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3091 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003092{
James Smart2e0fef82007-06-17 19:56:36 -05003093 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3094 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003095 IOCB_t *irsp;
3096
3097 irsp = &rspiocb->iocb;
3098 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3099 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3100 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003101 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003102 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3103 "0109 ACC to LOGO completes to NPort x%x "
3104 "Data: x%x x%x x%x\n",
3105 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3106 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003107
3108 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3109 /* NPort Recovery mode or node is just allocated */
3110 if (!lpfc_nlp_not_used(ndlp)) {
3111 /* If the ndlp is being used by another discovery
3112 * thread, just unregister the RPI.
3113 */
3114 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003115 } else {
3116 /* Indicate the node has already released, should
3117 * not reference to it from within lpfc_els_free_iocb.
3118 */
3119 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003120 }
dea31012005-04-17 16:05:31 -05003121 }
3122 lpfc_els_free_iocb(phba, cmdiocb);
3123 return;
3124}
3125
James Smarte59058c2008-08-24 21:49:00 -04003126/**
James Smart3621a712009-04-06 18:47:14 -04003127 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003128 * @phba: pointer to lpfc hba data structure.
3129 * @pmb: pointer to the driver internal queue element for mailbox command.
3130 *
3131 * This routine is the completion callback function for unregister default
3132 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3133 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3134 * decrements the ndlp reference count held for this completion callback
3135 * function. After that, it invokes the lpfc_nlp_not_used() to check
3136 * whether there is only one reference left on the ndlp. If so, it will
3137 * perform one more decrement and trigger the release of the ndlp.
3138 **/
James Smart858c9f62007-06-17 19:56:39 -05003139void
3140lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3141{
3142 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3143 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3144
James Smart6fb120a2009-05-22 14:52:59 -04003145 /*
3146 * This routine is used to register and unregister in previous SLI
3147 * modes.
3148 */
3149 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3150 (phba->sli_rev == LPFC_SLI_REV4))
3151 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3152
James Smart858c9f62007-06-17 19:56:39 -05003153 pmb->context1 = NULL;
3154 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3155 kfree(mp);
3156 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003157 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003158 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003159 /* This is the end of the default RPI cleanup logic for this
3160 * ndlp. If no other discovery threads are using this ndlp.
3161 * we should free all resources associated with it.
3162 */
3163 lpfc_nlp_not_used(ndlp);
3164 }
James Smart3772a992009-05-22 14:50:54 -04003165
James Smart858c9f62007-06-17 19:56:39 -05003166 return;
3167}
3168
James Smarte59058c2008-08-24 21:49:00 -04003169/**
James Smart3621a712009-04-06 18:47:14 -04003170 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003171 * @phba: pointer to lpfc hba data structure.
3172 * @cmdiocb: pointer to lpfc command iocb data structure.
3173 * @rspiocb: pointer to lpfc response iocb data structure.
3174 *
3175 * This routine is the completion callback function for ELS Response IOCB
3176 * command. In normal case, this callback function just properly sets the
3177 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3178 * field in the command IOCB is not NULL, the referred mailbox command will
3179 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3180 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3181 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3182 * routine shall be invoked trying to release the ndlp if no other threads
3183 * are currently referring it.
3184 **/
dea31012005-04-17 16:05:31 -05003185static void
James Smart858c9f62007-06-17 19:56:39 -05003186lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003187 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003188{
James Smart2e0fef82007-06-17 19:56:36 -05003189 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3190 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3191 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003192 IOCB_t *irsp;
3193 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003194 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003195 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003196 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003197
James Smart33ccf8d2006-08-17 11:57:58 -04003198 irsp = &rspiocb->iocb;
3199
dea31012005-04-17 16:05:31 -05003200 if (cmdiocb->context_un.mbox)
3201 mbox = cmdiocb->context_un.mbox;
3202
James Smartfa4066b2008-01-11 01:53:27 -05003203 /* First determine if this is a LS_RJT cmpl. Note, this callback
3204 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3205 */
James Smart87af33f2007-10-27 13:37:43 -04003206 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003207 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3208 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003209 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003210 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003211 */
3212 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3213 ls_rjt = 1;
3214 }
3215
dea31012005-04-17 16:05:31 -05003216 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003217 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003218 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003219 mp = (struct lpfc_dmabuf *) mbox->context1;
3220 if (mp) {
3221 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3222 kfree(mp);
3223 }
James Smart329f9bc2007-04-25 09:53:01 -04003224 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003225 }
James Smart58da1ff2008-04-07 10:15:56 -04003226 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3227 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003228 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003229 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003230 /* Indicate the node has already released,
3231 * should not reference to it from within
3232 * the routine lpfc_els_free_iocb.
3233 */
3234 cmdiocb->context1 = NULL;
3235 }
dea31012005-04-17 16:05:31 -05003236 goto out;
3237 }
3238
James Smart858c9f62007-06-17 19:56:39 -05003239 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003240 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003241 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003242 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003243 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003244 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3245 "0110 ELS response tag x%x completes "
3246 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3247 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3248 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3249 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3250 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003251 if (mbox) {
3252 if ((rspiocb->iocb.ulpStatus == 0)
3253 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003254 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003255 /* Increment reference count to ndlp to hold the
3256 * reference to ndlp for the callback function.
3257 */
James Smart329f9bc2007-04-25 09:53:01 -04003258 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003259 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003260 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3261 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3262 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3263 }
3264 else {
3265 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3266 ndlp->nlp_prev_state = ndlp->nlp_state;
3267 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003268 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003269 }
James Smart0b727fe2007-10-27 13:37:25 -04003270 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003271 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003272 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003273 else
3274 /* Decrement the ndlp reference count we
3275 * set for this failed mailbox command.
3276 */
3277 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003278
3279 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3280 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3281 "0138 ELS rsp: Cannot issue reg_login for x%x "
3282 "Data: x%x x%x x%x\n",
3283 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3284 ndlp->nlp_rpi);
3285
James Smartfa4066b2008-01-11 01:53:27 -05003286 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003287 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003288 /* Indicate node has already been released,
3289 * should not reference to it from within
3290 * the routine lpfc_els_free_iocb.
3291 */
3292 cmdiocb->context1 = NULL;
3293 }
dea31012005-04-17 16:05:31 -05003294 } else {
James Smart858c9f62007-06-17 19:56:39 -05003295 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3296 if (!lpfc_error_lost_link(irsp) &&
3297 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003298 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003299 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003300 /* Indicate node has already been
3301 * released, should not reference
3302 * to it from within the routine
3303 * lpfc_els_free_iocb.
3304 */
3305 cmdiocb->context1 = NULL;
3306 }
dea31012005-04-17 16:05:31 -05003307 }
3308 }
James Smart14691152006-12-02 13:34:28 -05003309 mp = (struct lpfc_dmabuf *) mbox->context1;
3310 if (mp) {
3311 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3312 kfree(mp);
3313 }
3314 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003315 }
3316out:
James Smart58da1ff2008-04-07 10:15:56 -04003317 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003318 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003319 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003320 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003321
3322 /* If the node is not being used by another discovery thread,
3323 * and we are sending a reject, we are done with it.
3324 * Release driver reference count here and free associated
3325 * resources.
3326 */
3327 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003328 if (lpfc_nlp_not_used(ndlp))
3329 /* Indicate node has already been released,
3330 * should not reference to it from within
3331 * the routine lpfc_els_free_iocb.
3332 */
3333 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003334 }
James Smart87af33f2007-10-27 13:37:43 -04003335
dea31012005-04-17 16:05:31 -05003336 lpfc_els_free_iocb(phba, cmdiocb);
3337 return;
3338}
3339
James Smarte59058c2008-08-24 21:49:00 -04003340/**
James Smart3621a712009-04-06 18:47:14 -04003341 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003342 * @vport: pointer to a host virtual N_Port data structure.
3343 * @flag: the els command code to be accepted.
3344 * @oldiocb: pointer to the original lpfc command iocb data structure.
3345 * @ndlp: pointer to a node-list data structure.
3346 * @mbox: pointer to the driver internal queue element for mailbox command.
3347 *
3348 * This routine prepares and issues an Accept (ACC) response IOCB
3349 * command. It uses the @flag to properly set up the IOCB field for the
3350 * specific ACC response command to be issued and invokes the
3351 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3352 * @mbox pointer is passed in, it will be put into the context_un.mbox
3353 * field of the IOCB for the completion callback function to issue the
3354 * mailbox command to the HBA later when callback is invoked.
3355 *
3356 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3357 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3358 * will be stored into the context1 field of the IOCB for the completion
3359 * callback function to the corresponding response ELS IOCB command.
3360 *
3361 * Return code
3362 * 0 - Successfully issued acc response
3363 * 1 - Failed to issue acc response
3364 **/
dea31012005-04-17 16:05:31 -05003365int
James Smart2e0fef82007-06-17 19:56:36 -05003366lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3367 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003368 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003369{
James Smart2e0fef82007-06-17 19:56:36 -05003370 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3371 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003372 IOCB_t *icmd;
3373 IOCB_t *oldcmd;
3374 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003375 struct lpfc_sli *psli;
3376 uint8_t *pcmd;
3377 uint16_t cmdsize;
3378 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003379 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003380
3381 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003382 oldcmd = &oldiocb->iocb;
3383
3384 switch (flag) {
3385 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003386 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003387 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3388 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003389 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003390 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003391 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003392 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003393 return 1;
dea31012005-04-17 16:05:31 -05003394 }
James Smart2e0fef82007-06-17 19:56:36 -05003395
dea31012005-04-17 16:05:31 -05003396 icmd = &elsiocb->iocb;
3397 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3398 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3399 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003400 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003401
3402 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3403 "Issue ACC: did:x%x flg:x%x",
3404 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003405 break;
3406 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003407 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003408 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3409 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003410 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003411 return 1;
James Smart488d1462006-03-07 15:02:37 -05003412
dea31012005-04-17 16:05:31 -05003413 icmd = &elsiocb->iocb;
3414 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3415 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3416
3417 if (mbox)
3418 elsiocb->context_un.mbox = mbox;
3419
3420 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003421 pcmd += sizeof(uint32_t);
3422 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003423
3424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3425 "Issue ACC PLOGI: did:x%x flg:x%x",
3426 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003427 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003428 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003429 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003430 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003431 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3432 if (!elsiocb)
3433 return 1;
3434
3435 icmd = &elsiocb->iocb;
3436 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3437 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3438
3439 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003440 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003441 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3442 els_pkt_ptr = (ELS_PKT *) pcmd;
3443 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003444
3445 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3446 "Issue ACC PRLO: did:x%x flg:x%x",
3447 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003448 break;
dea31012005-04-17 16:05:31 -05003449 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003450 return 1;
dea31012005-04-17 16:05:31 -05003451 }
dea31012005-04-17 16:05:31 -05003452 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003453 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3454 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3455 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3456 elsiocb->iotag, elsiocb->iocb.ulpContext,
3457 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3458 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003459 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003460 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003461 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003462 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003463 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3464 } else {
James Smart858c9f62007-06-17 19:56:39 -05003465 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003466 }
3467
3468 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003469 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003470 if (rc == IOCB_ERROR) {
3471 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003472 return 1;
dea31012005-04-17 16:05:31 -05003473 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003474 return 0;
dea31012005-04-17 16:05:31 -05003475}
3476
James Smarte59058c2008-08-24 21:49:00 -04003477/**
James Smart3621a712009-04-06 18:47:14 -04003478 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003479 * @vport: pointer to a virtual N_Port data structure.
3480 * @rejectError:
3481 * @oldiocb: pointer to the original lpfc command iocb data structure.
3482 * @ndlp: pointer to a node-list data structure.
3483 * @mbox: pointer to the driver internal queue element for mailbox command.
3484 *
3485 * This routine prepares and issue an Reject (RJT) response IOCB
3486 * command. If a @mbox pointer is passed in, it will be put into the
3487 * context_un.mbox field of the IOCB for the completion callback function
3488 * to issue to the HBA later.
3489 *
3490 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3491 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3492 * will be stored into the context1 field of the IOCB for the completion
3493 * callback function to the reject response ELS IOCB command.
3494 *
3495 * Return code
3496 * 0 - Successfully issued reject response
3497 * 1 - Failed to issue reject response
3498 **/
dea31012005-04-17 16:05:31 -05003499int
James Smart2e0fef82007-06-17 19:56:36 -05003500lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003501 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3502 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003503{
James Smart2e0fef82007-06-17 19:56:36 -05003504 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003505 IOCB_t *icmd;
3506 IOCB_t *oldcmd;
3507 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003508 struct lpfc_sli *psli;
3509 uint8_t *pcmd;
3510 uint16_t cmdsize;
3511 int rc;
3512
3513 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003514 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003515 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3516 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003517 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003518 return 1;
dea31012005-04-17 16:05:31 -05003519
3520 icmd = &elsiocb->iocb;
3521 oldcmd = &oldiocb->iocb;
3522 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3523 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3524
3525 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003526 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003527 *((uint32_t *) (pcmd)) = rejectError;
3528
James Smart51ef4c22007-08-02 11:10:31 -04003529 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003530 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003531
dea31012005-04-17 16:05:31 -05003532 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003533 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3534 "0129 Xmit ELS RJT x%x response tag x%x "
3535 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3536 "rpi x%x\n",
3537 rejectError, elsiocb->iotag,
3538 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3539 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3541 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3542 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3543
dea31012005-04-17 16:05:31 -05003544 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003545 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003546 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003547
dea31012005-04-17 16:05:31 -05003548 if (rc == IOCB_ERROR) {
3549 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003550 return 1;
dea31012005-04-17 16:05:31 -05003551 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003552 return 0;
dea31012005-04-17 16:05:31 -05003553}
3554
James Smarte59058c2008-08-24 21:49:00 -04003555/**
James Smart3621a712009-04-06 18:47:14 -04003556 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003557 * @vport: pointer to a virtual N_Port data structure.
3558 * @oldiocb: pointer to the original lpfc command iocb data structure.
3559 * @ndlp: pointer to a node-list data structure.
3560 *
3561 * This routine prepares and issues an Accept (ACC) response to Address
3562 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3563 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3564 *
3565 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3566 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3567 * will be stored into the context1 field of the IOCB for the completion
3568 * callback function to the ADISC Accept response ELS IOCB command.
3569 *
3570 * Return code
3571 * 0 - Successfully issued acc adisc response
3572 * 1 - Failed to issue adisc acc response
3573 **/
dea31012005-04-17 16:05:31 -05003574int
James Smart2e0fef82007-06-17 19:56:36 -05003575lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3576 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003577{
James Smart2e0fef82007-06-17 19:56:36 -05003578 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003579 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003580 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003581 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003582 uint8_t *pcmd;
3583 uint16_t cmdsize;
3584 int rc;
3585
James Smart92d7f7b2007-06-17 19:56:38 -05003586 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003587 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3588 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003589 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003590 return 1;
dea31012005-04-17 16:05:31 -05003591
dea31012005-04-17 16:05:31 -05003592 icmd = &elsiocb->iocb;
3593 oldcmd = &oldiocb->iocb;
3594 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003595
3596 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003597 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3598 "0130 Xmit ADISC ACC response iotag x%x xri: "
3599 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3600 elsiocb->iotag, elsiocb->iocb.ulpContext,
3601 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3602 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003603 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3604
3605 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003606 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003607
3608 ap = (ADISC *) (pcmd);
3609 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003610 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3611 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003612 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003613
James Smart858c9f62007-06-17 19:56:39 -05003614 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3615 "Issue ACC ADISC: did:x%x flg:x%x",
3616 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3617
dea31012005-04-17 16:05:31 -05003618 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003619 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003620 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003621 if (rc == IOCB_ERROR) {
3622 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003623 return 1;
dea31012005-04-17 16:05:31 -05003624 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003625 return 0;
dea31012005-04-17 16:05:31 -05003626}
3627
James Smarte59058c2008-08-24 21:49:00 -04003628/**
James Smart3621a712009-04-06 18:47:14 -04003629 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003630 * @vport: pointer to a virtual N_Port data structure.
3631 * @oldiocb: pointer to the original lpfc command iocb data structure.
3632 * @ndlp: pointer to a node-list data structure.
3633 *
3634 * This routine prepares and issues an Accept (ACC) response to Process
3635 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3636 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3637 *
3638 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3639 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3640 * will be stored into the context1 field of the IOCB for the completion
3641 * callback function to the PRLI Accept response ELS IOCB command.
3642 *
3643 * Return code
3644 * 0 - Successfully issued acc prli response
3645 * 1 - Failed to issue acc prli response
3646 **/
dea31012005-04-17 16:05:31 -05003647int
James Smart2e0fef82007-06-17 19:56:36 -05003648lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003649 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003650{
James Smart2e0fef82007-06-17 19:56:36 -05003651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003652 PRLI *npr;
3653 lpfc_vpd_t *vpd;
3654 IOCB_t *icmd;
3655 IOCB_t *oldcmd;
3656 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003657 struct lpfc_sli *psli;
3658 uint8_t *pcmd;
3659 uint16_t cmdsize;
3660 int rc;
3661
3662 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003663
James Smart92d7f7b2007-06-17 19:56:38 -05003664 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003665 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003666 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003667 if (!elsiocb)
3668 return 1;
dea31012005-04-17 16:05:31 -05003669
dea31012005-04-17 16:05:31 -05003670 icmd = &elsiocb->iocb;
3671 oldcmd = &oldiocb->iocb;
3672 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003673 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003674 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3675 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3676 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3677 elsiocb->iotag, elsiocb->iocb.ulpContext,
3678 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3679 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003680 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3681
3682 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003683 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003684
3685 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003686 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003687
3688 npr = (PRLI *) pcmd;
3689 vpd = &phba->vpd;
3690 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003691 * If the remote port is a target and our firmware version is 3.20 or
3692 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003693 */
James Smart0d2b6b82008-06-14 22:52:47 -04003694 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3695 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003696 npr->ConfmComplAllowed = 1;
3697 npr->Retry = 1;
3698 npr->TaskRetryIdReq = 1;
3699 }
3700
3701 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3702 npr->estabImagePair = 1;
3703 npr->readXferRdyDis = 1;
3704 npr->ConfmComplAllowed = 1;
3705
3706 npr->prliType = PRLI_FCP_TYPE;
3707 npr->initiatorFunc = 1;
3708
James Smart858c9f62007-06-17 19:56:39 -05003709 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3710 "Issue ACC PRLI: did:x%x flg:x%x",
3711 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3712
dea31012005-04-17 16:05:31 -05003713 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003714 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003715
James Smart3772a992009-05-22 14:50:54 -04003716 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003717 if (rc == IOCB_ERROR) {
3718 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003719 return 1;
dea31012005-04-17 16:05:31 -05003720 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003721 return 0;
dea31012005-04-17 16:05:31 -05003722}
3723
James Smarte59058c2008-08-24 21:49:00 -04003724/**
James Smart3621a712009-04-06 18:47:14 -04003725 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003726 * @vport: pointer to a virtual N_Port data structure.
3727 * @format: rnid command format.
3728 * @oldiocb: pointer to the original lpfc command iocb data structure.
3729 * @ndlp: pointer to a node-list data structure.
3730 *
3731 * This routine issues a Request Node Identification Data (RNID) Accept
3732 * (ACC) response. It constructs the RNID ACC response command according to
3733 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3734 * issue the response. Note that this command does not need to hold the ndlp
3735 * reference count for the callback. So, the ndlp reference count taken by
3736 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3737 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3738 * there is no ndlp reference available.
3739 *
3740 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3741 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3742 * will be stored into the context1 field of the IOCB for the completion
3743 * callback function. However, for the RNID Accept Response ELS command,
3744 * this is undone later by this routine after the IOCB is allocated.
3745 *
3746 * Return code
3747 * 0 - Successfully issued acc rnid response
3748 * 1 - Failed to issue acc rnid response
3749 **/
dea31012005-04-17 16:05:31 -05003750static int
James Smart2e0fef82007-06-17 19:56:36 -05003751lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003752 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003753{
James Smart2e0fef82007-06-17 19:56:36 -05003754 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003755 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003756 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003757 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003758 struct lpfc_sli *psli;
3759 uint8_t *pcmd;
3760 uint16_t cmdsize;
3761 int rc;
3762
3763 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003764 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3765 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003766 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003767 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003768
James Smart2e0fef82007-06-17 19:56:36 -05003769 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3770 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003771 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003772 return 1;
dea31012005-04-17 16:05:31 -05003773
dea31012005-04-17 16:05:31 -05003774 icmd = &elsiocb->iocb;
3775 oldcmd = &oldiocb->iocb;
3776 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003777 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003778 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3779 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3780 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003781 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003782 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003783 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003784
James Smart92d7f7b2007-06-17 19:56:38 -05003785 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003786 rn = (RNID *) (pcmd);
3787 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003788 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3789 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3790 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003791 switch (format) {
3792 case 0:
3793 rn->SpecificLen = 0;
3794 break;
3795 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003796 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003797 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003798 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003799 rn->un.topologyDisc.unitType = RNID_HBA;
3800 rn->un.topologyDisc.physPort = 0;
3801 rn->un.topologyDisc.attachedNodes = 0;
3802 break;
3803 default:
3804 rn->CommonLen = 0;
3805 rn->SpecificLen = 0;
3806 break;
3807 }
3808
James Smart858c9f62007-06-17 19:56:39 -05003809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3810 "Issue ACC RNID: did:x%x flg:x%x",
3811 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3812
dea31012005-04-17 16:05:31 -05003813 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003814 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003815 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003816 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3817 * it could be freed */
3818
James Smart3772a992009-05-22 14:50:54 -04003819 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003820 if (rc == IOCB_ERROR) {
3821 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003822 return 1;
dea31012005-04-17 16:05:31 -05003823 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003824 return 0;
dea31012005-04-17 16:05:31 -05003825}
3826
James Smarte59058c2008-08-24 21:49:00 -04003827/**
James Smart3621a712009-04-06 18:47:14 -04003828 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003829 * @vport: pointer to a host virtual N_Port data structure.
3830 *
3831 * This routine issues Address Discover (ADISC) ELS commands to those
3832 * N_Ports which are in node port recovery state and ADISC has not been issued
3833 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3834 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3835 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3836 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3837 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3838 * IOCBs quit for later pick up. On the other hand, after walking through
3839 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3840 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3841 * no more ADISC need to be sent.
3842 *
3843 * Return code
3844 * The number of N_Ports with adisc issued.
3845 **/
dea31012005-04-17 16:05:31 -05003846int
James Smart2e0fef82007-06-17 19:56:36 -05003847lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003848{
James Smart2e0fef82007-06-17 19:56:36 -05003849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003850 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003851 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003852
James Smart685f0bf2007-04-25 09:53:08 -04003853 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003854 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003855 if (!NLP_CHK_NODE_ACT(ndlp))
3856 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003857 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3858 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3859 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003860 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003861 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003862 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003863 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003864 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3865 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003866 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003867 vport->num_disc_nodes++;
3868 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003869 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003870 spin_lock_irq(shost->host_lock);
3871 vport->fc_flag |= FC_NLP_MORE;
3872 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003873 break;
dea31012005-04-17 16:05:31 -05003874 }
3875 }
3876 }
3877 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003878 spin_lock_irq(shost->host_lock);
3879 vport->fc_flag &= ~FC_NLP_MORE;
3880 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003881 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003882 return sentadisc;
dea31012005-04-17 16:05:31 -05003883}
3884
James Smarte59058c2008-08-24 21:49:00 -04003885/**
James Smart3621a712009-04-06 18:47:14 -04003886 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003887 * @vport: pointer to a host virtual N_Port data structure.
3888 *
3889 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3890 * which are in node port recovery state, with a @vport. Each time an ELS
3891 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3892 * the per @vport number of discover count (num_disc_nodes) shall be
3893 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3894 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3895 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3896 * later pick up. On the other hand, after walking through all the ndlps with
3897 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3898 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3899 * PLOGI need to be sent.
3900 *
3901 * Return code
3902 * The number of N_Ports with plogi issued.
3903 **/
dea31012005-04-17 16:05:31 -05003904int
James Smart2e0fef82007-06-17 19:56:36 -05003905lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003906{
James Smart2e0fef82007-06-17 19:56:36 -05003907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003908 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003909 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003910
James Smart2e0fef82007-06-17 19:56:36 -05003911 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3912 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003913 if (!NLP_CHK_NODE_ACT(ndlp))
3914 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003915 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3916 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3917 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3918 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3919 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003920 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3921 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003922 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003923 vport->num_disc_nodes++;
3924 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003925 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003926 spin_lock_irq(shost->host_lock);
3927 vport->fc_flag |= FC_NLP_MORE;
3928 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003929 break;
dea31012005-04-17 16:05:31 -05003930 }
3931 }
3932 }
James Smart87af33f2007-10-27 13:37:43 -04003933 if (sentplogi) {
3934 lpfc_set_disctmo(vport);
3935 }
3936 else {
James Smart2e0fef82007-06-17 19:56:36 -05003937 spin_lock_irq(shost->host_lock);
3938 vport->fc_flag &= ~FC_NLP_MORE;
3939 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003940 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003941 return sentplogi;
dea31012005-04-17 16:05:31 -05003942}
3943
James Smarte59058c2008-08-24 21:49:00 -04003944/**
James Smart3621a712009-04-06 18:47:14 -04003945 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003946 * @vport: pointer to a host virtual N_Port data structure.
3947 *
3948 * This routine cleans up any Registration State Change Notification
3949 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3950 * @vport together with the host_lock is used to prevent multiple thread
3951 * trying to access the RSCN array on a same @vport at the same time.
3952 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003953void
James Smart2e0fef82007-06-17 19:56:36 -05003954lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003955{
James Smart2e0fef82007-06-17 19:56:36 -05003956 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3957 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003958 int i;
3959
James Smart7f5f3d02008-02-08 18:50:14 -05003960 spin_lock_irq(shost->host_lock);
3961 if (vport->fc_rscn_flush) {
3962 /* Another thread is walking fc_rscn_id_list on this vport */
3963 spin_unlock_irq(shost->host_lock);
3964 return;
3965 }
3966 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3967 vport->fc_rscn_flush = 1;
3968 spin_unlock_irq(shost->host_lock);
3969
James Smart2e0fef82007-06-17 19:56:36 -05003970 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003971 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003972 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003973 }
James Smart2e0fef82007-06-17 19:56:36 -05003974 spin_lock_irq(shost->host_lock);
3975 vport->fc_rscn_id_cnt = 0;
3976 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3977 spin_unlock_irq(shost->host_lock);
3978 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003979 /* Indicate we are done walking this fc_rscn_id_list */
3980 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003981}
3982
James Smarte59058c2008-08-24 21:49:00 -04003983/**
James Smart3621a712009-04-06 18:47:14 -04003984 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003985 * @vport: pointer to a host virtual N_Port data structure.
3986 * @did: remote destination port identifier.
3987 *
3988 * This routine checks whether there is any pending Registration State
3989 * Configuration Notification (RSCN) to a @did on @vport.
3990 *
3991 * Return code
3992 * None zero - The @did matched with a pending rscn
3993 * 0 - not able to match @did with a pending rscn
3994 **/
dea31012005-04-17 16:05:31 -05003995int
James Smart2e0fef82007-06-17 19:56:36 -05003996lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003997{
3998 D_ID ns_did;
3999 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004000 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004001 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004002 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004003
4004 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004005
4006 /* Never match fabric nodes for RSCNs */
4007 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004008 return 0;
dea31012005-04-17 16:05:31 -05004009
4010 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004011 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004012 return did;
dea31012005-04-17 16:05:31 -05004013
James Smart7f5f3d02008-02-08 18:50:14 -05004014 spin_lock_irq(shost->host_lock);
4015 if (vport->fc_rscn_flush) {
4016 /* Another thread is walking fc_rscn_id_list on this vport */
4017 spin_unlock_irq(shost->host_lock);
4018 return 0;
4019 }
4020 /* Indicate we are walking fc_rscn_id_list on this vport */
4021 vport->fc_rscn_flush = 1;
4022 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004023 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004024 lp = vport->fc_rscn_id_list[i]->virt;
4025 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4026 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004027 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004028 rscn_did.un.word = be32_to_cpu(*lp++);
4029 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004030 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4031 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004032 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4033 && (ns_did.un.b.area == rscn_did.un.b.area)
4034 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004035 goto return_did_out;
dea31012005-04-17 16:05:31 -05004036 break;
James Smarteaf15d52008-12-04 22:39:29 -05004037 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004038 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4039 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004040 goto return_did_out;
dea31012005-04-17 16:05:31 -05004041 break;
James Smarteaf15d52008-12-04 22:39:29 -05004042 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004043 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004044 goto return_did_out;
dea31012005-04-17 16:05:31 -05004045 break;
James Smarteaf15d52008-12-04 22:39:29 -05004046 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004047 goto return_did_out;
dea31012005-04-17 16:05:31 -05004048 }
4049 }
James Smart92d7f7b2007-06-17 19:56:38 -05004050 }
James Smart7f5f3d02008-02-08 18:50:14 -05004051 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4052 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004053 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004054return_did_out:
4055 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4056 vport->fc_rscn_flush = 0;
4057 return did;
dea31012005-04-17 16:05:31 -05004058}
4059
James Smarte59058c2008-08-24 21:49:00 -04004060/**
James Smart3621a712009-04-06 18:47:14 -04004061 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004062 * @vport: pointer to a host virtual N_Port data structure.
4063 *
4064 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4065 * state machine for a @vport's nodes that are with pending RSCN (Registration
4066 * State Change Notification).
4067 *
4068 * Return code
4069 * 0 - Successful (currently alway return 0)
4070 **/
dea31012005-04-17 16:05:31 -05004071static int
James Smart2e0fef82007-06-17 19:56:36 -05004072lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004073{
James Smart685f0bf2007-04-25 09:53:08 -04004074 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004075
James Smart0d2b6b82008-06-14 22:52:47 -04004076 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004077 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004078 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004079 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4080 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004081 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004082 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004083 NLP_EVT_DEVICE_RECOVERY);
4084 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004085 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004086 return 0;
dea31012005-04-17 16:05:31 -05004087}
4088
James Smarte59058c2008-08-24 21:49:00 -04004089/**
James Smart3621a712009-04-06 18:47:14 -04004090 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004091 * @vport: pointer to a host virtual N_Port data structure.
4092 * @cmdiocb: pointer to lpfc command iocb data structure.
4093 *
4094 * lpfc_send_rscn_event sends an RSCN netlink event to management
4095 * applications.
4096 */
4097static void
4098lpfc_send_rscn_event(struct lpfc_vport *vport,
4099 struct lpfc_iocbq *cmdiocb)
4100{
4101 struct lpfc_dmabuf *pcmd;
4102 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4103 uint32_t *payload_ptr;
4104 uint32_t payload_len;
4105 struct lpfc_rscn_event_header *rscn_event_data;
4106
4107 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4108 payload_ptr = (uint32_t *) pcmd->virt;
4109 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4110
4111 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4112 payload_len, GFP_KERNEL);
4113 if (!rscn_event_data) {
4114 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4115 "0147 Failed to allocate memory for RSCN event\n");
4116 return;
4117 }
4118 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4119 rscn_event_data->payload_length = payload_len;
4120 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4121 payload_len);
4122
4123 fc_host_post_vendor_event(shost,
4124 fc_get_event_number(),
4125 sizeof(struct lpfc_els_event_header) + payload_len,
4126 (char *)rscn_event_data,
4127 LPFC_NL_VENDOR_ID);
4128
4129 kfree(rscn_event_data);
4130}
4131
4132/**
James Smart3621a712009-04-06 18:47:14 -04004133 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004134 * @vport: pointer to a host virtual N_Port data structure.
4135 * @cmdiocb: pointer to lpfc command iocb data structure.
4136 * @ndlp: pointer to a node-list data structure.
4137 *
4138 * This routine processes an unsolicited RSCN (Registration State Change
4139 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4140 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4141 * discover state machine is about to begin discovery, it just accepts the
4142 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4143 * contains N_Port IDs for other vports on this HBA, it just accepts the
4144 * RSCN and ignore processing it. If the state machine is in the recovery
4145 * state, the fc_rscn_id_list of this @vport is walked and the
4146 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4147 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4148 * routine is invoked to handle the RSCN event.
4149 *
4150 * Return code
4151 * 0 - Just sent the acc response
4152 * 1 - Sent the acc response and waited for name server completion
4153 **/
dea31012005-04-17 16:05:31 -05004154static int
James Smart2e0fef82007-06-17 19:56:36 -05004155lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004156 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004157{
James Smart2e0fef82007-06-17 19:56:36 -05004158 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4159 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004160 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004161 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004162 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004163 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004164 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004165 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004166 int i;
dea31012005-04-17 16:05:31 -05004167
4168 icmd = &cmdiocb->iocb;
4169 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4170 lp = (uint32_t *) pcmd->virt;
4171
James Smart92d7f7b2007-06-17 19:56:38 -05004172 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4173 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004174 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004175 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4176 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004177 vport->fc_flag, payload_len, *lp,
4178 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004179
4180 /* Send an RSCN event to the management application */
4181 lpfc_send_rscn_event(vport, cmdiocb);
4182
James Smartd2873e42006-08-18 17:46:43 -04004183 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004184 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004185 FCH_EVT_RSCN, lp[i]);
4186
dea31012005-04-17 16:05:31 -05004187 /* If we are about to begin discovery, just ACC the RSCN.
4188 * Discovery processing will satisfy it.
4189 */
James Smart2e0fef82007-06-17 19:56:36 -05004190 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004191 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4192 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4193 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4194
James Smart51ef4c22007-08-02 11:10:31 -04004195 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004196 return 0;
dea31012005-04-17 16:05:31 -05004197 }
4198
James Smart92d7f7b2007-06-17 19:56:38 -05004199 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4200 * just ACC and ignore it.
4201 */
4202 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004203 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004204 i = payload_len;
4205 datap = lp;
4206 while (i > 0) {
4207 nportid = *datap++;
4208 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4209 i -= sizeof(uint32_t);
4210 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004211 if (lpfc_find_vport_by_did(phba, nportid))
4212 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004213 }
4214 if (rscn_id == hba_id) {
4215 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004216 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004217 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004218 "Data: x%x x%x x%x x%x\n",
4219 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004220 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004221 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4222 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4223 ndlp->nlp_DID, vport->port_state,
4224 ndlp->nlp_flag);
4225
James Smart92d7f7b2007-06-17 19:56:38 -05004226 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004227 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004228 return 0;
4229 }
4230 }
4231
James Smart7f5f3d02008-02-08 18:50:14 -05004232 spin_lock_irq(shost->host_lock);
4233 if (vport->fc_rscn_flush) {
4234 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004235 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004236 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004237 /* Send back ACC */
4238 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004239 return 0;
4240 }
4241 /* Indicate we are walking fc_rscn_id_list on this vport */
4242 vport->fc_rscn_flush = 1;
4243 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004244 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004245 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004246 /* If we are already processing an RSCN, save the received
4247 * RSCN payload buffer, cmdiocb->context2 to process later.
4248 */
James Smart2e0fef82007-06-17 19:56:36 -05004249 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004250 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4251 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4252 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4253
James Smart09372822008-01-11 01:52:54 -05004254 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004255 vport->fc_flag |= FC_RSCN_DEFERRED;
4256 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004257 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004258 vport->fc_flag |= FC_RSCN_MODE;
4259 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004260 if (rscn_cnt) {
4261 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4262 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4263 }
4264 if ((rscn_cnt) &&
4265 (payload_len + length <= LPFC_BPL_SIZE)) {
4266 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004267 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004268 memcpy(((uint8_t *)cmd) + length, lp,
4269 payload_len);
4270 } else {
4271 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4272 vport->fc_rscn_id_cnt++;
4273 /* If we zero, cmdiocb->context2, the calling
4274 * routine will not try to free it.
4275 */
4276 cmdiocb->context2 = NULL;
4277 }
dea31012005-04-17 16:05:31 -05004278 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004279 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4280 "0235 Deferred RSCN "
4281 "Data: x%x x%x x%x\n",
4282 vport->fc_rscn_id_cnt, vport->fc_flag,
4283 vport->port_state);
dea31012005-04-17 16:05:31 -05004284 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004285 vport->fc_flag |= FC_RSCN_DISCOVERY;
4286 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004287 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004288 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4289 "0234 ReDiscovery RSCN "
4290 "Data: x%x x%x x%x\n",
4291 vport->fc_rscn_id_cnt, vport->fc_flag,
4292 vport->port_state);
dea31012005-04-17 16:05:31 -05004293 }
James Smart7f5f3d02008-02-08 18:50:14 -05004294 /* Indicate we are done walking fc_rscn_id_list on this vport */
4295 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004296 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004297 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004298 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004299 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004300 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004301 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004302 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004303 return 0;
dea31012005-04-17 16:05:31 -05004304 }
James Smart858c9f62007-06-17 19:56:39 -05004305 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4306 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4307 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4308
James Smart2e0fef82007-06-17 19:56:36 -05004309 spin_lock_irq(shost->host_lock);
4310 vport->fc_flag |= FC_RSCN_MODE;
4311 spin_unlock_irq(shost->host_lock);
4312 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004313 /* Indicate we are done walking fc_rscn_id_list on this vport */
4314 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004315 /*
4316 * If we zero, cmdiocb->context2, the calling routine will
4317 * not try to free it.
4318 */
4319 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004320 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004321 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004322 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004323 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004324 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004325 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004326}
4327
James Smarte59058c2008-08-24 21:49:00 -04004328/**
James Smart3621a712009-04-06 18:47:14 -04004329 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004330 * @vport: pointer to a host virtual N_Port data structure.
4331 *
4332 * This routine handles the Registration State Configuration Notification
4333 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4334 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4335 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4336 * NameServer shall be issued. If CT command to the NameServer fails to be
4337 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4338 * RSCN activities with the @vport.
4339 *
4340 * Return code
4341 * 0 - Cleaned up rscn on the @vport
4342 * 1 - Wait for plogi to name server before proceed
4343 **/
dea31012005-04-17 16:05:31 -05004344int
James Smart2e0fef82007-06-17 19:56:36 -05004345lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004346{
4347 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004348 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004349
James Smart92d7f7b2007-06-17 19:56:38 -05004350 /* Ignore RSCN if the port is being torn down. */
4351 if (vport->load_flag & FC_UNLOADING) {
4352 lpfc_els_flush_rscn(vport);
4353 return 0;
4354 }
4355
dea31012005-04-17 16:05:31 -05004356 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004357 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004358
4359 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004360 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4361 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4362 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4363 vport->port_state);
dea31012005-04-17 16:05:31 -05004364
4365 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004366 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004367 vport->num_disc_nodes = 0;
4368
James Smart2e0fef82007-06-17 19:56:36 -05004369 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004370 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4371 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004372 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004373 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004374 /* Wait for NameServer query cmpl before we can
4375 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004376 return 1;
dea31012005-04-17 16:05:31 -05004377 } else {
4378 /* If login to NameServer does not exist, issue one */
4379 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004380 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004381 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004382 /* Wait for NameServer login cmpl before we can
4383 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004384 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004385
James Smarte47c9092008-02-08 18:49:26 -05004386 if (ndlp) {
4387 ndlp = lpfc_enable_node(vport, ndlp,
4388 NLP_STE_PLOGI_ISSUE);
4389 if (!ndlp) {
4390 lpfc_els_flush_rscn(vport);
4391 return 0;
4392 }
4393 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004394 } else {
James Smarte47c9092008-02-08 18:49:26 -05004395 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4396 if (!ndlp) {
4397 lpfc_els_flush_rscn(vport);
4398 return 0;
4399 }
James Smart2e0fef82007-06-17 19:56:36 -05004400 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004401 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004402 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004403 }
James Smarte47c9092008-02-08 18:49:26 -05004404 ndlp->nlp_type |= NLP_FABRIC;
4405 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4406 /* Wait for NameServer login cmpl before we can
4407 * continue
4408 */
4409 return 1;
dea31012005-04-17 16:05:31 -05004410 }
4411
James Smart2e0fef82007-06-17 19:56:36 -05004412 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004413 return 0;
dea31012005-04-17 16:05:31 -05004414}
4415
James Smarte59058c2008-08-24 21:49:00 -04004416/**
James Smart3621a712009-04-06 18:47:14 -04004417 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004418 * @vport: pointer to a host virtual N_Port data structure.
4419 * @cmdiocb: pointer to lpfc command iocb data structure.
4420 * @ndlp: pointer to a node-list data structure.
4421 *
4422 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4423 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4424 * point topology. As an unsolicited FLOGI should not be received in a loop
4425 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4426 * lpfc_check_sparm() routine is invoked to check the parameters in the
4427 * unsolicited FLOGI. If parameters validation failed, the routine
4428 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4429 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4430 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4431 * will initiate PLOGI. The higher lexicographical value party shall has
4432 * higher priority (as the winning port) and will initiate PLOGI and
4433 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4434 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4435 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4436 *
4437 * Return code
4438 * 0 - Successfully processed the unsolicited flogi
4439 * 1 - Failed to process the unsolicited flogi
4440 **/
dea31012005-04-17 16:05:31 -05004441static int
James Smart2e0fef82007-06-17 19:56:36 -05004442lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004443 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004444{
James Smart2e0fef82007-06-17 19:56:36 -05004445 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4446 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004447 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4448 uint32_t *lp = (uint32_t *) pcmd->virt;
4449 IOCB_t *icmd = &cmdiocb->iocb;
4450 struct serv_parm *sp;
4451 LPFC_MBOXQ_t *mbox;
4452 struct ls_rjt stat;
4453 uint32_t cmd, did;
4454 int rc;
4455
4456 cmd = *lp++;
4457 sp = (struct serv_parm *) lp;
4458
4459 /* FLOGI received */
4460
James Smart2e0fef82007-06-17 19:56:36 -05004461 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004462
4463 if (phba->fc_topology == TOPOLOGY_LOOP) {
4464 /* We should never receive a FLOGI in loop mode, ignore it */
4465 did = icmd->un.elsreq64.remoteID;
4466
4467 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4468 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004469 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4470 "0113 An FLOGI ELS command x%x was "
4471 "received from DID x%x in Loop Mode\n",
4472 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004473 return 1;
dea31012005-04-17 16:05:31 -05004474 }
4475
4476 did = Fabric_DID;
4477
James Smart341af102010-01-26 23:07:37 -05004478 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004479 /* For a FLOGI we accept, then if our portname is greater
4480 * then the remote portname we initiate Nport login.
4481 */
4482
James Smart2e0fef82007-06-17 19:56:36 -05004483 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004484 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004485
4486 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004487 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4488 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004489 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004490
dea31012005-04-17 16:05:31 -05004491 lpfc_linkdown(phba);
4492 lpfc_init_link(phba, mbox,
4493 phba->cfg_topology,
4494 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004495 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004496 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004497 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004498 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004499 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004500 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004501 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004502 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004503 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004504 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004505 spin_lock_irq(shost->host_lock);
4506 vport->fc_flag |= FC_PT2PT_PLOGI;
4507 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004508 }
James Smart2e0fef82007-06-17 19:56:36 -05004509 spin_lock_irq(shost->host_lock);
4510 vport->fc_flag |= FC_PT2PT;
4511 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4512 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004513 } else {
4514 /* Reject this request because invalid parameters */
4515 stat.un.b.lsRjtRsvd0 = 0;
4516 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4517 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4518 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004519 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4520 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004521 return 1;
dea31012005-04-17 16:05:31 -05004522 }
4523
4524 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004525 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004526
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004527 return 0;
dea31012005-04-17 16:05:31 -05004528}
4529
James Smarte59058c2008-08-24 21:49:00 -04004530/**
James Smart3621a712009-04-06 18:47:14 -04004531 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004532 * @vport: pointer to a host virtual N_Port data structure.
4533 * @cmdiocb: pointer to lpfc command iocb data structure.
4534 * @ndlp: pointer to a node-list data structure.
4535 *
4536 * This routine processes Request Node Identification Data (RNID) IOCB
4537 * received as an ELS unsolicited event. Only when the RNID specified format
4538 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4539 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4540 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4541 * rejected by invoking the lpfc_els_rsp_reject() routine.
4542 *
4543 * Return code
4544 * 0 - Successfully processed rnid iocb (currently always return 0)
4545 **/
dea31012005-04-17 16:05:31 -05004546static int
James Smart2e0fef82007-06-17 19:56:36 -05004547lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4548 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004549{
4550 struct lpfc_dmabuf *pcmd;
4551 uint32_t *lp;
4552 IOCB_t *icmd;
4553 RNID *rn;
4554 struct ls_rjt stat;
4555 uint32_t cmd, did;
4556
4557 icmd = &cmdiocb->iocb;
4558 did = icmd->un.elsreq64.remoteID;
4559 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4560 lp = (uint32_t *) pcmd->virt;
4561
4562 cmd = *lp++;
4563 rn = (RNID *) lp;
4564
4565 /* RNID received */
4566
4567 switch (rn->Format) {
4568 case 0:
4569 case RNID_TOPOLOGY_DISC:
4570 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004571 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004572 break;
4573 default:
4574 /* Reject this request because format not supported */
4575 stat.un.b.lsRjtRsvd0 = 0;
4576 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4577 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4578 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004579 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4580 NULL);
dea31012005-04-17 16:05:31 -05004581 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004582 return 0;
dea31012005-04-17 16:05:31 -05004583}
4584
James Smarte59058c2008-08-24 21:49:00 -04004585/**
James Smart3621a712009-04-06 18:47:14 -04004586 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004587 * @vport: pointer to a host virtual N_Port data structure.
4588 * @cmdiocb: pointer to lpfc command iocb data structure.
4589 * @ndlp: pointer to a node-list data structure.
4590 *
4591 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4592 * received as an ELS unsolicited event. Currently, this function just invokes
4593 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4594 *
4595 * Return code
4596 * 0 - Successfully processed lirr iocb (currently always return 0)
4597 **/
dea31012005-04-17 16:05:31 -05004598static int
James Smart2e0fef82007-06-17 19:56:36 -05004599lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4600 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004601{
4602 struct ls_rjt stat;
4603
4604 /* For now, unconditionally reject this command */
4605 stat.un.b.lsRjtRsvd0 = 0;
4606 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4607 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4608 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004609 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004610 return 0;
4611}
4612
James Smarte59058c2008-08-24 21:49:00 -04004613/**
James Smart5ffc2662009-11-18 15:39:44 -05004614 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4615 * @vport: pointer to a host virtual N_Port data structure.
4616 * @cmdiocb: pointer to lpfc command iocb data structure.
4617 * @ndlp: pointer to a node-list data structure.
4618 *
4619 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4620 * received as an ELS unsolicited event. A request to RRQ shall only
4621 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4622 * Nx_Port N_Port_ID of the target Exchange is the same as the
4623 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4624 * not accepted, an LS_RJT with reason code "Unable to perform
4625 * command request" and reason code explanation "Invalid Originator
4626 * S_ID" shall be returned. For now, we just unconditionally accept
4627 * RRQ from the target.
4628 **/
4629static void
4630lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4631 struct lpfc_nodelist *ndlp)
4632{
4633 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4634}
4635
4636/**
James Smart3621a712009-04-06 18:47:14 -04004637 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004638 * @phba: pointer to lpfc hba data structure.
4639 * @pmb: pointer to the driver internal queue element for mailbox command.
4640 *
4641 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4642 * mailbox command. This callback function is to actually send the Accept
4643 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4644 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4645 * mailbox command, constructs the RPS response with the link statistics
4646 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4647 * response to the RPS.
4648 *
4649 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4650 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4651 * will be stored into the context1 field of the IOCB for the completion
4652 * callback function to the RPS Accept Response ELS IOCB command.
4653 *
4654 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004655static void
James Smart329f9bc2007-04-25 09:53:01 -04004656lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004657{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004658 MAILBOX_t *mb;
4659 IOCB_t *icmd;
4660 RPS_RSP *rps_rsp;
4661 uint8_t *pcmd;
4662 struct lpfc_iocbq *elsiocb;
4663 struct lpfc_nodelist *ndlp;
4664 uint16_t xri, status;
4665 uint32_t cmdsize;
4666
James Smart04c68492009-05-22 14:52:52 -04004667 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004668
4669 ndlp = (struct lpfc_nodelist *) pmb->context2;
4670 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004671 pmb->context1 = NULL;
4672 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004673
4674 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004675 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004676 return;
4677 }
4678
4679 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004680 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004681 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4682 lpfc_max_els_tries, ndlp,
4683 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004684
4685 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004686 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004687
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004688 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004689 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004690
4691 icmd = &elsiocb->iocb;
4692 icmd->ulpContext = xri;
4693
4694 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4695 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004696 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004697 rps_rsp = (RPS_RSP *)pcmd;
4698
4699 if (phba->fc_topology != TOPOLOGY_LOOP)
4700 status = 0x10;
4701 else
4702 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004703 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004704 status |= 0x4;
4705
4706 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004707 rps_rsp->portStatus = cpu_to_be16(status);
4708 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4709 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4710 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4711 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4712 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4713 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004714 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004715 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4716 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4717 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4718 elsiocb->iotag, elsiocb->iocb.ulpContext,
4719 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4720 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004721 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004722 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004723 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004724 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004725 return;
4726}
4727
James Smarte59058c2008-08-24 21:49:00 -04004728/**
James Smart3621a712009-04-06 18:47:14 -04004729 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004730 * @vport: pointer to a host virtual N_Port data structure.
4731 * @cmdiocb: pointer to lpfc command iocb data structure.
4732 * @ndlp: pointer to a node-list data structure.
4733 *
4734 * This routine processes Read Port Status (RPS) IOCB received as an
4735 * ELS unsolicited event. It first checks the remote port state. If the
4736 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4737 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4738 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4739 * for reading the HBA link statistics. It is for the callback function,
4740 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4741 * to actually sending out RPS Accept (ACC) response.
4742 *
4743 * Return codes
4744 * 0 - Successfully processed rps iocb (currently always return 0)
4745 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004746static int
James Smart2e0fef82007-06-17 19:56:36 -05004747lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4748 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004749{
James Smart2e0fef82007-06-17 19:56:36 -05004750 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004751 uint32_t *lp;
4752 uint8_t flag;
4753 LPFC_MBOXQ_t *mbox;
4754 struct lpfc_dmabuf *pcmd;
4755 RPS *rps;
4756 struct ls_rjt stat;
4757
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004758 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004759 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4760 /* reject the unsolicited RPS request and done with it */
4761 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004762
4763 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4764 lp = (uint32_t *) pcmd->virt;
4765 flag = (be32_to_cpu(*lp++) & 0xf);
4766 rps = (RPS *) lp;
4767
4768 if ((flag == 0) ||
4769 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004770 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004771 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004772
James Smart92d7f7b2007-06-17 19:56:38 -05004773 printk("Fix me....\n");
4774 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004775 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4776 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004777 lpfc_read_lnk_stat(phba, mbox);
4778 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004779 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004780 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004781 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004782 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004783 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004784 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004785 /* Mbox completion will send ELS Response */
4786 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004787 /* Decrement reference count used for the failed mbox
4788 * command.
4789 */
James Smart329f9bc2007-04-25 09:53:01 -04004790 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004791 mempool_free(mbox, phba->mbox_mem_pool);
4792 }
4793 }
James Smart90160e02008-08-24 21:49:45 -04004794
4795reject_out:
4796 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004797 stat.un.b.lsRjtRsvd0 = 0;
4798 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4799 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4800 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004801 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004802 return 0;
4803}
4804
James Smarte59058c2008-08-24 21:49:00 -04004805/**
James Smart3621a712009-04-06 18:47:14 -04004806 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004807 * @vport: pointer to a host virtual N_Port data structure.
4808 * @cmdsize: size of the ELS command.
4809 * @oldiocb: pointer to the original lpfc command iocb data structure.
4810 * @ndlp: pointer to a node-list data structure.
4811 *
4812 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4813 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4814 *
4815 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4816 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4817 * will be stored into the context1 field of the IOCB for the completion
4818 * callback function to the RPL Accept Response ELS command.
4819 *
4820 * Return code
4821 * 0 - Successfully issued ACC RPL ELS command
4822 * 1 - Failed to issue ACC RPL ELS command
4823 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004824static int
James Smart2e0fef82007-06-17 19:56:36 -05004825lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4826 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004827{
James Smart2e0fef82007-06-17 19:56:36 -05004828 struct lpfc_hba *phba = vport->phba;
4829 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004830 RPL_RSP rpl_rsp;
4831 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004832 uint8_t *pcmd;
4833
James Smart2e0fef82007-06-17 19:56:36 -05004834 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4835 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004836
James Smart488d1462006-03-07 15:02:37 -05004837 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004838 return 1;
James Smart488d1462006-03-07 15:02:37 -05004839
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004840 icmd = &elsiocb->iocb;
4841 oldcmd = &oldiocb->iocb;
4842 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4843
4844 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4845 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004846 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004847 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4848 pcmd += sizeof(uint16_t);
4849
4850 /* Setup the RPL ACC payload */
4851 rpl_rsp.listLen = be32_to_cpu(1);
4852 rpl_rsp.index = 0;
4853 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004854 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4855 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004856 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004857 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004858 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004859 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4860 "0120 Xmit ELS RPL ACC response tag x%x "
4861 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4862 "rpi x%x\n",
4863 elsiocb->iotag, elsiocb->iocb.ulpContext,
4864 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4865 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004866 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004867 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004868 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4869 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004870 lpfc_els_free_iocb(phba, elsiocb);
4871 return 1;
4872 }
4873 return 0;
4874}
4875
James Smarte59058c2008-08-24 21:49:00 -04004876/**
James Smart3621a712009-04-06 18:47:14 -04004877 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004878 * @vport: pointer to a host virtual N_Port data structure.
4879 * @cmdiocb: pointer to lpfc command iocb data structure.
4880 * @ndlp: pointer to a node-list data structure.
4881 *
4882 * This routine processes Read Port List (RPL) IOCB received as an ELS
4883 * unsolicited event. It first checks the remote port state. If the remote
4884 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4885 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4886 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4887 * to accept the RPL.
4888 *
4889 * Return code
4890 * 0 - Successfully processed rpl iocb (currently always return 0)
4891 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004892static int
James Smart2e0fef82007-06-17 19:56:36 -05004893lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4894 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004895{
4896 struct lpfc_dmabuf *pcmd;
4897 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004898 uint32_t maxsize;
4899 uint16_t cmdsize;
4900 RPL *rpl;
4901 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004902
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004903 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4904 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004905 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004906 stat.un.b.lsRjtRsvd0 = 0;
4907 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4908 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4909 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004910 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4911 NULL);
James Smart90160e02008-08-24 21:49:45 -04004912 /* rejected the unsolicited RPL request and done with it */
4913 return 0;
dea31012005-04-17 16:05:31 -05004914 }
4915
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004916 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4917 lp = (uint32_t *) pcmd->virt;
4918 rpl = (RPL *) (lp + 1);
4919
4920 maxsize = be32_to_cpu(rpl->maxsize);
4921
4922 /* We support only one port */
4923 if ((rpl->index == 0) &&
4924 ((maxsize == 0) ||
4925 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4926 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004927 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004928 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4929 }
James Smart2e0fef82007-06-17 19:56:36 -05004930 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004931
4932 return 0;
4933}
4934
James Smarte59058c2008-08-24 21:49:00 -04004935/**
James Smart3621a712009-04-06 18:47:14 -04004936 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004937 * @vport: pointer to a virtual N_Port data structure.
4938 * @cmdiocb: pointer to lpfc command iocb data structure.
4939 * @ndlp: pointer to a node-list data structure.
4940 *
4941 * This routine processes Fibre Channel Address Resolution Protocol
4942 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4943 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4944 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4945 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4946 * remote PortName is compared against the FC PortName stored in the @vport
4947 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4948 * compared against the FC NodeName stored in the @vport data structure.
4949 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4950 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4951 * invoked to send out FARP Response to the remote node. Before sending the
4952 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4953 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4954 * routine is invoked to log into the remote port first.
4955 *
4956 * Return code
4957 * 0 - Either the FARP Match Mode not supported or successfully processed
4958 **/
dea31012005-04-17 16:05:31 -05004959static int
James Smart2e0fef82007-06-17 19:56:36 -05004960lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4961 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004962{
4963 struct lpfc_dmabuf *pcmd;
4964 uint32_t *lp;
4965 IOCB_t *icmd;
4966 FARP *fp;
4967 uint32_t cmd, cnt, did;
4968
4969 icmd = &cmdiocb->iocb;
4970 did = icmd->un.elsreq64.remoteID;
4971 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4972 lp = (uint32_t *) pcmd->virt;
4973
4974 cmd = *lp++;
4975 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004976 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004977 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4978 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004979 /* We will only support match on WWPN or WWNN */
4980 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004981 return 0;
dea31012005-04-17 16:05:31 -05004982 }
4983
4984 cnt = 0;
4985 /* If this FARP command is searching for my portname */
4986 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004987 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004988 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004989 cnt = 1;
4990 }
4991
4992 /* If this FARP command is searching for my nodename */
4993 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004994 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004995 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004996 cnt = 1;
4997 }
4998
4999 if (cnt) {
5000 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5001 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5002 /* Log back into the node before sending the FARP. */
5003 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005004 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005005 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005006 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005007 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005008 }
5009
5010 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005011 if (fp->Rflags & FARP_REQUEST_FARPR)
5012 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005013 }
5014 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005015 return 0;
dea31012005-04-17 16:05:31 -05005016}
5017
James Smarte59058c2008-08-24 21:49:00 -04005018/**
James Smart3621a712009-04-06 18:47:14 -04005019 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005020 * @vport: pointer to a host virtual N_Port data structure.
5021 * @cmdiocb: pointer to lpfc command iocb data structure.
5022 * @ndlp: pointer to a node-list data structure.
5023 *
5024 * This routine processes Fibre Channel Address Resolution Protocol
5025 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5026 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5027 * the FARP response request.
5028 *
5029 * Return code
5030 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5031 **/
dea31012005-04-17 16:05:31 -05005032static int
James Smart2e0fef82007-06-17 19:56:36 -05005033lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5034 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005035{
5036 struct lpfc_dmabuf *pcmd;
5037 uint32_t *lp;
5038 IOCB_t *icmd;
5039 uint32_t cmd, did;
5040
5041 icmd = &cmdiocb->iocb;
5042 did = icmd->un.elsreq64.remoteID;
5043 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5044 lp = (uint32_t *) pcmd->virt;
5045
5046 cmd = *lp++;
5047 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005048 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5049 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005050 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005051 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005052
5053 return 0;
5054}
5055
James Smarte59058c2008-08-24 21:49:00 -04005056/**
James Smart3621a712009-04-06 18:47:14 -04005057 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005058 * @vport: pointer to a host virtual N_Port data structure.
5059 * @cmdiocb: pointer to lpfc command iocb data structure.
5060 * @fan_ndlp: pointer to a node-list data structure.
5061 *
5062 * This routine processes a Fabric Address Notification (FAN) IOCB
5063 * command received as an ELS unsolicited event. The FAN ELS command will
5064 * only be processed on a physical port (i.e., the @vport represents the
5065 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5066 * compared against those in the phba data structure. If any of those is
5067 * different, the lpfc_initial_flogi() routine is invoked to initialize
5068 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5069 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5070 * is invoked to register login to the fabric.
5071 *
5072 * Return code
5073 * 0 - Successfully processed fan iocb (currently always return 0).
5074 **/
dea31012005-04-17 16:05:31 -05005075static int
James Smart2e0fef82007-06-17 19:56:36 -05005076lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5077 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005078{
James Smart2e0fef82007-06-17 19:56:36 -05005079 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005080 uint32_t *lp;
5081 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005082
James Smart0d2b6b82008-06-14 22:52:47 -04005083 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5084 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5085 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005086 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005087 if ((vport == phba->pport) &&
5088 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005089 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005090 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005091 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005092 sizeof(struct lpfc_name)))) {
5093 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005094 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005095 } else {
5096 /* FAN verified - skip FLOGI */
5097 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005098 if (phba->sli_rev < LPFC_SLI_REV4)
5099 lpfc_issue_fabric_reglogin(vport);
5100 else
5101 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005102 }
dea31012005-04-17 16:05:31 -05005103 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005104 return 0;
dea31012005-04-17 16:05:31 -05005105}
5106
James Smarte59058c2008-08-24 21:49:00 -04005107/**
James Smart3621a712009-04-06 18:47:14 -04005108 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005109 * @ptr: holder for the timer function associated data.
5110 *
5111 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5112 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5113 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5114 * up the worker thread. It is for the worker thread to invoke the routine
5115 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5116 **/
dea31012005-04-17 16:05:31 -05005117void
5118lpfc_els_timeout(unsigned long ptr)
5119{
James Smart2e0fef82007-06-17 19:56:36 -05005120 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5121 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005122 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005123 unsigned long iflag;
5124
James Smart2e0fef82007-06-17 19:56:36 -05005125 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005126 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5127 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005128 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005129 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005130
James Smart5e9d9b82008-06-14 22:52:53 -04005131 if (!tmo_posted)
5132 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005133 return;
5134}
5135
James Smarte59058c2008-08-24 21:49:00 -04005136/**
James Smart3621a712009-04-06 18:47:14 -04005137 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005138 * @vport: pointer to a virtual N_Port data structure.
5139 *
5140 * This routine is the actual handler function that processes an ELS timeout
5141 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5142 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5143 * invoking the lpfc_sli_issue_abort_iotag() routine.
5144 **/
dea31012005-04-17 16:05:31 -05005145void
James Smart2e0fef82007-06-17 19:56:36 -05005146lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005147{
James Smart2e0fef82007-06-17 19:56:36 -05005148 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005149 struct lpfc_sli_ring *pring;
5150 struct lpfc_iocbq *tmp_iocb, *piocb;
5151 IOCB_t *cmd = NULL;
5152 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005153 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005154 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005155 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005156
James Smart2e0fef82007-06-17 19:56:36 -05005157 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005158 timeout = (uint32_t)(phba->fc_ratov << 1);
5159
5160 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005161
5162 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5163 cmd = &piocb->iocb;
5164
James Smart2e0fef82007-06-17 19:56:36 -05005165 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5166 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5167 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005168 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005169
5170 if (piocb->vport != vport)
5171 continue;
5172
dea31012005-04-17 16:05:31 -05005173 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005174 if (pcmd)
5175 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005176
James Smart92d7f7b2007-06-17 19:56:38 -05005177 if (els_command == ELS_CMD_FARP ||
5178 els_command == ELS_CMD_FARPR ||
5179 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005180 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005181
dea31012005-04-17 16:05:31 -05005182 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005183 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005184 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005185 else
dea31012005-04-17 16:05:31 -05005186 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005187 continue;
5188 }
5189
James Smart2e0fef82007-06-17 19:56:36 -05005190 remote_ID = 0xffffffff;
5191 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005192 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005193 else {
5194 struct lpfc_nodelist *ndlp;
5195 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005196 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005197 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005198 }
James Smarte8b62012007-08-02 11:10:09 -04005199 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5200 "0127 ELS timeout Data: x%x x%x x%x "
5201 "x%x\n", els_command,
5202 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005203 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005204 }
James Smart2e0fef82007-06-17 19:56:36 -05005205 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005206
James Smart2e0fef82007-06-17 19:56:36 -05005207 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5208 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005209}
5210
James Smarte59058c2008-08-24 21:49:00 -04005211/**
James Smart3621a712009-04-06 18:47:14 -04005212 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005213 * @vport: pointer to a host virtual N_Port data structure.
5214 *
5215 * This routine is used to clean up all the outstanding ELS commands on a
5216 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5217 * routine. After that, it walks the ELS transmit queue to remove all the
5218 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5219 * the IOCBs with a non-NULL completion callback function, the callback
5220 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5221 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5222 * callback function, the IOCB will simply be released. Finally, it walks
5223 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5224 * completion queue IOCB that is associated with the @vport and is not
5225 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5226 * part of the discovery state machine) out to HBA by invoking the
5227 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5228 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5229 * the IOCBs are aborted when this function returns.
5230 **/
dea31012005-04-17 16:05:31 -05005231void
James Smart2e0fef82007-06-17 19:56:36 -05005232lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005233{
James Smart2534ba72007-04-25 09:52:20 -04005234 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005235 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005236 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005237 struct lpfc_iocbq *tmp_iocb, *piocb;
5238 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005239
5240 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005241
James Smart2e0fef82007-06-17 19:56:36 -05005242 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005243 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5244 cmd = &piocb->iocb;
5245
5246 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5247 continue;
5248 }
5249
5250 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005251 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5252 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5253 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5254 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005255 continue;
dea31012005-04-17 16:05:31 -05005256
James Smart2e0fef82007-06-17 19:56:36 -05005257 if (piocb->vport != vport)
5258 continue;
5259
James Smart2534ba72007-04-25 09:52:20 -04005260 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005261 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005262 }
5263
5264 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005265 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5266 continue;
5267 }
dea31012005-04-17 16:05:31 -05005268
James Smart2e0fef82007-06-17 19:56:36 -05005269 if (piocb->vport != vport)
5270 continue;
5271
James Smart07951072007-04-25 09:51:38 -04005272 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005273 }
James Smart2e0fef82007-06-17 19:56:36 -05005274 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005275
James Smarta257bf92009-04-06 18:48:10 -04005276 /* Cancell all the IOCBs from the completions list */
5277 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5278 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005279
dea31012005-04-17 16:05:31 -05005280 return;
5281}
5282
James Smarte59058c2008-08-24 21:49:00 -04005283/**
James Smart3621a712009-04-06 18:47:14 -04005284 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005285 * @phba: pointer to lpfc hba data structure.
5286 *
5287 * This routine is used to clean up all the outstanding ELS commands on a
5288 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5289 * routine. After that, it walks the ELS transmit queue to remove all the
5290 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5291 * the IOCBs with the completion callback function associated, the callback
5292 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5293 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5294 * callback function associated, the IOCB will simply be released. Finally,
5295 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5296 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5297 * management plane IOCBs that are not part of the discovery state machine)
5298 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5299 **/
James Smart549e55c2007-08-02 11:09:51 -04005300void
5301lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5302{
5303 LIST_HEAD(completions);
5304 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5305 struct lpfc_iocbq *tmp_iocb, *piocb;
5306 IOCB_t *cmd = NULL;
5307
5308 lpfc_fabric_abort_hba(phba);
5309 spin_lock_irq(&phba->hbalock);
5310 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5311 cmd = &piocb->iocb;
5312 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5313 continue;
5314 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5315 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5316 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5317 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5318 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5319 continue;
5320 list_move_tail(&piocb->list, &completions);
5321 pring->txq_cnt--;
5322 }
5323 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5324 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5325 continue;
5326 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5327 }
5328 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005329
5330 /* Cancel all the IOCBs from the completions list */
5331 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5332 IOERR_SLI_ABORTED);
5333
James Smart549e55c2007-08-02 11:09:51 -04005334 return;
5335}
5336
James Smarte59058c2008-08-24 21:49:00 -04005337/**
James Smart3621a712009-04-06 18:47:14 -04005338 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005339 * @phba: Pointer to hba context object.
5340 * @cmdiocbp: Pointer to command iocb which reported error.
5341 * @rspiocbp: Pointer to response iocb which reported error.
5342 *
5343 * This function sends an event when there is an ELS command
5344 * failure.
5345 **/
5346void
5347lpfc_send_els_failure_event(struct lpfc_hba *phba,
5348 struct lpfc_iocbq *cmdiocbp,
5349 struct lpfc_iocbq *rspiocbp)
5350{
5351 struct lpfc_vport *vport = cmdiocbp->vport;
5352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5353 struct lpfc_lsrjt_event lsrjt_event;
5354 struct lpfc_fabric_event_header fabric_event;
5355 struct ls_rjt stat;
5356 struct lpfc_nodelist *ndlp;
5357 uint32_t *pcmd;
5358
5359 ndlp = cmdiocbp->context1;
5360 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5361 return;
5362
5363 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5364 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5365 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5366 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5367 sizeof(struct lpfc_name));
5368 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5369 sizeof(struct lpfc_name));
5370 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5371 cmdiocbp->context2)->virt);
5372 lsrjt_event.command = *pcmd;
5373 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5374 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5375 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5376 fc_host_post_vendor_event(shost,
5377 fc_get_event_number(),
5378 sizeof(lsrjt_event),
5379 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005380 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005381 return;
5382 }
5383 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5384 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5385 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5386 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5387 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5388 else
5389 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5390 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5391 sizeof(struct lpfc_name));
5392 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5393 sizeof(struct lpfc_name));
5394 fc_host_post_vendor_event(shost,
5395 fc_get_event_number(),
5396 sizeof(fabric_event),
5397 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005398 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005399 return;
5400 }
5401
5402}
5403
5404/**
James Smart3621a712009-04-06 18:47:14 -04005405 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005406 * @vport: Pointer to vport object.
5407 * @ndlp: Pointer FC node object.
5408 * @cmd: ELS command code.
5409 *
5410 * This function posts an event when there is an incoming
5411 * unsolicited ELS command.
5412 **/
5413static void
5414lpfc_send_els_event(struct lpfc_vport *vport,
5415 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005416 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005417{
James Smartddcc50f2008-12-04 22:38:46 -05005418 struct lpfc_els_event_header *els_data = NULL;
5419 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5421
James Smartddcc50f2008-12-04 22:38:46 -05005422 if (*payload == ELS_CMD_LOGO) {
5423 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5424 if (!logo_data) {
5425 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5426 "0148 Failed to allocate memory "
5427 "for LOGO event\n");
5428 return;
5429 }
5430 els_data = &logo_data->header;
5431 } else {
5432 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5433 GFP_KERNEL);
5434 if (!els_data) {
5435 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5436 "0149 Failed to allocate memory "
5437 "for ELS event\n");
5438 return;
5439 }
5440 }
5441 els_data->event_type = FC_REG_ELS_EVENT;
5442 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005443 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005444 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005445 break;
5446 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005447 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005448 break;
5449 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005450 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5451 break;
5452 case ELS_CMD_LOGO:
5453 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5454 /* Copy the WWPN in the LOGO payload */
5455 memcpy(logo_data->logo_wwpn, &payload[2],
5456 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005457 break;
5458 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005459 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005460 return;
5461 }
James Smartddcc50f2008-12-04 22:38:46 -05005462 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5463 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5464 if (*payload == ELS_CMD_LOGO) {
5465 fc_host_post_vendor_event(shost,
5466 fc_get_event_number(),
5467 sizeof(struct lpfc_logo_event),
5468 (char *)logo_data,
5469 LPFC_NL_VENDOR_ID);
5470 kfree(logo_data);
5471 } else {
5472 fc_host_post_vendor_event(shost,
5473 fc_get_event_number(),
5474 sizeof(struct lpfc_els_event_header),
5475 (char *)els_data,
5476 LPFC_NL_VENDOR_ID);
5477 kfree(els_data);
5478 }
James Smartea2151b2008-09-07 11:52:10 -04005479
5480 return;
5481}
5482
5483
5484/**
James Smart3621a712009-04-06 18:47:14 -04005485 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005486 * @phba: pointer to lpfc hba data structure.
5487 * @pring: pointer to a SLI ring.
5488 * @vport: pointer to a host virtual N_Port data structure.
5489 * @elsiocb: pointer to lpfc els command iocb data structure.
5490 *
5491 * This routine is used for processing the IOCB associated with a unsolicited
5492 * event. It first determines whether there is an existing ndlp that matches
5493 * the DID from the unsolicited IOCB. If not, it will create a new one with
5494 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5495 * IOCB is then used to invoke the proper routine and to set up proper state
5496 * of the discovery state machine.
5497 **/
James Smarted957682007-06-17 19:56:37 -05005498static void
5499lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005500 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005501{
James Smart87af33f2007-10-27 13:37:43 -04005502 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005503 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005504 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005505 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005506 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005507 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005508
James Smarte47c9092008-02-08 18:49:26 -05005509 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005510 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005511
dea31012005-04-17 16:05:31 -05005512 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005513 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5514 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005515 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005516 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005517
James Smart858c9f62007-06-17 19:56:39 -05005518 did = icmd->un.rcvels.remoteID;
5519 if (icmd->ulpStatus) {
5520 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5521 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5522 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005523 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005524 }
dea31012005-04-17 16:05:31 -05005525
5526 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005527 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005528 goto dropit;
dea31012005-04-17 16:05:31 -05005529
James Smartc8685952009-11-18 15:39:16 -05005530 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005531 if (vport->load_flag & FC_UNLOADING)
5532 goto dropit;
5533
James Smart2e0fef82007-06-17 19:56:36 -05005534 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005535 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005536 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005537 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005538 if (!ndlp)
dea31012005-04-17 16:05:31 -05005539 goto dropit;
dea31012005-04-17 16:05:31 -05005540
James Smart2e0fef82007-06-17 19:56:36 -05005541 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005542 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005543 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005544 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005545 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005546 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5547 ndlp = lpfc_enable_node(vport, ndlp,
5548 NLP_STE_UNUSED_NODE);
5549 if (!ndlp)
5550 goto dropit;
5551 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5552 newnode = 1;
5553 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5554 ndlp->nlp_type |= NLP_FABRIC;
5555 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5556 /* This is similar to the new node path */
5557 ndlp = lpfc_nlp_get(ndlp);
5558 if (!ndlp)
5559 goto dropit;
5560 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5561 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005562 }
dea31012005-04-17 16:05:31 -05005563
5564 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005565
James Smart329f9bc2007-04-25 09:53:01 -04005566 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005567 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005568
5569 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5570 cmd &= ELS_CMD_MASK;
5571 }
5572 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5574 "0112 ELS command x%x received from NPORT x%x "
5575 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005576 switch (cmd) {
5577 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005578 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5579 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5580 did, vport->port_state, ndlp->nlp_flag);
5581
dea31012005-04-17 16:05:31 -05005582 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005583 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5584
James Smartddcc50f2008-12-04 22:38:46 -05005585 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005586 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005587 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5588 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5589 rjt_err = LSRJT_UNABLE_TPC;
5590 break;
5591 }
5592 /* We get here, and drop thru, if we are PT2PT with
5593 * another NPort and the other side has initiated
5594 * the PLOGI before responding to our FLOGI.
5595 */
dea31012005-04-17 16:05:31 -05005596 }
James Smart87af33f2007-10-27 13:37:43 -04005597
5598 shost = lpfc_shost_from_vport(vport);
5599 spin_lock_irq(shost->host_lock);
5600 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5601 spin_unlock_irq(shost->host_lock);
5602
James Smart2e0fef82007-06-17 19:56:36 -05005603 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5604 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005605
dea31012005-04-17 16:05:31 -05005606 break;
5607 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005608 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5609 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5610 did, vport->port_state, ndlp->nlp_flag);
5611
dea31012005-04-17 16:05:31 -05005612 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005613 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005614 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005615 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005616 break;
5617 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5619 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5620 did, vport->port_state, ndlp->nlp_flag);
5621
dea31012005-04-17 16:05:31 -05005622 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005623 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005624 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005625 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005626 break;
5627 }
James Smart2e0fef82007-06-17 19:56:36 -05005628 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005629 break;
5630 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5632 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5633 did, vport->port_state, ndlp->nlp_flag);
5634
dea31012005-04-17 16:05:31 -05005635 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005636 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005637 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005638 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005639 break;
5640 }
James Smart2e0fef82007-06-17 19:56:36 -05005641 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005642 break;
5643 case ELS_CMD_RSCN:
5644 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005645 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005646 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005647 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005648 break;
5649 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005650 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5651 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5652 did, vport->port_state, ndlp->nlp_flag);
5653
James Smartddcc50f2008-12-04 22:38:46 -05005654 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005655 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005656 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005657 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005658 break;
5659 }
James Smart2e0fef82007-06-17 19:56:36 -05005660 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5661 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005662 break;
5663 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005664 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5665 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5666 did, vport->port_state, ndlp->nlp_flag);
5667
dea31012005-04-17 16:05:31 -05005668 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005669 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005670 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005671 break;
5672 }
James Smart2e0fef82007-06-17 19:56:36 -05005673 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5674 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005675 break;
5676 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005677 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5678 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5679 did, vport->port_state, ndlp->nlp_flag);
5680
dea31012005-04-17 16:05:31 -05005681 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005682 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005683 break;
5684 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5686 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5687 did, vport->port_state, ndlp->nlp_flag);
5688
dea31012005-04-17 16:05:31 -05005689 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005690 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005691 break;
5692 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005693 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5694 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5695 did, vport->port_state, ndlp->nlp_flag);
5696
dea31012005-04-17 16:05:31 -05005697 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005698 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005699 break;
dea31012005-04-17 16:05:31 -05005700 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005701 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5702 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5703 did, vport->port_state, ndlp->nlp_flag);
5704
dea31012005-04-17 16:05:31 -05005705 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005706 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005707 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005708 break;
5709 }
James Smart2e0fef82007-06-17 19:56:36 -05005710 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005711 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005712 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5714 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5715 did, vport->port_state, ndlp->nlp_flag);
5716
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005717 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005718 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005719 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005720 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005721 break;
5722 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005723 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5724 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5725 did, vport->port_state, ndlp->nlp_flag);
5726
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005727 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005728 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005729 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005730 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005731 break;
5732 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005733 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5734 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5735 did, vport->port_state, ndlp->nlp_flag);
5736
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005737 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005738 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005739 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005740 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005741 break;
dea31012005-04-17 16:05:31 -05005742 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005743 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5744 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5745 did, vport->port_state, ndlp->nlp_flag);
5746
dea31012005-04-17 16:05:31 -05005747 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005748 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005749 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005750 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005751 break;
James Smart5ffc2662009-11-18 15:39:44 -05005752 case ELS_CMD_RRQ:
5753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5754 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5755 did, vport->port_state, ndlp->nlp_flag);
5756
5757 phba->fc_stat.elsRcvRRQ++;
5758 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5759 if (newnode)
5760 lpfc_nlp_put(ndlp);
5761 break;
dea31012005-04-17 16:05:31 -05005762 default:
James Smart858c9f62007-06-17 19:56:39 -05005763 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5764 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5765 cmd, did, vport->port_state);
5766
dea31012005-04-17 16:05:31 -05005767 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005768 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005769
5770 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005771 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5772 "0115 Unknown ELS command x%x "
5773 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005774 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005775 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005776 break;
5777 }
5778
5779 /* check if need to LS_RJT received ELS cmd */
5780 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005781 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005782 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005783 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005784 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5785 NULL);
dea31012005-04-17 16:05:31 -05005786 }
5787
James Smartd7c255b2008-08-24 21:50:00 -04005788 lpfc_nlp_put(elsiocb->context1);
5789 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005790 return;
5791
5792dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005793 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005794 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5795 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005796 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005797 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005798 phba->fc_stat.elsRcvDrop++;
5799}
5800
James Smarte59058c2008-08-24 21:49:00 -04005801/**
James Smart3621a712009-04-06 18:47:14 -04005802 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005803 * @phba: pointer to lpfc hba data structure.
5804 * @vpi: host virtual N_Port identifier.
5805 *
5806 * This routine finds a vport on a HBA (referred by @phba) through a
5807 * @vpi. The function walks the HBA's vport list and returns the address
5808 * of the vport with the matching @vpi.
5809 *
5810 * Return code
5811 * NULL - No vport with the matching @vpi found
5812 * Otherwise - Address to the vport with the matching @vpi.
5813 **/
James Smart6669f9b2009-10-02 15:16:45 -04005814struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005815lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5816{
5817 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005818 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005819
James Smart549e55c2007-08-02 11:09:51 -04005820 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005821 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005822 if (vport->vpi == vpi) {
5823 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005824 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005825 }
James Smart92d7f7b2007-06-17 19:56:38 -05005826 }
James Smart549e55c2007-08-02 11:09:51 -04005827 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005828 return NULL;
5829}
James Smarted957682007-06-17 19:56:37 -05005830
James Smarte59058c2008-08-24 21:49:00 -04005831/**
James Smart3621a712009-04-06 18:47:14 -04005832 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005833 * @phba: pointer to lpfc hba data structure.
5834 * @pring: pointer to a SLI ring.
5835 * @elsiocb: pointer to lpfc els iocb data structure.
5836 *
5837 * This routine is used to process an unsolicited event received from a SLI
5838 * (Service Level Interface) ring. The actual processing of the data buffer
5839 * associated with the unsolicited event is done by invoking the routine
5840 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5841 * SLI ring on which the unsolicited event was received.
5842 **/
James Smarted957682007-06-17 19:56:37 -05005843void
5844lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5845 struct lpfc_iocbq *elsiocb)
5846{
5847 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005848 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005849 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005850 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5851 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005852
James Smartd7c255b2008-08-24 21:50:00 -04005853 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005854 elsiocb->context2 = NULL;
5855 elsiocb->context3 = NULL;
5856
5857 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5858 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5859 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5860 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005861 phba->fc_stat.NoRcvBuf++;
5862 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005863 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005864 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005865 return;
5866 }
5867
James Smart92d7f7b2007-06-17 19:56:38 -05005868 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5869 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5870 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5871 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5872 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005873 else
5874 vport = lpfc_find_vport_by_vpid(phba,
5875 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005876 }
James Smart7f5f3d02008-02-08 18:50:14 -05005877 /* If there are no BDEs associated
5878 * with this IOCB, there is nothing to do.
5879 */
James Smarted957682007-06-17 19:56:37 -05005880 if (icmd->ulpBdeCount == 0)
5881 return;
5882
James Smart7f5f3d02008-02-08 18:50:14 -05005883 /* type of ELS cmd is first 32bit word
5884 * in packet
5885 */
James Smarted957682007-06-17 19:56:37 -05005886 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005887 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005888 } else {
5889 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5890 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005891 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5892 paddr);
James Smarted957682007-06-17 19:56:37 -05005893 }
5894
James Smart92d7f7b2007-06-17 19:56:38 -05005895 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5896 /*
5897 * The different unsolicited event handlers would tell us
5898 * if they are done with "mp" by setting context2 to NULL.
5899 */
dea31012005-04-17 16:05:31 -05005900 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005901 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5902 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005903 }
James Smarted957682007-06-17 19:56:37 -05005904
5905 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005906 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005907 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005908 elsiocb->context2 = bdeBuf2;
5909 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005910 /* free mp if we are done with it */
5911 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005912 lpfc_in_buf_free(phba, elsiocb->context2);
5913 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005914 }
dea31012005-04-17 16:05:31 -05005915 }
dea31012005-04-17 16:05:31 -05005916}
James Smart92d7f7b2007-06-17 19:56:38 -05005917
James Smarte59058c2008-08-24 21:49:00 -04005918/**
James Smart3621a712009-04-06 18:47:14 -04005919 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005920 * @phba: pointer to lpfc hba data structure.
5921 * @vport: pointer to a virtual N_Port data structure.
5922 *
5923 * This routine issues a Port Login (PLOGI) to the Name Server with
5924 * State Change Request (SCR) for a @vport. This routine will create an
5925 * ndlp for the Name Server associated to the @vport if such node does
5926 * not already exist. The PLOGI to Name Server is issued by invoking the
5927 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5928 * (FDMI) is configured to the @vport, a FDMI node will be created and
5929 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5930 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005931void
5932lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5933{
5934 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5935
5936 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5937 if (!ndlp) {
5938 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5939 if (!ndlp) {
5940 if (phba->fc_topology == TOPOLOGY_LOOP) {
5941 lpfc_disc_start(vport);
5942 return;
5943 }
5944 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005945 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5946 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005947 return;
5948 }
5949 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005950 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5951 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5952 if (!ndlp) {
5953 if (phba->fc_topology == TOPOLOGY_LOOP) {
5954 lpfc_disc_start(vport);
5955 return;
5956 }
5957 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5958 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5959 "0348 NameServer login: node freed\n");
5960 return;
5961 }
James Smart92d7f7b2007-06-17 19:56:38 -05005962 }
James Smart58da1ff2008-04-07 10:15:56 -04005963 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005964
5965 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5966
5967 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5968 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005969 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5970 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005971 return;
5972 }
5973
James Smart3de2a652007-08-02 11:09:59 -04005974 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005975 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5976 GFP_KERNEL);
5977 if (ndlp_fdmi) {
5978 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5979 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005980 lpfc_nlp_set_state(vport, ndlp_fdmi,
5981 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005982 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5983 0);
5984 }
5985 }
5986 return;
5987}
5988
James Smarte59058c2008-08-24 21:49:00 -04005989/**
James Smart3621a712009-04-06 18:47:14 -04005990 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005991 * @phba: pointer to lpfc hba data structure.
5992 * @pmb: pointer to the driver internal queue element for mailbox command.
5993 *
5994 * This routine is the completion callback function to register new vport
5995 * mailbox command. If the new vport mailbox command completes successfully,
5996 * the fabric registration login shall be performed on physical port (the
5997 * new vport created is actually a physical port, with VPI 0) or the port
5998 * login to Name Server for State Change Request (SCR) will be performed
5999 * on virtual port (real virtual port, with VPI greater than 0).
6000 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006001static void
6002lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6003{
6004 struct lpfc_vport *vport = pmb->vport;
6005 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6006 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006007 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006008 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006009
James Smart09372822008-01-11 01:52:54 -05006010 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006011 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006012 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006013
6014 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006015 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6016 "0915 Register VPI failed: 0x%x\n",
6017 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05006018
6019 switch (mb->mbxStatus) {
6020 case 0x11: /* unsupported feature */
6021 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006022 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006023 /* giving up on vport registration */
6024 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6025 spin_lock_irq(shost->host_lock);
6026 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6027 spin_unlock_irq(shost->host_lock);
6028 lpfc_can_disctmo(vport);
6029 break;
James Smart695a8142010-01-26 23:08:03 -05006030 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6031 case 0x20:
6032 spin_lock_irq(shost->host_lock);
6033 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6034 spin_unlock_irq(shost->host_lock);
6035 lpfc_init_vpi(phba, pmb, vport->vpi);
6036 pmb->vport = vport;
6037 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6038 rc = lpfc_sli_issue_mbox(phba, pmb,
6039 MBX_NOWAIT);
6040 if (rc == MBX_NOT_FINISHED) {
6041 lpfc_printf_vlog(vport,
6042 KERN_ERR, LOG_MBOX,
6043 "2732 Failed to issue INIT_VPI"
6044 " mailbox command\n");
6045 } else {
6046 lpfc_nlp_put(ndlp);
6047 return;
6048 }
6049
James Smart92d7f7b2007-06-17 19:56:38 -05006050 default:
6051 /* Try to recover from this error */
6052 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006053 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006054 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006055 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05006056 if (vport->port_type == LPFC_PHYSICAL_PORT)
6057 lpfc_initial_flogi(vport);
6058 else
6059 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006060 break;
6061 }
James Smart92d7f7b2007-06-17 19:56:38 -05006062 } else {
James Smart695a8142010-01-26 23:08:03 -05006063 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006064 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006065 spin_unlock_irq(shost->host_lock);
6066 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006067 if (phba->sli_rev < LPFC_SLI_REV4)
6068 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006069 else {
James Smartfc2b9892010-02-26 14:15:29 -05006070 /*
6071 * If the physical port is instantiated using
6072 * FDISC, do not start vport discovery.
6073 */
6074 if (vport->port_state != LPFC_FDISC)
6075 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006076 lpfc_do_scr_ns_plogi(phba, vport);
6077 }
6078 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006079 lpfc_do_scr_ns_plogi(phba, vport);
6080 }
James Smartfa4066b2008-01-11 01:53:27 -05006081
6082 /* Now, we decrement the ndlp reference count held for this
6083 * callback function
6084 */
6085 lpfc_nlp_put(ndlp);
6086
James Smart92d7f7b2007-06-17 19:56:38 -05006087 mempool_free(pmb, phba->mbox_mem_pool);
6088 return;
6089}
6090
James Smarte59058c2008-08-24 21:49:00 -04006091/**
James Smart3621a712009-04-06 18:47:14 -04006092 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006093 * @phba: pointer to lpfc hba data structure.
6094 * @vport: pointer to a host virtual N_Port data structure.
6095 * @ndlp: pointer to a node-list data structure.
6096 *
6097 * This routine registers the @vport as a new virtual port with a HBA.
6098 * It is done through a registering vpi mailbox command.
6099 **/
James Smart695a8142010-01-26 23:08:03 -05006100void
James Smart92d7f7b2007-06-17 19:56:38 -05006101lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6102 struct lpfc_nodelist *ndlp)
6103{
James Smart09372822008-01-11 01:52:54 -05006104 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006105 LPFC_MBOXQ_t *mbox;
6106
6107 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6108 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006109 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006110 mbox->vport = vport;
6111 mbox->context2 = lpfc_nlp_get(ndlp);
6112 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006113 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006114 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006115 /* mailbox command not success, decrement ndlp
6116 * reference count for this command
6117 */
6118 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006119 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006120
James Smarte8b62012007-08-02 11:10:09 -04006121 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6122 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006123 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006124 }
6125 } else {
James Smarte8b62012007-08-02 11:10:09 -04006126 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6127 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006128 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006129 }
James Smartfa4066b2008-01-11 01:53:27 -05006130 return;
6131
6132mbox_err_exit:
6133 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6134 spin_lock_irq(shost->host_lock);
6135 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6136 spin_unlock_irq(shost->host_lock);
6137 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006138}
6139
James Smarte59058c2008-08-24 21:49:00 -04006140/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006141 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006142 * @phba: pointer to lpfc hba data structure.
6143 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006144 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006145 **/
6146void
James Smart0c9ab6f2010-02-26 14:15:57 -05006147lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006148{
6149 struct lpfc_vport **vports;
6150 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006151 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006152 int i;
James Smart695a8142010-01-26 23:08:03 -05006153
6154 /* Treat this failure as linkdown for all vports */
6155 link_state = phba->link_state;
6156 lpfc_linkdown(phba);
6157 phba->link_state = link_state;
6158
6159 vports = lpfc_create_vport_work_array(phba);
6160
6161 if (vports) {
6162 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6163 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6164 if (ndlp)
6165 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6166 lpfc_els_flush_cmd(vports[i]);
6167 }
6168 lpfc_destroy_vport_work_array(phba, vports);
6169 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006170}
6171
6172/**
6173 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6174 * @phba: pointer to lpfc hba data structure.
6175 *
6176 * This routine abort all pending discovery commands and
6177 * start a timer to retry FLOGI for the physical port
6178 * discovery.
6179 **/
6180void
6181lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6182{
6183 struct lpfc_nodelist *ndlp;
6184 struct Scsi_Host *shost;
6185
6186 /* Cancel the all vports retry delay retry timers */
6187 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006188
6189 /* If fabric require FLOGI, then re-instantiate physical login */
6190 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6191 if (!ndlp)
6192 return;
6193
James Smart695a8142010-01-26 23:08:03 -05006194 shost = lpfc_shost_from_vport(phba->pport);
6195 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6196 spin_lock_irq(shost->host_lock);
6197 ndlp->nlp_flag |= NLP_DELAY_TMO;
6198 spin_unlock_irq(shost->host_lock);
6199 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6200 phba->pport->port_state = LPFC_FLOGI;
6201 return;
6202}
6203
6204/**
6205 * lpfc_fabric_login_reqd - Check if FLOGI required.
6206 * @phba: pointer to lpfc hba data structure.
6207 * @cmdiocb: pointer to FDISC command iocb.
6208 * @rspiocb: pointer to FDISC response iocb.
6209 *
6210 * This routine checks if a FLOGI is reguired for FDISC
6211 * to succeed.
6212 **/
6213static int
6214lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6215 struct lpfc_iocbq *cmdiocb,
6216 struct lpfc_iocbq *rspiocb)
6217{
6218
6219 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6220 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6221 return 0;
6222 else
6223 return 1;
6224}
6225
6226/**
James Smart3621a712009-04-06 18:47:14 -04006227 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006228 * @phba: pointer to lpfc hba data structure.
6229 * @cmdiocb: pointer to lpfc command iocb data structure.
6230 * @rspiocb: pointer to lpfc response iocb data structure.
6231 *
6232 * This routine is the completion callback function to a Fabric Discover
6233 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6234 * single threaded, each FDISC completion callback function will reset
6235 * the discovery timer for all vports such that the timers will not get
6236 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6237 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6238 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6239 * assigned to the vport has been changed with the completion of the FDISC
6240 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6241 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6242 * routine is invoked to register new vport with the HBA. Otherwise, the
6243 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6244 * Server for State Change Request (SCR).
6245 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006246static void
6247lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6248 struct lpfc_iocbq *rspiocb)
6249{
6250 struct lpfc_vport *vport = cmdiocb->vport;
6251 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6252 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6253 struct lpfc_nodelist *np;
6254 struct lpfc_nodelist *next_np;
6255 IOCB_t *irsp = &rspiocb->iocb;
6256 struct lpfc_iocbq *piocb;
6257
James Smarte8b62012007-08-02 11:10:09 -04006258 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6259 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6260 irsp->ulpStatus, irsp->un.ulpWord[4],
6261 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006262 /* Since all FDISCs are being single threaded, we
6263 * must reset the discovery timer for ALL vports
6264 * waiting to send FDISC when one completes.
6265 */
6266 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6267 lpfc_set_disctmo(piocb->vport);
6268 }
6269
James Smart858c9f62007-06-17 19:56:39 -05006270 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6271 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6272 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6273
James Smart92d7f7b2007-06-17 19:56:38 -05006274 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006275
6276 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6277 lpfc_retry_pport_discovery(phba);
6278 goto out;
6279 }
6280
James Smart92d7f7b2007-06-17 19:56:38 -05006281 /* Check for retry */
6282 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6283 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006284 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006285 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006286 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006287 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006288 goto fdisc_failed;
6289 }
James Smartd7c255b2008-08-24 21:50:00 -04006290 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006291 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006292 vport->fc_flag |= FC_FABRIC;
6293 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6294 vport->fc_flag |= FC_PUBLIC_LOOP;
6295 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006296
James Smartd7c255b2008-08-24 21:50:00 -04006297 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6298 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6299 if ((vport->fc_prevDID != vport->fc_myDID) &&
6300 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6301 /* If our NportID changed, we need to ensure all
6302 * remaining NPORTs get unreg_login'ed so we can
6303 * issue unreg_vpi.
6304 */
6305 list_for_each_entry_safe(np, next_np,
6306 &vport->fc_nodes, nlp_listp) {
6307 if (!NLP_CHK_NODE_ACT(ndlp) ||
6308 (np->nlp_state != NLP_STE_NPR_NODE) ||
6309 !(np->nlp_flag & NLP_NPR_ADISC))
6310 continue;
James Smart09372822008-01-11 01:52:54 -05006311 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006312 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006313 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006314 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006315 }
James Smartd7c255b2008-08-24 21:50:00 -04006316 lpfc_mbx_unreg_vpi(vport);
6317 spin_lock_irq(shost->host_lock);
6318 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006319 if (phba->sli_rev == LPFC_SLI_REV4)
6320 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartd7c255b2008-08-24 21:50:00 -04006321 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006322 }
6323
James Smartecfd03c2010-02-12 14:41:27 -05006324 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6325 lpfc_issue_init_vpi(vport);
6326 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006327 lpfc_register_new_vport(phba, vport, ndlp);
6328 else
6329 lpfc_do_scr_ns_plogi(phba, vport);
6330 goto out;
6331fdisc_failed:
6332 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6333 /* Cancel discovery timer */
6334 lpfc_can_disctmo(vport);
6335 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006336out:
6337 lpfc_els_free_iocb(phba, cmdiocb);
6338}
6339
James Smarte59058c2008-08-24 21:49:00 -04006340/**
James Smart3621a712009-04-06 18:47:14 -04006341 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006342 * @vport: pointer to a virtual N_Port data structure.
6343 * @ndlp: pointer to a node-list data structure.
6344 * @retry: number of retries to the command IOCB.
6345 *
6346 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6347 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6348 * routine to issue the IOCB, which makes sure only one outstanding fabric
6349 * IOCB will be sent off HBA at any given time.
6350 *
6351 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6352 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6353 * will be stored into the context1 field of the IOCB for the completion
6354 * callback function to the FDISC ELS command.
6355 *
6356 * Return code
6357 * 0 - Successfully issued fdisc iocb command
6358 * 1 - Failed to issue fdisc iocb command
6359 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006360static int
James Smart92d7f7b2007-06-17 19:56:38 -05006361lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6362 uint8_t retry)
6363{
6364 struct lpfc_hba *phba = vport->phba;
6365 IOCB_t *icmd;
6366 struct lpfc_iocbq *elsiocb;
6367 struct serv_parm *sp;
6368 uint8_t *pcmd;
6369 uint16_t cmdsize;
6370 int did = ndlp->nlp_DID;
6371 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006372
James Smart5ffc2662009-11-18 15:39:44 -05006373 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006374 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6375 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6376 ELS_CMD_FDISC);
6377 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006378 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006379 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6380 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006381 return 1;
6382 }
6383
6384 icmd = &elsiocb->iocb;
6385 icmd->un.elsreq64.myID = 0;
6386 icmd->un.elsreq64.fl = 1;
6387
James Smartf1126682009-06-10 17:22:44 -04006388 if (phba->sli_rev == LPFC_SLI_REV4) {
6389 /* FDISC needs to be 1 for WQE VPI */
6390 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6391 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6392 /* Set the ulpContext to the vpi */
6393 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6394 } else {
6395 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6396 icmd->ulpCt_h = 1;
6397 icmd->ulpCt_l = 0;
6398 }
James Smart92d7f7b2007-06-17 19:56:38 -05006399
6400 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6401 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6402 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6403 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6404 sp = (struct serv_parm *) pcmd;
6405 /* Setup CSPs accordingly for Fabric */
6406 sp->cmn.e_d_tov = 0;
6407 sp->cmn.w2.r_a_tov = 0;
6408 sp->cls1.classValid = 0;
6409 sp->cls2.seqDelivery = 1;
6410 sp->cls3.seqDelivery = 1;
6411
6412 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6413 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6414 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6415 pcmd += sizeof(uint32_t); /* Port Name */
6416 memcpy(pcmd, &vport->fc_portname, 8);
6417 pcmd += sizeof(uint32_t); /* Node Name */
6418 pcmd += sizeof(uint32_t); /* Node Name */
6419 memcpy(pcmd, &vport->fc_nodename, 8);
6420
6421 lpfc_set_disctmo(vport);
6422
6423 phba->fc_stat.elsXmitFDISC++;
6424 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6425
James Smart858c9f62007-06-17 19:56:39 -05006426 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6427 "Issue FDISC: did:x%x",
6428 did, 0, 0);
6429
James Smart92d7f7b2007-06-17 19:56:38 -05006430 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6431 if (rc == IOCB_ERROR) {
6432 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006433 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006434 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6435 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006436 return 1;
6437 }
6438 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006439 return 0;
6440}
6441
James Smarte59058c2008-08-24 21:49:00 -04006442/**
James Smart3621a712009-04-06 18:47:14 -04006443 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006444 * @phba: pointer to lpfc hba data structure.
6445 * @cmdiocb: pointer to lpfc command iocb data structure.
6446 * @rspiocb: pointer to lpfc response iocb data structure.
6447 *
6448 * This routine is the completion callback function to the issuing of a LOGO
6449 * ELS command off a vport. It frees the command IOCB and then decrement the
6450 * reference count held on ndlp for this completion function, indicating that
6451 * the reference to the ndlp is no long needed. Note that the
6452 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6453 * callback function and an additional explicit ndlp reference decrementation
6454 * will trigger the actual release of the ndlp.
6455 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006456static void
6457lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6458 struct lpfc_iocbq *rspiocb)
6459{
6460 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006461 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006462 struct lpfc_nodelist *ndlp;
6463 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006464
6465 irsp = &rspiocb->iocb;
6466 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6467 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6468 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006469
6470 lpfc_els_free_iocb(phba, cmdiocb);
6471 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006472
6473 /* Trigger the release of the ndlp after logo */
6474 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006475}
6476
James Smarte59058c2008-08-24 21:49:00 -04006477/**
James Smart3621a712009-04-06 18:47:14 -04006478 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006479 * @vport: pointer to a virtual N_Port data structure.
6480 * @ndlp: pointer to a node-list data structure.
6481 *
6482 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6483 *
6484 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6485 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6486 * will be stored into the context1 field of the IOCB for the completion
6487 * callback function to the LOGO ELS command.
6488 *
6489 * Return codes
6490 * 0 - Successfully issued logo off the @vport
6491 * 1 - Failed to issue logo off the @vport
6492 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006493int
6494lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6495{
6496 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6497 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006498 IOCB_t *icmd;
6499 struct lpfc_iocbq *elsiocb;
6500 uint8_t *pcmd;
6501 uint16_t cmdsize;
6502
6503 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6504 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6505 ELS_CMD_LOGO);
6506 if (!elsiocb)
6507 return 1;
6508
6509 icmd = &elsiocb->iocb;
6510 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6511 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6512 pcmd += sizeof(uint32_t);
6513
6514 /* Fill in LOGO payload */
6515 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6516 pcmd += sizeof(uint32_t);
6517 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6518
James Smart858c9f62007-06-17 19:56:39 -05006519 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6520 "Issue LOGO npiv did:x%x flg:x%x",
6521 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6522
James Smart92d7f7b2007-06-17 19:56:38 -05006523 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6524 spin_lock_irq(shost->host_lock);
6525 ndlp->nlp_flag |= NLP_LOGO_SND;
6526 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006527 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6528 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006529 spin_lock_irq(shost->host_lock);
6530 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6531 spin_unlock_irq(shost->host_lock);
6532 lpfc_els_free_iocb(phba, elsiocb);
6533 return 1;
6534 }
6535 return 0;
6536}
6537
James Smarte59058c2008-08-24 21:49:00 -04006538/**
James Smart3621a712009-04-06 18:47:14 -04006539 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006540 * @ptr: holder for the timer function associated data.
6541 *
6542 * This routine is invoked by the fabric iocb block timer after
6543 * timeout. It posts the fabric iocb block timeout event by setting the
6544 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6545 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6546 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6547 * posted event WORKER_FABRIC_BLOCK_TMO.
6548 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006549void
6550lpfc_fabric_block_timeout(unsigned long ptr)
6551{
6552 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6553 unsigned long iflags;
6554 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006555
James Smart92d7f7b2007-06-17 19:56:38 -05006556 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6557 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6558 if (!tmo_posted)
6559 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6560 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6561
James Smart5e9d9b82008-06-14 22:52:53 -04006562 if (!tmo_posted)
6563 lpfc_worker_wake_up(phba);
6564 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006565}
6566
James Smarte59058c2008-08-24 21:49:00 -04006567/**
James Smart3621a712009-04-06 18:47:14 -04006568 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006569 * @phba: pointer to lpfc hba data structure.
6570 *
6571 * This routine issues one fabric iocb from the driver internal list to
6572 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6573 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6574 * remove one pending fabric iocb from the driver internal list and invokes
6575 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6576 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006577static void
6578lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6579{
6580 struct lpfc_iocbq *iocb;
6581 unsigned long iflags;
6582 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006583 IOCB_t *cmd;
6584
6585repeat:
6586 iocb = NULL;
6587 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006588 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006589 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6590 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6591 list);
6592 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006593 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006594 atomic_inc(&phba->fabric_iocb_count);
6595 }
6596 spin_unlock_irqrestore(&phba->hbalock, iflags);
6597 if (iocb) {
6598 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6599 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6600 iocb->iocb_flag |= LPFC_IO_FABRIC;
6601
James Smart858c9f62007-06-17 19:56:39 -05006602 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6603 "Fabric sched1: ste:x%x",
6604 iocb->vport->port_state, 0, 0);
6605
James Smart3772a992009-05-22 14:50:54 -04006606 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006607
6608 if (ret == IOCB_ERROR) {
6609 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6610 iocb->fabric_iocb_cmpl = NULL;
6611 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6612 cmd = &iocb->iocb;
6613 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6614 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6615 iocb->iocb_cmpl(phba, iocb, iocb);
6616
6617 atomic_dec(&phba->fabric_iocb_count);
6618 goto repeat;
6619 }
6620 }
6621
6622 return;
6623}
6624
James Smarte59058c2008-08-24 21:49:00 -04006625/**
James Smart3621a712009-04-06 18:47:14 -04006626 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006627 * @phba: pointer to lpfc hba data structure.
6628 *
6629 * This routine unblocks the issuing fabric iocb command. The function
6630 * will clear the fabric iocb block bit and then invoke the routine
6631 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6632 * from the driver internal fabric iocb list.
6633 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006634void
6635lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6636{
6637 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6638
6639 lpfc_resume_fabric_iocbs(phba);
6640 return;
6641}
6642
James Smarte59058c2008-08-24 21:49:00 -04006643/**
James Smart3621a712009-04-06 18:47:14 -04006644 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006645 * @phba: pointer to lpfc hba data structure.
6646 *
6647 * This routine blocks the issuing fabric iocb for a specified amount of
6648 * time (currently 100 ms). This is done by set the fabric iocb block bit
6649 * and set up a timeout timer for 100ms. When the block bit is set, no more
6650 * fabric iocb will be issued out of the HBA.
6651 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006652static void
6653lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6654{
6655 int blocked;
6656
6657 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006658 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006659 if (!blocked)
6660 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6661
6662 return;
6663}
6664
James Smarte59058c2008-08-24 21:49:00 -04006665/**
James Smart3621a712009-04-06 18:47:14 -04006666 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006667 * @phba: pointer to lpfc hba data structure.
6668 * @cmdiocb: pointer to lpfc command iocb data structure.
6669 * @rspiocb: pointer to lpfc response iocb data structure.
6670 *
6671 * This routine is the callback function that is put to the fabric iocb's
6672 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6673 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6674 * function first restores and invokes the original iocb's callback function
6675 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6676 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6677 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006678static void
6679lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6680 struct lpfc_iocbq *rspiocb)
6681{
6682 struct ls_rjt stat;
6683
6684 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6685 BUG();
6686
6687 switch (rspiocb->iocb.ulpStatus) {
6688 case IOSTAT_NPORT_RJT:
6689 case IOSTAT_FABRIC_RJT:
6690 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6691 lpfc_block_fabric_iocbs(phba);
6692 }
6693 break;
6694
6695 case IOSTAT_NPORT_BSY:
6696 case IOSTAT_FABRIC_BSY:
6697 lpfc_block_fabric_iocbs(phba);
6698 break;
6699
6700 case IOSTAT_LS_RJT:
6701 stat.un.lsRjtError =
6702 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6703 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6704 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6705 lpfc_block_fabric_iocbs(phba);
6706 break;
6707 }
6708
6709 if (atomic_read(&phba->fabric_iocb_count) == 0)
6710 BUG();
6711
6712 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6713 cmdiocb->fabric_iocb_cmpl = NULL;
6714 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6715 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6716
6717 atomic_dec(&phba->fabric_iocb_count);
6718 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006719 /* Post any pending iocbs to HBA */
6720 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006721 }
6722}
6723
James Smarte59058c2008-08-24 21:49:00 -04006724/**
James Smart3621a712009-04-06 18:47:14 -04006725 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006726 * @phba: pointer to lpfc hba data structure.
6727 * @iocb: pointer to lpfc command iocb data structure.
6728 *
6729 * This routine is used as the top-level API for issuing a fabric iocb command
6730 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6731 * function makes sure that only one fabric bound iocb will be outstanding at
6732 * any given time. As such, this function will first check to see whether there
6733 * is already an outstanding fabric iocb on the wire. If so, it will put the
6734 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6735 * issued later. Otherwise, it will issue the iocb on the wire and update the
6736 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6737 *
6738 * Note, this implementation has a potential sending out fabric IOCBs out of
6739 * order. The problem is caused by the construction of the "ready" boolen does
6740 * not include the condition that the internal fabric IOCB list is empty. As
6741 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6742 * ahead of the fabric IOCBs in the internal list.
6743 *
6744 * Return code
6745 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6746 * IOCB_ERROR - failed to issue fabric iocb
6747 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006748static int
James Smart92d7f7b2007-06-17 19:56:38 -05006749lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6750{
6751 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006752 int ready;
6753 int ret;
6754
6755 if (atomic_read(&phba->fabric_iocb_count) > 1)
6756 BUG();
6757
6758 spin_lock_irqsave(&phba->hbalock, iflags);
6759 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6760 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6761
James Smart7f5f3d02008-02-08 18:50:14 -05006762 if (ready)
6763 /* Increment fabric iocb count to hold the position */
6764 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006765 spin_unlock_irqrestore(&phba->hbalock, iflags);
6766 if (ready) {
6767 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6768 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6769 iocb->iocb_flag |= LPFC_IO_FABRIC;
6770
James Smart858c9f62007-06-17 19:56:39 -05006771 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6772 "Fabric sched2: ste:x%x",
6773 iocb->vport->port_state, 0, 0);
6774
James Smart3772a992009-05-22 14:50:54 -04006775 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006776
6777 if (ret == IOCB_ERROR) {
6778 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6779 iocb->fabric_iocb_cmpl = NULL;
6780 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6781 atomic_dec(&phba->fabric_iocb_count);
6782 }
6783 } else {
6784 spin_lock_irqsave(&phba->hbalock, iflags);
6785 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6786 spin_unlock_irqrestore(&phba->hbalock, iflags);
6787 ret = IOCB_SUCCESS;
6788 }
6789 return ret;
6790}
6791
James Smarte59058c2008-08-24 21:49:00 -04006792/**
James Smart3621a712009-04-06 18:47:14 -04006793 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006794 * @vport: pointer to a virtual N_Port data structure.
6795 *
6796 * This routine aborts all the IOCBs associated with a @vport from the
6797 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6798 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6799 * list, removes each IOCB associated with the @vport off the list, set the
6800 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6801 * associated with the IOCB.
6802 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006803static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006804{
6805 LIST_HEAD(completions);
6806 struct lpfc_hba *phba = vport->phba;
6807 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006808
6809 spin_lock_irq(&phba->hbalock);
6810 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6811 list) {
6812
6813 if (piocb->vport != vport)
6814 continue;
6815
6816 list_move_tail(&piocb->list, &completions);
6817 }
6818 spin_unlock_irq(&phba->hbalock);
6819
James Smarta257bf92009-04-06 18:48:10 -04006820 /* Cancel all the IOCBs from the completions list */
6821 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6822 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006823}
6824
James Smarte59058c2008-08-24 21:49:00 -04006825/**
James Smart3621a712009-04-06 18:47:14 -04006826 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006827 * @ndlp: pointer to a node-list data structure.
6828 *
6829 * This routine aborts all the IOCBs associated with an @ndlp from the
6830 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6831 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6832 * list, removes each IOCB associated with the @ndlp off the list, set the
6833 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6834 * associated with the IOCB.
6835 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006836void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6837{
6838 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006839 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006840 struct lpfc_iocbq *tmp_iocb, *piocb;
6841 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006842
6843 spin_lock_irq(&phba->hbalock);
6844 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6845 list) {
6846 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6847
6848 list_move_tail(&piocb->list, &completions);
6849 }
6850 }
6851 spin_unlock_irq(&phba->hbalock);
6852
James Smarta257bf92009-04-06 18:48:10 -04006853 /* Cancel all the IOCBs from the completions list */
6854 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6855 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006856}
6857
James Smarte59058c2008-08-24 21:49:00 -04006858/**
James Smart3621a712009-04-06 18:47:14 -04006859 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006860 * @phba: pointer to lpfc hba data structure.
6861 *
6862 * This routine aborts all the IOCBs currently on the driver internal
6863 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6864 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6865 * list, removes IOCBs off the list, set the status feild to
6866 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6867 * the IOCB.
6868 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006869void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6870{
6871 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006872
6873 spin_lock_irq(&phba->hbalock);
6874 list_splice_init(&phba->fabric_iocb_list, &completions);
6875 spin_unlock_irq(&phba->hbalock);
6876
James Smarta257bf92009-04-06 18:48:10 -04006877 /* Cancel all the IOCBs from the completions list */
6878 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6879 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006880}
James Smart6fb120a2009-05-22 14:52:59 -04006881
6882/**
6883 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6884 * @phba: pointer to lpfc hba data structure.
6885 * @axri: pointer to the els xri abort wcqe structure.
6886 *
6887 * This routine is invoked by the worker thread to process a SLI4 slow-path
6888 * ELS aborted xri.
6889 **/
6890void
6891lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6892 struct sli4_wcqe_xri_aborted *axri)
6893{
6894 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6895 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6896 unsigned long iflag = 0;
6897
James Smart0f65ff62010-02-26 14:14:23 -05006898 spin_lock_irqsave(&phba->hbalock, iflag);
6899 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006900 list_for_each_entry_safe(sglq_entry, sglq_next,
6901 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6902 if (sglq_entry->sli4_xritag == xri) {
6903 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006904 list_add_tail(&sglq_entry->list,
6905 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05006906 sglq_entry->state = SGL_FREED;
6907 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006908 spin_unlock_irqrestore(&phba->hbalock, iflag);
6909 return;
6910 }
6911 }
James Smart0f65ff62010-02-26 14:14:23 -05006912 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6913 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6914 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6915 spin_unlock_irqrestore(&phba->hbalock, iflag);
6916 return;
6917 }
6918 sglq_entry->state = SGL_XRI_ABORTED;
6919 spin_unlock_irqrestore(&phba->hbalock, iflag);
6920 return;
James Smart6fb120a2009-05-22 14:52:59 -04006921}