blob: b115e92025e58d27978bab6671e4c5d3cadda608 [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
James Smart12265f62010-10-22 11:05:53 -0400520 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500521 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
522
523 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500524 spin_lock_irq(shost->host_lock);
525 vport->fc_flag |= FC_PUBLIC_LOOP;
526 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500527 }
528
James Smart2e0fef82007-06-17 19:56:36 -0500529 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500530 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500531 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500532 ndlp->nlp_class_sup = 0;
533 if (sp->cls1.classValid)
534 ndlp->nlp_class_sup |= FC_COS_CLASS1;
535 if (sp->cls2.classValid)
536 ndlp->nlp_class_sup |= FC_COS_CLASS2;
537 if (sp->cls3.classValid)
538 ndlp->nlp_class_sup |= FC_COS_CLASS3;
539 if (sp->cls4.classValid)
540 ndlp->nlp_class_sup |= FC_COS_CLASS4;
541 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
542 sp->cmn.bbRcvSizeLsb;
543 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
544
James Smart92d7f7b2007-06-17 19:56:38 -0500545 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
546 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400547 lpfc_printf_vlog(vport, KERN_WARNING,
548 LOG_ELS | LOG_VPORT,
549 "1816 FLOGI NPIV supported, "
550 "response data 0x%x\n",
551 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500552 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500553 } else {
554 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400555 to call reg_vnpid atleast for the physcial host */
556 lpfc_printf_vlog(vport, KERN_WARNING,
557 LOG_ELS | LOG_VPORT,
558 "1817 Fabric does not support NPIV "
559 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500560 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
561 }
562 }
563
564 if ((vport->fc_prevDID != vport->fc_myDID) &&
565 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
566
567 /* If our NportID changed, we need to ensure all
568 * remaining NPORTs get unreg_login'ed.
569 */
570 list_for_each_entry_safe(np, next_np,
571 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400572 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500573 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500574 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
575 !(np->nlp_flag & NLP_NPR_ADISC))
576 continue;
577 spin_lock_irq(shost->host_lock);
578 np->nlp_flag &= ~NLP_NPR_ADISC;
579 spin_unlock_irq(shost->host_lock);
580 lpfc_unreg_rpi(vport, np);
581 }
James Smart78730cf2010-04-06 15:06:30 -0400582 lpfc_cleanup_pending_mbox(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500583 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
584 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500585 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500586 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500587 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500588 }
James Smartecfd03c2010-02-12 14:41:27 -0500589 /*
590 * If VPI is unreged, driver need to do INIT_VPI
591 * before re-registering
592 */
593 if (phba->sli_rev == LPFC_SLI_REV4) {
594 spin_lock_irq(shost->host_lock);
595 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
596 spin_unlock_irq(shost->host_lock);
597 }
James Smart38b92ef2010-08-04 16:11:39 -0400598 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
599 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
600 /*
601 * Driver needs to re-reg VPI in order for f/w
602 * to update the MAC address.
603 */
604 lpfc_register_new_vport(phba, vport, ndlp);
605 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500606 }
607
James Smart6fb120a2009-05-22 14:52:59 -0400608 if (phba->sli_rev < LPFC_SLI_REV4) {
609 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
610 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
611 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
612 lpfc_register_new_vport(phba, vport, ndlp);
613 else
614 lpfc_issue_fabric_reglogin(vport);
615 } else {
616 ndlp->nlp_type |= NLP_FABRIC;
617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500618 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
619 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400620 lpfc_start_fdiscs(phba);
621 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500622 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500623 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500624 else
James Smart6fb120a2009-05-22 14:52:59 -0400625 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500626 }
dea31012005-04-17 16:05:31 -0500627 return 0;
dea31012005-04-17 16:05:31 -0500628}
James Smarte59058c2008-08-24 21:49:00 -0400629/**
James Smart3621a712009-04-06 18:47:14 -0400630 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400631 * @vport: pointer to a host virtual N_Port data structure.
632 * @ndlp: pointer to a node-list data structure.
633 * @sp: pointer to service parameter data structure.
634 *
635 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
636 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
637 * in a point-to-point topology. First, the @vport's N_Port Name is compared
638 * with the received N_Port Name: if the @vport's N_Port Name is greater than
639 * the received N_Port Name lexicographically, this node shall assign local
640 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
641 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
642 * this node shall just wait for the remote node to issue PLOGI and assign
643 * N_Port IDs.
644 *
645 * Return code
646 * 0 - Success
647 * -ENXIO - Fail
648 **/
dea31012005-04-17 16:05:31 -0500649static int
James Smart2e0fef82007-06-17 19:56:36 -0500650lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
651 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500652{
James Smart2e0fef82007-06-17 19:56:36 -0500653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
654 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500655 LPFC_MBOXQ_t *mbox;
656 int rc;
657
James Smart2e0fef82007-06-17 19:56:36 -0500658 spin_lock_irq(shost->host_lock);
659 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
660 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500661
662 phba->fc_edtov = FF_DEF_EDTOV;
663 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500664 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500665 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500666 if (rc >= 0) {
667 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500668 spin_lock_irq(shost->host_lock);
669 vport->fc_flag |= FC_PT2PT_PLOGI;
670 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500671
672 /*
673 * N_Port ID cannot be 0, set our to LocalID the other
674 * side will be RemoteID.
675 */
676
677 /* not equal */
678 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500679 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500680
681 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
682 if (!mbox)
683 goto fail;
684
685 lpfc_config_link(phba, mbox);
686
687 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500688 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400689 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500690 if (rc == MBX_NOT_FINISHED) {
691 mempool_free(mbox, phba->mbox_mem_pool);
692 goto fail;
693 }
James Smarte47c9092008-02-08 18:49:26 -0500694 /* Decrement ndlp reference count indicating that ndlp can be
695 * safely released when other references to it are done.
696 */
James Smart329f9bc2007-04-25 09:53:01 -0400697 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500698
James Smart2e0fef82007-06-17 19:56:36 -0500699 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500700 if (!ndlp) {
701 /*
702 * Cannot find existing Fabric ndlp, so allocate a
703 * new one
704 */
705 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
706 if (!ndlp)
707 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500708 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500709 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
710 ndlp = lpfc_enable_node(vport, ndlp,
711 NLP_STE_UNUSED_NODE);
712 if(!ndlp)
713 goto fail;
dea31012005-04-17 16:05:31 -0500714 }
715
716 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500717 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500718 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500719 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500720 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
722 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500723 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500724 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500725 } else
726 /* This side will wait for the PLOGI, decrement ndlp reference
727 * count indicating that ndlp can be released when other
728 * references to it are done.
729 */
James Smart329f9bc2007-04-25 09:53:01 -0400730 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500731
James Smart09372822008-01-11 01:52:54 -0500732 /* If we are pt2pt with another NPort, force NPIV off! */
733 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
734
James Smart2e0fef82007-06-17 19:56:36 -0500735 spin_lock_irq(shost->host_lock);
736 vport->fc_flag |= FC_PT2PT;
737 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500738
739 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500740 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500741 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500742fail:
dea31012005-04-17 16:05:31 -0500743 return -ENXIO;
744}
745
James Smarte59058c2008-08-24 21:49:00 -0400746/**
James Smart3621a712009-04-06 18:47:14 -0400747 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400748 * @phba: pointer to lpfc hba data structure.
749 * @cmdiocb: pointer to lpfc command iocb data structure.
750 * @rspiocb: pointer to lpfc response iocb data structure.
751 *
752 * This routine is the top-level completion callback function for issuing
753 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
754 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
755 * retry has been made (either immediately or delayed with lpfc_els_retry()
756 * returning 1), the command IOCB will be released and function returned.
757 * If the retry attempt has been given up (possibly reach the maximum
758 * number of retries), one additional decrement of ndlp reference shall be
759 * invoked before going out after releasing the command IOCB. This will
760 * actually release the remote node (Note, lpfc_els_free_iocb() will also
761 * invoke one decrement of ndlp reference count). If no error reported in
762 * the IOCB status, the command Port ID field is used to determine whether
763 * this is a point-to-point topology or a fabric topology: if the Port ID
764 * field is assigned, it is a fabric topology; otherwise, it is a
765 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
766 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
767 * specific topology completion conditions.
768 **/
dea31012005-04-17 16:05:31 -0500769static void
James Smart329f9bc2007-04-25 09:53:01 -0400770lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
771 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500772{
James Smart2e0fef82007-06-17 19:56:36 -0500773 struct lpfc_vport *vport = cmdiocb->vport;
774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500775 IOCB_t *irsp = &rspiocb->iocb;
776 struct lpfc_nodelist *ndlp = cmdiocb->context1;
777 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
778 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500779 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500780 int rc;
781
782 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500783 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500784 /* One additional decrement on node reference count to
785 * trigger the release of the node
786 */
James Smart329f9bc2007-04-25 09:53:01 -0400787 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500788 goto out;
789 }
790
James Smart858c9f62007-06-17 19:56:39 -0500791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
792 "FLOGI cmpl: status:x%x/x%x state:x%x",
793 irsp->ulpStatus, irsp->un.ulpWord[4],
794 vport->port_state);
795
dea31012005-04-17 16:05:31 -0500796 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500797 /*
James Smarta93ff372010-10-22 11:06:08 -0400798 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500799 * due to new FCF discovery
800 */
801 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400802 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
803 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
804 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500805 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400806 "2611 FLOGI failed on FCF (x%x), "
807 "status:x%x/x%x, tmo:x%x, perform "
808 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400809 phba->fcf.current_rec.fcf_indx,
810 irsp->ulpStatus, irsp->un.ulpWord[4],
811 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500812 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400813 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
814 if (rc)
815 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500816 }
817
James Smart38b92ef2010-08-04 16:11:39 -0400818 /* FLOGI failure */
819 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
820 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
821 irsp->ulpStatus, irsp->un.ulpWord[4],
822 irsp->ulpTimeout);
823
dea31012005-04-17 16:05:31 -0500824 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500825 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500826 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500827
dea31012005-04-17 16:05:31 -0500828 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500829 spin_lock_irq(shost->host_lock);
830 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
831 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500832
James Smart329f9bc2007-04-25 09:53:01 -0400833 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500834 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
835 * alpa map would take too long otherwise.
836 */
837 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400838 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500839 }
840
841 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500842 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
843 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400844 irsp->ulpStatus, irsp->un.ulpWord[4],
845 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500846 goto flogifail;
847 }
James Smart695a8142010-01-26 23:08:03 -0500848 spin_lock_irq(shost->host_lock);
849 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400850 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500851 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500852
853 /*
854 * The FLogI succeeded. Sync the data for the CPU before
855 * accessing it.
856 */
857 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
858
859 sp = prsp->virt + sizeof(uint32_t);
860
861 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400862 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200863 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400864 "Data: x%x x%x x%x x%x\n",
865 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
866 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500867
James Smart2e0fef82007-06-17 19:56:36 -0500868 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500869 /*
870 * If Common Service Parameters indicate Nport
871 * we are point to point, if Fport we are Fabric.
872 */
873 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500874 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400875 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
James Smart2e0fef82007-06-17 19:56:36 -0500876 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400877 else {
878 lpfc_printf_vlog(vport, KERN_ERR,
879 LOG_FIP | LOG_ELS,
880 "2831 FLOGI response with cleared Fabric "
881 "bit fcf_index 0x%x "
882 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
883 "Fabric Name "
884 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
885 phba->fcf.current_rec.fcf_indx,
886 phba->fcf.current_rec.switch_name[0],
887 phba->fcf.current_rec.switch_name[1],
888 phba->fcf.current_rec.switch_name[2],
889 phba->fcf.current_rec.switch_name[3],
890 phba->fcf.current_rec.switch_name[4],
891 phba->fcf.current_rec.switch_name[5],
892 phba->fcf.current_rec.switch_name[6],
893 phba->fcf.current_rec.switch_name[7],
894 phba->fcf.current_rec.fabric_name[0],
895 phba->fcf.current_rec.fabric_name[1],
896 phba->fcf.current_rec.fabric_name[2],
897 phba->fcf.current_rec.fabric_name[3],
898 phba->fcf.current_rec.fabric_name[4],
899 phba->fcf.current_rec.fabric_name[5],
900 phba->fcf.current_rec.fabric_name[6],
901 phba->fcf.current_rec.fabric_name[7]);
902 lpfc_nlp_put(ndlp);
903 spin_lock_irq(&phba->hbalock);
904 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400905 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400906 spin_unlock_irq(&phba->hbalock);
907 goto out;
908 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500909 if (!rc) {
910 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400911 if (phba->hba_flag & HBA_FIP_SUPPORT)
912 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
913 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400914 "2769 FLOGI to FCF (x%x) "
915 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400916 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500917 spin_lock_irq(&phba->hbalock);
918 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400919 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500920 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500921 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500922 }
dea31012005-04-17 16:05:31 -0500923 }
924
925flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400926 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500927
James Smart858c9f62007-06-17 19:56:39 -0500928 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500929 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500930 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500931
932 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500933 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400934 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
935 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
936 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
937 (phba->link_state != LPFC_CLEAR_LA)) {
938 /* If FLOGI failed enable link interrupt. */
939 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500940 }
dea31012005-04-17 16:05:31 -0500941out:
942 lpfc_els_free_iocb(phba, cmdiocb);
943}
944
James Smarte59058c2008-08-24 21:49:00 -0400945/**
James Smart3621a712009-04-06 18:47:14 -0400946 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400947 * @vport: pointer to a host virtual N_Port data structure.
948 * @ndlp: pointer to a node-list data structure.
949 * @retry: number of retries to the command IOCB.
950 *
951 * This routine issues a Fabric Login (FLOGI) Request ELS command
952 * for a @vport. The initiator service parameters are put into the payload
953 * of the FLOGI Request IOCB and the top-level callback function pointer
954 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
955 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
956 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
957 *
958 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
959 * will be incremented by 1 for holding the ndlp and the reference to ndlp
960 * will be stored into the context1 field of the IOCB for the completion
961 * callback function to the FLOGI ELS command.
962 *
963 * Return code
964 * 0 - successfully issued flogi iocb for @vport
965 * 1 - failed to issue flogi iocb for @vport
966 **/
dea31012005-04-17 16:05:31 -0500967static int
James Smart2e0fef82007-06-17 19:56:36 -0500968lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500969 uint8_t retry)
970{
James Smart2e0fef82007-06-17 19:56:36 -0500971 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500972 struct serv_parm *sp;
973 IOCB_t *icmd;
974 struct lpfc_iocbq *elsiocb;
975 struct lpfc_sli_ring *pring;
976 uint8_t *pcmd;
977 uint16_t cmdsize;
978 uint32_t tmo;
979 int rc;
980
981 pring = &phba->sli.ring[LPFC_ELS_RING];
982
James Smart92d7f7b2007-06-17 19:56:38 -0500983 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500984 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
985 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500986
James Smart488d1462006-03-07 15:02:37 -0500987 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500988 return 1;
dea31012005-04-17 16:05:31 -0500989
990 icmd = &elsiocb->iocb;
991 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
992
993 /* For FLOGI request, remainder of payload is service parameters */
994 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500995 pcmd += sizeof(uint32_t);
996 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500997 sp = (struct serv_parm *) pcmd;
998
999 /* Setup CSPs accordingly for Fabric */
1000 sp->cmn.e_d_tov = 0;
1001 sp->cmn.w2.r_a_tov = 0;
1002 sp->cls1.classValid = 0;
1003 sp->cls2.seqDelivery = 1;
1004 sp->cls3.seqDelivery = 1;
1005 if (sp->cmn.fcphLow < FC_PH3)
1006 sp->cmn.fcphLow = FC_PH3;
1007 if (sp->cmn.fcphHigh < FC_PH3)
1008 sp->cmn.fcphHigh = FC_PH3;
1009
James Smart6fb120a2009-05-22 14:52:59 -04001010 if (phba->sli_rev == LPFC_SLI_REV4) {
1011 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1012 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1013 /* FLOGI needs to be 3 for WQE FCFI */
1014 /* Set the fcfi to the fcfi we registered with */
1015 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1016 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001017 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001018 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1019 icmd->ulpCt_h = 1;
1020 icmd->ulpCt_l = 0;
1021 }
1022
James Smart858c9f62007-06-17 19:56:39 -05001023 if (phba->fc_topology != TOPOLOGY_LOOP) {
1024 icmd->un.elsreq64.myID = 0;
1025 icmd->un.elsreq64.fl = 1;
1026 }
1027
dea31012005-04-17 16:05:31 -05001028 tmo = phba->fc_ratov;
1029 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001030 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001031 phba->fc_ratov = tmo;
1032
1033 phba->fc_stat.elsXmitFLOGI++;
1034 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001035
1036 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1037 "Issue FLOGI: opt:x%x",
1038 phba->sli3_options, 0, 0);
1039
James Smart92d7f7b2007-06-17 19:56:38 -05001040 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001041 if (rc == IOCB_ERROR) {
1042 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001043 return 1;
dea31012005-04-17 16:05:31 -05001044 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001045 return 0;
dea31012005-04-17 16:05:31 -05001046}
1047
James Smarte59058c2008-08-24 21:49:00 -04001048/**
James Smart3621a712009-04-06 18:47:14 -04001049 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001050 * @phba: pointer to lpfc hba data structure.
1051 *
1052 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1053 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1054 * list and issues an abort IOCB commond on each outstanding IOCB that
1055 * contains a active Fabric_DID ndlp. Note that this function is to issue
1056 * the abort IOCB command on all the outstanding IOCBs, thus when this
1057 * function returns, it does not guarantee all the IOCBs are actually aborted.
1058 *
1059 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001060 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001061 **/
dea31012005-04-17 16:05:31 -05001062int
James Smart2e0fef82007-06-17 19:56:36 -05001063lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001064{
1065 struct lpfc_sli_ring *pring;
1066 struct lpfc_iocbq *iocb, *next_iocb;
1067 struct lpfc_nodelist *ndlp;
1068 IOCB_t *icmd;
1069
1070 /* Abort outstanding I/O on NPort <nlp_DID> */
1071 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001072 "0201 Abort outstanding I/O on NPort x%x\n",
1073 Fabric_DID);
dea31012005-04-17 16:05:31 -05001074
1075 pring = &phba->sli.ring[LPFC_ELS_RING];
1076
1077 /*
1078 * Check the txcmplq for an iocb that matches the nport the driver is
1079 * searching for.
1080 */
James Smart2e0fef82007-06-17 19:56:36 -05001081 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001082 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1083 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001084 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1085 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001086 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001087 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1088 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001089 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001090 }
1091 }
James Smart2e0fef82007-06-17 19:56:36 -05001092 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001093
1094 return 0;
1095}
1096
James Smarte59058c2008-08-24 21:49:00 -04001097/**
James Smart3621a712009-04-06 18:47:14 -04001098 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001099 * @vport: pointer to a host virtual N_Port data structure.
1100 *
1101 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1102 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1103 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1104 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1105 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1106 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1107 * @vport.
1108 *
1109 * Return code
1110 * 0 - failed to issue initial flogi for @vport
1111 * 1 - successfully issued initial flogi for @vport
1112 **/
dea31012005-04-17 16:05:31 -05001113int
James Smart2e0fef82007-06-17 19:56:36 -05001114lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001115{
James Smart2e0fef82007-06-17 19:56:36 -05001116 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001117 struct lpfc_nodelist *ndlp;
1118
James Smart98c9ea52007-10-27 13:37:33 -04001119 vport->port_state = LPFC_FLOGI;
1120 lpfc_set_disctmo(vport);
1121
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001122 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001123 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001124 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001125 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001126 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1127 if (!ndlp)
1128 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001129 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001130 /* Set the node type */
1131 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001132 /* Put ndlp onto node list */
1133 lpfc_enqueue_node(vport, ndlp);
1134 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1135 /* re-setup ndlp without removing from node list */
1136 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1137 if (!ndlp)
1138 return 0;
dea31012005-04-17 16:05:31 -05001139 }
James Smart87af33f2007-10-27 13:37:43 -04001140
James Smart5ac6b302010-10-22 11:05:36 -04001141 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001142 /* This decrement of reference count to node shall kick off
1143 * the release of the node.
1144 */
James Smart329f9bc2007-04-25 09:53:01 -04001145 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001146 return 0;
1147 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001148 return 1;
dea31012005-04-17 16:05:31 -05001149}
1150
James Smarte59058c2008-08-24 21:49:00 -04001151/**
James Smart3621a712009-04-06 18:47:14 -04001152 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001153 * @vport: pointer to a host virtual N_Port data structure.
1154 *
1155 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1156 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1157 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1158 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1159 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1160 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1161 * @vport.
1162 *
1163 * Return code
1164 * 0 - failed to issue initial fdisc for @vport
1165 * 1 - successfully issued initial fdisc for @vport
1166 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001167int
1168lpfc_initial_fdisc(struct lpfc_vport *vport)
1169{
1170 struct lpfc_hba *phba = vport->phba;
1171 struct lpfc_nodelist *ndlp;
1172
1173 /* First look for the Fabric ndlp */
1174 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1175 if (!ndlp) {
1176 /* Cannot find existing Fabric ndlp, so allocate a new one */
1177 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1178 if (!ndlp)
1179 return 0;
1180 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001181 /* Put ndlp onto node list */
1182 lpfc_enqueue_node(vport, ndlp);
1183 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1184 /* re-setup ndlp without removing from node list */
1185 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1186 if (!ndlp)
1187 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001188 }
James Smarte47c9092008-02-08 18:49:26 -05001189
James Smart92d7f7b2007-06-17 19:56:38 -05001190 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001191 /* decrement node reference count to trigger the release of
1192 * the node.
1193 */
James Smart92d7f7b2007-06-17 19:56:38 -05001194 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001195 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001196 }
1197 return 1;
1198}
James Smart87af33f2007-10-27 13:37:43 -04001199
James Smarte59058c2008-08-24 21:49:00 -04001200/**
James Smart3621a712009-04-06 18:47:14 -04001201 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001202 * @vport: pointer to a host virtual N_Port data structure.
1203 *
1204 * This routine checks whether there are more remaining Port Logins
1205 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1206 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1207 * to issue ELS PLOGIs up to the configured discover threads with the
1208 * @vport (@vport->cfg_discovery_threads). The function also decrement
1209 * the @vport's num_disc_node by 1 if it is not already 0.
1210 **/
James Smart87af33f2007-10-27 13:37:43 -04001211void
James Smart2e0fef82007-06-17 19:56:36 -05001212lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001213{
1214 int sentplogi;
1215
James Smart2e0fef82007-06-17 19:56:36 -05001216 if (vport->num_disc_nodes)
1217 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001218
1219 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001220 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1221 "0232 Continue discovery with %d PLOGIs to go "
1222 "Data: x%x x%x x%x\n",
1223 vport->num_disc_nodes, vport->fc_plogi_cnt,
1224 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001225 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001226 if (vport->fc_flag & FC_NLP_MORE)
1227 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1228 sentplogi = lpfc_els_disc_plogi(vport);
1229
dea31012005-04-17 16:05:31 -05001230 return;
1231}
1232
James Smarte59058c2008-08-24 21:49:00 -04001233/**
James Smart3621a712009-04-06 18:47:14 -04001234 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001235 * @phba: pointer to lpfc hba data structure.
1236 * @prsp: pointer to response IOCB payload.
1237 * @ndlp: pointer to a node-list data structure.
1238 *
1239 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1240 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1241 * The following cases are considered N_Port confirmed:
1242 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1243 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1244 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1245 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1246 * 1) if there is a node on vport list other than the @ndlp with the same
1247 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1248 * on that node to release the RPI associated with the node; 2) if there is
1249 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1250 * into, a new node shall be allocated (or activated). In either case, the
1251 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1252 * be released and the new_ndlp shall be put on to the vport node list and
1253 * its pointer returned as the confirmed node.
1254 *
1255 * Note that before the @ndlp got "released", the keepDID from not-matching
1256 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1257 * of the @ndlp. This is because the release of @ndlp is actually to put it
1258 * into an inactive state on the vport node list and the vport node list
1259 * management algorithm does not allow two node with a same DID.
1260 *
1261 * Return code
1262 * pointer to the PLOGI N_Port @ndlp
1263 **/
James Smart488d1462006-03-07 15:02:37 -05001264static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001265lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001266 struct lpfc_nodelist *ndlp)
1267{
James Smart2e0fef82007-06-17 19:56:36 -05001268 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001269 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001270 struct lpfc_rport_data *rdata;
1271 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001272 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001273 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001274 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001275 int put_node;
1276 int put_rport;
James Smart488d1462006-03-07 15:02:37 -05001277
James Smart2fb9bd82006-12-02 13:33:57 -05001278 /* Fabric nodes can have the same WWPN so we don't bother searching
1279 * by WWPN. Just return the ndlp that was given to us.
1280 */
1281 if (ndlp->nlp_type & NLP_FABRIC)
1282 return ndlp;
1283
James Smart92d7f7b2007-06-17 19:56:38 -05001284 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001285 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001286
James Smart685f0bf2007-04-25 09:53:08 -04001287 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001288 * we have for that ndlp. If not, we have some work to do.
1289 */
James Smart2e0fef82007-06-17 19:56:36 -05001290 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001291
James Smarte47c9092008-02-08 18:49:26 -05001292 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001293 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001294
1295 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001296 rc = memcmp(&ndlp->nlp_portname, name,
1297 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001298 if (!rc)
1299 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001300 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1301 if (!new_ndlp)
1302 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001303 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001304 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001305 rc = memcmp(&ndlp->nlp_portname, name,
1306 sizeof(struct lpfc_name));
1307 if (!rc)
1308 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001309 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1310 NLP_STE_UNUSED_NODE);
1311 if (!new_ndlp)
1312 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001313 keepDID = new_ndlp->nlp_DID;
1314 } else
1315 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001316
James Smart2e0fef82007-06-17 19:56:36 -05001317 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001318 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001319 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001320
1321 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1322 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1323 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1324
James Smarte47c9092008-02-08 18:49:26 -05001325 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001326 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001327
James Smart2e0fef82007-06-17 19:56:36 -05001328 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001329 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1330 /* The new_ndlp is replacing ndlp totally, so we need
1331 * to put ndlp on UNUSED list and try to free it.
1332 */
James Smart0ff10d42008-01-11 01:52:36 -05001333
1334 /* Fix up the rport accordingly */
1335 rport = ndlp->rport;
1336 if (rport) {
1337 rdata = rport->dd_data;
1338 if (rdata->pnode == ndlp) {
1339 lpfc_nlp_put(ndlp);
1340 ndlp->rport = NULL;
1341 rdata->pnode = lpfc_nlp_get(new_ndlp);
1342 new_ndlp->rport = rport;
1343 }
1344 new_ndlp->nlp_type = ndlp->nlp_type;
1345 }
James Smart58da1ff2008-04-07 10:15:56 -04001346 /* We shall actually free the ndlp with both nlp_DID and
1347 * nlp_portname fields equals 0 to avoid any ndlp on the
1348 * nodelist never to be used.
1349 */
1350 if (ndlp->nlp_DID == 0) {
1351 spin_lock_irq(&phba->ndlp_lock);
1352 NLP_SET_FREE_REQ(ndlp);
1353 spin_unlock_irq(&phba->ndlp_lock);
1354 }
James Smart0ff10d42008-01-11 01:52:36 -05001355
James Smart58da1ff2008-04-07 10:15:56 -04001356 /* Two ndlps cannot have the same did on the nodelist */
1357 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001358 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001359 }
James Smart92795652006-07-06 15:50:02 -04001360 else {
James Smart2e0fef82007-06-17 19:56:36 -05001361 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001362 /* Two ndlps cannot have the same did */
1363 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001365 /* Since we are swapping the ndlp passed in with the new one
1366 * and the did has already been swapped, copy over the
1367 * state and names.
1368 */
1369 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1370 sizeof(struct lpfc_name));
1371 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1372 sizeof(struct lpfc_name));
1373 new_ndlp->nlp_state = ndlp->nlp_state;
1374 /* Fix up the rport accordingly */
1375 rport = ndlp->rport;
1376 if (rport) {
1377 rdata = rport->dd_data;
1378 put_node = rdata->pnode != NULL;
1379 put_rport = ndlp->rport != NULL;
1380 rdata->pnode = NULL;
1381 ndlp->rport = NULL;
1382 if (put_node)
1383 lpfc_nlp_put(ndlp);
1384 if (put_rport)
1385 put_device(&rport->dev);
1386 }
James Smart92795652006-07-06 15:50:02 -04001387 }
James Smart488d1462006-03-07 15:02:37 -05001388 return new_ndlp;
1389}
1390
James Smarte59058c2008-08-24 21:49:00 -04001391/**
James Smart3621a712009-04-06 18:47:14 -04001392 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001393 * @vport: pointer to a host virtual N_Port data structure.
1394 *
1395 * This routine checks whether more Registration State Change
1396 * Notifications (RSCNs) came in while the discovery state machine was in
1397 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1398 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1399 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1400 * handling the RSCNs.
1401 **/
James Smart87af33f2007-10-27 13:37:43 -04001402void
1403lpfc_end_rscn(struct lpfc_vport *vport)
1404{
1405 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1406
1407 if (vport->fc_flag & FC_RSCN_MODE) {
1408 /*
1409 * Check to see if more RSCNs came in while we were
1410 * processing this one.
1411 */
1412 if (vport->fc_rscn_id_cnt ||
1413 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1414 lpfc_els_handle_rscn(vport);
1415 else {
1416 spin_lock_irq(shost->host_lock);
1417 vport->fc_flag &= ~FC_RSCN_MODE;
1418 spin_unlock_irq(shost->host_lock);
1419 }
1420 }
1421}
1422
James Smarte59058c2008-08-24 21:49:00 -04001423/**
James Smart3621a712009-04-06 18:47:14 -04001424 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001425 * @phba: pointer to lpfc hba data structure.
1426 * @cmdiocb: pointer to lpfc command iocb data structure.
1427 * @rspiocb: pointer to lpfc response iocb data structure.
1428 *
1429 * This routine is the completion callback function for issuing the Port
1430 * Login (PLOGI) command. For PLOGI completion, there must be an active
1431 * ndlp on the vport node list that matches the remote node ID from the
1432 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1433 * ignored and command IOCB released. The PLOGI response IOCB status is
1434 * checked for error conditons. If there is error status reported, PLOGI
1435 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1436 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1437 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1438 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1439 * there are additional N_Port nodes with the vport that need to perform
1440 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1441 * PLOGIs.
1442 **/
dea31012005-04-17 16:05:31 -05001443static void
James Smart2e0fef82007-06-17 19:56:36 -05001444lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1445 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001446{
James Smart2e0fef82007-06-17 19:56:36 -05001447 struct lpfc_vport *vport = cmdiocb->vport;
1448 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001449 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001450 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001451 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001452 int disc, rc, did, type;
1453
dea31012005-04-17 16:05:31 -05001454 /* we pass cmdiocb to state machine which needs rspiocb as well */
1455 cmdiocb->context_un.rsp_iocb = rspiocb;
1456
1457 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001458 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1459 "PLOGI cmpl: status:x%x/x%x did:x%x",
1460 irsp->ulpStatus, irsp->un.ulpWord[4],
1461 irsp->un.elsreq64.remoteID);
1462
James Smart2e0fef82007-06-17 19:56:36 -05001463 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001464 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001465 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1466 "0136 PLOGI completes to NPort x%x "
1467 "with no ndlp. Data: x%x x%x x%x\n",
1468 irsp->un.elsreq64.remoteID,
1469 irsp->ulpStatus, irsp->un.ulpWord[4],
1470 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001471 goto out;
James Smarted957682007-06-17 19:56:37 -05001472 }
dea31012005-04-17 16:05:31 -05001473
1474 /* Since ndlp can be freed in the disc state machine, note if this node
1475 * is being used during discovery.
1476 */
James Smart2e0fef82007-06-17 19:56:36 -05001477 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001478 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001479 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001480 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001481 rc = 0;
1482
1483 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001484 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1485 "0102 PLOGI completes to NPort x%x "
1486 "Data: x%x x%x x%x x%x x%x\n",
1487 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1488 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001489 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001490 if (lpfc_els_chk_latt(vport)) {
1491 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001492 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001493 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001494 goto out;
1495 }
1496
1497 /* ndlp could be freed in DSM, save these values now */
1498 type = ndlp->nlp_type;
1499 did = ndlp->nlp_DID;
1500
1501 if (irsp->ulpStatus) {
1502 /* Check for retry */
1503 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1504 /* ELS command is being retried */
1505 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001506 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001507 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001508 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001509 }
1510 goto out;
1511 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001512 /* PLOGI failed Don't print the vport to vport rjts */
1513 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1514 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1515 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1516 (phba)->pport->cfg_log_verbose & LOG_ELS)
1517 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001518 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1519 ndlp->nlp_DID, irsp->ulpStatus,
1520 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001521 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001522 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001523 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001524 else
James Smart2e0fef82007-06-17 19:56:36 -05001525 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001526 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001527 } else {
1528 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001529 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001530 cmdiocb->context2)->list.next,
1531 struct lpfc_dmabuf, list);
1532 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001533 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001534 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001535 }
1536
James Smart2e0fef82007-06-17 19:56:36 -05001537 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001538 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001539 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001540
James Smart2e0fef82007-06-17 19:56:36 -05001541 if (vport->num_disc_nodes == 0) {
1542 spin_lock_irq(shost->host_lock);
1543 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1544 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001545
James Smart2e0fef82007-06-17 19:56:36 -05001546 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001547 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001548 }
1549 }
1550
1551out:
1552 lpfc_els_free_iocb(phba, cmdiocb);
1553 return;
1554}
1555
James Smarte59058c2008-08-24 21:49:00 -04001556/**
James Smart3621a712009-04-06 18:47:14 -04001557 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001558 * @vport: pointer to a host virtual N_Port data structure.
1559 * @did: destination port identifier.
1560 * @retry: number of retries to the command IOCB.
1561 *
1562 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1563 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1564 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1565 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1566 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1567 *
1568 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1569 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1570 * will be stored into the context1 field of the IOCB for the completion
1571 * callback function to the PLOGI ELS command.
1572 *
1573 * Return code
1574 * 0 - Successfully issued a plogi for @vport
1575 * 1 - failed to issue a plogi for @vport
1576 **/
dea31012005-04-17 16:05:31 -05001577int
James Smart2e0fef82007-06-17 19:56:36 -05001578lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001579{
James Smart2e0fef82007-06-17 19:56:36 -05001580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001581 struct serv_parm *sp;
1582 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001583 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001584 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001585 struct lpfc_sli *psli;
1586 uint8_t *pcmd;
1587 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001588 int ret;
dea31012005-04-17 16:05:31 -05001589
1590 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001591
James Smart98c9ea52007-10-27 13:37:33 -04001592 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001593 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1594 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001595
James Smarte47c9092008-02-08 18:49:26 -05001596 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001597 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001598 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001599 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001600 if (!elsiocb)
1601 return 1;
dea31012005-04-17 16:05:31 -05001602
1603 icmd = &elsiocb->iocb;
1604 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1605
1606 /* For PLOGI request, remainder of payload is service parameters */
1607 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001608 pcmd += sizeof(uint32_t);
1609 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001610 sp = (struct serv_parm *) pcmd;
1611
James Smart5ac6b302010-10-22 11:05:36 -04001612 /*
1613 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1614 * to device on remote loops work.
1615 */
1616 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1617 sp->cmn.altBbCredit = 1;
1618
dea31012005-04-17 16:05:31 -05001619 if (sp->cmn.fcphLow < FC_PH_4_3)
1620 sp->cmn.fcphLow = FC_PH_4_3;
1621
1622 if (sp->cmn.fcphHigh < FC_PH3)
1623 sp->cmn.fcphHigh = FC_PH3;
1624
James Smart858c9f62007-06-17 19:56:39 -05001625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1626 "Issue PLOGI: did:x%x",
1627 did, 0, 0);
1628
dea31012005-04-17 16:05:31 -05001629 phba->fc_stat.elsXmitPLOGI++;
1630 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001631 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001632
1633 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001634 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001635 return 1;
dea31012005-04-17 16:05:31 -05001636 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001637 return 0;
dea31012005-04-17 16:05:31 -05001638}
1639
James Smarte59058c2008-08-24 21:49:00 -04001640/**
James Smart3621a712009-04-06 18:47:14 -04001641 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001642 * @phba: pointer to lpfc hba data structure.
1643 * @cmdiocb: pointer to lpfc command iocb data structure.
1644 * @rspiocb: pointer to lpfc response iocb data structure.
1645 *
1646 * This routine is the completion callback function for a Process Login
1647 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1648 * status. If there is error status reported, PRLI retry shall be attempted
1649 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1650 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1651 * ndlp to mark the PRLI completion.
1652 **/
dea31012005-04-17 16:05:31 -05001653static void
James Smart2e0fef82007-06-17 19:56:36 -05001654lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1655 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001656{
James Smart2e0fef82007-06-17 19:56:36 -05001657 struct lpfc_vport *vport = cmdiocb->vport;
1658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001659 IOCB_t *irsp;
1660 struct lpfc_sli *psli;
1661 struct lpfc_nodelist *ndlp;
1662
1663 psli = &phba->sli;
1664 /* we pass cmdiocb to state machine which needs rspiocb as well */
1665 cmdiocb->context_un.rsp_iocb = rspiocb;
1666
1667 irsp = &(rspiocb->iocb);
1668 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001669 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001670 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001671 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001672
James Smart858c9f62007-06-17 19:56:39 -05001673 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1674 "PRLI cmpl: status:x%x/x%x did:x%x",
1675 irsp->ulpStatus, irsp->un.ulpWord[4],
1676 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001677 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001678 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1679 "0103 PRLI completes to NPort x%x "
1680 "Data: x%x x%x x%x x%x\n",
1681 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1682 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001683
James Smart2e0fef82007-06-17 19:56:36 -05001684 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001685 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001686 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001687 goto out;
1688
1689 if (irsp->ulpStatus) {
1690 /* Check for retry */
1691 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1692 /* ELS command is being retried */
1693 goto out;
1694 }
1695 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001696 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1697 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1698 ndlp->nlp_DID, irsp->ulpStatus,
1699 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001700 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001701 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001702 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001703 else
James Smart2e0fef82007-06-17 19:56:36 -05001704 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001705 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001706 } else
dea31012005-04-17 16:05:31 -05001707 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001708 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001709 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001710out:
1711 lpfc_els_free_iocb(phba, cmdiocb);
1712 return;
1713}
1714
James Smarte59058c2008-08-24 21:49:00 -04001715/**
James Smart3621a712009-04-06 18:47:14 -04001716 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001717 * @vport: pointer to a host virtual N_Port data structure.
1718 * @ndlp: pointer to a node-list data structure.
1719 * @retry: number of retries to the command IOCB.
1720 *
1721 * This routine issues a Process Login (PRLI) ELS command for the
1722 * @vport. The PRLI service parameters are set up in the payload of the
1723 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1724 * is put to the IOCB completion callback func field before invoking the
1725 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1726 *
1727 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1728 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1729 * will be stored into the context1 field of the IOCB for the completion
1730 * callback function to the PRLI ELS command.
1731 *
1732 * Return code
1733 * 0 - successfully issued prli iocb command for @vport
1734 * 1 - failed to issue prli iocb command for @vport
1735 **/
dea31012005-04-17 16:05:31 -05001736int
James Smart2e0fef82007-06-17 19:56:36 -05001737lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001738 uint8_t retry)
1739{
James Smart2e0fef82007-06-17 19:56:36 -05001740 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1741 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001742 PRLI *npr;
1743 IOCB_t *icmd;
1744 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001745 uint8_t *pcmd;
1746 uint16_t cmdsize;
1747
James Smart92d7f7b2007-06-17 19:56:38 -05001748 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001749 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1750 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001751 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001752 return 1;
dea31012005-04-17 16:05:31 -05001753
1754 icmd = &elsiocb->iocb;
1755 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1756
1757 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001758 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001759 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001760 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001761
1762 /* For PRLI, remainder of payload is PRLI parameter page */
1763 npr = (PRLI *) pcmd;
1764 /*
1765 * If our firmware version is 3.20 or later,
1766 * set the following bits for FC-TAPE support.
1767 */
1768 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1769 npr->ConfmComplAllowed = 1;
1770 npr->Retry = 1;
1771 npr->TaskRetryIdReq = 1;
1772 }
1773 npr->estabImagePair = 1;
1774 npr->readXferRdyDis = 1;
1775
1776 /* For FCP support */
1777 npr->prliType = PRLI_FCP_TYPE;
1778 npr->initiatorFunc = 1;
1779
James Smart858c9f62007-06-17 19:56:39 -05001780 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1781 "Issue PRLI: did:x%x",
1782 ndlp->nlp_DID, 0, 0);
1783
dea31012005-04-17 16:05:31 -05001784 phba->fc_stat.elsXmitPRLI++;
1785 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001786 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001787 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001788 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001789 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1790 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001791 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001792 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001793 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001794 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001795 return 1;
dea31012005-04-17 16:05:31 -05001796 }
James Smart2e0fef82007-06-17 19:56:36 -05001797 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001798 return 0;
dea31012005-04-17 16:05:31 -05001799}
1800
James Smarte59058c2008-08-24 21:49:00 -04001801/**
James Smart3621a712009-04-06 18:47:14 -04001802 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001803 * @vport: pointer to a host virtual N_Port data structure.
1804 *
1805 * This routine performs Registration State Change Notification (RSCN)
1806 * discovery for a @vport. If the @vport's node port recovery count is not
1807 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1808 * the nodes that need recovery. If none of the PLOGI were needed through
1809 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1810 * invoked to check and handle possible more RSCN came in during the period
1811 * of processing the current ones.
1812 **/
1813static void
1814lpfc_rscn_disc(struct lpfc_vport *vport)
1815{
1816 lpfc_can_disctmo(vport);
1817
1818 /* RSCN discovery */
1819 /* go thru NPR nodes and issue ELS PLOGIs */
1820 if (vport->fc_npr_cnt)
1821 if (lpfc_els_disc_plogi(vport))
1822 return;
1823
1824 lpfc_end_rscn(vport);
1825}
1826
1827/**
James Smart3621a712009-04-06 18:47:14 -04001828 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001829 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1830 *
1831 * This function is called when the final ADISC is completed during discovery.
1832 * This function handles clearing link attention or issuing reg_vpi depending
1833 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1834 * discovery.
1835 * This function is called with no locks held.
1836 **/
1837static void
1838lpfc_adisc_done(struct lpfc_vport *vport)
1839{
1840 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1841 struct lpfc_hba *phba = vport->phba;
1842
1843 /*
1844 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1845 * and continue discovery.
1846 */
1847 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001848 !(vport->fc_flag & FC_RSCN_MODE) &&
1849 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001850 lpfc_issue_reg_vpi(phba, vport);
1851 return;
1852 }
1853 /*
1854 * For SLI2, we need to set port_state to READY
1855 * and continue discovery.
1856 */
1857 if (vport->port_state < LPFC_VPORT_READY) {
1858 /* If we get here, there is nothing to ADISC */
1859 if (vport->port_type == LPFC_PHYSICAL_PORT)
1860 lpfc_issue_clear_la(phba, vport);
1861 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1862 vport->num_disc_nodes = 0;
1863 /* go thru NPR list, issue ELS PLOGIs */
1864 if (vport->fc_npr_cnt)
1865 lpfc_els_disc_plogi(vport);
1866 if (!vport->num_disc_nodes) {
1867 spin_lock_irq(shost->host_lock);
1868 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1869 spin_unlock_irq(shost->host_lock);
1870 lpfc_can_disctmo(vport);
1871 lpfc_end_rscn(vport);
1872 }
1873 }
1874 vport->port_state = LPFC_VPORT_READY;
1875 } else
1876 lpfc_rscn_disc(vport);
1877}
1878
1879/**
James Smart3621a712009-04-06 18:47:14 -04001880 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001881 * @vport: pointer to a host virtual N_Port data structure.
1882 *
1883 * This routine determines whether there are more ndlps on a @vport
1884 * node list need to have Address Discover (ADISC) issued. If so, it will
1885 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1886 * remaining nodes which need to have ADISC sent.
1887 **/
James Smart0ff10d42008-01-11 01:52:36 -05001888void
James Smart2e0fef82007-06-17 19:56:36 -05001889lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001890{
1891 int sentadisc;
1892
James Smart2e0fef82007-06-17 19:56:36 -05001893 if (vport->num_disc_nodes)
1894 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001895 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001896 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1897 "0210 Continue discovery with %d ADISCs to go "
1898 "Data: x%x x%x x%x\n",
1899 vport->num_disc_nodes, vport->fc_adisc_cnt,
1900 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001901 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001902 if (vport->fc_flag & FC_NLP_MORE) {
1903 lpfc_set_disctmo(vport);
1904 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1905 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001906 }
James Smart90160e02008-08-24 21:49:45 -04001907 if (!vport->num_disc_nodes)
1908 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001909 return;
1910}
1911
James Smarte59058c2008-08-24 21:49:00 -04001912/**
James Smart3621a712009-04-06 18:47:14 -04001913 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001914 * @phba: pointer to lpfc hba data structure.
1915 * @cmdiocb: pointer to lpfc command iocb data structure.
1916 * @rspiocb: pointer to lpfc response iocb data structure.
1917 *
1918 * This routine is the completion function for issuing the Address Discover
1919 * (ADISC) command. It first checks to see whether link went down during
1920 * the discovery process. If so, the node will be marked as node port
1921 * recovery for issuing discover IOCB by the link attention handler and
1922 * exit. Otherwise, the response status is checked. If error was reported
1923 * in the response status, the ADISC command shall be retried by invoking
1924 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1925 * the response status, the state machine is invoked to set transition
1926 * with respect to NLP_EVT_CMPL_ADISC event.
1927 **/
dea31012005-04-17 16:05:31 -05001928static void
James Smart2e0fef82007-06-17 19:56:36 -05001929lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1930 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001931{
James Smart2e0fef82007-06-17 19:56:36 -05001932 struct lpfc_vport *vport = cmdiocb->vport;
1933 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001934 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001935 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001936 int disc;
dea31012005-04-17 16:05:31 -05001937
1938 /* we pass cmdiocb to state machine which needs rspiocb as well */
1939 cmdiocb->context_un.rsp_iocb = rspiocb;
1940
1941 irsp = &(rspiocb->iocb);
1942 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001943
James Smart858c9f62007-06-17 19:56:39 -05001944 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1945 "ADISC cmpl: status:x%x/x%x did:x%x",
1946 irsp->ulpStatus, irsp->un.ulpWord[4],
1947 ndlp->nlp_DID);
1948
dea31012005-04-17 16:05:31 -05001949 /* Since ndlp can be freed in the disc state machine, note if this node
1950 * is being used during discovery.
1951 */
James Smart2e0fef82007-06-17 19:56:36 -05001952 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001953 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001954 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001955 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001956 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001957 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1958 "0104 ADISC completes to NPort x%x "
1959 "Data: x%x x%x x%x x%x x%x\n",
1960 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1961 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001962 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001963 if (lpfc_els_chk_latt(vport)) {
1964 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001965 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001966 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001967 goto out;
1968 }
1969
1970 if (irsp->ulpStatus) {
1971 /* Check for retry */
1972 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1973 /* ELS command is being retried */
1974 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001975 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001976 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001977 spin_unlock_irq(shost->host_lock);
1978 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001979 }
1980 goto out;
1981 }
1982 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001983 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1984 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1985 ndlp->nlp_DID, irsp->ulpStatus,
1986 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001987 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001988 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001989 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001990 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001991 } else
dea31012005-04-17 16:05:31 -05001992 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001993 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001994 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001995
James Smart90160e02008-08-24 21:49:45 -04001996 /* Check to see if there are more ADISCs to be sent */
1997 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001998 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001999out:
2000 lpfc_els_free_iocb(phba, cmdiocb);
2001 return;
2002}
2003
James Smarte59058c2008-08-24 21:49:00 -04002004/**
James Smart3621a712009-04-06 18:47:14 -04002005 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002006 * @vport: pointer to a virtual N_Port data structure.
2007 * @ndlp: pointer to a node-list data structure.
2008 * @retry: number of retries to the command IOCB.
2009 *
2010 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2011 * @vport. It prepares the payload of the ADISC ELS command, updates the
2012 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2013 * to issue the ADISC ELS command.
2014 *
2015 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2016 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2017 * will be stored into the context1 field of the IOCB for the completion
2018 * callback function to the ADISC ELS command.
2019 *
2020 * Return code
2021 * 0 - successfully issued adisc
2022 * 1 - failed to issue adisc
2023 **/
dea31012005-04-17 16:05:31 -05002024int
James Smart2e0fef82007-06-17 19:56:36 -05002025lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002026 uint8_t retry)
2027{
James Smart2e0fef82007-06-17 19:56:36 -05002028 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2029 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002030 ADISC *ap;
2031 IOCB_t *icmd;
2032 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002033 uint8_t *pcmd;
2034 uint16_t cmdsize;
2035
James Smart92d7f7b2007-06-17 19:56:38 -05002036 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002037 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2038 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002039 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002040 return 1;
dea31012005-04-17 16:05:31 -05002041
2042 icmd = &elsiocb->iocb;
2043 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2044
2045 /* For ADISC request, remainder of payload is service parameters */
2046 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002047 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002048
2049 /* Fill in ADISC payload */
2050 ap = (ADISC *) pcmd;
2051 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002052 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2053 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002054 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002055
James Smart858c9f62007-06-17 19:56:39 -05002056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2057 "Issue ADISC: did:x%x",
2058 ndlp->nlp_DID, 0, 0);
2059
dea31012005-04-17 16:05:31 -05002060 phba->fc_stat.elsXmitADISC++;
2061 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002062 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002063 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002064 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002065 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2066 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002067 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002068 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002069 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002070 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002071 return 1;
dea31012005-04-17 16:05:31 -05002072 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002073 return 0;
dea31012005-04-17 16:05:31 -05002074}
2075
James Smarte59058c2008-08-24 21:49:00 -04002076/**
James Smart3621a712009-04-06 18:47:14 -04002077 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002078 * @phba: pointer to lpfc hba data structure.
2079 * @cmdiocb: pointer to lpfc command iocb data structure.
2080 * @rspiocb: pointer to lpfc response iocb data structure.
2081 *
2082 * This routine is the completion function for issuing the ELS Logout (LOGO)
2083 * command. If no error status was reported from the LOGO response, the
2084 * state machine of the associated ndlp shall be invoked for transition with
2085 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2086 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2087 **/
dea31012005-04-17 16:05:31 -05002088static void
James Smart2e0fef82007-06-17 19:56:36 -05002089lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2090 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002091{
James Smart2e0fef82007-06-17 19:56:36 -05002092 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2093 struct lpfc_vport *vport = ndlp->vport;
2094 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002095 IOCB_t *irsp;
2096 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002097
2098 psli = &phba->sli;
2099 /* we pass cmdiocb to state machine which needs rspiocb as well */
2100 cmdiocb->context_un.rsp_iocb = rspiocb;
2101
2102 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002103 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002104 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002105 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002106
James Smart858c9f62007-06-17 19:56:39 -05002107 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2108 "LOGO cmpl: status:x%x/x%x did:x%x",
2109 irsp->ulpStatus, irsp->un.ulpWord[4],
2110 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002111 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2113 "0105 LOGO completes to NPort x%x "
2114 "Data: x%x x%x x%x x%x\n",
2115 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2116 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002117 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002118 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002119 goto out;
2120
James Smart92d7f7b2007-06-17 19:56:38 -05002121 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2122 /* NLP_EVT_DEVICE_RM should unregister the RPI
2123 * which should abort all outstanding IOs.
2124 */
2125 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2126 NLP_EVT_DEVICE_RM);
2127 goto out;
2128 }
2129
dea31012005-04-17 16:05:31 -05002130 if (irsp->ulpStatus) {
2131 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002132 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002133 /* ELS command is being retried */
2134 goto out;
dea31012005-04-17 16:05:31 -05002135 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002136 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2137 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2138 ndlp->nlp_DID, irsp->ulpStatus,
2139 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002140 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002141 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002142 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002143 else
James Smart2e0fef82007-06-17 19:56:36 -05002144 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002145 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002146 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002147 /* Good status, call state machine.
2148 * This will unregister the rpi if needed.
2149 */
James Smart2e0fef82007-06-17 19:56:36 -05002150 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002151 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002152out:
2153 lpfc_els_free_iocb(phba, cmdiocb);
2154 return;
2155}
2156
James Smarte59058c2008-08-24 21:49:00 -04002157/**
James Smart3621a712009-04-06 18:47:14 -04002158 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002159 * @vport: pointer to a virtual N_Port data structure.
2160 * @ndlp: pointer to a node-list data structure.
2161 * @retry: number of retries to the command IOCB.
2162 *
2163 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2164 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2165 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2166 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2167 *
2168 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2169 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2170 * will be stored into the context1 field of the IOCB for the completion
2171 * callback function to the LOGO ELS command.
2172 *
2173 * Return code
2174 * 0 - successfully issued logo
2175 * 1 - failed to issue logo
2176 **/
dea31012005-04-17 16:05:31 -05002177int
James Smart2e0fef82007-06-17 19:56:36 -05002178lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002179 uint8_t retry)
2180{
James Smart2e0fef82007-06-17 19:56:36 -05002181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2182 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002183 IOCB_t *icmd;
2184 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002185 uint8_t *pcmd;
2186 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002187 int rc;
dea31012005-04-17 16:05:31 -05002188
James Smart98c9ea52007-10-27 13:37:33 -04002189 spin_lock_irq(shost->host_lock);
2190 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2191 spin_unlock_irq(shost->host_lock);
2192 return 0;
2193 }
2194 spin_unlock_irq(shost->host_lock);
2195
James Smart92d7f7b2007-06-17 19:56:38 -05002196 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002197 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2198 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002199 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002200 return 1;
dea31012005-04-17 16:05:31 -05002201
2202 icmd = &elsiocb->iocb;
2203 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2204 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002205 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002206
2207 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002208 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002209 pcmd += sizeof(uint32_t);
2210 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002211
James Smart858c9f62007-06-17 19:56:39 -05002212 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2213 "Issue LOGO: did:x%x",
2214 ndlp->nlp_DID, 0, 0);
2215
dea31012005-04-17 16:05:31 -05002216 phba->fc_stat.elsXmitLOGO++;
2217 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002218 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002219 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002220 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002221 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002222
2223 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002224 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002225 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002226 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002227 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002228 return 1;
dea31012005-04-17 16:05:31 -05002229 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002230 return 0;
dea31012005-04-17 16:05:31 -05002231}
2232
James Smarte59058c2008-08-24 21:49:00 -04002233/**
James Smart3621a712009-04-06 18:47:14 -04002234 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002235 * @phba: pointer to lpfc hba data structure.
2236 * @cmdiocb: pointer to lpfc command iocb data structure.
2237 * @rspiocb: pointer to lpfc response iocb data structure.
2238 *
2239 * This routine is a generic completion callback function for ELS commands.
2240 * Specifically, it is the callback function which does not need to perform
2241 * any command specific operations. It is currently used by the ELS command
2242 * issuing routines for the ELS State Change Request (SCR),
2243 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2244 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2245 * certain debug loggings, this callback function simply invokes the
2246 * lpfc_els_chk_latt() routine to check whether link went down during the
2247 * discovery process.
2248 **/
dea31012005-04-17 16:05:31 -05002249static void
James Smart2e0fef82007-06-17 19:56:36 -05002250lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2251 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002252{
James Smart2e0fef82007-06-17 19:56:36 -05002253 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002254 IOCB_t *irsp;
2255
2256 irsp = &rspiocb->iocb;
2257
James Smart858c9f62007-06-17 19:56:39 -05002258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2259 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2260 irsp->ulpStatus, irsp->un.ulpWord[4],
2261 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002262 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002263 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2264 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2265 irsp->ulpIoTag, irsp->ulpStatus,
2266 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002267 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002268 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002269 lpfc_els_free_iocb(phba, cmdiocb);
2270 return;
2271}
2272
James Smarte59058c2008-08-24 21:49:00 -04002273/**
James Smart3621a712009-04-06 18:47:14 -04002274 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002275 * @vport: pointer to a host virtual N_Port data structure.
2276 * @nportid: N_Port identifier to the remote node.
2277 * @retry: number of retries to the command IOCB.
2278 *
2279 * This routine issues a State Change Request (SCR) to a fabric node
2280 * on a @vport. The remote node @nportid is passed into the function. It
2281 * first search the @vport node list to find the matching ndlp. If no such
2282 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2283 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2284 * routine is invoked to send the SCR IOCB.
2285 *
2286 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2287 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2288 * will be stored into the context1 field of the IOCB for the completion
2289 * callback function to the SCR ELS command.
2290 *
2291 * Return code
2292 * 0 - Successfully issued scr command
2293 * 1 - Failed to issue scr command
2294 **/
dea31012005-04-17 16:05:31 -05002295int
James Smart2e0fef82007-06-17 19:56:36 -05002296lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002297{
James Smart2e0fef82007-06-17 19:56:36 -05002298 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002299 IOCB_t *icmd;
2300 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002301 struct lpfc_sli *psli;
2302 uint8_t *pcmd;
2303 uint16_t cmdsize;
2304 struct lpfc_nodelist *ndlp;
2305
2306 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002307 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002308
James Smarte47c9092008-02-08 18:49:26 -05002309 ndlp = lpfc_findnode_did(vport, nportid);
2310 if (!ndlp) {
2311 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2312 if (!ndlp)
2313 return 1;
2314 lpfc_nlp_init(vport, ndlp, nportid);
2315 lpfc_enqueue_node(vport, ndlp);
2316 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2317 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2318 if (!ndlp)
2319 return 1;
2320 }
dea31012005-04-17 16:05:31 -05002321
James Smart2e0fef82007-06-17 19:56:36 -05002322 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2323 ndlp->nlp_DID, ELS_CMD_SCR);
2324
James Smart488d1462006-03-07 15:02:37 -05002325 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002326 /* This will trigger the release of the node just
2327 * allocated
2328 */
James Smart329f9bc2007-04-25 09:53:01 -04002329 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002330 return 1;
dea31012005-04-17 16:05:31 -05002331 }
2332
2333 icmd = &elsiocb->iocb;
2334 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2335
2336 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002337 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002338
2339 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002340 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002341 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2342
James Smart858c9f62007-06-17 19:56:39 -05002343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2344 "Issue SCR: did:x%x",
2345 ndlp->nlp_DID, 0, 0);
2346
dea31012005-04-17 16:05:31 -05002347 phba->fc_stat.elsXmitSCR++;
2348 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002349 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2350 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002351 /* The additional lpfc_nlp_put will cause the following
2352 * lpfc_els_free_iocb routine to trigger the rlease of
2353 * the node.
2354 */
James Smart329f9bc2007-04-25 09:53:01 -04002355 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002356 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002357 return 1;
dea31012005-04-17 16:05:31 -05002358 }
James Smartfa4066b2008-01-11 01:53:27 -05002359 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2360 * trigger the release of node.
2361 */
James Smart329f9bc2007-04-25 09:53:01 -04002362 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002363 return 0;
dea31012005-04-17 16:05:31 -05002364}
2365
James Smarte59058c2008-08-24 21:49:00 -04002366/**
James Smart3621a712009-04-06 18:47:14 -04002367 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002368 * @vport: pointer to a host virtual N_Port data structure.
2369 * @nportid: N_Port identifier to the remote node.
2370 * @retry: number of retries to the command IOCB.
2371 *
2372 * This routine issues a Fibre Channel Address Resolution Response
2373 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2374 * is passed into the function. It first search the @vport node list to find
2375 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2376 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2377 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2378 *
2379 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2380 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2381 * will be stored into the context1 field of the IOCB for the completion
2382 * callback function to the PARPR ELS command.
2383 *
2384 * Return code
2385 * 0 - Successfully issued farpr command
2386 * 1 - Failed to issue farpr command
2387 **/
dea31012005-04-17 16:05:31 -05002388static int
James Smart2e0fef82007-06-17 19:56:36 -05002389lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002390{
James Smart2e0fef82007-06-17 19:56:36 -05002391 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002392 IOCB_t *icmd;
2393 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002394 struct lpfc_sli *psli;
2395 FARP *fp;
2396 uint8_t *pcmd;
2397 uint32_t *lp;
2398 uint16_t cmdsize;
2399 struct lpfc_nodelist *ondlp;
2400 struct lpfc_nodelist *ndlp;
2401
2402 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002403 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002404
James Smarte47c9092008-02-08 18:49:26 -05002405 ndlp = lpfc_findnode_did(vport, nportid);
2406 if (!ndlp) {
2407 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2408 if (!ndlp)
2409 return 1;
2410 lpfc_nlp_init(vport, ndlp, nportid);
2411 lpfc_enqueue_node(vport, ndlp);
2412 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2413 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2414 if (!ndlp)
2415 return 1;
2416 }
James Smart2e0fef82007-06-17 19:56:36 -05002417
2418 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2419 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002420 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002421 /* This will trigger the release of the node just
2422 * allocated
2423 */
James Smart329f9bc2007-04-25 09:53:01 -04002424 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002425 return 1;
dea31012005-04-17 16:05:31 -05002426 }
2427
2428 icmd = &elsiocb->iocb;
2429 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2430
2431 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002432 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002433
2434 /* Fill in FARPR payload */
2435 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002436 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002437 lp = (uint32_t *) pcmd;
2438 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002439 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002440 fp->Rflags = 0;
2441 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2442
James Smart92d7f7b2007-06-17 19:56:38 -05002443 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2444 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002445 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002446 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002447 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002448 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002449 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002450 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002451 }
2452
James Smart858c9f62007-06-17 19:56:39 -05002453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2454 "Issue FARPR: did:x%x",
2455 ndlp->nlp_DID, 0, 0);
2456
dea31012005-04-17 16:05:31 -05002457 phba->fc_stat.elsXmitFARPR++;
2458 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002459 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2460 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002461 /* The additional lpfc_nlp_put will cause the following
2462 * lpfc_els_free_iocb routine to trigger the release of
2463 * the node.
2464 */
James Smart329f9bc2007-04-25 09:53:01 -04002465 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002466 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002467 return 1;
dea31012005-04-17 16:05:31 -05002468 }
James Smartfa4066b2008-01-11 01:53:27 -05002469 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2470 * trigger the release of the node.
2471 */
James Smart329f9bc2007-04-25 09:53:01 -04002472 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002473 return 0;
dea31012005-04-17 16:05:31 -05002474}
2475
James Smarte59058c2008-08-24 21:49:00 -04002476/**
James Smart3621a712009-04-06 18:47:14 -04002477 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002478 * @vport: pointer to a host virtual N_Port data structure.
2479 * @nlp: pointer to a node-list data structure.
2480 *
2481 * This routine cancels the timer with a delayed IOCB-command retry for
2482 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2483 * removes the ELS retry event if it presents. In addition, if the
2484 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2485 * commands are sent for the @vport's nodes that require issuing discovery
2486 * ADISC.
2487 **/
dea31012005-04-17 16:05:31 -05002488void
James Smart2e0fef82007-06-17 19:56:36 -05002489lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002490{
James Smart2e0fef82007-06-17 19:56:36 -05002491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002492 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002493
James Smart0d2b6b82008-06-14 22:52:47 -04002494 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2495 return;
James Smart2e0fef82007-06-17 19:56:36 -05002496 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002497 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002498 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002499 del_timer_sync(&nlp->nlp_delayfunc);
2500 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002501 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002502 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002503 /* Decrement nlp reference count held for the delayed retry */
2504 evtp = &nlp->els_retry_evt;
2505 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2506 }
James Smartfdcebe22006-03-07 15:04:01 -05002507 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002508 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002509 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002510 spin_unlock_irq(shost->host_lock);
2511 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002512 if (vport->port_state < LPFC_VPORT_READY) {
2513 /* Check if there are more ADISCs to be sent */
2514 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002515 } else {
2516 /* Check if there are more PLOGIs to be sent */
2517 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002518 if (vport->num_disc_nodes == 0) {
2519 spin_lock_irq(shost->host_lock);
2520 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2521 spin_unlock_irq(shost->host_lock);
2522 lpfc_can_disctmo(vport);
2523 lpfc_end_rscn(vport);
2524 }
James Smartfdcebe22006-03-07 15:04:01 -05002525 }
2526 }
2527 }
2528 return;
2529}
2530
James Smarte59058c2008-08-24 21:49:00 -04002531/**
James Smart3621a712009-04-06 18:47:14 -04002532 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002533 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2534 *
2535 * This routine is invoked by the ndlp delayed-function timer to check
2536 * whether there is any pending ELS retry event(s) with the node. If not, it
2537 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2538 * adds the delayed events to the HBA work list and invokes the
2539 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2540 * event. Note that lpfc_nlp_get() is called before posting the event to
2541 * the work list to hold reference count of ndlp so that it guarantees the
2542 * reference to ndlp will still be available when the worker thread gets
2543 * to the event associated with the ndlp.
2544 **/
James Smartfdcebe22006-03-07 15:04:01 -05002545void
dea31012005-04-17 16:05:31 -05002546lpfc_els_retry_delay(unsigned long ptr)
2547{
James Smart2e0fef82007-06-17 19:56:36 -05002548 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2549 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002550 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002551 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002552 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002553
James Smart92d7f7b2007-06-17 19:56:38 -05002554 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002555 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002556 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002557 return;
2558 }
2559
James Smartfa4066b2008-01-11 01:53:27 -05002560 /* We need to hold the node by incrementing the reference
2561 * count until the queued work is done
2562 */
2563 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002564 if (evtp->evt_arg1) {
2565 evtp->evt = LPFC_EVT_ELS_RETRY;
2566 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002567 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002568 }
James Smart92d7f7b2007-06-17 19:56:38 -05002569 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002570 return;
2571}
2572
James Smarte59058c2008-08-24 21:49:00 -04002573/**
James Smart3621a712009-04-06 18:47:14 -04002574 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002575 * @ndlp: pointer to a node-list data structure.
2576 *
2577 * This routine is the worker-thread handler for processing the @ndlp delayed
2578 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2579 * the last ELS command from the associated ndlp and invokes the proper ELS
2580 * function according to the delayed ELS command to retry the command.
2581 **/
dea31012005-04-17 16:05:31 -05002582void
2583lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2584{
James Smart2e0fef82007-06-17 19:56:36 -05002585 struct lpfc_vport *vport = ndlp->vport;
2586 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2587 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002588
James Smart2e0fef82007-06-17 19:56:36 -05002589 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002590 did = ndlp->nlp_DID;
2591 cmd = ndlp->nlp_last_elscmd;
2592 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002593
2594 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002595 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002596 return;
2597 }
2598
2599 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002600 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002601 /*
2602 * If a discovery event readded nlp_delayfunc after timer
2603 * firing and before processing the timer, cancel the
2604 * nlp_delayfunc.
2605 */
2606 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002607 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002608 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002609
2610 switch (cmd) {
2611 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002612 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002613 break;
2614 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002615 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002616 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002618 }
dea31012005-04-17 16:05:31 -05002619 break;
2620 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002621 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002622 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002624 }
dea31012005-04-17 16:05:31 -05002625 break;
2626 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002627 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002628 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002629 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002630 }
dea31012005-04-17 16:05:31 -05002631 break;
2632 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002633 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002634 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002635 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002636 }
dea31012005-04-17 16:05:31 -05002637 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002638 case ELS_CMD_FDISC:
2639 lpfc_issue_els_fdisc(vport, ndlp, retry);
2640 break;
dea31012005-04-17 16:05:31 -05002641 }
2642 return;
2643}
2644
James Smarte59058c2008-08-24 21:49:00 -04002645/**
James Smart3621a712009-04-06 18:47:14 -04002646 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002647 * @phba: pointer to lpfc hba data structure.
2648 * @cmdiocb: pointer to lpfc command iocb data structure.
2649 * @rspiocb: pointer to lpfc response iocb data structure.
2650 *
2651 * This routine makes a retry decision on an ELS command IOCB, which has
2652 * failed. The following ELS IOCBs use this function for retrying the command
2653 * when previously issued command responsed with error status: FLOGI, PLOGI,
2654 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2655 * returned error status, it makes the decision whether a retry shall be
2656 * issued for the command, and whether a retry shall be made immediately or
2657 * delayed. In the former case, the corresponding ELS command issuing-function
2658 * is called to retry the command. In the later case, the ELS command shall
2659 * be posted to the ndlp delayed event and delayed function timer set to the
2660 * ndlp for the delayed command issusing.
2661 *
2662 * Return code
2663 * 0 - No retry of els command is made
2664 * 1 - Immediate or delayed retry of els command is made
2665 **/
dea31012005-04-17 16:05:31 -05002666static int
James Smart2e0fef82007-06-17 19:56:36 -05002667lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2668 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002669{
James Smart2e0fef82007-06-17 19:56:36 -05002670 struct lpfc_vport *vport = cmdiocb->vport;
2671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2672 IOCB_t *irsp = &rspiocb->iocb;
2673 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2674 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002675 uint32_t *elscmd;
2676 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002677 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002678 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002679 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002680 uint32_t did;
dea31012005-04-17 16:05:31 -05002681
James Smart488d1462006-03-07 15:02:37 -05002682
dea31012005-04-17 16:05:31 -05002683 /* Note: context2 may be 0 for internal driver abort
2684 * of delays ELS command.
2685 */
2686
2687 if (pcmd && pcmd->virt) {
2688 elscmd = (uint32_t *) (pcmd->virt);
2689 cmd = *elscmd++;
2690 }
2691
James Smarte47c9092008-02-08 18:49:26 -05002692 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002693 did = ndlp->nlp_DID;
2694 else {
2695 /* We should only hit this case for retrying PLOGI */
2696 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002697 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002698 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2699 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002700 return 1;
2701 }
2702
James Smart858c9f62007-06-17 19:56:39 -05002703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2704 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2705 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2706
dea31012005-04-17 16:05:31 -05002707 switch (irsp->ulpStatus) {
2708 case IOSTAT_FCP_RSP_ERROR:
2709 case IOSTAT_REMOTE_STOP:
2710 break;
2711
2712 case IOSTAT_LOCAL_REJECT:
2713 switch ((irsp->un.ulpWord[4] & 0xff)) {
2714 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002715 if (cmd == ELS_CMD_FLOGI) {
2716 if (PCI_DEVICE_ID_HORNET ==
2717 phba->pcidev->device) {
2718 phba->fc_topology = TOPOLOGY_LOOP;
2719 phba->pport->fc_myDID = 0;
2720 phba->alpa_map[0] = 0;
2721 phba->alpa_map[1] = 0;
2722 }
2723 }
James Smart2e0fef82007-06-17 19:56:36 -05002724 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002725 delay = 1000;
dea31012005-04-17 16:05:31 -05002726 retry = 1;
2727 break;
2728
James Smart92d7f7b2007-06-17 19:56:38 -05002729 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002730 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2731 "0124 Retry illegal cmd x%x "
2732 "retry:x%x delay:x%x\n",
2733 cmd, cmdiocb->retry, delay);
2734 retry = 1;
2735 /* All command's retry policy */
2736 maxretry = 8;
2737 if (cmdiocb->retry > 2)
2738 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002739 break;
2740
dea31012005-04-17 16:05:31 -05002741 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002742 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002743 retry = 1;
2744 if (cmdiocb->retry > 100)
2745 delay = 100;
2746 maxretry = 250;
2747 break;
2748
2749 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002750 delay = 100;
dea31012005-04-17 16:05:31 -05002751 retry = 1;
2752 break;
2753
James Smart858c9f62007-06-17 19:56:39 -05002754 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002755 case IOERR_INVALID_RPI:
2756 retry = 1;
2757 break;
2758 }
2759 break;
2760
2761 case IOSTAT_NPORT_RJT:
2762 case IOSTAT_FABRIC_RJT:
2763 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2764 retry = 1;
2765 break;
2766 }
2767 break;
2768
2769 case IOSTAT_NPORT_BSY:
2770 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002771 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002772 retry = 1;
2773 break;
2774
2775 case IOSTAT_LS_RJT:
2776 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2777 /* Added for Vendor specifc support
2778 * Just keep retrying for these Rsn / Exp codes
2779 */
2780 switch (stat.un.b.lsRjtRsnCode) {
2781 case LSRJT_UNABLE_TPC:
2782 if (stat.un.b.lsRjtRsnCodeExp ==
2783 LSEXP_CMD_IN_PROGRESS) {
2784 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002785 delay = 1000;
dea31012005-04-17 16:05:31 -05002786 maxretry = 48;
2787 }
2788 retry = 1;
2789 break;
2790 }
James Smartffc95492010-06-07 15:23:17 -04002791 if (stat.un.b.lsRjtRsnCodeExp ==
2792 LSEXP_CANT_GIVE_DATA) {
2793 if (cmd == ELS_CMD_PLOGI) {
2794 delay = 1000;
2795 maxretry = 48;
2796 }
2797 retry = 1;
2798 break;
2799 }
dea31012005-04-17 16:05:31 -05002800 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002801 delay = 1000;
dea31012005-04-17 16:05:31 -05002802 maxretry = lpfc_max_els_tries + 1;
2803 retry = 1;
2804 break;
2805 }
James Smart92d7f7b2007-06-17 19:56:38 -05002806 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2807 (cmd == ELS_CMD_FDISC) &&
2808 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002809 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2810 "0125 FDISC Failed (x%x). "
2811 "Fabric out of resources\n",
2812 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002813 lpfc_vport_set_state(vport,
2814 FC_VPORT_NO_FABRIC_RSCS);
2815 }
dea31012005-04-17 16:05:31 -05002816 break;
2817
2818 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002819 if ((cmd == ELS_CMD_PLOGI) ||
2820 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002821 delay = 1000;
dea31012005-04-17 16:05:31 -05002822 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002823 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002824 /* FDISC retry policy */
2825 maxretry = 48;
2826 if (cmdiocb->retry >= 32)
2827 delay = 1000;
dea31012005-04-17 16:05:31 -05002828 }
2829 retry = 1;
2830 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002831
2832 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002833 /* There are some cases where switches return this
2834 * error when they are not ready and should be returning
2835 * Logical Busy. We should delay every time.
2836 */
2837 if (cmd == ELS_CMD_FDISC &&
2838 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2839 maxretry = 3;
2840 delay = 1000;
2841 retry = 1;
2842 break;
2843 }
James Smart92d7f7b2007-06-17 19:56:38 -05002844 case LSRJT_PROTOCOL_ERR:
2845 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2846 (cmd == ELS_CMD_FDISC) &&
2847 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2848 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2849 ) {
James Smarte8b62012007-08-02 11:10:09 -04002850 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002851 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002852 "Fabric Detected Bad WWN\n",
2853 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002854 lpfc_vport_set_state(vport,
2855 FC_VPORT_FABRIC_REJ_WWN);
2856 }
2857 break;
dea31012005-04-17 16:05:31 -05002858 }
2859 break;
2860
2861 case IOSTAT_INTERMED_RSP:
2862 case IOSTAT_BA_RJT:
2863 break;
2864
2865 default:
2866 break;
2867 }
2868
James Smart488d1462006-03-07 15:02:37 -05002869 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002870 retry = 1;
dea31012005-04-17 16:05:31 -05002871
James Smart695a8142010-01-26 23:08:03 -05002872 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002873 (phba->fc_topology != TOPOLOGY_LOOP) &&
2874 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002875 /* FLOGI retry policy */
2876 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002877 /* retry forever */
2878 maxretry = 0;
2879 if (cmdiocb->retry >= 100)
2880 delay = 5000;
2881 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002882 delay = 1000;
2883 }
2884
James Smart6669f9b2009-10-02 15:16:45 -04002885 cmdiocb->retry++;
2886 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002887 phba->fc_stat.elsRetryExceeded++;
2888 retry = 0;
2889 }
2890
James Smarted957682007-06-17 19:56:37 -05002891 if ((vport->load_flag & FC_UNLOADING) != 0)
2892 retry = 0;
2893
dea31012005-04-17 16:05:31 -05002894 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04002895 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2896 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2897 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2898 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2899 "2849 Stop retry ELS command "
2900 "x%x to remote NPORT x%x, "
2901 "Data: x%x x%x\n", cmd, did,
2902 cmdiocb->retry, delay);
2903 return 0;
2904 }
2905 }
dea31012005-04-17 16:05:31 -05002906
2907 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002908 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2909 "0107 Retry ELS command x%x to remote "
2910 "NPORT x%x Data: x%x x%x\n",
2911 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002912
James Smart858c9f62007-06-17 19:56:39 -05002913 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2914 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2915 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2916 /* Don't reset timer for no resources */
2917
dea31012005-04-17 16:05:31 -05002918 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002919 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002920 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002921 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002922 }
2923
2924 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002925 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002926 phba->fc_stat.elsDelayRetry++;
2927 ndlp->nlp_retry = cmdiocb->retry;
2928
James Smart92d7f7b2007-06-17 19:56:38 -05002929 /* delay is specified in milliseconds */
2930 mod_timer(&ndlp->nlp_delayfunc,
2931 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002932 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002933 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002934 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002935
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002936 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002937 if (cmd == ELS_CMD_PRLI)
2938 lpfc_nlp_set_state(vport, ndlp,
2939 NLP_STE_REG_LOGIN_ISSUE);
2940 else
2941 lpfc_nlp_set_state(vport, ndlp,
2942 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002943 ndlp->nlp_last_elscmd = cmd;
2944
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002945 return 1;
dea31012005-04-17 16:05:31 -05002946 }
2947 switch (cmd) {
2948 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002949 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002950 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002951 case ELS_CMD_FDISC:
2952 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2953 return 1;
dea31012005-04-17 16:05:31 -05002954 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002955 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002956 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002957 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002958 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002959 }
James Smart2e0fef82007-06-17 19:56:36 -05002960 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002961 return 1;
dea31012005-04-17 16:05:31 -05002962 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002963 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002964 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2965 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002966 return 1;
dea31012005-04-17 16:05:31 -05002967 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002968 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002969 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2970 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002971 return 1;
dea31012005-04-17 16:05:31 -05002972 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002973 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002974 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2975 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002976 return 1;
dea31012005-04-17 16:05:31 -05002977 }
2978 }
dea31012005-04-17 16:05:31 -05002979 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002980 if (logerr) {
2981 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2982 "0137 No retry ELS command x%x to remote "
2983 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2984 cmd, did, irsp->ulpStatus,
2985 irsp->un.ulpWord[4]);
2986 }
2987 else {
2988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002989 "0108 No retry ELS command x%x to remote "
2990 "NPORT x%x Retried:%d Error:x%x/%x\n",
2991 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2992 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002993 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002994 return 0;
dea31012005-04-17 16:05:31 -05002995}
2996
James Smarte59058c2008-08-24 21:49:00 -04002997/**
James Smart3621a712009-04-06 18:47:14 -04002998 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002999 * @phba: pointer to lpfc hba data structure.
3000 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3001 *
3002 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3003 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3004 * checks to see whether there is a lpfc DMA buffer associated with the
3005 * response of the command IOCB. If so, it will be released before releasing
3006 * the lpfc DMA buffer associated with the IOCB itself.
3007 *
3008 * Return code
3009 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3010 **/
James Smart09372822008-01-11 01:52:54 -05003011static int
James Smart87af33f2007-10-27 13:37:43 -04003012lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3013{
3014 struct lpfc_dmabuf *buf_ptr;
3015
James Smarte59058c2008-08-24 21:49:00 -04003016 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003017 if (!list_empty(&buf_ptr1->list)) {
3018 list_remove_head(&buf_ptr1->list, buf_ptr,
3019 struct lpfc_dmabuf,
3020 list);
3021 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3022 kfree(buf_ptr);
3023 }
3024 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3025 kfree(buf_ptr1);
3026 return 0;
3027}
3028
James Smarte59058c2008-08-24 21:49:00 -04003029/**
James Smart3621a712009-04-06 18:47:14 -04003030 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003031 * @phba: pointer to lpfc hba data structure.
3032 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3033 *
3034 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3035 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3036 * pool.
3037 *
3038 * Return code
3039 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3040 **/
James Smart09372822008-01-11 01:52:54 -05003041static int
James Smart87af33f2007-10-27 13:37:43 -04003042lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3043{
3044 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3045 kfree(buf_ptr);
3046 return 0;
3047}
3048
James Smarte59058c2008-08-24 21:49:00 -04003049/**
James Smart3621a712009-04-06 18:47:14 -04003050 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003051 * @phba: pointer to lpfc hba data structure.
3052 * @elsiocb: pointer to lpfc els command iocb data structure.
3053 *
3054 * This routine frees a command IOCB and its associated resources. The
3055 * command IOCB data structure contains the reference to various associated
3056 * resources, these fields must be set to NULL if the associated reference
3057 * not present:
3058 * context1 - reference to ndlp
3059 * context2 - reference to cmd
3060 * context2->next - reference to rsp
3061 * context3 - reference to bpl
3062 *
3063 * It first properly decrements the reference count held on ndlp for the
3064 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3065 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3066 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3067 * adds the DMA buffer the @phba data structure for the delayed release.
3068 * If reference to the Buffer Pointer List (BPL) is present, the
3069 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3070 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3071 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3072 *
3073 * Return code
3074 * 0 - Success (currently, always return 0)
3075 **/
James Smart87af33f2007-10-27 13:37:43 -04003076int
James Smart329f9bc2007-04-25 09:53:01 -04003077lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003078{
3079 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003080 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003081
James Smarta8adb832007-10-27 13:37:53 -04003082 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3083 if (ndlp) {
3084 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3085 lpfc_nlp_put(ndlp);
3086
3087 /* If the ndlp is not being used by another discovery
3088 * thread, free it.
3089 */
3090 if (!lpfc_nlp_not_used(ndlp)) {
3091 /* If ndlp is being used by another discovery
3092 * thread, just clear NLP_DEFER_RM
3093 */
3094 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3095 }
3096 }
3097 else
3098 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003099 elsiocb->context1 = NULL;
3100 }
dea31012005-04-17 16:05:31 -05003101 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3102 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003103 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3104 /* Firmware could still be in progress of DMAing
3105 * payload, so don't free data buffer till after
3106 * a hbeat.
3107 */
3108 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3109 buf_ptr = elsiocb->context2;
3110 elsiocb->context2 = NULL;
3111 if (buf_ptr) {
3112 buf_ptr1 = NULL;
3113 spin_lock_irq(&phba->hbalock);
3114 if (!list_empty(&buf_ptr->list)) {
3115 list_remove_head(&buf_ptr->list,
3116 buf_ptr1, struct lpfc_dmabuf,
3117 list);
3118 INIT_LIST_HEAD(&buf_ptr1->list);
3119 list_add_tail(&buf_ptr1->list,
3120 &phba->elsbuf);
3121 phba->elsbuf_cnt++;
3122 }
3123 INIT_LIST_HEAD(&buf_ptr->list);
3124 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3125 phba->elsbuf_cnt++;
3126 spin_unlock_irq(&phba->hbalock);
3127 }
3128 } else {
3129 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3130 lpfc_els_free_data(phba, buf_ptr1);
3131 }
dea31012005-04-17 16:05:31 -05003132 }
3133
3134 if (elsiocb->context3) {
3135 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003136 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003137 }
James Bottomley604a3e32005-10-29 10:28:33 -05003138 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003139 return 0;
3140}
3141
James Smarte59058c2008-08-24 21:49:00 -04003142/**
James Smart3621a712009-04-06 18:47:14 -04003143 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003144 * @phba: pointer to lpfc hba data structure.
3145 * @cmdiocb: pointer to lpfc command iocb data structure.
3146 * @rspiocb: pointer to lpfc response iocb data structure.
3147 *
3148 * This routine is the completion callback function to the Logout (LOGO)
3149 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3150 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3151 * release the ndlp if it has the last reference remaining (reference count
3152 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3153 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3154 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3155 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3156 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3157 * IOCB data structure.
3158 **/
dea31012005-04-17 16:05:31 -05003159static void
James Smart2e0fef82007-06-17 19:56:36 -05003160lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3161 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003162{
James Smart2e0fef82007-06-17 19:56:36 -05003163 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3164 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003165 IOCB_t *irsp;
3166
3167 irsp = &rspiocb->iocb;
3168 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3169 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3170 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003171 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003172 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3173 "0109 ACC to LOGO completes to NPort x%x "
3174 "Data: x%x x%x x%x\n",
3175 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3176 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003177
3178 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3179 /* NPort Recovery mode or node is just allocated */
3180 if (!lpfc_nlp_not_used(ndlp)) {
3181 /* If the ndlp is being used by another discovery
3182 * thread, just unregister the RPI.
3183 */
3184 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003185 } else {
3186 /* Indicate the node has already released, should
3187 * not reference to it from within lpfc_els_free_iocb.
3188 */
3189 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003190 }
dea31012005-04-17 16:05:31 -05003191 }
3192 lpfc_els_free_iocb(phba, cmdiocb);
3193 return;
3194}
3195
James Smarte59058c2008-08-24 21:49:00 -04003196/**
James Smart3621a712009-04-06 18:47:14 -04003197 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003198 * @phba: pointer to lpfc hba data structure.
3199 * @pmb: pointer to the driver internal queue element for mailbox command.
3200 *
3201 * This routine is the completion callback function for unregister default
3202 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3203 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3204 * decrements the ndlp reference count held for this completion callback
3205 * function. After that, it invokes the lpfc_nlp_not_used() to check
3206 * whether there is only one reference left on the ndlp. If so, it will
3207 * perform one more decrement and trigger the release of the ndlp.
3208 **/
James Smart858c9f62007-06-17 19:56:39 -05003209void
3210lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3211{
3212 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3213 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3214
James Smart6fb120a2009-05-22 14:52:59 -04003215 /*
3216 * This routine is used to register and unregister in previous SLI
3217 * modes.
3218 */
3219 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3220 (phba->sli_rev == LPFC_SLI_REV4))
3221 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3222
James Smart858c9f62007-06-17 19:56:39 -05003223 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003224 pmb->context2 = NULL;
3225
James Smart858c9f62007-06-17 19:56:39 -05003226 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3227 kfree(mp);
3228 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003229 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003230 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003231 /* This is the end of the default RPI cleanup logic for this
3232 * ndlp. If no other discovery threads are using this ndlp.
3233 * we should free all resources associated with it.
3234 */
3235 lpfc_nlp_not_used(ndlp);
3236 }
James Smart3772a992009-05-22 14:50:54 -04003237
James Smart858c9f62007-06-17 19:56:39 -05003238 return;
3239}
3240
James Smarte59058c2008-08-24 21:49:00 -04003241/**
James Smart3621a712009-04-06 18:47:14 -04003242 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003243 * @phba: pointer to lpfc hba data structure.
3244 * @cmdiocb: pointer to lpfc command iocb data structure.
3245 * @rspiocb: pointer to lpfc response iocb data structure.
3246 *
3247 * This routine is the completion callback function for ELS Response IOCB
3248 * command. In normal case, this callback function just properly sets the
3249 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3250 * field in the command IOCB is not NULL, the referred mailbox command will
3251 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3252 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3253 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3254 * routine shall be invoked trying to release the ndlp if no other threads
3255 * are currently referring it.
3256 **/
dea31012005-04-17 16:05:31 -05003257static void
James Smart858c9f62007-06-17 19:56:39 -05003258lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003259 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003260{
James Smart2e0fef82007-06-17 19:56:36 -05003261 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3262 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3263 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003264 IOCB_t *irsp;
3265 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003266 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003267 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003268 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003269
James Smart33ccf8d2006-08-17 11:57:58 -04003270 irsp = &rspiocb->iocb;
3271
dea31012005-04-17 16:05:31 -05003272 if (cmdiocb->context_un.mbox)
3273 mbox = cmdiocb->context_un.mbox;
3274
James Smartfa4066b2008-01-11 01:53:27 -05003275 /* First determine if this is a LS_RJT cmpl. Note, this callback
3276 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3277 */
James Smart87af33f2007-10-27 13:37:43 -04003278 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003279 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3280 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003281 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003282 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003283 */
3284 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3285 ls_rjt = 1;
3286 }
3287
dea31012005-04-17 16:05:31 -05003288 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003289 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003290 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003291 mp = (struct lpfc_dmabuf *) mbox->context1;
3292 if (mp) {
3293 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3294 kfree(mp);
3295 }
James Smart329f9bc2007-04-25 09:53:01 -04003296 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003297 }
James Smart58da1ff2008-04-07 10:15:56 -04003298 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3299 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003300 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003301 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003302 /* Indicate the node has already released,
3303 * should not reference to it from within
3304 * the routine lpfc_els_free_iocb.
3305 */
3306 cmdiocb->context1 = NULL;
3307 }
dea31012005-04-17 16:05:31 -05003308 goto out;
3309 }
3310
James Smart858c9f62007-06-17 19:56:39 -05003311 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003312 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003313 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003314 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003315 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3317 "0110 ELS response tag x%x completes "
3318 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3319 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3320 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3321 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3322 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003323 if (mbox) {
3324 if ((rspiocb->iocb.ulpStatus == 0)
3325 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003326 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003327 /* Increment reference count to ndlp to hold the
3328 * reference to ndlp for the callback function.
3329 */
James Smart329f9bc2007-04-25 09:53:01 -04003330 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003331 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003332 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3333 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3334 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3335 }
3336 else {
3337 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3338 ndlp->nlp_prev_state = ndlp->nlp_state;
3339 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003340 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003341 }
James Smart0b727fe2007-10-27 13:37:25 -04003342 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003343 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003344 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003345 else
3346 /* Decrement the ndlp reference count we
3347 * set for this failed mailbox command.
3348 */
3349 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003350
3351 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3352 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3353 "0138 ELS rsp: Cannot issue reg_login for x%x "
3354 "Data: x%x x%x x%x\n",
3355 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3356 ndlp->nlp_rpi);
3357
James Smartfa4066b2008-01-11 01:53:27 -05003358 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003359 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003360 /* Indicate node has already been released,
3361 * should not reference to it from within
3362 * the routine lpfc_els_free_iocb.
3363 */
3364 cmdiocb->context1 = NULL;
3365 }
dea31012005-04-17 16:05:31 -05003366 } else {
James Smart858c9f62007-06-17 19:56:39 -05003367 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3368 if (!lpfc_error_lost_link(irsp) &&
3369 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003370 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003371 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003372 /* Indicate node has already been
3373 * released, should not reference
3374 * to it from within the routine
3375 * lpfc_els_free_iocb.
3376 */
3377 cmdiocb->context1 = NULL;
3378 }
dea31012005-04-17 16:05:31 -05003379 }
3380 }
James Smart14691152006-12-02 13:34:28 -05003381 mp = (struct lpfc_dmabuf *) mbox->context1;
3382 if (mp) {
3383 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3384 kfree(mp);
3385 }
3386 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003387 }
3388out:
James Smart58da1ff2008-04-07 10:15:56 -04003389 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003390 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003391 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003392 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003393
3394 /* If the node is not being used by another discovery thread,
3395 * and we are sending a reject, we are done with it.
3396 * Release driver reference count here and free associated
3397 * resources.
3398 */
3399 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003400 if (lpfc_nlp_not_used(ndlp))
3401 /* Indicate node has already been released,
3402 * should not reference to it from within
3403 * the routine lpfc_els_free_iocb.
3404 */
3405 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003406 }
James Smart87af33f2007-10-27 13:37:43 -04003407
dea31012005-04-17 16:05:31 -05003408 lpfc_els_free_iocb(phba, cmdiocb);
3409 return;
3410}
3411
James Smarte59058c2008-08-24 21:49:00 -04003412/**
James Smart3621a712009-04-06 18:47:14 -04003413 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003414 * @vport: pointer to a host virtual N_Port data structure.
3415 * @flag: the els command code to be accepted.
3416 * @oldiocb: pointer to the original lpfc command iocb data structure.
3417 * @ndlp: pointer to a node-list data structure.
3418 * @mbox: pointer to the driver internal queue element for mailbox command.
3419 *
3420 * This routine prepares and issues an Accept (ACC) response IOCB
3421 * command. It uses the @flag to properly set up the IOCB field for the
3422 * specific ACC response command to be issued and invokes the
3423 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3424 * @mbox pointer is passed in, it will be put into the context_un.mbox
3425 * field of the IOCB for the completion callback function to issue the
3426 * mailbox command to the HBA later when callback is invoked.
3427 *
3428 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3429 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3430 * will be stored into the context1 field of the IOCB for the completion
3431 * callback function to the corresponding response ELS IOCB command.
3432 *
3433 * Return code
3434 * 0 - Successfully issued acc response
3435 * 1 - Failed to issue acc response
3436 **/
dea31012005-04-17 16:05:31 -05003437int
James Smart2e0fef82007-06-17 19:56:36 -05003438lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3439 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003440 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003441{
James Smart2e0fef82007-06-17 19:56:36 -05003442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3443 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003444 IOCB_t *icmd;
3445 IOCB_t *oldcmd;
3446 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003447 struct lpfc_sli *psli;
3448 uint8_t *pcmd;
3449 uint16_t cmdsize;
3450 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003451 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003452
3453 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003454 oldcmd = &oldiocb->iocb;
3455
3456 switch (flag) {
3457 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003458 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003459 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3460 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003461 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003462 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003463 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003464 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003465 return 1;
dea31012005-04-17 16:05:31 -05003466 }
James Smart2e0fef82007-06-17 19:56:36 -05003467
dea31012005-04-17 16:05:31 -05003468 icmd = &elsiocb->iocb;
3469 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3470 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3471 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003472 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003473
3474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3475 "Issue ACC: did:x%x flg:x%x",
3476 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003477 break;
3478 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003479 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003480 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3481 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003482 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003483 return 1;
James Smart488d1462006-03-07 15:02:37 -05003484
dea31012005-04-17 16:05:31 -05003485 icmd = &elsiocb->iocb;
3486 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3487 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3488
3489 if (mbox)
3490 elsiocb->context_un.mbox = mbox;
3491
3492 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003493 pcmd += sizeof(uint32_t);
3494 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003495
3496 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3497 "Issue ACC PLOGI: did:x%x flg:x%x",
3498 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003499 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003500 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003501 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003502 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003503 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3504 if (!elsiocb)
3505 return 1;
3506
3507 icmd = &elsiocb->iocb;
3508 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3509 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3510
3511 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003512 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003513 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3514 els_pkt_ptr = (ELS_PKT *) pcmd;
3515 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003516
3517 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3518 "Issue ACC PRLO: did:x%x flg:x%x",
3519 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003520 break;
dea31012005-04-17 16:05:31 -05003521 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003522 return 1;
dea31012005-04-17 16:05:31 -05003523 }
dea31012005-04-17 16:05:31 -05003524 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003525 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3526 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3527 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3528 elsiocb->iotag, elsiocb->iocb.ulpContext,
3529 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3530 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003531 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003532 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003533 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003534 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003535 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3536 } else {
James Smart858c9f62007-06-17 19:56:39 -05003537 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003538 }
3539
3540 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003541 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003542 if (rc == IOCB_ERROR) {
3543 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003544 return 1;
dea31012005-04-17 16:05:31 -05003545 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003546 return 0;
dea31012005-04-17 16:05:31 -05003547}
3548
James Smarte59058c2008-08-24 21:49:00 -04003549/**
James Smart3621a712009-04-06 18:47:14 -04003550 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003551 * @vport: pointer to a virtual N_Port data structure.
3552 * @rejectError:
3553 * @oldiocb: pointer to the original lpfc command iocb data structure.
3554 * @ndlp: pointer to a node-list data structure.
3555 * @mbox: pointer to the driver internal queue element for mailbox command.
3556 *
3557 * This routine prepares and issue an Reject (RJT) response IOCB
3558 * command. If a @mbox pointer is passed in, it will be put into the
3559 * context_un.mbox field of the IOCB for the completion callback function
3560 * to issue to the HBA later.
3561 *
3562 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3563 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3564 * will be stored into the context1 field of the IOCB for the completion
3565 * callback function to the reject response ELS IOCB command.
3566 *
3567 * Return code
3568 * 0 - Successfully issued reject response
3569 * 1 - Failed to issue reject response
3570 **/
dea31012005-04-17 16:05:31 -05003571int
James Smart2e0fef82007-06-17 19:56:36 -05003572lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003573 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3574 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003575{
James Smart2e0fef82007-06-17 19:56:36 -05003576 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003577 IOCB_t *icmd;
3578 IOCB_t *oldcmd;
3579 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003580 struct lpfc_sli *psli;
3581 uint8_t *pcmd;
3582 uint16_t cmdsize;
3583 int rc;
3584
3585 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003586 cmdsize = 2 * sizeof(uint32_t);
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_LS_RJT);
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
3592 icmd = &elsiocb->iocb;
3593 oldcmd = &oldiocb->iocb;
3594 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3595 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3596
3597 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003598 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003599 *((uint32_t *) (pcmd)) = rejectError;
3600
James Smart51ef4c22007-08-02 11:10:31 -04003601 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003602 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003603
dea31012005-04-17 16:05:31 -05003604 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003605 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3606 "0129 Xmit ELS RJT x%x response tag x%x "
3607 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3608 "rpi x%x\n",
3609 rejectError, elsiocb->iotag,
3610 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3611 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3613 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3614 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3615
dea31012005-04-17 16:05:31 -05003616 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003617 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003618 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003619
dea31012005-04-17 16:05:31 -05003620 if (rc == IOCB_ERROR) {
3621 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003622 return 1;
dea31012005-04-17 16:05:31 -05003623 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003624 return 0;
dea31012005-04-17 16:05:31 -05003625}
3626
James Smarte59058c2008-08-24 21:49:00 -04003627/**
James Smart3621a712009-04-06 18:47:14 -04003628 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003629 * @vport: pointer to a virtual N_Port data structure.
3630 * @oldiocb: pointer to the original lpfc command iocb data structure.
3631 * @ndlp: pointer to a node-list data structure.
3632 *
3633 * This routine prepares and issues an Accept (ACC) response to Address
3634 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3635 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3636 *
3637 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3638 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3639 * will be stored into the context1 field of the IOCB for the completion
3640 * callback function to the ADISC Accept response ELS IOCB command.
3641 *
3642 * Return code
3643 * 0 - Successfully issued acc adisc response
3644 * 1 - Failed to issue adisc acc response
3645 **/
dea31012005-04-17 16:05:31 -05003646int
James Smart2e0fef82007-06-17 19:56:36 -05003647lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3648 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003649{
James Smart2e0fef82007-06-17 19:56:36 -05003650 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003651 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003652 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003653 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003654 uint8_t *pcmd;
3655 uint16_t cmdsize;
3656 int rc;
3657
James Smart92d7f7b2007-06-17 19:56:38 -05003658 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003659 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3660 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003661 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003662 return 1;
dea31012005-04-17 16:05:31 -05003663
dea31012005-04-17 16:05:31 -05003664 icmd = &elsiocb->iocb;
3665 oldcmd = &oldiocb->iocb;
3666 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003667
3668 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003669 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3670 "0130 Xmit ADISC ACC response iotag x%x xri: "
3671 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3672 elsiocb->iotag, elsiocb->iocb.ulpContext,
3673 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3674 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003675 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3676
3677 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003678 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003679
3680 ap = (ADISC *) (pcmd);
3681 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003682 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3683 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003684 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003685
James Smart858c9f62007-06-17 19:56:39 -05003686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3687 "Issue ACC ADISC: did:x%x flg:x%x",
3688 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3689
dea31012005-04-17 16:05:31 -05003690 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003691 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003692 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003693 if (rc == IOCB_ERROR) {
3694 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003695 return 1;
dea31012005-04-17 16:05:31 -05003696 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003697 return 0;
dea31012005-04-17 16:05:31 -05003698}
3699
James Smarte59058c2008-08-24 21:49:00 -04003700/**
James Smart3621a712009-04-06 18:47:14 -04003701 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003702 * @vport: pointer to a virtual N_Port data structure.
3703 * @oldiocb: pointer to the original lpfc command iocb data structure.
3704 * @ndlp: pointer to a node-list data structure.
3705 *
3706 * This routine prepares and issues an Accept (ACC) response to Process
3707 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3708 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3709 *
3710 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3711 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3712 * will be stored into the context1 field of the IOCB for the completion
3713 * callback function to the PRLI Accept response ELS IOCB command.
3714 *
3715 * Return code
3716 * 0 - Successfully issued acc prli response
3717 * 1 - Failed to issue acc prli response
3718 **/
dea31012005-04-17 16:05:31 -05003719int
James Smart2e0fef82007-06-17 19:56:36 -05003720lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003721 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003722{
James Smart2e0fef82007-06-17 19:56:36 -05003723 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003724 PRLI *npr;
3725 lpfc_vpd_t *vpd;
3726 IOCB_t *icmd;
3727 IOCB_t *oldcmd;
3728 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003729 struct lpfc_sli *psli;
3730 uint8_t *pcmd;
3731 uint16_t cmdsize;
3732 int rc;
3733
3734 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003735
James Smart92d7f7b2007-06-17 19:56:38 -05003736 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003737 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003738 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003739 if (!elsiocb)
3740 return 1;
dea31012005-04-17 16:05:31 -05003741
dea31012005-04-17 16:05:31 -05003742 icmd = &elsiocb->iocb;
3743 oldcmd = &oldiocb->iocb;
3744 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003745 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003746 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3747 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3748 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3749 elsiocb->iotag, elsiocb->iocb.ulpContext,
3750 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3751 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003752 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3753
3754 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003755 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003756
3757 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003758 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003759
3760 npr = (PRLI *) pcmd;
3761 vpd = &phba->vpd;
3762 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003763 * If the remote port is a target and our firmware version is 3.20 or
3764 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003765 */
James Smart0d2b6b82008-06-14 22:52:47 -04003766 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3767 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003768 npr->ConfmComplAllowed = 1;
3769 npr->Retry = 1;
3770 npr->TaskRetryIdReq = 1;
3771 }
3772
3773 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3774 npr->estabImagePair = 1;
3775 npr->readXferRdyDis = 1;
3776 npr->ConfmComplAllowed = 1;
3777
3778 npr->prliType = PRLI_FCP_TYPE;
3779 npr->initiatorFunc = 1;
3780
James Smart858c9f62007-06-17 19:56:39 -05003781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3782 "Issue ACC PRLI: did:x%x flg:x%x",
3783 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3784
dea31012005-04-17 16:05:31 -05003785 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003786 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003787
James Smart3772a992009-05-22 14:50:54 -04003788 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003789 if (rc == IOCB_ERROR) {
3790 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003791 return 1;
dea31012005-04-17 16:05:31 -05003792 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003793 return 0;
dea31012005-04-17 16:05:31 -05003794}
3795
James Smarte59058c2008-08-24 21:49:00 -04003796/**
James Smart3621a712009-04-06 18:47:14 -04003797 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003798 * @vport: pointer to a virtual N_Port data structure.
3799 * @format: rnid command format.
3800 * @oldiocb: pointer to the original lpfc command iocb data structure.
3801 * @ndlp: pointer to a node-list data structure.
3802 *
3803 * This routine issues a Request Node Identification Data (RNID) Accept
3804 * (ACC) response. It constructs the RNID ACC response command according to
3805 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3806 * issue the response. Note that this command does not need to hold the ndlp
3807 * reference count for the callback. So, the ndlp reference count taken by
3808 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3809 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3810 * there is no ndlp reference available.
3811 *
3812 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3813 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3814 * will be stored into the context1 field of the IOCB for the completion
3815 * callback function. However, for the RNID Accept Response ELS command,
3816 * this is undone later by this routine after the IOCB is allocated.
3817 *
3818 * Return code
3819 * 0 - Successfully issued acc rnid response
3820 * 1 - Failed to issue acc rnid response
3821 **/
dea31012005-04-17 16:05:31 -05003822static int
James Smart2e0fef82007-06-17 19:56:36 -05003823lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003824 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003825{
James Smart2e0fef82007-06-17 19:56:36 -05003826 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003827 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003828 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003829 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003830 struct lpfc_sli *psli;
3831 uint8_t *pcmd;
3832 uint16_t cmdsize;
3833 int rc;
3834
3835 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003836 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3837 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003838 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003839 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003840
James Smart2e0fef82007-06-17 19:56:36 -05003841 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3842 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003843 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003844 return 1;
dea31012005-04-17 16:05:31 -05003845
dea31012005-04-17 16:05:31 -05003846 icmd = &elsiocb->iocb;
3847 oldcmd = &oldiocb->iocb;
3848 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003849 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003850 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3851 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3852 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003853 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003854 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003855 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003856
James Smart92d7f7b2007-06-17 19:56:38 -05003857 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003858 rn = (RNID *) (pcmd);
3859 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003860 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3861 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3862 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003863 switch (format) {
3864 case 0:
3865 rn->SpecificLen = 0;
3866 break;
3867 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003868 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003869 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003870 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003871 rn->un.topologyDisc.unitType = RNID_HBA;
3872 rn->un.topologyDisc.physPort = 0;
3873 rn->un.topologyDisc.attachedNodes = 0;
3874 break;
3875 default:
3876 rn->CommonLen = 0;
3877 rn->SpecificLen = 0;
3878 break;
3879 }
3880
James Smart858c9f62007-06-17 19:56:39 -05003881 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3882 "Issue ACC RNID: did:x%x flg:x%x",
3883 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3884
dea31012005-04-17 16:05:31 -05003885 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003886 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003887 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003888 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3889 * it could be freed */
3890
James Smart3772a992009-05-22 14:50:54 -04003891 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003892 if (rc == IOCB_ERROR) {
3893 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003894 return 1;
dea31012005-04-17 16:05:31 -05003895 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003896 return 0;
dea31012005-04-17 16:05:31 -05003897}
3898
James Smarte59058c2008-08-24 21:49:00 -04003899/**
James Smart12265f62010-10-22 11:05:53 -04003900 * lpfc_els_rsp_echo_acc - Issue echo acc response
3901 * @vport: pointer to a virtual N_Port data structure.
3902 * @data: pointer to echo data to return in the accept.
3903 * @oldiocb: pointer to the original lpfc command iocb data structure.
3904 * @ndlp: pointer to a node-list data structure.
3905 *
3906 * Return code
3907 * 0 - Successfully issued acc echo response
3908 * 1 - Failed to issue acc echo response
3909 **/
3910static int
3911lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3912 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3913{
3914 struct lpfc_hba *phba = vport->phba;
3915 struct lpfc_iocbq *elsiocb;
3916 struct lpfc_sli *psli;
3917 uint8_t *pcmd;
3918 uint16_t cmdsize;
3919 int rc;
3920
3921 psli = &phba->sli;
3922 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3923
3924 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3925 ndlp->nlp_DID, ELS_CMD_ACC);
3926 if (!elsiocb)
3927 return 1;
3928
3929 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3930 /* Xmit ECHO ACC response tag <ulpIoTag> */
3931 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3932 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3933 elsiocb->iotag, elsiocb->iocb.ulpContext);
3934 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3935 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3936 pcmd += sizeof(uint32_t);
3937 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3938
3939 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3940 "Issue ACC ECHO: did:x%x flg:x%x",
3941 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3942
3943 phba->fc_stat.elsXmitACC++;
3944 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3945 lpfc_nlp_put(ndlp);
3946 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3947 * it could be freed */
3948
3949 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3950 if (rc == IOCB_ERROR) {
3951 lpfc_els_free_iocb(phba, elsiocb);
3952 return 1;
3953 }
3954 return 0;
3955}
3956
3957/**
James Smart3621a712009-04-06 18:47:14 -04003958 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003959 * @vport: pointer to a host virtual N_Port data structure.
3960 *
3961 * This routine issues Address Discover (ADISC) ELS commands to those
3962 * N_Ports which are in node port recovery state and ADISC has not been issued
3963 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3964 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3965 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3966 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3967 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3968 * IOCBs quit for later pick up. On the other hand, after walking through
3969 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3970 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3971 * no more ADISC need to be sent.
3972 *
3973 * Return code
3974 * The number of N_Ports with adisc issued.
3975 **/
dea31012005-04-17 16:05:31 -05003976int
James Smart2e0fef82007-06-17 19:56:36 -05003977lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003978{
James Smart2e0fef82007-06-17 19:56:36 -05003979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003980 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003981 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003982
James Smart685f0bf2007-04-25 09:53:08 -04003983 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003984 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003985 if (!NLP_CHK_NODE_ACT(ndlp))
3986 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003987 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3988 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3989 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003990 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003991 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003992 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003993 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003994 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3995 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003996 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003997 vport->num_disc_nodes++;
3998 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003999 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004000 spin_lock_irq(shost->host_lock);
4001 vport->fc_flag |= FC_NLP_MORE;
4002 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004003 break;
dea31012005-04-17 16:05:31 -05004004 }
4005 }
4006 }
4007 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004008 spin_lock_irq(shost->host_lock);
4009 vport->fc_flag &= ~FC_NLP_MORE;
4010 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004011 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004012 return sentadisc;
dea31012005-04-17 16:05:31 -05004013}
4014
James Smarte59058c2008-08-24 21:49:00 -04004015/**
James Smart3621a712009-04-06 18:47:14 -04004016 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004017 * @vport: pointer to a host virtual N_Port data structure.
4018 *
4019 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4020 * which are in node port recovery state, with a @vport. Each time an ELS
4021 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4022 * the per @vport number of discover count (num_disc_nodes) shall be
4023 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4024 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4025 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4026 * later pick up. On the other hand, after walking through all the ndlps with
4027 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4028 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4029 * PLOGI need to be sent.
4030 *
4031 * Return code
4032 * The number of N_Ports with plogi issued.
4033 **/
dea31012005-04-17 16:05:31 -05004034int
James Smart2e0fef82007-06-17 19:56:36 -05004035lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004036{
James Smart2e0fef82007-06-17 19:56:36 -05004037 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004038 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004039 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004040
James Smart2e0fef82007-06-17 19:56:36 -05004041 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4042 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004043 if (!NLP_CHK_NODE_ACT(ndlp))
4044 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004045 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4046 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4047 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4048 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4049 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004050 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4051 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004052 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004053 vport->num_disc_nodes++;
4054 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004055 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004056 spin_lock_irq(shost->host_lock);
4057 vport->fc_flag |= FC_NLP_MORE;
4058 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004059 break;
dea31012005-04-17 16:05:31 -05004060 }
4061 }
4062 }
James Smart87af33f2007-10-27 13:37:43 -04004063 if (sentplogi) {
4064 lpfc_set_disctmo(vport);
4065 }
4066 else {
James Smart2e0fef82007-06-17 19:56:36 -05004067 spin_lock_irq(shost->host_lock);
4068 vport->fc_flag &= ~FC_NLP_MORE;
4069 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004070 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004071 return sentplogi;
dea31012005-04-17 16:05:31 -05004072}
4073
James Smarte59058c2008-08-24 21:49:00 -04004074/**
James Smart3621a712009-04-06 18:47:14 -04004075 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004076 * @vport: pointer to a host virtual N_Port data structure.
4077 *
4078 * This routine cleans up any Registration State Change Notification
4079 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4080 * @vport together with the host_lock is used to prevent multiple thread
4081 * trying to access the RSCN array on a same @vport at the same time.
4082 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004083void
James Smart2e0fef82007-06-17 19:56:36 -05004084lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004085{
James Smart2e0fef82007-06-17 19:56:36 -05004086 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4087 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004088 int i;
4089
James Smart7f5f3d02008-02-08 18:50:14 -05004090 spin_lock_irq(shost->host_lock);
4091 if (vport->fc_rscn_flush) {
4092 /* Another thread is walking fc_rscn_id_list on this vport */
4093 spin_unlock_irq(shost->host_lock);
4094 return;
4095 }
4096 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4097 vport->fc_rscn_flush = 1;
4098 spin_unlock_irq(shost->host_lock);
4099
James Smart2e0fef82007-06-17 19:56:36 -05004100 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004101 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004102 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004103 }
James Smart2e0fef82007-06-17 19:56:36 -05004104 spin_lock_irq(shost->host_lock);
4105 vport->fc_rscn_id_cnt = 0;
4106 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4107 spin_unlock_irq(shost->host_lock);
4108 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004109 /* Indicate we are done walking this fc_rscn_id_list */
4110 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004111}
4112
James Smarte59058c2008-08-24 21:49:00 -04004113/**
James Smart3621a712009-04-06 18:47:14 -04004114 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004115 * @vport: pointer to a host virtual N_Port data structure.
4116 * @did: remote destination port identifier.
4117 *
4118 * This routine checks whether there is any pending Registration State
4119 * Configuration Notification (RSCN) to a @did on @vport.
4120 *
4121 * Return code
4122 * None zero - The @did matched with a pending rscn
4123 * 0 - not able to match @did with a pending rscn
4124 **/
dea31012005-04-17 16:05:31 -05004125int
James Smart2e0fef82007-06-17 19:56:36 -05004126lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004127{
4128 D_ID ns_did;
4129 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004130 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004131 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004132 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004133
4134 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004135
4136 /* Never match fabric nodes for RSCNs */
4137 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004138 return 0;
dea31012005-04-17 16:05:31 -05004139
4140 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004141 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004142 return did;
dea31012005-04-17 16:05:31 -05004143
James Smart7f5f3d02008-02-08 18:50:14 -05004144 spin_lock_irq(shost->host_lock);
4145 if (vport->fc_rscn_flush) {
4146 /* Another thread is walking fc_rscn_id_list on this vport */
4147 spin_unlock_irq(shost->host_lock);
4148 return 0;
4149 }
4150 /* Indicate we are walking fc_rscn_id_list on this vport */
4151 vport->fc_rscn_flush = 1;
4152 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004153 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004154 lp = vport->fc_rscn_id_list[i]->virt;
4155 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4156 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004157 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004158 rscn_did.un.word = be32_to_cpu(*lp++);
4159 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004160 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4161 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004162 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4163 && (ns_did.un.b.area == rscn_did.un.b.area)
4164 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004165 goto return_did_out;
dea31012005-04-17 16:05:31 -05004166 break;
James Smarteaf15d52008-12-04 22:39:29 -05004167 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004168 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4169 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004170 goto return_did_out;
dea31012005-04-17 16:05:31 -05004171 break;
James Smarteaf15d52008-12-04 22:39:29 -05004172 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004173 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004174 goto return_did_out;
dea31012005-04-17 16:05:31 -05004175 break;
James Smarteaf15d52008-12-04 22:39:29 -05004176 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004177 goto return_did_out;
dea31012005-04-17 16:05:31 -05004178 }
4179 }
James Smart92d7f7b2007-06-17 19:56:38 -05004180 }
James Smart7f5f3d02008-02-08 18:50:14 -05004181 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4182 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004183 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004184return_did_out:
4185 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4186 vport->fc_rscn_flush = 0;
4187 return did;
dea31012005-04-17 16:05:31 -05004188}
4189
James Smarte59058c2008-08-24 21:49:00 -04004190/**
James Smart3621a712009-04-06 18:47:14 -04004191 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004192 * @vport: pointer to a host virtual N_Port data structure.
4193 *
4194 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4195 * state machine for a @vport's nodes that are with pending RSCN (Registration
4196 * State Change Notification).
4197 *
4198 * Return code
4199 * 0 - Successful (currently alway return 0)
4200 **/
dea31012005-04-17 16:05:31 -05004201static int
James Smart2e0fef82007-06-17 19:56:36 -05004202lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004203{
James Smart685f0bf2007-04-25 09:53:08 -04004204 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004205
James Smart0d2b6b82008-06-14 22:52:47 -04004206 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004207 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004208 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004209 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4210 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004211 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004212 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004213 NLP_EVT_DEVICE_RECOVERY);
4214 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004215 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004216 return 0;
dea31012005-04-17 16:05:31 -05004217}
4218
James Smarte59058c2008-08-24 21:49:00 -04004219/**
James Smart3621a712009-04-06 18:47:14 -04004220 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004221 * @vport: pointer to a host virtual N_Port data structure.
4222 * @cmdiocb: pointer to lpfc command iocb data structure.
4223 *
4224 * lpfc_send_rscn_event sends an RSCN netlink event to management
4225 * applications.
4226 */
4227static void
4228lpfc_send_rscn_event(struct lpfc_vport *vport,
4229 struct lpfc_iocbq *cmdiocb)
4230{
4231 struct lpfc_dmabuf *pcmd;
4232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4233 uint32_t *payload_ptr;
4234 uint32_t payload_len;
4235 struct lpfc_rscn_event_header *rscn_event_data;
4236
4237 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4238 payload_ptr = (uint32_t *) pcmd->virt;
4239 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4240
4241 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4242 payload_len, GFP_KERNEL);
4243 if (!rscn_event_data) {
4244 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4245 "0147 Failed to allocate memory for RSCN event\n");
4246 return;
4247 }
4248 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4249 rscn_event_data->payload_length = payload_len;
4250 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4251 payload_len);
4252
4253 fc_host_post_vendor_event(shost,
4254 fc_get_event_number(),
4255 sizeof(struct lpfc_els_event_header) + payload_len,
4256 (char *)rscn_event_data,
4257 LPFC_NL_VENDOR_ID);
4258
4259 kfree(rscn_event_data);
4260}
4261
4262/**
James Smart3621a712009-04-06 18:47:14 -04004263 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004264 * @vport: pointer to a host virtual N_Port data structure.
4265 * @cmdiocb: pointer to lpfc command iocb data structure.
4266 * @ndlp: pointer to a node-list data structure.
4267 *
4268 * This routine processes an unsolicited RSCN (Registration State Change
4269 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4270 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4271 * discover state machine is about to begin discovery, it just accepts the
4272 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4273 * contains N_Port IDs for other vports on this HBA, it just accepts the
4274 * RSCN and ignore processing it. If the state machine is in the recovery
4275 * state, the fc_rscn_id_list of this @vport is walked and the
4276 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4277 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4278 * routine is invoked to handle the RSCN event.
4279 *
4280 * Return code
4281 * 0 - Just sent the acc response
4282 * 1 - Sent the acc response and waited for name server completion
4283 **/
dea31012005-04-17 16:05:31 -05004284static int
James Smart2e0fef82007-06-17 19:56:36 -05004285lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004286 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004287{
James Smart2e0fef82007-06-17 19:56:36 -05004288 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4289 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004290 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004291 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004292 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004293 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004294 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004295 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004296 int i;
dea31012005-04-17 16:05:31 -05004297
4298 icmd = &cmdiocb->iocb;
4299 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4300 lp = (uint32_t *) pcmd->virt;
4301
James Smart92d7f7b2007-06-17 19:56:38 -05004302 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4303 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004304 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004305 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4306 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004307 vport->fc_flag, payload_len, *lp,
4308 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004309
4310 /* Send an RSCN event to the management application */
4311 lpfc_send_rscn_event(vport, cmdiocb);
4312
James Smartd2873e42006-08-18 17:46:43 -04004313 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004314 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004315 FCH_EVT_RSCN, lp[i]);
4316
dea31012005-04-17 16:05:31 -05004317 /* If we are about to begin discovery, just ACC the RSCN.
4318 * Discovery processing will satisfy it.
4319 */
James Smart2e0fef82007-06-17 19:56:36 -05004320 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4322 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4323 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4324
James Smart51ef4c22007-08-02 11:10:31 -04004325 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004326 return 0;
dea31012005-04-17 16:05:31 -05004327 }
4328
James Smart92d7f7b2007-06-17 19:56:38 -05004329 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4330 * just ACC and ignore it.
4331 */
4332 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004333 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004334 i = payload_len;
4335 datap = lp;
4336 while (i > 0) {
4337 nportid = *datap++;
4338 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4339 i -= sizeof(uint32_t);
4340 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004341 if (lpfc_find_vport_by_did(phba, nportid))
4342 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004343 }
4344 if (rscn_id == hba_id) {
4345 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004346 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004347 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004348 "Data: x%x x%x x%x x%x\n",
4349 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004350 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4352 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4353 ndlp->nlp_DID, vport->port_state,
4354 ndlp->nlp_flag);
4355
James Smart92d7f7b2007-06-17 19:56:38 -05004356 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004357 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004358 return 0;
4359 }
4360 }
4361
James Smart7f5f3d02008-02-08 18:50:14 -05004362 spin_lock_irq(shost->host_lock);
4363 if (vport->fc_rscn_flush) {
4364 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004365 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004366 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004367 /* Send back ACC */
4368 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004369 return 0;
4370 }
4371 /* Indicate we are walking fc_rscn_id_list on this vport */
4372 vport->fc_rscn_flush = 1;
4373 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004374 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004375 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004376 /* If we are already processing an RSCN, save the received
4377 * RSCN payload buffer, cmdiocb->context2 to process later.
4378 */
James Smart2e0fef82007-06-17 19:56:36 -05004379 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004380 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4381 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4382 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4383
James Smart09372822008-01-11 01:52:54 -05004384 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004385 vport->fc_flag |= FC_RSCN_DEFERRED;
4386 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004387 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004388 vport->fc_flag |= FC_RSCN_MODE;
4389 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004390 if (rscn_cnt) {
4391 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4392 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4393 }
4394 if ((rscn_cnt) &&
4395 (payload_len + length <= LPFC_BPL_SIZE)) {
4396 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004397 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004398 memcpy(((uint8_t *)cmd) + length, lp,
4399 payload_len);
4400 } else {
4401 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4402 vport->fc_rscn_id_cnt++;
4403 /* If we zero, cmdiocb->context2, the calling
4404 * routine will not try to free it.
4405 */
4406 cmdiocb->context2 = NULL;
4407 }
dea31012005-04-17 16:05:31 -05004408 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004409 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4410 "0235 Deferred RSCN "
4411 "Data: x%x x%x x%x\n",
4412 vport->fc_rscn_id_cnt, vport->fc_flag,
4413 vport->port_state);
dea31012005-04-17 16:05:31 -05004414 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004415 vport->fc_flag |= FC_RSCN_DISCOVERY;
4416 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004417 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004418 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4419 "0234 ReDiscovery RSCN "
4420 "Data: x%x x%x x%x\n",
4421 vport->fc_rscn_id_cnt, vport->fc_flag,
4422 vport->port_state);
dea31012005-04-17 16:05:31 -05004423 }
James Smart7f5f3d02008-02-08 18:50:14 -05004424 /* Indicate we are done walking fc_rscn_id_list on this vport */
4425 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004426 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004427 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004428 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004429 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004430 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004431 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004432 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004433 return 0;
dea31012005-04-17 16:05:31 -05004434 }
James Smart858c9f62007-06-17 19:56:39 -05004435 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4436 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4437 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4438
James Smart2e0fef82007-06-17 19:56:36 -05004439 spin_lock_irq(shost->host_lock);
4440 vport->fc_flag |= FC_RSCN_MODE;
4441 spin_unlock_irq(shost->host_lock);
4442 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004443 /* Indicate we are done walking fc_rscn_id_list on this vport */
4444 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004445 /*
4446 * If we zero, cmdiocb->context2, the calling routine will
4447 * not try to free it.
4448 */
4449 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004450 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004451 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004452 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004453 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004454 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004455 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004456}
4457
James Smarte59058c2008-08-24 21:49:00 -04004458/**
James Smart3621a712009-04-06 18:47:14 -04004459 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004460 * @vport: pointer to a host virtual N_Port data structure.
4461 *
4462 * This routine handles the Registration State Configuration Notification
4463 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4464 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4465 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4466 * NameServer shall be issued. If CT command to the NameServer fails to be
4467 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4468 * RSCN activities with the @vport.
4469 *
4470 * Return code
4471 * 0 - Cleaned up rscn on the @vport
4472 * 1 - Wait for plogi to name server before proceed
4473 **/
dea31012005-04-17 16:05:31 -05004474int
James Smart2e0fef82007-06-17 19:56:36 -05004475lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004476{
4477 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004478 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004479
James Smart92d7f7b2007-06-17 19:56:38 -05004480 /* Ignore RSCN if the port is being torn down. */
4481 if (vport->load_flag & FC_UNLOADING) {
4482 lpfc_els_flush_rscn(vport);
4483 return 0;
4484 }
4485
dea31012005-04-17 16:05:31 -05004486 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004487 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004488
4489 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004490 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4491 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4492 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4493 vport->port_state);
dea31012005-04-17 16:05:31 -05004494
4495 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004496 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004497 vport->num_disc_nodes = 0;
4498
James Smart2e0fef82007-06-17 19:56:36 -05004499 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004500 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4501 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004502 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004503 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004504 /* Wait for NameServer query cmpl before we can
4505 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004506 return 1;
dea31012005-04-17 16:05:31 -05004507 } else {
4508 /* If login to NameServer does not exist, issue one */
4509 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004510 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004511 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004512 /* Wait for NameServer login cmpl before we can
4513 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004514 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004515
James Smarte47c9092008-02-08 18:49:26 -05004516 if (ndlp) {
4517 ndlp = lpfc_enable_node(vport, ndlp,
4518 NLP_STE_PLOGI_ISSUE);
4519 if (!ndlp) {
4520 lpfc_els_flush_rscn(vport);
4521 return 0;
4522 }
4523 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004524 } else {
James Smarte47c9092008-02-08 18:49:26 -05004525 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4526 if (!ndlp) {
4527 lpfc_els_flush_rscn(vport);
4528 return 0;
4529 }
James Smart2e0fef82007-06-17 19:56:36 -05004530 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004531 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004532 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004533 }
James Smarte47c9092008-02-08 18:49:26 -05004534 ndlp->nlp_type |= NLP_FABRIC;
4535 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4536 /* Wait for NameServer login cmpl before we can
4537 * continue
4538 */
4539 return 1;
dea31012005-04-17 16:05:31 -05004540 }
4541
James Smart2e0fef82007-06-17 19:56:36 -05004542 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004543 return 0;
dea31012005-04-17 16:05:31 -05004544}
4545
James Smarte59058c2008-08-24 21:49:00 -04004546/**
James Smart3621a712009-04-06 18:47:14 -04004547 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004548 * @vport: pointer to a host virtual N_Port data structure.
4549 * @cmdiocb: pointer to lpfc command iocb data structure.
4550 * @ndlp: pointer to a node-list data structure.
4551 *
4552 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4553 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4554 * point topology. As an unsolicited FLOGI should not be received in a loop
4555 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4556 * lpfc_check_sparm() routine is invoked to check the parameters in the
4557 * unsolicited FLOGI. If parameters validation failed, the routine
4558 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4559 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4560 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4561 * will initiate PLOGI. The higher lexicographical value party shall has
4562 * higher priority (as the winning port) and will initiate PLOGI and
4563 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4564 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4565 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4566 *
4567 * Return code
4568 * 0 - Successfully processed the unsolicited flogi
4569 * 1 - Failed to process the unsolicited flogi
4570 **/
dea31012005-04-17 16:05:31 -05004571static int
James Smart2e0fef82007-06-17 19:56:36 -05004572lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004573 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004574{
James Smart2e0fef82007-06-17 19:56:36 -05004575 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4576 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004577 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4578 uint32_t *lp = (uint32_t *) pcmd->virt;
4579 IOCB_t *icmd = &cmdiocb->iocb;
4580 struct serv_parm *sp;
4581 LPFC_MBOXQ_t *mbox;
4582 struct ls_rjt stat;
4583 uint32_t cmd, did;
4584 int rc;
4585
4586 cmd = *lp++;
4587 sp = (struct serv_parm *) lp;
4588
4589 /* FLOGI received */
4590
James Smart2e0fef82007-06-17 19:56:36 -05004591 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004592
4593 if (phba->fc_topology == TOPOLOGY_LOOP) {
4594 /* We should never receive a FLOGI in loop mode, ignore it */
4595 did = icmd->un.elsreq64.remoteID;
4596
4597 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4598 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004599 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4600 "0113 An FLOGI ELS command x%x was "
4601 "received from DID x%x in Loop Mode\n",
4602 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004603 return 1;
dea31012005-04-17 16:05:31 -05004604 }
4605
4606 did = Fabric_DID;
4607
James Smart341af102010-01-26 23:07:37 -05004608 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004609 /* For a FLOGI we accept, then if our portname is greater
4610 * then the remote portname we initiate Nport login.
4611 */
4612
James Smart2e0fef82007-06-17 19:56:36 -05004613 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004614 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004615
4616 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004617 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4618 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004619 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004620
dea31012005-04-17 16:05:31 -05004621 lpfc_linkdown(phba);
4622 lpfc_init_link(phba, mbox,
4623 phba->cfg_topology,
4624 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004625 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004626 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004627 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004628 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004629 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004630 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004631 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004632 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004633 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004634 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004635 spin_lock_irq(shost->host_lock);
4636 vport->fc_flag |= FC_PT2PT_PLOGI;
4637 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004638 }
James Smart2e0fef82007-06-17 19:56:36 -05004639 spin_lock_irq(shost->host_lock);
4640 vport->fc_flag |= FC_PT2PT;
4641 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4642 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004643 } else {
4644 /* Reject this request because invalid parameters */
4645 stat.un.b.lsRjtRsvd0 = 0;
4646 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4647 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4648 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004649 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4650 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004651 return 1;
dea31012005-04-17 16:05:31 -05004652 }
4653
4654 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004655 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004656
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004657 return 0;
dea31012005-04-17 16:05:31 -05004658}
4659
James Smarte59058c2008-08-24 21:49:00 -04004660/**
James Smart3621a712009-04-06 18:47:14 -04004661 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004662 * @vport: pointer to a host virtual N_Port data structure.
4663 * @cmdiocb: pointer to lpfc command iocb data structure.
4664 * @ndlp: pointer to a node-list data structure.
4665 *
4666 * This routine processes Request Node Identification Data (RNID) IOCB
4667 * received as an ELS unsolicited event. Only when the RNID specified format
4668 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4669 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4670 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4671 * rejected by invoking the lpfc_els_rsp_reject() routine.
4672 *
4673 * Return code
4674 * 0 - Successfully processed rnid iocb (currently always return 0)
4675 **/
dea31012005-04-17 16:05:31 -05004676static int
James Smart2e0fef82007-06-17 19:56:36 -05004677lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4678 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004679{
4680 struct lpfc_dmabuf *pcmd;
4681 uint32_t *lp;
4682 IOCB_t *icmd;
4683 RNID *rn;
4684 struct ls_rjt stat;
4685 uint32_t cmd, did;
4686
4687 icmd = &cmdiocb->iocb;
4688 did = icmd->un.elsreq64.remoteID;
4689 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4690 lp = (uint32_t *) pcmd->virt;
4691
4692 cmd = *lp++;
4693 rn = (RNID *) lp;
4694
4695 /* RNID received */
4696
4697 switch (rn->Format) {
4698 case 0:
4699 case RNID_TOPOLOGY_DISC:
4700 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004701 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004702 break;
4703 default:
4704 /* Reject this request because format not supported */
4705 stat.un.b.lsRjtRsvd0 = 0;
4706 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4707 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4708 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004709 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4710 NULL);
dea31012005-04-17 16:05:31 -05004711 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004712 return 0;
dea31012005-04-17 16:05:31 -05004713}
4714
James Smarte59058c2008-08-24 21:49:00 -04004715/**
James Smart12265f62010-10-22 11:05:53 -04004716 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4717 * @vport: pointer to a host virtual N_Port data structure.
4718 * @cmdiocb: pointer to lpfc command iocb data structure.
4719 * @ndlp: pointer to a node-list data structure.
4720 *
4721 * Return code
4722 * 0 - Successfully processed echo iocb (currently always return 0)
4723 **/
4724static int
4725lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4726 struct lpfc_nodelist *ndlp)
4727{
4728 uint8_t *pcmd;
4729
4730 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4731
4732 /* skip over first word of echo command to find echo data */
4733 pcmd += sizeof(uint32_t);
4734
4735 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4736 return 0;
4737}
4738
4739/**
James Smart3621a712009-04-06 18:47:14 -04004740 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004741 * @vport: pointer to a host virtual N_Port data structure.
4742 * @cmdiocb: pointer to lpfc command iocb data structure.
4743 * @ndlp: pointer to a node-list data structure.
4744 *
4745 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4746 * received as an ELS unsolicited event. Currently, this function just invokes
4747 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4748 *
4749 * Return code
4750 * 0 - Successfully processed lirr iocb (currently always return 0)
4751 **/
dea31012005-04-17 16:05:31 -05004752static int
James Smart2e0fef82007-06-17 19:56:36 -05004753lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4754 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004755{
4756 struct ls_rjt stat;
4757
4758 /* For now, unconditionally reject this command */
4759 stat.un.b.lsRjtRsvd0 = 0;
4760 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4761 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4762 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004763 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004764 return 0;
4765}
4766
James Smarte59058c2008-08-24 21:49:00 -04004767/**
James Smart5ffc2662009-11-18 15:39:44 -05004768 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4769 * @vport: pointer to a host virtual N_Port data structure.
4770 * @cmdiocb: pointer to lpfc command iocb data structure.
4771 * @ndlp: pointer to a node-list data structure.
4772 *
4773 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4774 * received as an ELS unsolicited event. A request to RRQ shall only
4775 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4776 * Nx_Port N_Port_ID of the target Exchange is the same as the
4777 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4778 * not accepted, an LS_RJT with reason code "Unable to perform
4779 * command request" and reason code explanation "Invalid Originator
4780 * S_ID" shall be returned. For now, we just unconditionally accept
4781 * RRQ from the target.
4782 **/
4783static void
4784lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4785 struct lpfc_nodelist *ndlp)
4786{
4787 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4788}
4789
4790/**
James Smart12265f62010-10-22 11:05:53 -04004791 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4792 * @phba: pointer to lpfc hba data structure.
4793 * @pmb: pointer to the driver internal queue element for mailbox command.
4794 *
4795 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4796 * mailbox command. This callback function is to actually send the Accept
4797 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4798 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4799 * mailbox command, constructs the RPS response with the link statistics
4800 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4801 * response to the RPS.
4802 *
4803 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4804 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4805 * will be stored into the context1 field of the IOCB for the completion
4806 * callback function to the RPS Accept Response ELS IOCB command.
4807 *
4808 **/
4809static void
4810lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4811{
4812 MAILBOX_t *mb;
4813 IOCB_t *icmd;
4814 struct RLS_RSP *rls_rsp;
4815 uint8_t *pcmd;
4816 struct lpfc_iocbq *elsiocb;
4817 struct lpfc_nodelist *ndlp;
4818 uint16_t xri;
4819 uint32_t cmdsize;
4820
4821 mb = &pmb->u.mb;
4822
4823 ndlp = (struct lpfc_nodelist *) pmb->context2;
4824 xri = (uint16_t) ((unsigned long)(pmb->context1));
4825 pmb->context1 = NULL;
4826 pmb->context2 = NULL;
4827
4828 if (mb->mbxStatus) {
4829 mempool_free(pmb, phba->mbox_mem_pool);
4830 return;
4831 }
4832
4833 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4834 mempool_free(pmb, phba->mbox_mem_pool);
4835 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4836 lpfc_max_els_tries, ndlp,
4837 ndlp->nlp_DID, ELS_CMD_ACC);
4838
4839 /* Decrement the ndlp reference count from previous mbox command */
4840 lpfc_nlp_put(ndlp);
4841
4842 if (!elsiocb)
4843 return;
4844
4845 icmd = &elsiocb->iocb;
4846 icmd->ulpContext = xri;
4847
4848 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4849 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4850 pcmd += sizeof(uint32_t); /* Skip past command */
4851 rls_rsp = (struct RLS_RSP *)pcmd;
4852
4853 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4854 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4855 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4856 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4857 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4858 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4859
4860 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4861 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4862 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4863 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4864 elsiocb->iotag, elsiocb->iocb.ulpContext,
4865 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4866 ndlp->nlp_rpi);
4867 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4868 phba->fc_stat.elsXmitACC++;
4869 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4870 lpfc_els_free_iocb(phba, elsiocb);
4871}
4872
4873/**
James Smart3621a712009-04-06 18:47:14 -04004874 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004875 * @phba: pointer to lpfc hba data structure.
4876 * @pmb: pointer to the driver internal queue element for mailbox command.
4877 *
4878 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4879 * mailbox command. This callback function is to actually send the Accept
4880 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4881 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4882 * mailbox command, constructs the RPS response with the link statistics
4883 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4884 * response to the RPS.
4885 *
4886 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4887 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4888 * will be stored into the context1 field of the IOCB for the completion
4889 * callback function to the RPS Accept Response ELS IOCB command.
4890 *
4891 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004892static void
James Smart329f9bc2007-04-25 09:53:01 -04004893lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004894{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004895 MAILBOX_t *mb;
4896 IOCB_t *icmd;
4897 RPS_RSP *rps_rsp;
4898 uint8_t *pcmd;
4899 struct lpfc_iocbq *elsiocb;
4900 struct lpfc_nodelist *ndlp;
4901 uint16_t xri, status;
4902 uint32_t cmdsize;
4903
James Smart04c68492009-05-22 14:52:52 -04004904 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004905
4906 ndlp = (struct lpfc_nodelist *) pmb->context2;
4907 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004908 pmb->context1 = NULL;
4909 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004910
4911 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004912 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004913 return;
4914 }
4915
4916 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004917 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004918 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4919 lpfc_max_els_tries, ndlp,
4920 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004921
4922 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004923 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004924
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004925 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004926 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004927
4928 icmd = &elsiocb->iocb;
4929 icmd->ulpContext = xri;
4930
4931 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4932 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004933 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004934 rps_rsp = (RPS_RSP *)pcmd;
4935
4936 if (phba->fc_topology != TOPOLOGY_LOOP)
4937 status = 0x10;
4938 else
4939 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004940 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004941 status |= 0x4;
4942
4943 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004944 rps_rsp->portStatus = cpu_to_be16(status);
4945 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4946 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4947 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4948 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4949 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4950 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004951 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004952 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4953 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4954 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4955 elsiocb->iotag, elsiocb->iocb.ulpContext,
4956 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4957 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004958 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004959 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004960 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004961 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004962 return;
4963}
4964
James Smarte59058c2008-08-24 21:49:00 -04004965/**
James Smart12265f62010-10-22 11:05:53 -04004966 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4967 * @vport: pointer to a host virtual N_Port data structure.
4968 * @cmdiocb: pointer to lpfc command iocb data structure.
4969 * @ndlp: pointer to a node-list data structure.
4970 *
4971 * This routine processes Read Port Status (RPL) IOCB received as an
4972 * ELS unsolicited event. It first checks the remote port state. If the
4973 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4974 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
4975 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4976 * for reading the HBA link statistics. It is for the callback function,
4977 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
4978 * to actually sending out RPL Accept (ACC) response.
4979 *
4980 * Return codes
4981 * 0 - Successfully processed rls iocb (currently always return 0)
4982 **/
4983static int
4984lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4985 struct lpfc_nodelist *ndlp)
4986{
4987 struct lpfc_hba *phba = vport->phba;
4988 LPFC_MBOXQ_t *mbox;
4989 struct lpfc_dmabuf *pcmd;
4990 struct ls_rjt stat;
4991
4992 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4993 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4994 /* reject the unsolicited RPS request and done with it */
4995 goto reject_out;
4996
4997 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4998
4999 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5000 if (mbox) {
5001 lpfc_read_lnk_stat(phba, mbox);
5002 mbox->context1 =
5003 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5004 mbox->context2 = lpfc_nlp_get(ndlp);
5005 mbox->vport = vport;
5006 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5007 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5008 != MBX_NOT_FINISHED)
5009 /* Mbox completion will send ELS Response */
5010 return 0;
5011 /* Decrement reference count used for the failed mbox
5012 * command.
5013 */
5014 lpfc_nlp_put(ndlp);
5015 mempool_free(mbox, phba->mbox_mem_pool);
5016 }
5017reject_out:
5018 /* issue rejection response */
5019 stat.un.b.lsRjtRsvd0 = 0;
5020 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5021 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5022 stat.un.b.vendorUnique = 0;
5023 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5024 return 0;
5025}
5026
5027/**
5028 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5029 * @vport: pointer to a host virtual N_Port data structure.
5030 * @cmdiocb: pointer to lpfc command iocb data structure.
5031 * @ndlp: pointer to a node-list data structure.
5032 *
5033 * This routine processes Read Timout Value (RTV) IOCB received as an
5034 * ELS unsolicited event. It first checks the remote port state. If the
5035 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5036 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5037 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5038 * Value (RTV) unsolicited IOCB event.
5039 *
5040 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5041 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5042 * will be stored into the context1 field of the IOCB for the completion
5043 * callback function to the RPS Accept Response ELS IOCB command.
5044 *
5045 * Return codes
5046 * 0 - Successfully processed rtv iocb (currently always return 0)
5047 **/
5048static int
5049lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5050 struct lpfc_nodelist *ndlp)
5051{
5052 struct lpfc_hba *phba = vport->phba;
5053 struct ls_rjt stat;
5054 struct RTV_RSP *rtv_rsp;
5055 uint8_t *pcmd;
5056 struct lpfc_iocbq *elsiocb;
5057 uint32_t cmdsize;
5058
5059
5060 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5061 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5062 /* reject the unsolicited RPS request and done with it */
5063 goto reject_out;
5064
5065 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5066 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5067 lpfc_max_els_tries, ndlp,
5068 ndlp->nlp_DID, ELS_CMD_ACC);
5069
5070 if (!elsiocb)
5071 return 1;
5072
5073 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5074 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5075 pcmd += sizeof(uint32_t); /* Skip past command */
5076
5077 /* use the command's xri in the response */
5078 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5079
5080 rtv_rsp = (struct RTV_RSP *)pcmd;
5081
5082 /* populate RTV payload */
5083 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5084 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5085 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5086 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5087 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5088
5089 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5090 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5091 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5092 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5093 "Data: x%x x%x x%x\n",
5094 elsiocb->iotag, elsiocb->iocb.ulpContext,
5095 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5096 ndlp->nlp_rpi,
5097 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5098 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5099 phba->fc_stat.elsXmitACC++;
5100 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5101 lpfc_els_free_iocb(phba, elsiocb);
5102 return 0;
5103
5104reject_out:
5105 /* issue rejection response */
5106 stat.un.b.lsRjtRsvd0 = 0;
5107 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5108 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5109 stat.un.b.vendorUnique = 0;
5110 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5111 return 0;
5112}
5113
5114/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005115 * @vport: pointer to a host virtual N_Port data structure.
5116 * @cmdiocb: pointer to lpfc command iocb data structure.
5117 * @ndlp: pointer to a node-list data structure.
5118 *
5119 * This routine processes Read Port Status (RPS) IOCB received as an
5120 * ELS unsolicited event. It first checks the remote port state. If the
5121 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5122 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5123 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5124 * for reading the HBA link statistics. It is for the callback function,
5125 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5126 * to actually sending out RPS Accept (ACC) response.
5127 *
5128 * Return codes
5129 * 0 - Successfully processed rps iocb (currently always return 0)
5130 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005131static int
James Smart2e0fef82007-06-17 19:56:36 -05005132lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5133 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005134{
James Smart2e0fef82007-06-17 19:56:36 -05005135 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005136 uint32_t *lp;
5137 uint8_t flag;
5138 LPFC_MBOXQ_t *mbox;
5139 struct lpfc_dmabuf *pcmd;
5140 RPS *rps;
5141 struct ls_rjt stat;
5142
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005143 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005144 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5145 /* reject the unsolicited RPS request and done with it */
5146 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005147
5148 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5149 lp = (uint32_t *) pcmd->virt;
5150 flag = (be32_to_cpu(*lp++) & 0xf);
5151 rps = (RPS *) lp;
5152
5153 if ((flag == 0) ||
5154 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005155 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005156 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005157
James Smart92d7f7b2007-06-17 19:56:38 -05005158 printk("Fix me....\n");
5159 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005160 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5161 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005162 lpfc_read_lnk_stat(phba, mbox);
5163 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005164 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005165 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005166 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005167 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005168 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005169 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005170 /* Mbox completion will send ELS Response */
5171 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005172 /* Decrement reference count used for the failed mbox
5173 * command.
5174 */
James Smart329f9bc2007-04-25 09:53:01 -04005175 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005176 mempool_free(mbox, phba->mbox_mem_pool);
5177 }
5178 }
James Smart90160e02008-08-24 21:49:45 -04005179
5180reject_out:
5181 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005182 stat.un.b.lsRjtRsvd0 = 0;
5183 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5184 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5185 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005186 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005187 return 0;
5188}
5189
James Smarte59058c2008-08-24 21:49:00 -04005190/**
James Smart3621a712009-04-06 18:47:14 -04005191 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005192 * @vport: pointer to a host virtual N_Port data structure.
5193 * @cmdsize: size of the ELS command.
5194 * @oldiocb: pointer to the original lpfc command iocb data structure.
5195 * @ndlp: pointer to a node-list data structure.
5196 *
5197 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5198 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5199 *
5200 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5201 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5202 * will be stored into the context1 field of the IOCB for the completion
5203 * callback function to the RPL Accept Response ELS command.
5204 *
5205 * Return code
5206 * 0 - Successfully issued ACC RPL ELS command
5207 * 1 - Failed to issue ACC RPL ELS command
5208 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005209static int
James Smart2e0fef82007-06-17 19:56:36 -05005210lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5211 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005212{
James Smart2e0fef82007-06-17 19:56:36 -05005213 struct lpfc_hba *phba = vport->phba;
5214 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005215 RPL_RSP rpl_rsp;
5216 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005217 uint8_t *pcmd;
5218
James Smart2e0fef82007-06-17 19:56:36 -05005219 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5220 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005221
James Smart488d1462006-03-07 15:02:37 -05005222 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005223 return 1;
James Smart488d1462006-03-07 15:02:37 -05005224
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005225 icmd = &elsiocb->iocb;
5226 oldcmd = &oldiocb->iocb;
5227 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5228
5229 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5230 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005231 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005232 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5233 pcmd += sizeof(uint16_t);
5234
5235 /* Setup the RPL ACC payload */
5236 rpl_rsp.listLen = be32_to_cpu(1);
5237 rpl_rsp.index = 0;
5238 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005239 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5240 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005241 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005242 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005243 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005244 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5245 "0120 Xmit ELS RPL ACC response tag x%x "
5246 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5247 "rpi x%x\n",
5248 elsiocb->iotag, elsiocb->iocb.ulpContext,
5249 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5250 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005251 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005252 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005253 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5254 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005255 lpfc_els_free_iocb(phba, elsiocb);
5256 return 1;
5257 }
5258 return 0;
5259}
5260
James Smarte59058c2008-08-24 21:49:00 -04005261/**
James Smart3621a712009-04-06 18:47:14 -04005262 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005263 * @vport: pointer to a host virtual N_Port data structure.
5264 * @cmdiocb: pointer to lpfc command iocb data structure.
5265 * @ndlp: pointer to a node-list data structure.
5266 *
5267 * This routine processes Read Port List (RPL) IOCB received as an ELS
5268 * unsolicited event. It first checks the remote port state. If the remote
5269 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5270 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5271 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5272 * to accept the RPL.
5273 *
5274 * Return code
5275 * 0 - Successfully processed rpl iocb (currently always return 0)
5276 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005277static int
James Smart2e0fef82007-06-17 19:56:36 -05005278lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5279 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005280{
5281 struct lpfc_dmabuf *pcmd;
5282 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005283 uint32_t maxsize;
5284 uint16_t cmdsize;
5285 RPL *rpl;
5286 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005287
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005288 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5289 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005290 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005291 stat.un.b.lsRjtRsvd0 = 0;
5292 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5293 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5294 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005295 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5296 NULL);
James Smart90160e02008-08-24 21:49:45 -04005297 /* rejected the unsolicited RPL request and done with it */
5298 return 0;
dea31012005-04-17 16:05:31 -05005299 }
5300
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005301 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5302 lp = (uint32_t *) pcmd->virt;
5303 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005304 maxsize = be32_to_cpu(rpl->maxsize);
5305
5306 /* We support only one port */
5307 if ((rpl->index == 0) &&
5308 ((maxsize == 0) ||
5309 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5310 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005311 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005312 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5313 }
James Smart2e0fef82007-06-17 19:56:36 -05005314 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005315
5316 return 0;
5317}
5318
James Smarte59058c2008-08-24 21:49:00 -04005319/**
James Smart3621a712009-04-06 18:47:14 -04005320 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005321 * @vport: pointer to a virtual N_Port data structure.
5322 * @cmdiocb: pointer to lpfc command iocb data structure.
5323 * @ndlp: pointer to a node-list data structure.
5324 *
5325 * This routine processes Fibre Channel Address Resolution Protocol
5326 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5327 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5328 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5329 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5330 * remote PortName is compared against the FC PortName stored in the @vport
5331 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5332 * compared against the FC NodeName stored in the @vport data structure.
5333 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5334 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5335 * invoked to send out FARP Response to the remote node. Before sending the
5336 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5337 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5338 * routine is invoked to log into the remote port first.
5339 *
5340 * Return code
5341 * 0 - Either the FARP Match Mode not supported or successfully processed
5342 **/
dea31012005-04-17 16:05:31 -05005343static int
James Smart2e0fef82007-06-17 19:56:36 -05005344lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5345 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005346{
5347 struct lpfc_dmabuf *pcmd;
5348 uint32_t *lp;
5349 IOCB_t *icmd;
5350 FARP *fp;
5351 uint32_t cmd, cnt, did;
5352
5353 icmd = &cmdiocb->iocb;
5354 did = icmd->un.elsreq64.remoteID;
5355 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5356 lp = (uint32_t *) pcmd->virt;
5357
5358 cmd = *lp++;
5359 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005360 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005361 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5362 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005363 /* We will only support match on WWPN or WWNN */
5364 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005365 return 0;
dea31012005-04-17 16:05:31 -05005366 }
5367
5368 cnt = 0;
5369 /* If this FARP command is searching for my portname */
5370 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005371 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005372 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005373 cnt = 1;
5374 }
5375
5376 /* If this FARP command is searching for my nodename */
5377 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005378 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005379 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005380 cnt = 1;
5381 }
5382
5383 if (cnt) {
5384 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5385 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5386 /* Log back into the node before sending the FARP. */
5387 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005388 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005389 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005390 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005391 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005392 }
5393
5394 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005395 if (fp->Rflags & FARP_REQUEST_FARPR)
5396 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005397 }
5398 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005399 return 0;
dea31012005-04-17 16:05:31 -05005400}
5401
James Smarte59058c2008-08-24 21:49:00 -04005402/**
James Smart3621a712009-04-06 18:47:14 -04005403 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005404 * @vport: pointer to a host virtual N_Port data structure.
5405 * @cmdiocb: pointer to lpfc command iocb data structure.
5406 * @ndlp: pointer to a node-list data structure.
5407 *
5408 * This routine processes Fibre Channel Address Resolution Protocol
5409 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5410 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5411 * the FARP response request.
5412 *
5413 * Return code
5414 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5415 **/
dea31012005-04-17 16:05:31 -05005416static int
James Smart2e0fef82007-06-17 19:56:36 -05005417lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5418 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005419{
5420 struct lpfc_dmabuf *pcmd;
5421 uint32_t *lp;
5422 IOCB_t *icmd;
5423 uint32_t cmd, did;
5424
5425 icmd = &cmdiocb->iocb;
5426 did = icmd->un.elsreq64.remoteID;
5427 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5428 lp = (uint32_t *) pcmd->virt;
5429
5430 cmd = *lp++;
5431 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005432 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5433 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005434 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005435 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005436
5437 return 0;
5438}
5439
James Smarte59058c2008-08-24 21:49:00 -04005440/**
James Smart3621a712009-04-06 18:47:14 -04005441 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005442 * @vport: pointer to a host virtual N_Port data structure.
5443 * @cmdiocb: pointer to lpfc command iocb data structure.
5444 * @fan_ndlp: pointer to a node-list data structure.
5445 *
5446 * This routine processes a Fabric Address Notification (FAN) IOCB
5447 * command received as an ELS unsolicited event. The FAN ELS command will
5448 * only be processed on a physical port (i.e., the @vport represents the
5449 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5450 * compared against those in the phba data structure. If any of those is
5451 * different, the lpfc_initial_flogi() routine is invoked to initialize
5452 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5453 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5454 * is invoked to register login to the fabric.
5455 *
5456 * Return code
5457 * 0 - Successfully processed fan iocb (currently always return 0).
5458 **/
dea31012005-04-17 16:05:31 -05005459static int
James Smart2e0fef82007-06-17 19:56:36 -05005460lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5461 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005462{
James Smart2e0fef82007-06-17 19:56:36 -05005463 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005464 uint32_t *lp;
5465 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005466
James Smart0d2b6b82008-06-14 22:52:47 -04005467 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5468 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5469 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005470 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005471 if ((vport == phba->pport) &&
5472 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005473 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005474 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005475 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005476 sizeof(struct lpfc_name)))) {
5477 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005478 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005479 } else {
5480 /* FAN verified - skip FLOGI */
5481 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005482 if (phba->sli_rev < LPFC_SLI_REV4)
5483 lpfc_issue_fabric_reglogin(vport);
5484 else
5485 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005486 }
dea31012005-04-17 16:05:31 -05005487 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005488 return 0;
dea31012005-04-17 16:05:31 -05005489}
5490
James Smarte59058c2008-08-24 21:49:00 -04005491/**
James Smart3621a712009-04-06 18:47:14 -04005492 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005493 * @ptr: holder for the timer function associated data.
5494 *
5495 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5496 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5497 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5498 * up the worker thread. It is for the worker thread to invoke the routine
5499 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5500 **/
dea31012005-04-17 16:05:31 -05005501void
5502lpfc_els_timeout(unsigned long ptr)
5503{
James Smart2e0fef82007-06-17 19:56:36 -05005504 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5505 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005506 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005507 unsigned long iflag;
5508
James Smart2e0fef82007-06-17 19:56:36 -05005509 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005510 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5511 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005512 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005513 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005514
James Smart5e9d9b82008-06-14 22:52:53 -04005515 if (!tmo_posted)
5516 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005517 return;
5518}
5519
James Smart2a9bf3d2010-06-07 15:24:45 -04005520
James Smarte59058c2008-08-24 21:49:00 -04005521/**
James Smart3621a712009-04-06 18:47:14 -04005522 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005523 * @vport: pointer to a virtual N_Port data structure.
5524 *
5525 * This routine is the actual handler function that processes an ELS timeout
5526 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5527 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5528 * invoking the lpfc_sli_issue_abort_iotag() routine.
5529 **/
dea31012005-04-17 16:05:31 -05005530void
James Smart2e0fef82007-06-17 19:56:36 -05005531lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005532{
James Smart2e0fef82007-06-17 19:56:36 -05005533 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005534 struct lpfc_sli_ring *pring;
5535 struct lpfc_iocbq *tmp_iocb, *piocb;
5536 IOCB_t *cmd = NULL;
5537 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005538 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005539 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005540 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005541 LIST_HEAD(txcmplq_completions);
5542 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005543
James Smart2a9bf3d2010-06-07 15:24:45 -04005544
dea31012005-04-17 16:05:31 -05005545 timeout = (uint32_t)(phba->fc_ratov << 1);
5546
5547 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005548
James Smart2a9bf3d2010-06-07 15:24:45 -04005549 spin_lock_irq(&phba->hbalock);
5550 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5551 spin_unlock_irq(&phba->hbalock);
5552
5553 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005554 cmd = &piocb->iocb;
5555
James Smart2e0fef82007-06-17 19:56:36 -05005556 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5557 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5558 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005559 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005560
5561 if (piocb->vport != vport)
5562 continue;
5563
dea31012005-04-17 16:05:31 -05005564 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005565 if (pcmd)
5566 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005567
James Smart92d7f7b2007-06-17 19:56:38 -05005568 if (els_command == ELS_CMD_FARP ||
5569 els_command == ELS_CMD_FARPR ||
5570 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005571 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005572
dea31012005-04-17 16:05:31 -05005573 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005574 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005575 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005576 else
dea31012005-04-17 16:05:31 -05005577 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005578 continue;
5579 }
5580
James Smart2e0fef82007-06-17 19:56:36 -05005581 remote_ID = 0xffffffff;
5582 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005583 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005584 else {
5585 struct lpfc_nodelist *ndlp;
5586 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005587 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005588 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005589 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005590 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005591 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005592 spin_lock_irq(&phba->hbalock);
5593 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005594 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005595
James Smart2a9bf3d2010-06-07 15:24:45 -04005596 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5597 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5598 "0127 ELS timeout Data: x%x x%x x%x "
5599 "x%x\n", els_command,
5600 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5601 spin_lock_irq(&phba->hbalock);
5602 list_del_init(&piocb->dlist);
5603 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5604 spin_unlock_irq(&phba->hbalock);
5605 }
5606
James Smart2e0fef82007-06-17 19:56:36 -05005607 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5608 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005609}
5610
James Smarte59058c2008-08-24 21:49:00 -04005611/**
James Smart3621a712009-04-06 18:47:14 -04005612 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005613 * @vport: pointer to a host virtual N_Port data structure.
5614 *
5615 * This routine is used to clean up all the outstanding ELS commands on a
5616 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5617 * routine. After that, it walks the ELS transmit queue to remove all the
5618 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5619 * the IOCBs with a non-NULL completion callback function, the callback
5620 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5621 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5622 * callback function, the IOCB will simply be released. Finally, it walks
5623 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5624 * completion queue IOCB that is associated with the @vport and is not
5625 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5626 * part of the discovery state machine) out to HBA by invoking the
5627 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5628 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5629 * the IOCBs are aborted when this function returns.
5630 **/
dea31012005-04-17 16:05:31 -05005631void
James Smart2e0fef82007-06-17 19:56:36 -05005632lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005633{
James Smart2534ba72007-04-25 09:52:20 -04005634 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005635 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005636 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005637 struct lpfc_iocbq *tmp_iocb, *piocb;
5638 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005639
5640 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005641
James Smart2e0fef82007-06-17 19:56:36 -05005642 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005643 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5644 cmd = &piocb->iocb;
5645
5646 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5647 continue;
5648 }
5649
5650 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005651 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5652 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5653 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5654 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005655 continue;
dea31012005-04-17 16:05:31 -05005656
James Smart2e0fef82007-06-17 19:56:36 -05005657 if (piocb->vport != vport)
5658 continue;
5659
James Smart2534ba72007-04-25 09:52:20 -04005660 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005661 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005662 }
5663
5664 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005665 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5666 continue;
5667 }
dea31012005-04-17 16:05:31 -05005668
James Smart2e0fef82007-06-17 19:56:36 -05005669 if (piocb->vport != vport)
5670 continue;
5671
James Smart07951072007-04-25 09:51:38 -04005672 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005673 }
James Smart2e0fef82007-06-17 19:56:36 -05005674 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005675
James Smarta257bf92009-04-06 18:48:10 -04005676 /* Cancell all the IOCBs from the completions list */
5677 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5678 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005679
dea31012005-04-17 16:05:31 -05005680 return;
5681}
5682
James Smarte59058c2008-08-24 21:49:00 -04005683/**
James Smart3621a712009-04-06 18:47:14 -04005684 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005685 * @phba: pointer to lpfc hba data structure.
5686 *
5687 * This routine is used to clean up all the outstanding ELS commands on a
5688 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5689 * routine. After that, it walks the ELS transmit queue to remove all the
5690 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5691 * the IOCBs with the completion callback function associated, the callback
5692 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5693 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5694 * callback function associated, the IOCB will simply be released. Finally,
5695 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5696 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5697 * management plane IOCBs that are not part of the discovery state machine)
5698 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5699 **/
James Smart549e55c2007-08-02 11:09:51 -04005700void
5701lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5702{
5703 LIST_HEAD(completions);
5704 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5705 struct lpfc_iocbq *tmp_iocb, *piocb;
5706 IOCB_t *cmd = NULL;
5707
5708 lpfc_fabric_abort_hba(phba);
5709 spin_lock_irq(&phba->hbalock);
5710 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5711 cmd = &piocb->iocb;
5712 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5713 continue;
5714 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5715 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5716 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5717 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5718 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5719 continue;
5720 list_move_tail(&piocb->list, &completions);
5721 pring->txq_cnt--;
5722 }
5723 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5724 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5725 continue;
5726 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5727 }
5728 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005729
5730 /* Cancel all the IOCBs from the completions list */
5731 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5732 IOERR_SLI_ABORTED);
5733
James Smart549e55c2007-08-02 11:09:51 -04005734 return;
5735}
5736
James Smarte59058c2008-08-24 21:49:00 -04005737/**
James Smart3621a712009-04-06 18:47:14 -04005738 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005739 * @phba: Pointer to hba context object.
5740 * @cmdiocbp: Pointer to command iocb which reported error.
5741 * @rspiocbp: Pointer to response iocb which reported error.
5742 *
5743 * This function sends an event when there is an ELS command
5744 * failure.
5745 **/
5746void
5747lpfc_send_els_failure_event(struct lpfc_hba *phba,
5748 struct lpfc_iocbq *cmdiocbp,
5749 struct lpfc_iocbq *rspiocbp)
5750{
5751 struct lpfc_vport *vport = cmdiocbp->vport;
5752 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5753 struct lpfc_lsrjt_event lsrjt_event;
5754 struct lpfc_fabric_event_header fabric_event;
5755 struct ls_rjt stat;
5756 struct lpfc_nodelist *ndlp;
5757 uint32_t *pcmd;
5758
5759 ndlp = cmdiocbp->context1;
5760 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5761 return;
5762
5763 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5764 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5765 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5766 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5767 sizeof(struct lpfc_name));
5768 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5769 sizeof(struct lpfc_name));
5770 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5771 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005772 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005773 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5774 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5775 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5776 fc_host_post_vendor_event(shost,
5777 fc_get_event_number(),
5778 sizeof(lsrjt_event),
5779 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005780 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005781 return;
5782 }
5783 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5784 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5785 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5786 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5787 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5788 else
5789 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5790 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5791 sizeof(struct lpfc_name));
5792 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5793 sizeof(struct lpfc_name));
5794 fc_host_post_vendor_event(shost,
5795 fc_get_event_number(),
5796 sizeof(fabric_event),
5797 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005798 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005799 return;
5800 }
5801
5802}
5803
5804/**
James Smart3621a712009-04-06 18:47:14 -04005805 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005806 * @vport: Pointer to vport object.
5807 * @ndlp: Pointer FC node object.
5808 * @cmd: ELS command code.
5809 *
5810 * This function posts an event when there is an incoming
5811 * unsolicited ELS command.
5812 **/
5813static void
5814lpfc_send_els_event(struct lpfc_vport *vport,
5815 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005816 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005817{
James Smartddcc50f2008-12-04 22:38:46 -05005818 struct lpfc_els_event_header *els_data = NULL;
5819 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5821
James Smartddcc50f2008-12-04 22:38:46 -05005822 if (*payload == ELS_CMD_LOGO) {
5823 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5824 if (!logo_data) {
5825 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5826 "0148 Failed to allocate memory "
5827 "for LOGO event\n");
5828 return;
5829 }
5830 els_data = &logo_data->header;
5831 } else {
5832 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5833 GFP_KERNEL);
5834 if (!els_data) {
5835 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5836 "0149 Failed to allocate memory "
5837 "for ELS event\n");
5838 return;
5839 }
5840 }
5841 els_data->event_type = FC_REG_ELS_EVENT;
5842 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005843 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005844 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005845 break;
5846 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005847 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005848 break;
5849 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005850 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5851 break;
5852 case ELS_CMD_LOGO:
5853 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5854 /* Copy the WWPN in the LOGO payload */
5855 memcpy(logo_data->logo_wwpn, &payload[2],
5856 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005857 break;
5858 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005859 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005860 return;
5861 }
James Smartddcc50f2008-12-04 22:38:46 -05005862 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5863 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5864 if (*payload == ELS_CMD_LOGO) {
5865 fc_host_post_vendor_event(shost,
5866 fc_get_event_number(),
5867 sizeof(struct lpfc_logo_event),
5868 (char *)logo_data,
5869 LPFC_NL_VENDOR_ID);
5870 kfree(logo_data);
5871 } else {
5872 fc_host_post_vendor_event(shost,
5873 fc_get_event_number(),
5874 sizeof(struct lpfc_els_event_header),
5875 (char *)els_data,
5876 LPFC_NL_VENDOR_ID);
5877 kfree(els_data);
5878 }
James Smartea2151b2008-09-07 11:52:10 -04005879
5880 return;
5881}
5882
5883
5884/**
James Smart3621a712009-04-06 18:47:14 -04005885 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005886 * @phba: pointer to lpfc hba data structure.
5887 * @pring: pointer to a SLI ring.
5888 * @vport: pointer to a host virtual N_Port data structure.
5889 * @elsiocb: pointer to lpfc els command iocb data structure.
5890 *
5891 * This routine is used for processing the IOCB associated with a unsolicited
5892 * event. It first determines whether there is an existing ndlp that matches
5893 * the DID from the unsolicited IOCB. If not, it will create a new one with
5894 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5895 * IOCB is then used to invoke the proper routine and to set up proper state
5896 * of the discovery state machine.
5897 **/
James Smarted957682007-06-17 19:56:37 -05005898static void
5899lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005900 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005901{
James Smart87af33f2007-10-27 13:37:43 -04005902 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005903 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005904 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005905 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005906 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005907 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005908
James Smarte47c9092008-02-08 18:49:26 -05005909 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005910 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005911
dea31012005-04-17 16:05:31 -05005912 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005913 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5914 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005915 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005916 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005917
James Smart858c9f62007-06-17 19:56:39 -05005918 did = icmd->un.rcvels.remoteID;
5919 if (icmd->ulpStatus) {
5920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5921 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5922 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005923 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005924 }
dea31012005-04-17 16:05:31 -05005925
5926 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005927 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005928 goto dropit;
dea31012005-04-17 16:05:31 -05005929
James Smartc8685952009-11-18 15:39:16 -05005930 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005931 if (vport->load_flag & FC_UNLOADING)
5932 goto dropit;
5933
James Smart2e0fef82007-06-17 19:56:36 -05005934 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005935 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005936 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005937 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005938 if (!ndlp)
dea31012005-04-17 16:05:31 -05005939 goto dropit;
dea31012005-04-17 16:05:31 -05005940
James Smart2e0fef82007-06-17 19:56:36 -05005941 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005942 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005943 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005944 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005945 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005946 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5947 ndlp = lpfc_enable_node(vport, ndlp,
5948 NLP_STE_UNUSED_NODE);
5949 if (!ndlp)
5950 goto dropit;
5951 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5952 newnode = 1;
5953 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5954 ndlp->nlp_type |= NLP_FABRIC;
5955 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5956 /* This is similar to the new node path */
5957 ndlp = lpfc_nlp_get(ndlp);
5958 if (!ndlp)
5959 goto dropit;
5960 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5961 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005962 }
dea31012005-04-17 16:05:31 -05005963
5964 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005965
James Smart329f9bc2007-04-25 09:53:01 -04005966 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005967 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005968
5969 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5970 cmd &= ELS_CMD_MASK;
5971 }
5972 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005973 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5974 "0112 ELS command x%x received from NPORT x%x "
5975 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005976 switch (cmd) {
5977 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5979 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5980 did, vport->port_state, ndlp->nlp_flag);
5981
dea31012005-04-17 16:05:31 -05005982 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005983 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5984
James Smartddcc50f2008-12-04 22:38:46 -05005985 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005986 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005987 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5988 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5989 rjt_err = LSRJT_UNABLE_TPC;
5990 break;
5991 }
5992 /* We get here, and drop thru, if we are PT2PT with
5993 * another NPort and the other side has initiated
5994 * the PLOGI before responding to our FLOGI.
5995 */
dea31012005-04-17 16:05:31 -05005996 }
James Smart87af33f2007-10-27 13:37:43 -04005997
5998 shost = lpfc_shost_from_vport(vport);
5999 spin_lock_irq(shost->host_lock);
6000 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6001 spin_unlock_irq(shost->host_lock);
6002
James Smart2e0fef82007-06-17 19:56:36 -05006003 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6004 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006005
dea31012005-04-17 16:05:31 -05006006 break;
6007 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6009 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6010 did, vport->port_state, ndlp->nlp_flag);
6011
dea31012005-04-17 16:05:31 -05006012 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006013 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006014 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006015 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006016 break;
6017 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6019 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6020 did, vport->port_state, ndlp->nlp_flag);
6021
dea31012005-04-17 16:05:31 -05006022 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006023 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006024 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006025 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006026 break;
6027 }
James Smart2e0fef82007-06-17 19:56:36 -05006028 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006029 break;
6030 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006031 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6032 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6033 did, vport->port_state, ndlp->nlp_flag);
6034
dea31012005-04-17 16:05:31 -05006035 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006036 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006037 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006038 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006039 break;
6040 }
James Smart2e0fef82007-06-17 19:56:36 -05006041 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006042 break;
6043 case ELS_CMD_RSCN:
6044 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006045 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006046 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006047 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006048 break;
6049 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6051 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6052 did, vport->port_state, ndlp->nlp_flag);
6053
James Smartddcc50f2008-12-04 22:38:46 -05006054 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006055 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006056 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006057 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006058 break;
6059 }
James Smart2e0fef82007-06-17 19:56:36 -05006060 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6061 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006062 break;
6063 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006064 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6065 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6066 did, vport->port_state, ndlp->nlp_flag);
6067
dea31012005-04-17 16:05:31 -05006068 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006069 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006070 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006071 break;
6072 }
James Smart2e0fef82007-06-17 19:56:36 -05006073 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6074 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006075 break;
6076 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006077 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6078 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6079 did, vport->port_state, ndlp->nlp_flag);
6080
dea31012005-04-17 16:05:31 -05006081 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006082 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006083 break;
6084 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006085 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6086 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6087 did, vport->port_state, ndlp->nlp_flag);
6088
dea31012005-04-17 16:05:31 -05006089 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006090 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006091 break;
6092 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006093 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6094 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6095 did, vport->port_state, ndlp->nlp_flag);
6096
dea31012005-04-17 16:05:31 -05006097 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006098 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006099 break;
dea31012005-04-17 16:05:31 -05006100 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006101 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6102 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6103 did, vport->port_state, ndlp->nlp_flag);
6104
dea31012005-04-17 16:05:31 -05006105 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006106 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006107 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006108 break;
6109 }
James Smart2e0fef82007-06-17 19:56:36 -05006110 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006111 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006112 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6114 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6115 did, vport->port_state, ndlp->nlp_flag);
6116
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006117 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006118 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006119 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006120 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006121 break;
James Smart12265f62010-10-22 11:05:53 -04006122 case ELS_CMD_RLS:
6123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6124 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6125 did, vport->port_state, ndlp->nlp_flag);
6126
6127 phba->fc_stat.elsRcvRLS++;
6128 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6129 if (newnode)
6130 lpfc_nlp_put(ndlp);
6131 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006132 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006133 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6134 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6135 did, vport->port_state, ndlp->nlp_flag);
6136
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006137 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006138 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006139 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006140 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006141 break;
6142 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006143 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6144 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6145 did, vport->port_state, ndlp->nlp_flag);
6146
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006147 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006148 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006149 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006150 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006151 break;
dea31012005-04-17 16:05:31 -05006152 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6154 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6155 did, vport->port_state, ndlp->nlp_flag);
6156
dea31012005-04-17 16:05:31 -05006157 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006158 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006159 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006160 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006161 break;
James Smart12265f62010-10-22 11:05:53 -04006162 case ELS_CMD_RTV:
6163 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6164 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6165 did, vport->port_state, ndlp->nlp_flag);
6166 phba->fc_stat.elsRcvRTV++;
6167 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6168 if (newnode)
6169 lpfc_nlp_put(ndlp);
6170 break;
James Smart5ffc2662009-11-18 15:39:44 -05006171 case ELS_CMD_RRQ:
6172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6173 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6174 did, vport->port_state, ndlp->nlp_flag);
6175
6176 phba->fc_stat.elsRcvRRQ++;
6177 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6178 if (newnode)
6179 lpfc_nlp_put(ndlp);
6180 break;
James Smart12265f62010-10-22 11:05:53 -04006181 case ELS_CMD_ECHO:
6182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6183 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6184 did, vport->port_state, ndlp->nlp_flag);
6185
6186 phba->fc_stat.elsRcvECHO++;
6187 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6188 if (newnode)
6189 lpfc_nlp_put(ndlp);
6190 break;
dea31012005-04-17 16:05:31 -05006191 default:
James Smart858c9f62007-06-17 19:56:39 -05006192 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6193 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6194 cmd, did, vport->port_state);
6195
dea31012005-04-17 16:05:31 -05006196 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05006197 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05006198
6199 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006200 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6201 "0115 Unknown ELS command x%x "
6202 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006203 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006204 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006205 break;
6206 }
6207
6208 /* check if need to LS_RJT received ELS cmd */
6209 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006210 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006211 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006212 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006213 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6214 NULL);
dea31012005-04-17 16:05:31 -05006215 }
6216
James Smartd7c255b2008-08-24 21:50:00 -04006217 lpfc_nlp_put(elsiocb->context1);
6218 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006219 return;
6220
6221dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006222 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006223 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6224 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006225 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006226 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006227 phba->fc_stat.elsRcvDrop++;
6228}
6229
James Smarte59058c2008-08-24 21:49:00 -04006230/**
James Smart3621a712009-04-06 18:47:14 -04006231 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006232 * @phba: pointer to lpfc hba data structure.
6233 * @vpi: host virtual N_Port identifier.
6234 *
6235 * This routine finds a vport on a HBA (referred by @phba) through a
6236 * @vpi. The function walks the HBA's vport list and returns the address
6237 * of the vport with the matching @vpi.
6238 *
6239 * Return code
6240 * NULL - No vport with the matching @vpi found
6241 * Otherwise - Address to the vport with the matching @vpi.
6242 **/
James Smart6669f9b2009-10-02 15:16:45 -04006243struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006244lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6245{
6246 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006247 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006248
James Smart549e55c2007-08-02 11:09:51 -04006249 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006250 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006251 if (vport->vpi == vpi) {
6252 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006253 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006254 }
James Smart92d7f7b2007-06-17 19:56:38 -05006255 }
James Smart549e55c2007-08-02 11:09:51 -04006256 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006257 return NULL;
6258}
James Smarted957682007-06-17 19:56:37 -05006259
James Smarte59058c2008-08-24 21:49:00 -04006260/**
James Smart3621a712009-04-06 18:47:14 -04006261 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006262 * @phba: pointer to lpfc hba data structure.
6263 * @pring: pointer to a SLI ring.
6264 * @elsiocb: pointer to lpfc els iocb data structure.
6265 *
6266 * This routine is used to process an unsolicited event received from a SLI
6267 * (Service Level Interface) ring. The actual processing of the data buffer
6268 * associated with the unsolicited event is done by invoking the routine
6269 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6270 * SLI ring on which the unsolicited event was received.
6271 **/
James Smarted957682007-06-17 19:56:37 -05006272void
6273lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6274 struct lpfc_iocbq *elsiocb)
6275{
6276 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006277 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006278 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006279 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6280 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006281
James Smartd7c255b2008-08-24 21:50:00 -04006282 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006283 elsiocb->context2 = NULL;
6284 elsiocb->context3 = NULL;
6285
6286 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6287 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6288 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6289 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006290 phba->fc_stat.NoRcvBuf++;
6291 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006292 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006293 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006294 return;
6295 }
6296
James Smart92d7f7b2007-06-17 19:56:38 -05006297 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6298 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6299 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6300 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6301 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006302 else
6303 vport = lpfc_find_vport_by_vpid(phba,
6304 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006305 }
James Smart7f5f3d02008-02-08 18:50:14 -05006306 /* If there are no BDEs associated
6307 * with this IOCB, there is nothing to do.
6308 */
James Smarted957682007-06-17 19:56:37 -05006309 if (icmd->ulpBdeCount == 0)
6310 return;
6311
James Smart7f5f3d02008-02-08 18:50:14 -05006312 /* type of ELS cmd is first 32bit word
6313 * in packet
6314 */
James Smarted957682007-06-17 19:56:37 -05006315 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006316 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006317 } else {
6318 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6319 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006320 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6321 paddr);
James Smarted957682007-06-17 19:56:37 -05006322 }
6323
James Smart92d7f7b2007-06-17 19:56:38 -05006324 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6325 /*
6326 * The different unsolicited event handlers would tell us
6327 * if they are done with "mp" by setting context2 to NULL.
6328 */
dea31012005-04-17 16:05:31 -05006329 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006330 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6331 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006332 }
James Smarted957682007-06-17 19:56:37 -05006333
6334 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006335 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006336 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006337 elsiocb->context2 = bdeBuf2;
6338 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006339 /* free mp if we are done with it */
6340 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006341 lpfc_in_buf_free(phba, elsiocb->context2);
6342 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006343 }
dea31012005-04-17 16:05:31 -05006344 }
dea31012005-04-17 16:05:31 -05006345}
James Smart92d7f7b2007-06-17 19:56:38 -05006346
James Smarte59058c2008-08-24 21:49:00 -04006347/**
James Smart3621a712009-04-06 18:47:14 -04006348 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006349 * @phba: pointer to lpfc hba data structure.
6350 * @vport: pointer to a virtual N_Port data structure.
6351 *
6352 * This routine issues a Port Login (PLOGI) to the Name Server with
6353 * State Change Request (SCR) for a @vport. This routine will create an
6354 * ndlp for the Name Server associated to the @vport if such node does
6355 * not already exist. The PLOGI to Name Server is issued by invoking the
6356 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6357 * (FDMI) is configured to the @vport, a FDMI node will be created and
6358 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6359 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006360void
6361lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6362{
6363 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6364
6365 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6366 if (!ndlp) {
6367 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6368 if (!ndlp) {
6369 if (phba->fc_topology == TOPOLOGY_LOOP) {
6370 lpfc_disc_start(vport);
6371 return;
6372 }
6373 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006374 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6375 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006376 return;
6377 }
6378 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006379 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6380 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6381 if (!ndlp) {
6382 if (phba->fc_topology == TOPOLOGY_LOOP) {
6383 lpfc_disc_start(vport);
6384 return;
6385 }
6386 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6387 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6388 "0348 NameServer login: node freed\n");
6389 return;
6390 }
James Smart92d7f7b2007-06-17 19:56:38 -05006391 }
James Smart58da1ff2008-04-07 10:15:56 -04006392 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006393
6394 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6395
6396 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6397 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006398 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6399 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006400 return;
6401 }
6402
James Smart3de2a652007-08-02 11:09:59 -04006403 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006404 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6405 GFP_KERNEL);
6406 if (ndlp_fdmi) {
6407 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6408 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006409 lpfc_nlp_set_state(vport, ndlp_fdmi,
6410 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006411 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6412 0);
6413 }
6414 }
6415 return;
6416}
6417
James Smarte59058c2008-08-24 21:49:00 -04006418/**
James Smart3621a712009-04-06 18:47:14 -04006419 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006420 * @phba: pointer to lpfc hba data structure.
6421 * @pmb: pointer to the driver internal queue element for mailbox command.
6422 *
6423 * This routine is the completion callback function to register new vport
6424 * mailbox command. If the new vport mailbox command completes successfully,
6425 * the fabric registration login shall be performed on physical port (the
6426 * new vport created is actually a physical port, with VPI 0) or the port
6427 * login to Name Server for State Change Request (SCR) will be performed
6428 * on virtual port (real virtual port, with VPI greater than 0).
6429 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006430static void
6431lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6432{
6433 struct lpfc_vport *vport = pmb->vport;
6434 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6435 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006436 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006437 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006438
James Smart09372822008-01-11 01:52:54 -05006439 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006440 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006441 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006442
6443 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006444 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006445 "0915 Register VPI failed : Status: x%x"
6446 " upd bit: x%x \n", mb->mbxStatus,
6447 mb->un.varRegVpi.upd);
6448 if (phba->sli_rev == LPFC_SLI_REV4 &&
6449 mb->un.varRegVpi.upd)
6450 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006451
6452 switch (mb->mbxStatus) {
6453 case 0x11: /* unsupported feature */
6454 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006455 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006456 /* giving up on vport registration */
6457 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6458 spin_lock_irq(shost->host_lock);
6459 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6460 spin_unlock_irq(shost->host_lock);
6461 lpfc_can_disctmo(vport);
6462 break;
James Smart695a8142010-01-26 23:08:03 -05006463 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6464 case 0x20:
6465 spin_lock_irq(shost->host_lock);
6466 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6467 spin_unlock_irq(shost->host_lock);
6468 lpfc_init_vpi(phba, pmb, vport->vpi);
6469 pmb->vport = vport;
6470 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6471 rc = lpfc_sli_issue_mbox(phba, pmb,
6472 MBX_NOWAIT);
6473 if (rc == MBX_NOT_FINISHED) {
6474 lpfc_printf_vlog(vport,
6475 KERN_ERR, LOG_MBOX,
6476 "2732 Failed to issue INIT_VPI"
6477 " mailbox command\n");
6478 } else {
6479 lpfc_nlp_put(ndlp);
6480 return;
6481 }
6482
James Smart92d7f7b2007-06-17 19:56:38 -05006483 default:
6484 /* Try to recover from this error */
6485 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006486 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006487 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006488 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006489 if (vport->port_type == LPFC_PHYSICAL_PORT
6490 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006491 lpfc_initial_flogi(vport);
6492 else
6493 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006494 break;
6495 }
James Smart92d7f7b2007-06-17 19:56:38 -05006496 } else {
James Smart695a8142010-01-26 23:08:03 -05006497 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006498 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006499 spin_unlock_irq(shost->host_lock);
6500 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006501 if (phba->sli_rev < LPFC_SLI_REV4)
6502 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006503 else {
James Smartfc2b9892010-02-26 14:15:29 -05006504 /*
6505 * If the physical port is instantiated using
6506 * FDISC, do not start vport discovery.
6507 */
6508 if (vport->port_state != LPFC_FDISC)
6509 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006510 lpfc_do_scr_ns_plogi(phba, vport);
6511 }
6512 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006513 lpfc_do_scr_ns_plogi(phba, vport);
6514 }
James Smart38b92ef2010-08-04 16:11:39 -04006515mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006516 /* Now, we decrement the ndlp reference count held for this
6517 * callback function
6518 */
6519 lpfc_nlp_put(ndlp);
6520
James Smart92d7f7b2007-06-17 19:56:38 -05006521 mempool_free(pmb, phba->mbox_mem_pool);
6522 return;
6523}
6524
James Smarte59058c2008-08-24 21:49:00 -04006525/**
James Smart3621a712009-04-06 18:47:14 -04006526 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006527 * @phba: pointer to lpfc hba data structure.
6528 * @vport: pointer to a host virtual N_Port data structure.
6529 * @ndlp: pointer to a node-list data structure.
6530 *
6531 * This routine registers the @vport as a new virtual port with a HBA.
6532 * It is done through a registering vpi mailbox command.
6533 **/
James Smart695a8142010-01-26 23:08:03 -05006534void
James Smart92d7f7b2007-06-17 19:56:38 -05006535lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6536 struct lpfc_nodelist *ndlp)
6537{
James Smart09372822008-01-11 01:52:54 -05006538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006539 LPFC_MBOXQ_t *mbox;
6540
6541 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6542 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006543 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006544 mbox->vport = vport;
6545 mbox->context2 = lpfc_nlp_get(ndlp);
6546 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006547 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006548 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006549 /* mailbox command not success, decrement ndlp
6550 * reference count for this command
6551 */
6552 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006553 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006554
James Smarte8b62012007-08-02 11:10:09 -04006555 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6556 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006557 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006558 }
6559 } else {
James Smarte8b62012007-08-02 11:10:09 -04006560 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6561 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006562 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006563 }
James Smartfa4066b2008-01-11 01:53:27 -05006564 return;
6565
6566mbox_err_exit:
6567 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6568 spin_lock_irq(shost->host_lock);
6569 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6570 spin_unlock_irq(shost->host_lock);
6571 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006572}
6573
James Smarte59058c2008-08-24 21:49:00 -04006574/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006575 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006576 * @phba: pointer to lpfc hba data structure.
6577 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006578 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006579 **/
6580void
James Smart0c9ab6f2010-02-26 14:15:57 -05006581lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006582{
6583 struct lpfc_vport **vports;
6584 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006585 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006586 int i;
James Smart695a8142010-01-26 23:08:03 -05006587
6588 /* Treat this failure as linkdown for all vports */
6589 link_state = phba->link_state;
6590 lpfc_linkdown(phba);
6591 phba->link_state = link_state;
6592
6593 vports = lpfc_create_vport_work_array(phba);
6594
6595 if (vports) {
6596 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6597 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6598 if (ndlp)
6599 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6600 lpfc_els_flush_cmd(vports[i]);
6601 }
6602 lpfc_destroy_vport_work_array(phba, vports);
6603 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006604}
6605
6606/**
6607 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6608 * @phba: pointer to lpfc hba data structure.
6609 *
6610 * This routine abort all pending discovery commands and
6611 * start a timer to retry FLOGI for the physical port
6612 * discovery.
6613 **/
6614void
6615lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6616{
6617 struct lpfc_nodelist *ndlp;
6618 struct Scsi_Host *shost;
6619
6620 /* Cancel the all vports retry delay retry timers */
6621 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006622
6623 /* If fabric require FLOGI, then re-instantiate physical login */
6624 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6625 if (!ndlp)
6626 return;
6627
James Smart695a8142010-01-26 23:08:03 -05006628 shost = lpfc_shost_from_vport(phba->pport);
6629 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6630 spin_lock_irq(shost->host_lock);
6631 ndlp->nlp_flag |= NLP_DELAY_TMO;
6632 spin_unlock_irq(shost->host_lock);
6633 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6634 phba->pport->port_state = LPFC_FLOGI;
6635 return;
6636}
6637
6638/**
6639 * lpfc_fabric_login_reqd - Check if FLOGI required.
6640 * @phba: pointer to lpfc hba data structure.
6641 * @cmdiocb: pointer to FDISC command iocb.
6642 * @rspiocb: pointer to FDISC response iocb.
6643 *
6644 * This routine checks if a FLOGI is reguired for FDISC
6645 * to succeed.
6646 **/
6647static int
6648lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6649 struct lpfc_iocbq *cmdiocb,
6650 struct lpfc_iocbq *rspiocb)
6651{
6652
6653 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6654 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6655 return 0;
6656 else
6657 return 1;
6658}
6659
6660/**
James Smart3621a712009-04-06 18:47:14 -04006661 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006662 * @phba: pointer to lpfc hba data structure.
6663 * @cmdiocb: pointer to lpfc command iocb data structure.
6664 * @rspiocb: pointer to lpfc response iocb data structure.
6665 *
6666 * This routine is the completion callback function to a Fabric Discover
6667 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6668 * single threaded, each FDISC completion callback function will reset
6669 * the discovery timer for all vports such that the timers will not get
6670 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6671 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6672 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6673 * assigned to the vport has been changed with the completion of the FDISC
6674 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6675 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6676 * routine is invoked to register new vport with the HBA. Otherwise, the
6677 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6678 * Server for State Change Request (SCR).
6679 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006680static void
6681lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6682 struct lpfc_iocbq *rspiocb)
6683{
6684 struct lpfc_vport *vport = cmdiocb->vport;
6685 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6686 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6687 struct lpfc_nodelist *np;
6688 struct lpfc_nodelist *next_np;
6689 IOCB_t *irsp = &rspiocb->iocb;
6690 struct lpfc_iocbq *piocb;
6691
James Smarte8b62012007-08-02 11:10:09 -04006692 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6693 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6694 irsp->ulpStatus, irsp->un.ulpWord[4],
6695 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006696 /* Since all FDISCs are being single threaded, we
6697 * must reset the discovery timer for ALL vports
6698 * waiting to send FDISC when one completes.
6699 */
6700 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6701 lpfc_set_disctmo(piocb->vport);
6702 }
6703
James Smart858c9f62007-06-17 19:56:39 -05006704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6705 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6706 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6707
James Smart92d7f7b2007-06-17 19:56:38 -05006708 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006709
6710 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6711 lpfc_retry_pport_discovery(phba);
6712 goto out;
6713 }
6714
James Smart92d7f7b2007-06-17 19:56:38 -05006715 /* Check for retry */
6716 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6717 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006718 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006719 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006720 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006721 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006722 goto fdisc_failed;
6723 }
James Smartd7c255b2008-08-24 21:50:00 -04006724 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006725 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006726 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006727 vport->fc_flag |= FC_FABRIC;
6728 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6729 vport->fc_flag |= FC_PUBLIC_LOOP;
6730 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006731
James Smartd7c255b2008-08-24 21:50:00 -04006732 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6733 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6734 if ((vport->fc_prevDID != vport->fc_myDID) &&
6735 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6736 /* If our NportID changed, we need to ensure all
6737 * remaining NPORTs get unreg_login'ed so we can
6738 * issue unreg_vpi.
6739 */
6740 list_for_each_entry_safe(np, next_np,
6741 &vport->fc_nodes, nlp_listp) {
6742 if (!NLP_CHK_NODE_ACT(ndlp) ||
6743 (np->nlp_state != NLP_STE_NPR_NODE) ||
6744 !(np->nlp_flag & NLP_NPR_ADISC))
6745 continue;
James Smart09372822008-01-11 01:52:54 -05006746 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006747 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006748 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006749 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006750 }
James Smart78730cf2010-04-06 15:06:30 -04006751 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006752 lpfc_mbx_unreg_vpi(vport);
6753 spin_lock_irq(shost->host_lock);
6754 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006755 if (phba->sli_rev == LPFC_SLI_REV4)
6756 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006757 else
6758 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006759 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04006760 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6761 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6762 /*
6763 * Driver needs to re-reg VPI in order for f/w
6764 * to update the MAC address.
6765 */
6766 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04006767 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006768 }
6769
James Smartecfd03c2010-02-12 14:41:27 -05006770 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6771 lpfc_issue_init_vpi(vport);
6772 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006773 lpfc_register_new_vport(phba, vport, ndlp);
6774 else
6775 lpfc_do_scr_ns_plogi(phba, vport);
6776 goto out;
6777fdisc_failed:
6778 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6779 /* Cancel discovery timer */
6780 lpfc_can_disctmo(vport);
6781 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006782out:
6783 lpfc_els_free_iocb(phba, cmdiocb);
6784}
6785
James Smarte59058c2008-08-24 21:49:00 -04006786/**
James Smart3621a712009-04-06 18:47:14 -04006787 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006788 * @vport: pointer to a virtual N_Port data structure.
6789 * @ndlp: pointer to a node-list data structure.
6790 * @retry: number of retries to the command IOCB.
6791 *
6792 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6793 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6794 * routine to issue the IOCB, which makes sure only one outstanding fabric
6795 * IOCB will be sent off HBA at any given time.
6796 *
6797 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6798 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6799 * will be stored into the context1 field of the IOCB for the completion
6800 * callback function to the FDISC ELS command.
6801 *
6802 * Return code
6803 * 0 - Successfully issued fdisc iocb command
6804 * 1 - Failed to issue fdisc iocb command
6805 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006806static int
James Smart92d7f7b2007-06-17 19:56:38 -05006807lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6808 uint8_t retry)
6809{
6810 struct lpfc_hba *phba = vport->phba;
6811 IOCB_t *icmd;
6812 struct lpfc_iocbq *elsiocb;
6813 struct serv_parm *sp;
6814 uint8_t *pcmd;
6815 uint16_t cmdsize;
6816 int did = ndlp->nlp_DID;
6817 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006818
James Smart5ffc2662009-11-18 15:39:44 -05006819 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006820 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6821 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6822 ELS_CMD_FDISC);
6823 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006824 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006825 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6826 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006827 return 1;
6828 }
6829
6830 icmd = &elsiocb->iocb;
6831 icmd->un.elsreq64.myID = 0;
6832 icmd->un.elsreq64.fl = 1;
6833
James Smartf1126682009-06-10 17:22:44 -04006834 if (phba->sli_rev == LPFC_SLI_REV4) {
6835 /* FDISC needs to be 1 for WQE VPI */
6836 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6837 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6838 /* Set the ulpContext to the vpi */
6839 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6840 } else {
6841 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6842 icmd->ulpCt_h = 1;
6843 icmd->ulpCt_l = 0;
6844 }
James Smart92d7f7b2007-06-17 19:56:38 -05006845
6846 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6847 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6848 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6849 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6850 sp = (struct serv_parm *) pcmd;
6851 /* Setup CSPs accordingly for Fabric */
6852 sp->cmn.e_d_tov = 0;
6853 sp->cmn.w2.r_a_tov = 0;
6854 sp->cls1.classValid = 0;
6855 sp->cls2.seqDelivery = 1;
6856 sp->cls3.seqDelivery = 1;
6857
6858 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6859 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6860 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6861 pcmd += sizeof(uint32_t); /* Port Name */
6862 memcpy(pcmd, &vport->fc_portname, 8);
6863 pcmd += sizeof(uint32_t); /* Node Name */
6864 pcmd += sizeof(uint32_t); /* Node Name */
6865 memcpy(pcmd, &vport->fc_nodename, 8);
6866
6867 lpfc_set_disctmo(vport);
6868
6869 phba->fc_stat.elsXmitFDISC++;
6870 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6871
James Smart858c9f62007-06-17 19:56:39 -05006872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6873 "Issue FDISC: did:x%x",
6874 did, 0, 0);
6875
James Smart92d7f7b2007-06-17 19:56:38 -05006876 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6877 if (rc == IOCB_ERROR) {
6878 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006879 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006880 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6881 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006882 return 1;
6883 }
6884 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006885 return 0;
6886}
6887
James Smarte59058c2008-08-24 21:49:00 -04006888/**
James Smart3621a712009-04-06 18:47:14 -04006889 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006890 * @phba: pointer to lpfc hba data structure.
6891 * @cmdiocb: pointer to lpfc command iocb data structure.
6892 * @rspiocb: pointer to lpfc response iocb data structure.
6893 *
6894 * This routine is the completion callback function to the issuing of a LOGO
6895 * ELS command off a vport. It frees the command IOCB and then decrement the
6896 * reference count held on ndlp for this completion function, indicating that
6897 * the reference to the ndlp is no long needed. Note that the
6898 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6899 * callback function and an additional explicit ndlp reference decrementation
6900 * will trigger the actual release of the ndlp.
6901 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006902static void
6903lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6904 struct lpfc_iocbq *rspiocb)
6905{
6906 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006907 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006908 struct lpfc_nodelist *ndlp;
6909 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006910
6911 irsp = &rspiocb->iocb;
6912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6913 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6914 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006915
6916 lpfc_els_free_iocb(phba, cmdiocb);
6917 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006918
6919 /* Trigger the release of the ndlp after logo */
6920 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006921}
6922
James Smarte59058c2008-08-24 21:49:00 -04006923/**
James Smart3621a712009-04-06 18:47:14 -04006924 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006925 * @vport: pointer to a virtual N_Port data structure.
6926 * @ndlp: pointer to a node-list data structure.
6927 *
6928 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6929 *
6930 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6931 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6932 * will be stored into the context1 field of the IOCB for the completion
6933 * callback function to the LOGO ELS command.
6934 *
6935 * Return codes
6936 * 0 - Successfully issued logo off the @vport
6937 * 1 - Failed to issue logo off the @vport
6938 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006939int
6940lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6941{
6942 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6943 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006944 IOCB_t *icmd;
6945 struct lpfc_iocbq *elsiocb;
6946 uint8_t *pcmd;
6947 uint16_t cmdsize;
6948
6949 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6950 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6951 ELS_CMD_LOGO);
6952 if (!elsiocb)
6953 return 1;
6954
6955 icmd = &elsiocb->iocb;
6956 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6957 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6958 pcmd += sizeof(uint32_t);
6959
6960 /* Fill in LOGO payload */
6961 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6962 pcmd += sizeof(uint32_t);
6963 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6964
James Smart858c9f62007-06-17 19:56:39 -05006965 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6966 "Issue LOGO npiv did:x%x flg:x%x",
6967 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6968
James Smart92d7f7b2007-06-17 19:56:38 -05006969 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6970 spin_lock_irq(shost->host_lock);
6971 ndlp->nlp_flag |= NLP_LOGO_SND;
6972 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006973 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6974 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006975 spin_lock_irq(shost->host_lock);
6976 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6977 spin_unlock_irq(shost->host_lock);
6978 lpfc_els_free_iocb(phba, elsiocb);
6979 return 1;
6980 }
6981 return 0;
6982}
6983
James Smarte59058c2008-08-24 21:49:00 -04006984/**
James Smart3621a712009-04-06 18:47:14 -04006985 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006986 * @ptr: holder for the timer function associated data.
6987 *
6988 * This routine is invoked by the fabric iocb block timer after
6989 * timeout. It posts the fabric iocb block timeout event by setting the
6990 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6991 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6992 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6993 * posted event WORKER_FABRIC_BLOCK_TMO.
6994 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006995void
6996lpfc_fabric_block_timeout(unsigned long ptr)
6997{
6998 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6999 unsigned long iflags;
7000 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007001
James Smart92d7f7b2007-06-17 19:56:38 -05007002 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7003 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7004 if (!tmo_posted)
7005 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7006 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7007
James Smart5e9d9b82008-06-14 22:52:53 -04007008 if (!tmo_posted)
7009 lpfc_worker_wake_up(phba);
7010 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007011}
7012
James Smarte59058c2008-08-24 21:49:00 -04007013/**
James Smart3621a712009-04-06 18:47:14 -04007014 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007015 * @phba: pointer to lpfc hba data structure.
7016 *
7017 * This routine issues one fabric iocb from the driver internal list to
7018 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7019 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7020 * remove one pending fabric iocb from the driver internal list and invokes
7021 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7022 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007023static void
7024lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7025{
7026 struct lpfc_iocbq *iocb;
7027 unsigned long iflags;
7028 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007029 IOCB_t *cmd;
7030
7031repeat:
7032 iocb = NULL;
7033 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007034 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007035 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7036 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7037 list);
7038 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007039 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007040 atomic_inc(&phba->fabric_iocb_count);
7041 }
7042 spin_unlock_irqrestore(&phba->hbalock, iflags);
7043 if (iocb) {
7044 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7045 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7046 iocb->iocb_flag |= LPFC_IO_FABRIC;
7047
James Smart858c9f62007-06-17 19:56:39 -05007048 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7049 "Fabric sched1: ste:x%x",
7050 iocb->vport->port_state, 0, 0);
7051
James Smart3772a992009-05-22 14:50:54 -04007052 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007053
7054 if (ret == IOCB_ERROR) {
7055 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7056 iocb->fabric_iocb_cmpl = NULL;
7057 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7058 cmd = &iocb->iocb;
7059 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7060 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7061 iocb->iocb_cmpl(phba, iocb, iocb);
7062
7063 atomic_dec(&phba->fabric_iocb_count);
7064 goto repeat;
7065 }
7066 }
7067
7068 return;
7069}
7070
James Smarte59058c2008-08-24 21:49:00 -04007071/**
James Smart3621a712009-04-06 18:47:14 -04007072 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007073 * @phba: pointer to lpfc hba data structure.
7074 *
7075 * This routine unblocks the issuing fabric iocb command. The function
7076 * will clear the fabric iocb block bit and then invoke the routine
7077 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7078 * from the driver internal fabric iocb list.
7079 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007080void
7081lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7082{
7083 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7084
7085 lpfc_resume_fabric_iocbs(phba);
7086 return;
7087}
7088
James Smarte59058c2008-08-24 21:49:00 -04007089/**
James Smart3621a712009-04-06 18:47:14 -04007090 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007091 * @phba: pointer to lpfc hba data structure.
7092 *
7093 * This routine blocks the issuing fabric iocb for a specified amount of
7094 * time (currently 100 ms). This is done by set the fabric iocb block bit
7095 * and set up a timeout timer for 100ms. When the block bit is set, no more
7096 * fabric iocb will be issued out of the HBA.
7097 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007098static void
7099lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7100{
7101 int blocked;
7102
7103 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007104 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007105 if (!blocked)
7106 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7107
7108 return;
7109}
7110
James Smarte59058c2008-08-24 21:49:00 -04007111/**
James Smart3621a712009-04-06 18:47:14 -04007112 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007113 * @phba: pointer to lpfc hba data structure.
7114 * @cmdiocb: pointer to lpfc command iocb data structure.
7115 * @rspiocb: pointer to lpfc response iocb data structure.
7116 *
7117 * This routine is the callback function that is put to the fabric iocb's
7118 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7119 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7120 * function first restores and invokes the original iocb's callback function
7121 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7122 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7123 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007124static void
7125lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7126 struct lpfc_iocbq *rspiocb)
7127{
7128 struct ls_rjt stat;
7129
7130 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7131 BUG();
7132
7133 switch (rspiocb->iocb.ulpStatus) {
7134 case IOSTAT_NPORT_RJT:
7135 case IOSTAT_FABRIC_RJT:
7136 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7137 lpfc_block_fabric_iocbs(phba);
7138 }
7139 break;
7140
7141 case IOSTAT_NPORT_BSY:
7142 case IOSTAT_FABRIC_BSY:
7143 lpfc_block_fabric_iocbs(phba);
7144 break;
7145
7146 case IOSTAT_LS_RJT:
7147 stat.un.lsRjtError =
7148 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7149 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7150 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7151 lpfc_block_fabric_iocbs(phba);
7152 break;
7153 }
7154
7155 if (atomic_read(&phba->fabric_iocb_count) == 0)
7156 BUG();
7157
7158 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7159 cmdiocb->fabric_iocb_cmpl = NULL;
7160 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7161 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7162
7163 atomic_dec(&phba->fabric_iocb_count);
7164 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007165 /* Post any pending iocbs to HBA */
7166 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007167 }
7168}
7169
James Smarte59058c2008-08-24 21:49:00 -04007170/**
James Smart3621a712009-04-06 18:47:14 -04007171 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007172 * @phba: pointer to lpfc hba data structure.
7173 * @iocb: pointer to lpfc command iocb data structure.
7174 *
7175 * This routine is used as the top-level API for issuing a fabric iocb command
7176 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7177 * function makes sure that only one fabric bound iocb will be outstanding at
7178 * any given time. As such, this function will first check to see whether there
7179 * is already an outstanding fabric iocb on the wire. If so, it will put the
7180 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7181 * issued later. Otherwise, it will issue the iocb on the wire and update the
7182 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7183 *
7184 * Note, this implementation has a potential sending out fabric IOCBs out of
7185 * order. The problem is caused by the construction of the "ready" boolen does
7186 * not include the condition that the internal fabric IOCB list is empty. As
7187 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7188 * ahead of the fabric IOCBs in the internal list.
7189 *
7190 * Return code
7191 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7192 * IOCB_ERROR - failed to issue fabric iocb
7193 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007194static int
James Smart92d7f7b2007-06-17 19:56:38 -05007195lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7196{
7197 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007198 int ready;
7199 int ret;
7200
7201 if (atomic_read(&phba->fabric_iocb_count) > 1)
7202 BUG();
7203
7204 spin_lock_irqsave(&phba->hbalock, iflags);
7205 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7206 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7207
James Smart7f5f3d02008-02-08 18:50:14 -05007208 if (ready)
7209 /* Increment fabric iocb count to hold the position */
7210 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007211 spin_unlock_irqrestore(&phba->hbalock, iflags);
7212 if (ready) {
7213 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7214 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7215 iocb->iocb_flag |= LPFC_IO_FABRIC;
7216
James Smart858c9f62007-06-17 19:56:39 -05007217 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7218 "Fabric sched2: ste:x%x",
7219 iocb->vport->port_state, 0, 0);
7220
James Smart3772a992009-05-22 14:50:54 -04007221 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007222
7223 if (ret == IOCB_ERROR) {
7224 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7225 iocb->fabric_iocb_cmpl = NULL;
7226 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7227 atomic_dec(&phba->fabric_iocb_count);
7228 }
7229 } else {
7230 spin_lock_irqsave(&phba->hbalock, iflags);
7231 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7232 spin_unlock_irqrestore(&phba->hbalock, iflags);
7233 ret = IOCB_SUCCESS;
7234 }
7235 return ret;
7236}
7237
James Smarte59058c2008-08-24 21:49:00 -04007238/**
James Smart3621a712009-04-06 18:47:14 -04007239 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007240 * @vport: pointer to a virtual N_Port data structure.
7241 *
7242 * This routine aborts all the IOCBs associated with a @vport from the
7243 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7244 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7245 * list, removes each IOCB associated with the @vport off the list, set the
7246 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7247 * associated with the IOCB.
7248 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007249static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007250{
7251 LIST_HEAD(completions);
7252 struct lpfc_hba *phba = vport->phba;
7253 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007254
7255 spin_lock_irq(&phba->hbalock);
7256 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7257 list) {
7258
7259 if (piocb->vport != vport)
7260 continue;
7261
7262 list_move_tail(&piocb->list, &completions);
7263 }
7264 spin_unlock_irq(&phba->hbalock);
7265
James Smarta257bf92009-04-06 18:48:10 -04007266 /* Cancel all the IOCBs from the completions list */
7267 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7268 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007269}
7270
James Smarte59058c2008-08-24 21:49:00 -04007271/**
James Smart3621a712009-04-06 18:47:14 -04007272 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007273 * @ndlp: pointer to a node-list data structure.
7274 *
7275 * This routine aborts all the IOCBs associated with an @ndlp from the
7276 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7277 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7278 * list, removes each IOCB associated with the @ndlp off the list, set the
7279 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7280 * associated with the IOCB.
7281 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007282void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7283{
7284 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007285 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007286 struct lpfc_iocbq *tmp_iocb, *piocb;
7287 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007288
7289 spin_lock_irq(&phba->hbalock);
7290 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7291 list) {
7292 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7293
7294 list_move_tail(&piocb->list, &completions);
7295 }
7296 }
7297 spin_unlock_irq(&phba->hbalock);
7298
James Smarta257bf92009-04-06 18:48:10 -04007299 /* Cancel all the IOCBs from the completions list */
7300 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7301 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007302}
7303
James Smarte59058c2008-08-24 21:49:00 -04007304/**
James Smart3621a712009-04-06 18:47:14 -04007305 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007306 * @phba: pointer to lpfc hba data structure.
7307 *
7308 * This routine aborts all the IOCBs currently on the driver internal
7309 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7310 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7311 * list, removes IOCBs off the list, set the status feild to
7312 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7313 * the IOCB.
7314 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007315void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7316{
7317 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007318
7319 spin_lock_irq(&phba->hbalock);
7320 list_splice_init(&phba->fabric_iocb_list, &completions);
7321 spin_unlock_irq(&phba->hbalock);
7322
James Smarta257bf92009-04-06 18:48:10 -04007323 /* Cancel all the IOCBs from the completions list */
7324 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7325 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007326}
James Smart6fb120a2009-05-22 14:52:59 -04007327
7328/**
7329 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7330 * @phba: pointer to lpfc hba data structure.
7331 * @axri: pointer to the els xri abort wcqe structure.
7332 *
7333 * This routine is invoked by the worker thread to process a SLI4 slow-path
7334 * ELS aborted xri.
7335 **/
7336void
7337lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7338 struct sli4_wcqe_xri_aborted *axri)
7339{
7340 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7341 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7342 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04007343 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007344
James Smart0f65ff62010-02-26 14:14:23 -05007345 spin_lock_irqsave(&phba->hbalock, iflag);
7346 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007347 list_for_each_entry_safe(sglq_entry, sglq_next,
7348 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7349 if (sglq_entry->sli4_xritag == xri) {
7350 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007351 list_add_tail(&sglq_entry->list,
7352 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007353 sglq_entry->state = SGL_FREED;
7354 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007355 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04007356
7357 /* Check if TXQ queue needs to be serviced */
7358 if (pring->txq_cnt)
7359 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007360 return;
7361 }
7362 }
James Smart0f65ff62010-02-26 14:14:23 -05007363 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7364 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7365 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7366 spin_unlock_irqrestore(&phba->hbalock, iflag);
7367 return;
7368 }
7369 sglq_entry->state = SGL_XRI_ABORTED;
7370 spin_unlock_irqrestore(&phba->hbalock, iflag);
7371 return;
James Smart6fb120a2009-05-22 14:52:59 -04007372}