blob: 8c5c3aea4a1921693bba59a94dbca2d326fb8a54 [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 Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 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>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
James Smartea2151b2008-09-07 11:52:10 -040033#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_disc.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050039#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050040#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050041
42static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
43 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050044static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
45 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010046static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
47static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
48 struct lpfc_nodelist *ndlp, uint8_t retry);
49static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
50 struct lpfc_iocbq *iocb);
51static void lpfc_register_new_vport(struct lpfc_hba *phba,
52 struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp);
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 **/
dea31012005-04-17 16:05:31 -0500147static struct 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
dea31012005-04-17 16:05:31 -0500169 icmd = &elsiocb->iocb;
170
171 /* fill in BDEs for command */
172 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400173 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
174 if (pcmd)
175 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500176 if (!pcmd || !pcmd->virt)
177 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500178
179 INIT_LIST_HEAD(&pcmd->list);
180
181 /* Allocate buffer for response payload */
182 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500183 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500184 if (prsp)
185 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
186 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500187 if (!prsp || !prsp->virt)
188 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500189 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500190 } else
dea31012005-04-17 16:05:31 -0500191 prsp = NULL;
dea31012005-04-17 16:05:31 -0500192
193 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500194 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500195 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500196 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
197 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500198 if (!pbuflist || !pbuflist->virt)
199 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500200
201 INIT_LIST_HEAD(&pbuflist->list);
202
203 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
204 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400205 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500206 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500207 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500208 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500209 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400210 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500211 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500212 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500213 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
214 }
dea31012005-04-17 16:05:31 -0500215 icmd->ulpBdeCount = 1;
216 icmd->ulpLe = 1;
217 icmd->ulpClass = CLASS3;
218
James Smart92d7f7b2007-06-17 19:56:38 -0500219 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
220 icmd->un.elsreq64.myID = vport->fc_myDID;
221
222 /* For ELS_REQUEST64_CR, use the VPI by default */
223 icmd->ulpContext = vport->vpi;
224 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500225 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
226 if (elscmd == ELS_CMD_ECHO)
227 icmd->ulpCt_l = 0; /* context = invalid RPI */
228 else
229 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500230 }
231
dea31012005-04-17 16:05:31 -0500232 bpl = (struct ulp_bde64 *) pbuflist->virt;
233 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
234 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
235 bpl->tus.f.bdeSize = cmdSize;
236 bpl->tus.f.bdeFlags = 0;
237 bpl->tus.w = le32_to_cpu(bpl->tus.w);
238
239 if (expectRsp) {
240 bpl++;
241 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
242 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
243 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400244 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500245 bpl->tus.w = le32_to_cpu(bpl->tus.w);
246 }
247
James Smartfa4066b2008-01-11 01:53:27 -0500248 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400249 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500250 if (!elsiocb->context1)
251 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400252 elsiocb->context2 = pcmd;
253 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500254 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500255 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500256 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
257
258 if (prsp) {
259 list_add(&prsp->list, &pcmd->list);
260 }
dea31012005-04-17 16:05:31 -0500261 if (expectRsp) {
262 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400263 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
264 "0116 Xmit ELS command x%x to remote "
265 "NPORT x%x I/O tag: x%x, port state: x%x\n",
266 elscmd, did, elsiocb->iotag,
267 vport->port_state);
dea31012005-04-17 16:05:31 -0500268 } else {
269 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400270 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
271 "0117 Xmit ELS response x%x to remote "
272 "NPORT x%x I/O tag: x%x, size: x%x\n",
273 elscmd, ndlp->nlp_DID, elsiocb->iotag,
274 cmdSize);
dea31012005-04-17 16:05:31 -0500275 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500276 return elsiocb;
dea31012005-04-17 16:05:31 -0500277
James Smartfa4066b2008-01-11 01:53:27 -0500278els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500279 if (expectRsp)
280 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500281 kfree(pbuflist);
282
283els_iocb_free_prsp_exit:
284 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
285 kfree(prsp);
286
287els_iocb_free_pcmb_exit:
288 kfree(pcmd);
289 lpfc_sli_release_iocbq(phba, elsiocb);
290 return NULL;
291}
dea31012005-04-17 16:05:31 -0500292
James Smarte59058c2008-08-24 21:49:00 -0400293/**
James Smart3621a712009-04-06 18:47:14 -0400294 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400295 * @vport: pointer to a host virtual N_Port data structure.
296 *
297 * This routine issues a fabric registration login for a @vport. An
298 * active ndlp node with Fabric_DID must already exist for this @vport.
299 * The routine invokes two mailbox commands to carry out fabric registration
300 * login through the HBA firmware: the first mailbox command requests the
301 * HBA to perform link configuration for the @vport; and the second mailbox
302 * command requests the HBA to perform the actual fabric registration login
303 * with the @vport.
304 *
305 * Return code
306 * 0 - successfully issued fabric registration login for @vport
307 * -ENXIO -- failed to issue fabric registration login for @vport
308 **/
James Smart3772a992009-05-22 14:50:54 -0400309int
James Smart92d7f7b2007-06-17 19:56:38 -0500310lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
311{
312 struct lpfc_hba *phba = vport->phba;
313 LPFC_MBOXQ_t *mbox;
314 struct lpfc_dmabuf *mp;
315 struct lpfc_nodelist *ndlp;
316 struct serv_parm *sp;
317 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400318 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500319
320 sp = &phba->fc_fabparam;
321 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500322 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400323 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500324 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400325 }
James Smart92d7f7b2007-06-17 19:56:38 -0500326
327 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400328 if (!mbox) {
329 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500330 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400331 }
James Smart92d7f7b2007-06-17 19:56:38 -0500332
333 vport->port_state = LPFC_FABRIC_CFG_LINK;
334 lpfc_config_link(phba, mbox);
335 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
336 mbox->vport = vport;
337
James Smart0b727fe2007-10-27 13:37:25 -0400338 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400339 if (rc == MBX_NOT_FINISHED) {
340 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500341 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400342 }
James Smart92d7f7b2007-06-17 19:56:38 -0500343
344 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400345 if (!mbox) {
346 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500347 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400348 }
James Smart3772a992009-05-22 14:50:54 -0400349 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400350 if (rc) {
351 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500352 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400353 }
James Smart92d7f7b2007-06-17 19:56:38 -0500354
355 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
356 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500357 /* increment the reference count on ndlp to hold reference
358 * for the callback routine.
359 */
James Smart92d7f7b2007-06-17 19:56:38 -0500360 mbox->context2 = lpfc_nlp_get(ndlp);
361
James Smart0b727fe2007-10-27 13:37:25 -0400362 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400363 if (rc == MBX_NOT_FINISHED) {
364 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500365 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400366 }
James Smart92d7f7b2007-06-17 19:56:38 -0500367
368 return 0;
369
370fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500371 /* decrement the reference count on ndlp just incremented
372 * for the failed mbox command.
373 */
James Smart92d7f7b2007-06-17 19:56:38 -0500374 lpfc_nlp_put(ndlp);
375 mp = (struct lpfc_dmabuf *) mbox->context1;
376 lpfc_mbuf_free(phba, mp->virt, mp->phys);
377 kfree(mp);
378fail_free_mbox:
379 mempool_free(mbox, phba->mbox_mem_pool);
380
381fail:
382 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400383 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400384 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500385 return -ENXIO;
386}
387
James Smarte59058c2008-08-24 21:49:00 -0400388/**
James Smart3621a712009-04-06 18:47:14 -0400389 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400390 * @vport: pointer to a host virtual N_Port data structure.
391 * @ndlp: pointer to a node-list data structure.
392 * @sp: pointer to service parameter data structure.
393 * @irsp: pointer to the IOCB within the lpfc response IOCB.
394 *
395 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
396 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
397 * port in a fabric topology. It properly sets up the parameters to the @ndlp
398 * from the IOCB response. It also check the newly assigned N_Port ID to the
399 * @vport against the previously assigned N_Port ID. If it is different from
400 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
401 * is invoked on all the remaining nodes with the @vport to unregister the
402 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
403 * is invoked to register login to the fabric.
404 *
405 * Return code
406 * 0 - Success (currently, always return 0)
407 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500408static int
James Smart2e0fef82007-06-17 19:56:36 -0500409lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
410 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500411{
James Smart2e0fef82007-06-17 19:56:36 -0500412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
413 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500414 struct lpfc_nodelist *np;
415 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500416
James Smart2e0fef82007-06-17 19:56:36 -0500417 spin_lock_irq(shost->host_lock);
418 vport->fc_flag |= FC_FABRIC;
419 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500420
421 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
422 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
423 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
424
425 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
426
427 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500428 spin_lock_irq(shost->host_lock);
429 vport->fc_flag |= FC_PUBLIC_LOOP;
430 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500431 } else {
432 /*
433 * If we are a N-port connected to a Fabric, fixup sparam's so
434 * logins to devices on remote loops work.
435 */
James Smart2e0fef82007-06-17 19:56:36 -0500436 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500437 }
438
James Smart2e0fef82007-06-17 19:56:36 -0500439 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500440 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500441 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500442 ndlp->nlp_class_sup = 0;
443 if (sp->cls1.classValid)
444 ndlp->nlp_class_sup |= FC_COS_CLASS1;
445 if (sp->cls2.classValid)
446 ndlp->nlp_class_sup |= FC_COS_CLASS2;
447 if (sp->cls3.classValid)
448 ndlp->nlp_class_sup |= FC_COS_CLASS3;
449 if (sp->cls4.classValid)
450 ndlp->nlp_class_sup |= FC_COS_CLASS4;
451 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
452 sp->cmn.bbRcvSizeLsb;
453 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
454
James Smart92d7f7b2007-06-17 19:56:38 -0500455 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
456 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400457 lpfc_printf_vlog(vport, KERN_WARNING,
458 LOG_ELS | LOG_VPORT,
459 "1816 FLOGI NPIV supported, "
460 "response data 0x%x\n",
461 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500462 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500463 } else {
464 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400465 to call reg_vnpid atleast for the physcial host */
466 lpfc_printf_vlog(vport, KERN_WARNING,
467 LOG_ELS | LOG_VPORT,
468 "1817 Fabric does not support NPIV "
469 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500470 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
471 }
472 }
473
474 if ((vport->fc_prevDID != vport->fc_myDID) &&
475 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
476
477 /* If our NportID changed, we need to ensure all
478 * remaining NPORTs get unreg_login'ed.
479 */
480 list_for_each_entry_safe(np, next_np,
481 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400482 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500483 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500484 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
485 !(np->nlp_flag & NLP_NPR_ADISC))
486 continue;
487 spin_lock_irq(shost->host_lock);
488 np->nlp_flag &= ~NLP_NPR_ADISC;
489 spin_unlock_irq(shost->host_lock);
490 lpfc_unreg_rpi(vport, np);
491 }
492 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
493 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500494 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500495 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500496 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500497 }
498 }
499
James Smart92d7f7b2007-06-17 19:56:38 -0500500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500501
James Smart92d7f7b2007-06-17 19:56:38 -0500502 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
503 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
504 lpfc_register_new_vport(phba, vport, ndlp);
505 return 0;
506 }
507 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500508 return 0;
dea31012005-04-17 16:05:31 -0500509}
510
James Smarte59058c2008-08-24 21:49:00 -0400511/**
James Smart3621a712009-04-06 18:47:14 -0400512 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400513 * @vport: pointer to a host virtual N_Port data structure.
514 * @ndlp: pointer to a node-list data structure.
515 * @sp: pointer to service parameter data structure.
516 *
517 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
518 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
519 * in a point-to-point topology. First, the @vport's N_Port Name is compared
520 * with the received N_Port Name: if the @vport's N_Port Name is greater than
521 * the received N_Port Name lexicographically, this node shall assign local
522 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
523 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
524 * this node shall just wait for the remote node to issue PLOGI and assign
525 * N_Port IDs.
526 *
527 * Return code
528 * 0 - Success
529 * -ENXIO - Fail
530 **/
dea31012005-04-17 16:05:31 -0500531static int
James Smart2e0fef82007-06-17 19:56:36 -0500532lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
533 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500534{
James Smart2e0fef82007-06-17 19:56:36 -0500535 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
536 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500537 LPFC_MBOXQ_t *mbox;
538 int rc;
539
James Smart2e0fef82007-06-17 19:56:36 -0500540 spin_lock_irq(shost->host_lock);
541 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
542 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500543
544 phba->fc_edtov = FF_DEF_EDTOV;
545 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500546 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500547 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500548 if (rc >= 0) {
549 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500550 spin_lock_irq(shost->host_lock);
551 vport->fc_flag |= FC_PT2PT_PLOGI;
552 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500553
554 /*
555 * N_Port ID cannot be 0, set our to LocalID the other
556 * side will be RemoteID.
557 */
558
559 /* not equal */
560 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500561 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500562
563 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
564 if (!mbox)
565 goto fail;
566
567 lpfc_config_link(phba, mbox);
568
569 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500570 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400571 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500572 if (rc == MBX_NOT_FINISHED) {
573 mempool_free(mbox, phba->mbox_mem_pool);
574 goto fail;
575 }
James Smarte47c9092008-02-08 18:49:26 -0500576 /* Decrement ndlp reference count indicating that ndlp can be
577 * safely released when other references to it are done.
578 */
James Smart329f9bc2007-04-25 09:53:01 -0400579 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500580
James Smart2e0fef82007-06-17 19:56:36 -0500581 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500582 if (!ndlp) {
583 /*
584 * Cannot find existing Fabric ndlp, so allocate a
585 * new one
586 */
587 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
588 if (!ndlp)
589 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500590 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500591 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
592 ndlp = lpfc_enable_node(vport, ndlp,
593 NLP_STE_UNUSED_NODE);
594 if(!ndlp)
595 goto fail;
dea31012005-04-17 16:05:31 -0500596 }
597
598 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500599 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500600 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500601 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500602 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500603 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
604 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500605 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500606 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500607 } else
608 /* This side will wait for the PLOGI, decrement ndlp reference
609 * count indicating that ndlp can be released when other
610 * references to it are done.
611 */
James Smart329f9bc2007-04-25 09:53:01 -0400612 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500613
James Smart09372822008-01-11 01:52:54 -0500614 /* If we are pt2pt with another NPort, force NPIV off! */
615 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
616
James Smart2e0fef82007-06-17 19:56:36 -0500617 spin_lock_irq(shost->host_lock);
618 vport->fc_flag |= FC_PT2PT;
619 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500620
621 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500622 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500623 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500624fail:
dea31012005-04-17 16:05:31 -0500625 return -ENXIO;
626}
627
James Smarte59058c2008-08-24 21:49:00 -0400628/**
James Smart3621a712009-04-06 18:47:14 -0400629 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400630 * @phba: pointer to lpfc hba data structure.
631 * @cmdiocb: pointer to lpfc command iocb data structure.
632 * @rspiocb: pointer to lpfc response iocb data structure.
633 *
634 * This routine is the top-level completion callback function for issuing
635 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
636 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
637 * retry has been made (either immediately or delayed with lpfc_els_retry()
638 * returning 1), the command IOCB will be released and function returned.
639 * If the retry attempt has been given up (possibly reach the maximum
640 * number of retries), one additional decrement of ndlp reference shall be
641 * invoked before going out after releasing the command IOCB. This will
642 * actually release the remote node (Note, lpfc_els_free_iocb() will also
643 * invoke one decrement of ndlp reference count). If no error reported in
644 * the IOCB status, the command Port ID field is used to determine whether
645 * this is a point-to-point topology or a fabric topology: if the Port ID
646 * field is assigned, it is a fabric topology; otherwise, it is a
647 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
648 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
649 * specific topology completion conditions.
650 **/
dea31012005-04-17 16:05:31 -0500651static void
James Smart329f9bc2007-04-25 09:53:01 -0400652lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
653 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500654{
James Smart2e0fef82007-06-17 19:56:36 -0500655 struct lpfc_vport *vport = cmdiocb->vport;
656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500657 IOCB_t *irsp = &rspiocb->iocb;
658 struct lpfc_nodelist *ndlp = cmdiocb->context1;
659 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
660 struct serv_parm *sp;
661 int rc;
662
663 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500664 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500665 /* One additional decrement on node reference count to
666 * trigger the release of the node
667 */
James Smart329f9bc2007-04-25 09:53:01 -0400668 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500669 goto out;
670 }
671
James Smart858c9f62007-06-17 19:56:39 -0500672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
673 "FLOGI cmpl: status:x%x/x%x state:x%x",
674 irsp->ulpStatus, irsp->un.ulpWord[4],
675 vport->port_state);
676
dea31012005-04-17 16:05:31 -0500677 if (irsp->ulpStatus) {
678 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500679 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500680 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500681
dea31012005-04-17 16:05:31 -0500682 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500683 spin_lock_irq(shost->host_lock);
684 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
685 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500686
James Smart329f9bc2007-04-25 09:53:01 -0400687 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500688 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
689 * alpa map would take too long otherwise.
690 */
691 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400692 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500693 }
694
695 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400696 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
697 "0100 FLOGI failure Data: x%x x%x "
698 "x%x\n",
699 irsp->ulpStatus, irsp->un.ulpWord[4],
700 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500701 goto flogifail;
702 }
703
704 /*
705 * The FLogI succeeded. Sync the data for the CPU before
706 * accessing it.
707 */
708 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
709
710 sp = prsp->virt + sizeof(uint32_t);
711
712 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
714 "0101 FLOGI completes sucessfully "
715 "Data: x%x x%x x%x x%x\n",
716 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
717 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500718
James Smart2e0fef82007-06-17 19:56:36 -0500719 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500720 /*
721 * If Common Service Parameters indicate Nport
722 * we are point to point, if Fport we are Fabric.
723 */
724 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500725 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500726 else
James Smart2e0fef82007-06-17 19:56:36 -0500727 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500728
729 if (!rc)
730 goto out;
731 }
732
733flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400734 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500735
James Smart858c9f62007-06-17 19:56:39 -0500736 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500737 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500738 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500739
740 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500741 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400742 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
743 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
744 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
745 (phba->link_state != LPFC_CLEAR_LA)) {
746 /* If FLOGI failed enable link interrupt. */
747 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500748 }
dea31012005-04-17 16:05:31 -0500749out:
750 lpfc_els_free_iocb(phba, cmdiocb);
751}
752
James Smarte59058c2008-08-24 21:49:00 -0400753/**
James Smart3621a712009-04-06 18:47:14 -0400754 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400755 * @vport: pointer to a host virtual N_Port data structure.
756 * @ndlp: pointer to a node-list data structure.
757 * @retry: number of retries to the command IOCB.
758 *
759 * This routine issues a Fabric Login (FLOGI) Request ELS command
760 * for a @vport. The initiator service parameters are put into the payload
761 * of the FLOGI Request IOCB and the top-level callback function pointer
762 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
763 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
764 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
765 *
766 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
767 * will be incremented by 1 for holding the ndlp and the reference to ndlp
768 * will be stored into the context1 field of the IOCB for the completion
769 * callback function to the FLOGI ELS command.
770 *
771 * Return code
772 * 0 - successfully issued flogi iocb for @vport
773 * 1 - failed to issue flogi iocb for @vport
774 **/
dea31012005-04-17 16:05:31 -0500775static int
James Smart2e0fef82007-06-17 19:56:36 -0500776lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500777 uint8_t retry)
778{
James Smart2e0fef82007-06-17 19:56:36 -0500779 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500780 struct serv_parm *sp;
781 IOCB_t *icmd;
782 struct lpfc_iocbq *elsiocb;
783 struct lpfc_sli_ring *pring;
784 uint8_t *pcmd;
785 uint16_t cmdsize;
786 uint32_t tmo;
787 int rc;
788
789 pring = &phba->sli.ring[LPFC_ELS_RING];
790
James Smart92d7f7b2007-06-17 19:56:38 -0500791 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500792 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
793 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500794
James Smart488d1462006-03-07 15:02:37 -0500795 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500796 return 1;
dea31012005-04-17 16:05:31 -0500797
798 icmd = &elsiocb->iocb;
799 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
800
801 /* For FLOGI request, remainder of payload is service parameters */
802 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500803 pcmd += sizeof(uint32_t);
804 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500805 sp = (struct serv_parm *) pcmd;
806
807 /* Setup CSPs accordingly for Fabric */
808 sp->cmn.e_d_tov = 0;
809 sp->cmn.w2.r_a_tov = 0;
810 sp->cls1.classValid = 0;
811 sp->cls2.seqDelivery = 1;
812 sp->cls3.seqDelivery = 1;
813 if (sp->cmn.fcphLow < FC_PH3)
814 sp->cmn.fcphLow = FC_PH3;
815 if (sp->cmn.fcphHigh < FC_PH3)
816 sp->cmn.fcphHigh = FC_PH3;
817
James Smart92d7f7b2007-06-17 19:56:38 -0500818 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
819 sp->cmn.request_multiple_Nport = 1;
820
821 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
822 icmd->ulpCt_h = 1;
823 icmd->ulpCt_l = 0;
824 }
825
James Smart858c9f62007-06-17 19:56:39 -0500826 if (phba->fc_topology != TOPOLOGY_LOOP) {
827 icmd->un.elsreq64.myID = 0;
828 icmd->un.elsreq64.fl = 1;
829 }
830
dea31012005-04-17 16:05:31 -0500831 tmo = phba->fc_ratov;
832 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500833 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500834 phba->fc_ratov = tmo;
835
836 phba->fc_stat.elsXmitFLOGI++;
837 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500838
839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
840 "Issue FLOGI: opt:x%x",
841 phba->sli3_options, 0, 0);
842
James Smart92d7f7b2007-06-17 19:56:38 -0500843 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500844 if (rc == IOCB_ERROR) {
845 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500846 return 1;
dea31012005-04-17 16:05:31 -0500847 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500848 return 0;
dea31012005-04-17 16:05:31 -0500849}
850
James Smarte59058c2008-08-24 21:49:00 -0400851/**
James Smart3621a712009-04-06 18:47:14 -0400852 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -0400853 * @phba: pointer to lpfc hba data structure.
854 *
855 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
856 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
857 * list and issues an abort IOCB commond on each outstanding IOCB that
858 * contains a active Fabric_DID ndlp. Note that this function is to issue
859 * the abort IOCB command on all the outstanding IOCBs, thus when this
860 * function returns, it does not guarantee all the IOCBs are actually aborted.
861 *
862 * Return code
863 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
864 **/
dea31012005-04-17 16:05:31 -0500865int
James Smart2e0fef82007-06-17 19:56:36 -0500866lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500867{
868 struct lpfc_sli_ring *pring;
869 struct lpfc_iocbq *iocb, *next_iocb;
870 struct lpfc_nodelist *ndlp;
871 IOCB_t *icmd;
872
873 /* Abort outstanding I/O on NPort <nlp_DID> */
874 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400875 "0201 Abort outstanding I/O on NPort x%x\n",
876 Fabric_DID);
dea31012005-04-17 16:05:31 -0500877
878 pring = &phba->sli.ring[LPFC_ELS_RING];
879
880 /*
881 * Check the txcmplq for an iocb that matches the nport the driver is
882 * searching for.
883 */
James Smart2e0fef82007-06-17 19:56:36 -0500884 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500885 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
886 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500887 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
888 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500889 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -0400890 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
891 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -0400892 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -0500893 }
894 }
James Smart2e0fef82007-06-17 19:56:36 -0500895 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500896
897 return 0;
898}
899
James Smarte59058c2008-08-24 21:49:00 -0400900/**
James Smart3621a712009-04-06 18:47:14 -0400901 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400902 * @vport: pointer to a host virtual N_Port data structure.
903 *
904 * This routine issues an initial Fabric Login (FLOGI) for the @vport
905 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
906 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
907 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
908 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
909 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
910 * @vport.
911 *
912 * Return code
913 * 0 - failed to issue initial flogi for @vport
914 * 1 - successfully issued initial flogi for @vport
915 **/
dea31012005-04-17 16:05:31 -0500916int
James Smart2e0fef82007-06-17 19:56:36 -0500917lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500918{
James Smart2e0fef82007-06-17 19:56:36 -0500919 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500920 struct lpfc_nodelist *ndlp;
921
James Smart98c9ea52007-10-27 13:37:33 -0400922 vport->port_state = LPFC_FLOGI;
923 lpfc_set_disctmo(vport);
924
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500925 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500926 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500927 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500928 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500929 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
930 if (!ndlp)
931 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500932 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500933 /* Put ndlp onto node list */
934 lpfc_enqueue_node(vport, ndlp);
935 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
936 /* re-setup ndlp without removing from node list */
937 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
938 if (!ndlp)
939 return 0;
dea31012005-04-17 16:05:31 -0500940 }
James Smart87af33f2007-10-27 13:37:43 -0400941
James Smarte47c9092008-02-08 18:49:26 -0500942 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -0500943 /* This decrement of reference count to node shall kick off
944 * the release of the node.
945 */
James Smart329f9bc2007-04-25 09:53:01 -0400946 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -0500947
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500948 return 1;
dea31012005-04-17 16:05:31 -0500949}
950
James Smarte59058c2008-08-24 21:49:00 -0400951/**
James Smart3621a712009-04-06 18:47:14 -0400952 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -0400953 * @vport: pointer to a host virtual N_Port data structure.
954 *
955 * This routine issues an initial Fabric Discover (FDISC) for the @vport
956 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
957 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
958 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
959 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
960 * is then invoked with the @vport and the ndlp to perform the FDISC for the
961 * @vport.
962 *
963 * Return code
964 * 0 - failed to issue initial fdisc for @vport
965 * 1 - successfully issued initial fdisc for @vport
966 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500967int
968lpfc_initial_fdisc(struct lpfc_vport *vport)
969{
970 struct lpfc_hba *phba = vport->phba;
971 struct lpfc_nodelist *ndlp;
972
973 /* First look for the Fabric ndlp */
974 ndlp = lpfc_findnode_did(vport, Fabric_DID);
975 if (!ndlp) {
976 /* Cannot find existing Fabric ndlp, so allocate a new one */
977 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
978 if (!ndlp)
979 return 0;
980 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500981 /* Put ndlp onto node list */
982 lpfc_enqueue_node(vport, ndlp);
983 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
984 /* re-setup ndlp without removing from node list */
985 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
986 if (!ndlp)
987 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500988 }
James Smarte47c9092008-02-08 18:49:26 -0500989
James Smart92d7f7b2007-06-17 19:56:38 -0500990 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500991 /* decrement node reference count to trigger the release of
992 * the node.
993 */
James Smart92d7f7b2007-06-17 19:56:38 -0500994 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500995 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500996 }
997 return 1;
998}
James Smart87af33f2007-10-27 13:37:43 -0400999
James Smarte59058c2008-08-24 21:49:00 -04001000/**
James Smart3621a712009-04-06 18:47:14 -04001001 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001002 * @vport: pointer to a host virtual N_Port data structure.
1003 *
1004 * This routine checks whether there are more remaining Port Logins
1005 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1006 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1007 * to issue ELS PLOGIs up to the configured discover threads with the
1008 * @vport (@vport->cfg_discovery_threads). The function also decrement
1009 * the @vport's num_disc_node by 1 if it is not already 0.
1010 **/
James Smart87af33f2007-10-27 13:37:43 -04001011void
James Smart2e0fef82007-06-17 19:56:36 -05001012lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001013{
1014 int sentplogi;
1015
James Smart2e0fef82007-06-17 19:56:36 -05001016 if (vport->num_disc_nodes)
1017 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001018
1019 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001020 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1021 "0232 Continue discovery with %d PLOGIs to go "
1022 "Data: x%x x%x x%x\n",
1023 vport->num_disc_nodes, vport->fc_plogi_cnt,
1024 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001025 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001026 if (vport->fc_flag & FC_NLP_MORE)
1027 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1028 sentplogi = lpfc_els_disc_plogi(vport);
1029
dea31012005-04-17 16:05:31 -05001030 return;
1031}
1032
James Smarte59058c2008-08-24 21:49:00 -04001033/**
James Smart3621a712009-04-06 18:47:14 -04001034 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001035 * @phba: pointer to lpfc hba data structure.
1036 * @prsp: pointer to response IOCB payload.
1037 * @ndlp: pointer to a node-list data structure.
1038 *
1039 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1040 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1041 * The following cases are considered N_Port confirmed:
1042 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1043 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1044 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1045 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1046 * 1) if there is a node on vport list other than the @ndlp with the same
1047 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1048 * on that node to release the RPI associated with the node; 2) if there is
1049 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1050 * into, a new node shall be allocated (or activated). In either case, the
1051 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1052 * be released and the new_ndlp shall be put on to the vport node list and
1053 * its pointer returned as the confirmed node.
1054 *
1055 * Note that before the @ndlp got "released", the keepDID from not-matching
1056 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1057 * of the @ndlp. This is because the release of @ndlp is actually to put it
1058 * into an inactive state on the vport node list and the vport node list
1059 * management algorithm does not allow two node with a same DID.
1060 *
1061 * Return code
1062 * pointer to the PLOGI N_Port @ndlp
1063 **/
James Smart488d1462006-03-07 15:02:37 -05001064static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001065lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001066 struct lpfc_nodelist *ndlp)
1067{
James Smart2e0fef82007-06-17 19:56:36 -05001068 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001069 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001070 struct lpfc_rport_data *rdata;
1071 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001072 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001073 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001074 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001075
James Smart2fb9bd82006-12-02 13:33:57 -05001076 /* Fabric nodes can have the same WWPN so we don't bother searching
1077 * by WWPN. Just return the ndlp that was given to us.
1078 */
1079 if (ndlp->nlp_type & NLP_FABRIC)
1080 return ndlp;
1081
James Smart92d7f7b2007-06-17 19:56:38 -05001082 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001083 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001084
James Smart685f0bf2007-04-25 09:53:08 -04001085 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001086 * we have for that ndlp. If not, we have some work to do.
1087 */
James Smart2e0fef82007-06-17 19:56:36 -05001088 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001089
James Smarte47c9092008-02-08 18:49:26 -05001090 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001091 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001092
1093 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001094 rc = memcmp(&ndlp->nlp_portname, name,
1095 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001096 if (!rc)
1097 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001098 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1099 if (!new_ndlp)
1100 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001101 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001102 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001103 rc = memcmp(&ndlp->nlp_portname, name,
1104 sizeof(struct lpfc_name));
1105 if (!rc)
1106 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001107 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1108 NLP_STE_UNUSED_NODE);
1109 if (!new_ndlp)
1110 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001111 keepDID = new_ndlp->nlp_DID;
1112 } else
1113 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001114
James Smart2e0fef82007-06-17 19:56:36 -05001115 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001116 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001117 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001118
1119 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1120 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1121 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1122
James Smarte47c9092008-02-08 18:49:26 -05001123 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001124 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001125
James Smart2e0fef82007-06-17 19:56:36 -05001126 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001127 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1128 /* The new_ndlp is replacing ndlp totally, so we need
1129 * to put ndlp on UNUSED list and try to free it.
1130 */
James Smart0ff10d42008-01-11 01:52:36 -05001131
1132 /* Fix up the rport accordingly */
1133 rport = ndlp->rport;
1134 if (rport) {
1135 rdata = rport->dd_data;
1136 if (rdata->pnode == ndlp) {
1137 lpfc_nlp_put(ndlp);
1138 ndlp->rport = NULL;
1139 rdata->pnode = lpfc_nlp_get(new_ndlp);
1140 new_ndlp->rport = rport;
1141 }
1142 new_ndlp->nlp_type = ndlp->nlp_type;
1143 }
James Smart58da1ff2008-04-07 10:15:56 -04001144 /* We shall actually free the ndlp with both nlp_DID and
1145 * nlp_portname fields equals 0 to avoid any ndlp on the
1146 * nodelist never to be used.
1147 */
1148 if (ndlp->nlp_DID == 0) {
1149 spin_lock_irq(&phba->ndlp_lock);
1150 NLP_SET_FREE_REQ(ndlp);
1151 spin_unlock_irq(&phba->ndlp_lock);
1152 }
James Smart0ff10d42008-01-11 01:52:36 -05001153
James Smart58da1ff2008-04-07 10:15:56 -04001154 /* Two ndlps cannot have the same did on the nodelist */
1155 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001156 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001157 }
James Smart92795652006-07-06 15:50:02 -04001158 else {
James Smart2e0fef82007-06-17 19:56:36 -05001159 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001160 /* Two ndlps cannot have the same did */
1161 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001163 }
James Smart488d1462006-03-07 15:02:37 -05001164 return new_ndlp;
1165}
1166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
James Smart3621a712009-04-06 18:47:14 -04001168 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001169 * @vport: pointer to a host virtual N_Port data structure.
1170 *
1171 * This routine checks whether more Registration State Change
1172 * Notifications (RSCNs) came in while the discovery state machine was in
1173 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1174 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1175 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1176 * handling the RSCNs.
1177 **/
James Smart87af33f2007-10-27 13:37:43 -04001178void
1179lpfc_end_rscn(struct lpfc_vport *vport)
1180{
1181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1182
1183 if (vport->fc_flag & FC_RSCN_MODE) {
1184 /*
1185 * Check to see if more RSCNs came in while we were
1186 * processing this one.
1187 */
1188 if (vport->fc_rscn_id_cnt ||
1189 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1190 lpfc_els_handle_rscn(vport);
1191 else {
1192 spin_lock_irq(shost->host_lock);
1193 vport->fc_flag &= ~FC_RSCN_MODE;
1194 spin_unlock_irq(shost->host_lock);
1195 }
1196 }
1197}
1198
James Smarte59058c2008-08-24 21:49:00 -04001199/**
James Smart3621a712009-04-06 18:47:14 -04001200 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001201 * @phba: pointer to lpfc hba data structure.
1202 * @cmdiocb: pointer to lpfc command iocb data structure.
1203 * @rspiocb: pointer to lpfc response iocb data structure.
1204 *
1205 * This routine is the completion callback function for issuing the Port
1206 * Login (PLOGI) command. For PLOGI completion, there must be an active
1207 * ndlp on the vport node list that matches the remote node ID from the
1208 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1209 * ignored and command IOCB released. The PLOGI response IOCB status is
1210 * checked for error conditons. If there is error status reported, PLOGI
1211 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1212 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1213 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1214 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1215 * there are additional N_Port nodes with the vport that need to perform
1216 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1217 * PLOGIs.
1218 **/
dea31012005-04-17 16:05:31 -05001219static void
James Smart2e0fef82007-06-17 19:56:36 -05001220lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1221 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001222{
James Smart2e0fef82007-06-17 19:56:36 -05001223 struct lpfc_vport *vport = cmdiocb->vport;
1224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001225 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001226 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001227 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001228 int disc, rc, did, type;
1229
dea31012005-04-17 16:05:31 -05001230 /* we pass cmdiocb to state machine which needs rspiocb as well */
1231 cmdiocb->context_un.rsp_iocb = rspiocb;
1232
1233 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1235 "PLOGI cmpl: status:x%x/x%x did:x%x",
1236 irsp->ulpStatus, irsp->un.ulpWord[4],
1237 irsp->un.elsreq64.remoteID);
1238
James Smart2e0fef82007-06-17 19:56:36 -05001239 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001240 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001241 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1242 "0136 PLOGI completes to NPort x%x "
1243 "with no ndlp. Data: x%x x%x x%x\n",
1244 irsp->un.elsreq64.remoteID,
1245 irsp->ulpStatus, irsp->un.ulpWord[4],
1246 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001247 goto out;
James Smarted957682007-06-17 19:56:37 -05001248 }
dea31012005-04-17 16:05:31 -05001249
1250 /* Since ndlp can be freed in the disc state machine, note if this node
1251 * is being used during discovery.
1252 */
James Smart2e0fef82007-06-17 19:56:36 -05001253 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001254 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001255 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001256 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001257 rc = 0;
1258
1259 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1261 "0102 PLOGI completes to NPort x%x "
1262 "Data: x%x x%x x%x x%x x%x\n",
1263 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1264 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001265 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001266 if (lpfc_els_chk_latt(vport)) {
1267 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001268 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001269 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001270 goto out;
1271 }
1272
1273 /* ndlp could be freed in DSM, save these values now */
1274 type = ndlp->nlp_type;
1275 did = ndlp->nlp_DID;
1276
1277 if (irsp->ulpStatus) {
1278 /* Check for retry */
1279 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1280 /* ELS command is being retried */
1281 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001282 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001283 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001284 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001285 }
1286 goto out;
1287 }
dea31012005-04-17 16:05:31 -05001288 /* PLOGI failed */
1289 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001290 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001291 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001292 else
James Smart2e0fef82007-06-17 19:56:36 -05001293 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001294 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001295 } else {
1296 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001297 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001298 cmdiocb->context2)->list.next,
1299 struct lpfc_dmabuf, list);
1300 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001301 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001302 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001303 }
1304
James Smart2e0fef82007-06-17 19:56:36 -05001305 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001306 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001307 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001308
James Smart2e0fef82007-06-17 19:56:36 -05001309 if (vport->num_disc_nodes == 0) {
1310 spin_lock_irq(shost->host_lock);
1311 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1312 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001313
James Smart2e0fef82007-06-17 19:56:36 -05001314 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001315 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001316 }
1317 }
1318
1319out:
1320 lpfc_els_free_iocb(phba, cmdiocb);
1321 return;
1322}
1323
James Smarte59058c2008-08-24 21:49:00 -04001324/**
James Smart3621a712009-04-06 18:47:14 -04001325 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001326 * @vport: pointer to a host virtual N_Port data structure.
1327 * @did: destination port identifier.
1328 * @retry: number of retries to the command IOCB.
1329 *
1330 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1331 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1332 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1333 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1334 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1335 *
1336 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1337 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1338 * will be stored into the context1 field of the IOCB for the completion
1339 * callback function to the PLOGI ELS command.
1340 *
1341 * Return code
1342 * 0 - Successfully issued a plogi for @vport
1343 * 1 - failed to issue a plogi for @vport
1344 **/
dea31012005-04-17 16:05:31 -05001345int
James Smart2e0fef82007-06-17 19:56:36 -05001346lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001347{
James Smart2e0fef82007-06-17 19:56:36 -05001348 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001349 struct serv_parm *sp;
1350 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001351 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001352 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001353 struct lpfc_sli *psli;
1354 uint8_t *pcmd;
1355 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001356 int ret;
dea31012005-04-17 16:05:31 -05001357
1358 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001359
James Smart98c9ea52007-10-27 13:37:33 -04001360 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001361 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1362 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001363
James Smarte47c9092008-02-08 18:49:26 -05001364 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001365 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001366 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001367 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001368 if (!elsiocb)
1369 return 1;
dea31012005-04-17 16:05:31 -05001370
1371 icmd = &elsiocb->iocb;
1372 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1373
1374 /* For PLOGI request, remainder of payload is service parameters */
1375 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001376 pcmd += sizeof(uint32_t);
1377 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001378 sp = (struct serv_parm *) pcmd;
1379
1380 if (sp->cmn.fcphLow < FC_PH_4_3)
1381 sp->cmn.fcphLow = FC_PH_4_3;
1382
1383 if (sp->cmn.fcphHigh < FC_PH3)
1384 sp->cmn.fcphHigh = FC_PH3;
1385
James Smart858c9f62007-06-17 19:56:39 -05001386 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1387 "Issue PLOGI: did:x%x",
1388 did, 0, 0);
1389
dea31012005-04-17 16:05:31 -05001390 phba->fc_stat.elsXmitPLOGI++;
1391 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001392 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001393
1394 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001395 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001396 return 1;
dea31012005-04-17 16:05:31 -05001397 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398 return 0;
dea31012005-04-17 16:05:31 -05001399}
1400
James Smarte59058c2008-08-24 21:49:00 -04001401/**
James Smart3621a712009-04-06 18:47:14 -04001402 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001403 * @phba: pointer to lpfc hba data structure.
1404 * @cmdiocb: pointer to lpfc command iocb data structure.
1405 * @rspiocb: pointer to lpfc response iocb data structure.
1406 *
1407 * This routine is the completion callback function for a Process Login
1408 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1409 * status. If there is error status reported, PRLI retry shall be attempted
1410 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1411 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1412 * ndlp to mark the PRLI completion.
1413 **/
dea31012005-04-17 16:05:31 -05001414static void
James Smart2e0fef82007-06-17 19:56:36 -05001415lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1416 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001417{
James Smart2e0fef82007-06-17 19:56:36 -05001418 struct lpfc_vport *vport = cmdiocb->vport;
1419 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001420 IOCB_t *irsp;
1421 struct lpfc_sli *psli;
1422 struct lpfc_nodelist *ndlp;
1423
1424 psli = &phba->sli;
1425 /* we pass cmdiocb to state machine which needs rspiocb as well */
1426 cmdiocb->context_un.rsp_iocb = rspiocb;
1427
1428 irsp = &(rspiocb->iocb);
1429 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001430 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001431 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001432 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001433
James Smart858c9f62007-06-17 19:56:39 -05001434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1435 "PRLI cmpl: status:x%x/x%x did:x%x",
1436 irsp->ulpStatus, irsp->un.ulpWord[4],
1437 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001438 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001439 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1440 "0103 PRLI completes to NPort x%x "
1441 "Data: x%x x%x x%x x%x\n",
1442 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1443 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001444
James Smart2e0fef82007-06-17 19:56:36 -05001445 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001446 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001447 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001448 goto out;
1449
1450 if (irsp->ulpStatus) {
1451 /* Check for retry */
1452 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1453 /* ELS command is being retried */
1454 goto out;
1455 }
1456 /* PRLI failed */
1457 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001458 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001459 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001460 else
James Smart2e0fef82007-06-17 19:56:36 -05001461 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001462 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001463 } else
dea31012005-04-17 16:05:31 -05001464 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001465 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001466 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001467out:
1468 lpfc_els_free_iocb(phba, cmdiocb);
1469 return;
1470}
1471
James Smarte59058c2008-08-24 21:49:00 -04001472/**
James Smart3621a712009-04-06 18:47:14 -04001473 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001474 * @vport: pointer to a host virtual N_Port data structure.
1475 * @ndlp: pointer to a node-list data structure.
1476 * @retry: number of retries to the command IOCB.
1477 *
1478 * This routine issues a Process Login (PRLI) ELS command for the
1479 * @vport. The PRLI service parameters are set up in the payload of the
1480 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1481 * is put to the IOCB completion callback func field before invoking the
1482 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1483 *
1484 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1485 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1486 * will be stored into the context1 field of the IOCB for the completion
1487 * callback function to the PRLI ELS command.
1488 *
1489 * Return code
1490 * 0 - successfully issued prli iocb command for @vport
1491 * 1 - failed to issue prli iocb command for @vport
1492 **/
dea31012005-04-17 16:05:31 -05001493int
James Smart2e0fef82007-06-17 19:56:36 -05001494lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001495 uint8_t retry)
1496{
James Smart2e0fef82007-06-17 19:56:36 -05001497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1498 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001499 PRLI *npr;
1500 IOCB_t *icmd;
1501 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001502 uint8_t *pcmd;
1503 uint16_t cmdsize;
1504
James Smart92d7f7b2007-06-17 19:56:38 -05001505 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001506 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1507 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001508 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001509 return 1;
dea31012005-04-17 16:05:31 -05001510
1511 icmd = &elsiocb->iocb;
1512 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1513
1514 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001515 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001516 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001517 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001518
1519 /* For PRLI, remainder of payload is PRLI parameter page */
1520 npr = (PRLI *) pcmd;
1521 /*
1522 * If our firmware version is 3.20 or later,
1523 * set the following bits for FC-TAPE support.
1524 */
1525 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1526 npr->ConfmComplAllowed = 1;
1527 npr->Retry = 1;
1528 npr->TaskRetryIdReq = 1;
1529 }
1530 npr->estabImagePair = 1;
1531 npr->readXferRdyDis = 1;
1532
1533 /* For FCP support */
1534 npr->prliType = PRLI_FCP_TYPE;
1535 npr->initiatorFunc = 1;
1536
James Smart858c9f62007-06-17 19:56:39 -05001537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1538 "Issue PRLI: did:x%x",
1539 ndlp->nlp_DID, 0, 0);
1540
dea31012005-04-17 16:05:31 -05001541 phba->fc_stat.elsXmitPRLI++;
1542 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001543 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001544 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001545 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001546 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1547 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001548 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001549 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001550 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001551 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001552 return 1;
dea31012005-04-17 16:05:31 -05001553 }
James Smart2e0fef82007-06-17 19:56:36 -05001554 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001555 return 0;
dea31012005-04-17 16:05:31 -05001556}
1557
James Smarte59058c2008-08-24 21:49:00 -04001558/**
James Smart3621a712009-04-06 18:47:14 -04001559 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001560 * @vport: pointer to a host virtual N_Port data structure.
1561 *
1562 * This routine performs Registration State Change Notification (RSCN)
1563 * discovery for a @vport. If the @vport's node port recovery count is not
1564 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1565 * the nodes that need recovery. If none of the PLOGI were needed through
1566 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1567 * invoked to check and handle possible more RSCN came in during the period
1568 * of processing the current ones.
1569 **/
1570static void
1571lpfc_rscn_disc(struct lpfc_vport *vport)
1572{
1573 lpfc_can_disctmo(vport);
1574
1575 /* RSCN discovery */
1576 /* go thru NPR nodes and issue ELS PLOGIs */
1577 if (vport->fc_npr_cnt)
1578 if (lpfc_els_disc_plogi(vport))
1579 return;
1580
1581 lpfc_end_rscn(vport);
1582}
1583
1584/**
James Smart3621a712009-04-06 18:47:14 -04001585 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001586 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1587 *
1588 * This function is called when the final ADISC is completed during discovery.
1589 * This function handles clearing link attention or issuing reg_vpi depending
1590 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1591 * discovery.
1592 * This function is called with no locks held.
1593 **/
1594static void
1595lpfc_adisc_done(struct lpfc_vport *vport)
1596{
1597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1598 struct lpfc_hba *phba = vport->phba;
1599
1600 /*
1601 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1602 * and continue discovery.
1603 */
1604 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1605 !(vport->fc_flag & FC_RSCN_MODE)) {
1606 lpfc_issue_reg_vpi(phba, vport);
1607 return;
1608 }
1609 /*
1610 * For SLI2, we need to set port_state to READY
1611 * and continue discovery.
1612 */
1613 if (vport->port_state < LPFC_VPORT_READY) {
1614 /* If we get here, there is nothing to ADISC */
1615 if (vport->port_type == LPFC_PHYSICAL_PORT)
1616 lpfc_issue_clear_la(phba, vport);
1617 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1618 vport->num_disc_nodes = 0;
1619 /* go thru NPR list, issue ELS PLOGIs */
1620 if (vport->fc_npr_cnt)
1621 lpfc_els_disc_plogi(vport);
1622 if (!vport->num_disc_nodes) {
1623 spin_lock_irq(shost->host_lock);
1624 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1625 spin_unlock_irq(shost->host_lock);
1626 lpfc_can_disctmo(vport);
1627 lpfc_end_rscn(vport);
1628 }
1629 }
1630 vport->port_state = LPFC_VPORT_READY;
1631 } else
1632 lpfc_rscn_disc(vport);
1633}
1634
1635/**
James Smart3621a712009-04-06 18:47:14 -04001636 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001637 * @vport: pointer to a host virtual N_Port data structure.
1638 *
1639 * This routine determines whether there are more ndlps on a @vport
1640 * node list need to have Address Discover (ADISC) issued. If so, it will
1641 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1642 * remaining nodes which need to have ADISC sent.
1643 **/
James Smart0ff10d42008-01-11 01:52:36 -05001644void
James Smart2e0fef82007-06-17 19:56:36 -05001645lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001646{
1647 int sentadisc;
1648
James Smart2e0fef82007-06-17 19:56:36 -05001649 if (vport->num_disc_nodes)
1650 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001651 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001652 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1653 "0210 Continue discovery with %d ADISCs to go "
1654 "Data: x%x x%x x%x\n",
1655 vport->num_disc_nodes, vport->fc_adisc_cnt,
1656 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001657 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001658 if (vport->fc_flag & FC_NLP_MORE) {
1659 lpfc_set_disctmo(vport);
1660 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1661 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001662 }
James Smart90160e02008-08-24 21:49:45 -04001663 if (!vport->num_disc_nodes)
1664 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001665 return;
1666}
1667
James Smarte59058c2008-08-24 21:49:00 -04001668/**
James Smart3621a712009-04-06 18:47:14 -04001669 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001670 * @phba: pointer to lpfc hba data structure.
1671 * @cmdiocb: pointer to lpfc command iocb data structure.
1672 * @rspiocb: pointer to lpfc response iocb data structure.
1673 *
1674 * This routine is the completion function for issuing the Address Discover
1675 * (ADISC) command. It first checks to see whether link went down during
1676 * the discovery process. If so, the node will be marked as node port
1677 * recovery for issuing discover IOCB by the link attention handler and
1678 * exit. Otherwise, the response status is checked. If error was reported
1679 * in the response status, the ADISC command shall be retried by invoking
1680 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1681 * the response status, the state machine is invoked to set transition
1682 * with respect to NLP_EVT_CMPL_ADISC event.
1683 **/
dea31012005-04-17 16:05:31 -05001684static void
James Smart2e0fef82007-06-17 19:56:36 -05001685lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1686 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001687{
James Smart2e0fef82007-06-17 19:56:36 -05001688 struct lpfc_vport *vport = cmdiocb->vport;
1689 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001690 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001691 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001692 int disc;
dea31012005-04-17 16:05:31 -05001693
1694 /* we pass cmdiocb to state machine which needs rspiocb as well */
1695 cmdiocb->context_un.rsp_iocb = rspiocb;
1696
1697 irsp = &(rspiocb->iocb);
1698 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001699
James Smart858c9f62007-06-17 19:56:39 -05001700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1701 "ADISC cmpl: status:x%x/x%x did:x%x",
1702 irsp->ulpStatus, irsp->un.ulpWord[4],
1703 ndlp->nlp_DID);
1704
dea31012005-04-17 16:05:31 -05001705 /* Since ndlp can be freed in the disc state machine, note if this node
1706 * is being used during discovery.
1707 */
James Smart2e0fef82007-06-17 19:56:36 -05001708 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001709 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001710 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001711 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001712 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1714 "0104 ADISC completes to NPort x%x "
1715 "Data: x%x x%x x%x x%x x%x\n",
1716 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1717 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001718 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001719 if (lpfc_els_chk_latt(vport)) {
1720 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001721 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001722 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001723 goto out;
1724 }
1725
1726 if (irsp->ulpStatus) {
1727 /* Check for retry */
1728 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1729 /* ELS command is being retried */
1730 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001731 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001732 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001733 spin_unlock_irq(shost->host_lock);
1734 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001735 }
1736 goto out;
1737 }
1738 /* ADISC failed */
1739 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001740 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001741 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001742 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001743 } else
dea31012005-04-17 16:05:31 -05001744 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001745 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001746 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001747
James Smart90160e02008-08-24 21:49:45 -04001748 /* Check to see if there are more ADISCs to be sent */
1749 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001750 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001751out:
1752 lpfc_els_free_iocb(phba, cmdiocb);
1753 return;
1754}
1755
James Smarte59058c2008-08-24 21:49:00 -04001756/**
James Smart3621a712009-04-06 18:47:14 -04001757 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001758 * @vport: pointer to a virtual N_Port data structure.
1759 * @ndlp: pointer to a node-list data structure.
1760 * @retry: number of retries to the command IOCB.
1761 *
1762 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1763 * @vport. It prepares the payload of the ADISC ELS command, updates the
1764 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1765 * to issue the ADISC ELS command.
1766 *
1767 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1768 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1769 * will be stored into the context1 field of the IOCB for the completion
1770 * callback function to the ADISC ELS command.
1771 *
1772 * Return code
1773 * 0 - successfully issued adisc
1774 * 1 - failed to issue adisc
1775 **/
dea31012005-04-17 16:05:31 -05001776int
James Smart2e0fef82007-06-17 19:56:36 -05001777lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001778 uint8_t retry)
1779{
James Smart2e0fef82007-06-17 19:56:36 -05001780 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1781 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001782 ADISC *ap;
1783 IOCB_t *icmd;
1784 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001785 uint8_t *pcmd;
1786 uint16_t cmdsize;
1787
James Smart92d7f7b2007-06-17 19:56:38 -05001788 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001789 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1790 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001791 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001792 return 1;
dea31012005-04-17 16:05:31 -05001793
1794 icmd = &elsiocb->iocb;
1795 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1796
1797 /* For ADISC request, remainder of payload is service parameters */
1798 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001799 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001800
1801 /* Fill in ADISC payload */
1802 ap = (ADISC *) pcmd;
1803 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001804 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1805 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001806 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001807
James Smart858c9f62007-06-17 19:56:39 -05001808 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1809 "Issue ADISC: did:x%x",
1810 ndlp->nlp_DID, 0, 0);
1811
dea31012005-04-17 16:05:31 -05001812 phba->fc_stat.elsXmitADISC++;
1813 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001814 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001815 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001816 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001817 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1818 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001820 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001821 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001822 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001823 return 1;
dea31012005-04-17 16:05:31 -05001824 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001825 return 0;
dea31012005-04-17 16:05:31 -05001826}
1827
James Smarte59058c2008-08-24 21:49:00 -04001828/**
James Smart3621a712009-04-06 18:47:14 -04001829 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04001830 * @phba: pointer to lpfc hba data structure.
1831 * @cmdiocb: pointer to lpfc command iocb data structure.
1832 * @rspiocb: pointer to lpfc response iocb data structure.
1833 *
1834 * This routine is the completion function for issuing the ELS Logout (LOGO)
1835 * command. If no error status was reported from the LOGO response, the
1836 * state machine of the associated ndlp shall be invoked for transition with
1837 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1838 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1839 **/
dea31012005-04-17 16:05:31 -05001840static void
James Smart2e0fef82007-06-17 19:56:36 -05001841lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1842 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001843{
James Smart2e0fef82007-06-17 19:56:36 -05001844 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1845 struct lpfc_vport *vport = ndlp->vport;
1846 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001847 IOCB_t *irsp;
1848 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001849
1850 psli = &phba->sli;
1851 /* we pass cmdiocb to state machine which needs rspiocb as well */
1852 cmdiocb->context_un.rsp_iocb = rspiocb;
1853
1854 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001855 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001856 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001857 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001858
James Smart858c9f62007-06-17 19:56:39 -05001859 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1860 "LOGO cmpl: status:x%x/x%x did:x%x",
1861 irsp->ulpStatus, irsp->un.ulpWord[4],
1862 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001863 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001864 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1865 "0105 LOGO completes to NPort x%x "
1866 "Data: x%x x%x x%x x%x\n",
1867 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1868 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001869 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001870 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001871 goto out;
1872
James Smart92d7f7b2007-06-17 19:56:38 -05001873 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1874 /* NLP_EVT_DEVICE_RM should unregister the RPI
1875 * which should abort all outstanding IOs.
1876 */
1877 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1878 NLP_EVT_DEVICE_RM);
1879 goto out;
1880 }
1881
dea31012005-04-17 16:05:31 -05001882 if (irsp->ulpStatus) {
1883 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001884 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001885 /* ELS command is being retried */
1886 goto out;
dea31012005-04-17 16:05:31 -05001887 /* LOGO failed */
1888 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001889 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001890 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001891 else
James Smart2e0fef82007-06-17 19:56:36 -05001892 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001893 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05001894 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001895 /* Good status, call state machine.
1896 * This will unregister the rpi if needed.
1897 */
James Smart2e0fef82007-06-17 19:56:36 -05001898 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001899 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001900out:
1901 lpfc_els_free_iocb(phba, cmdiocb);
1902 return;
1903}
1904
James Smarte59058c2008-08-24 21:49:00 -04001905/**
James Smart3621a712009-04-06 18:47:14 -04001906 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001907 * @vport: pointer to a virtual N_Port data structure.
1908 * @ndlp: pointer to a node-list data structure.
1909 * @retry: number of retries to the command IOCB.
1910 *
1911 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1912 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1913 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1914 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1915 *
1916 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1917 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1918 * will be stored into the context1 field of the IOCB for the completion
1919 * callback function to the LOGO ELS command.
1920 *
1921 * Return code
1922 * 0 - successfully issued logo
1923 * 1 - failed to issue logo
1924 **/
dea31012005-04-17 16:05:31 -05001925int
James Smart2e0fef82007-06-17 19:56:36 -05001926lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001927 uint8_t retry)
1928{
James Smart2e0fef82007-06-17 19:56:36 -05001929 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1930 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001931 IOCB_t *icmd;
1932 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001933 uint8_t *pcmd;
1934 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001935 int rc;
dea31012005-04-17 16:05:31 -05001936
James Smart98c9ea52007-10-27 13:37:33 -04001937 spin_lock_irq(shost->host_lock);
1938 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1939 spin_unlock_irq(shost->host_lock);
1940 return 0;
1941 }
1942 spin_unlock_irq(shost->host_lock);
1943
James Smart92d7f7b2007-06-17 19:56:38 -05001944 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001945 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1946 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001947 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001948 return 1;
dea31012005-04-17 16:05:31 -05001949
1950 icmd = &elsiocb->iocb;
1951 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1952 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001953 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001954
1955 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001956 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001957 pcmd += sizeof(uint32_t);
1958 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001959
James Smart858c9f62007-06-17 19:56:39 -05001960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1961 "Issue LOGO: did:x%x",
1962 ndlp->nlp_DID, 0, 0);
1963
dea31012005-04-17 16:05:31 -05001964 phba->fc_stat.elsXmitLOGO++;
1965 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001966 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001967 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001968 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001969 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001970
1971 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001972 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001973 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001974 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001975 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001976 return 1;
dea31012005-04-17 16:05:31 -05001977 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001978 return 0;
dea31012005-04-17 16:05:31 -05001979}
1980
James Smarte59058c2008-08-24 21:49:00 -04001981/**
James Smart3621a712009-04-06 18:47:14 -04001982 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04001983 * @phba: pointer to lpfc hba data structure.
1984 * @cmdiocb: pointer to lpfc command iocb data structure.
1985 * @rspiocb: pointer to lpfc response iocb data structure.
1986 *
1987 * This routine is a generic completion callback function for ELS commands.
1988 * Specifically, it is the callback function which does not need to perform
1989 * any command specific operations. It is currently used by the ELS command
1990 * issuing routines for the ELS State Change Request (SCR),
1991 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
1992 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
1993 * certain debug loggings, this callback function simply invokes the
1994 * lpfc_els_chk_latt() routine to check whether link went down during the
1995 * discovery process.
1996 **/
dea31012005-04-17 16:05:31 -05001997static void
James Smart2e0fef82007-06-17 19:56:36 -05001998lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1999 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002000{
James Smart2e0fef82007-06-17 19:56:36 -05002001 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002002 IOCB_t *irsp;
2003
2004 irsp = &rspiocb->iocb;
2005
James Smart858c9f62007-06-17 19:56:39 -05002006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2007 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2008 irsp->ulpStatus, irsp->un.ulpWord[4],
2009 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002010 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002011 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2012 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2013 irsp->ulpIoTag, irsp->ulpStatus,
2014 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002015 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002016 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002017 lpfc_els_free_iocb(phba, cmdiocb);
2018 return;
2019}
2020
James Smarte59058c2008-08-24 21:49:00 -04002021/**
James Smart3621a712009-04-06 18:47:14 -04002022 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002023 * @vport: pointer to a host virtual N_Port data structure.
2024 * @nportid: N_Port identifier to the remote node.
2025 * @retry: number of retries to the command IOCB.
2026 *
2027 * This routine issues a State Change Request (SCR) to a fabric node
2028 * on a @vport. The remote node @nportid is passed into the function. It
2029 * first search the @vport node list to find the matching ndlp. If no such
2030 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2031 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2032 * routine is invoked to send the SCR IOCB.
2033 *
2034 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2035 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2036 * will be stored into the context1 field of the IOCB for the completion
2037 * callback function to the SCR ELS command.
2038 *
2039 * Return code
2040 * 0 - Successfully issued scr command
2041 * 1 - Failed to issue scr command
2042 **/
dea31012005-04-17 16:05:31 -05002043int
James Smart2e0fef82007-06-17 19:56:36 -05002044lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002045{
James Smart2e0fef82007-06-17 19:56:36 -05002046 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002047 IOCB_t *icmd;
2048 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002049 struct lpfc_sli *psli;
2050 uint8_t *pcmd;
2051 uint16_t cmdsize;
2052 struct lpfc_nodelist *ndlp;
2053
2054 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002055 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002056
James Smarte47c9092008-02-08 18:49:26 -05002057 ndlp = lpfc_findnode_did(vport, nportid);
2058 if (!ndlp) {
2059 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2060 if (!ndlp)
2061 return 1;
2062 lpfc_nlp_init(vport, ndlp, nportid);
2063 lpfc_enqueue_node(vport, ndlp);
2064 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2065 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2066 if (!ndlp)
2067 return 1;
2068 }
dea31012005-04-17 16:05:31 -05002069
James Smart2e0fef82007-06-17 19:56:36 -05002070 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2071 ndlp->nlp_DID, ELS_CMD_SCR);
2072
James Smart488d1462006-03-07 15:02:37 -05002073 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002074 /* This will trigger the release of the node just
2075 * allocated
2076 */
James Smart329f9bc2007-04-25 09:53:01 -04002077 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002078 return 1;
dea31012005-04-17 16:05:31 -05002079 }
2080
2081 icmd = &elsiocb->iocb;
2082 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2083
2084 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002085 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002086
2087 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002088 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002089 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2090
James Smart858c9f62007-06-17 19:56:39 -05002091 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2092 "Issue SCR: did:x%x",
2093 ndlp->nlp_DID, 0, 0);
2094
dea31012005-04-17 16:05:31 -05002095 phba->fc_stat.elsXmitSCR++;
2096 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002097 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2098 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002099 /* The additional lpfc_nlp_put will cause the following
2100 * lpfc_els_free_iocb routine to trigger the rlease of
2101 * the node.
2102 */
James Smart329f9bc2007-04-25 09:53:01 -04002103 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002104 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002105 return 1;
dea31012005-04-17 16:05:31 -05002106 }
James Smartfa4066b2008-01-11 01:53:27 -05002107 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2108 * trigger the release of node.
2109 */
James Smart329f9bc2007-04-25 09:53:01 -04002110 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002111 return 0;
dea31012005-04-17 16:05:31 -05002112}
2113
James Smarte59058c2008-08-24 21:49:00 -04002114/**
James Smart3621a712009-04-06 18:47:14 -04002115 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002116 * @vport: pointer to a host virtual N_Port data structure.
2117 * @nportid: N_Port identifier to the remote node.
2118 * @retry: number of retries to the command IOCB.
2119 *
2120 * This routine issues a Fibre Channel Address Resolution Response
2121 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2122 * is passed into the function. It first search the @vport node list to find
2123 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2124 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2125 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2126 *
2127 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2128 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2129 * will be stored into the context1 field of the IOCB for the completion
2130 * callback function to the PARPR ELS command.
2131 *
2132 * Return code
2133 * 0 - Successfully issued farpr command
2134 * 1 - Failed to issue farpr command
2135 **/
dea31012005-04-17 16:05:31 -05002136static int
James Smart2e0fef82007-06-17 19:56:36 -05002137lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002138{
James Smart2e0fef82007-06-17 19:56:36 -05002139 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002140 IOCB_t *icmd;
2141 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002142 struct lpfc_sli *psli;
2143 FARP *fp;
2144 uint8_t *pcmd;
2145 uint32_t *lp;
2146 uint16_t cmdsize;
2147 struct lpfc_nodelist *ondlp;
2148 struct lpfc_nodelist *ndlp;
2149
2150 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002151 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002152
James Smarte47c9092008-02-08 18:49:26 -05002153 ndlp = lpfc_findnode_did(vport, nportid);
2154 if (!ndlp) {
2155 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2156 if (!ndlp)
2157 return 1;
2158 lpfc_nlp_init(vport, ndlp, nportid);
2159 lpfc_enqueue_node(vport, ndlp);
2160 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2161 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2162 if (!ndlp)
2163 return 1;
2164 }
James Smart2e0fef82007-06-17 19:56:36 -05002165
2166 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2167 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002168 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002169 /* This will trigger the release of the node just
2170 * allocated
2171 */
James Smart329f9bc2007-04-25 09:53:01 -04002172 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002173 return 1;
dea31012005-04-17 16:05:31 -05002174 }
2175
2176 icmd = &elsiocb->iocb;
2177 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2178
2179 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002180 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002181
2182 /* Fill in FARPR payload */
2183 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002184 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002185 lp = (uint32_t *) pcmd;
2186 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002187 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002188 fp->Rflags = 0;
2189 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2190
James Smart92d7f7b2007-06-17 19:56:38 -05002191 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2192 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002193 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002194 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002195 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002196 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002197 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002198 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002199 }
2200
James Smart858c9f62007-06-17 19:56:39 -05002201 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2202 "Issue FARPR: did:x%x",
2203 ndlp->nlp_DID, 0, 0);
2204
dea31012005-04-17 16:05:31 -05002205 phba->fc_stat.elsXmitFARPR++;
2206 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002207 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2208 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002209 /* The additional lpfc_nlp_put will cause the following
2210 * lpfc_els_free_iocb routine to trigger the release of
2211 * the node.
2212 */
James Smart329f9bc2007-04-25 09:53:01 -04002213 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002214 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002215 return 1;
dea31012005-04-17 16:05:31 -05002216 }
James Smartfa4066b2008-01-11 01:53:27 -05002217 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2218 * trigger the release of the node.
2219 */
James Smart329f9bc2007-04-25 09:53:01 -04002220 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002221 return 0;
dea31012005-04-17 16:05:31 -05002222}
2223
James Smarte59058c2008-08-24 21:49:00 -04002224/**
James Smart3621a712009-04-06 18:47:14 -04002225 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002226 * @vport: pointer to a host virtual N_Port data structure.
2227 * @nlp: pointer to a node-list data structure.
2228 *
2229 * This routine cancels the timer with a delayed IOCB-command retry for
2230 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2231 * removes the ELS retry event if it presents. In addition, if the
2232 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2233 * commands are sent for the @vport's nodes that require issuing discovery
2234 * ADISC.
2235 **/
dea31012005-04-17 16:05:31 -05002236void
James Smart2e0fef82007-06-17 19:56:36 -05002237lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002238{
James Smart2e0fef82007-06-17 19:56:36 -05002239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002240 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002241
James Smart0d2b6b82008-06-14 22:52:47 -04002242 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2243 return;
James Smart2e0fef82007-06-17 19:56:36 -05002244 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002245 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002246 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002247 del_timer_sync(&nlp->nlp_delayfunc);
2248 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002249 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002250 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002251 /* Decrement nlp reference count held for the delayed retry */
2252 evtp = &nlp->els_retry_evt;
2253 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2254 }
James Smartfdcebe22006-03-07 15:04:01 -05002255 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002256 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002257 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002258 spin_unlock_irq(shost->host_lock);
2259 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002260 if (vport->port_state < LPFC_VPORT_READY) {
2261 /* Check if there are more ADISCs to be sent */
2262 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002263 } else {
2264 /* Check if there are more PLOGIs to be sent */
2265 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002266 if (vport->num_disc_nodes == 0) {
2267 spin_lock_irq(shost->host_lock);
2268 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2269 spin_unlock_irq(shost->host_lock);
2270 lpfc_can_disctmo(vport);
2271 lpfc_end_rscn(vport);
2272 }
James Smartfdcebe22006-03-07 15:04:01 -05002273 }
2274 }
2275 }
2276 return;
2277}
2278
James Smarte59058c2008-08-24 21:49:00 -04002279/**
James Smart3621a712009-04-06 18:47:14 -04002280 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002281 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2282 *
2283 * This routine is invoked by the ndlp delayed-function timer to check
2284 * whether there is any pending ELS retry event(s) with the node. If not, it
2285 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2286 * adds the delayed events to the HBA work list and invokes the
2287 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2288 * event. Note that lpfc_nlp_get() is called before posting the event to
2289 * the work list to hold reference count of ndlp so that it guarantees the
2290 * reference to ndlp will still be available when the worker thread gets
2291 * to the event associated with the ndlp.
2292 **/
James Smartfdcebe22006-03-07 15:04:01 -05002293void
dea31012005-04-17 16:05:31 -05002294lpfc_els_retry_delay(unsigned long ptr)
2295{
James Smart2e0fef82007-06-17 19:56:36 -05002296 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2297 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002298 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002299 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002300 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002301
James Smart92d7f7b2007-06-17 19:56:38 -05002302 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002303 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002304 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002305 return;
2306 }
2307
James Smartfa4066b2008-01-11 01:53:27 -05002308 /* We need to hold the node by incrementing the reference
2309 * count until the queued work is done
2310 */
2311 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002312 if (evtp->evt_arg1) {
2313 evtp->evt = LPFC_EVT_ELS_RETRY;
2314 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002315 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002316 }
James Smart92d7f7b2007-06-17 19:56:38 -05002317 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002318 return;
2319}
2320
James Smarte59058c2008-08-24 21:49:00 -04002321/**
James Smart3621a712009-04-06 18:47:14 -04002322 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002323 * @ndlp: pointer to a node-list data structure.
2324 *
2325 * This routine is the worker-thread handler for processing the @ndlp delayed
2326 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2327 * the last ELS command from the associated ndlp and invokes the proper ELS
2328 * function according to the delayed ELS command to retry the command.
2329 **/
dea31012005-04-17 16:05:31 -05002330void
2331lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2332{
James Smart2e0fef82007-06-17 19:56:36 -05002333 struct lpfc_vport *vport = ndlp->vport;
2334 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2335 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002336
James Smart2e0fef82007-06-17 19:56:36 -05002337 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002338 did = ndlp->nlp_DID;
2339 cmd = ndlp->nlp_last_elscmd;
2340 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002341
2342 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002343 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002344 return;
2345 }
2346
2347 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002348 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002349 /*
2350 * If a discovery event readded nlp_delayfunc after timer
2351 * firing and before processing the timer, cancel the
2352 * nlp_delayfunc.
2353 */
2354 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002355 retry = ndlp->nlp_retry;
2356
2357 switch (cmd) {
2358 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002359 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002360 break;
2361 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002362 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002363 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002365 }
dea31012005-04-17 16:05:31 -05002366 break;
2367 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002368 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002369 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002370 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002371 }
dea31012005-04-17 16:05:31 -05002372 break;
2373 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002374 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002375 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002376 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002377 }
dea31012005-04-17 16:05:31 -05002378 break;
2379 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002380 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002381 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002382 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002383 }
dea31012005-04-17 16:05:31 -05002384 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002385 case ELS_CMD_FDISC:
2386 lpfc_issue_els_fdisc(vport, ndlp, retry);
2387 break;
dea31012005-04-17 16:05:31 -05002388 }
2389 return;
2390}
2391
James Smarte59058c2008-08-24 21:49:00 -04002392/**
James Smart3621a712009-04-06 18:47:14 -04002393 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002394 * @phba: pointer to lpfc hba data structure.
2395 * @cmdiocb: pointer to lpfc command iocb data structure.
2396 * @rspiocb: pointer to lpfc response iocb data structure.
2397 *
2398 * This routine makes a retry decision on an ELS command IOCB, which has
2399 * failed. The following ELS IOCBs use this function for retrying the command
2400 * when previously issued command responsed with error status: FLOGI, PLOGI,
2401 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2402 * returned error status, it makes the decision whether a retry shall be
2403 * issued for the command, and whether a retry shall be made immediately or
2404 * delayed. In the former case, the corresponding ELS command issuing-function
2405 * is called to retry the command. In the later case, the ELS command shall
2406 * be posted to the ndlp delayed event and delayed function timer set to the
2407 * ndlp for the delayed command issusing.
2408 *
2409 * Return code
2410 * 0 - No retry of els command is made
2411 * 1 - Immediate or delayed retry of els command is made
2412 **/
dea31012005-04-17 16:05:31 -05002413static int
James Smart2e0fef82007-06-17 19:56:36 -05002414lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2415 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002416{
James Smart2e0fef82007-06-17 19:56:36 -05002417 struct lpfc_vport *vport = cmdiocb->vport;
2418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2419 IOCB_t *irsp = &rspiocb->iocb;
2420 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2421 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002422 uint32_t *elscmd;
2423 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002424 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002425 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002426 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002427 uint32_t did;
dea31012005-04-17 16:05:31 -05002428
James Smart488d1462006-03-07 15:02:37 -05002429
dea31012005-04-17 16:05:31 -05002430 /* Note: context2 may be 0 for internal driver abort
2431 * of delays ELS command.
2432 */
2433
2434 if (pcmd && pcmd->virt) {
2435 elscmd = (uint32_t *) (pcmd->virt);
2436 cmd = *elscmd++;
2437 }
2438
James Smarte47c9092008-02-08 18:49:26 -05002439 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002440 did = ndlp->nlp_DID;
2441 else {
2442 /* We should only hit this case for retrying PLOGI */
2443 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002444 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002445 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2446 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002447 return 1;
2448 }
2449
James Smart858c9f62007-06-17 19:56:39 -05002450 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2451 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2452 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2453
dea31012005-04-17 16:05:31 -05002454 switch (irsp->ulpStatus) {
2455 case IOSTAT_FCP_RSP_ERROR:
2456 case IOSTAT_REMOTE_STOP:
2457 break;
2458
2459 case IOSTAT_LOCAL_REJECT:
2460 switch ((irsp->un.ulpWord[4] & 0xff)) {
2461 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002462 if (cmd == ELS_CMD_FLOGI) {
2463 if (PCI_DEVICE_ID_HORNET ==
2464 phba->pcidev->device) {
2465 phba->fc_topology = TOPOLOGY_LOOP;
2466 phba->pport->fc_myDID = 0;
2467 phba->alpa_map[0] = 0;
2468 phba->alpa_map[1] = 0;
2469 }
2470 }
James Smart2e0fef82007-06-17 19:56:36 -05002471 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002472 delay = 1000;
dea31012005-04-17 16:05:31 -05002473 retry = 1;
2474 break;
2475
James Smart92d7f7b2007-06-17 19:56:38 -05002476 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002477 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2478 "0124 Retry illegal cmd x%x "
2479 "retry:x%x delay:x%x\n",
2480 cmd, cmdiocb->retry, delay);
2481 retry = 1;
2482 /* All command's retry policy */
2483 maxretry = 8;
2484 if (cmdiocb->retry > 2)
2485 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002486 break;
2487
dea31012005-04-17 16:05:31 -05002488 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002489 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002490 retry = 1;
2491 if (cmdiocb->retry > 100)
2492 delay = 100;
2493 maxretry = 250;
2494 break;
2495
2496 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002497 delay = 100;
dea31012005-04-17 16:05:31 -05002498 retry = 1;
2499 break;
2500
James Smart858c9f62007-06-17 19:56:39 -05002501 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002502 case IOERR_INVALID_RPI:
2503 retry = 1;
2504 break;
2505 }
2506 break;
2507
2508 case IOSTAT_NPORT_RJT:
2509 case IOSTAT_FABRIC_RJT:
2510 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2511 retry = 1;
2512 break;
2513 }
2514 break;
2515
2516 case IOSTAT_NPORT_BSY:
2517 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002518 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002519 retry = 1;
2520 break;
2521
2522 case IOSTAT_LS_RJT:
2523 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2524 /* Added for Vendor specifc support
2525 * Just keep retrying for these Rsn / Exp codes
2526 */
2527 switch (stat.un.b.lsRjtRsnCode) {
2528 case LSRJT_UNABLE_TPC:
2529 if (stat.un.b.lsRjtRsnCodeExp ==
2530 LSEXP_CMD_IN_PROGRESS) {
2531 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002532 delay = 1000;
dea31012005-04-17 16:05:31 -05002533 maxretry = 48;
2534 }
2535 retry = 1;
2536 break;
2537 }
2538 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002539 delay = 1000;
dea31012005-04-17 16:05:31 -05002540 maxretry = lpfc_max_els_tries + 1;
2541 retry = 1;
2542 break;
2543 }
James Smart92d7f7b2007-06-17 19:56:38 -05002544 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2545 (cmd == ELS_CMD_FDISC) &&
2546 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002547 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2548 "0125 FDISC Failed (x%x). "
2549 "Fabric out of resources\n",
2550 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002551 lpfc_vport_set_state(vport,
2552 FC_VPORT_NO_FABRIC_RSCS);
2553 }
dea31012005-04-17 16:05:31 -05002554 break;
2555
2556 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002557 if ((cmd == ELS_CMD_PLOGI) ||
2558 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002559 delay = 1000;
dea31012005-04-17 16:05:31 -05002560 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002561 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002562 /* FDISC retry policy */
2563 maxretry = 48;
2564 if (cmdiocb->retry >= 32)
2565 delay = 1000;
dea31012005-04-17 16:05:31 -05002566 }
2567 retry = 1;
2568 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002569
2570 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002571 /* There are some cases where switches return this
2572 * error when they are not ready and should be returning
2573 * Logical Busy. We should delay every time.
2574 */
2575 if (cmd == ELS_CMD_FDISC &&
2576 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2577 maxretry = 3;
2578 delay = 1000;
2579 retry = 1;
2580 break;
2581 }
James Smart92d7f7b2007-06-17 19:56:38 -05002582 case LSRJT_PROTOCOL_ERR:
2583 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2584 (cmd == ELS_CMD_FDISC) &&
2585 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2586 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2587 ) {
James Smarte8b62012007-08-02 11:10:09 -04002588 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002589 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002590 "Fabric Detected Bad WWN\n",
2591 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002592 lpfc_vport_set_state(vport,
2593 FC_VPORT_FABRIC_REJ_WWN);
2594 }
2595 break;
dea31012005-04-17 16:05:31 -05002596 }
2597 break;
2598
2599 case IOSTAT_INTERMED_RSP:
2600 case IOSTAT_BA_RJT:
2601 break;
2602
2603 default:
2604 break;
2605 }
2606
James Smart488d1462006-03-07 15:02:37 -05002607 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002608 retry = 1;
dea31012005-04-17 16:05:31 -05002609
James Smart98c9ea52007-10-27 13:37:33 -04002610 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002611 (phba->fc_topology != TOPOLOGY_LOOP) &&
2612 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002613 /* FLOGI retry policy */
2614 retry = 1;
2615 maxretry = 48;
2616 if (cmdiocb->retry >= 32)
2617 delay = 1000;
2618 }
2619
dea31012005-04-17 16:05:31 -05002620 if ((++cmdiocb->retry) >= maxretry) {
2621 phba->fc_stat.elsRetryExceeded++;
2622 retry = 0;
2623 }
2624
James Smarted957682007-06-17 19:56:37 -05002625 if ((vport->load_flag & FC_UNLOADING) != 0)
2626 retry = 0;
2627
dea31012005-04-17 16:05:31 -05002628 if (retry) {
2629
2630 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002631 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2632 "0107 Retry ELS command x%x to remote "
2633 "NPORT x%x Data: x%x x%x\n",
2634 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002635
James Smart858c9f62007-06-17 19:56:39 -05002636 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2637 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2638 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2639 /* Don't reset timer for no resources */
2640
dea31012005-04-17 16:05:31 -05002641 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002642 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002643 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002644 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002645 }
2646
2647 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002648 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002649 phba->fc_stat.elsDelayRetry++;
2650 ndlp->nlp_retry = cmdiocb->retry;
2651
James Smart92d7f7b2007-06-17 19:56:38 -05002652 /* delay is specified in milliseconds */
2653 mod_timer(&ndlp->nlp_delayfunc,
2654 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002655 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002656 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002657 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002658
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002659 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002660 if (cmd == ELS_CMD_PRLI)
2661 lpfc_nlp_set_state(vport, ndlp,
2662 NLP_STE_REG_LOGIN_ISSUE);
2663 else
2664 lpfc_nlp_set_state(vport, ndlp,
2665 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002666 ndlp->nlp_last_elscmd = cmd;
2667
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002668 return 1;
dea31012005-04-17 16:05:31 -05002669 }
2670 switch (cmd) {
2671 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002672 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002673 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002674 case ELS_CMD_FDISC:
2675 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2676 return 1;
dea31012005-04-17 16:05:31 -05002677 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002678 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002679 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002680 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002681 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002682 }
James Smart2e0fef82007-06-17 19:56:36 -05002683 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002684 return 1;
dea31012005-04-17 16:05:31 -05002685 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002686 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002687 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2688 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002689 return 1;
dea31012005-04-17 16:05:31 -05002690 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002691 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002692 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2693 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002694 return 1;
dea31012005-04-17 16:05:31 -05002695 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002696 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002697 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2698 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002699 return 1;
dea31012005-04-17 16:05:31 -05002700 }
2701 }
dea31012005-04-17 16:05:31 -05002702 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002703 if (logerr) {
2704 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2705 "0137 No retry ELS command x%x to remote "
2706 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2707 cmd, did, irsp->ulpStatus,
2708 irsp->un.ulpWord[4]);
2709 }
2710 else {
2711 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002712 "0108 No retry ELS command x%x to remote "
2713 "NPORT x%x Retried:%d Error:x%x/%x\n",
2714 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2715 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002716 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002717 return 0;
dea31012005-04-17 16:05:31 -05002718}
2719
James Smarte59058c2008-08-24 21:49:00 -04002720/**
James Smart3621a712009-04-06 18:47:14 -04002721 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002722 * @phba: pointer to lpfc hba data structure.
2723 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2724 *
2725 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2726 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2727 * checks to see whether there is a lpfc DMA buffer associated with the
2728 * response of the command IOCB. If so, it will be released before releasing
2729 * the lpfc DMA buffer associated with the IOCB itself.
2730 *
2731 * Return code
2732 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2733 **/
James Smart09372822008-01-11 01:52:54 -05002734static int
James Smart87af33f2007-10-27 13:37:43 -04002735lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2736{
2737 struct lpfc_dmabuf *buf_ptr;
2738
James Smarte59058c2008-08-24 21:49:00 -04002739 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002740 if (!list_empty(&buf_ptr1->list)) {
2741 list_remove_head(&buf_ptr1->list, buf_ptr,
2742 struct lpfc_dmabuf,
2743 list);
2744 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2745 kfree(buf_ptr);
2746 }
2747 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2748 kfree(buf_ptr1);
2749 return 0;
2750}
2751
James Smarte59058c2008-08-24 21:49:00 -04002752/**
James Smart3621a712009-04-06 18:47:14 -04002753 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002754 * @phba: pointer to lpfc hba data structure.
2755 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2756 *
2757 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2758 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2759 * pool.
2760 *
2761 * Return code
2762 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2763 **/
James Smart09372822008-01-11 01:52:54 -05002764static int
James Smart87af33f2007-10-27 13:37:43 -04002765lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2766{
2767 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2768 kfree(buf_ptr);
2769 return 0;
2770}
2771
James Smarte59058c2008-08-24 21:49:00 -04002772/**
James Smart3621a712009-04-06 18:47:14 -04002773 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002774 * @phba: pointer to lpfc hba data structure.
2775 * @elsiocb: pointer to lpfc els command iocb data structure.
2776 *
2777 * This routine frees a command IOCB and its associated resources. The
2778 * command IOCB data structure contains the reference to various associated
2779 * resources, these fields must be set to NULL if the associated reference
2780 * not present:
2781 * context1 - reference to ndlp
2782 * context2 - reference to cmd
2783 * context2->next - reference to rsp
2784 * context3 - reference to bpl
2785 *
2786 * It first properly decrements the reference count held on ndlp for the
2787 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2788 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2789 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2790 * adds the DMA buffer the @phba data structure for the delayed release.
2791 * If reference to the Buffer Pointer List (BPL) is present, the
2792 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2793 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2794 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2795 *
2796 * Return code
2797 * 0 - Success (currently, always return 0)
2798 **/
James Smart87af33f2007-10-27 13:37:43 -04002799int
James Smart329f9bc2007-04-25 09:53:01 -04002800lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002801{
2802 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002803 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002804
James Smarta8adb832007-10-27 13:37:53 -04002805 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2806 if (ndlp) {
2807 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2808 lpfc_nlp_put(ndlp);
2809
2810 /* If the ndlp is not being used by another discovery
2811 * thread, free it.
2812 */
2813 if (!lpfc_nlp_not_used(ndlp)) {
2814 /* If ndlp is being used by another discovery
2815 * thread, just clear NLP_DEFER_RM
2816 */
2817 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2818 }
2819 }
2820 else
2821 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002822 elsiocb->context1 = NULL;
2823 }
dea31012005-04-17 16:05:31 -05002824 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2825 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002826 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2827 /* Firmware could still be in progress of DMAing
2828 * payload, so don't free data buffer till after
2829 * a hbeat.
2830 */
2831 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2832 buf_ptr = elsiocb->context2;
2833 elsiocb->context2 = NULL;
2834 if (buf_ptr) {
2835 buf_ptr1 = NULL;
2836 spin_lock_irq(&phba->hbalock);
2837 if (!list_empty(&buf_ptr->list)) {
2838 list_remove_head(&buf_ptr->list,
2839 buf_ptr1, struct lpfc_dmabuf,
2840 list);
2841 INIT_LIST_HEAD(&buf_ptr1->list);
2842 list_add_tail(&buf_ptr1->list,
2843 &phba->elsbuf);
2844 phba->elsbuf_cnt++;
2845 }
2846 INIT_LIST_HEAD(&buf_ptr->list);
2847 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2848 phba->elsbuf_cnt++;
2849 spin_unlock_irq(&phba->hbalock);
2850 }
2851 } else {
2852 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2853 lpfc_els_free_data(phba, buf_ptr1);
2854 }
dea31012005-04-17 16:05:31 -05002855 }
2856
2857 if (elsiocb->context3) {
2858 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002859 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002860 }
James Bottomley604a3e32005-10-29 10:28:33 -05002861 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002862 return 0;
2863}
2864
James Smarte59058c2008-08-24 21:49:00 -04002865/**
James Smart3621a712009-04-06 18:47:14 -04002866 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04002867 * @phba: pointer to lpfc hba data structure.
2868 * @cmdiocb: pointer to lpfc command iocb data structure.
2869 * @rspiocb: pointer to lpfc response iocb data structure.
2870 *
2871 * This routine is the completion callback function to the Logout (LOGO)
2872 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2873 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2874 * release the ndlp if it has the last reference remaining (reference count
2875 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2876 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2877 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2878 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2879 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2880 * IOCB data structure.
2881 **/
dea31012005-04-17 16:05:31 -05002882static void
James Smart2e0fef82007-06-17 19:56:36 -05002883lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2884 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002885{
James Smart2e0fef82007-06-17 19:56:36 -05002886 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2887 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002888 IOCB_t *irsp;
2889
2890 irsp = &rspiocb->iocb;
2891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2892 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2893 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002894 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002895 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2896 "0109 ACC to LOGO completes to NPort x%x "
2897 "Data: x%x x%x x%x\n",
2898 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2899 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002900
2901 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2902 /* NPort Recovery mode or node is just allocated */
2903 if (!lpfc_nlp_not_used(ndlp)) {
2904 /* If the ndlp is being used by another discovery
2905 * thread, just unregister the RPI.
2906 */
2907 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002908 } else {
2909 /* Indicate the node has already released, should
2910 * not reference to it from within lpfc_els_free_iocb.
2911 */
2912 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002913 }
dea31012005-04-17 16:05:31 -05002914 }
2915 lpfc_els_free_iocb(phba, cmdiocb);
2916 return;
2917}
2918
James Smarte59058c2008-08-24 21:49:00 -04002919/**
James Smart3621a712009-04-06 18:47:14 -04002920 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04002921 * @phba: pointer to lpfc hba data structure.
2922 * @pmb: pointer to the driver internal queue element for mailbox command.
2923 *
2924 * This routine is the completion callback function for unregister default
2925 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2926 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2927 * decrements the ndlp reference count held for this completion callback
2928 * function. After that, it invokes the lpfc_nlp_not_used() to check
2929 * whether there is only one reference left on the ndlp. If so, it will
2930 * perform one more decrement and trigger the release of the ndlp.
2931 **/
James Smart858c9f62007-06-17 19:56:39 -05002932void
2933lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2934{
2935 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2936 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2937
2938 pmb->context1 = NULL;
2939 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2940 kfree(mp);
2941 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04002942 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04002943 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002944 /* This is the end of the default RPI cleanup logic for this
2945 * ndlp. If no other discovery threads are using this ndlp.
2946 * we should free all resources associated with it.
2947 */
2948 lpfc_nlp_not_used(ndlp);
2949 }
James Smart3772a992009-05-22 14:50:54 -04002950
James Smart858c9f62007-06-17 19:56:39 -05002951 return;
2952}
2953
James Smarte59058c2008-08-24 21:49:00 -04002954/**
James Smart3621a712009-04-06 18:47:14 -04002955 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04002956 * @phba: pointer to lpfc hba data structure.
2957 * @cmdiocb: pointer to lpfc command iocb data structure.
2958 * @rspiocb: pointer to lpfc response iocb data structure.
2959 *
2960 * This routine is the completion callback function for ELS Response IOCB
2961 * command. In normal case, this callback function just properly sets the
2962 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2963 * field in the command IOCB is not NULL, the referred mailbox command will
2964 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2965 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2966 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2967 * routine shall be invoked trying to release the ndlp if no other threads
2968 * are currently referring it.
2969 **/
dea31012005-04-17 16:05:31 -05002970static void
James Smart858c9f62007-06-17 19:56:39 -05002971lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002972 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002973{
James Smart2e0fef82007-06-17 19:56:36 -05002974 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2975 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2976 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002977 IOCB_t *irsp;
2978 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002979 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002980 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002981 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002982
James Smart33ccf8d2006-08-17 11:57:58 -04002983 irsp = &rspiocb->iocb;
2984
dea31012005-04-17 16:05:31 -05002985 if (cmdiocb->context_un.mbox)
2986 mbox = cmdiocb->context_un.mbox;
2987
James Smartfa4066b2008-01-11 01:53:27 -05002988 /* First determine if this is a LS_RJT cmpl. Note, this callback
2989 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2990 */
James Smart87af33f2007-10-27 13:37:43 -04002991 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04002992 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
2993 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05002994 /* A LS_RJT associated with Default RPI cleanup has its own
2995 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04002996 */
2997 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2998 ls_rjt = 1;
2999 }
3000
dea31012005-04-17 16:05:31 -05003001 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003002 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003003 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003004 mp = (struct lpfc_dmabuf *) mbox->context1;
3005 if (mp) {
3006 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3007 kfree(mp);
3008 }
James Smart329f9bc2007-04-25 09:53:01 -04003009 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003010 }
James Smart58da1ff2008-04-07 10:15:56 -04003011 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3012 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003013 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003014 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003015 /* Indicate the node has already released,
3016 * should not reference to it from within
3017 * the routine lpfc_els_free_iocb.
3018 */
3019 cmdiocb->context1 = NULL;
3020 }
dea31012005-04-17 16:05:31 -05003021 goto out;
3022 }
3023
James Smart858c9f62007-06-17 19:56:39 -05003024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003025 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003026 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003027 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003028 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003029 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3030 "0110 ELS response tag x%x completes "
3031 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3032 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3033 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3034 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3035 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003036 if (mbox) {
3037 if ((rspiocb->iocb.ulpStatus == 0)
3038 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003039 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003040 /* Increment reference count to ndlp to hold the
3041 * reference to ndlp for the callback function.
3042 */
James Smart329f9bc2007-04-25 09:53:01 -04003043 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003044 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003045 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3046 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3047 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3048 }
3049 else {
3050 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3051 ndlp->nlp_prev_state = ndlp->nlp_state;
3052 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003053 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003054 }
James Smart0b727fe2007-10-27 13:37:25 -04003055 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003056 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003057 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003058 else
3059 /* Decrement the ndlp reference count we
3060 * set for this failed mailbox command.
3061 */
3062 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003063
3064 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3065 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3066 "0138 ELS rsp: Cannot issue reg_login for x%x "
3067 "Data: x%x x%x x%x\n",
3068 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3069 ndlp->nlp_rpi);
3070
James Smartfa4066b2008-01-11 01:53:27 -05003071 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003072 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003073 /* Indicate node has already been released,
3074 * should not reference to it from within
3075 * the routine lpfc_els_free_iocb.
3076 */
3077 cmdiocb->context1 = NULL;
3078 }
dea31012005-04-17 16:05:31 -05003079 } else {
James Smart858c9f62007-06-17 19:56:39 -05003080 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3081 if (!lpfc_error_lost_link(irsp) &&
3082 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003083 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003084 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003085 /* Indicate node has already been
3086 * released, should not reference
3087 * to it from within the routine
3088 * lpfc_els_free_iocb.
3089 */
3090 cmdiocb->context1 = NULL;
3091 }
dea31012005-04-17 16:05:31 -05003092 }
3093 }
James Smart14691152006-12-02 13:34:28 -05003094 mp = (struct lpfc_dmabuf *) mbox->context1;
3095 if (mp) {
3096 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3097 kfree(mp);
3098 }
3099 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003100 }
3101out:
James Smart58da1ff2008-04-07 10:15:56 -04003102 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003103 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003104 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003105 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003106
3107 /* If the node is not being used by another discovery thread,
3108 * and we are sending a reject, we are done with it.
3109 * Release driver reference count here and free associated
3110 * resources.
3111 */
3112 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003113 if (lpfc_nlp_not_used(ndlp))
3114 /* Indicate node has already been released,
3115 * should not reference to it from within
3116 * the routine lpfc_els_free_iocb.
3117 */
3118 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003119 }
James Smart87af33f2007-10-27 13:37:43 -04003120
dea31012005-04-17 16:05:31 -05003121 lpfc_els_free_iocb(phba, cmdiocb);
3122 return;
3123}
3124
James Smarte59058c2008-08-24 21:49:00 -04003125/**
James Smart3621a712009-04-06 18:47:14 -04003126 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003127 * @vport: pointer to a host virtual N_Port data structure.
3128 * @flag: the els command code to be accepted.
3129 * @oldiocb: pointer to the original lpfc command iocb data structure.
3130 * @ndlp: pointer to a node-list data structure.
3131 * @mbox: pointer to the driver internal queue element for mailbox command.
3132 *
3133 * This routine prepares and issues an Accept (ACC) response IOCB
3134 * command. It uses the @flag to properly set up the IOCB field for the
3135 * specific ACC response command to be issued and invokes the
3136 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3137 * @mbox pointer is passed in, it will be put into the context_un.mbox
3138 * field of the IOCB for the completion callback function to issue the
3139 * mailbox command to the HBA later when callback is invoked.
3140 *
3141 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3142 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3143 * will be stored into the context1 field of the IOCB for the completion
3144 * callback function to the corresponding response ELS IOCB command.
3145 *
3146 * Return code
3147 * 0 - Successfully issued acc response
3148 * 1 - Failed to issue acc response
3149 **/
dea31012005-04-17 16:05:31 -05003150int
James Smart2e0fef82007-06-17 19:56:36 -05003151lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3152 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003153 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003154{
James Smart2e0fef82007-06-17 19:56:36 -05003155 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3156 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003157 IOCB_t *icmd;
3158 IOCB_t *oldcmd;
3159 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003160 struct lpfc_sli *psli;
3161 uint8_t *pcmd;
3162 uint16_t cmdsize;
3163 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003164 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003165
3166 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003167 oldcmd = &oldiocb->iocb;
3168
3169 switch (flag) {
3170 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003171 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003172 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3173 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003174 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003175 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003176 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003177 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003178 return 1;
dea31012005-04-17 16:05:31 -05003179 }
James Smart2e0fef82007-06-17 19:56:36 -05003180
dea31012005-04-17 16:05:31 -05003181 icmd = &elsiocb->iocb;
3182 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3183 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3184 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003185 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003186
3187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3188 "Issue ACC: did:x%x flg:x%x",
3189 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003190 break;
3191 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003192 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003193 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3194 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003195 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003196 return 1;
James Smart488d1462006-03-07 15:02:37 -05003197
dea31012005-04-17 16:05:31 -05003198 icmd = &elsiocb->iocb;
3199 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3200 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3201
3202 if (mbox)
3203 elsiocb->context_un.mbox = mbox;
3204
3205 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003206 pcmd += sizeof(uint32_t);
3207 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003208
3209 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3210 "Issue ACC PLOGI: did:x%x flg:x%x",
3211 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003212 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003213 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003214 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003215 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003216 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3217 if (!elsiocb)
3218 return 1;
3219
3220 icmd = &elsiocb->iocb;
3221 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3222 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3223
3224 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003225 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003226 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3227 els_pkt_ptr = (ELS_PKT *) pcmd;
3228 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003229
3230 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3231 "Issue ACC PRLO: did:x%x flg:x%x",
3232 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003233 break;
dea31012005-04-17 16:05:31 -05003234 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003235 return 1;
dea31012005-04-17 16:05:31 -05003236 }
dea31012005-04-17 16:05:31 -05003237 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3239 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3240 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3241 elsiocb->iotag, elsiocb->iocb.ulpContext,
3242 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3243 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003244 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003245 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003246 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003247 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003248 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3249 } else {
James Smart858c9f62007-06-17 19:56:39 -05003250 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003251 }
3252
3253 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003254 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003255 if (rc == IOCB_ERROR) {
3256 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003257 return 1;
dea31012005-04-17 16:05:31 -05003258 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003259 return 0;
dea31012005-04-17 16:05:31 -05003260}
3261
James Smarte59058c2008-08-24 21:49:00 -04003262/**
James Smart3621a712009-04-06 18:47:14 -04003263 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003264 * @vport: pointer to a virtual N_Port data structure.
3265 * @rejectError:
3266 * @oldiocb: pointer to the original lpfc command iocb data structure.
3267 * @ndlp: pointer to a node-list data structure.
3268 * @mbox: pointer to the driver internal queue element for mailbox command.
3269 *
3270 * This routine prepares and issue an Reject (RJT) response IOCB
3271 * command. If a @mbox pointer is passed in, it will be put into the
3272 * context_un.mbox field of the IOCB for the completion callback function
3273 * to issue to the HBA later.
3274 *
3275 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3276 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3277 * will be stored into the context1 field of the IOCB for the completion
3278 * callback function to the reject response ELS IOCB command.
3279 *
3280 * Return code
3281 * 0 - Successfully issued reject response
3282 * 1 - Failed to issue reject response
3283 **/
dea31012005-04-17 16:05:31 -05003284int
James Smart2e0fef82007-06-17 19:56:36 -05003285lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003286 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3287 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003288{
James Smart2e0fef82007-06-17 19:56:36 -05003289 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003290 IOCB_t *icmd;
3291 IOCB_t *oldcmd;
3292 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003293 struct lpfc_sli *psli;
3294 uint8_t *pcmd;
3295 uint16_t cmdsize;
3296 int rc;
3297
3298 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003299 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003300 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3301 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003302 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003303 return 1;
dea31012005-04-17 16:05:31 -05003304
3305 icmd = &elsiocb->iocb;
3306 oldcmd = &oldiocb->iocb;
3307 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3308 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3309
3310 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003311 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003312 *((uint32_t *) (pcmd)) = rejectError;
3313
James Smart51ef4c22007-08-02 11:10:31 -04003314 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003315 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003316
dea31012005-04-17 16:05:31 -05003317 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3319 "0129 Xmit ELS RJT x%x response tag x%x "
3320 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3321 "rpi x%x\n",
3322 rejectError, elsiocb->iotag,
3323 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3324 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3326 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3327 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3328
dea31012005-04-17 16:05:31 -05003329 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003330 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003331 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003332
dea31012005-04-17 16:05:31 -05003333 if (rc == IOCB_ERROR) {
3334 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003335 return 1;
dea31012005-04-17 16:05:31 -05003336 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003337 return 0;
dea31012005-04-17 16:05:31 -05003338}
3339
James Smarte59058c2008-08-24 21:49:00 -04003340/**
James Smart3621a712009-04-06 18:47:14 -04003341 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003342 * @vport: pointer to a virtual N_Port data structure.
3343 * @oldiocb: pointer to the original lpfc command iocb data structure.
3344 * @ndlp: pointer to a node-list data structure.
3345 *
3346 * This routine prepares and issues an Accept (ACC) response to Address
3347 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3348 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3349 *
3350 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3351 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3352 * will be stored into the context1 field of the IOCB for the completion
3353 * callback function to the ADISC Accept response ELS IOCB command.
3354 *
3355 * Return code
3356 * 0 - Successfully issued acc adisc response
3357 * 1 - Failed to issue adisc acc response
3358 **/
dea31012005-04-17 16:05:31 -05003359int
James Smart2e0fef82007-06-17 19:56:36 -05003360lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3361 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003362{
James Smart2e0fef82007-06-17 19:56:36 -05003363 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003364 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003365 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003366 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003367 uint8_t *pcmd;
3368 uint16_t cmdsize;
3369 int rc;
3370
James Smart92d7f7b2007-06-17 19:56:38 -05003371 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003372 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3373 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003374 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003375 return 1;
dea31012005-04-17 16:05:31 -05003376
dea31012005-04-17 16:05:31 -05003377 icmd = &elsiocb->iocb;
3378 oldcmd = &oldiocb->iocb;
3379 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003380
3381 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003382 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3383 "0130 Xmit ADISC ACC response iotag x%x xri: "
3384 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3385 elsiocb->iotag, elsiocb->iocb.ulpContext,
3386 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3387 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003388 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3389
3390 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003391 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003392
3393 ap = (ADISC *) (pcmd);
3394 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003395 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3396 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003397 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003398
James Smart858c9f62007-06-17 19:56:39 -05003399 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3400 "Issue ACC ADISC: did:x%x flg:x%x",
3401 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3402
dea31012005-04-17 16:05:31 -05003403 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003404 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003405 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003406 if (rc == IOCB_ERROR) {
3407 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003408 return 1;
dea31012005-04-17 16:05:31 -05003409 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003410 return 0;
dea31012005-04-17 16:05:31 -05003411}
3412
James Smarte59058c2008-08-24 21:49:00 -04003413/**
James Smart3621a712009-04-06 18:47:14 -04003414 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003415 * @vport: pointer to a virtual N_Port data structure.
3416 * @oldiocb: pointer to the original lpfc command iocb data structure.
3417 * @ndlp: pointer to a node-list data structure.
3418 *
3419 * This routine prepares and issues an Accept (ACC) response to Process
3420 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3421 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3422 *
3423 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3424 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3425 * will be stored into the context1 field of the IOCB for the completion
3426 * callback function to the PRLI Accept response ELS IOCB command.
3427 *
3428 * Return code
3429 * 0 - Successfully issued acc prli response
3430 * 1 - Failed to issue acc prli response
3431 **/
dea31012005-04-17 16:05:31 -05003432int
James Smart2e0fef82007-06-17 19:56:36 -05003433lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003434 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003435{
James Smart2e0fef82007-06-17 19:56:36 -05003436 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003437 PRLI *npr;
3438 lpfc_vpd_t *vpd;
3439 IOCB_t *icmd;
3440 IOCB_t *oldcmd;
3441 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003442 struct lpfc_sli *psli;
3443 uint8_t *pcmd;
3444 uint16_t cmdsize;
3445 int rc;
3446
3447 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003448
James Smart92d7f7b2007-06-17 19:56:38 -05003449 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003450 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003451 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003452 if (!elsiocb)
3453 return 1;
dea31012005-04-17 16:05:31 -05003454
dea31012005-04-17 16:05:31 -05003455 icmd = &elsiocb->iocb;
3456 oldcmd = &oldiocb->iocb;
3457 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003458 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003459 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3460 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3461 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3462 elsiocb->iotag, elsiocb->iocb.ulpContext,
3463 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3464 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003465 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3466
3467 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003468 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003469
3470 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003471 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003472
3473 npr = (PRLI *) pcmd;
3474 vpd = &phba->vpd;
3475 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003476 * If the remote port is a target and our firmware version is 3.20 or
3477 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003478 */
James Smart0d2b6b82008-06-14 22:52:47 -04003479 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3480 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003481 npr->ConfmComplAllowed = 1;
3482 npr->Retry = 1;
3483 npr->TaskRetryIdReq = 1;
3484 }
3485
3486 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3487 npr->estabImagePair = 1;
3488 npr->readXferRdyDis = 1;
3489 npr->ConfmComplAllowed = 1;
3490
3491 npr->prliType = PRLI_FCP_TYPE;
3492 npr->initiatorFunc = 1;
3493
James Smart858c9f62007-06-17 19:56:39 -05003494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3495 "Issue ACC PRLI: did:x%x flg:x%x",
3496 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3497
dea31012005-04-17 16:05:31 -05003498 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003499 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003500
James Smart3772a992009-05-22 14:50:54 -04003501 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003502 if (rc == IOCB_ERROR) {
3503 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003504 return 1;
dea31012005-04-17 16:05:31 -05003505 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003506 return 0;
dea31012005-04-17 16:05:31 -05003507}
3508
James Smarte59058c2008-08-24 21:49:00 -04003509/**
James Smart3621a712009-04-06 18:47:14 -04003510 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003511 * @vport: pointer to a virtual N_Port data structure.
3512 * @format: rnid command format.
3513 * @oldiocb: pointer to the original lpfc command iocb data structure.
3514 * @ndlp: pointer to a node-list data structure.
3515 *
3516 * This routine issues a Request Node Identification Data (RNID) Accept
3517 * (ACC) response. It constructs the RNID ACC response command according to
3518 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3519 * issue the response. Note that this command does not need to hold the ndlp
3520 * reference count for the callback. So, the ndlp reference count taken by
3521 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3522 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3523 * there is no ndlp reference available.
3524 *
3525 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3526 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3527 * will be stored into the context1 field of the IOCB for the completion
3528 * callback function. However, for the RNID Accept Response ELS command,
3529 * this is undone later by this routine after the IOCB is allocated.
3530 *
3531 * Return code
3532 * 0 - Successfully issued acc rnid response
3533 * 1 - Failed to issue acc rnid response
3534 **/
dea31012005-04-17 16:05:31 -05003535static int
James Smart2e0fef82007-06-17 19:56:36 -05003536lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003537 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003538{
James Smart2e0fef82007-06-17 19:56:36 -05003539 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003540 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003541 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003542 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003543 struct lpfc_sli *psli;
3544 uint8_t *pcmd;
3545 uint16_t cmdsize;
3546 int rc;
3547
3548 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003549 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3550 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003551 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003552 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003553
James Smart2e0fef82007-06-17 19:56:36 -05003554 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3555 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003556 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003557 return 1;
dea31012005-04-17 16:05:31 -05003558
dea31012005-04-17 16:05:31 -05003559 icmd = &elsiocb->iocb;
3560 oldcmd = &oldiocb->iocb;
3561 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003562 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003563 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3564 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3565 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003566 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003567 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003568 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003569
James Smart92d7f7b2007-06-17 19:56:38 -05003570 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003571 rn = (RNID *) (pcmd);
3572 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003573 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3574 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3575 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003576 switch (format) {
3577 case 0:
3578 rn->SpecificLen = 0;
3579 break;
3580 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003581 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003582 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003583 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003584 rn->un.topologyDisc.unitType = RNID_HBA;
3585 rn->un.topologyDisc.physPort = 0;
3586 rn->un.topologyDisc.attachedNodes = 0;
3587 break;
3588 default:
3589 rn->CommonLen = 0;
3590 rn->SpecificLen = 0;
3591 break;
3592 }
3593
James Smart858c9f62007-06-17 19:56:39 -05003594 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3595 "Issue ACC RNID: did:x%x flg:x%x",
3596 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3597
dea31012005-04-17 16:05:31 -05003598 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003599 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003600 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003601 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3602 * it could be freed */
3603
James Smart3772a992009-05-22 14:50:54 -04003604 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003605 if (rc == IOCB_ERROR) {
3606 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003607 return 1;
dea31012005-04-17 16:05:31 -05003608 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003609 return 0;
dea31012005-04-17 16:05:31 -05003610}
3611
James Smarte59058c2008-08-24 21:49:00 -04003612/**
James Smart3621a712009-04-06 18:47:14 -04003613 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003614 * @vport: pointer to a host virtual N_Port data structure.
3615 *
3616 * This routine issues Address Discover (ADISC) ELS commands to those
3617 * N_Ports which are in node port recovery state and ADISC has not been issued
3618 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3619 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3620 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3621 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3622 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3623 * IOCBs quit for later pick up. On the other hand, after walking through
3624 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3625 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3626 * no more ADISC need to be sent.
3627 *
3628 * Return code
3629 * The number of N_Ports with adisc issued.
3630 **/
dea31012005-04-17 16:05:31 -05003631int
James Smart2e0fef82007-06-17 19:56:36 -05003632lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003633{
James Smart2e0fef82007-06-17 19:56:36 -05003634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003635 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003636 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003637
James Smart685f0bf2007-04-25 09:53:08 -04003638 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003639 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003640 if (!NLP_CHK_NODE_ACT(ndlp))
3641 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003642 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3643 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3644 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003645 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003646 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003647 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003648 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003649 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3650 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003651 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003652 vport->num_disc_nodes++;
3653 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003654 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003655 spin_lock_irq(shost->host_lock);
3656 vport->fc_flag |= FC_NLP_MORE;
3657 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003658 break;
dea31012005-04-17 16:05:31 -05003659 }
3660 }
3661 }
3662 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003663 spin_lock_irq(shost->host_lock);
3664 vport->fc_flag &= ~FC_NLP_MORE;
3665 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003666 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003667 return sentadisc;
dea31012005-04-17 16:05:31 -05003668}
3669
James Smarte59058c2008-08-24 21:49:00 -04003670/**
James Smart3621a712009-04-06 18:47:14 -04003671 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003672 * @vport: pointer to a host virtual N_Port data structure.
3673 *
3674 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3675 * which are in node port recovery state, with a @vport. Each time an ELS
3676 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3677 * the per @vport number of discover count (num_disc_nodes) shall be
3678 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3679 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3680 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3681 * later pick up. On the other hand, after walking through all the ndlps with
3682 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3683 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3684 * PLOGI need to be sent.
3685 *
3686 * Return code
3687 * The number of N_Ports with plogi issued.
3688 **/
dea31012005-04-17 16:05:31 -05003689int
James Smart2e0fef82007-06-17 19:56:36 -05003690lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003691{
James Smart2e0fef82007-06-17 19:56:36 -05003692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003693 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003694 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003695
James Smart2e0fef82007-06-17 19:56:36 -05003696 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3697 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003698 if (!NLP_CHK_NODE_ACT(ndlp))
3699 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003700 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3701 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3702 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3703 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3704 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003705 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3706 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003707 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003708 vport->num_disc_nodes++;
3709 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003710 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003711 spin_lock_irq(shost->host_lock);
3712 vport->fc_flag |= FC_NLP_MORE;
3713 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003714 break;
dea31012005-04-17 16:05:31 -05003715 }
3716 }
3717 }
James Smart87af33f2007-10-27 13:37:43 -04003718 if (sentplogi) {
3719 lpfc_set_disctmo(vport);
3720 }
3721 else {
James Smart2e0fef82007-06-17 19:56:36 -05003722 spin_lock_irq(shost->host_lock);
3723 vport->fc_flag &= ~FC_NLP_MORE;
3724 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003725 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003726 return sentplogi;
dea31012005-04-17 16:05:31 -05003727}
3728
James Smarte59058c2008-08-24 21:49:00 -04003729/**
James Smart3621a712009-04-06 18:47:14 -04003730 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003731 * @vport: pointer to a host virtual N_Port data structure.
3732 *
3733 * This routine cleans up any Registration State Change Notification
3734 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3735 * @vport together with the host_lock is used to prevent multiple thread
3736 * trying to access the RSCN array on a same @vport at the same time.
3737 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003738void
James Smart2e0fef82007-06-17 19:56:36 -05003739lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003740{
James Smart2e0fef82007-06-17 19:56:36 -05003741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3742 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003743 int i;
3744
James Smart7f5f3d02008-02-08 18:50:14 -05003745 spin_lock_irq(shost->host_lock);
3746 if (vport->fc_rscn_flush) {
3747 /* Another thread is walking fc_rscn_id_list on this vport */
3748 spin_unlock_irq(shost->host_lock);
3749 return;
3750 }
3751 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3752 vport->fc_rscn_flush = 1;
3753 spin_unlock_irq(shost->host_lock);
3754
James Smart2e0fef82007-06-17 19:56:36 -05003755 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003756 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003757 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003758 }
James Smart2e0fef82007-06-17 19:56:36 -05003759 spin_lock_irq(shost->host_lock);
3760 vport->fc_rscn_id_cnt = 0;
3761 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3762 spin_unlock_irq(shost->host_lock);
3763 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003764 /* Indicate we are done walking this fc_rscn_id_list */
3765 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003766}
3767
James Smarte59058c2008-08-24 21:49:00 -04003768/**
James Smart3621a712009-04-06 18:47:14 -04003769 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003770 * @vport: pointer to a host virtual N_Port data structure.
3771 * @did: remote destination port identifier.
3772 *
3773 * This routine checks whether there is any pending Registration State
3774 * Configuration Notification (RSCN) to a @did on @vport.
3775 *
3776 * Return code
3777 * None zero - The @did matched with a pending rscn
3778 * 0 - not able to match @did with a pending rscn
3779 **/
dea31012005-04-17 16:05:31 -05003780int
James Smart2e0fef82007-06-17 19:56:36 -05003781lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003782{
3783 D_ID ns_did;
3784 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003785 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003786 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003787 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003788
3789 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05003790
3791 /* Never match fabric nodes for RSCNs */
3792 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003793 return 0;
dea31012005-04-17 16:05:31 -05003794
3795 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003796 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003797 return did;
dea31012005-04-17 16:05:31 -05003798
James Smart7f5f3d02008-02-08 18:50:14 -05003799 spin_lock_irq(shost->host_lock);
3800 if (vport->fc_rscn_flush) {
3801 /* Another thread is walking fc_rscn_id_list on this vport */
3802 spin_unlock_irq(shost->host_lock);
3803 return 0;
3804 }
3805 /* Indicate we are walking fc_rscn_id_list on this vport */
3806 vport->fc_rscn_flush = 1;
3807 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003808 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003809 lp = vport->fc_rscn_id_list[i]->virt;
3810 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3811 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003812 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003813 rscn_did.un.word = be32_to_cpu(*lp++);
3814 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05003815 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3816 case RSCN_ADDRESS_FORMAT_PORT:
James Smart2e0fef82007-06-17 19:56:36 -05003817 if (ns_did.un.word == rscn_did.un.word)
James Smart7f5f3d02008-02-08 18:50:14 -05003818 goto return_did_out;
dea31012005-04-17 16:05:31 -05003819 break;
James Smarteaf15d52008-12-04 22:39:29 -05003820 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05003821 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3822 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003823 goto return_did_out;
dea31012005-04-17 16:05:31 -05003824 break;
James Smarteaf15d52008-12-04 22:39:29 -05003825 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05003826 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003827 goto return_did_out;
dea31012005-04-17 16:05:31 -05003828 break;
James Smarteaf15d52008-12-04 22:39:29 -05003829 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05003830 goto return_did_out;
dea31012005-04-17 16:05:31 -05003831 }
3832 }
James Smart92d7f7b2007-06-17 19:56:38 -05003833 }
James Smart7f5f3d02008-02-08 18:50:14 -05003834 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3835 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003836 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003837return_did_out:
3838 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3839 vport->fc_rscn_flush = 0;
3840 return did;
dea31012005-04-17 16:05:31 -05003841}
3842
James Smarte59058c2008-08-24 21:49:00 -04003843/**
James Smart3621a712009-04-06 18:47:14 -04003844 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04003845 * @vport: pointer to a host virtual N_Port data structure.
3846 *
3847 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3848 * state machine for a @vport's nodes that are with pending RSCN (Registration
3849 * State Change Notification).
3850 *
3851 * Return code
3852 * 0 - Successful (currently alway return 0)
3853 **/
dea31012005-04-17 16:05:31 -05003854static int
James Smart2e0fef82007-06-17 19:56:36 -05003855lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003856{
James Smart685f0bf2007-04-25 09:53:08 -04003857 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003858
James Smart0d2b6b82008-06-14 22:52:47 -04003859 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003860 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003861 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04003862 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3863 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05003864 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003865 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04003866 NLP_EVT_DEVICE_RECOVERY);
3867 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003868 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003869 return 0;
dea31012005-04-17 16:05:31 -05003870}
3871
James Smarte59058c2008-08-24 21:49:00 -04003872/**
James Smart3621a712009-04-06 18:47:14 -04003873 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05003874 * @vport: pointer to a host virtual N_Port data structure.
3875 * @cmdiocb: pointer to lpfc command iocb data structure.
3876 *
3877 * lpfc_send_rscn_event sends an RSCN netlink event to management
3878 * applications.
3879 */
3880static void
3881lpfc_send_rscn_event(struct lpfc_vport *vport,
3882 struct lpfc_iocbq *cmdiocb)
3883{
3884 struct lpfc_dmabuf *pcmd;
3885 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3886 uint32_t *payload_ptr;
3887 uint32_t payload_len;
3888 struct lpfc_rscn_event_header *rscn_event_data;
3889
3890 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3891 payload_ptr = (uint32_t *) pcmd->virt;
3892 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
3893
3894 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
3895 payload_len, GFP_KERNEL);
3896 if (!rscn_event_data) {
3897 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3898 "0147 Failed to allocate memory for RSCN event\n");
3899 return;
3900 }
3901 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
3902 rscn_event_data->payload_length = payload_len;
3903 memcpy(rscn_event_data->rscn_payload, payload_ptr,
3904 payload_len);
3905
3906 fc_host_post_vendor_event(shost,
3907 fc_get_event_number(),
3908 sizeof(struct lpfc_els_event_header) + payload_len,
3909 (char *)rscn_event_data,
3910 LPFC_NL_VENDOR_ID);
3911
3912 kfree(rscn_event_data);
3913}
3914
3915/**
James Smart3621a712009-04-06 18:47:14 -04003916 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04003917 * @vport: pointer to a host virtual N_Port data structure.
3918 * @cmdiocb: pointer to lpfc command iocb data structure.
3919 * @ndlp: pointer to a node-list data structure.
3920 *
3921 * This routine processes an unsolicited RSCN (Registration State Change
3922 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3923 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3924 * discover state machine is about to begin discovery, it just accepts the
3925 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3926 * contains N_Port IDs for other vports on this HBA, it just accepts the
3927 * RSCN and ignore processing it. If the state machine is in the recovery
3928 * state, the fc_rscn_id_list of this @vport is walked and the
3929 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3930 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3931 * routine is invoked to handle the RSCN event.
3932 *
3933 * Return code
3934 * 0 - Just sent the acc response
3935 * 1 - Sent the acc response and waited for name server completion
3936 **/
dea31012005-04-17 16:05:31 -05003937static int
James Smart2e0fef82007-06-17 19:56:36 -05003938lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003939 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003940{
James Smart2e0fef82007-06-17 19:56:36 -05003941 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3942 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003943 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003944 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05003945 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003946 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003947 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05003948 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04003949 int i;
dea31012005-04-17 16:05:31 -05003950
3951 icmd = &cmdiocb->iocb;
3952 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3953 lp = (uint32_t *) pcmd->virt;
3954
James Smart92d7f7b2007-06-17 19:56:38 -05003955 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3956 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003957 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04003958 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3959 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05003960 vport->fc_flag, payload_len, *lp,
3961 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05003962
3963 /* Send an RSCN event to the management application */
3964 lpfc_send_rscn_event(vport, cmdiocb);
3965
James Smartd2873e42006-08-18 17:46:43 -04003966 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05003967 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04003968 FCH_EVT_RSCN, lp[i]);
3969
dea31012005-04-17 16:05:31 -05003970 /* If we are about to begin discovery, just ACC the RSCN.
3971 * Discovery processing will satisfy it.
3972 */
James Smart2e0fef82007-06-17 19:56:36 -05003973 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05003974 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3975 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3976 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3977
James Smart51ef4c22007-08-02 11:10:31 -04003978 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003979 return 0;
dea31012005-04-17 16:05:31 -05003980 }
3981
James Smart92d7f7b2007-06-17 19:56:38 -05003982 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3983 * just ACC and ignore it.
3984 */
3985 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04003986 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003987 i = payload_len;
3988 datap = lp;
3989 while (i > 0) {
3990 nportid = *datap++;
3991 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3992 i -= sizeof(uint32_t);
3993 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04003994 if (lpfc_find_vport_by_did(phba, nportid))
3995 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05003996 }
3997 if (rscn_id == hba_id) {
3998 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04003999 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004000 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004001 "Data: x%x x%x x%x x%x\n",
4002 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004003 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4005 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4006 ndlp->nlp_DID, vport->port_state,
4007 ndlp->nlp_flag);
4008
James Smart92d7f7b2007-06-17 19:56:38 -05004009 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004010 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004011 return 0;
4012 }
4013 }
4014
James Smart7f5f3d02008-02-08 18:50:14 -05004015 spin_lock_irq(shost->host_lock);
4016 if (vport->fc_rscn_flush) {
4017 /* Another thread is walking fc_rscn_id_list on this vport */
4018 spin_unlock_irq(shost->host_lock);
4019 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart58da1ff2008-04-07 10:15:56 -04004020 /* Send back ACC */
4021 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004022 return 0;
4023 }
4024 /* Indicate we are walking fc_rscn_id_list on this vport */
4025 vport->fc_rscn_flush = 1;
4026 spin_unlock_irq(shost->host_lock);
4027 /* Get the array count after sucessfully have the token */
4028 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004029 /* If we are already processing an RSCN, save the received
4030 * RSCN payload buffer, cmdiocb->context2 to process later.
4031 */
James Smart2e0fef82007-06-17 19:56:36 -05004032 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004033 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4034 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4035 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4036
James Smart09372822008-01-11 01:52:54 -05004037 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004038 vport->fc_flag |= FC_RSCN_DEFERRED;
4039 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004040 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004041 vport->fc_flag |= FC_RSCN_MODE;
4042 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004043 if (rscn_cnt) {
4044 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4045 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4046 }
4047 if ((rscn_cnt) &&
4048 (payload_len + length <= LPFC_BPL_SIZE)) {
4049 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004050 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004051 memcpy(((uint8_t *)cmd) + length, lp,
4052 payload_len);
4053 } else {
4054 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4055 vport->fc_rscn_id_cnt++;
4056 /* If we zero, cmdiocb->context2, the calling
4057 * routine will not try to free it.
4058 */
4059 cmdiocb->context2 = NULL;
4060 }
dea31012005-04-17 16:05:31 -05004061 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004062 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4063 "0235 Deferred RSCN "
4064 "Data: x%x x%x x%x\n",
4065 vport->fc_rscn_id_cnt, vport->fc_flag,
4066 vport->port_state);
dea31012005-04-17 16:05:31 -05004067 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004068 vport->fc_flag |= FC_RSCN_DISCOVERY;
4069 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004070 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004071 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4072 "0234 ReDiscovery RSCN "
4073 "Data: x%x x%x x%x\n",
4074 vport->fc_rscn_id_cnt, vport->fc_flag,
4075 vport->port_state);
dea31012005-04-17 16:05:31 -05004076 }
James Smart7f5f3d02008-02-08 18:50:14 -05004077 /* Indicate we are done walking fc_rscn_id_list on this vport */
4078 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004079 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004080 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004081 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004082 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004083 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004084 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004085 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004086 return 0;
dea31012005-04-17 16:05:31 -05004087 }
James Smart858c9f62007-06-17 19:56:39 -05004088 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4089 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4090 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4091
James Smart2e0fef82007-06-17 19:56:36 -05004092 spin_lock_irq(shost->host_lock);
4093 vport->fc_flag |= FC_RSCN_MODE;
4094 spin_unlock_irq(shost->host_lock);
4095 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004096 /* Indicate we are done walking fc_rscn_id_list on this vport */
4097 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004098 /*
4099 * If we zero, cmdiocb->context2, the calling routine will
4100 * not try to free it.
4101 */
4102 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004103 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004104 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004105 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004106 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004107 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004108 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004109}
4110
James Smarte59058c2008-08-24 21:49:00 -04004111/**
James Smart3621a712009-04-06 18:47:14 -04004112 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004113 * @vport: pointer to a host virtual N_Port data structure.
4114 *
4115 * This routine handles the Registration State Configuration Notification
4116 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4117 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4118 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4119 * NameServer shall be issued. If CT command to the NameServer fails to be
4120 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4121 * RSCN activities with the @vport.
4122 *
4123 * Return code
4124 * 0 - Cleaned up rscn on the @vport
4125 * 1 - Wait for plogi to name server before proceed
4126 **/
dea31012005-04-17 16:05:31 -05004127int
James Smart2e0fef82007-06-17 19:56:36 -05004128lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004129{
4130 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004131 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004132
James Smart92d7f7b2007-06-17 19:56:38 -05004133 /* Ignore RSCN if the port is being torn down. */
4134 if (vport->load_flag & FC_UNLOADING) {
4135 lpfc_els_flush_rscn(vport);
4136 return 0;
4137 }
4138
dea31012005-04-17 16:05:31 -05004139 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004140 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004141
4142 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004143 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4144 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4145 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4146 vport->port_state);
dea31012005-04-17 16:05:31 -05004147
4148 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004149 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004150 vport->num_disc_nodes = 0;
4151
James Smart2e0fef82007-06-17 19:56:36 -05004152 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004153 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4154 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004155 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004156 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004157 /* Wait for NameServer query cmpl before we can
4158 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004159 return 1;
dea31012005-04-17 16:05:31 -05004160 } else {
4161 /* If login to NameServer does not exist, issue one */
4162 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004163 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004164 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004165 /* Wait for NameServer login cmpl before we can
4166 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004167 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004168
James Smarte47c9092008-02-08 18:49:26 -05004169 if (ndlp) {
4170 ndlp = lpfc_enable_node(vport, ndlp,
4171 NLP_STE_PLOGI_ISSUE);
4172 if (!ndlp) {
4173 lpfc_els_flush_rscn(vport);
4174 return 0;
4175 }
4176 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004177 } else {
James Smarte47c9092008-02-08 18:49:26 -05004178 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4179 if (!ndlp) {
4180 lpfc_els_flush_rscn(vport);
4181 return 0;
4182 }
James Smart2e0fef82007-06-17 19:56:36 -05004183 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004184 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004185 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004186 }
James Smarte47c9092008-02-08 18:49:26 -05004187 ndlp->nlp_type |= NLP_FABRIC;
4188 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4189 /* Wait for NameServer login cmpl before we can
4190 * continue
4191 */
4192 return 1;
dea31012005-04-17 16:05:31 -05004193 }
4194
James Smart2e0fef82007-06-17 19:56:36 -05004195 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004196 return 0;
dea31012005-04-17 16:05:31 -05004197}
4198
James Smarte59058c2008-08-24 21:49:00 -04004199/**
James Smart3621a712009-04-06 18:47:14 -04004200 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004201 * @vport: pointer to a host virtual N_Port data structure.
4202 * @cmdiocb: pointer to lpfc command iocb data structure.
4203 * @ndlp: pointer to a node-list data structure.
4204 *
4205 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4206 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4207 * point topology. As an unsolicited FLOGI should not be received in a loop
4208 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4209 * lpfc_check_sparm() routine is invoked to check the parameters in the
4210 * unsolicited FLOGI. If parameters validation failed, the routine
4211 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4212 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4213 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4214 * will initiate PLOGI. The higher lexicographical value party shall has
4215 * higher priority (as the winning port) and will initiate PLOGI and
4216 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4217 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4218 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4219 *
4220 * Return code
4221 * 0 - Successfully processed the unsolicited flogi
4222 * 1 - Failed to process the unsolicited flogi
4223 **/
dea31012005-04-17 16:05:31 -05004224static int
James Smart2e0fef82007-06-17 19:56:36 -05004225lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004226 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004227{
James Smart2e0fef82007-06-17 19:56:36 -05004228 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4229 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004230 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4231 uint32_t *lp = (uint32_t *) pcmd->virt;
4232 IOCB_t *icmd = &cmdiocb->iocb;
4233 struct serv_parm *sp;
4234 LPFC_MBOXQ_t *mbox;
4235 struct ls_rjt stat;
4236 uint32_t cmd, did;
4237 int rc;
4238
4239 cmd = *lp++;
4240 sp = (struct serv_parm *) lp;
4241
4242 /* FLOGI received */
4243
James Smart2e0fef82007-06-17 19:56:36 -05004244 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004245
4246 if (phba->fc_topology == TOPOLOGY_LOOP) {
4247 /* We should never receive a FLOGI in loop mode, ignore it */
4248 did = icmd->un.elsreq64.remoteID;
4249
4250 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4251 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004252 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4253 "0113 An FLOGI ELS command x%x was "
4254 "received from DID x%x in Loop Mode\n",
4255 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004256 return 1;
dea31012005-04-17 16:05:31 -05004257 }
4258
4259 did = Fabric_DID;
4260
James Smart2e0fef82007-06-17 19:56:36 -05004261 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05004262 /* For a FLOGI we accept, then if our portname is greater
4263 * then the remote portname we initiate Nport login.
4264 */
4265
James Smart2e0fef82007-06-17 19:56:36 -05004266 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004267 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004268
4269 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004270 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4271 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004272 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004273
dea31012005-04-17 16:05:31 -05004274 lpfc_linkdown(phba);
4275 lpfc_init_link(phba, mbox,
4276 phba->cfg_topology,
4277 phba->cfg_link_speed);
4278 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
4279 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004280 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004281 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004282 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004283 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004284 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004285 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004286 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004287 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004288 spin_lock_irq(shost->host_lock);
4289 vport->fc_flag |= FC_PT2PT_PLOGI;
4290 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004291 }
James Smart2e0fef82007-06-17 19:56:36 -05004292 spin_lock_irq(shost->host_lock);
4293 vport->fc_flag |= FC_PT2PT;
4294 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4295 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004296 } else {
4297 /* Reject this request because invalid parameters */
4298 stat.un.b.lsRjtRsvd0 = 0;
4299 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4300 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4301 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004302 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4303 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004304 return 1;
dea31012005-04-17 16:05:31 -05004305 }
4306
4307 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004308 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004309
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004310 return 0;
dea31012005-04-17 16:05:31 -05004311}
4312
James Smarte59058c2008-08-24 21:49:00 -04004313/**
James Smart3621a712009-04-06 18:47:14 -04004314 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004315 * @vport: pointer to a host virtual N_Port data structure.
4316 * @cmdiocb: pointer to lpfc command iocb data structure.
4317 * @ndlp: pointer to a node-list data structure.
4318 *
4319 * This routine processes Request Node Identification Data (RNID) IOCB
4320 * received as an ELS unsolicited event. Only when the RNID specified format
4321 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4322 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4323 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4324 * rejected by invoking the lpfc_els_rsp_reject() routine.
4325 *
4326 * Return code
4327 * 0 - Successfully processed rnid iocb (currently always return 0)
4328 **/
dea31012005-04-17 16:05:31 -05004329static int
James Smart2e0fef82007-06-17 19:56:36 -05004330lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4331 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004332{
4333 struct lpfc_dmabuf *pcmd;
4334 uint32_t *lp;
4335 IOCB_t *icmd;
4336 RNID *rn;
4337 struct ls_rjt stat;
4338 uint32_t cmd, did;
4339
4340 icmd = &cmdiocb->iocb;
4341 did = icmd->un.elsreq64.remoteID;
4342 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4343 lp = (uint32_t *) pcmd->virt;
4344
4345 cmd = *lp++;
4346 rn = (RNID *) lp;
4347
4348 /* RNID received */
4349
4350 switch (rn->Format) {
4351 case 0:
4352 case RNID_TOPOLOGY_DISC:
4353 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004354 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004355 break;
4356 default:
4357 /* Reject this request because format not supported */
4358 stat.un.b.lsRjtRsvd0 = 0;
4359 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4360 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4361 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004362 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4363 NULL);
dea31012005-04-17 16:05:31 -05004364 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004365 return 0;
dea31012005-04-17 16:05:31 -05004366}
4367
James Smarte59058c2008-08-24 21:49:00 -04004368/**
James Smart3621a712009-04-06 18:47:14 -04004369 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004370 * @vport: pointer to a host virtual N_Port data structure.
4371 * @cmdiocb: pointer to lpfc command iocb data structure.
4372 * @ndlp: pointer to a node-list data structure.
4373 *
4374 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4375 * received as an ELS unsolicited event. Currently, this function just invokes
4376 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4377 *
4378 * Return code
4379 * 0 - Successfully processed lirr iocb (currently always return 0)
4380 **/
dea31012005-04-17 16:05:31 -05004381static int
James Smart2e0fef82007-06-17 19:56:36 -05004382lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4383 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004384{
4385 struct ls_rjt stat;
4386
4387 /* For now, unconditionally reject this command */
4388 stat.un.b.lsRjtRsvd0 = 0;
4389 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4390 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4391 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004392 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004393 return 0;
4394}
4395
James Smarte59058c2008-08-24 21:49:00 -04004396/**
James Smart3621a712009-04-06 18:47:14 -04004397 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004398 * @phba: pointer to lpfc hba data structure.
4399 * @pmb: pointer to the driver internal queue element for mailbox command.
4400 *
4401 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4402 * mailbox command. This callback function is to actually send the Accept
4403 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4404 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4405 * mailbox command, constructs the RPS response with the link statistics
4406 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4407 * response to the RPS.
4408 *
4409 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4410 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4411 * will be stored into the context1 field of the IOCB for the completion
4412 * callback function to the RPS Accept Response ELS IOCB command.
4413 *
4414 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004415static void
James Smart329f9bc2007-04-25 09:53:01 -04004416lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004417{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004418 MAILBOX_t *mb;
4419 IOCB_t *icmd;
4420 RPS_RSP *rps_rsp;
4421 uint8_t *pcmd;
4422 struct lpfc_iocbq *elsiocb;
4423 struct lpfc_nodelist *ndlp;
4424 uint16_t xri, status;
4425 uint32_t cmdsize;
4426
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004427 mb = &pmb->mb;
4428
4429 ndlp = (struct lpfc_nodelist *) pmb->context2;
4430 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004431 pmb->context1 = NULL;
4432 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004433
4434 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004435 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004436 return;
4437 }
4438
4439 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004440 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004441 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4442 lpfc_max_els_tries, ndlp,
4443 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004444
4445 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004446 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004447
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004448 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004449 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004450
4451 icmd = &elsiocb->iocb;
4452 icmd->ulpContext = xri;
4453
4454 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4455 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004456 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004457 rps_rsp = (RPS_RSP *)pcmd;
4458
4459 if (phba->fc_topology != TOPOLOGY_LOOP)
4460 status = 0x10;
4461 else
4462 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004463 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004464 status |= 0x4;
4465
4466 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004467 rps_rsp->portStatus = cpu_to_be16(status);
4468 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4469 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4470 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4471 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4472 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4473 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004474 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004475 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4476 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4477 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4478 elsiocb->iotag, elsiocb->iocb.ulpContext,
4479 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4480 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004481 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004482 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004483 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004484 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004485 return;
4486}
4487
James Smarte59058c2008-08-24 21:49:00 -04004488/**
James Smart3621a712009-04-06 18:47:14 -04004489 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004490 * @vport: pointer to a host virtual N_Port data structure.
4491 * @cmdiocb: pointer to lpfc command iocb data structure.
4492 * @ndlp: pointer to a node-list data structure.
4493 *
4494 * This routine processes Read Port Status (RPS) IOCB received as an
4495 * ELS unsolicited event. It first checks the remote port state. If the
4496 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4497 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4498 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4499 * for reading the HBA link statistics. It is for the callback function,
4500 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4501 * to actually sending out RPS Accept (ACC) response.
4502 *
4503 * Return codes
4504 * 0 - Successfully processed rps iocb (currently always return 0)
4505 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004506static int
James Smart2e0fef82007-06-17 19:56:36 -05004507lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4508 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004509{
James Smart2e0fef82007-06-17 19:56:36 -05004510 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004511 uint32_t *lp;
4512 uint8_t flag;
4513 LPFC_MBOXQ_t *mbox;
4514 struct lpfc_dmabuf *pcmd;
4515 RPS *rps;
4516 struct ls_rjt stat;
4517
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004518 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004519 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4520 /* reject the unsolicited RPS request and done with it */
4521 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004522
4523 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4524 lp = (uint32_t *) pcmd->virt;
4525 flag = (be32_to_cpu(*lp++) & 0xf);
4526 rps = (RPS *) lp;
4527
4528 if ((flag == 0) ||
4529 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004530 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004531 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004532
James Smart92d7f7b2007-06-17 19:56:38 -05004533 printk("Fix me....\n");
4534 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004535 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4536 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004537 lpfc_read_lnk_stat(phba, mbox);
4538 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004539 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004540 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004541 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004542 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004543 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004544 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004545 /* Mbox completion will send ELS Response */
4546 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004547 /* Decrement reference count used for the failed mbox
4548 * command.
4549 */
James Smart329f9bc2007-04-25 09:53:01 -04004550 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004551 mempool_free(mbox, phba->mbox_mem_pool);
4552 }
4553 }
James Smart90160e02008-08-24 21:49:45 -04004554
4555reject_out:
4556 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004557 stat.un.b.lsRjtRsvd0 = 0;
4558 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4559 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4560 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004561 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004562 return 0;
4563}
4564
James Smarte59058c2008-08-24 21:49:00 -04004565/**
James Smart3621a712009-04-06 18:47:14 -04004566 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004567 * @vport: pointer to a host virtual N_Port data structure.
4568 * @cmdsize: size of the ELS command.
4569 * @oldiocb: pointer to the original lpfc command iocb data structure.
4570 * @ndlp: pointer to a node-list data structure.
4571 *
4572 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4573 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4574 *
4575 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4576 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4577 * will be stored into the context1 field of the IOCB for the completion
4578 * callback function to the RPL Accept Response ELS command.
4579 *
4580 * Return code
4581 * 0 - Successfully issued ACC RPL ELS command
4582 * 1 - Failed to issue ACC RPL ELS command
4583 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004584static int
James Smart2e0fef82007-06-17 19:56:36 -05004585lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4586 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004587{
James Smart2e0fef82007-06-17 19:56:36 -05004588 struct lpfc_hba *phba = vport->phba;
4589 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004590 RPL_RSP rpl_rsp;
4591 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004592 uint8_t *pcmd;
4593
James Smart2e0fef82007-06-17 19:56:36 -05004594 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4595 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004596
James Smart488d1462006-03-07 15:02:37 -05004597 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004598 return 1;
James Smart488d1462006-03-07 15:02:37 -05004599
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004600 icmd = &elsiocb->iocb;
4601 oldcmd = &oldiocb->iocb;
4602 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4603
4604 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4605 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004606 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004607 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4608 pcmd += sizeof(uint16_t);
4609
4610 /* Setup the RPL ACC payload */
4611 rpl_rsp.listLen = be32_to_cpu(1);
4612 rpl_rsp.index = 0;
4613 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004614 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4615 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004616 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004617 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004618 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004619 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4620 "0120 Xmit ELS RPL ACC response tag x%x "
4621 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4622 "rpi x%x\n",
4623 elsiocb->iotag, elsiocb->iocb.ulpContext,
4624 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4625 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004626 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004627 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004628 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4629 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004630 lpfc_els_free_iocb(phba, elsiocb);
4631 return 1;
4632 }
4633 return 0;
4634}
4635
James Smarte59058c2008-08-24 21:49:00 -04004636/**
James Smart3621a712009-04-06 18:47:14 -04004637 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004638 * @vport: pointer to a host virtual N_Port data structure.
4639 * @cmdiocb: pointer to lpfc command iocb data structure.
4640 * @ndlp: pointer to a node-list data structure.
4641 *
4642 * This routine processes Read Port List (RPL) IOCB received as an ELS
4643 * unsolicited event. It first checks the remote port state. If the remote
4644 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4645 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4646 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4647 * to accept the RPL.
4648 *
4649 * Return code
4650 * 0 - Successfully processed rpl iocb (currently always return 0)
4651 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004652static int
James Smart2e0fef82007-06-17 19:56:36 -05004653lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4654 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004655{
4656 struct lpfc_dmabuf *pcmd;
4657 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004658 uint32_t maxsize;
4659 uint16_t cmdsize;
4660 RPL *rpl;
4661 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004662
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004663 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4664 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004665 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004666 stat.un.b.lsRjtRsvd0 = 0;
4667 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4668 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4669 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004670 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4671 NULL);
James Smart90160e02008-08-24 21:49:45 -04004672 /* rejected the unsolicited RPL request and done with it */
4673 return 0;
dea31012005-04-17 16:05:31 -05004674 }
4675
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004676 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4677 lp = (uint32_t *) pcmd->virt;
4678 rpl = (RPL *) (lp + 1);
4679
4680 maxsize = be32_to_cpu(rpl->maxsize);
4681
4682 /* We support only one port */
4683 if ((rpl->index == 0) &&
4684 ((maxsize == 0) ||
4685 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4686 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004687 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004688 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4689 }
James Smart2e0fef82007-06-17 19:56:36 -05004690 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004691
4692 return 0;
4693}
4694
James Smarte59058c2008-08-24 21:49:00 -04004695/**
James Smart3621a712009-04-06 18:47:14 -04004696 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004697 * @vport: pointer to a virtual N_Port data structure.
4698 * @cmdiocb: pointer to lpfc command iocb data structure.
4699 * @ndlp: pointer to a node-list data structure.
4700 *
4701 * This routine processes Fibre Channel Address Resolution Protocol
4702 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4703 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4704 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4705 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4706 * remote PortName is compared against the FC PortName stored in the @vport
4707 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4708 * compared against the FC NodeName stored in the @vport data structure.
4709 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4710 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4711 * invoked to send out FARP Response to the remote node. Before sending the
4712 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4713 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4714 * routine is invoked to log into the remote port first.
4715 *
4716 * Return code
4717 * 0 - Either the FARP Match Mode not supported or successfully processed
4718 **/
dea31012005-04-17 16:05:31 -05004719static int
James Smart2e0fef82007-06-17 19:56:36 -05004720lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4721 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004722{
4723 struct lpfc_dmabuf *pcmd;
4724 uint32_t *lp;
4725 IOCB_t *icmd;
4726 FARP *fp;
4727 uint32_t cmd, cnt, did;
4728
4729 icmd = &cmdiocb->iocb;
4730 did = icmd->un.elsreq64.remoteID;
4731 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4732 lp = (uint32_t *) pcmd->virt;
4733
4734 cmd = *lp++;
4735 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004736 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004737 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4738 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004739 /* We will only support match on WWPN or WWNN */
4740 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004741 return 0;
dea31012005-04-17 16:05:31 -05004742 }
4743
4744 cnt = 0;
4745 /* If this FARP command is searching for my portname */
4746 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004747 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004748 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004749 cnt = 1;
4750 }
4751
4752 /* If this FARP command is searching for my nodename */
4753 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004754 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004755 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004756 cnt = 1;
4757 }
4758
4759 if (cnt) {
4760 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4761 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4762 /* Log back into the node before sending the FARP. */
4763 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004764 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004765 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004766 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004767 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05004768 }
4769
4770 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05004771 if (fp->Rflags & FARP_REQUEST_FARPR)
4772 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05004773 }
4774 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004775 return 0;
dea31012005-04-17 16:05:31 -05004776}
4777
James Smarte59058c2008-08-24 21:49:00 -04004778/**
James Smart3621a712009-04-06 18:47:14 -04004779 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04004780 * @vport: pointer to a host virtual N_Port data structure.
4781 * @cmdiocb: pointer to lpfc command iocb data structure.
4782 * @ndlp: pointer to a node-list data structure.
4783 *
4784 * This routine processes Fibre Channel Address Resolution Protocol
4785 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4786 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4787 * the FARP response request.
4788 *
4789 * Return code
4790 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4791 **/
dea31012005-04-17 16:05:31 -05004792static int
James Smart2e0fef82007-06-17 19:56:36 -05004793lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4794 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004795{
4796 struct lpfc_dmabuf *pcmd;
4797 uint32_t *lp;
4798 IOCB_t *icmd;
4799 uint32_t cmd, did;
4800
4801 icmd = &cmdiocb->iocb;
4802 did = icmd->un.elsreq64.remoteID;
4803 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4804 lp = (uint32_t *) pcmd->virt;
4805
4806 cmd = *lp++;
4807 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004808 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4809 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004810 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04004811 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004812
4813 return 0;
4814}
4815
James Smarte59058c2008-08-24 21:49:00 -04004816/**
James Smart3621a712009-04-06 18:47:14 -04004817 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04004818 * @vport: pointer to a host virtual N_Port data structure.
4819 * @cmdiocb: pointer to lpfc command iocb data structure.
4820 * @fan_ndlp: pointer to a node-list data structure.
4821 *
4822 * This routine processes a Fabric Address Notification (FAN) IOCB
4823 * command received as an ELS unsolicited event. The FAN ELS command will
4824 * only be processed on a physical port (i.e., the @vport represents the
4825 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4826 * compared against those in the phba data structure. If any of those is
4827 * different, the lpfc_initial_flogi() routine is invoked to initialize
4828 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4829 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4830 * is invoked to register login to the fabric.
4831 *
4832 * Return code
4833 * 0 - Successfully processed fan iocb (currently always return 0).
4834 **/
dea31012005-04-17 16:05:31 -05004835static int
James Smart2e0fef82007-06-17 19:56:36 -05004836lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4837 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05004838{
James Smart2e0fef82007-06-17 19:56:36 -05004839 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04004840 uint32_t *lp;
4841 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004842
James Smart0d2b6b82008-06-14 22:52:47 -04004843 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4844 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4845 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004846 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04004847 if ((vport == phba->pport) &&
4848 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004849 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04004850 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004851 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04004852 sizeof(struct lpfc_name)))) {
4853 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05004854 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04004855 } else {
4856 /* FAN verified - skip FLOGI */
4857 vport->fc_myDID = vport->fc_prevDID;
4858 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -05004859 }
dea31012005-04-17 16:05:31 -05004860 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004861 return 0;
dea31012005-04-17 16:05:31 -05004862}
4863
James Smarte59058c2008-08-24 21:49:00 -04004864/**
James Smart3621a712009-04-06 18:47:14 -04004865 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04004866 * @ptr: holder for the timer function associated data.
4867 *
4868 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4869 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4870 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4871 * up the worker thread. It is for the worker thread to invoke the routine
4872 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4873 **/
dea31012005-04-17 16:05:31 -05004874void
4875lpfc_els_timeout(unsigned long ptr)
4876{
James Smart2e0fef82007-06-17 19:56:36 -05004877 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4878 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04004879 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05004880 unsigned long iflag;
4881
James Smart2e0fef82007-06-17 19:56:36 -05004882 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04004883 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4884 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05004885 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04004886 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05004887
James Smart5e9d9b82008-06-14 22:52:53 -04004888 if (!tmo_posted)
4889 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05004890 return;
4891}
4892
James Smarte59058c2008-08-24 21:49:00 -04004893/**
James Smart3621a712009-04-06 18:47:14 -04004894 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04004895 * @vport: pointer to a virtual N_Port data structure.
4896 *
4897 * This routine is the actual handler function that processes an ELS timeout
4898 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4899 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4900 * invoking the lpfc_sli_issue_abort_iotag() routine.
4901 **/
dea31012005-04-17 16:05:31 -05004902void
James Smart2e0fef82007-06-17 19:56:36 -05004903lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004904{
James Smart2e0fef82007-06-17 19:56:36 -05004905 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004906 struct lpfc_sli_ring *pring;
4907 struct lpfc_iocbq *tmp_iocb, *piocb;
4908 IOCB_t *cmd = NULL;
4909 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05004910 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05004911 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05004912 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05004913
James Smart2e0fef82007-06-17 19:56:36 -05004914 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004915 timeout = (uint32_t)(phba->fc_ratov << 1);
4916
4917 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05004918
4919 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4920 cmd = &piocb->iocb;
4921
James Smart2e0fef82007-06-17 19:56:36 -05004922 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
4923 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
4924 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05004925 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004926
4927 if (piocb->vport != vport)
4928 continue;
4929
dea31012005-04-17 16:05:31 -05004930 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05004931 if (pcmd)
4932 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05004933
James Smart92d7f7b2007-06-17 19:56:38 -05004934 if (els_command == ELS_CMD_FARP ||
4935 els_command == ELS_CMD_FARPR ||
4936 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05004937 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05004938
dea31012005-04-17 16:05:31 -05004939 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05004940 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05004941 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05004942 else
dea31012005-04-17 16:05:31 -05004943 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05004944 continue;
4945 }
4946
James Smart2e0fef82007-06-17 19:56:36 -05004947 remote_ID = 0xffffffff;
4948 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05004949 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05004950 else {
4951 struct lpfc_nodelist *ndlp;
4952 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04004953 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05004954 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05004955 }
James Smarte8b62012007-08-02 11:10:09 -04004956 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4957 "0127 ELS timeout Data: x%x x%x x%x "
4958 "x%x\n", els_command,
4959 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04004960 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05004961 }
James Smart2e0fef82007-06-17 19:56:36 -05004962 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04004963
James Smart2e0fef82007-06-17 19:56:36 -05004964 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
4965 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05004966}
4967
James Smarte59058c2008-08-24 21:49:00 -04004968/**
James Smart3621a712009-04-06 18:47:14 -04004969 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04004970 * @vport: pointer to a host virtual N_Port data structure.
4971 *
4972 * This routine is used to clean up all the outstanding ELS commands on a
4973 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
4974 * routine. After that, it walks the ELS transmit queue to remove all the
4975 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
4976 * the IOCBs with a non-NULL completion callback function, the callback
4977 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
4978 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
4979 * callback function, the IOCB will simply be released. Finally, it walks
4980 * the ELS transmit completion queue to issue an abort IOCB to any transmit
4981 * completion queue IOCB that is associated with the @vport and is not
4982 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
4983 * part of the discovery state machine) out to HBA by invoking the
4984 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
4985 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
4986 * the IOCBs are aborted when this function returns.
4987 **/
dea31012005-04-17 16:05:31 -05004988void
James Smart2e0fef82007-06-17 19:56:36 -05004989lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004990{
James Smart2534ba72007-04-25 09:52:20 -04004991 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05004992 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04004993 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05004994 struct lpfc_iocbq *tmp_iocb, *piocb;
4995 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004996
4997 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05004998
James Smart2e0fef82007-06-17 19:56:36 -05004999 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005000 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5001 cmd = &piocb->iocb;
5002
5003 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5004 continue;
5005 }
5006
5007 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005008 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5009 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5010 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5011 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005012 continue;
dea31012005-04-17 16:05:31 -05005013
James Smart2e0fef82007-06-17 19:56:36 -05005014 if (piocb->vport != vport)
5015 continue;
5016
James Smart2534ba72007-04-25 09:52:20 -04005017 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005018 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005019 }
5020
5021 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005022 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5023 continue;
5024 }
dea31012005-04-17 16:05:31 -05005025
James Smart2e0fef82007-06-17 19:56:36 -05005026 if (piocb->vport != vport)
5027 continue;
5028
James Smart07951072007-04-25 09:51:38 -04005029 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005030 }
James Smart2e0fef82007-06-17 19:56:36 -05005031 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005032
James Smarta257bf92009-04-06 18:48:10 -04005033 /* Cancell all the IOCBs from the completions list */
5034 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5035 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005036
dea31012005-04-17 16:05:31 -05005037 return;
5038}
5039
James Smarte59058c2008-08-24 21:49:00 -04005040/**
James Smart3621a712009-04-06 18:47:14 -04005041 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005042 * @phba: pointer to lpfc hba data structure.
5043 *
5044 * This routine is used to clean up all the outstanding ELS commands on a
5045 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5046 * routine. After that, it walks the ELS transmit queue to remove all the
5047 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5048 * the IOCBs with the completion callback function associated, the callback
5049 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5050 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5051 * callback function associated, the IOCB will simply be released. Finally,
5052 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5053 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5054 * management plane IOCBs that are not part of the discovery state machine)
5055 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5056 **/
James Smart549e55c2007-08-02 11:09:51 -04005057void
5058lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5059{
5060 LIST_HEAD(completions);
5061 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5062 struct lpfc_iocbq *tmp_iocb, *piocb;
5063 IOCB_t *cmd = NULL;
5064
5065 lpfc_fabric_abort_hba(phba);
5066 spin_lock_irq(&phba->hbalock);
5067 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5068 cmd = &piocb->iocb;
5069 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5070 continue;
5071 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5072 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5073 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5074 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5075 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5076 continue;
5077 list_move_tail(&piocb->list, &completions);
5078 pring->txq_cnt--;
5079 }
5080 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5081 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5082 continue;
5083 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5084 }
5085 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005086
5087 /* Cancel all the IOCBs from the completions list */
5088 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5089 IOERR_SLI_ABORTED);
5090
James Smart549e55c2007-08-02 11:09:51 -04005091 return;
5092}
5093
James Smarte59058c2008-08-24 21:49:00 -04005094/**
James Smart3621a712009-04-06 18:47:14 -04005095 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005096 * @phba: Pointer to hba context object.
5097 * @cmdiocbp: Pointer to command iocb which reported error.
5098 * @rspiocbp: Pointer to response iocb which reported error.
5099 *
5100 * This function sends an event when there is an ELS command
5101 * failure.
5102 **/
5103void
5104lpfc_send_els_failure_event(struct lpfc_hba *phba,
5105 struct lpfc_iocbq *cmdiocbp,
5106 struct lpfc_iocbq *rspiocbp)
5107{
5108 struct lpfc_vport *vport = cmdiocbp->vport;
5109 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5110 struct lpfc_lsrjt_event lsrjt_event;
5111 struct lpfc_fabric_event_header fabric_event;
5112 struct ls_rjt stat;
5113 struct lpfc_nodelist *ndlp;
5114 uint32_t *pcmd;
5115
5116 ndlp = cmdiocbp->context1;
5117 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5118 return;
5119
5120 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5121 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5122 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5123 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5124 sizeof(struct lpfc_name));
5125 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5126 sizeof(struct lpfc_name));
5127 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5128 cmdiocbp->context2)->virt);
5129 lsrjt_event.command = *pcmd;
5130 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5131 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5132 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5133 fc_host_post_vendor_event(shost,
5134 fc_get_event_number(),
5135 sizeof(lsrjt_event),
5136 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005137 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005138 return;
5139 }
5140 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5141 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5142 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5143 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5144 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5145 else
5146 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5147 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5148 sizeof(struct lpfc_name));
5149 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5150 sizeof(struct lpfc_name));
5151 fc_host_post_vendor_event(shost,
5152 fc_get_event_number(),
5153 sizeof(fabric_event),
5154 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005155 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005156 return;
5157 }
5158
5159}
5160
5161/**
James Smart3621a712009-04-06 18:47:14 -04005162 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005163 * @vport: Pointer to vport object.
5164 * @ndlp: Pointer FC node object.
5165 * @cmd: ELS command code.
5166 *
5167 * This function posts an event when there is an incoming
5168 * unsolicited ELS command.
5169 **/
5170static void
5171lpfc_send_els_event(struct lpfc_vport *vport,
5172 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005173 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005174{
James Smartddcc50f2008-12-04 22:38:46 -05005175 struct lpfc_els_event_header *els_data = NULL;
5176 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005177 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5178
James Smartddcc50f2008-12-04 22:38:46 -05005179 if (*payload == ELS_CMD_LOGO) {
5180 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5181 if (!logo_data) {
5182 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5183 "0148 Failed to allocate memory "
5184 "for LOGO event\n");
5185 return;
5186 }
5187 els_data = &logo_data->header;
5188 } else {
5189 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5190 GFP_KERNEL);
5191 if (!els_data) {
5192 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5193 "0149 Failed to allocate memory "
5194 "for ELS event\n");
5195 return;
5196 }
5197 }
5198 els_data->event_type = FC_REG_ELS_EVENT;
5199 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005200 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005201 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005202 break;
5203 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005204 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005205 break;
5206 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005207 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5208 break;
5209 case ELS_CMD_LOGO:
5210 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5211 /* Copy the WWPN in the LOGO payload */
5212 memcpy(logo_data->logo_wwpn, &payload[2],
5213 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005214 break;
5215 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005216 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005217 return;
5218 }
James Smartddcc50f2008-12-04 22:38:46 -05005219 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5220 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5221 if (*payload == ELS_CMD_LOGO) {
5222 fc_host_post_vendor_event(shost,
5223 fc_get_event_number(),
5224 sizeof(struct lpfc_logo_event),
5225 (char *)logo_data,
5226 LPFC_NL_VENDOR_ID);
5227 kfree(logo_data);
5228 } else {
5229 fc_host_post_vendor_event(shost,
5230 fc_get_event_number(),
5231 sizeof(struct lpfc_els_event_header),
5232 (char *)els_data,
5233 LPFC_NL_VENDOR_ID);
5234 kfree(els_data);
5235 }
James Smartea2151b2008-09-07 11:52:10 -04005236
5237 return;
5238}
5239
5240
5241/**
James Smart3621a712009-04-06 18:47:14 -04005242 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005243 * @phba: pointer to lpfc hba data structure.
5244 * @pring: pointer to a SLI ring.
5245 * @vport: pointer to a host virtual N_Port data structure.
5246 * @elsiocb: pointer to lpfc els command iocb data structure.
5247 *
5248 * This routine is used for processing the IOCB associated with a unsolicited
5249 * event. It first determines whether there is an existing ndlp that matches
5250 * the DID from the unsolicited IOCB. If not, it will create a new one with
5251 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5252 * IOCB is then used to invoke the proper routine and to set up proper state
5253 * of the discovery state machine.
5254 **/
James Smarted957682007-06-17 19:56:37 -05005255static void
5256lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005257 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005258{
James Smart87af33f2007-10-27 13:37:43 -04005259 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005260 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005261 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005262 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005263 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005264 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005265
James Smarte47c9092008-02-08 18:49:26 -05005266 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005267 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005268
dea31012005-04-17 16:05:31 -05005269 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005270 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5271 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005272 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005273 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005274
James Smart858c9f62007-06-17 19:56:39 -05005275 did = icmd->un.rcvels.remoteID;
5276 if (icmd->ulpStatus) {
5277 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5278 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5279 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005280 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005281 }
dea31012005-04-17 16:05:31 -05005282
5283 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005284 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005285 goto dropit;
dea31012005-04-17 16:05:31 -05005286
James Smart92d7f7b2007-06-17 19:56:38 -05005287 /* Ignore traffic recevied during vport shutdown. */
5288 if (vport->load_flag & FC_UNLOADING)
5289 goto dropit;
5290
James Smart2e0fef82007-06-17 19:56:36 -05005291 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005292 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005293 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005294 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005295 if (!ndlp)
dea31012005-04-17 16:05:31 -05005296 goto dropit;
dea31012005-04-17 16:05:31 -05005297
James Smart2e0fef82007-06-17 19:56:36 -05005298 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005299 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005300 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005301 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005302 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005303 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5304 ndlp = lpfc_enable_node(vport, ndlp,
5305 NLP_STE_UNUSED_NODE);
5306 if (!ndlp)
5307 goto dropit;
5308 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5309 newnode = 1;
5310 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5311 ndlp->nlp_type |= NLP_FABRIC;
5312 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5313 /* This is similar to the new node path */
5314 ndlp = lpfc_nlp_get(ndlp);
5315 if (!ndlp)
5316 goto dropit;
5317 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5318 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005319 }
dea31012005-04-17 16:05:31 -05005320
5321 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005322
James Smart329f9bc2007-04-25 09:53:01 -04005323 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005324 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005325
5326 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5327 cmd &= ELS_CMD_MASK;
5328 }
5329 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005330 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5331 "0112 ELS command x%x received from NPORT x%x "
5332 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005333 switch (cmd) {
5334 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5336 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5337 did, vport->port_state, ndlp->nlp_flag);
5338
dea31012005-04-17 16:05:31 -05005339 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005340 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5341
James Smartddcc50f2008-12-04 22:38:46 -05005342 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005343 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005344 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5345 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5346 rjt_err = LSRJT_UNABLE_TPC;
5347 break;
5348 }
5349 /* We get here, and drop thru, if we are PT2PT with
5350 * another NPort and the other side has initiated
5351 * the PLOGI before responding to our FLOGI.
5352 */
dea31012005-04-17 16:05:31 -05005353 }
James Smart87af33f2007-10-27 13:37:43 -04005354
5355 shost = lpfc_shost_from_vport(vport);
5356 spin_lock_irq(shost->host_lock);
5357 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5358 spin_unlock_irq(shost->host_lock);
5359
James Smart2e0fef82007-06-17 19:56:36 -05005360 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5361 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005362
dea31012005-04-17 16:05:31 -05005363 break;
5364 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005365 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5366 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5367 did, vport->port_state, ndlp->nlp_flag);
5368
dea31012005-04-17 16:05:31 -05005369 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005370 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005371 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005372 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005373 break;
5374 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005375 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5376 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5377 did, vport->port_state, ndlp->nlp_flag);
5378
dea31012005-04-17 16:05:31 -05005379 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005380 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005381 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005382 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005383 break;
5384 }
James Smart2e0fef82007-06-17 19:56:36 -05005385 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005386 break;
5387 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5389 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5390 did, vport->port_state, ndlp->nlp_flag);
5391
dea31012005-04-17 16:05:31 -05005392 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005393 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005394 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005395 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005396 break;
5397 }
James Smart2e0fef82007-06-17 19:56:36 -05005398 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005399 break;
5400 case ELS_CMD_RSCN:
5401 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005402 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005403 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005404 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005405 break;
5406 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005407 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5408 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5409 did, vport->port_state, ndlp->nlp_flag);
5410
James Smartddcc50f2008-12-04 22:38:46 -05005411 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005412 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005413 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005414 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005415 break;
5416 }
James Smart2e0fef82007-06-17 19:56:36 -05005417 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5418 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005419 break;
5420 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5422 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5423 did, vport->port_state, ndlp->nlp_flag);
5424
dea31012005-04-17 16:05:31 -05005425 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005426 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005427 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005428 break;
5429 }
James Smart2e0fef82007-06-17 19:56:36 -05005430 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5431 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005432 break;
5433 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5435 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5436 did, vport->port_state, ndlp->nlp_flag);
5437
dea31012005-04-17 16:05:31 -05005438 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005439 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005440 break;
5441 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5443 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5444 did, vport->port_state, ndlp->nlp_flag);
5445
dea31012005-04-17 16:05:31 -05005446 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005447 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005448 break;
5449 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005450 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5451 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5452 did, vport->port_state, ndlp->nlp_flag);
5453
dea31012005-04-17 16:05:31 -05005454 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005455 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005456 break;
dea31012005-04-17 16:05:31 -05005457 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005458 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5459 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5460 did, vport->port_state, ndlp->nlp_flag);
5461
dea31012005-04-17 16:05:31 -05005462 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005463 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005464 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005465 break;
5466 }
James Smart2e0fef82007-06-17 19:56:36 -05005467 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005468 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005469 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5471 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5472 did, vport->port_state, ndlp->nlp_flag);
5473
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005474 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005475 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005476 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005477 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005478 break;
5479 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005480 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5481 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5482 did, vport->port_state, ndlp->nlp_flag);
5483
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005484 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005485 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005486 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005487 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005488 break;
5489 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5491 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5492 did, vport->port_state, ndlp->nlp_flag);
5493
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005494 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005495 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005496 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005497 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005498 break;
dea31012005-04-17 16:05:31 -05005499 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5501 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5502 did, vport->port_state, ndlp->nlp_flag);
5503
dea31012005-04-17 16:05:31 -05005504 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005505 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005506 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005507 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005508 break;
5509 default:
James Smart858c9f62007-06-17 19:56:39 -05005510 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5511 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5512 cmd, did, vport->port_state);
5513
dea31012005-04-17 16:05:31 -05005514 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005515 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005516
5517 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005518 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5519 "0115 Unknown ELS command x%x "
5520 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005521 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005522 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005523 break;
5524 }
5525
5526 /* check if need to LS_RJT received ELS cmd */
5527 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005528 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005529 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005530 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005531 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5532 NULL);
dea31012005-04-17 16:05:31 -05005533 }
5534
James Smartd7c255b2008-08-24 21:50:00 -04005535 lpfc_nlp_put(elsiocb->context1);
5536 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005537 return;
5538
5539dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005540 if (vport && !(vport->load_flag & FC_UNLOADING))
5541 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04005542 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005543 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04005544 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04005545 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005546 phba->fc_stat.elsRcvDrop++;
5547}
5548
James Smarte59058c2008-08-24 21:49:00 -04005549/**
James Smart3621a712009-04-06 18:47:14 -04005550 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005551 * @phba: pointer to lpfc hba data structure.
5552 * @vpi: host virtual N_Port identifier.
5553 *
5554 * This routine finds a vport on a HBA (referred by @phba) through a
5555 * @vpi. The function walks the HBA's vport list and returns the address
5556 * of the vport with the matching @vpi.
5557 *
5558 * Return code
5559 * NULL - No vport with the matching @vpi found
5560 * Otherwise - Address to the vport with the matching @vpi.
5561 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005562static struct lpfc_vport *
5563lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5564{
5565 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005566 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005567
James Smart549e55c2007-08-02 11:09:51 -04005568 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005569 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005570 if (vport->vpi == vpi) {
5571 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005572 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005573 }
James Smart92d7f7b2007-06-17 19:56:38 -05005574 }
James Smart549e55c2007-08-02 11:09:51 -04005575 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005576 return NULL;
5577}
James Smarted957682007-06-17 19:56:37 -05005578
James Smarte59058c2008-08-24 21:49:00 -04005579/**
James Smart3621a712009-04-06 18:47:14 -04005580 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005581 * @phba: pointer to lpfc hba data structure.
5582 * @pring: pointer to a SLI ring.
5583 * @elsiocb: pointer to lpfc els iocb data structure.
5584 *
5585 * This routine is used to process an unsolicited event received from a SLI
5586 * (Service Level Interface) ring. The actual processing of the data buffer
5587 * associated with the unsolicited event is done by invoking the routine
5588 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5589 * SLI ring on which the unsolicited event was received.
5590 **/
James Smarted957682007-06-17 19:56:37 -05005591void
5592lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5593 struct lpfc_iocbq *elsiocb)
5594{
5595 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005596 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005597 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005598 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5599 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005600
James Smartd7c255b2008-08-24 21:50:00 -04005601 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005602 elsiocb->context2 = NULL;
5603 elsiocb->context3 = NULL;
5604
5605 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5606 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5607 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5608 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005609 phba->fc_stat.NoRcvBuf++;
5610 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005611 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005612 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005613 return;
5614 }
5615
James Smart92d7f7b2007-06-17 19:56:38 -05005616 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5617 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5618 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5619 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5620 vport = phba->pport;
5621 else {
5622 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
5623 vport = lpfc_find_vport_by_vpid(phba, vpi);
5624 }
5625 }
James Smart7f5f3d02008-02-08 18:50:14 -05005626 /* If there are no BDEs associated
5627 * with this IOCB, there is nothing to do.
5628 */
James Smarted957682007-06-17 19:56:37 -05005629 if (icmd->ulpBdeCount == 0)
5630 return;
5631
James Smart7f5f3d02008-02-08 18:50:14 -05005632 /* type of ELS cmd is first 32bit word
5633 * in packet
5634 */
James Smarted957682007-06-17 19:56:37 -05005635 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005636 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005637 } else {
5638 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5639 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005640 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5641 paddr);
James Smarted957682007-06-17 19:56:37 -05005642 }
5643
James Smart92d7f7b2007-06-17 19:56:38 -05005644 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5645 /*
5646 * The different unsolicited event handlers would tell us
5647 * if they are done with "mp" by setting context2 to NULL.
5648 */
dea31012005-04-17 16:05:31 -05005649 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005650 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5651 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005652 }
James Smarted957682007-06-17 19:56:37 -05005653
5654 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005655 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005656 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005657 elsiocb->context2 = bdeBuf2;
5658 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005659 /* free mp if we are done with it */
5660 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005661 lpfc_in_buf_free(phba, elsiocb->context2);
5662 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005663 }
dea31012005-04-17 16:05:31 -05005664 }
dea31012005-04-17 16:05:31 -05005665}
James Smart92d7f7b2007-06-17 19:56:38 -05005666
James Smarte59058c2008-08-24 21:49:00 -04005667/**
James Smart3621a712009-04-06 18:47:14 -04005668 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005669 * @phba: pointer to lpfc hba data structure.
5670 * @vport: pointer to a virtual N_Port data structure.
5671 *
5672 * This routine issues a Port Login (PLOGI) to the Name Server with
5673 * State Change Request (SCR) for a @vport. This routine will create an
5674 * ndlp for the Name Server associated to the @vport if such node does
5675 * not already exist. The PLOGI to Name Server is issued by invoking the
5676 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5677 * (FDMI) is configured to the @vport, a FDMI node will be created and
5678 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5679 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005680void
5681lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5682{
5683 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5684
5685 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5686 if (!ndlp) {
5687 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5688 if (!ndlp) {
5689 if (phba->fc_topology == TOPOLOGY_LOOP) {
5690 lpfc_disc_start(vport);
5691 return;
5692 }
5693 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005694 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5695 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005696 return;
5697 }
5698 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005699 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5700 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5701 if (!ndlp) {
5702 if (phba->fc_topology == TOPOLOGY_LOOP) {
5703 lpfc_disc_start(vport);
5704 return;
5705 }
5706 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5707 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5708 "0348 NameServer login: node freed\n");
5709 return;
5710 }
James Smart92d7f7b2007-06-17 19:56:38 -05005711 }
James Smart58da1ff2008-04-07 10:15:56 -04005712 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005713
5714 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5715
5716 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5717 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005718 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5719 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005720 return;
5721 }
5722
James Smart3de2a652007-08-02 11:09:59 -04005723 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005724 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5725 GFP_KERNEL);
5726 if (ndlp_fdmi) {
5727 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5728 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005729 lpfc_nlp_set_state(vport, ndlp_fdmi,
5730 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005731 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5732 0);
5733 }
5734 }
5735 return;
5736}
5737
James Smarte59058c2008-08-24 21:49:00 -04005738/**
James Smart3621a712009-04-06 18:47:14 -04005739 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005740 * @phba: pointer to lpfc hba data structure.
5741 * @pmb: pointer to the driver internal queue element for mailbox command.
5742 *
5743 * This routine is the completion callback function to register new vport
5744 * mailbox command. If the new vport mailbox command completes successfully,
5745 * the fabric registration login shall be performed on physical port (the
5746 * new vport created is actually a physical port, with VPI 0) or the port
5747 * login to Name Server for State Change Request (SCR) will be performed
5748 * on virtual port (real virtual port, with VPI greater than 0).
5749 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005750static void
5751lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5752{
5753 struct lpfc_vport *vport = pmb->vport;
5754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5755 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5756 MAILBOX_t *mb = &pmb->mb;
5757
James Smart09372822008-01-11 01:52:54 -05005758 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005759 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005760 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005761
5762 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04005763 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5764 "0915 Register VPI failed: 0x%x\n",
5765 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05005766
5767 switch (mb->mbxStatus) {
5768 case 0x11: /* unsupported feature */
5769 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05005770 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05005771 /* giving up on vport registration */
5772 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5773 spin_lock_irq(shost->host_lock);
5774 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5775 spin_unlock_irq(shost->host_lock);
5776 lpfc_can_disctmo(vport);
5777 break;
5778 default:
5779 /* Try to recover from this error */
5780 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005781 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005782 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005783 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05005784 if (vport->port_type == LPFC_PHYSICAL_PORT)
5785 lpfc_initial_flogi(vport);
5786 else
5787 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005788 break;
5789 }
5790
5791 } else {
5792 if (vport == phba->pport)
5793 lpfc_issue_fabric_reglogin(vport);
5794 else
5795 lpfc_do_scr_ns_plogi(phba, vport);
5796 }
James Smartfa4066b2008-01-11 01:53:27 -05005797
5798 /* Now, we decrement the ndlp reference count held for this
5799 * callback function
5800 */
5801 lpfc_nlp_put(ndlp);
5802
James Smart92d7f7b2007-06-17 19:56:38 -05005803 mempool_free(pmb, phba->mbox_mem_pool);
5804 return;
5805}
5806
James Smarte59058c2008-08-24 21:49:00 -04005807/**
James Smart3621a712009-04-06 18:47:14 -04005808 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04005809 * @phba: pointer to lpfc hba data structure.
5810 * @vport: pointer to a host virtual N_Port data structure.
5811 * @ndlp: pointer to a node-list data structure.
5812 *
5813 * This routine registers the @vport as a new virtual port with a HBA.
5814 * It is done through a registering vpi mailbox command.
5815 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005816static void
James Smart92d7f7b2007-06-17 19:56:38 -05005817lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5818 struct lpfc_nodelist *ndlp)
5819{
James Smart09372822008-01-11 01:52:54 -05005820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005821 LPFC_MBOXQ_t *mbox;
5822
5823 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5824 if (mbox) {
5825 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
5826 mbox->vport = vport;
5827 mbox->context2 = lpfc_nlp_get(ndlp);
5828 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04005829 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005830 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05005831 /* mailbox command not success, decrement ndlp
5832 * reference count for this command
5833 */
5834 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005835 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05005836
James Smarte8b62012007-08-02 11:10:09 -04005837 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5838 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05005839 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005840 }
5841 } else {
James Smarte8b62012007-08-02 11:10:09 -04005842 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5843 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05005844 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005845 }
James Smartfa4066b2008-01-11 01:53:27 -05005846 return;
5847
5848mbox_err_exit:
5849 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5850 spin_lock_irq(shost->host_lock);
5851 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5852 spin_unlock_irq(shost->host_lock);
5853 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005854}
5855
James Smarte59058c2008-08-24 21:49:00 -04005856/**
James Smart3621a712009-04-06 18:47:14 -04005857 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04005858 * @phba: pointer to lpfc hba data structure.
5859 * @cmdiocb: pointer to lpfc command iocb data structure.
5860 * @rspiocb: pointer to lpfc response iocb data structure.
5861 *
5862 * This routine is the completion callback function to a Fabric Discover
5863 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5864 * single threaded, each FDISC completion callback function will reset
5865 * the discovery timer for all vports such that the timers will not get
5866 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5867 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5868 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5869 * assigned to the vport has been changed with the completion of the FDISC
5870 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5871 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5872 * routine is invoked to register new vport with the HBA. Otherwise, the
5873 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5874 * Server for State Change Request (SCR).
5875 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005876static void
5877lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5878 struct lpfc_iocbq *rspiocb)
5879{
5880 struct lpfc_vport *vport = cmdiocb->vport;
5881 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5882 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5883 struct lpfc_nodelist *np;
5884 struct lpfc_nodelist *next_np;
5885 IOCB_t *irsp = &rspiocb->iocb;
5886 struct lpfc_iocbq *piocb;
5887
James Smarte8b62012007-08-02 11:10:09 -04005888 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5889 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5890 irsp->ulpStatus, irsp->un.ulpWord[4],
5891 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05005892 /* Since all FDISCs are being single threaded, we
5893 * must reset the discovery timer for ALL vports
5894 * waiting to send FDISC when one completes.
5895 */
5896 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5897 lpfc_set_disctmo(piocb->vport);
5898 }
5899
James Smart858c9f62007-06-17 19:56:39 -05005900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5901 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
5902 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
5903
James Smart92d7f7b2007-06-17 19:56:38 -05005904 if (irsp->ulpStatus) {
5905 /* Check for retry */
5906 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
5907 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05005908 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04005909 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04005910 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04005911 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04005912 goto fdisc_failed;
5913 }
James Smart92d7f7b2007-06-17 19:56:38 -05005914 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
5915 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05005916 lpfc_nlp_put(ndlp);
5917 /* giving up on FDISC. Cancel discovery timer */
5918 lpfc_can_disctmo(vport);
James Smartd7c255b2008-08-24 21:50:00 -04005919 spin_lock_irq(shost->host_lock);
5920 vport->fc_flag |= FC_FABRIC;
5921 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
5922 vport->fc_flag |= FC_PUBLIC_LOOP;
5923 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005924
James Smartd7c255b2008-08-24 21:50:00 -04005925 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
5926 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
5927 if ((vport->fc_prevDID != vport->fc_myDID) &&
5928 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
5929 /* If our NportID changed, we need to ensure all
5930 * remaining NPORTs get unreg_login'ed so we can
5931 * issue unreg_vpi.
5932 */
5933 list_for_each_entry_safe(np, next_np,
5934 &vport->fc_nodes, nlp_listp) {
5935 if (!NLP_CHK_NODE_ACT(ndlp) ||
5936 (np->nlp_state != NLP_STE_NPR_NODE) ||
5937 !(np->nlp_flag & NLP_NPR_ADISC))
5938 continue;
James Smart09372822008-01-11 01:52:54 -05005939 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04005940 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05005941 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04005942 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05005943 }
James Smartd7c255b2008-08-24 21:50:00 -04005944 lpfc_mbx_unreg_vpi(vport);
5945 spin_lock_irq(shost->host_lock);
5946 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5947 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005948 }
5949
James Smartd7c255b2008-08-24 21:50:00 -04005950 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
5951 lpfc_register_new_vport(phba, vport, ndlp);
5952 else
5953 lpfc_do_scr_ns_plogi(phba, vport);
5954 goto out;
5955fdisc_failed:
5956 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5957 /* Cancel discovery timer */
5958 lpfc_can_disctmo(vport);
5959 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005960out:
5961 lpfc_els_free_iocb(phba, cmdiocb);
5962}
5963
James Smarte59058c2008-08-24 21:49:00 -04005964/**
James Smart3621a712009-04-06 18:47:14 -04005965 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04005966 * @vport: pointer to a virtual N_Port data structure.
5967 * @ndlp: pointer to a node-list data structure.
5968 * @retry: number of retries to the command IOCB.
5969 *
5970 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
5971 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
5972 * routine to issue the IOCB, which makes sure only one outstanding fabric
5973 * IOCB will be sent off HBA at any given time.
5974 *
5975 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5976 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5977 * will be stored into the context1 field of the IOCB for the completion
5978 * callback function to the FDISC ELS command.
5979 *
5980 * Return code
5981 * 0 - Successfully issued fdisc iocb command
5982 * 1 - Failed to issue fdisc iocb command
5983 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005984static int
James Smart92d7f7b2007-06-17 19:56:38 -05005985lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5986 uint8_t retry)
5987{
5988 struct lpfc_hba *phba = vport->phba;
5989 IOCB_t *icmd;
5990 struct lpfc_iocbq *elsiocb;
5991 struct serv_parm *sp;
5992 uint8_t *pcmd;
5993 uint16_t cmdsize;
5994 int did = ndlp->nlp_DID;
5995 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05005996
5997 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
5998 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
5999 ELS_CMD_FDISC);
6000 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006001 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006002 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6003 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006004 return 1;
6005 }
6006
6007 icmd = &elsiocb->iocb;
6008 icmd->un.elsreq64.myID = 0;
6009 icmd->un.elsreq64.fl = 1;
6010
6011 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6012 icmd->ulpCt_h = 1;
6013 icmd->ulpCt_l = 0;
6014
6015 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6016 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6017 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6018 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6019 sp = (struct serv_parm *) pcmd;
6020 /* Setup CSPs accordingly for Fabric */
6021 sp->cmn.e_d_tov = 0;
6022 sp->cmn.w2.r_a_tov = 0;
6023 sp->cls1.classValid = 0;
6024 sp->cls2.seqDelivery = 1;
6025 sp->cls3.seqDelivery = 1;
6026
6027 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6028 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6029 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6030 pcmd += sizeof(uint32_t); /* Port Name */
6031 memcpy(pcmd, &vport->fc_portname, 8);
6032 pcmd += sizeof(uint32_t); /* Node Name */
6033 pcmd += sizeof(uint32_t); /* Node Name */
6034 memcpy(pcmd, &vport->fc_nodename, 8);
6035
6036 lpfc_set_disctmo(vport);
6037
6038 phba->fc_stat.elsXmitFDISC++;
6039 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6040
James Smart858c9f62007-06-17 19:56:39 -05006041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6042 "Issue FDISC: did:x%x",
6043 did, 0, 0);
6044
James Smart92d7f7b2007-06-17 19:56:38 -05006045 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6046 if (rc == IOCB_ERROR) {
6047 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006048 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006049 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6050 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006051 return 1;
6052 }
6053 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6054 vport->port_state = LPFC_FDISC;
6055 return 0;
6056}
6057
James Smarte59058c2008-08-24 21:49:00 -04006058/**
James Smart3621a712009-04-06 18:47:14 -04006059 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006060 * @phba: pointer to lpfc hba data structure.
6061 * @cmdiocb: pointer to lpfc command iocb data structure.
6062 * @rspiocb: pointer to lpfc response iocb data structure.
6063 *
6064 * This routine is the completion callback function to the issuing of a LOGO
6065 * ELS command off a vport. It frees the command IOCB and then decrement the
6066 * reference count held on ndlp for this completion function, indicating that
6067 * the reference to the ndlp is no long needed. Note that the
6068 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6069 * callback function and an additional explicit ndlp reference decrementation
6070 * will trigger the actual release of the ndlp.
6071 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006072static void
6073lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6074 struct lpfc_iocbq *rspiocb)
6075{
6076 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006077 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006078 struct lpfc_nodelist *ndlp;
6079 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006080
6081 irsp = &rspiocb->iocb;
6082 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6083 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6084 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006085
6086 lpfc_els_free_iocb(phba, cmdiocb);
6087 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006088
6089 /* Trigger the release of the ndlp after logo */
6090 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006091}
6092
James Smarte59058c2008-08-24 21:49:00 -04006093/**
James Smart3621a712009-04-06 18:47:14 -04006094 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006095 * @vport: pointer to a virtual N_Port data structure.
6096 * @ndlp: pointer to a node-list data structure.
6097 *
6098 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6099 *
6100 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6101 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6102 * will be stored into the context1 field of the IOCB for the completion
6103 * callback function to the LOGO ELS command.
6104 *
6105 * Return codes
6106 * 0 - Successfully issued logo off the @vport
6107 * 1 - Failed to issue logo off the @vport
6108 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006109int
6110lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6111{
6112 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6113 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006114 IOCB_t *icmd;
6115 struct lpfc_iocbq *elsiocb;
6116 uint8_t *pcmd;
6117 uint16_t cmdsize;
6118
6119 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6120 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6121 ELS_CMD_LOGO);
6122 if (!elsiocb)
6123 return 1;
6124
6125 icmd = &elsiocb->iocb;
6126 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6127 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6128 pcmd += sizeof(uint32_t);
6129
6130 /* Fill in LOGO payload */
6131 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6132 pcmd += sizeof(uint32_t);
6133 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6134
James Smart858c9f62007-06-17 19:56:39 -05006135 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6136 "Issue LOGO npiv did:x%x flg:x%x",
6137 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6138
James Smart92d7f7b2007-06-17 19:56:38 -05006139 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6140 spin_lock_irq(shost->host_lock);
6141 ndlp->nlp_flag |= NLP_LOGO_SND;
6142 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006143 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6144 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006145 spin_lock_irq(shost->host_lock);
6146 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6147 spin_unlock_irq(shost->host_lock);
6148 lpfc_els_free_iocb(phba, elsiocb);
6149 return 1;
6150 }
6151 return 0;
6152}
6153
James Smarte59058c2008-08-24 21:49:00 -04006154/**
James Smart3621a712009-04-06 18:47:14 -04006155 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006156 * @ptr: holder for the timer function associated data.
6157 *
6158 * This routine is invoked by the fabric iocb block timer after
6159 * timeout. It posts the fabric iocb block timeout event by setting the
6160 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6161 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6162 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6163 * posted event WORKER_FABRIC_BLOCK_TMO.
6164 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006165void
6166lpfc_fabric_block_timeout(unsigned long ptr)
6167{
6168 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6169 unsigned long iflags;
6170 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006171
James Smart92d7f7b2007-06-17 19:56:38 -05006172 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6173 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6174 if (!tmo_posted)
6175 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6176 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6177
James Smart5e9d9b82008-06-14 22:52:53 -04006178 if (!tmo_posted)
6179 lpfc_worker_wake_up(phba);
6180 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006181}
6182
James Smarte59058c2008-08-24 21:49:00 -04006183/**
James Smart3621a712009-04-06 18:47:14 -04006184 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006185 * @phba: pointer to lpfc hba data structure.
6186 *
6187 * This routine issues one fabric iocb from the driver internal list to
6188 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6189 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6190 * remove one pending fabric iocb from the driver internal list and invokes
6191 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6192 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006193static void
6194lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6195{
6196 struct lpfc_iocbq *iocb;
6197 unsigned long iflags;
6198 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006199 IOCB_t *cmd;
6200
6201repeat:
6202 iocb = NULL;
6203 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006204 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006205 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6206 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6207 list);
6208 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006209 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006210 atomic_inc(&phba->fabric_iocb_count);
6211 }
6212 spin_unlock_irqrestore(&phba->hbalock, iflags);
6213 if (iocb) {
6214 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6215 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6216 iocb->iocb_flag |= LPFC_IO_FABRIC;
6217
James Smart858c9f62007-06-17 19:56:39 -05006218 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6219 "Fabric sched1: ste:x%x",
6220 iocb->vport->port_state, 0, 0);
6221
James Smart3772a992009-05-22 14:50:54 -04006222 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006223
6224 if (ret == IOCB_ERROR) {
6225 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6226 iocb->fabric_iocb_cmpl = NULL;
6227 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6228 cmd = &iocb->iocb;
6229 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6230 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6231 iocb->iocb_cmpl(phba, iocb, iocb);
6232
6233 atomic_dec(&phba->fabric_iocb_count);
6234 goto repeat;
6235 }
6236 }
6237
6238 return;
6239}
6240
James Smarte59058c2008-08-24 21:49:00 -04006241/**
James Smart3621a712009-04-06 18:47:14 -04006242 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006243 * @phba: pointer to lpfc hba data structure.
6244 *
6245 * This routine unblocks the issuing fabric iocb command. The function
6246 * will clear the fabric iocb block bit and then invoke the routine
6247 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6248 * from the driver internal fabric iocb list.
6249 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006250void
6251lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6252{
6253 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6254
6255 lpfc_resume_fabric_iocbs(phba);
6256 return;
6257}
6258
James Smarte59058c2008-08-24 21:49:00 -04006259/**
James Smart3621a712009-04-06 18:47:14 -04006260 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006261 * @phba: pointer to lpfc hba data structure.
6262 *
6263 * This routine blocks the issuing fabric iocb for a specified amount of
6264 * time (currently 100 ms). This is done by set the fabric iocb block bit
6265 * and set up a timeout timer for 100ms. When the block bit is set, no more
6266 * fabric iocb will be issued out of the HBA.
6267 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006268static void
6269lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6270{
6271 int blocked;
6272
6273 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006274 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006275 if (!blocked)
6276 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6277
6278 return;
6279}
6280
James Smarte59058c2008-08-24 21:49:00 -04006281/**
James Smart3621a712009-04-06 18:47:14 -04006282 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006283 * @phba: pointer to lpfc hba data structure.
6284 * @cmdiocb: pointer to lpfc command iocb data structure.
6285 * @rspiocb: pointer to lpfc response iocb data structure.
6286 *
6287 * This routine is the callback function that is put to the fabric iocb's
6288 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6289 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6290 * function first restores and invokes the original iocb's callback function
6291 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6292 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6293 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006294static void
6295lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6296 struct lpfc_iocbq *rspiocb)
6297{
6298 struct ls_rjt stat;
6299
6300 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6301 BUG();
6302
6303 switch (rspiocb->iocb.ulpStatus) {
6304 case IOSTAT_NPORT_RJT:
6305 case IOSTAT_FABRIC_RJT:
6306 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6307 lpfc_block_fabric_iocbs(phba);
6308 }
6309 break;
6310
6311 case IOSTAT_NPORT_BSY:
6312 case IOSTAT_FABRIC_BSY:
6313 lpfc_block_fabric_iocbs(phba);
6314 break;
6315
6316 case IOSTAT_LS_RJT:
6317 stat.un.lsRjtError =
6318 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6319 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6320 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6321 lpfc_block_fabric_iocbs(phba);
6322 break;
6323 }
6324
6325 if (atomic_read(&phba->fabric_iocb_count) == 0)
6326 BUG();
6327
6328 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6329 cmdiocb->fabric_iocb_cmpl = NULL;
6330 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6331 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6332
6333 atomic_dec(&phba->fabric_iocb_count);
6334 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006335 /* Post any pending iocbs to HBA */
6336 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006337 }
6338}
6339
James Smarte59058c2008-08-24 21:49:00 -04006340/**
James Smart3621a712009-04-06 18:47:14 -04006341 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006342 * @phba: pointer to lpfc hba data structure.
6343 * @iocb: pointer to lpfc command iocb data structure.
6344 *
6345 * This routine is used as the top-level API for issuing a fabric iocb command
6346 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6347 * function makes sure that only one fabric bound iocb will be outstanding at
6348 * any given time. As such, this function will first check to see whether there
6349 * is already an outstanding fabric iocb on the wire. If so, it will put the
6350 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6351 * issued later. Otherwise, it will issue the iocb on the wire and update the
6352 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6353 *
6354 * Note, this implementation has a potential sending out fabric IOCBs out of
6355 * order. The problem is caused by the construction of the "ready" boolen does
6356 * not include the condition that the internal fabric IOCB list is empty. As
6357 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6358 * ahead of the fabric IOCBs in the internal list.
6359 *
6360 * Return code
6361 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6362 * IOCB_ERROR - failed to issue fabric iocb
6363 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006364static int
James Smart92d7f7b2007-06-17 19:56:38 -05006365lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6366{
6367 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006368 int ready;
6369 int ret;
6370
6371 if (atomic_read(&phba->fabric_iocb_count) > 1)
6372 BUG();
6373
6374 spin_lock_irqsave(&phba->hbalock, iflags);
6375 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6376 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6377
James Smart7f5f3d02008-02-08 18:50:14 -05006378 if (ready)
6379 /* Increment fabric iocb count to hold the position */
6380 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006381 spin_unlock_irqrestore(&phba->hbalock, iflags);
6382 if (ready) {
6383 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6384 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6385 iocb->iocb_flag |= LPFC_IO_FABRIC;
6386
James Smart858c9f62007-06-17 19:56:39 -05006387 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6388 "Fabric sched2: ste:x%x",
6389 iocb->vport->port_state, 0, 0);
6390
James Smart3772a992009-05-22 14:50:54 -04006391 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006392
6393 if (ret == IOCB_ERROR) {
6394 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6395 iocb->fabric_iocb_cmpl = NULL;
6396 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6397 atomic_dec(&phba->fabric_iocb_count);
6398 }
6399 } else {
6400 spin_lock_irqsave(&phba->hbalock, iflags);
6401 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6402 spin_unlock_irqrestore(&phba->hbalock, iflags);
6403 ret = IOCB_SUCCESS;
6404 }
6405 return ret;
6406}
6407
James Smarte59058c2008-08-24 21:49:00 -04006408/**
James Smart3621a712009-04-06 18:47:14 -04006409 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006410 * @vport: pointer to a virtual N_Port data structure.
6411 *
6412 * This routine aborts all the IOCBs associated with a @vport from the
6413 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6414 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6415 * list, removes each IOCB associated with the @vport off the list, set the
6416 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6417 * associated with the IOCB.
6418 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006419static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006420{
6421 LIST_HEAD(completions);
6422 struct lpfc_hba *phba = vport->phba;
6423 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006424
6425 spin_lock_irq(&phba->hbalock);
6426 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6427 list) {
6428
6429 if (piocb->vport != vport)
6430 continue;
6431
6432 list_move_tail(&piocb->list, &completions);
6433 }
6434 spin_unlock_irq(&phba->hbalock);
6435
James Smarta257bf92009-04-06 18:48:10 -04006436 /* Cancel all the IOCBs from the completions list */
6437 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6438 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006439}
6440
James Smarte59058c2008-08-24 21:49:00 -04006441/**
James Smart3621a712009-04-06 18:47:14 -04006442 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006443 * @ndlp: pointer to a node-list data structure.
6444 *
6445 * This routine aborts all the IOCBs associated with an @ndlp from the
6446 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6447 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6448 * list, removes each IOCB associated with the @ndlp off the list, set the
6449 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6450 * associated with the IOCB.
6451 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006452void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6453{
6454 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006455 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006456 struct lpfc_iocbq *tmp_iocb, *piocb;
6457 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006458
6459 spin_lock_irq(&phba->hbalock);
6460 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6461 list) {
6462 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6463
6464 list_move_tail(&piocb->list, &completions);
6465 }
6466 }
6467 spin_unlock_irq(&phba->hbalock);
6468
James Smarta257bf92009-04-06 18:48:10 -04006469 /* Cancel all the IOCBs from the completions list */
6470 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6471 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006472}
6473
James Smarte59058c2008-08-24 21:49:00 -04006474/**
James Smart3621a712009-04-06 18:47:14 -04006475 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006476 * @phba: pointer to lpfc hba data structure.
6477 *
6478 * This routine aborts all the IOCBs currently on the driver internal
6479 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6480 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6481 * list, removes IOCBs off the list, set the status feild to
6482 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6483 * the IOCB.
6484 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006485void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6486{
6487 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006488
6489 spin_lock_irq(&phba->hbalock);
6490 list_splice_init(&phba->fabric_iocb_list, &completions);
6491 spin_unlock_irq(&phba->hbalock);
6492
James Smarta257bf92009-04-06 18:48:10 -04006493 /* Cancel all the IOCBs from the completions list */
6494 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6495 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006496}