blob: e9e423f28f8ae97bb809c0ce6fbe6f2209f91bbc [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
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
James Smartda0436e2009-05-22 14:51:39 -040031#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050032#include "lpfc_hw.h"
33#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050041#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050042#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050043
44static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
45 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050046static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
47 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010048static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
49static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
50 struct lpfc_nodelist *ndlp, uint8_t retry);
51static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
52 struct lpfc_iocbq *iocb);
53static void lpfc_register_new_vport(struct lpfc_hba *phba,
54 struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050056
dea31012005-04-17 16:05:31 -050057static int lpfc_max_els_tries = 3;
58
James Smarte59058c2008-08-24 21:49:00 -040059/**
James Smart3621a712009-04-06 18:47:14 -040060 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040061 * @vport: pointer to a host virtual N_Port data structure.
62 *
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
70 * had happened.
71 *
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
76 *
77 * Return codes
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
80 **/
James Smart858c9f62007-06-17 19:56:39 -050081int
James Smart2e0fef82007-06-17 19:56:36 -050082lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050083{
James Smart2e0fef82007-06-17 19:56:36 -050084 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050086 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050087
James Smart2e0fef82007-06-17 19:56:36 -050088 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040089 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050091 return 0;
92
93 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050094 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050095
96 if (!(ha_copy & HA_LATT))
97 return 0;
98
99 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -0400100 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500104
105 /* CLEAR_LA should re-enable link attention events and
106 * we should then imediately take a LATT event. The
107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
109 * events.
110 */
James Smart2e0fef82007-06-17 19:56:36 -0500111 spin_lock_irq(shost->host_lock);
112 vport->fc_flag |= FC_ABORT_DISCOVERY;
113 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500114
James Smart92d7f7b2007-06-17 19:56:38 -0500115 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500116 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500117
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500118 return 1;
dea31012005-04-17 16:05:31 -0500119}
120
James Smarte59058c2008-08-24 21:49:00 -0400121/**
James Smart3621a712009-04-06 18:47:14 -0400122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
130 *
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
144 *
145 * Return code
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
148 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400149struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500150lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
151 uint16_t cmdSize, uint8_t retry,
152 struct lpfc_nodelist *ndlp, uint32_t did,
153 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500154{
James Smart2e0fef82007-06-17 19:56:36 -0500155 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400156 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500157 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
158 struct ulp_bde64 *bpl;
159 IOCB_t *icmd;
160
dea31012005-04-17 16:05:31 -0500161
James Smart2e0fef82007-06-17 19:56:36 -0500162 if (!lpfc_is_link_up(phba))
163 return NULL;
dea31012005-04-17 16:05:31 -0500164
dea31012005-04-17 16:05:31 -0500165 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400166 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500167
168 if (elsiocb == NULL)
169 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500170
James Smart0c287582009-06-10 17:22:56 -0400171 /*
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
174 */
175 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400176 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400177 ((elscmd == ELS_CMD_FLOGI) ||
178 (elscmd == ELS_CMD_FDISC) ||
179 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500180 switch (elscmd) {
181 case ELS_CMD_FLOGI:
182 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
183 & LPFC_FIP_ELS_ID_MASK);
184 break;
185 case ELS_CMD_FDISC:
186 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
187 & LPFC_FIP_ELS_ID_MASK);
188 break;
189 case ELS_CMD_LOGO:
190 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
191 & LPFC_FIP_ELS_ID_MASK);
192 break;
193 }
James Smart0c287582009-06-10 17:22:56 -0400194 else
James Smartc8685952009-11-18 15:39:16 -0500195 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400196
dea31012005-04-17 16:05:31 -0500197 icmd = &elsiocb->iocb;
198
199 /* fill in BDEs for command */
200 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400201 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
202 if (pcmd)
203 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500204 if (!pcmd || !pcmd->virt)
205 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500206
207 INIT_LIST_HEAD(&pcmd->list);
208
209 /* Allocate buffer for response payload */
210 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500211 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500212 if (prsp)
213 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
214 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500215 if (!prsp || !prsp->virt)
216 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500217 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500218 } else
dea31012005-04-17 16:05:31 -0500219 prsp = NULL;
dea31012005-04-17 16:05:31 -0500220
221 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500222 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500223 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500224 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
225 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500226 if (!pbuflist || !pbuflist->virt)
227 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500228
229 INIT_LIST_HEAD(&pbuflist->list);
230
231 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
232 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400233 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500234 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500235 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500236 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500237 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400238 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500239 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500240 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500241 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
242 }
dea31012005-04-17 16:05:31 -0500243 icmd->ulpBdeCount = 1;
244 icmd->ulpLe = 1;
245 icmd->ulpClass = CLASS3;
246
James Smart92d7f7b2007-06-17 19:56:38 -0500247 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
248 icmd->un.elsreq64.myID = vport->fc_myDID;
249
250 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400251 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500252 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500253 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
254 if (elscmd == ELS_CMD_ECHO)
255 icmd->ulpCt_l = 0; /* context = invalid RPI */
256 else
257 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500258 }
259
dea31012005-04-17 16:05:31 -0500260 bpl = (struct ulp_bde64 *) pbuflist->virt;
261 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
262 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
263 bpl->tus.f.bdeSize = cmdSize;
264 bpl->tus.f.bdeFlags = 0;
265 bpl->tus.w = le32_to_cpu(bpl->tus.w);
266
267 if (expectRsp) {
268 bpl++;
269 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
270 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
271 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400272 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500273 bpl->tus.w = le32_to_cpu(bpl->tus.w);
274 }
275
James Smartfa4066b2008-01-11 01:53:27 -0500276 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400277 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500278 if (!elsiocb->context1)
279 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400280 elsiocb->context2 = pcmd;
281 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500282 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500283 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500284 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
285
286 if (prsp) {
287 list_add(&prsp->list, &pcmd->list);
288 }
dea31012005-04-17 16:05:31 -0500289 if (expectRsp) {
290 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400291 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
292 "0116 Xmit ELS command x%x to remote "
293 "NPORT x%x I/O tag: x%x, port state: x%x\n",
294 elscmd, did, elsiocb->iotag,
295 vport->port_state);
dea31012005-04-17 16:05:31 -0500296 } else {
297 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400298 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
299 "0117 Xmit ELS response x%x to remote "
300 "NPORT x%x I/O tag: x%x, size: x%x\n",
301 elscmd, ndlp->nlp_DID, elsiocb->iotag,
302 cmdSize);
dea31012005-04-17 16:05:31 -0500303 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500304 return elsiocb;
dea31012005-04-17 16:05:31 -0500305
James Smartfa4066b2008-01-11 01:53:27 -0500306els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500307 if (expectRsp)
308 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500309 kfree(pbuflist);
310
311els_iocb_free_prsp_exit:
312 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
313 kfree(prsp);
314
315els_iocb_free_pcmb_exit:
316 kfree(pcmd);
317 lpfc_sli_release_iocbq(phba, elsiocb);
318 return NULL;
319}
dea31012005-04-17 16:05:31 -0500320
James Smarte59058c2008-08-24 21:49:00 -0400321/**
James Smart3621a712009-04-06 18:47:14 -0400322 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400323 * @vport: pointer to a host virtual N_Port data structure.
324 *
325 * This routine issues a fabric registration login for a @vport. An
326 * active ndlp node with Fabric_DID must already exist for this @vport.
327 * The routine invokes two mailbox commands to carry out fabric registration
328 * login through the HBA firmware: the first mailbox command requests the
329 * HBA to perform link configuration for the @vport; and the second mailbox
330 * command requests the HBA to perform the actual fabric registration login
331 * with the @vport.
332 *
333 * Return code
334 * 0 - successfully issued fabric registration login for @vport
335 * -ENXIO -- failed to issue fabric registration login for @vport
336 **/
James Smart3772a992009-05-22 14:50:54 -0400337int
James Smart92d7f7b2007-06-17 19:56:38 -0500338lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
339{
340 struct lpfc_hba *phba = vport->phba;
341 LPFC_MBOXQ_t *mbox;
342 struct lpfc_dmabuf *mp;
343 struct lpfc_nodelist *ndlp;
344 struct serv_parm *sp;
345 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400346 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500347
348 sp = &phba->fc_fabparam;
349 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500350 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400351 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500352 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400353 }
James Smart92d7f7b2007-06-17 19:56:38 -0500354
355 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400356 if (!mbox) {
357 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500358 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400359 }
James Smart92d7f7b2007-06-17 19:56:38 -0500360
361 vport->port_state = LPFC_FABRIC_CFG_LINK;
362 lpfc_config_link(phba, mbox);
363 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
364 mbox->vport = vport;
365
James Smart0b727fe2007-10-27 13:37:25 -0400366 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400367 if (rc == MBX_NOT_FINISHED) {
368 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500369 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400370 }
James Smart92d7f7b2007-06-17 19:56:38 -0500371
372 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400373 if (!mbox) {
374 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500375 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400376 }
James Smart3772a992009-05-22 14:50:54 -0400377 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400378 if (rc) {
379 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500380 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400381 }
James Smart92d7f7b2007-06-17 19:56:38 -0500382
383 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
384 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500385 /* increment the reference count on ndlp to hold reference
386 * for the callback routine.
387 */
James Smart92d7f7b2007-06-17 19:56:38 -0500388 mbox->context2 = lpfc_nlp_get(ndlp);
389
James Smart0b727fe2007-10-27 13:37:25 -0400390 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400391 if (rc == MBX_NOT_FINISHED) {
392 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500393 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400394 }
James Smart92d7f7b2007-06-17 19:56:38 -0500395
396 return 0;
397
398fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500399 /* decrement the reference count on ndlp just incremented
400 * for the failed mbox command.
401 */
James Smart92d7f7b2007-06-17 19:56:38 -0500402 lpfc_nlp_put(ndlp);
403 mp = (struct lpfc_dmabuf *) mbox->context1;
404 lpfc_mbuf_free(phba, mp->virt, mp->phys);
405 kfree(mp);
406fail_free_mbox:
407 mempool_free(mbox, phba->mbox_mem_pool);
408
409fail:
410 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400411 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400412 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500413 return -ENXIO;
414}
415
James Smarte59058c2008-08-24 21:49:00 -0400416/**
James Smart6fb120a2009-05-22 14:52:59 -0400417 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
418 * @vport: pointer to a host virtual N_Port data structure.
419 *
420 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
421 * the @vport. This mailbox command is necessary for FCoE only.
422 *
423 * Return code
424 * 0 - successfully issued REG_VFI for @vport
425 * A failure code otherwise.
426 **/
427static int
428lpfc_issue_reg_vfi(struct lpfc_vport *vport)
429{
430 struct lpfc_hba *phba = vport->phba;
431 LPFC_MBOXQ_t *mboxq;
432 struct lpfc_nodelist *ndlp;
433 struct serv_parm *sp;
434 struct lpfc_dmabuf *dmabuf;
435 int rc = 0;
436
437 sp = &phba->fc_fabparam;
438 ndlp = lpfc_findnode_did(vport, Fabric_DID);
439 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
440 rc = -ENODEV;
441 goto fail;
442 }
443
444 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
445 if (!dmabuf) {
446 rc = -ENOMEM;
447 goto fail;
448 }
449 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
450 if (!dmabuf->virt) {
451 rc = -ENOMEM;
452 goto fail_free_dmabuf;
453 }
454 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
455 if (!mboxq) {
456 rc = -ENOMEM;
457 goto fail_free_coherent;
458 }
459 vport->port_state = LPFC_FABRIC_CFG_LINK;
460 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
461 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
462 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
463 mboxq->vport = vport;
464 mboxq->context1 = dmabuf;
465 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
466 if (rc == MBX_NOT_FINISHED) {
467 rc = -ENXIO;
468 goto fail_free_mbox;
469 }
470 return 0;
471
472fail_free_mbox:
473 mempool_free(mboxq, phba->mbox_mem_pool);
474fail_free_coherent:
475 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
476fail_free_dmabuf:
477 kfree(dmabuf);
478fail:
479 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
480 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
481 "0289 Issue Register VFI failed: Err %d\n", rc);
482 return rc;
483}
484
485/**
James Smart3621a712009-04-06 18:47:14 -0400486 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400487 * @vport: pointer to a host virtual N_Port data structure.
488 * @ndlp: pointer to a node-list data structure.
489 * @sp: pointer to service parameter data structure.
490 * @irsp: pointer to the IOCB within the lpfc response IOCB.
491 *
492 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
493 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
494 * port in a fabric topology. It properly sets up the parameters to the @ndlp
495 * from the IOCB response. It also check the newly assigned N_Port ID to the
496 * @vport against the previously assigned N_Port ID. If it is different from
497 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
498 * is invoked on all the remaining nodes with the @vport to unregister the
499 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
500 * is invoked to register login to the fabric.
501 *
502 * Return code
503 * 0 - Success (currently, always return 0)
504 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500505static int
James Smart2e0fef82007-06-17 19:56:36 -0500506lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
507 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500508{
James Smart2e0fef82007-06-17 19:56:36 -0500509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
510 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500511 struct lpfc_nodelist *np;
512 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500513
James Smart2e0fef82007-06-17 19:56:36 -0500514 spin_lock_irq(shost->host_lock);
515 vport->fc_flag |= FC_FABRIC;
516 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500517
518 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
519 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
520 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
521
522 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
523
524 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500525 spin_lock_irq(shost->host_lock);
526 vport->fc_flag |= FC_PUBLIC_LOOP;
527 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500528 } else {
529 /*
530 * If we are a N-port connected to a Fabric, fixup sparam's so
531 * logins to devices on remote loops work.
532 */
James Smart2e0fef82007-06-17 19:56:36 -0500533 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500534 }
535
James Smart2e0fef82007-06-17 19:56:36 -0500536 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500537 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500538 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500539 ndlp->nlp_class_sup = 0;
540 if (sp->cls1.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS1;
542 if (sp->cls2.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS2;
544 if (sp->cls3.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS3;
546 if (sp->cls4.classValid)
547 ndlp->nlp_class_sup |= FC_COS_CLASS4;
548 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
549 sp->cmn.bbRcvSizeLsb;
550 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
551
James Smart92d7f7b2007-06-17 19:56:38 -0500552 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
553 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400554 lpfc_printf_vlog(vport, KERN_WARNING,
555 LOG_ELS | LOG_VPORT,
556 "1816 FLOGI NPIV supported, "
557 "response data 0x%x\n",
558 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500559 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500560 } else {
561 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400562 to call reg_vnpid atleast for the physcial host */
563 lpfc_printf_vlog(vport, KERN_WARNING,
564 LOG_ELS | LOG_VPORT,
565 "1817 Fabric does not support NPIV "
566 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500567 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
568 }
569 }
570
571 if ((vport->fc_prevDID != vport->fc_myDID) &&
572 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
573
574 /* If our NportID changed, we need to ensure all
575 * remaining NPORTs get unreg_login'ed.
576 */
577 list_for_each_entry_safe(np, next_np,
578 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400579 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500580 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500581 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
582 !(np->nlp_flag & NLP_NPR_ADISC))
583 continue;
584 spin_lock_irq(shost->host_lock);
585 np->nlp_flag &= ~NLP_NPR_ADISC;
586 spin_unlock_irq(shost->host_lock);
587 lpfc_unreg_rpi(vport, np);
588 }
589 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
590 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500591 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500592 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500593 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500594 }
595 }
596
James Smart6fb120a2009-05-22 14:52:59 -0400597 if (phba->sli_rev < LPFC_SLI_REV4) {
598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
599 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
600 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
601 lpfc_register_new_vport(phba, vport, ndlp);
602 else
603 lpfc_issue_fabric_reglogin(vport);
604 } else {
605 ndlp->nlp_type |= NLP_FABRIC;
606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartc8685952009-11-18 15:39:16 -0500607 if (vport->vpi_state & LPFC_VPI_REGISTERED) {
James Smart6fb120a2009-05-22 14:52:59 -0400608 lpfc_start_fdiscs(phba);
609 lpfc_do_scr_ns_plogi(phba, vport);
610 } else
611 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500612 }
dea31012005-04-17 16:05:31 -0500613 return 0;
dea31012005-04-17 16:05:31 -0500614}
James Smarte59058c2008-08-24 21:49:00 -0400615/**
James Smart3621a712009-04-06 18:47:14 -0400616 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400617 * @vport: pointer to a host virtual N_Port data structure.
618 * @ndlp: pointer to a node-list data structure.
619 * @sp: pointer to service parameter data structure.
620 *
621 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
622 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
623 * in a point-to-point topology. First, the @vport's N_Port Name is compared
624 * with the received N_Port Name: if the @vport's N_Port Name is greater than
625 * the received N_Port Name lexicographically, this node shall assign local
626 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
627 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
628 * this node shall just wait for the remote node to issue PLOGI and assign
629 * N_Port IDs.
630 *
631 * Return code
632 * 0 - Success
633 * -ENXIO - Fail
634 **/
dea31012005-04-17 16:05:31 -0500635static int
James Smart2e0fef82007-06-17 19:56:36 -0500636lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
637 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500638{
James Smart2e0fef82007-06-17 19:56:36 -0500639 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
640 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500641 LPFC_MBOXQ_t *mbox;
642 int rc;
643
James Smart2e0fef82007-06-17 19:56:36 -0500644 spin_lock_irq(shost->host_lock);
645 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
646 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500647
648 phba->fc_edtov = FF_DEF_EDTOV;
649 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500650 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500651 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500652 if (rc >= 0) {
653 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500654 spin_lock_irq(shost->host_lock);
655 vport->fc_flag |= FC_PT2PT_PLOGI;
656 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500657
658 /*
659 * N_Port ID cannot be 0, set our to LocalID the other
660 * side will be RemoteID.
661 */
662
663 /* not equal */
664 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500665 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500666
667 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
668 if (!mbox)
669 goto fail;
670
671 lpfc_config_link(phba, mbox);
672
673 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500674 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400675 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500676 if (rc == MBX_NOT_FINISHED) {
677 mempool_free(mbox, phba->mbox_mem_pool);
678 goto fail;
679 }
James Smarte47c9092008-02-08 18:49:26 -0500680 /* Decrement ndlp reference count indicating that ndlp can be
681 * safely released when other references to it are done.
682 */
James Smart329f9bc2007-04-25 09:53:01 -0400683 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500684
James Smart2e0fef82007-06-17 19:56:36 -0500685 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500686 if (!ndlp) {
687 /*
688 * Cannot find existing Fabric ndlp, so allocate a
689 * new one
690 */
691 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
692 if (!ndlp)
693 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500694 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500695 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
696 ndlp = lpfc_enable_node(vport, ndlp,
697 NLP_STE_UNUSED_NODE);
698 if(!ndlp)
699 goto fail;
dea31012005-04-17 16:05:31 -0500700 }
701
702 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500703 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500704 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500705 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500706 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500707 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
708 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500709 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500710 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500711 } else
712 /* This side will wait for the PLOGI, decrement ndlp reference
713 * count indicating that ndlp can be released when other
714 * references to it are done.
715 */
James Smart329f9bc2007-04-25 09:53:01 -0400716 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500717
James Smart09372822008-01-11 01:52:54 -0500718 /* If we are pt2pt with another NPort, force NPIV off! */
719 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
720
James Smart2e0fef82007-06-17 19:56:36 -0500721 spin_lock_irq(shost->host_lock);
722 vport->fc_flag |= FC_PT2PT;
723 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500724
725 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500726 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500727 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500728fail:
dea31012005-04-17 16:05:31 -0500729 return -ENXIO;
730}
731
James Smarte59058c2008-08-24 21:49:00 -0400732/**
James Smart3621a712009-04-06 18:47:14 -0400733 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400734 * @phba: pointer to lpfc hba data structure.
735 * @cmdiocb: pointer to lpfc command iocb data structure.
736 * @rspiocb: pointer to lpfc response iocb data structure.
737 *
738 * This routine is the top-level completion callback function for issuing
739 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
740 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
741 * retry has been made (either immediately or delayed with lpfc_els_retry()
742 * returning 1), the command IOCB will be released and function returned.
743 * If the retry attempt has been given up (possibly reach the maximum
744 * number of retries), one additional decrement of ndlp reference shall be
745 * invoked before going out after releasing the command IOCB. This will
746 * actually release the remote node (Note, lpfc_els_free_iocb() will also
747 * invoke one decrement of ndlp reference count). If no error reported in
748 * the IOCB status, the command Port ID field is used to determine whether
749 * this is a point-to-point topology or a fabric topology: if the Port ID
750 * field is assigned, it is a fabric topology; otherwise, it is a
751 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
752 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
753 * specific topology completion conditions.
754 **/
dea31012005-04-17 16:05:31 -0500755static void
James Smart329f9bc2007-04-25 09:53:01 -0400756lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
757 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500758{
James Smart2e0fef82007-06-17 19:56:36 -0500759 struct lpfc_vport *vport = cmdiocb->vport;
760 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500761 IOCB_t *irsp = &rspiocb->iocb;
762 struct lpfc_nodelist *ndlp = cmdiocb->context1;
763 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
764 struct serv_parm *sp;
765 int rc;
766
767 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500768 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500769 /* One additional decrement on node reference count to
770 * trigger the release of the node
771 */
James Smart329f9bc2007-04-25 09:53:01 -0400772 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500773 goto out;
774 }
775
James Smart858c9f62007-06-17 19:56:39 -0500776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
777 "FLOGI cmpl: status:x%x/x%x state:x%x",
778 irsp->ulpStatus, irsp->un.ulpWord[4],
779 vport->port_state);
780
dea31012005-04-17 16:05:31 -0500781 if (irsp->ulpStatus) {
782 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500783 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500784 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500785
dea31012005-04-17 16:05:31 -0500786 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500787 spin_lock_irq(shost->host_lock);
788 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
789 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500790
James Smart329f9bc2007-04-25 09:53:01 -0400791 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500792 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
793 * alpa map would take too long otherwise.
794 */
795 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400796 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500797 }
798
799 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400800 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
801 "0100 FLOGI failure Data: x%x x%x "
802 "x%x\n",
803 irsp->ulpStatus, irsp->un.ulpWord[4],
804 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500805 goto flogifail;
806 }
807
808 /*
809 * The FLogI succeeded. Sync the data for the CPU before
810 * accessing it.
811 */
812 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
813
814 sp = prsp->virt + sizeof(uint32_t);
815
816 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
818 "0101 FLOGI completes sucessfully "
819 "Data: x%x x%x x%x x%x\n",
820 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
821 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500822
James Smart2e0fef82007-06-17 19:56:36 -0500823 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500824 /*
825 * If Common Service Parameters indicate Nport
826 * we are point to point, if Fport we are Fabric.
827 */
828 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500829 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500830 else
James Smart2e0fef82007-06-17 19:56:36 -0500831 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500832
833 if (!rc)
834 goto out;
835 }
836
837flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400838 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500839
James Smart858c9f62007-06-17 19:56:39 -0500840 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500841 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500842 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500843
844 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500845 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400846 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
847 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
848 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
849 (phba->link_state != LPFC_CLEAR_LA)) {
850 /* If FLOGI failed enable link interrupt. */
851 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500852 }
dea31012005-04-17 16:05:31 -0500853out:
854 lpfc_els_free_iocb(phba, cmdiocb);
855}
856
James Smarte59058c2008-08-24 21:49:00 -0400857/**
James Smart3621a712009-04-06 18:47:14 -0400858 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400859 * @vport: pointer to a host virtual N_Port data structure.
860 * @ndlp: pointer to a node-list data structure.
861 * @retry: number of retries to the command IOCB.
862 *
863 * This routine issues a Fabric Login (FLOGI) Request ELS command
864 * for a @vport. The initiator service parameters are put into the payload
865 * of the FLOGI Request IOCB and the top-level callback function pointer
866 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
867 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
868 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
869 *
870 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
871 * will be incremented by 1 for holding the ndlp and the reference to ndlp
872 * will be stored into the context1 field of the IOCB for the completion
873 * callback function to the FLOGI ELS command.
874 *
875 * Return code
876 * 0 - successfully issued flogi iocb for @vport
877 * 1 - failed to issue flogi iocb for @vport
878 **/
dea31012005-04-17 16:05:31 -0500879static int
James Smart2e0fef82007-06-17 19:56:36 -0500880lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500881 uint8_t retry)
882{
James Smart2e0fef82007-06-17 19:56:36 -0500883 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500884 struct serv_parm *sp;
885 IOCB_t *icmd;
886 struct lpfc_iocbq *elsiocb;
887 struct lpfc_sli_ring *pring;
888 uint8_t *pcmd;
889 uint16_t cmdsize;
890 uint32_t tmo;
891 int rc;
892
893 pring = &phba->sli.ring[LPFC_ELS_RING];
894
James Smart92d7f7b2007-06-17 19:56:38 -0500895 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500896 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
897 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500898
James Smart488d1462006-03-07 15:02:37 -0500899 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500900 return 1;
dea31012005-04-17 16:05:31 -0500901
902 icmd = &elsiocb->iocb;
903 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
904
905 /* For FLOGI request, remainder of payload is service parameters */
906 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500907 pcmd += sizeof(uint32_t);
908 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500909 sp = (struct serv_parm *) pcmd;
910
911 /* Setup CSPs accordingly for Fabric */
912 sp->cmn.e_d_tov = 0;
913 sp->cmn.w2.r_a_tov = 0;
914 sp->cls1.classValid = 0;
915 sp->cls2.seqDelivery = 1;
916 sp->cls3.seqDelivery = 1;
917 if (sp->cmn.fcphLow < FC_PH3)
918 sp->cmn.fcphLow = FC_PH3;
919 if (sp->cmn.fcphHigh < FC_PH3)
920 sp->cmn.fcphHigh = FC_PH3;
921
James Smart6fb120a2009-05-22 14:52:59 -0400922 if (phba->sli_rev == LPFC_SLI_REV4) {
923 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
924 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
925 /* FLOGI needs to be 3 for WQE FCFI */
926 /* Set the fcfi to the fcfi we registered with */
927 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
928 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500929 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500930 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
931 icmd->ulpCt_h = 1;
932 icmd->ulpCt_l = 0;
933 }
934
James Smart858c9f62007-06-17 19:56:39 -0500935 if (phba->fc_topology != TOPOLOGY_LOOP) {
936 icmd->un.elsreq64.myID = 0;
937 icmd->un.elsreq64.fl = 1;
938 }
939
dea31012005-04-17 16:05:31 -0500940 tmo = phba->fc_ratov;
941 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500942 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500943 phba->fc_ratov = tmo;
944
945 phba->fc_stat.elsXmitFLOGI++;
946 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500947
948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
949 "Issue FLOGI: opt:x%x",
950 phba->sli3_options, 0, 0);
951
James Smart92d7f7b2007-06-17 19:56:38 -0500952 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500953 if (rc == IOCB_ERROR) {
954 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500955 return 1;
dea31012005-04-17 16:05:31 -0500956 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500957 return 0;
dea31012005-04-17 16:05:31 -0500958}
959
James Smarte59058c2008-08-24 21:49:00 -0400960/**
James Smart3621a712009-04-06 18:47:14 -0400961 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -0400962 * @phba: pointer to lpfc hba data structure.
963 *
964 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
965 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
966 * list and issues an abort IOCB commond on each outstanding IOCB that
967 * contains a active Fabric_DID ndlp. Note that this function is to issue
968 * the abort IOCB command on all the outstanding IOCBs, thus when this
969 * function returns, it does not guarantee all the IOCBs are actually aborted.
970 *
971 * Return code
972 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
973 **/
dea31012005-04-17 16:05:31 -0500974int
James Smart2e0fef82007-06-17 19:56:36 -0500975lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500976{
977 struct lpfc_sli_ring *pring;
978 struct lpfc_iocbq *iocb, *next_iocb;
979 struct lpfc_nodelist *ndlp;
980 IOCB_t *icmd;
981
982 /* Abort outstanding I/O on NPort <nlp_DID> */
983 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400984 "0201 Abort outstanding I/O on NPort x%x\n",
985 Fabric_DID);
dea31012005-04-17 16:05:31 -0500986
987 pring = &phba->sli.ring[LPFC_ELS_RING];
988
989 /*
990 * Check the txcmplq for an iocb that matches the nport the driver is
991 * searching for.
992 */
James Smart2e0fef82007-06-17 19:56:36 -0500993 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500994 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
995 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500996 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
997 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500998 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -0400999 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1000 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001001 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001002 }
1003 }
James Smart2e0fef82007-06-17 19:56:36 -05001004 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001005
1006 return 0;
1007}
1008
James Smarte59058c2008-08-24 21:49:00 -04001009/**
James Smart3621a712009-04-06 18:47:14 -04001010 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001011 * @vport: pointer to a host virtual N_Port data structure.
1012 *
1013 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1014 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1015 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1016 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1017 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1018 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1019 * @vport.
1020 *
1021 * Return code
1022 * 0 - failed to issue initial flogi for @vport
1023 * 1 - successfully issued initial flogi for @vport
1024 **/
dea31012005-04-17 16:05:31 -05001025int
James Smart2e0fef82007-06-17 19:56:36 -05001026lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001027{
James Smart2e0fef82007-06-17 19:56:36 -05001028 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001029 struct lpfc_nodelist *ndlp;
1030
James Smart98c9ea52007-10-27 13:37:33 -04001031 vport->port_state = LPFC_FLOGI;
1032 lpfc_set_disctmo(vport);
1033
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001034 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001035 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001036 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001037 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001038 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1039 if (!ndlp)
1040 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001041 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001042 /* Set the node type */
1043 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001044 /* Put ndlp onto node list */
1045 lpfc_enqueue_node(vport, ndlp);
1046 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1047 /* re-setup ndlp without removing from node list */
1048 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1049 if (!ndlp)
1050 return 0;
dea31012005-04-17 16:05:31 -05001051 }
James Smart87af33f2007-10-27 13:37:43 -04001052
James Smarte47c9092008-02-08 18:49:26 -05001053 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001054 /* This decrement of reference count to node shall kick off
1055 * the release of the node.
1056 */
James Smart329f9bc2007-04-25 09:53:01 -04001057 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001058
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001059 return 1;
dea31012005-04-17 16:05:31 -05001060}
1061
James Smarte59058c2008-08-24 21:49:00 -04001062/**
James Smart3621a712009-04-06 18:47:14 -04001063 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001064 * @vport: pointer to a host virtual N_Port data structure.
1065 *
1066 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1067 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1068 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1069 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1070 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1071 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1072 * @vport.
1073 *
1074 * Return code
1075 * 0 - failed to issue initial fdisc for @vport
1076 * 1 - successfully issued initial fdisc for @vport
1077 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001078int
1079lpfc_initial_fdisc(struct lpfc_vport *vport)
1080{
1081 struct lpfc_hba *phba = vport->phba;
1082 struct lpfc_nodelist *ndlp;
1083
1084 /* First look for the Fabric ndlp */
1085 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1086 if (!ndlp) {
1087 /* Cannot find existing Fabric ndlp, so allocate a new one */
1088 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1089 if (!ndlp)
1090 return 0;
1091 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001092 /* Put ndlp onto node list */
1093 lpfc_enqueue_node(vport, ndlp);
1094 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1095 /* re-setup ndlp without removing from node list */
1096 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1097 if (!ndlp)
1098 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001099 }
James Smarte47c9092008-02-08 18:49:26 -05001100
James Smart92d7f7b2007-06-17 19:56:38 -05001101 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001102 /* decrement node reference count to trigger the release of
1103 * the node.
1104 */
James Smart92d7f7b2007-06-17 19:56:38 -05001105 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001106 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001107 }
1108 return 1;
1109}
James Smart87af33f2007-10-27 13:37:43 -04001110
James Smarte59058c2008-08-24 21:49:00 -04001111/**
James Smart3621a712009-04-06 18:47:14 -04001112 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001113 * @vport: pointer to a host virtual N_Port data structure.
1114 *
1115 * This routine checks whether there are more remaining Port Logins
1116 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1117 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1118 * to issue ELS PLOGIs up to the configured discover threads with the
1119 * @vport (@vport->cfg_discovery_threads). The function also decrement
1120 * the @vport's num_disc_node by 1 if it is not already 0.
1121 **/
James Smart87af33f2007-10-27 13:37:43 -04001122void
James Smart2e0fef82007-06-17 19:56:36 -05001123lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001124{
1125 int sentplogi;
1126
James Smart2e0fef82007-06-17 19:56:36 -05001127 if (vport->num_disc_nodes)
1128 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001129
1130 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001131 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1132 "0232 Continue discovery with %d PLOGIs to go "
1133 "Data: x%x x%x x%x\n",
1134 vport->num_disc_nodes, vport->fc_plogi_cnt,
1135 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001136 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001137 if (vport->fc_flag & FC_NLP_MORE)
1138 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1139 sentplogi = lpfc_els_disc_plogi(vport);
1140
dea31012005-04-17 16:05:31 -05001141 return;
1142}
1143
James Smarte59058c2008-08-24 21:49:00 -04001144/**
James Smart3621a712009-04-06 18:47:14 -04001145 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001146 * @phba: pointer to lpfc hba data structure.
1147 * @prsp: pointer to response IOCB payload.
1148 * @ndlp: pointer to a node-list data structure.
1149 *
1150 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1151 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1152 * The following cases are considered N_Port confirmed:
1153 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1154 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1155 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1156 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1157 * 1) if there is a node on vport list other than the @ndlp with the same
1158 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1159 * on that node to release the RPI associated with the node; 2) if there is
1160 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1161 * into, a new node shall be allocated (or activated). In either case, the
1162 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1163 * be released and the new_ndlp shall be put on to the vport node list and
1164 * its pointer returned as the confirmed node.
1165 *
1166 * Note that before the @ndlp got "released", the keepDID from not-matching
1167 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1168 * of the @ndlp. This is because the release of @ndlp is actually to put it
1169 * into an inactive state on the vport node list and the vport node list
1170 * management algorithm does not allow two node with a same DID.
1171 *
1172 * Return code
1173 * pointer to the PLOGI N_Port @ndlp
1174 **/
James Smart488d1462006-03-07 15:02:37 -05001175static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001176lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001177 struct lpfc_nodelist *ndlp)
1178{
James Smart2e0fef82007-06-17 19:56:36 -05001179 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001180 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001181 struct lpfc_rport_data *rdata;
1182 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001183 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001184 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001185 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001186
James Smart2fb9bd82006-12-02 13:33:57 -05001187 /* Fabric nodes can have the same WWPN so we don't bother searching
1188 * by WWPN. Just return the ndlp that was given to us.
1189 */
1190 if (ndlp->nlp_type & NLP_FABRIC)
1191 return ndlp;
1192
James Smart92d7f7b2007-06-17 19:56:38 -05001193 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001194 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001195
James Smart685f0bf2007-04-25 09:53:08 -04001196 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001197 * we have for that ndlp. If not, we have some work to do.
1198 */
James Smart2e0fef82007-06-17 19:56:36 -05001199 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001200
James Smarte47c9092008-02-08 18:49:26 -05001201 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001202 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001203
1204 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001205 rc = memcmp(&ndlp->nlp_portname, name,
1206 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001207 if (!rc)
1208 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001209 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1210 if (!new_ndlp)
1211 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001212 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001213 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001214 rc = memcmp(&ndlp->nlp_portname, name,
1215 sizeof(struct lpfc_name));
1216 if (!rc)
1217 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001218 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1219 NLP_STE_UNUSED_NODE);
1220 if (!new_ndlp)
1221 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001222 keepDID = new_ndlp->nlp_DID;
1223 } else
1224 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001225
James Smart2e0fef82007-06-17 19:56:36 -05001226 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001227 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001228 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001229
1230 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1231 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1232 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1233
James Smarte47c9092008-02-08 18:49:26 -05001234 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001235 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001236
James Smart2e0fef82007-06-17 19:56:36 -05001237 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001238 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1239 /* The new_ndlp is replacing ndlp totally, so we need
1240 * to put ndlp on UNUSED list and try to free it.
1241 */
James Smart0ff10d42008-01-11 01:52:36 -05001242
1243 /* Fix up the rport accordingly */
1244 rport = ndlp->rport;
1245 if (rport) {
1246 rdata = rport->dd_data;
1247 if (rdata->pnode == ndlp) {
1248 lpfc_nlp_put(ndlp);
1249 ndlp->rport = NULL;
1250 rdata->pnode = lpfc_nlp_get(new_ndlp);
1251 new_ndlp->rport = rport;
1252 }
1253 new_ndlp->nlp_type = ndlp->nlp_type;
1254 }
James Smart58da1ff2008-04-07 10:15:56 -04001255 /* We shall actually free the ndlp with both nlp_DID and
1256 * nlp_portname fields equals 0 to avoid any ndlp on the
1257 * nodelist never to be used.
1258 */
1259 if (ndlp->nlp_DID == 0) {
1260 spin_lock_irq(&phba->ndlp_lock);
1261 NLP_SET_FREE_REQ(ndlp);
1262 spin_unlock_irq(&phba->ndlp_lock);
1263 }
James Smart0ff10d42008-01-11 01:52:36 -05001264
James Smart58da1ff2008-04-07 10:15:56 -04001265 /* Two ndlps cannot have the same did on the nodelist */
1266 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001267 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001268 }
James Smart92795652006-07-06 15:50:02 -04001269 else {
James Smart2e0fef82007-06-17 19:56:36 -05001270 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001271 /* Two ndlps cannot have the same did */
1272 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001273 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001274 }
James Smart488d1462006-03-07 15:02:37 -05001275 return new_ndlp;
1276}
1277
James Smarte59058c2008-08-24 21:49:00 -04001278/**
James Smart3621a712009-04-06 18:47:14 -04001279 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001280 * @vport: pointer to a host virtual N_Port data structure.
1281 *
1282 * This routine checks whether more Registration State Change
1283 * Notifications (RSCNs) came in while the discovery state machine was in
1284 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1285 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1286 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1287 * handling the RSCNs.
1288 **/
James Smart87af33f2007-10-27 13:37:43 -04001289void
1290lpfc_end_rscn(struct lpfc_vport *vport)
1291{
1292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1293
1294 if (vport->fc_flag & FC_RSCN_MODE) {
1295 /*
1296 * Check to see if more RSCNs came in while we were
1297 * processing this one.
1298 */
1299 if (vport->fc_rscn_id_cnt ||
1300 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1301 lpfc_els_handle_rscn(vport);
1302 else {
1303 spin_lock_irq(shost->host_lock);
1304 vport->fc_flag &= ~FC_RSCN_MODE;
1305 spin_unlock_irq(shost->host_lock);
1306 }
1307 }
1308}
1309
James Smarte59058c2008-08-24 21:49:00 -04001310/**
James Smart3621a712009-04-06 18:47:14 -04001311 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001312 * @phba: pointer to lpfc hba data structure.
1313 * @cmdiocb: pointer to lpfc command iocb data structure.
1314 * @rspiocb: pointer to lpfc response iocb data structure.
1315 *
1316 * This routine is the completion callback function for issuing the Port
1317 * Login (PLOGI) command. For PLOGI completion, there must be an active
1318 * ndlp on the vport node list that matches the remote node ID from the
1319 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1320 * ignored and command IOCB released. The PLOGI response IOCB status is
1321 * checked for error conditons. If there is error status reported, PLOGI
1322 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1323 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1324 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1325 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1326 * there are additional N_Port nodes with the vport that need to perform
1327 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1328 * PLOGIs.
1329 **/
dea31012005-04-17 16:05:31 -05001330static void
James Smart2e0fef82007-06-17 19:56:36 -05001331lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1332 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001333{
James Smart2e0fef82007-06-17 19:56:36 -05001334 struct lpfc_vport *vport = cmdiocb->vport;
1335 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001336 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001337 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001338 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001339 int disc, rc, did, type;
1340
dea31012005-04-17 16:05:31 -05001341 /* we pass cmdiocb to state machine which needs rspiocb as well */
1342 cmdiocb->context_un.rsp_iocb = rspiocb;
1343
1344 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001345 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1346 "PLOGI cmpl: status:x%x/x%x did:x%x",
1347 irsp->ulpStatus, irsp->un.ulpWord[4],
1348 irsp->un.elsreq64.remoteID);
1349
James Smart2e0fef82007-06-17 19:56:36 -05001350 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001351 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001352 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1353 "0136 PLOGI completes to NPort x%x "
1354 "with no ndlp. Data: x%x x%x x%x\n",
1355 irsp->un.elsreq64.remoteID,
1356 irsp->ulpStatus, irsp->un.ulpWord[4],
1357 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001358 goto out;
James Smarted957682007-06-17 19:56:37 -05001359 }
dea31012005-04-17 16:05:31 -05001360
1361 /* Since ndlp can be freed in the disc state machine, note if this node
1362 * is being used during discovery.
1363 */
James Smart2e0fef82007-06-17 19:56:36 -05001364 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001365 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001366 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001367 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001368 rc = 0;
1369
1370 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001371 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1372 "0102 PLOGI completes to NPort x%x "
1373 "Data: x%x x%x x%x x%x x%x\n",
1374 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1375 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001376 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001377 if (lpfc_els_chk_latt(vport)) {
1378 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001379 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001380 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001381 goto out;
1382 }
1383
1384 /* ndlp could be freed in DSM, save these values now */
1385 type = ndlp->nlp_type;
1386 did = ndlp->nlp_DID;
1387
1388 if (irsp->ulpStatus) {
1389 /* Check for retry */
1390 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1391 /* ELS command is being retried */
1392 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001393 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001394 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001395 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001396 }
1397 goto out;
1398 }
dea31012005-04-17 16:05:31 -05001399 /* PLOGI failed */
1400 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001401 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001402 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001403 else
James Smart2e0fef82007-06-17 19:56:36 -05001404 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001405 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001406 } else {
1407 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001408 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001409 cmdiocb->context2)->list.next,
1410 struct lpfc_dmabuf, list);
1411 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001412 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001413 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001414 }
1415
James Smart2e0fef82007-06-17 19:56:36 -05001416 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001417 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001418 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001419
James Smart2e0fef82007-06-17 19:56:36 -05001420 if (vport->num_disc_nodes == 0) {
1421 spin_lock_irq(shost->host_lock);
1422 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1423 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001424
James Smart2e0fef82007-06-17 19:56:36 -05001425 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001426 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001427 }
1428 }
1429
1430out:
1431 lpfc_els_free_iocb(phba, cmdiocb);
1432 return;
1433}
1434
James Smarte59058c2008-08-24 21:49:00 -04001435/**
James Smart3621a712009-04-06 18:47:14 -04001436 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001437 * @vport: pointer to a host virtual N_Port data structure.
1438 * @did: destination port identifier.
1439 * @retry: number of retries to the command IOCB.
1440 *
1441 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1442 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1443 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1444 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1445 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1446 *
1447 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1448 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1449 * will be stored into the context1 field of the IOCB for the completion
1450 * callback function to the PLOGI ELS command.
1451 *
1452 * Return code
1453 * 0 - Successfully issued a plogi for @vport
1454 * 1 - failed to issue a plogi for @vport
1455 **/
dea31012005-04-17 16:05:31 -05001456int
James Smart2e0fef82007-06-17 19:56:36 -05001457lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001458{
James Smart2e0fef82007-06-17 19:56:36 -05001459 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001460 struct serv_parm *sp;
1461 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001462 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001463 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001464 struct lpfc_sli *psli;
1465 uint8_t *pcmd;
1466 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001467 int ret;
dea31012005-04-17 16:05:31 -05001468
1469 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001470
James Smart98c9ea52007-10-27 13:37:33 -04001471 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001472 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1473 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001474
James Smarte47c9092008-02-08 18:49:26 -05001475 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001476 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001477 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001478 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001479 if (!elsiocb)
1480 return 1;
dea31012005-04-17 16:05:31 -05001481
1482 icmd = &elsiocb->iocb;
1483 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1484
1485 /* For PLOGI request, remainder of payload is service parameters */
1486 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001487 pcmd += sizeof(uint32_t);
1488 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001489 sp = (struct serv_parm *) pcmd;
1490
1491 if (sp->cmn.fcphLow < FC_PH_4_3)
1492 sp->cmn.fcphLow = FC_PH_4_3;
1493
1494 if (sp->cmn.fcphHigh < FC_PH3)
1495 sp->cmn.fcphHigh = FC_PH3;
1496
James Smart858c9f62007-06-17 19:56:39 -05001497 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1498 "Issue PLOGI: did:x%x",
1499 did, 0, 0);
1500
dea31012005-04-17 16:05:31 -05001501 phba->fc_stat.elsXmitPLOGI++;
1502 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001503 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001504
1505 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001506 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001507 return 1;
dea31012005-04-17 16:05:31 -05001508 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001509 return 0;
dea31012005-04-17 16:05:31 -05001510}
1511
James Smarte59058c2008-08-24 21:49:00 -04001512/**
James Smart3621a712009-04-06 18:47:14 -04001513 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001514 * @phba: pointer to lpfc hba data structure.
1515 * @cmdiocb: pointer to lpfc command iocb data structure.
1516 * @rspiocb: pointer to lpfc response iocb data structure.
1517 *
1518 * This routine is the completion callback function for a Process Login
1519 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1520 * status. If there is error status reported, PRLI retry shall be attempted
1521 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1522 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1523 * ndlp to mark the PRLI completion.
1524 **/
dea31012005-04-17 16:05:31 -05001525static void
James Smart2e0fef82007-06-17 19:56:36 -05001526lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1527 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001528{
James Smart2e0fef82007-06-17 19:56:36 -05001529 struct lpfc_vport *vport = cmdiocb->vport;
1530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001531 IOCB_t *irsp;
1532 struct lpfc_sli *psli;
1533 struct lpfc_nodelist *ndlp;
1534
1535 psli = &phba->sli;
1536 /* we pass cmdiocb to state machine which needs rspiocb as well */
1537 cmdiocb->context_un.rsp_iocb = rspiocb;
1538
1539 irsp = &(rspiocb->iocb);
1540 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001541 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001542 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001543 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001544
James Smart858c9f62007-06-17 19:56:39 -05001545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1546 "PRLI cmpl: status:x%x/x%x did:x%x",
1547 irsp->ulpStatus, irsp->un.ulpWord[4],
1548 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001549 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001550 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1551 "0103 PRLI completes to NPort x%x "
1552 "Data: x%x x%x x%x x%x\n",
1553 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1554 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001555
James Smart2e0fef82007-06-17 19:56:36 -05001556 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001557 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001558 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001559 goto out;
1560
1561 if (irsp->ulpStatus) {
1562 /* Check for retry */
1563 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1564 /* ELS command is being retried */
1565 goto out;
1566 }
1567 /* PRLI failed */
1568 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001569 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001570 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001571 else
James Smart2e0fef82007-06-17 19:56:36 -05001572 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001573 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001574 } else
dea31012005-04-17 16:05:31 -05001575 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001576 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001577 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001578out:
1579 lpfc_els_free_iocb(phba, cmdiocb);
1580 return;
1581}
1582
James Smarte59058c2008-08-24 21:49:00 -04001583/**
James Smart3621a712009-04-06 18:47:14 -04001584 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001585 * @vport: pointer to a host virtual N_Port data structure.
1586 * @ndlp: pointer to a node-list data structure.
1587 * @retry: number of retries to the command IOCB.
1588 *
1589 * This routine issues a Process Login (PRLI) ELS command for the
1590 * @vport. The PRLI service parameters are set up in the payload of the
1591 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1592 * is put to the IOCB completion callback func field before invoking the
1593 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1594 *
1595 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1596 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1597 * will be stored into the context1 field of the IOCB for the completion
1598 * callback function to the PRLI ELS command.
1599 *
1600 * Return code
1601 * 0 - successfully issued prli iocb command for @vport
1602 * 1 - failed to issue prli iocb command for @vport
1603 **/
dea31012005-04-17 16:05:31 -05001604int
James Smart2e0fef82007-06-17 19:56:36 -05001605lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001606 uint8_t retry)
1607{
James Smart2e0fef82007-06-17 19:56:36 -05001608 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1609 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001610 PRLI *npr;
1611 IOCB_t *icmd;
1612 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001613 uint8_t *pcmd;
1614 uint16_t cmdsize;
1615
James Smart92d7f7b2007-06-17 19:56:38 -05001616 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001617 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1618 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001619 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001620 return 1;
dea31012005-04-17 16:05:31 -05001621
1622 icmd = &elsiocb->iocb;
1623 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1624
1625 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001626 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001627 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001628 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001629
1630 /* For PRLI, remainder of payload is PRLI parameter page */
1631 npr = (PRLI *) pcmd;
1632 /*
1633 * If our firmware version is 3.20 or later,
1634 * set the following bits for FC-TAPE support.
1635 */
1636 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1637 npr->ConfmComplAllowed = 1;
1638 npr->Retry = 1;
1639 npr->TaskRetryIdReq = 1;
1640 }
1641 npr->estabImagePair = 1;
1642 npr->readXferRdyDis = 1;
1643
1644 /* For FCP support */
1645 npr->prliType = PRLI_FCP_TYPE;
1646 npr->initiatorFunc = 1;
1647
James Smart858c9f62007-06-17 19:56:39 -05001648 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1649 "Issue PRLI: did:x%x",
1650 ndlp->nlp_DID, 0, 0);
1651
dea31012005-04-17 16:05:31 -05001652 phba->fc_stat.elsXmitPRLI++;
1653 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001654 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001655 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001656 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001657 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1658 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001659 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001660 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001661 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001662 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001663 return 1;
dea31012005-04-17 16:05:31 -05001664 }
James Smart2e0fef82007-06-17 19:56:36 -05001665 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001666 return 0;
dea31012005-04-17 16:05:31 -05001667}
1668
James Smarte59058c2008-08-24 21:49:00 -04001669/**
James Smart3621a712009-04-06 18:47:14 -04001670 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001671 * @vport: pointer to a host virtual N_Port data structure.
1672 *
1673 * This routine performs Registration State Change Notification (RSCN)
1674 * discovery for a @vport. If the @vport's node port recovery count is not
1675 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1676 * the nodes that need recovery. If none of the PLOGI were needed through
1677 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1678 * invoked to check and handle possible more RSCN came in during the period
1679 * of processing the current ones.
1680 **/
1681static void
1682lpfc_rscn_disc(struct lpfc_vport *vport)
1683{
1684 lpfc_can_disctmo(vport);
1685
1686 /* RSCN discovery */
1687 /* go thru NPR nodes and issue ELS PLOGIs */
1688 if (vport->fc_npr_cnt)
1689 if (lpfc_els_disc_plogi(vport))
1690 return;
1691
1692 lpfc_end_rscn(vport);
1693}
1694
1695/**
James Smart3621a712009-04-06 18:47:14 -04001696 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001697 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1698 *
1699 * This function is called when the final ADISC is completed during discovery.
1700 * This function handles clearing link attention or issuing reg_vpi depending
1701 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1702 * discovery.
1703 * This function is called with no locks held.
1704 **/
1705static void
1706lpfc_adisc_done(struct lpfc_vport *vport)
1707{
1708 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1709 struct lpfc_hba *phba = vport->phba;
1710
1711 /*
1712 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1713 * and continue discovery.
1714 */
1715 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001716 !(vport->fc_flag & FC_RSCN_MODE) &&
1717 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001718 lpfc_issue_reg_vpi(phba, vport);
1719 return;
1720 }
1721 /*
1722 * For SLI2, we need to set port_state to READY
1723 * and continue discovery.
1724 */
1725 if (vport->port_state < LPFC_VPORT_READY) {
1726 /* If we get here, there is nothing to ADISC */
1727 if (vport->port_type == LPFC_PHYSICAL_PORT)
1728 lpfc_issue_clear_la(phba, vport);
1729 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1730 vport->num_disc_nodes = 0;
1731 /* go thru NPR list, issue ELS PLOGIs */
1732 if (vport->fc_npr_cnt)
1733 lpfc_els_disc_plogi(vport);
1734 if (!vport->num_disc_nodes) {
1735 spin_lock_irq(shost->host_lock);
1736 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1737 spin_unlock_irq(shost->host_lock);
1738 lpfc_can_disctmo(vport);
1739 lpfc_end_rscn(vport);
1740 }
1741 }
1742 vport->port_state = LPFC_VPORT_READY;
1743 } else
1744 lpfc_rscn_disc(vport);
1745}
1746
1747/**
James Smart3621a712009-04-06 18:47:14 -04001748 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001749 * @vport: pointer to a host virtual N_Port data structure.
1750 *
1751 * This routine determines whether there are more ndlps on a @vport
1752 * node list need to have Address Discover (ADISC) issued. If so, it will
1753 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1754 * remaining nodes which need to have ADISC sent.
1755 **/
James Smart0ff10d42008-01-11 01:52:36 -05001756void
James Smart2e0fef82007-06-17 19:56:36 -05001757lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001758{
1759 int sentadisc;
1760
James Smart2e0fef82007-06-17 19:56:36 -05001761 if (vport->num_disc_nodes)
1762 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001763 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001764 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1765 "0210 Continue discovery with %d ADISCs to go "
1766 "Data: x%x x%x x%x\n",
1767 vport->num_disc_nodes, vport->fc_adisc_cnt,
1768 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001769 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001770 if (vport->fc_flag & FC_NLP_MORE) {
1771 lpfc_set_disctmo(vport);
1772 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1773 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001774 }
James Smart90160e02008-08-24 21:49:45 -04001775 if (!vport->num_disc_nodes)
1776 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001777 return;
1778}
1779
James Smarte59058c2008-08-24 21:49:00 -04001780/**
James Smart3621a712009-04-06 18:47:14 -04001781 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001782 * @phba: pointer to lpfc hba data structure.
1783 * @cmdiocb: pointer to lpfc command iocb data structure.
1784 * @rspiocb: pointer to lpfc response iocb data structure.
1785 *
1786 * This routine is the completion function for issuing the Address Discover
1787 * (ADISC) command. It first checks to see whether link went down during
1788 * the discovery process. If so, the node will be marked as node port
1789 * recovery for issuing discover IOCB by the link attention handler and
1790 * exit. Otherwise, the response status is checked. If error was reported
1791 * in the response status, the ADISC command shall be retried by invoking
1792 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1793 * the response status, the state machine is invoked to set transition
1794 * with respect to NLP_EVT_CMPL_ADISC event.
1795 **/
dea31012005-04-17 16:05:31 -05001796static void
James Smart2e0fef82007-06-17 19:56:36 -05001797lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1798 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001799{
James Smart2e0fef82007-06-17 19:56:36 -05001800 struct lpfc_vport *vport = cmdiocb->vport;
1801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001802 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001803 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001804 int disc;
dea31012005-04-17 16:05:31 -05001805
1806 /* we pass cmdiocb to state machine which needs rspiocb as well */
1807 cmdiocb->context_un.rsp_iocb = rspiocb;
1808
1809 irsp = &(rspiocb->iocb);
1810 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001811
James Smart858c9f62007-06-17 19:56:39 -05001812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1813 "ADISC cmpl: status:x%x/x%x did:x%x",
1814 irsp->ulpStatus, irsp->un.ulpWord[4],
1815 ndlp->nlp_DID);
1816
dea31012005-04-17 16:05:31 -05001817 /* Since ndlp can be freed in the disc state machine, note if this node
1818 * is being used during discovery.
1819 */
James Smart2e0fef82007-06-17 19:56:36 -05001820 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001821 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001822 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001823 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001824 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001825 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1826 "0104 ADISC completes to NPort x%x "
1827 "Data: x%x x%x x%x x%x x%x\n",
1828 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1829 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001830 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001831 if (lpfc_els_chk_latt(vport)) {
1832 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001833 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001834 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001835 goto out;
1836 }
1837
1838 if (irsp->ulpStatus) {
1839 /* Check for retry */
1840 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1841 /* ELS command is being retried */
1842 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001843 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001844 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001845 spin_unlock_irq(shost->host_lock);
1846 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001847 }
1848 goto out;
1849 }
1850 /* ADISC failed */
1851 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001852 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001853 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001854 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001855 } else
dea31012005-04-17 16:05:31 -05001856 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001857 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001858 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001859
James Smart90160e02008-08-24 21:49:45 -04001860 /* Check to see if there are more ADISCs to be sent */
1861 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001862 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001863out:
1864 lpfc_els_free_iocb(phba, cmdiocb);
1865 return;
1866}
1867
James Smarte59058c2008-08-24 21:49:00 -04001868/**
James Smart3621a712009-04-06 18:47:14 -04001869 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001870 * @vport: pointer to a virtual N_Port data structure.
1871 * @ndlp: pointer to a node-list data structure.
1872 * @retry: number of retries to the command IOCB.
1873 *
1874 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1875 * @vport. It prepares the payload of the ADISC ELS command, updates the
1876 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1877 * to issue the ADISC ELS command.
1878 *
1879 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1880 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1881 * will be stored into the context1 field of the IOCB for the completion
1882 * callback function to the ADISC ELS command.
1883 *
1884 * Return code
1885 * 0 - successfully issued adisc
1886 * 1 - failed to issue adisc
1887 **/
dea31012005-04-17 16:05:31 -05001888int
James Smart2e0fef82007-06-17 19:56:36 -05001889lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001890 uint8_t retry)
1891{
James Smart2e0fef82007-06-17 19:56:36 -05001892 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1893 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001894 ADISC *ap;
1895 IOCB_t *icmd;
1896 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001897 uint8_t *pcmd;
1898 uint16_t cmdsize;
1899
James Smart92d7f7b2007-06-17 19:56:38 -05001900 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001901 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1902 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001903 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001904 return 1;
dea31012005-04-17 16:05:31 -05001905
1906 icmd = &elsiocb->iocb;
1907 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1908
1909 /* For ADISC request, remainder of payload is service parameters */
1910 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001911 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001912
1913 /* Fill in ADISC payload */
1914 ap = (ADISC *) pcmd;
1915 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001916 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1917 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001918 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001919
James Smart858c9f62007-06-17 19:56:39 -05001920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1921 "Issue ADISC: did:x%x",
1922 ndlp->nlp_DID, 0, 0);
1923
dea31012005-04-17 16:05:31 -05001924 phba->fc_stat.elsXmitADISC++;
1925 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001926 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001927 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001928 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001929 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1930 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001931 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001932 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001933 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001934 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001935 return 1;
dea31012005-04-17 16:05:31 -05001936 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001937 return 0;
dea31012005-04-17 16:05:31 -05001938}
1939
James Smarte59058c2008-08-24 21:49:00 -04001940/**
James Smart3621a712009-04-06 18:47:14 -04001941 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04001942 * @phba: pointer to lpfc hba data structure.
1943 * @cmdiocb: pointer to lpfc command iocb data structure.
1944 * @rspiocb: pointer to lpfc response iocb data structure.
1945 *
1946 * This routine is the completion function for issuing the ELS Logout (LOGO)
1947 * command. If no error status was reported from the LOGO response, the
1948 * state machine of the associated ndlp shall be invoked for transition with
1949 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1950 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1951 **/
dea31012005-04-17 16:05:31 -05001952static void
James Smart2e0fef82007-06-17 19:56:36 -05001953lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1954 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001955{
James Smart2e0fef82007-06-17 19:56:36 -05001956 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1957 struct lpfc_vport *vport = ndlp->vport;
1958 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001959 IOCB_t *irsp;
1960 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001961
1962 psli = &phba->sli;
1963 /* we pass cmdiocb to state machine which needs rspiocb as well */
1964 cmdiocb->context_un.rsp_iocb = rspiocb;
1965
1966 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001967 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001968 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001969 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001970
James Smart858c9f62007-06-17 19:56:39 -05001971 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1972 "LOGO cmpl: status:x%x/x%x did:x%x",
1973 irsp->ulpStatus, irsp->un.ulpWord[4],
1974 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001975 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001976 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1977 "0105 LOGO completes to NPort x%x "
1978 "Data: x%x x%x x%x x%x\n",
1979 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1980 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001981 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001982 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001983 goto out;
1984
James Smart92d7f7b2007-06-17 19:56:38 -05001985 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1986 /* NLP_EVT_DEVICE_RM should unregister the RPI
1987 * which should abort all outstanding IOs.
1988 */
1989 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1990 NLP_EVT_DEVICE_RM);
1991 goto out;
1992 }
1993
dea31012005-04-17 16:05:31 -05001994 if (irsp->ulpStatus) {
1995 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001996 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001997 /* ELS command is being retried */
1998 goto out;
dea31012005-04-17 16:05:31 -05001999 /* LOGO failed */
2000 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002001 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002002 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002003 else
James Smart2e0fef82007-06-17 19:56:36 -05002004 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002005 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002006 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002007 /* Good status, call state machine.
2008 * This will unregister the rpi if needed.
2009 */
James Smart2e0fef82007-06-17 19:56:36 -05002010 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002011 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002012out:
2013 lpfc_els_free_iocb(phba, cmdiocb);
2014 return;
2015}
2016
James Smarte59058c2008-08-24 21:49:00 -04002017/**
James Smart3621a712009-04-06 18:47:14 -04002018 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002019 * @vport: pointer to a virtual N_Port data structure.
2020 * @ndlp: pointer to a node-list data structure.
2021 * @retry: number of retries to the command IOCB.
2022 *
2023 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2024 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2025 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2026 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2027 *
2028 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2029 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2030 * will be stored into the context1 field of the IOCB for the completion
2031 * callback function to the LOGO ELS command.
2032 *
2033 * Return code
2034 * 0 - successfully issued logo
2035 * 1 - failed to issue logo
2036 **/
dea31012005-04-17 16:05:31 -05002037int
James Smart2e0fef82007-06-17 19:56:36 -05002038lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002039 uint8_t retry)
2040{
James Smart2e0fef82007-06-17 19:56:36 -05002041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2042 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002043 IOCB_t *icmd;
2044 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002045 uint8_t *pcmd;
2046 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002047 int rc;
dea31012005-04-17 16:05:31 -05002048
James Smart98c9ea52007-10-27 13:37:33 -04002049 spin_lock_irq(shost->host_lock);
2050 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2051 spin_unlock_irq(shost->host_lock);
2052 return 0;
2053 }
2054 spin_unlock_irq(shost->host_lock);
2055
James Smart92d7f7b2007-06-17 19:56:38 -05002056 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002057 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2058 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002059 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002060 return 1;
dea31012005-04-17 16:05:31 -05002061
2062 icmd = &elsiocb->iocb;
2063 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2064 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002065 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002066
2067 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002068 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002069 pcmd += sizeof(uint32_t);
2070 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002071
James Smart858c9f62007-06-17 19:56:39 -05002072 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2073 "Issue LOGO: did:x%x",
2074 ndlp->nlp_DID, 0, 0);
2075
dea31012005-04-17 16:05:31 -05002076 phba->fc_stat.elsXmitLOGO++;
2077 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002078 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002079 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002080 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002081 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002082
2083 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002084 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002085 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002086 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002087 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002088 return 1;
dea31012005-04-17 16:05:31 -05002089 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002090 return 0;
dea31012005-04-17 16:05:31 -05002091}
2092
James Smarte59058c2008-08-24 21:49:00 -04002093/**
James Smart3621a712009-04-06 18:47:14 -04002094 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002095 * @phba: pointer to lpfc hba data structure.
2096 * @cmdiocb: pointer to lpfc command iocb data structure.
2097 * @rspiocb: pointer to lpfc response iocb data structure.
2098 *
2099 * This routine is a generic completion callback function for ELS commands.
2100 * Specifically, it is the callback function which does not need to perform
2101 * any command specific operations. It is currently used by the ELS command
2102 * issuing routines for the ELS State Change Request (SCR),
2103 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2104 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2105 * certain debug loggings, this callback function simply invokes the
2106 * lpfc_els_chk_latt() routine to check whether link went down during the
2107 * discovery process.
2108 **/
dea31012005-04-17 16:05:31 -05002109static void
James Smart2e0fef82007-06-17 19:56:36 -05002110lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2111 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002112{
James Smart2e0fef82007-06-17 19:56:36 -05002113 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002114 IOCB_t *irsp;
2115
2116 irsp = &rspiocb->iocb;
2117
James Smart858c9f62007-06-17 19:56:39 -05002118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2119 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2120 irsp->ulpStatus, irsp->un.ulpWord[4],
2121 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002122 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002123 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2124 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2125 irsp->ulpIoTag, irsp->ulpStatus,
2126 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002127 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002128 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002129 lpfc_els_free_iocb(phba, cmdiocb);
2130 return;
2131}
2132
James Smarte59058c2008-08-24 21:49:00 -04002133/**
James Smart3621a712009-04-06 18:47:14 -04002134 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002135 * @vport: pointer to a host virtual N_Port data structure.
2136 * @nportid: N_Port identifier to the remote node.
2137 * @retry: number of retries to the command IOCB.
2138 *
2139 * This routine issues a State Change Request (SCR) to a fabric node
2140 * on a @vport. The remote node @nportid is passed into the function. It
2141 * first search the @vport node list to find the matching ndlp. If no such
2142 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2143 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2144 * routine is invoked to send the SCR IOCB.
2145 *
2146 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2147 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2148 * will be stored into the context1 field of the IOCB for the completion
2149 * callback function to the SCR ELS command.
2150 *
2151 * Return code
2152 * 0 - Successfully issued scr command
2153 * 1 - Failed to issue scr command
2154 **/
dea31012005-04-17 16:05:31 -05002155int
James Smart2e0fef82007-06-17 19:56:36 -05002156lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002157{
James Smart2e0fef82007-06-17 19:56:36 -05002158 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002159 IOCB_t *icmd;
2160 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002161 struct lpfc_sli *psli;
2162 uint8_t *pcmd;
2163 uint16_t cmdsize;
2164 struct lpfc_nodelist *ndlp;
2165
2166 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002167 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002168
James Smarte47c9092008-02-08 18:49:26 -05002169 ndlp = lpfc_findnode_did(vport, nportid);
2170 if (!ndlp) {
2171 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2172 if (!ndlp)
2173 return 1;
2174 lpfc_nlp_init(vport, ndlp, nportid);
2175 lpfc_enqueue_node(vport, ndlp);
2176 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2177 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2178 if (!ndlp)
2179 return 1;
2180 }
dea31012005-04-17 16:05:31 -05002181
James Smart2e0fef82007-06-17 19:56:36 -05002182 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2183 ndlp->nlp_DID, ELS_CMD_SCR);
2184
James Smart488d1462006-03-07 15:02:37 -05002185 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002186 /* This will trigger the release of the node just
2187 * allocated
2188 */
James Smart329f9bc2007-04-25 09:53:01 -04002189 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002190 return 1;
dea31012005-04-17 16:05:31 -05002191 }
2192
2193 icmd = &elsiocb->iocb;
2194 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2195
2196 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002197 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002198
2199 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002200 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002201 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2202
James Smart858c9f62007-06-17 19:56:39 -05002203 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2204 "Issue SCR: did:x%x",
2205 ndlp->nlp_DID, 0, 0);
2206
dea31012005-04-17 16:05:31 -05002207 phba->fc_stat.elsXmitSCR++;
2208 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002209 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2210 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002211 /* The additional lpfc_nlp_put will cause the following
2212 * lpfc_els_free_iocb routine to trigger the rlease of
2213 * the node.
2214 */
James Smart329f9bc2007-04-25 09:53:01 -04002215 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002216 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002217 return 1;
dea31012005-04-17 16:05:31 -05002218 }
James Smartfa4066b2008-01-11 01:53:27 -05002219 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2220 * trigger the release of node.
2221 */
James Smart329f9bc2007-04-25 09:53:01 -04002222 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002223 return 0;
dea31012005-04-17 16:05:31 -05002224}
2225
James Smarte59058c2008-08-24 21:49:00 -04002226/**
James Smart3621a712009-04-06 18:47:14 -04002227 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002228 * @vport: pointer to a host virtual N_Port data structure.
2229 * @nportid: N_Port identifier to the remote node.
2230 * @retry: number of retries to the command IOCB.
2231 *
2232 * This routine issues a Fibre Channel Address Resolution Response
2233 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2234 * is passed into the function. It first search the @vport node list to find
2235 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2236 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2237 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2238 *
2239 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2240 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2241 * will be stored into the context1 field of the IOCB for the completion
2242 * callback function to the PARPR ELS command.
2243 *
2244 * Return code
2245 * 0 - Successfully issued farpr command
2246 * 1 - Failed to issue farpr command
2247 **/
dea31012005-04-17 16:05:31 -05002248static int
James Smart2e0fef82007-06-17 19:56:36 -05002249lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002250{
James Smart2e0fef82007-06-17 19:56:36 -05002251 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002252 IOCB_t *icmd;
2253 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002254 struct lpfc_sli *psli;
2255 FARP *fp;
2256 uint8_t *pcmd;
2257 uint32_t *lp;
2258 uint16_t cmdsize;
2259 struct lpfc_nodelist *ondlp;
2260 struct lpfc_nodelist *ndlp;
2261
2262 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002263 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002264
James Smarte47c9092008-02-08 18:49:26 -05002265 ndlp = lpfc_findnode_did(vport, nportid);
2266 if (!ndlp) {
2267 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2268 if (!ndlp)
2269 return 1;
2270 lpfc_nlp_init(vport, ndlp, nportid);
2271 lpfc_enqueue_node(vport, ndlp);
2272 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2273 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2274 if (!ndlp)
2275 return 1;
2276 }
James Smart2e0fef82007-06-17 19:56:36 -05002277
2278 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2279 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002280 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002281 /* This will trigger the release of the node just
2282 * allocated
2283 */
James Smart329f9bc2007-04-25 09:53:01 -04002284 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002285 return 1;
dea31012005-04-17 16:05:31 -05002286 }
2287
2288 icmd = &elsiocb->iocb;
2289 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2290
2291 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002292 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002293
2294 /* Fill in FARPR payload */
2295 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002296 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002297 lp = (uint32_t *) pcmd;
2298 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002299 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002300 fp->Rflags = 0;
2301 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2302
James Smart92d7f7b2007-06-17 19:56:38 -05002303 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2304 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002305 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002306 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002307 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002308 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002309 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002310 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002311 }
2312
James Smart858c9f62007-06-17 19:56:39 -05002313 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2314 "Issue FARPR: did:x%x",
2315 ndlp->nlp_DID, 0, 0);
2316
dea31012005-04-17 16:05:31 -05002317 phba->fc_stat.elsXmitFARPR++;
2318 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002319 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2320 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002321 /* The additional lpfc_nlp_put will cause the following
2322 * lpfc_els_free_iocb routine to trigger the release of
2323 * the node.
2324 */
James Smart329f9bc2007-04-25 09:53:01 -04002325 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002326 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002327 return 1;
dea31012005-04-17 16:05:31 -05002328 }
James Smartfa4066b2008-01-11 01:53:27 -05002329 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2330 * trigger the release of the node.
2331 */
James Smart329f9bc2007-04-25 09:53:01 -04002332 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002333 return 0;
dea31012005-04-17 16:05:31 -05002334}
2335
James Smarte59058c2008-08-24 21:49:00 -04002336/**
James Smart3621a712009-04-06 18:47:14 -04002337 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002338 * @vport: pointer to a host virtual N_Port data structure.
2339 * @nlp: pointer to a node-list data structure.
2340 *
2341 * This routine cancels the timer with a delayed IOCB-command retry for
2342 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2343 * removes the ELS retry event if it presents. In addition, if the
2344 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2345 * commands are sent for the @vport's nodes that require issuing discovery
2346 * ADISC.
2347 **/
dea31012005-04-17 16:05:31 -05002348void
James Smart2e0fef82007-06-17 19:56:36 -05002349lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002350{
James Smart2e0fef82007-06-17 19:56:36 -05002351 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002352 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002353
James Smart0d2b6b82008-06-14 22:52:47 -04002354 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2355 return;
James Smart2e0fef82007-06-17 19:56:36 -05002356 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002357 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002358 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002359 del_timer_sync(&nlp->nlp_delayfunc);
2360 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002361 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002362 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002363 /* Decrement nlp reference count held for the delayed retry */
2364 evtp = &nlp->els_retry_evt;
2365 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2366 }
James Smartfdcebe22006-03-07 15:04:01 -05002367 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002368 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002369 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002370 spin_unlock_irq(shost->host_lock);
2371 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002372 if (vport->port_state < LPFC_VPORT_READY) {
2373 /* Check if there are more ADISCs to be sent */
2374 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002375 } else {
2376 /* Check if there are more PLOGIs to be sent */
2377 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002378 if (vport->num_disc_nodes == 0) {
2379 spin_lock_irq(shost->host_lock);
2380 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2381 spin_unlock_irq(shost->host_lock);
2382 lpfc_can_disctmo(vport);
2383 lpfc_end_rscn(vport);
2384 }
James Smartfdcebe22006-03-07 15:04:01 -05002385 }
2386 }
2387 }
2388 return;
2389}
2390
James Smarte59058c2008-08-24 21:49:00 -04002391/**
James Smart3621a712009-04-06 18:47:14 -04002392 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002393 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2394 *
2395 * This routine is invoked by the ndlp delayed-function timer to check
2396 * whether there is any pending ELS retry event(s) with the node. If not, it
2397 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2398 * adds the delayed events to the HBA work list and invokes the
2399 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2400 * event. Note that lpfc_nlp_get() is called before posting the event to
2401 * the work list to hold reference count of ndlp so that it guarantees the
2402 * reference to ndlp will still be available when the worker thread gets
2403 * to the event associated with the ndlp.
2404 **/
James Smartfdcebe22006-03-07 15:04:01 -05002405void
dea31012005-04-17 16:05:31 -05002406lpfc_els_retry_delay(unsigned long ptr)
2407{
James Smart2e0fef82007-06-17 19:56:36 -05002408 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2409 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002410 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002411 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002412 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002413
James Smart92d7f7b2007-06-17 19:56:38 -05002414 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002415 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002416 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002417 return;
2418 }
2419
James Smartfa4066b2008-01-11 01:53:27 -05002420 /* We need to hold the node by incrementing the reference
2421 * count until the queued work is done
2422 */
2423 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002424 if (evtp->evt_arg1) {
2425 evtp->evt = LPFC_EVT_ELS_RETRY;
2426 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002427 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002428 }
James Smart92d7f7b2007-06-17 19:56:38 -05002429 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002430 return;
2431}
2432
James Smarte59058c2008-08-24 21:49:00 -04002433/**
James Smart3621a712009-04-06 18:47:14 -04002434 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002435 * @ndlp: pointer to a node-list data structure.
2436 *
2437 * This routine is the worker-thread handler for processing the @ndlp delayed
2438 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2439 * the last ELS command from the associated ndlp and invokes the proper ELS
2440 * function according to the delayed ELS command to retry the command.
2441 **/
dea31012005-04-17 16:05:31 -05002442void
2443lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2444{
James Smart2e0fef82007-06-17 19:56:36 -05002445 struct lpfc_vport *vport = ndlp->vport;
2446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2447 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002448
James Smart2e0fef82007-06-17 19:56:36 -05002449 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002450 did = ndlp->nlp_DID;
2451 cmd = ndlp->nlp_last_elscmd;
2452 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002453
2454 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002455 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002456 return;
2457 }
2458
2459 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002460 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002461 /*
2462 * If a discovery event readded nlp_delayfunc after timer
2463 * firing and before processing the timer, cancel the
2464 * nlp_delayfunc.
2465 */
2466 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002467 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002468 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002469
2470 switch (cmd) {
2471 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002472 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002473 break;
2474 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002475 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002476 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002477 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002478 }
dea31012005-04-17 16:05:31 -05002479 break;
2480 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002481 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002482 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002483 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002484 }
dea31012005-04-17 16:05:31 -05002485 break;
2486 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002487 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002488 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002489 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002490 }
dea31012005-04-17 16:05:31 -05002491 break;
2492 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002493 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002494 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002495 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002496 }
dea31012005-04-17 16:05:31 -05002497 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002498 case ELS_CMD_FDISC:
2499 lpfc_issue_els_fdisc(vport, ndlp, retry);
2500 break;
dea31012005-04-17 16:05:31 -05002501 }
2502 return;
2503}
2504
James Smarte59058c2008-08-24 21:49:00 -04002505/**
James Smart3621a712009-04-06 18:47:14 -04002506 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002507 * @phba: pointer to lpfc hba data structure.
2508 * @cmdiocb: pointer to lpfc command iocb data structure.
2509 * @rspiocb: pointer to lpfc response iocb data structure.
2510 *
2511 * This routine makes a retry decision on an ELS command IOCB, which has
2512 * failed. The following ELS IOCBs use this function for retrying the command
2513 * when previously issued command responsed with error status: FLOGI, PLOGI,
2514 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2515 * returned error status, it makes the decision whether a retry shall be
2516 * issued for the command, and whether a retry shall be made immediately or
2517 * delayed. In the former case, the corresponding ELS command issuing-function
2518 * is called to retry the command. In the later case, the ELS command shall
2519 * be posted to the ndlp delayed event and delayed function timer set to the
2520 * ndlp for the delayed command issusing.
2521 *
2522 * Return code
2523 * 0 - No retry of els command is made
2524 * 1 - Immediate or delayed retry of els command is made
2525 **/
dea31012005-04-17 16:05:31 -05002526static int
James Smart2e0fef82007-06-17 19:56:36 -05002527lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2528 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002529{
James Smart2e0fef82007-06-17 19:56:36 -05002530 struct lpfc_vport *vport = cmdiocb->vport;
2531 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2532 IOCB_t *irsp = &rspiocb->iocb;
2533 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2534 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002535 uint32_t *elscmd;
2536 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002537 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002538 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002539 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002540 uint32_t did;
dea31012005-04-17 16:05:31 -05002541
James Smart488d1462006-03-07 15:02:37 -05002542
dea31012005-04-17 16:05:31 -05002543 /* Note: context2 may be 0 for internal driver abort
2544 * of delays ELS command.
2545 */
2546
2547 if (pcmd && pcmd->virt) {
2548 elscmd = (uint32_t *) (pcmd->virt);
2549 cmd = *elscmd++;
2550 }
2551
James Smarte47c9092008-02-08 18:49:26 -05002552 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002553 did = ndlp->nlp_DID;
2554 else {
2555 /* We should only hit this case for retrying PLOGI */
2556 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002557 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002558 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2559 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002560 return 1;
2561 }
2562
James Smart858c9f62007-06-17 19:56:39 -05002563 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2564 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2565 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2566
dea31012005-04-17 16:05:31 -05002567 switch (irsp->ulpStatus) {
2568 case IOSTAT_FCP_RSP_ERROR:
2569 case IOSTAT_REMOTE_STOP:
2570 break;
2571
2572 case IOSTAT_LOCAL_REJECT:
2573 switch ((irsp->un.ulpWord[4] & 0xff)) {
2574 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002575 if (cmd == ELS_CMD_FLOGI) {
2576 if (PCI_DEVICE_ID_HORNET ==
2577 phba->pcidev->device) {
2578 phba->fc_topology = TOPOLOGY_LOOP;
2579 phba->pport->fc_myDID = 0;
2580 phba->alpa_map[0] = 0;
2581 phba->alpa_map[1] = 0;
2582 }
2583 }
James Smart2e0fef82007-06-17 19:56:36 -05002584 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002585 delay = 1000;
dea31012005-04-17 16:05:31 -05002586 retry = 1;
2587 break;
2588
James Smart92d7f7b2007-06-17 19:56:38 -05002589 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002590 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2591 "0124 Retry illegal cmd x%x "
2592 "retry:x%x delay:x%x\n",
2593 cmd, cmdiocb->retry, delay);
2594 retry = 1;
2595 /* All command's retry policy */
2596 maxretry = 8;
2597 if (cmdiocb->retry > 2)
2598 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002599 break;
2600
dea31012005-04-17 16:05:31 -05002601 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002602 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002603 retry = 1;
2604 if (cmdiocb->retry > 100)
2605 delay = 100;
2606 maxretry = 250;
2607 break;
2608
2609 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002610 delay = 100;
dea31012005-04-17 16:05:31 -05002611 retry = 1;
2612 break;
2613
James Smart858c9f62007-06-17 19:56:39 -05002614 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002615 case IOERR_INVALID_RPI:
2616 retry = 1;
2617 break;
2618 }
2619 break;
2620
2621 case IOSTAT_NPORT_RJT:
2622 case IOSTAT_FABRIC_RJT:
2623 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2624 retry = 1;
2625 break;
2626 }
2627 break;
2628
2629 case IOSTAT_NPORT_BSY:
2630 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002631 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002632 retry = 1;
2633 break;
2634
2635 case IOSTAT_LS_RJT:
2636 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2637 /* Added for Vendor specifc support
2638 * Just keep retrying for these Rsn / Exp codes
2639 */
2640 switch (stat.un.b.lsRjtRsnCode) {
2641 case LSRJT_UNABLE_TPC:
2642 if (stat.un.b.lsRjtRsnCodeExp ==
2643 LSEXP_CMD_IN_PROGRESS) {
2644 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002645 delay = 1000;
dea31012005-04-17 16:05:31 -05002646 maxretry = 48;
2647 }
2648 retry = 1;
2649 break;
2650 }
2651 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002652 delay = 1000;
dea31012005-04-17 16:05:31 -05002653 maxretry = lpfc_max_els_tries + 1;
2654 retry = 1;
2655 break;
2656 }
James Smart92d7f7b2007-06-17 19:56:38 -05002657 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2658 (cmd == ELS_CMD_FDISC) &&
2659 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002660 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2661 "0125 FDISC Failed (x%x). "
2662 "Fabric out of resources\n",
2663 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002664 lpfc_vport_set_state(vport,
2665 FC_VPORT_NO_FABRIC_RSCS);
2666 }
dea31012005-04-17 16:05:31 -05002667 break;
2668
2669 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002670 if ((cmd == ELS_CMD_PLOGI) ||
2671 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002672 delay = 1000;
dea31012005-04-17 16:05:31 -05002673 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002674 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002675 /* FDISC retry policy */
2676 maxretry = 48;
2677 if (cmdiocb->retry >= 32)
2678 delay = 1000;
dea31012005-04-17 16:05:31 -05002679 }
2680 retry = 1;
2681 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002682
2683 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002684 /* There are some cases where switches return this
2685 * error when they are not ready and should be returning
2686 * Logical Busy. We should delay every time.
2687 */
2688 if (cmd == ELS_CMD_FDISC &&
2689 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2690 maxretry = 3;
2691 delay = 1000;
2692 retry = 1;
2693 break;
2694 }
James Smart92d7f7b2007-06-17 19:56:38 -05002695 case LSRJT_PROTOCOL_ERR:
2696 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2697 (cmd == ELS_CMD_FDISC) &&
2698 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2699 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2700 ) {
James Smarte8b62012007-08-02 11:10:09 -04002701 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002702 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002703 "Fabric Detected Bad WWN\n",
2704 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002705 lpfc_vport_set_state(vport,
2706 FC_VPORT_FABRIC_REJ_WWN);
2707 }
2708 break;
dea31012005-04-17 16:05:31 -05002709 }
2710 break;
2711
2712 case IOSTAT_INTERMED_RSP:
2713 case IOSTAT_BA_RJT:
2714 break;
2715
2716 default:
2717 break;
2718 }
2719
James Smart488d1462006-03-07 15:02:37 -05002720 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002721 retry = 1;
dea31012005-04-17 16:05:31 -05002722
James Smart98c9ea52007-10-27 13:37:33 -04002723 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002724 (phba->fc_topology != TOPOLOGY_LOOP) &&
2725 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002726 /* FLOGI retry policy */
2727 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002728 /* retry forever */
2729 maxretry = 0;
2730 if (cmdiocb->retry >= 100)
2731 delay = 5000;
2732 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002733 delay = 1000;
2734 }
2735
James Smart6669f9b2009-10-02 15:16:45 -04002736 cmdiocb->retry++;
2737 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002738 phba->fc_stat.elsRetryExceeded++;
2739 retry = 0;
2740 }
2741
James Smarted957682007-06-17 19:56:37 -05002742 if ((vport->load_flag & FC_UNLOADING) != 0)
2743 retry = 0;
2744
dea31012005-04-17 16:05:31 -05002745 if (retry) {
2746
2747 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002748 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2749 "0107 Retry ELS command x%x to remote "
2750 "NPORT x%x Data: x%x x%x\n",
2751 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002752
James Smart858c9f62007-06-17 19:56:39 -05002753 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2754 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2755 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2756 /* Don't reset timer for no resources */
2757
dea31012005-04-17 16:05:31 -05002758 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002759 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002760 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002761 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002762 }
2763
2764 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002765 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002766 phba->fc_stat.elsDelayRetry++;
2767 ndlp->nlp_retry = cmdiocb->retry;
2768
James Smart92d7f7b2007-06-17 19:56:38 -05002769 /* delay is specified in milliseconds */
2770 mod_timer(&ndlp->nlp_delayfunc,
2771 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002772 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002773 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002774 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002775
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002776 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002777 if (cmd == ELS_CMD_PRLI)
2778 lpfc_nlp_set_state(vport, ndlp,
2779 NLP_STE_REG_LOGIN_ISSUE);
2780 else
2781 lpfc_nlp_set_state(vport, ndlp,
2782 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002783 ndlp->nlp_last_elscmd = cmd;
2784
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002785 return 1;
dea31012005-04-17 16:05:31 -05002786 }
2787 switch (cmd) {
2788 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002789 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002790 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002791 case ELS_CMD_FDISC:
2792 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2793 return 1;
dea31012005-04-17 16:05:31 -05002794 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002795 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002796 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002797 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002798 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002799 }
James Smart2e0fef82007-06-17 19:56:36 -05002800 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002801 return 1;
dea31012005-04-17 16:05:31 -05002802 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002803 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2805 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002806 return 1;
dea31012005-04-17 16:05:31 -05002807 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002808 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002809 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2810 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002811 return 1;
dea31012005-04-17 16:05:31 -05002812 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002813 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002814 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2815 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002816 return 1;
dea31012005-04-17 16:05:31 -05002817 }
2818 }
dea31012005-04-17 16:05:31 -05002819 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002820 if (logerr) {
2821 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2822 "0137 No retry ELS command x%x to remote "
2823 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2824 cmd, did, irsp->ulpStatus,
2825 irsp->un.ulpWord[4]);
2826 }
2827 else {
2828 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002829 "0108 No retry ELS command x%x to remote "
2830 "NPORT x%x Retried:%d Error:x%x/%x\n",
2831 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2832 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002833 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002834 return 0;
dea31012005-04-17 16:05:31 -05002835}
2836
James Smarte59058c2008-08-24 21:49:00 -04002837/**
James Smart3621a712009-04-06 18:47:14 -04002838 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002839 * @phba: pointer to lpfc hba data structure.
2840 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2841 *
2842 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2843 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2844 * checks to see whether there is a lpfc DMA buffer associated with the
2845 * response of the command IOCB. If so, it will be released before releasing
2846 * the lpfc DMA buffer associated with the IOCB itself.
2847 *
2848 * Return code
2849 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2850 **/
James Smart09372822008-01-11 01:52:54 -05002851static int
James Smart87af33f2007-10-27 13:37:43 -04002852lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2853{
2854 struct lpfc_dmabuf *buf_ptr;
2855
James Smarte59058c2008-08-24 21:49:00 -04002856 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002857 if (!list_empty(&buf_ptr1->list)) {
2858 list_remove_head(&buf_ptr1->list, buf_ptr,
2859 struct lpfc_dmabuf,
2860 list);
2861 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2862 kfree(buf_ptr);
2863 }
2864 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2865 kfree(buf_ptr1);
2866 return 0;
2867}
2868
James Smarte59058c2008-08-24 21:49:00 -04002869/**
James Smart3621a712009-04-06 18:47:14 -04002870 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002871 * @phba: pointer to lpfc hba data structure.
2872 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2873 *
2874 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2875 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2876 * pool.
2877 *
2878 * Return code
2879 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2880 **/
James Smart09372822008-01-11 01:52:54 -05002881static int
James Smart87af33f2007-10-27 13:37:43 -04002882lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2883{
2884 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2885 kfree(buf_ptr);
2886 return 0;
2887}
2888
James Smarte59058c2008-08-24 21:49:00 -04002889/**
James Smart3621a712009-04-06 18:47:14 -04002890 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002891 * @phba: pointer to lpfc hba data structure.
2892 * @elsiocb: pointer to lpfc els command iocb data structure.
2893 *
2894 * This routine frees a command IOCB and its associated resources. The
2895 * command IOCB data structure contains the reference to various associated
2896 * resources, these fields must be set to NULL if the associated reference
2897 * not present:
2898 * context1 - reference to ndlp
2899 * context2 - reference to cmd
2900 * context2->next - reference to rsp
2901 * context3 - reference to bpl
2902 *
2903 * It first properly decrements the reference count held on ndlp for the
2904 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2905 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2906 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2907 * adds the DMA buffer the @phba data structure for the delayed release.
2908 * If reference to the Buffer Pointer List (BPL) is present, the
2909 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2910 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2911 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2912 *
2913 * Return code
2914 * 0 - Success (currently, always return 0)
2915 **/
James Smart87af33f2007-10-27 13:37:43 -04002916int
James Smart329f9bc2007-04-25 09:53:01 -04002917lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002918{
2919 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002920 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002921
James Smarta8adb832007-10-27 13:37:53 -04002922 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2923 if (ndlp) {
2924 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2925 lpfc_nlp_put(ndlp);
2926
2927 /* If the ndlp is not being used by another discovery
2928 * thread, free it.
2929 */
2930 if (!lpfc_nlp_not_used(ndlp)) {
2931 /* If ndlp is being used by another discovery
2932 * thread, just clear NLP_DEFER_RM
2933 */
2934 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2935 }
2936 }
2937 else
2938 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002939 elsiocb->context1 = NULL;
2940 }
dea31012005-04-17 16:05:31 -05002941 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2942 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002943 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2944 /* Firmware could still be in progress of DMAing
2945 * payload, so don't free data buffer till after
2946 * a hbeat.
2947 */
2948 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2949 buf_ptr = elsiocb->context2;
2950 elsiocb->context2 = NULL;
2951 if (buf_ptr) {
2952 buf_ptr1 = NULL;
2953 spin_lock_irq(&phba->hbalock);
2954 if (!list_empty(&buf_ptr->list)) {
2955 list_remove_head(&buf_ptr->list,
2956 buf_ptr1, struct lpfc_dmabuf,
2957 list);
2958 INIT_LIST_HEAD(&buf_ptr1->list);
2959 list_add_tail(&buf_ptr1->list,
2960 &phba->elsbuf);
2961 phba->elsbuf_cnt++;
2962 }
2963 INIT_LIST_HEAD(&buf_ptr->list);
2964 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2965 phba->elsbuf_cnt++;
2966 spin_unlock_irq(&phba->hbalock);
2967 }
2968 } else {
2969 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2970 lpfc_els_free_data(phba, buf_ptr1);
2971 }
dea31012005-04-17 16:05:31 -05002972 }
2973
2974 if (elsiocb->context3) {
2975 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002976 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002977 }
James Bottomley604a3e32005-10-29 10:28:33 -05002978 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002979 return 0;
2980}
2981
James Smarte59058c2008-08-24 21:49:00 -04002982/**
James Smart3621a712009-04-06 18:47:14 -04002983 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04002984 * @phba: pointer to lpfc hba data structure.
2985 * @cmdiocb: pointer to lpfc command iocb data structure.
2986 * @rspiocb: pointer to lpfc response iocb data structure.
2987 *
2988 * This routine is the completion callback function to the Logout (LOGO)
2989 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2990 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2991 * release the ndlp if it has the last reference remaining (reference count
2992 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2993 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2994 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2995 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2996 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2997 * IOCB data structure.
2998 **/
dea31012005-04-17 16:05:31 -05002999static void
James Smart2e0fef82007-06-17 19:56:36 -05003000lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3001 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003002{
James Smart2e0fef82007-06-17 19:56:36 -05003003 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3004 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003005 IOCB_t *irsp;
3006
3007 irsp = &rspiocb->iocb;
3008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3009 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3010 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003011 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003012 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3013 "0109 ACC to LOGO completes to NPort x%x "
3014 "Data: x%x x%x x%x\n",
3015 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3016 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003017
3018 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3019 /* NPort Recovery mode or node is just allocated */
3020 if (!lpfc_nlp_not_used(ndlp)) {
3021 /* If the ndlp is being used by another discovery
3022 * thread, just unregister the RPI.
3023 */
3024 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003025 } else {
3026 /* Indicate the node has already released, should
3027 * not reference to it from within lpfc_els_free_iocb.
3028 */
3029 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003030 }
dea31012005-04-17 16:05:31 -05003031 }
3032 lpfc_els_free_iocb(phba, cmdiocb);
3033 return;
3034}
3035
James Smarte59058c2008-08-24 21:49:00 -04003036/**
James Smart3621a712009-04-06 18:47:14 -04003037 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003038 * @phba: pointer to lpfc hba data structure.
3039 * @pmb: pointer to the driver internal queue element for mailbox command.
3040 *
3041 * This routine is the completion callback function for unregister default
3042 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3043 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3044 * decrements the ndlp reference count held for this completion callback
3045 * function. After that, it invokes the lpfc_nlp_not_used() to check
3046 * whether there is only one reference left on the ndlp. If so, it will
3047 * perform one more decrement and trigger the release of the ndlp.
3048 **/
James Smart858c9f62007-06-17 19:56:39 -05003049void
3050lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3051{
3052 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3053 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3054
James Smart6fb120a2009-05-22 14:52:59 -04003055 /*
3056 * This routine is used to register and unregister in previous SLI
3057 * modes.
3058 */
3059 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3060 (phba->sli_rev == LPFC_SLI_REV4))
3061 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3062
James Smart858c9f62007-06-17 19:56:39 -05003063 pmb->context1 = NULL;
3064 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3065 kfree(mp);
3066 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003067 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003068 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003069 /* This is the end of the default RPI cleanup logic for this
3070 * ndlp. If no other discovery threads are using this ndlp.
3071 * we should free all resources associated with it.
3072 */
3073 lpfc_nlp_not_used(ndlp);
3074 }
James Smart3772a992009-05-22 14:50:54 -04003075
James Smart858c9f62007-06-17 19:56:39 -05003076 return;
3077}
3078
James Smarte59058c2008-08-24 21:49:00 -04003079/**
James Smart3621a712009-04-06 18:47:14 -04003080 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003081 * @phba: pointer to lpfc hba data structure.
3082 * @cmdiocb: pointer to lpfc command iocb data structure.
3083 * @rspiocb: pointer to lpfc response iocb data structure.
3084 *
3085 * This routine is the completion callback function for ELS Response IOCB
3086 * command. In normal case, this callback function just properly sets the
3087 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3088 * field in the command IOCB is not NULL, the referred mailbox command will
3089 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3090 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3091 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3092 * routine shall be invoked trying to release the ndlp if no other threads
3093 * are currently referring it.
3094 **/
dea31012005-04-17 16:05:31 -05003095static void
James Smart858c9f62007-06-17 19:56:39 -05003096lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003097 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003098{
James Smart2e0fef82007-06-17 19:56:36 -05003099 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3100 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3101 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003102 IOCB_t *irsp;
3103 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003104 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003105 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003106 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003107
James Smart33ccf8d2006-08-17 11:57:58 -04003108 irsp = &rspiocb->iocb;
3109
dea31012005-04-17 16:05:31 -05003110 if (cmdiocb->context_un.mbox)
3111 mbox = cmdiocb->context_un.mbox;
3112
James Smartfa4066b2008-01-11 01:53:27 -05003113 /* First determine if this is a LS_RJT cmpl. Note, this callback
3114 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3115 */
James Smart87af33f2007-10-27 13:37:43 -04003116 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003117 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3118 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003119 /* A LS_RJT associated with Default RPI cleanup has its own
3120 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04003121 */
3122 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3123 ls_rjt = 1;
3124 }
3125
dea31012005-04-17 16:05:31 -05003126 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003127 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003128 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003129 mp = (struct lpfc_dmabuf *) mbox->context1;
3130 if (mp) {
3131 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3132 kfree(mp);
3133 }
James Smart329f9bc2007-04-25 09:53:01 -04003134 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003135 }
James Smart58da1ff2008-04-07 10:15:56 -04003136 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3137 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003138 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003139 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003140 /* Indicate the node has already released,
3141 * should not reference to it from within
3142 * the routine lpfc_els_free_iocb.
3143 */
3144 cmdiocb->context1 = NULL;
3145 }
dea31012005-04-17 16:05:31 -05003146 goto out;
3147 }
3148
James Smart858c9f62007-06-17 19:56:39 -05003149 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003150 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003151 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003152 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003153 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003154 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3155 "0110 ELS response tag x%x completes "
3156 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3157 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3158 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3159 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3160 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003161 if (mbox) {
3162 if ((rspiocb->iocb.ulpStatus == 0)
3163 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003164 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003165 /* Increment reference count to ndlp to hold the
3166 * reference to ndlp for the callback function.
3167 */
James Smart329f9bc2007-04-25 09:53:01 -04003168 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003169 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003170 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3171 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3172 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3173 }
3174 else {
3175 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3176 ndlp->nlp_prev_state = ndlp->nlp_state;
3177 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003178 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003179 }
James Smart0b727fe2007-10-27 13:37:25 -04003180 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003181 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003182 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003183 else
3184 /* Decrement the ndlp reference count we
3185 * set for this failed mailbox command.
3186 */
3187 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003188
3189 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3190 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3191 "0138 ELS rsp: Cannot issue reg_login for x%x "
3192 "Data: x%x x%x x%x\n",
3193 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3194 ndlp->nlp_rpi);
3195
James Smartfa4066b2008-01-11 01:53:27 -05003196 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003197 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003198 /* Indicate node has already been released,
3199 * should not reference to it from within
3200 * the routine lpfc_els_free_iocb.
3201 */
3202 cmdiocb->context1 = NULL;
3203 }
dea31012005-04-17 16:05:31 -05003204 } else {
James Smart858c9f62007-06-17 19:56:39 -05003205 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3206 if (!lpfc_error_lost_link(irsp) &&
3207 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003208 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003209 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003210 /* Indicate node has already been
3211 * released, should not reference
3212 * to it from within the routine
3213 * lpfc_els_free_iocb.
3214 */
3215 cmdiocb->context1 = NULL;
3216 }
dea31012005-04-17 16:05:31 -05003217 }
3218 }
James Smart14691152006-12-02 13:34:28 -05003219 mp = (struct lpfc_dmabuf *) mbox->context1;
3220 if (mp) {
3221 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3222 kfree(mp);
3223 }
3224 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003225 }
3226out:
James Smart58da1ff2008-04-07 10:15:56 -04003227 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003228 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003229 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003230 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003231
3232 /* If the node is not being used by another discovery thread,
3233 * and we are sending a reject, we are done with it.
3234 * Release driver reference count here and free associated
3235 * resources.
3236 */
3237 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003238 if (lpfc_nlp_not_used(ndlp))
3239 /* Indicate node has already been released,
3240 * should not reference to it from within
3241 * the routine lpfc_els_free_iocb.
3242 */
3243 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003244 }
James Smart87af33f2007-10-27 13:37:43 -04003245
dea31012005-04-17 16:05:31 -05003246 lpfc_els_free_iocb(phba, cmdiocb);
3247 return;
3248}
3249
James Smarte59058c2008-08-24 21:49:00 -04003250/**
James Smart3621a712009-04-06 18:47:14 -04003251 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003252 * @vport: pointer to a host virtual N_Port data structure.
3253 * @flag: the els command code to be accepted.
3254 * @oldiocb: pointer to the original lpfc command iocb data structure.
3255 * @ndlp: pointer to a node-list data structure.
3256 * @mbox: pointer to the driver internal queue element for mailbox command.
3257 *
3258 * This routine prepares and issues an Accept (ACC) response IOCB
3259 * command. It uses the @flag to properly set up the IOCB field for the
3260 * specific ACC response command to be issued and invokes the
3261 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3262 * @mbox pointer is passed in, it will be put into the context_un.mbox
3263 * field of the IOCB for the completion callback function to issue the
3264 * mailbox command to the HBA later when callback is invoked.
3265 *
3266 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3267 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3268 * will be stored into the context1 field of the IOCB for the completion
3269 * callback function to the corresponding response ELS IOCB command.
3270 *
3271 * Return code
3272 * 0 - Successfully issued acc response
3273 * 1 - Failed to issue acc response
3274 **/
dea31012005-04-17 16:05:31 -05003275int
James Smart2e0fef82007-06-17 19:56:36 -05003276lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3277 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003278 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003279{
James Smart2e0fef82007-06-17 19:56:36 -05003280 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3281 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003282 IOCB_t *icmd;
3283 IOCB_t *oldcmd;
3284 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003285 struct lpfc_sli *psli;
3286 uint8_t *pcmd;
3287 uint16_t cmdsize;
3288 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003289 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003290
3291 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003292 oldcmd = &oldiocb->iocb;
3293
3294 switch (flag) {
3295 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003296 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003297 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3298 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003299 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003300 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003301 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003302 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003303 return 1;
dea31012005-04-17 16:05:31 -05003304 }
James Smart2e0fef82007-06-17 19:56:36 -05003305
dea31012005-04-17 16:05:31 -05003306 icmd = &elsiocb->iocb;
3307 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3308 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3309 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003310 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003311
3312 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3313 "Issue ACC: did:x%x flg:x%x",
3314 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003315 break;
3316 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003317 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003318 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3319 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003320 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003321 return 1;
James Smart488d1462006-03-07 15:02:37 -05003322
dea31012005-04-17 16:05:31 -05003323 icmd = &elsiocb->iocb;
3324 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3325 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3326
3327 if (mbox)
3328 elsiocb->context_un.mbox = mbox;
3329
3330 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003331 pcmd += sizeof(uint32_t);
3332 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003333
3334 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3335 "Issue ACC PLOGI: did:x%x flg:x%x",
3336 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003337 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003338 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003339 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003340 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003341 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3342 if (!elsiocb)
3343 return 1;
3344
3345 icmd = &elsiocb->iocb;
3346 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3347 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3348
3349 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003350 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003351 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3352 els_pkt_ptr = (ELS_PKT *) pcmd;
3353 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003354
3355 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3356 "Issue ACC PRLO: did:x%x flg:x%x",
3357 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003358 break;
dea31012005-04-17 16:05:31 -05003359 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003360 return 1;
dea31012005-04-17 16:05:31 -05003361 }
dea31012005-04-17 16:05:31 -05003362 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003363 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3364 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3365 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3366 elsiocb->iotag, elsiocb->iocb.ulpContext,
3367 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3368 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003369 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003370 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003371 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003372 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003373 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3374 } else {
James Smart858c9f62007-06-17 19:56:39 -05003375 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003376 }
3377
3378 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003379 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003380 if (rc == IOCB_ERROR) {
3381 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003382 return 1;
dea31012005-04-17 16:05:31 -05003383 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003384 return 0;
dea31012005-04-17 16:05:31 -05003385}
3386
James Smarte59058c2008-08-24 21:49:00 -04003387/**
James Smart3621a712009-04-06 18:47:14 -04003388 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003389 * @vport: pointer to a virtual N_Port data structure.
3390 * @rejectError:
3391 * @oldiocb: pointer to the original lpfc command iocb data structure.
3392 * @ndlp: pointer to a node-list data structure.
3393 * @mbox: pointer to the driver internal queue element for mailbox command.
3394 *
3395 * This routine prepares and issue an Reject (RJT) response IOCB
3396 * command. If a @mbox pointer is passed in, it will be put into the
3397 * context_un.mbox field of the IOCB for the completion callback function
3398 * to issue to the HBA later.
3399 *
3400 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3401 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3402 * will be stored into the context1 field of the IOCB for the completion
3403 * callback function to the reject response ELS IOCB command.
3404 *
3405 * Return code
3406 * 0 - Successfully issued reject response
3407 * 1 - Failed to issue reject response
3408 **/
dea31012005-04-17 16:05:31 -05003409int
James Smart2e0fef82007-06-17 19:56:36 -05003410lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003411 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3412 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003413{
James Smart2e0fef82007-06-17 19:56:36 -05003414 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003415 IOCB_t *icmd;
3416 IOCB_t *oldcmd;
3417 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003418 struct lpfc_sli *psli;
3419 uint8_t *pcmd;
3420 uint16_t cmdsize;
3421 int rc;
3422
3423 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003424 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003425 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3426 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003427 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003428 return 1;
dea31012005-04-17 16:05:31 -05003429
3430 icmd = &elsiocb->iocb;
3431 oldcmd = &oldiocb->iocb;
3432 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3433 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3434
3435 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003436 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003437 *((uint32_t *) (pcmd)) = rejectError;
3438
James Smart51ef4c22007-08-02 11:10:31 -04003439 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003440 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003441
dea31012005-04-17 16:05:31 -05003442 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003443 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3444 "0129 Xmit ELS RJT x%x response tag x%x "
3445 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3446 "rpi x%x\n",
3447 rejectError, elsiocb->iotag,
3448 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3449 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003450 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3451 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3452 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3453
dea31012005-04-17 16:05:31 -05003454 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003455 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003456 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003457
dea31012005-04-17 16:05:31 -05003458 if (rc == IOCB_ERROR) {
3459 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003460 return 1;
dea31012005-04-17 16:05:31 -05003461 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003462 return 0;
dea31012005-04-17 16:05:31 -05003463}
3464
James Smarte59058c2008-08-24 21:49:00 -04003465/**
James Smart3621a712009-04-06 18:47:14 -04003466 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003467 * @vport: pointer to a virtual N_Port data structure.
3468 * @oldiocb: pointer to the original lpfc command iocb data structure.
3469 * @ndlp: pointer to a node-list data structure.
3470 *
3471 * This routine prepares and issues an Accept (ACC) response to Address
3472 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3473 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3474 *
3475 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3476 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3477 * will be stored into the context1 field of the IOCB for the completion
3478 * callback function to the ADISC Accept response ELS IOCB command.
3479 *
3480 * Return code
3481 * 0 - Successfully issued acc adisc response
3482 * 1 - Failed to issue adisc acc response
3483 **/
dea31012005-04-17 16:05:31 -05003484int
James Smart2e0fef82007-06-17 19:56:36 -05003485lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3486 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003487{
James Smart2e0fef82007-06-17 19:56:36 -05003488 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003489 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003490 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003491 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003492 uint8_t *pcmd;
3493 uint16_t cmdsize;
3494 int rc;
3495
James Smart92d7f7b2007-06-17 19:56:38 -05003496 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003497 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3498 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003499 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003500 return 1;
dea31012005-04-17 16:05:31 -05003501
dea31012005-04-17 16:05:31 -05003502 icmd = &elsiocb->iocb;
3503 oldcmd = &oldiocb->iocb;
3504 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003505
3506 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003507 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3508 "0130 Xmit ADISC ACC response iotag x%x xri: "
3509 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3510 elsiocb->iotag, elsiocb->iocb.ulpContext,
3511 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3512 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003513 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3514
3515 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003516 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003517
3518 ap = (ADISC *) (pcmd);
3519 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003520 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3521 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003522 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003523
James Smart858c9f62007-06-17 19:56:39 -05003524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3525 "Issue ACC ADISC: did:x%x flg:x%x",
3526 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3527
dea31012005-04-17 16:05:31 -05003528 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003529 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003530 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003531 if (rc == IOCB_ERROR) {
3532 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003533 return 1;
dea31012005-04-17 16:05:31 -05003534 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003535 return 0;
dea31012005-04-17 16:05:31 -05003536}
3537
James Smarte59058c2008-08-24 21:49:00 -04003538/**
James Smart3621a712009-04-06 18:47:14 -04003539 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003540 * @vport: pointer to a virtual N_Port data structure.
3541 * @oldiocb: pointer to the original lpfc command iocb data structure.
3542 * @ndlp: pointer to a node-list data structure.
3543 *
3544 * This routine prepares and issues an Accept (ACC) response to Process
3545 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3546 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3547 *
3548 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3549 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3550 * will be stored into the context1 field of the IOCB for the completion
3551 * callback function to the PRLI Accept response ELS IOCB command.
3552 *
3553 * Return code
3554 * 0 - Successfully issued acc prli response
3555 * 1 - Failed to issue acc prli response
3556 **/
dea31012005-04-17 16:05:31 -05003557int
James Smart2e0fef82007-06-17 19:56:36 -05003558lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003559 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003560{
James Smart2e0fef82007-06-17 19:56:36 -05003561 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003562 PRLI *npr;
3563 lpfc_vpd_t *vpd;
3564 IOCB_t *icmd;
3565 IOCB_t *oldcmd;
3566 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003567 struct lpfc_sli *psli;
3568 uint8_t *pcmd;
3569 uint16_t cmdsize;
3570 int rc;
3571
3572 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003573
James Smart92d7f7b2007-06-17 19:56:38 -05003574 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003575 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003576 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003577 if (!elsiocb)
3578 return 1;
dea31012005-04-17 16:05:31 -05003579
dea31012005-04-17 16:05:31 -05003580 icmd = &elsiocb->iocb;
3581 oldcmd = &oldiocb->iocb;
3582 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003583 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003584 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3585 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3586 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3587 elsiocb->iotag, elsiocb->iocb.ulpContext,
3588 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3589 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003590 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3591
3592 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003593 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003594
3595 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003596 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003597
3598 npr = (PRLI *) pcmd;
3599 vpd = &phba->vpd;
3600 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003601 * If the remote port is a target and our firmware version is 3.20 or
3602 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003603 */
James Smart0d2b6b82008-06-14 22:52:47 -04003604 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3605 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003606 npr->ConfmComplAllowed = 1;
3607 npr->Retry = 1;
3608 npr->TaskRetryIdReq = 1;
3609 }
3610
3611 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3612 npr->estabImagePair = 1;
3613 npr->readXferRdyDis = 1;
3614 npr->ConfmComplAllowed = 1;
3615
3616 npr->prliType = PRLI_FCP_TYPE;
3617 npr->initiatorFunc = 1;
3618
James Smart858c9f62007-06-17 19:56:39 -05003619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3620 "Issue ACC PRLI: did:x%x flg:x%x",
3621 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3622
dea31012005-04-17 16:05:31 -05003623 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003624 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003625
James Smart3772a992009-05-22 14:50:54 -04003626 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003627 if (rc == IOCB_ERROR) {
3628 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003629 return 1;
dea31012005-04-17 16:05:31 -05003630 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003631 return 0;
dea31012005-04-17 16:05:31 -05003632}
3633
James Smarte59058c2008-08-24 21:49:00 -04003634/**
James Smart3621a712009-04-06 18:47:14 -04003635 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003636 * @vport: pointer to a virtual N_Port data structure.
3637 * @format: rnid command format.
3638 * @oldiocb: pointer to the original lpfc command iocb data structure.
3639 * @ndlp: pointer to a node-list data structure.
3640 *
3641 * This routine issues a Request Node Identification Data (RNID) Accept
3642 * (ACC) response. It constructs the RNID ACC response command according to
3643 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3644 * issue the response. Note that this command does not need to hold the ndlp
3645 * reference count for the callback. So, the ndlp reference count taken by
3646 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3647 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3648 * there is no ndlp reference available.
3649 *
3650 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3651 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3652 * will be stored into the context1 field of the IOCB for the completion
3653 * callback function. However, for the RNID Accept Response ELS command,
3654 * this is undone later by this routine after the IOCB is allocated.
3655 *
3656 * Return code
3657 * 0 - Successfully issued acc rnid response
3658 * 1 - Failed to issue acc rnid response
3659 **/
dea31012005-04-17 16:05:31 -05003660static int
James Smart2e0fef82007-06-17 19:56:36 -05003661lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003662 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003663{
James Smart2e0fef82007-06-17 19:56:36 -05003664 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003665 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003666 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003667 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003668 struct lpfc_sli *psli;
3669 uint8_t *pcmd;
3670 uint16_t cmdsize;
3671 int rc;
3672
3673 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003674 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3675 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003676 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003677 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003678
James Smart2e0fef82007-06-17 19:56:36 -05003679 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3680 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003681 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003682 return 1;
dea31012005-04-17 16:05:31 -05003683
dea31012005-04-17 16:05:31 -05003684 icmd = &elsiocb->iocb;
3685 oldcmd = &oldiocb->iocb;
3686 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003687 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003688 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3689 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3690 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003691 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003692 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003693 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003694
James Smart92d7f7b2007-06-17 19:56:38 -05003695 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003696 rn = (RNID *) (pcmd);
3697 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003698 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3699 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3700 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003701 switch (format) {
3702 case 0:
3703 rn->SpecificLen = 0;
3704 break;
3705 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003706 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003707 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003708 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003709 rn->un.topologyDisc.unitType = RNID_HBA;
3710 rn->un.topologyDisc.physPort = 0;
3711 rn->un.topologyDisc.attachedNodes = 0;
3712 break;
3713 default:
3714 rn->CommonLen = 0;
3715 rn->SpecificLen = 0;
3716 break;
3717 }
3718
James Smart858c9f62007-06-17 19:56:39 -05003719 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3720 "Issue ACC RNID: did:x%x flg:x%x",
3721 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3722
dea31012005-04-17 16:05:31 -05003723 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003724 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003725 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003726 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3727 * it could be freed */
3728
James Smart3772a992009-05-22 14:50:54 -04003729 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003730 if (rc == IOCB_ERROR) {
3731 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003732 return 1;
dea31012005-04-17 16:05:31 -05003733 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003734 return 0;
dea31012005-04-17 16:05:31 -05003735}
3736
James Smarte59058c2008-08-24 21:49:00 -04003737/**
James Smart3621a712009-04-06 18:47:14 -04003738 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003739 * @vport: pointer to a host virtual N_Port data structure.
3740 *
3741 * This routine issues Address Discover (ADISC) ELS commands to those
3742 * N_Ports which are in node port recovery state and ADISC has not been issued
3743 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3744 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3745 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3746 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3747 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3748 * IOCBs quit for later pick up. On the other hand, after walking through
3749 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3750 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3751 * no more ADISC need to be sent.
3752 *
3753 * Return code
3754 * The number of N_Ports with adisc issued.
3755 **/
dea31012005-04-17 16:05:31 -05003756int
James Smart2e0fef82007-06-17 19:56:36 -05003757lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003758{
James Smart2e0fef82007-06-17 19:56:36 -05003759 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003760 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003761 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003762
James Smart685f0bf2007-04-25 09:53:08 -04003763 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003764 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003765 if (!NLP_CHK_NODE_ACT(ndlp))
3766 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003767 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3768 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3769 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003770 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003771 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003772 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003773 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003774 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3775 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003776 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003777 vport->num_disc_nodes++;
3778 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003779 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003780 spin_lock_irq(shost->host_lock);
3781 vport->fc_flag |= FC_NLP_MORE;
3782 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003783 break;
dea31012005-04-17 16:05:31 -05003784 }
3785 }
3786 }
3787 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003788 spin_lock_irq(shost->host_lock);
3789 vport->fc_flag &= ~FC_NLP_MORE;
3790 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003791 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003792 return sentadisc;
dea31012005-04-17 16:05:31 -05003793}
3794
James Smarte59058c2008-08-24 21:49:00 -04003795/**
James Smart3621a712009-04-06 18:47:14 -04003796 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003797 * @vport: pointer to a host virtual N_Port data structure.
3798 *
3799 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3800 * which are in node port recovery state, with a @vport. Each time an ELS
3801 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3802 * the per @vport number of discover count (num_disc_nodes) shall be
3803 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3804 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3805 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3806 * later pick up. On the other hand, after walking through all the ndlps with
3807 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3808 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3809 * PLOGI need to be sent.
3810 *
3811 * Return code
3812 * The number of N_Ports with plogi issued.
3813 **/
dea31012005-04-17 16:05:31 -05003814int
James Smart2e0fef82007-06-17 19:56:36 -05003815lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003816{
James Smart2e0fef82007-06-17 19:56:36 -05003817 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003818 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003819 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003820
James Smart2e0fef82007-06-17 19:56:36 -05003821 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3822 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003823 if (!NLP_CHK_NODE_ACT(ndlp))
3824 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003825 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3826 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3827 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3828 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3829 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003830 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3831 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003832 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003833 vport->num_disc_nodes++;
3834 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003835 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003836 spin_lock_irq(shost->host_lock);
3837 vport->fc_flag |= FC_NLP_MORE;
3838 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003839 break;
dea31012005-04-17 16:05:31 -05003840 }
3841 }
3842 }
James Smart87af33f2007-10-27 13:37:43 -04003843 if (sentplogi) {
3844 lpfc_set_disctmo(vport);
3845 }
3846 else {
James Smart2e0fef82007-06-17 19:56:36 -05003847 spin_lock_irq(shost->host_lock);
3848 vport->fc_flag &= ~FC_NLP_MORE;
3849 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003850 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003851 return sentplogi;
dea31012005-04-17 16:05:31 -05003852}
3853
James Smarte59058c2008-08-24 21:49:00 -04003854/**
James Smart3621a712009-04-06 18:47:14 -04003855 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003856 * @vport: pointer to a host virtual N_Port data structure.
3857 *
3858 * This routine cleans up any Registration State Change Notification
3859 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3860 * @vport together with the host_lock is used to prevent multiple thread
3861 * trying to access the RSCN array on a same @vport at the same time.
3862 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003863void
James Smart2e0fef82007-06-17 19:56:36 -05003864lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003865{
James Smart2e0fef82007-06-17 19:56:36 -05003866 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3867 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003868 int i;
3869
James Smart7f5f3d02008-02-08 18:50:14 -05003870 spin_lock_irq(shost->host_lock);
3871 if (vport->fc_rscn_flush) {
3872 /* Another thread is walking fc_rscn_id_list on this vport */
3873 spin_unlock_irq(shost->host_lock);
3874 return;
3875 }
3876 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3877 vport->fc_rscn_flush = 1;
3878 spin_unlock_irq(shost->host_lock);
3879
James Smart2e0fef82007-06-17 19:56:36 -05003880 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003881 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003882 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003883 }
James Smart2e0fef82007-06-17 19:56:36 -05003884 spin_lock_irq(shost->host_lock);
3885 vport->fc_rscn_id_cnt = 0;
3886 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3887 spin_unlock_irq(shost->host_lock);
3888 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003889 /* Indicate we are done walking this fc_rscn_id_list */
3890 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003891}
3892
James Smarte59058c2008-08-24 21:49:00 -04003893/**
James Smart3621a712009-04-06 18:47:14 -04003894 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003895 * @vport: pointer to a host virtual N_Port data structure.
3896 * @did: remote destination port identifier.
3897 *
3898 * This routine checks whether there is any pending Registration State
3899 * Configuration Notification (RSCN) to a @did on @vport.
3900 *
3901 * Return code
3902 * None zero - The @did matched with a pending rscn
3903 * 0 - not able to match @did with a pending rscn
3904 **/
dea31012005-04-17 16:05:31 -05003905int
James Smart2e0fef82007-06-17 19:56:36 -05003906lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003907{
3908 D_ID ns_did;
3909 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003910 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003911 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003912 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003913
3914 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05003915
3916 /* Never match fabric nodes for RSCNs */
3917 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003918 return 0;
dea31012005-04-17 16:05:31 -05003919
3920 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003921 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003922 return did;
dea31012005-04-17 16:05:31 -05003923
James Smart7f5f3d02008-02-08 18:50:14 -05003924 spin_lock_irq(shost->host_lock);
3925 if (vport->fc_rscn_flush) {
3926 /* Another thread is walking fc_rscn_id_list on this vport */
3927 spin_unlock_irq(shost->host_lock);
3928 return 0;
3929 }
3930 /* Indicate we are walking fc_rscn_id_list on this vport */
3931 vport->fc_rscn_flush = 1;
3932 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003933 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003934 lp = vport->fc_rscn_id_list[i]->virt;
3935 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3936 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003937 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003938 rscn_did.un.word = be32_to_cpu(*lp++);
3939 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05003940 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3941 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04003942 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3943 && (ns_did.un.b.area == rscn_did.un.b.area)
3944 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05003945 goto return_did_out;
dea31012005-04-17 16:05:31 -05003946 break;
James Smarteaf15d52008-12-04 22:39:29 -05003947 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05003948 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3949 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003950 goto return_did_out;
dea31012005-04-17 16:05:31 -05003951 break;
James Smarteaf15d52008-12-04 22:39:29 -05003952 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05003953 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003954 goto return_did_out;
dea31012005-04-17 16:05:31 -05003955 break;
James Smarteaf15d52008-12-04 22:39:29 -05003956 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05003957 goto return_did_out;
dea31012005-04-17 16:05:31 -05003958 }
3959 }
James Smart92d7f7b2007-06-17 19:56:38 -05003960 }
James Smart7f5f3d02008-02-08 18:50:14 -05003961 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3962 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003963 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003964return_did_out:
3965 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3966 vport->fc_rscn_flush = 0;
3967 return did;
dea31012005-04-17 16:05:31 -05003968}
3969
James Smarte59058c2008-08-24 21:49:00 -04003970/**
James Smart3621a712009-04-06 18:47:14 -04003971 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04003972 * @vport: pointer to a host virtual N_Port data structure.
3973 *
3974 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3975 * state machine for a @vport's nodes that are with pending RSCN (Registration
3976 * State Change Notification).
3977 *
3978 * Return code
3979 * 0 - Successful (currently alway return 0)
3980 **/
dea31012005-04-17 16:05:31 -05003981static int
James Smart2e0fef82007-06-17 19:56:36 -05003982lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003983{
James Smart685f0bf2007-04-25 09:53:08 -04003984 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003985
James Smart0d2b6b82008-06-14 22:52:47 -04003986 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003987 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003988 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04003989 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3990 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05003991 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003992 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04003993 NLP_EVT_DEVICE_RECOVERY);
3994 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003995 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003996 return 0;
dea31012005-04-17 16:05:31 -05003997}
3998
James Smarte59058c2008-08-24 21:49:00 -04003999/**
James Smart3621a712009-04-06 18:47:14 -04004000 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004001 * @vport: pointer to a host virtual N_Port data structure.
4002 * @cmdiocb: pointer to lpfc command iocb data structure.
4003 *
4004 * lpfc_send_rscn_event sends an RSCN netlink event to management
4005 * applications.
4006 */
4007static void
4008lpfc_send_rscn_event(struct lpfc_vport *vport,
4009 struct lpfc_iocbq *cmdiocb)
4010{
4011 struct lpfc_dmabuf *pcmd;
4012 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4013 uint32_t *payload_ptr;
4014 uint32_t payload_len;
4015 struct lpfc_rscn_event_header *rscn_event_data;
4016
4017 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4018 payload_ptr = (uint32_t *) pcmd->virt;
4019 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4020
4021 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4022 payload_len, GFP_KERNEL);
4023 if (!rscn_event_data) {
4024 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4025 "0147 Failed to allocate memory for RSCN event\n");
4026 return;
4027 }
4028 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4029 rscn_event_data->payload_length = payload_len;
4030 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4031 payload_len);
4032
4033 fc_host_post_vendor_event(shost,
4034 fc_get_event_number(),
4035 sizeof(struct lpfc_els_event_header) + payload_len,
4036 (char *)rscn_event_data,
4037 LPFC_NL_VENDOR_ID);
4038
4039 kfree(rscn_event_data);
4040}
4041
4042/**
James Smart3621a712009-04-06 18:47:14 -04004043 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004044 * @vport: pointer to a host virtual N_Port data structure.
4045 * @cmdiocb: pointer to lpfc command iocb data structure.
4046 * @ndlp: pointer to a node-list data structure.
4047 *
4048 * This routine processes an unsolicited RSCN (Registration State Change
4049 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4050 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4051 * discover state machine is about to begin discovery, it just accepts the
4052 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4053 * contains N_Port IDs for other vports on this HBA, it just accepts the
4054 * RSCN and ignore processing it. If the state machine is in the recovery
4055 * state, the fc_rscn_id_list of this @vport is walked and the
4056 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4057 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4058 * routine is invoked to handle the RSCN event.
4059 *
4060 * Return code
4061 * 0 - Just sent the acc response
4062 * 1 - Sent the acc response and waited for name server completion
4063 **/
dea31012005-04-17 16:05:31 -05004064static int
James Smart2e0fef82007-06-17 19:56:36 -05004065lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004066 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004067{
James Smart2e0fef82007-06-17 19:56:36 -05004068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4069 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004070 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004071 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004072 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004073 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004074 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004075 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004076 int i;
dea31012005-04-17 16:05:31 -05004077
4078 icmd = &cmdiocb->iocb;
4079 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4080 lp = (uint32_t *) pcmd->virt;
4081
James Smart92d7f7b2007-06-17 19:56:38 -05004082 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4083 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004084 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004085 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4086 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004087 vport->fc_flag, payload_len, *lp,
4088 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004089
4090 /* Send an RSCN event to the management application */
4091 lpfc_send_rscn_event(vport, cmdiocb);
4092
James Smartd2873e42006-08-18 17:46:43 -04004093 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004094 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004095 FCH_EVT_RSCN, lp[i]);
4096
dea31012005-04-17 16:05:31 -05004097 /* If we are about to begin discovery, just ACC the RSCN.
4098 * Discovery processing will satisfy it.
4099 */
James Smart2e0fef82007-06-17 19:56:36 -05004100 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004101 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4102 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4103 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4104
James Smart51ef4c22007-08-02 11:10:31 -04004105 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004106 return 0;
dea31012005-04-17 16:05:31 -05004107 }
4108
James Smart92d7f7b2007-06-17 19:56:38 -05004109 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4110 * just ACC and ignore it.
4111 */
4112 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004113 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004114 i = payload_len;
4115 datap = lp;
4116 while (i > 0) {
4117 nportid = *datap++;
4118 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4119 i -= sizeof(uint32_t);
4120 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004121 if (lpfc_find_vport_by_did(phba, nportid))
4122 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004123 }
4124 if (rscn_id == hba_id) {
4125 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004126 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004127 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004128 "Data: x%x x%x x%x x%x\n",
4129 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004130 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4132 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4133 ndlp->nlp_DID, vport->port_state,
4134 ndlp->nlp_flag);
4135
James Smart92d7f7b2007-06-17 19:56:38 -05004136 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004137 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004138 return 0;
4139 }
4140 }
4141
James Smart7f5f3d02008-02-08 18:50:14 -05004142 spin_lock_irq(shost->host_lock);
4143 if (vport->fc_rscn_flush) {
4144 /* Another thread is walking fc_rscn_id_list on this vport */
4145 spin_unlock_irq(shost->host_lock);
4146 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart58da1ff2008-04-07 10:15:56 -04004147 /* Send back ACC */
4148 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004149 return 0;
4150 }
4151 /* Indicate we are walking fc_rscn_id_list on this vport */
4152 vport->fc_rscn_flush = 1;
4153 spin_unlock_irq(shost->host_lock);
4154 /* Get the array count after sucessfully have the token */
4155 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004156 /* If we are already processing an RSCN, save the received
4157 * RSCN payload buffer, cmdiocb->context2 to process later.
4158 */
James Smart2e0fef82007-06-17 19:56:36 -05004159 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4161 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4162 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4163
James Smart09372822008-01-11 01:52:54 -05004164 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004165 vport->fc_flag |= FC_RSCN_DEFERRED;
4166 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004167 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004168 vport->fc_flag |= FC_RSCN_MODE;
4169 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004170 if (rscn_cnt) {
4171 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4172 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4173 }
4174 if ((rscn_cnt) &&
4175 (payload_len + length <= LPFC_BPL_SIZE)) {
4176 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004177 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004178 memcpy(((uint8_t *)cmd) + length, lp,
4179 payload_len);
4180 } else {
4181 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4182 vport->fc_rscn_id_cnt++;
4183 /* If we zero, cmdiocb->context2, the calling
4184 * routine will not try to free it.
4185 */
4186 cmdiocb->context2 = NULL;
4187 }
dea31012005-04-17 16:05:31 -05004188 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004189 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4190 "0235 Deferred RSCN "
4191 "Data: x%x x%x x%x\n",
4192 vport->fc_rscn_id_cnt, vport->fc_flag,
4193 vport->port_state);
dea31012005-04-17 16:05:31 -05004194 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004195 vport->fc_flag |= FC_RSCN_DISCOVERY;
4196 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004197 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004198 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4199 "0234 ReDiscovery RSCN "
4200 "Data: x%x x%x x%x\n",
4201 vport->fc_rscn_id_cnt, vport->fc_flag,
4202 vport->port_state);
dea31012005-04-17 16:05:31 -05004203 }
James Smart7f5f3d02008-02-08 18:50:14 -05004204 /* Indicate we are done walking fc_rscn_id_list on this vport */
4205 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004206 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004207 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004208 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004209 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004210 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004211 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004212 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004213 return 0;
dea31012005-04-17 16:05:31 -05004214 }
James Smart858c9f62007-06-17 19:56:39 -05004215 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4216 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4217 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4218
James Smart2e0fef82007-06-17 19:56:36 -05004219 spin_lock_irq(shost->host_lock);
4220 vport->fc_flag |= FC_RSCN_MODE;
4221 spin_unlock_irq(shost->host_lock);
4222 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004223 /* Indicate we are done walking fc_rscn_id_list on this vport */
4224 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004225 /*
4226 * If we zero, cmdiocb->context2, the calling routine will
4227 * not try to free it.
4228 */
4229 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004230 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004231 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004232 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004233 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004234 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004235 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004236}
4237
James Smarte59058c2008-08-24 21:49:00 -04004238/**
James Smart3621a712009-04-06 18:47:14 -04004239 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004240 * @vport: pointer to a host virtual N_Port data structure.
4241 *
4242 * This routine handles the Registration State Configuration Notification
4243 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4244 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4245 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4246 * NameServer shall be issued. If CT command to the NameServer fails to be
4247 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4248 * RSCN activities with the @vport.
4249 *
4250 * Return code
4251 * 0 - Cleaned up rscn on the @vport
4252 * 1 - Wait for plogi to name server before proceed
4253 **/
dea31012005-04-17 16:05:31 -05004254int
James Smart2e0fef82007-06-17 19:56:36 -05004255lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004256{
4257 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004258 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004259
James Smart92d7f7b2007-06-17 19:56:38 -05004260 /* Ignore RSCN if the port is being torn down. */
4261 if (vport->load_flag & FC_UNLOADING) {
4262 lpfc_els_flush_rscn(vport);
4263 return 0;
4264 }
4265
dea31012005-04-17 16:05:31 -05004266 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004267 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004268
4269 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004270 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4271 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4272 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4273 vport->port_state);
dea31012005-04-17 16:05:31 -05004274
4275 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004276 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004277 vport->num_disc_nodes = 0;
4278
James Smart2e0fef82007-06-17 19:56:36 -05004279 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004280 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4281 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004282 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004283 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004284 /* Wait for NameServer query cmpl before we can
4285 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004286 return 1;
dea31012005-04-17 16:05:31 -05004287 } else {
4288 /* If login to NameServer does not exist, issue one */
4289 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004290 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004291 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004292 /* Wait for NameServer login cmpl before we can
4293 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004294 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004295
James Smarte47c9092008-02-08 18:49:26 -05004296 if (ndlp) {
4297 ndlp = lpfc_enable_node(vport, ndlp,
4298 NLP_STE_PLOGI_ISSUE);
4299 if (!ndlp) {
4300 lpfc_els_flush_rscn(vport);
4301 return 0;
4302 }
4303 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004304 } else {
James Smarte47c9092008-02-08 18:49:26 -05004305 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4306 if (!ndlp) {
4307 lpfc_els_flush_rscn(vport);
4308 return 0;
4309 }
James Smart2e0fef82007-06-17 19:56:36 -05004310 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004311 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004312 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004313 }
James Smarte47c9092008-02-08 18:49:26 -05004314 ndlp->nlp_type |= NLP_FABRIC;
4315 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4316 /* Wait for NameServer login cmpl before we can
4317 * continue
4318 */
4319 return 1;
dea31012005-04-17 16:05:31 -05004320 }
4321
James Smart2e0fef82007-06-17 19:56:36 -05004322 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004323 return 0;
dea31012005-04-17 16:05:31 -05004324}
4325
James Smarte59058c2008-08-24 21:49:00 -04004326/**
James Smart3621a712009-04-06 18:47:14 -04004327 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004328 * @vport: pointer to a host virtual N_Port data structure.
4329 * @cmdiocb: pointer to lpfc command iocb data structure.
4330 * @ndlp: pointer to a node-list data structure.
4331 *
4332 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4333 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4334 * point topology. As an unsolicited FLOGI should not be received in a loop
4335 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4336 * lpfc_check_sparm() routine is invoked to check the parameters in the
4337 * unsolicited FLOGI. If parameters validation failed, the routine
4338 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4339 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4340 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4341 * will initiate PLOGI. The higher lexicographical value party shall has
4342 * higher priority (as the winning port) and will initiate PLOGI and
4343 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4344 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4345 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4346 *
4347 * Return code
4348 * 0 - Successfully processed the unsolicited flogi
4349 * 1 - Failed to process the unsolicited flogi
4350 **/
dea31012005-04-17 16:05:31 -05004351static int
James Smart2e0fef82007-06-17 19:56:36 -05004352lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004353 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004354{
James Smart2e0fef82007-06-17 19:56:36 -05004355 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4356 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004357 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4358 uint32_t *lp = (uint32_t *) pcmd->virt;
4359 IOCB_t *icmd = &cmdiocb->iocb;
4360 struct serv_parm *sp;
4361 LPFC_MBOXQ_t *mbox;
4362 struct ls_rjt stat;
4363 uint32_t cmd, did;
4364 int rc;
4365
4366 cmd = *lp++;
4367 sp = (struct serv_parm *) lp;
4368
4369 /* FLOGI received */
4370
James Smart2e0fef82007-06-17 19:56:36 -05004371 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004372
4373 if (phba->fc_topology == TOPOLOGY_LOOP) {
4374 /* We should never receive a FLOGI in loop mode, ignore it */
4375 did = icmd->un.elsreq64.remoteID;
4376
4377 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4378 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004379 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4380 "0113 An FLOGI ELS command x%x was "
4381 "received from DID x%x in Loop Mode\n",
4382 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004383 return 1;
dea31012005-04-17 16:05:31 -05004384 }
4385
4386 did = Fabric_DID;
4387
James Smart2e0fef82007-06-17 19:56:36 -05004388 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05004389 /* For a FLOGI we accept, then if our portname is greater
4390 * then the remote portname we initiate Nport login.
4391 */
4392
James Smart2e0fef82007-06-17 19:56:36 -05004393 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004394 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004395
4396 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004397 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4398 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004399 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004400
dea31012005-04-17 16:05:31 -05004401 lpfc_linkdown(phba);
4402 lpfc_init_link(phba, mbox,
4403 phba->cfg_topology,
4404 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004405 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004406 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004407 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004408 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004409 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004410 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004411 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004412 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004413 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004414 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004415 spin_lock_irq(shost->host_lock);
4416 vport->fc_flag |= FC_PT2PT_PLOGI;
4417 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004418 }
James Smart2e0fef82007-06-17 19:56:36 -05004419 spin_lock_irq(shost->host_lock);
4420 vport->fc_flag |= FC_PT2PT;
4421 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4422 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004423 } else {
4424 /* Reject this request because invalid parameters */
4425 stat.un.b.lsRjtRsvd0 = 0;
4426 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4427 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4428 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004429 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4430 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004431 return 1;
dea31012005-04-17 16:05:31 -05004432 }
4433
4434 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004435 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004436
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004437 return 0;
dea31012005-04-17 16:05:31 -05004438}
4439
James Smarte59058c2008-08-24 21:49:00 -04004440/**
James Smart3621a712009-04-06 18:47:14 -04004441 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004442 * @vport: pointer to a host virtual N_Port data structure.
4443 * @cmdiocb: pointer to lpfc command iocb data structure.
4444 * @ndlp: pointer to a node-list data structure.
4445 *
4446 * This routine processes Request Node Identification Data (RNID) IOCB
4447 * received as an ELS unsolicited event. Only when the RNID specified format
4448 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4449 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4450 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4451 * rejected by invoking the lpfc_els_rsp_reject() routine.
4452 *
4453 * Return code
4454 * 0 - Successfully processed rnid iocb (currently always return 0)
4455 **/
dea31012005-04-17 16:05:31 -05004456static int
James Smart2e0fef82007-06-17 19:56:36 -05004457lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4458 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004459{
4460 struct lpfc_dmabuf *pcmd;
4461 uint32_t *lp;
4462 IOCB_t *icmd;
4463 RNID *rn;
4464 struct ls_rjt stat;
4465 uint32_t cmd, did;
4466
4467 icmd = &cmdiocb->iocb;
4468 did = icmd->un.elsreq64.remoteID;
4469 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4470 lp = (uint32_t *) pcmd->virt;
4471
4472 cmd = *lp++;
4473 rn = (RNID *) lp;
4474
4475 /* RNID received */
4476
4477 switch (rn->Format) {
4478 case 0:
4479 case RNID_TOPOLOGY_DISC:
4480 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004481 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004482 break;
4483 default:
4484 /* Reject this request because format not supported */
4485 stat.un.b.lsRjtRsvd0 = 0;
4486 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4487 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4488 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004489 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4490 NULL);
dea31012005-04-17 16:05:31 -05004491 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004492 return 0;
dea31012005-04-17 16:05:31 -05004493}
4494
James Smarte59058c2008-08-24 21:49:00 -04004495/**
James Smart3621a712009-04-06 18:47:14 -04004496 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004497 * @vport: pointer to a host virtual N_Port data structure.
4498 * @cmdiocb: pointer to lpfc command iocb data structure.
4499 * @ndlp: pointer to a node-list data structure.
4500 *
4501 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4502 * received as an ELS unsolicited event. Currently, this function just invokes
4503 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4504 *
4505 * Return code
4506 * 0 - Successfully processed lirr iocb (currently always return 0)
4507 **/
dea31012005-04-17 16:05:31 -05004508static int
James Smart2e0fef82007-06-17 19:56:36 -05004509lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4510 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004511{
4512 struct ls_rjt stat;
4513
4514 /* For now, unconditionally reject this command */
4515 stat.un.b.lsRjtRsvd0 = 0;
4516 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4517 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4518 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004519 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004520 return 0;
4521}
4522
James Smarte59058c2008-08-24 21:49:00 -04004523/**
James Smart3621a712009-04-06 18:47:14 -04004524 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004525 * @phba: pointer to lpfc hba data structure.
4526 * @pmb: pointer to the driver internal queue element for mailbox command.
4527 *
4528 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4529 * mailbox command. This callback function is to actually send the Accept
4530 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4531 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4532 * mailbox command, constructs the RPS response with the link statistics
4533 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4534 * response to the RPS.
4535 *
4536 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4537 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4538 * will be stored into the context1 field of the IOCB for the completion
4539 * callback function to the RPS Accept Response ELS IOCB command.
4540 *
4541 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004542static void
James Smart329f9bc2007-04-25 09:53:01 -04004543lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004544{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004545 MAILBOX_t *mb;
4546 IOCB_t *icmd;
4547 RPS_RSP *rps_rsp;
4548 uint8_t *pcmd;
4549 struct lpfc_iocbq *elsiocb;
4550 struct lpfc_nodelist *ndlp;
4551 uint16_t xri, status;
4552 uint32_t cmdsize;
4553
James Smart04c68492009-05-22 14:52:52 -04004554 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004555
4556 ndlp = (struct lpfc_nodelist *) pmb->context2;
4557 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004558 pmb->context1 = NULL;
4559 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004560
4561 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004562 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004563 return;
4564 }
4565
4566 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004567 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004568 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4569 lpfc_max_els_tries, ndlp,
4570 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004571
4572 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004573 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004574
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004575 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004576 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004577
4578 icmd = &elsiocb->iocb;
4579 icmd->ulpContext = xri;
4580
4581 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4582 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004583 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004584 rps_rsp = (RPS_RSP *)pcmd;
4585
4586 if (phba->fc_topology != TOPOLOGY_LOOP)
4587 status = 0x10;
4588 else
4589 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004590 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004591 status |= 0x4;
4592
4593 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004594 rps_rsp->portStatus = cpu_to_be16(status);
4595 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4596 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4597 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4598 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4599 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4600 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004601 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004602 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4603 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4604 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4605 elsiocb->iotag, elsiocb->iocb.ulpContext,
4606 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4607 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004608 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004609 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004610 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004611 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004612 return;
4613}
4614
James Smarte59058c2008-08-24 21:49:00 -04004615/**
James Smart3621a712009-04-06 18:47:14 -04004616 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004617 * @vport: pointer to a host virtual N_Port data structure.
4618 * @cmdiocb: pointer to lpfc command iocb data structure.
4619 * @ndlp: pointer to a node-list data structure.
4620 *
4621 * This routine processes Read Port Status (RPS) IOCB received as an
4622 * ELS unsolicited event. It first checks the remote port state. If the
4623 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4624 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4625 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4626 * for reading the HBA link statistics. It is for the callback function,
4627 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4628 * to actually sending out RPS Accept (ACC) response.
4629 *
4630 * Return codes
4631 * 0 - Successfully processed rps iocb (currently always return 0)
4632 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004633static int
James Smart2e0fef82007-06-17 19:56:36 -05004634lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4635 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004636{
James Smart2e0fef82007-06-17 19:56:36 -05004637 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004638 uint32_t *lp;
4639 uint8_t flag;
4640 LPFC_MBOXQ_t *mbox;
4641 struct lpfc_dmabuf *pcmd;
4642 RPS *rps;
4643 struct ls_rjt stat;
4644
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004645 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004646 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4647 /* reject the unsolicited RPS request and done with it */
4648 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004649
4650 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4651 lp = (uint32_t *) pcmd->virt;
4652 flag = (be32_to_cpu(*lp++) & 0xf);
4653 rps = (RPS *) lp;
4654
4655 if ((flag == 0) ||
4656 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004657 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004658 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004659
James Smart92d7f7b2007-06-17 19:56:38 -05004660 printk("Fix me....\n");
4661 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004662 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4663 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004664 lpfc_read_lnk_stat(phba, mbox);
4665 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004666 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004667 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004668 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004669 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004670 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004671 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004672 /* Mbox completion will send ELS Response */
4673 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004674 /* Decrement reference count used for the failed mbox
4675 * command.
4676 */
James Smart329f9bc2007-04-25 09:53:01 -04004677 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004678 mempool_free(mbox, phba->mbox_mem_pool);
4679 }
4680 }
James Smart90160e02008-08-24 21:49:45 -04004681
4682reject_out:
4683 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004684 stat.un.b.lsRjtRsvd0 = 0;
4685 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4686 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4687 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004688 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004689 return 0;
4690}
4691
James Smarte59058c2008-08-24 21:49:00 -04004692/**
James Smart3621a712009-04-06 18:47:14 -04004693 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004694 * @vport: pointer to a host virtual N_Port data structure.
4695 * @cmdsize: size of the ELS command.
4696 * @oldiocb: pointer to the original lpfc command iocb data structure.
4697 * @ndlp: pointer to a node-list data structure.
4698 *
4699 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4700 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4701 *
4702 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4703 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4704 * will be stored into the context1 field of the IOCB for the completion
4705 * callback function to the RPL Accept Response ELS command.
4706 *
4707 * Return code
4708 * 0 - Successfully issued ACC RPL ELS command
4709 * 1 - Failed to issue ACC RPL ELS command
4710 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004711static int
James Smart2e0fef82007-06-17 19:56:36 -05004712lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4713 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004714{
James Smart2e0fef82007-06-17 19:56:36 -05004715 struct lpfc_hba *phba = vport->phba;
4716 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004717 RPL_RSP rpl_rsp;
4718 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004719 uint8_t *pcmd;
4720
James Smart2e0fef82007-06-17 19:56:36 -05004721 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4722 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004723
James Smart488d1462006-03-07 15:02:37 -05004724 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004725 return 1;
James Smart488d1462006-03-07 15:02:37 -05004726
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004727 icmd = &elsiocb->iocb;
4728 oldcmd = &oldiocb->iocb;
4729 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4730
4731 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4732 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004733 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004734 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4735 pcmd += sizeof(uint16_t);
4736
4737 /* Setup the RPL ACC payload */
4738 rpl_rsp.listLen = be32_to_cpu(1);
4739 rpl_rsp.index = 0;
4740 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004741 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4742 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004743 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004744 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004745 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004746 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4747 "0120 Xmit ELS RPL ACC response tag x%x "
4748 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4749 "rpi x%x\n",
4750 elsiocb->iotag, elsiocb->iocb.ulpContext,
4751 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4752 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004753 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004754 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004755 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4756 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004757 lpfc_els_free_iocb(phba, elsiocb);
4758 return 1;
4759 }
4760 return 0;
4761}
4762
James Smarte59058c2008-08-24 21:49:00 -04004763/**
James Smart3621a712009-04-06 18:47:14 -04004764 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004765 * @vport: pointer to a host virtual N_Port data structure.
4766 * @cmdiocb: pointer to lpfc command iocb data structure.
4767 * @ndlp: pointer to a node-list data structure.
4768 *
4769 * This routine processes Read Port List (RPL) IOCB received as an ELS
4770 * unsolicited event. It first checks the remote port state. If the remote
4771 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4772 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4773 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4774 * to accept the RPL.
4775 *
4776 * Return code
4777 * 0 - Successfully processed rpl iocb (currently always return 0)
4778 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004779static int
James Smart2e0fef82007-06-17 19:56:36 -05004780lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4781 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004782{
4783 struct lpfc_dmabuf *pcmd;
4784 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004785 uint32_t maxsize;
4786 uint16_t cmdsize;
4787 RPL *rpl;
4788 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004789
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004790 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4791 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004792 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004793 stat.un.b.lsRjtRsvd0 = 0;
4794 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4795 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4796 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004797 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4798 NULL);
James Smart90160e02008-08-24 21:49:45 -04004799 /* rejected the unsolicited RPL request and done with it */
4800 return 0;
dea31012005-04-17 16:05:31 -05004801 }
4802
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004803 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4804 lp = (uint32_t *) pcmd->virt;
4805 rpl = (RPL *) (lp + 1);
4806
4807 maxsize = be32_to_cpu(rpl->maxsize);
4808
4809 /* We support only one port */
4810 if ((rpl->index == 0) &&
4811 ((maxsize == 0) ||
4812 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4813 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004814 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004815 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4816 }
James Smart2e0fef82007-06-17 19:56:36 -05004817 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004818
4819 return 0;
4820}
4821
James Smarte59058c2008-08-24 21:49:00 -04004822/**
James Smart3621a712009-04-06 18:47:14 -04004823 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004824 * @vport: pointer to a virtual N_Port data structure.
4825 * @cmdiocb: pointer to lpfc command iocb data structure.
4826 * @ndlp: pointer to a node-list data structure.
4827 *
4828 * This routine processes Fibre Channel Address Resolution Protocol
4829 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4830 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4831 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4832 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4833 * remote PortName is compared against the FC PortName stored in the @vport
4834 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4835 * compared against the FC NodeName stored in the @vport data structure.
4836 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4837 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4838 * invoked to send out FARP Response to the remote node. Before sending the
4839 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4840 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4841 * routine is invoked to log into the remote port first.
4842 *
4843 * Return code
4844 * 0 - Either the FARP Match Mode not supported or successfully processed
4845 **/
dea31012005-04-17 16:05:31 -05004846static int
James Smart2e0fef82007-06-17 19:56:36 -05004847lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4848 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004849{
4850 struct lpfc_dmabuf *pcmd;
4851 uint32_t *lp;
4852 IOCB_t *icmd;
4853 FARP *fp;
4854 uint32_t cmd, cnt, did;
4855
4856 icmd = &cmdiocb->iocb;
4857 did = icmd->un.elsreq64.remoteID;
4858 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4859 lp = (uint32_t *) pcmd->virt;
4860
4861 cmd = *lp++;
4862 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004863 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004864 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4865 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004866 /* We will only support match on WWPN or WWNN */
4867 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004868 return 0;
dea31012005-04-17 16:05:31 -05004869 }
4870
4871 cnt = 0;
4872 /* If this FARP command is searching for my portname */
4873 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004874 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004875 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004876 cnt = 1;
4877 }
4878
4879 /* If this FARP command is searching for my nodename */
4880 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004881 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004882 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004883 cnt = 1;
4884 }
4885
4886 if (cnt) {
4887 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4888 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4889 /* Log back into the node before sending the FARP. */
4890 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004891 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004892 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004893 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004894 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05004895 }
4896
4897 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05004898 if (fp->Rflags & FARP_REQUEST_FARPR)
4899 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05004900 }
4901 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004902 return 0;
dea31012005-04-17 16:05:31 -05004903}
4904
James Smarte59058c2008-08-24 21:49:00 -04004905/**
James Smart3621a712009-04-06 18:47:14 -04004906 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04004907 * @vport: pointer to a host virtual N_Port data structure.
4908 * @cmdiocb: pointer to lpfc command iocb data structure.
4909 * @ndlp: pointer to a node-list data structure.
4910 *
4911 * This routine processes Fibre Channel Address Resolution Protocol
4912 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4913 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4914 * the FARP response request.
4915 *
4916 * Return code
4917 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4918 **/
dea31012005-04-17 16:05:31 -05004919static int
James Smart2e0fef82007-06-17 19:56:36 -05004920lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4921 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004922{
4923 struct lpfc_dmabuf *pcmd;
4924 uint32_t *lp;
4925 IOCB_t *icmd;
4926 uint32_t cmd, did;
4927
4928 icmd = &cmdiocb->iocb;
4929 did = icmd->un.elsreq64.remoteID;
4930 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4931 lp = (uint32_t *) pcmd->virt;
4932
4933 cmd = *lp++;
4934 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4936 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004937 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04004938 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004939
4940 return 0;
4941}
4942
James Smarte59058c2008-08-24 21:49:00 -04004943/**
James Smart3621a712009-04-06 18:47:14 -04004944 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04004945 * @vport: pointer to a host virtual N_Port data structure.
4946 * @cmdiocb: pointer to lpfc command iocb data structure.
4947 * @fan_ndlp: pointer to a node-list data structure.
4948 *
4949 * This routine processes a Fabric Address Notification (FAN) IOCB
4950 * command received as an ELS unsolicited event. The FAN ELS command will
4951 * only be processed on a physical port (i.e., the @vport represents the
4952 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4953 * compared against those in the phba data structure. If any of those is
4954 * different, the lpfc_initial_flogi() routine is invoked to initialize
4955 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4956 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4957 * is invoked to register login to the fabric.
4958 *
4959 * Return code
4960 * 0 - Successfully processed fan iocb (currently always return 0).
4961 **/
dea31012005-04-17 16:05:31 -05004962static int
James Smart2e0fef82007-06-17 19:56:36 -05004963lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4964 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05004965{
James Smart2e0fef82007-06-17 19:56:36 -05004966 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04004967 uint32_t *lp;
4968 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004969
James Smart0d2b6b82008-06-14 22:52:47 -04004970 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4971 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4972 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004973 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04004974 if ((vport == phba->pport) &&
4975 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004976 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04004977 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004978 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04004979 sizeof(struct lpfc_name)))) {
4980 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05004981 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04004982 } else {
4983 /* FAN verified - skip FLOGI */
4984 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04004985 if (phba->sli_rev < LPFC_SLI_REV4)
4986 lpfc_issue_fabric_reglogin(vport);
4987 else
4988 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05004989 }
dea31012005-04-17 16:05:31 -05004990 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004991 return 0;
dea31012005-04-17 16:05:31 -05004992}
4993
James Smarte59058c2008-08-24 21:49:00 -04004994/**
James Smart3621a712009-04-06 18:47:14 -04004995 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04004996 * @ptr: holder for the timer function associated data.
4997 *
4998 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4999 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5000 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5001 * up the worker thread. It is for the worker thread to invoke the routine
5002 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5003 **/
dea31012005-04-17 16:05:31 -05005004void
5005lpfc_els_timeout(unsigned long ptr)
5006{
James Smart2e0fef82007-06-17 19:56:36 -05005007 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5008 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005009 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005010 unsigned long iflag;
5011
James Smart2e0fef82007-06-17 19:56:36 -05005012 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005013 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5014 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005015 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005016 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005017
James Smart5e9d9b82008-06-14 22:52:53 -04005018 if (!tmo_posted)
5019 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005020 return;
5021}
5022
James Smarte59058c2008-08-24 21:49:00 -04005023/**
James Smart3621a712009-04-06 18:47:14 -04005024 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005025 * @vport: pointer to a virtual N_Port data structure.
5026 *
5027 * This routine is the actual handler function that processes an ELS timeout
5028 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5029 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5030 * invoking the lpfc_sli_issue_abort_iotag() routine.
5031 **/
dea31012005-04-17 16:05:31 -05005032void
James Smart2e0fef82007-06-17 19:56:36 -05005033lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005034{
James Smart2e0fef82007-06-17 19:56:36 -05005035 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005036 struct lpfc_sli_ring *pring;
5037 struct lpfc_iocbq *tmp_iocb, *piocb;
5038 IOCB_t *cmd = NULL;
5039 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005040 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005041 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005042 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005043
James Smart2e0fef82007-06-17 19:56:36 -05005044 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005045 timeout = (uint32_t)(phba->fc_ratov << 1);
5046
5047 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005048
5049 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5050 cmd = &piocb->iocb;
5051
James Smart2e0fef82007-06-17 19:56:36 -05005052 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5053 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5054 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005055 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005056
5057 if (piocb->vport != vport)
5058 continue;
5059
dea31012005-04-17 16:05:31 -05005060 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005061 if (pcmd)
5062 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005063
James Smart92d7f7b2007-06-17 19:56:38 -05005064 if (els_command == ELS_CMD_FARP ||
5065 els_command == ELS_CMD_FARPR ||
5066 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005067 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005068
dea31012005-04-17 16:05:31 -05005069 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005070 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005071 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005072 else
dea31012005-04-17 16:05:31 -05005073 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005074 continue;
5075 }
5076
James Smart2e0fef82007-06-17 19:56:36 -05005077 remote_ID = 0xffffffff;
5078 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005079 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005080 else {
5081 struct lpfc_nodelist *ndlp;
5082 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005083 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005084 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005085 }
James Smarte8b62012007-08-02 11:10:09 -04005086 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5087 "0127 ELS timeout Data: x%x x%x x%x "
5088 "x%x\n", els_command,
5089 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005090 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005091 }
James Smart2e0fef82007-06-17 19:56:36 -05005092 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005093
James Smart2e0fef82007-06-17 19:56:36 -05005094 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5095 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005096}
5097
James Smarte59058c2008-08-24 21:49:00 -04005098/**
James Smart3621a712009-04-06 18:47:14 -04005099 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005100 * @vport: pointer to a host virtual N_Port data structure.
5101 *
5102 * This routine is used to clean up all the outstanding ELS commands on a
5103 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5104 * routine. After that, it walks the ELS transmit queue to remove all the
5105 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5106 * the IOCBs with a non-NULL completion callback function, the callback
5107 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5108 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5109 * callback function, the IOCB will simply be released. Finally, it walks
5110 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5111 * completion queue IOCB that is associated with the @vport and is not
5112 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5113 * part of the discovery state machine) out to HBA by invoking the
5114 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5115 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5116 * the IOCBs are aborted when this function returns.
5117 **/
dea31012005-04-17 16:05:31 -05005118void
James Smart2e0fef82007-06-17 19:56:36 -05005119lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005120{
James Smart2534ba72007-04-25 09:52:20 -04005121 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005122 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005123 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005124 struct lpfc_iocbq *tmp_iocb, *piocb;
5125 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005126
5127 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005128
James Smart2e0fef82007-06-17 19:56:36 -05005129 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005130 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5131 cmd = &piocb->iocb;
5132
5133 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5134 continue;
5135 }
5136
5137 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005138 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5139 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5140 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5141 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005142 continue;
dea31012005-04-17 16:05:31 -05005143
James Smart2e0fef82007-06-17 19:56:36 -05005144 if (piocb->vport != vport)
5145 continue;
5146
James Smart2534ba72007-04-25 09:52:20 -04005147 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005148 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005149 }
5150
5151 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005152 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5153 continue;
5154 }
dea31012005-04-17 16:05:31 -05005155
James Smart2e0fef82007-06-17 19:56:36 -05005156 if (piocb->vport != vport)
5157 continue;
5158
James Smart07951072007-04-25 09:51:38 -04005159 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005160 }
James Smart2e0fef82007-06-17 19:56:36 -05005161 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005162
James Smarta257bf92009-04-06 18:48:10 -04005163 /* Cancell all the IOCBs from the completions list */
5164 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5165 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005166
dea31012005-04-17 16:05:31 -05005167 return;
5168}
5169
James Smarte59058c2008-08-24 21:49:00 -04005170/**
James Smart3621a712009-04-06 18:47:14 -04005171 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005172 * @phba: pointer to lpfc hba data structure.
5173 *
5174 * This routine is used to clean up all the outstanding ELS commands on a
5175 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5176 * routine. After that, it walks the ELS transmit queue to remove all the
5177 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5178 * the IOCBs with the completion callback function associated, the callback
5179 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5180 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5181 * callback function associated, the IOCB will simply be released. Finally,
5182 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5183 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5184 * management plane IOCBs that are not part of the discovery state machine)
5185 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5186 **/
James Smart549e55c2007-08-02 11:09:51 -04005187void
5188lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5189{
5190 LIST_HEAD(completions);
5191 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5192 struct lpfc_iocbq *tmp_iocb, *piocb;
5193 IOCB_t *cmd = NULL;
5194
5195 lpfc_fabric_abort_hba(phba);
5196 spin_lock_irq(&phba->hbalock);
5197 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5198 cmd = &piocb->iocb;
5199 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5200 continue;
5201 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5202 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5203 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5204 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5205 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5206 continue;
5207 list_move_tail(&piocb->list, &completions);
5208 pring->txq_cnt--;
5209 }
5210 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5211 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5212 continue;
5213 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5214 }
5215 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005216
5217 /* Cancel all the IOCBs from the completions list */
5218 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5219 IOERR_SLI_ABORTED);
5220
James Smart549e55c2007-08-02 11:09:51 -04005221 return;
5222}
5223
James Smarte59058c2008-08-24 21:49:00 -04005224/**
James Smart3621a712009-04-06 18:47:14 -04005225 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005226 * @phba: Pointer to hba context object.
5227 * @cmdiocbp: Pointer to command iocb which reported error.
5228 * @rspiocbp: Pointer to response iocb which reported error.
5229 *
5230 * This function sends an event when there is an ELS command
5231 * failure.
5232 **/
5233void
5234lpfc_send_els_failure_event(struct lpfc_hba *phba,
5235 struct lpfc_iocbq *cmdiocbp,
5236 struct lpfc_iocbq *rspiocbp)
5237{
5238 struct lpfc_vport *vport = cmdiocbp->vport;
5239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5240 struct lpfc_lsrjt_event lsrjt_event;
5241 struct lpfc_fabric_event_header fabric_event;
5242 struct ls_rjt stat;
5243 struct lpfc_nodelist *ndlp;
5244 uint32_t *pcmd;
5245
5246 ndlp = cmdiocbp->context1;
5247 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5248 return;
5249
5250 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5251 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5252 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5253 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5254 sizeof(struct lpfc_name));
5255 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5256 sizeof(struct lpfc_name));
5257 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5258 cmdiocbp->context2)->virt);
5259 lsrjt_event.command = *pcmd;
5260 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5261 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5262 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5263 fc_host_post_vendor_event(shost,
5264 fc_get_event_number(),
5265 sizeof(lsrjt_event),
5266 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005267 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005268 return;
5269 }
5270 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5271 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5272 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5273 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5274 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5275 else
5276 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5277 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5278 sizeof(struct lpfc_name));
5279 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5280 sizeof(struct lpfc_name));
5281 fc_host_post_vendor_event(shost,
5282 fc_get_event_number(),
5283 sizeof(fabric_event),
5284 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005285 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005286 return;
5287 }
5288
5289}
5290
5291/**
James Smart3621a712009-04-06 18:47:14 -04005292 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005293 * @vport: Pointer to vport object.
5294 * @ndlp: Pointer FC node object.
5295 * @cmd: ELS command code.
5296 *
5297 * This function posts an event when there is an incoming
5298 * unsolicited ELS command.
5299 **/
5300static void
5301lpfc_send_els_event(struct lpfc_vport *vport,
5302 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005303 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005304{
James Smartddcc50f2008-12-04 22:38:46 -05005305 struct lpfc_els_event_header *els_data = NULL;
5306 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5308
James Smartddcc50f2008-12-04 22:38:46 -05005309 if (*payload == ELS_CMD_LOGO) {
5310 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5311 if (!logo_data) {
5312 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5313 "0148 Failed to allocate memory "
5314 "for LOGO event\n");
5315 return;
5316 }
5317 els_data = &logo_data->header;
5318 } else {
5319 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5320 GFP_KERNEL);
5321 if (!els_data) {
5322 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5323 "0149 Failed to allocate memory "
5324 "for ELS event\n");
5325 return;
5326 }
5327 }
5328 els_data->event_type = FC_REG_ELS_EVENT;
5329 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005330 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005331 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005332 break;
5333 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005334 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005335 break;
5336 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005337 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5338 break;
5339 case ELS_CMD_LOGO:
5340 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5341 /* Copy the WWPN in the LOGO payload */
5342 memcpy(logo_data->logo_wwpn, &payload[2],
5343 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005344 break;
5345 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005346 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005347 return;
5348 }
James Smartddcc50f2008-12-04 22:38:46 -05005349 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5350 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5351 if (*payload == ELS_CMD_LOGO) {
5352 fc_host_post_vendor_event(shost,
5353 fc_get_event_number(),
5354 sizeof(struct lpfc_logo_event),
5355 (char *)logo_data,
5356 LPFC_NL_VENDOR_ID);
5357 kfree(logo_data);
5358 } else {
5359 fc_host_post_vendor_event(shost,
5360 fc_get_event_number(),
5361 sizeof(struct lpfc_els_event_header),
5362 (char *)els_data,
5363 LPFC_NL_VENDOR_ID);
5364 kfree(els_data);
5365 }
James Smartea2151b2008-09-07 11:52:10 -04005366
5367 return;
5368}
5369
5370
5371/**
James Smart3621a712009-04-06 18:47:14 -04005372 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005373 * @phba: pointer to lpfc hba data structure.
5374 * @pring: pointer to a SLI ring.
5375 * @vport: pointer to a host virtual N_Port data structure.
5376 * @elsiocb: pointer to lpfc els command iocb data structure.
5377 *
5378 * This routine is used for processing the IOCB associated with a unsolicited
5379 * event. It first determines whether there is an existing ndlp that matches
5380 * the DID from the unsolicited IOCB. If not, it will create a new one with
5381 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5382 * IOCB is then used to invoke the proper routine and to set up proper state
5383 * of the discovery state machine.
5384 **/
James Smarted957682007-06-17 19:56:37 -05005385static void
5386lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005387 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005388{
James Smart87af33f2007-10-27 13:37:43 -04005389 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005390 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005391 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005392 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005393 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005394 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005395
James Smarte47c9092008-02-08 18:49:26 -05005396 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005397 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005398
dea31012005-04-17 16:05:31 -05005399 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005400 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5401 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005402 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005403 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005404
James Smart858c9f62007-06-17 19:56:39 -05005405 did = icmd->un.rcvels.remoteID;
5406 if (icmd->ulpStatus) {
5407 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5408 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5409 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005410 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005411 }
dea31012005-04-17 16:05:31 -05005412
5413 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005414 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005415 goto dropit;
dea31012005-04-17 16:05:31 -05005416
James Smartc8685952009-11-18 15:39:16 -05005417 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005418 if (vport->load_flag & FC_UNLOADING)
5419 goto dropit;
5420
James Smart2e0fef82007-06-17 19:56:36 -05005421 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005422 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005423 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005424 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005425 if (!ndlp)
dea31012005-04-17 16:05:31 -05005426 goto dropit;
dea31012005-04-17 16:05:31 -05005427
James Smart2e0fef82007-06-17 19:56:36 -05005428 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005429 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005430 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005431 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005432 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005433 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5434 ndlp = lpfc_enable_node(vport, ndlp,
5435 NLP_STE_UNUSED_NODE);
5436 if (!ndlp)
5437 goto dropit;
5438 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5439 newnode = 1;
5440 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5441 ndlp->nlp_type |= NLP_FABRIC;
5442 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5443 /* This is similar to the new node path */
5444 ndlp = lpfc_nlp_get(ndlp);
5445 if (!ndlp)
5446 goto dropit;
5447 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5448 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005449 }
dea31012005-04-17 16:05:31 -05005450
5451 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005452
James Smart329f9bc2007-04-25 09:53:01 -04005453 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005454 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005455
5456 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5457 cmd &= ELS_CMD_MASK;
5458 }
5459 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005460 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5461 "0112 ELS command x%x received from NPORT x%x "
5462 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005463 switch (cmd) {
5464 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005465 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5466 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5467 did, vport->port_state, ndlp->nlp_flag);
5468
dea31012005-04-17 16:05:31 -05005469 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005470 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5471
James Smartddcc50f2008-12-04 22:38:46 -05005472 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005473 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005474 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5475 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5476 rjt_err = LSRJT_UNABLE_TPC;
5477 break;
5478 }
5479 /* We get here, and drop thru, if we are PT2PT with
5480 * another NPort and the other side has initiated
5481 * the PLOGI before responding to our FLOGI.
5482 */
dea31012005-04-17 16:05:31 -05005483 }
James Smart87af33f2007-10-27 13:37:43 -04005484
5485 shost = lpfc_shost_from_vport(vport);
5486 spin_lock_irq(shost->host_lock);
5487 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5488 spin_unlock_irq(shost->host_lock);
5489
James Smart2e0fef82007-06-17 19:56:36 -05005490 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5491 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005492
dea31012005-04-17 16:05:31 -05005493 break;
5494 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5496 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5497 did, vport->port_state, ndlp->nlp_flag);
5498
dea31012005-04-17 16:05:31 -05005499 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005500 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005501 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005502 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005503 break;
5504 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005505 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5506 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5507 did, vport->port_state, ndlp->nlp_flag);
5508
dea31012005-04-17 16:05:31 -05005509 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005510 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005511 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005512 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005513 break;
5514 }
James Smart2e0fef82007-06-17 19:56:36 -05005515 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005516 break;
5517 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005518 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5519 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5520 did, vport->port_state, ndlp->nlp_flag);
5521
dea31012005-04-17 16:05:31 -05005522 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005523 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005524 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005525 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005526 break;
5527 }
James Smart2e0fef82007-06-17 19:56:36 -05005528 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005529 break;
5530 case ELS_CMD_RSCN:
5531 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005532 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005533 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005534 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005535 break;
5536 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5538 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5539 did, vport->port_state, ndlp->nlp_flag);
5540
James Smartddcc50f2008-12-04 22:38:46 -05005541 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005542 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005543 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005544 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005545 break;
5546 }
James Smart2e0fef82007-06-17 19:56:36 -05005547 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5548 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005549 break;
5550 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5552 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5553 did, vport->port_state, ndlp->nlp_flag);
5554
dea31012005-04-17 16:05:31 -05005555 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005556 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005557 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005558 break;
5559 }
James Smart2e0fef82007-06-17 19:56:36 -05005560 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5561 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005562 break;
5563 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5565 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5566 did, vport->port_state, ndlp->nlp_flag);
5567
dea31012005-04-17 16:05:31 -05005568 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005569 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005570 break;
5571 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5573 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5574 did, vport->port_state, ndlp->nlp_flag);
5575
dea31012005-04-17 16:05:31 -05005576 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005577 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005578 break;
5579 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005580 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5581 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5582 did, vport->port_state, ndlp->nlp_flag);
5583
dea31012005-04-17 16:05:31 -05005584 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005585 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005586 break;
dea31012005-04-17 16:05:31 -05005587 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005588 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5589 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5590 did, vport->port_state, ndlp->nlp_flag);
5591
dea31012005-04-17 16:05:31 -05005592 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005593 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005594 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005595 break;
5596 }
James Smart2e0fef82007-06-17 19:56:36 -05005597 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005598 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005599 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5601 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5602 did, vport->port_state, ndlp->nlp_flag);
5603
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005604 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005605 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005606 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005607 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005608 break;
5609 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005610 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5611 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5612 did, vport->port_state, ndlp->nlp_flag);
5613
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005614 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005615 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005616 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005617 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005618 break;
5619 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5621 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5622 did, vport->port_state, ndlp->nlp_flag);
5623
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005624 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005625 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005626 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005627 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005628 break;
dea31012005-04-17 16:05:31 -05005629 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005630 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5631 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5632 did, vport->port_state, ndlp->nlp_flag);
5633
dea31012005-04-17 16:05:31 -05005634 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005635 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005636 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005637 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005638 break;
5639 default:
James Smart858c9f62007-06-17 19:56:39 -05005640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5641 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5642 cmd, did, vport->port_state);
5643
dea31012005-04-17 16:05:31 -05005644 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005645 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005646
5647 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005648 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5649 "0115 Unknown ELS command x%x "
5650 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005651 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005652 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005653 break;
5654 }
5655
5656 /* check if need to LS_RJT received ELS cmd */
5657 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005658 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005659 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005660 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005661 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5662 NULL);
dea31012005-04-17 16:05:31 -05005663 }
5664
James Smartd7c255b2008-08-24 21:50:00 -04005665 lpfc_nlp_put(elsiocb->context1);
5666 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005667 return;
5668
5669dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005670 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005671 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5672 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005673 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005674 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005675 phba->fc_stat.elsRcvDrop++;
5676}
5677
James Smarte59058c2008-08-24 21:49:00 -04005678/**
James Smart3621a712009-04-06 18:47:14 -04005679 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005680 * @phba: pointer to lpfc hba data structure.
5681 * @vpi: host virtual N_Port identifier.
5682 *
5683 * This routine finds a vport on a HBA (referred by @phba) through a
5684 * @vpi. The function walks the HBA's vport list and returns the address
5685 * of the vport with the matching @vpi.
5686 *
5687 * Return code
5688 * NULL - No vport with the matching @vpi found
5689 * Otherwise - Address to the vport with the matching @vpi.
5690 **/
James Smart6669f9b2009-10-02 15:16:45 -04005691struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005692lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5693{
5694 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005695 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005696
James Smart549e55c2007-08-02 11:09:51 -04005697 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005698 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005699 if (vport->vpi == vpi) {
5700 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005701 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005702 }
James Smart92d7f7b2007-06-17 19:56:38 -05005703 }
James Smart549e55c2007-08-02 11:09:51 -04005704 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005705 return NULL;
5706}
James Smarted957682007-06-17 19:56:37 -05005707
James Smarte59058c2008-08-24 21:49:00 -04005708/**
James Smart3621a712009-04-06 18:47:14 -04005709 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005710 * @phba: pointer to lpfc hba data structure.
5711 * @pring: pointer to a SLI ring.
5712 * @elsiocb: pointer to lpfc els iocb data structure.
5713 *
5714 * This routine is used to process an unsolicited event received from a SLI
5715 * (Service Level Interface) ring. The actual processing of the data buffer
5716 * associated with the unsolicited event is done by invoking the routine
5717 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5718 * SLI ring on which the unsolicited event was received.
5719 **/
James Smarted957682007-06-17 19:56:37 -05005720void
5721lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5722 struct lpfc_iocbq *elsiocb)
5723{
5724 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005725 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005726 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005727 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5728 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005729
James Smartd7c255b2008-08-24 21:50:00 -04005730 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005731 elsiocb->context2 = NULL;
5732 elsiocb->context3 = NULL;
5733
5734 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5735 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5736 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5737 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005738 phba->fc_stat.NoRcvBuf++;
5739 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005740 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005741 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005742 return;
5743 }
5744
James Smart92d7f7b2007-06-17 19:56:38 -05005745 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5746 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5747 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5748 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5749 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005750 else
5751 vport = lpfc_find_vport_by_vpid(phba,
5752 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005753 }
James Smart7f5f3d02008-02-08 18:50:14 -05005754 /* If there are no BDEs associated
5755 * with this IOCB, there is nothing to do.
5756 */
James Smarted957682007-06-17 19:56:37 -05005757 if (icmd->ulpBdeCount == 0)
5758 return;
5759
James Smart7f5f3d02008-02-08 18:50:14 -05005760 /* type of ELS cmd is first 32bit word
5761 * in packet
5762 */
James Smarted957682007-06-17 19:56:37 -05005763 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005764 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005765 } else {
5766 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5767 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005768 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5769 paddr);
James Smarted957682007-06-17 19:56:37 -05005770 }
5771
James Smart92d7f7b2007-06-17 19:56:38 -05005772 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5773 /*
5774 * The different unsolicited event handlers would tell us
5775 * if they are done with "mp" by setting context2 to NULL.
5776 */
dea31012005-04-17 16:05:31 -05005777 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005778 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5779 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005780 }
James Smarted957682007-06-17 19:56:37 -05005781
5782 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005783 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005784 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005785 elsiocb->context2 = bdeBuf2;
5786 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005787 /* free mp if we are done with it */
5788 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005789 lpfc_in_buf_free(phba, elsiocb->context2);
5790 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005791 }
dea31012005-04-17 16:05:31 -05005792 }
dea31012005-04-17 16:05:31 -05005793}
James Smart92d7f7b2007-06-17 19:56:38 -05005794
James Smarte59058c2008-08-24 21:49:00 -04005795/**
James Smart3621a712009-04-06 18:47:14 -04005796 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005797 * @phba: pointer to lpfc hba data structure.
5798 * @vport: pointer to a virtual N_Port data structure.
5799 *
5800 * This routine issues a Port Login (PLOGI) to the Name Server with
5801 * State Change Request (SCR) for a @vport. This routine will create an
5802 * ndlp for the Name Server associated to the @vport if such node does
5803 * not already exist. The PLOGI to Name Server is issued by invoking the
5804 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5805 * (FDMI) is configured to the @vport, a FDMI node will be created and
5806 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5807 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005808void
5809lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5810{
5811 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5812
5813 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5814 if (!ndlp) {
5815 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5816 if (!ndlp) {
5817 if (phba->fc_topology == TOPOLOGY_LOOP) {
5818 lpfc_disc_start(vport);
5819 return;
5820 }
5821 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005822 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5823 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005824 return;
5825 }
5826 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005827 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5828 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5829 if (!ndlp) {
5830 if (phba->fc_topology == TOPOLOGY_LOOP) {
5831 lpfc_disc_start(vport);
5832 return;
5833 }
5834 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5835 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5836 "0348 NameServer login: node freed\n");
5837 return;
5838 }
James Smart92d7f7b2007-06-17 19:56:38 -05005839 }
James Smart58da1ff2008-04-07 10:15:56 -04005840 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005841
5842 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5843
5844 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5845 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005846 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5847 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005848 return;
5849 }
5850
James Smart3de2a652007-08-02 11:09:59 -04005851 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005852 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5853 GFP_KERNEL);
5854 if (ndlp_fdmi) {
5855 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5856 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005857 lpfc_nlp_set_state(vport, ndlp_fdmi,
5858 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005859 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5860 0);
5861 }
5862 }
5863 return;
5864}
5865
James Smarte59058c2008-08-24 21:49:00 -04005866/**
James Smart3621a712009-04-06 18:47:14 -04005867 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005868 * @phba: pointer to lpfc hba data structure.
5869 * @pmb: pointer to the driver internal queue element for mailbox command.
5870 *
5871 * This routine is the completion callback function to register new vport
5872 * mailbox command. If the new vport mailbox command completes successfully,
5873 * the fabric registration login shall be performed on physical port (the
5874 * new vport created is actually a physical port, with VPI 0) or the port
5875 * login to Name Server for State Change Request (SCR) will be performed
5876 * on virtual port (real virtual port, with VPI greater than 0).
5877 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005878static void
5879lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5880{
5881 struct lpfc_vport *vport = pmb->vport;
5882 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5883 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04005884 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05005885
James Smart09372822008-01-11 01:52:54 -05005886 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005887 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005888 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005889
5890 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04005891 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5892 "0915 Register VPI failed: 0x%x\n",
5893 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05005894
5895 switch (mb->mbxStatus) {
5896 case 0x11: /* unsupported feature */
5897 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05005898 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05005899 /* giving up on vport registration */
5900 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5901 spin_lock_irq(shost->host_lock);
5902 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5903 spin_unlock_irq(shost->host_lock);
5904 lpfc_can_disctmo(vport);
5905 break;
5906 default:
5907 /* Try to recover from this error */
5908 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005909 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005910 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005911 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05005912 if (vport->port_type == LPFC_PHYSICAL_PORT)
5913 lpfc_initial_flogi(vport);
5914 else
5915 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005916 break;
5917 }
5918
5919 } else {
5920 if (vport == phba->pport)
James Smart6fb120a2009-05-22 14:52:59 -04005921 if (phba->sli_rev < LPFC_SLI_REV4)
5922 lpfc_issue_fabric_reglogin(vport);
5923 else
5924 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005925 else
5926 lpfc_do_scr_ns_plogi(phba, vport);
5927 }
James Smartfa4066b2008-01-11 01:53:27 -05005928
5929 /* Now, we decrement the ndlp reference count held for this
5930 * callback function
5931 */
5932 lpfc_nlp_put(ndlp);
5933
James Smart92d7f7b2007-06-17 19:56:38 -05005934 mempool_free(pmb, phba->mbox_mem_pool);
5935 return;
5936}
5937
James Smarte59058c2008-08-24 21:49:00 -04005938/**
James Smart3621a712009-04-06 18:47:14 -04005939 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04005940 * @phba: pointer to lpfc hba data structure.
5941 * @vport: pointer to a host virtual N_Port data structure.
5942 * @ndlp: pointer to a node-list data structure.
5943 *
5944 * This routine registers the @vport as a new virtual port with a HBA.
5945 * It is done through a registering vpi mailbox command.
5946 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005947static void
James Smart92d7f7b2007-06-17 19:56:38 -05005948lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5949 struct lpfc_nodelist *ndlp)
5950{
James Smart09372822008-01-11 01:52:54 -05005951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005952 LPFC_MBOXQ_t *mbox;
5953
5954 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5955 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04005956 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005957 mbox->vport = vport;
5958 mbox->context2 = lpfc_nlp_get(ndlp);
5959 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04005960 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005961 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05005962 /* mailbox command not success, decrement ndlp
5963 * reference count for this command
5964 */
5965 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005966 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05005967
James Smarte8b62012007-08-02 11:10:09 -04005968 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5969 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05005970 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005971 }
5972 } else {
James Smarte8b62012007-08-02 11:10:09 -04005973 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5974 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05005975 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005976 }
James Smartfa4066b2008-01-11 01:53:27 -05005977 return;
5978
5979mbox_err_exit:
5980 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5981 spin_lock_irq(shost->host_lock);
5982 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5983 spin_unlock_irq(shost->host_lock);
5984 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005985}
5986
James Smarte59058c2008-08-24 21:49:00 -04005987/**
James Smart3621a712009-04-06 18:47:14 -04005988 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04005989 * @phba: pointer to lpfc hba data structure.
5990 * @cmdiocb: pointer to lpfc command iocb data structure.
5991 * @rspiocb: pointer to lpfc response iocb data structure.
5992 *
5993 * This routine is the completion callback function to a Fabric Discover
5994 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5995 * single threaded, each FDISC completion callback function will reset
5996 * the discovery timer for all vports such that the timers will not get
5997 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5998 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5999 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6000 * assigned to the vport has been changed with the completion of the FDISC
6001 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6002 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6003 * routine is invoked to register new vport with the HBA. Otherwise, the
6004 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6005 * Server for State Change Request (SCR).
6006 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006007static void
6008lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6009 struct lpfc_iocbq *rspiocb)
6010{
6011 struct lpfc_vport *vport = cmdiocb->vport;
6012 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6013 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6014 struct lpfc_nodelist *np;
6015 struct lpfc_nodelist *next_np;
6016 IOCB_t *irsp = &rspiocb->iocb;
6017 struct lpfc_iocbq *piocb;
6018
James Smarte8b62012007-08-02 11:10:09 -04006019 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6020 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6021 irsp->ulpStatus, irsp->un.ulpWord[4],
6022 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006023 /* Since all FDISCs are being single threaded, we
6024 * must reset the discovery timer for ALL vports
6025 * waiting to send FDISC when one completes.
6026 */
6027 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6028 lpfc_set_disctmo(piocb->vport);
6029 }
6030
James Smart858c9f62007-06-17 19:56:39 -05006031 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6032 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6033 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6034
James Smart92d7f7b2007-06-17 19:56:38 -05006035 if (irsp->ulpStatus) {
6036 /* Check for retry */
6037 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6038 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006039 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006040 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006041 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006042 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006043 goto fdisc_failed;
6044 }
James Smart92d7f7b2007-06-17 19:56:38 -05006045 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
6046 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05006047 lpfc_nlp_put(ndlp);
6048 /* giving up on FDISC. Cancel discovery timer */
6049 lpfc_can_disctmo(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006050 spin_lock_irq(shost->host_lock);
6051 vport->fc_flag |= FC_FABRIC;
6052 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6053 vport->fc_flag |= FC_PUBLIC_LOOP;
6054 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006055
James Smartd7c255b2008-08-24 21:50:00 -04006056 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6057 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6058 if ((vport->fc_prevDID != vport->fc_myDID) &&
6059 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6060 /* If our NportID changed, we need to ensure all
6061 * remaining NPORTs get unreg_login'ed so we can
6062 * issue unreg_vpi.
6063 */
6064 list_for_each_entry_safe(np, next_np,
6065 &vport->fc_nodes, nlp_listp) {
6066 if (!NLP_CHK_NODE_ACT(ndlp) ||
6067 (np->nlp_state != NLP_STE_NPR_NODE) ||
6068 !(np->nlp_flag & NLP_NPR_ADISC))
6069 continue;
James Smart09372822008-01-11 01:52:54 -05006070 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006071 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006072 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006073 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006074 }
James Smartd7c255b2008-08-24 21:50:00 -04006075 lpfc_mbx_unreg_vpi(vport);
6076 spin_lock_irq(shost->host_lock);
6077 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6078 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006079 }
6080
James Smartd7c255b2008-08-24 21:50:00 -04006081 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
6082 lpfc_register_new_vport(phba, vport, ndlp);
6083 else
6084 lpfc_do_scr_ns_plogi(phba, vport);
6085 goto out;
6086fdisc_failed:
6087 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6088 /* Cancel discovery timer */
6089 lpfc_can_disctmo(vport);
6090 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006091out:
6092 lpfc_els_free_iocb(phba, cmdiocb);
6093}
6094
James Smarte59058c2008-08-24 21:49:00 -04006095/**
James Smart3621a712009-04-06 18:47:14 -04006096 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006097 * @vport: pointer to a virtual N_Port data structure.
6098 * @ndlp: pointer to a node-list data structure.
6099 * @retry: number of retries to the command IOCB.
6100 *
6101 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6102 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6103 * routine to issue the IOCB, which makes sure only one outstanding fabric
6104 * IOCB will be sent off HBA at any given time.
6105 *
6106 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6107 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6108 * will be stored into the context1 field of the IOCB for the completion
6109 * callback function to the FDISC ELS command.
6110 *
6111 * Return code
6112 * 0 - Successfully issued fdisc iocb command
6113 * 1 - Failed to issue fdisc iocb command
6114 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006115static int
James Smart92d7f7b2007-06-17 19:56:38 -05006116lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6117 uint8_t retry)
6118{
6119 struct lpfc_hba *phba = vport->phba;
6120 IOCB_t *icmd;
6121 struct lpfc_iocbq *elsiocb;
6122 struct serv_parm *sp;
6123 uint8_t *pcmd;
6124 uint16_t cmdsize;
6125 int did = ndlp->nlp_DID;
6126 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006127
6128 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6129 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6130 ELS_CMD_FDISC);
6131 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006132 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006133 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6134 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006135 return 1;
6136 }
6137
6138 icmd = &elsiocb->iocb;
6139 icmd->un.elsreq64.myID = 0;
6140 icmd->un.elsreq64.fl = 1;
6141
James Smartf1126682009-06-10 17:22:44 -04006142 if (phba->sli_rev == LPFC_SLI_REV4) {
6143 /* FDISC needs to be 1 for WQE VPI */
6144 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6145 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6146 /* Set the ulpContext to the vpi */
6147 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6148 } else {
6149 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6150 icmd->ulpCt_h = 1;
6151 icmd->ulpCt_l = 0;
6152 }
James Smart92d7f7b2007-06-17 19:56:38 -05006153
6154 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6155 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6156 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6157 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6158 sp = (struct serv_parm *) pcmd;
6159 /* Setup CSPs accordingly for Fabric */
6160 sp->cmn.e_d_tov = 0;
6161 sp->cmn.w2.r_a_tov = 0;
6162 sp->cls1.classValid = 0;
6163 sp->cls2.seqDelivery = 1;
6164 sp->cls3.seqDelivery = 1;
6165
6166 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6167 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6168 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6169 pcmd += sizeof(uint32_t); /* Port Name */
6170 memcpy(pcmd, &vport->fc_portname, 8);
6171 pcmd += sizeof(uint32_t); /* Node Name */
6172 pcmd += sizeof(uint32_t); /* Node Name */
6173 memcpy(pcmd, &vport->fc_nodename, 8);
6174
6175 lpfc_set_disctmo(vport);
6176
6177 phba->fc_stat.elsXmitFDISC++;
6178 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6179
James Smart858c9f62007-06-17 19:56:39 -05006180 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6181 "Issue FDISC: did:x%x",
6182 did, 0, 0);
6183
James Smart92d7f7b2007-06-17 19:56:38 -05006184 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6185 if (rc == IOCB_ERROR) {
6186 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006187 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006188 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6189 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006190 return 1;
6191 }
6192 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6193 vport->port_state = LPFC_FDISC;
6194 return 0;
6195}
6196
James Smarte59058c2008-08-24 21:49:00 -04006197/**
James Smart3621a712009-04-06 18:47:14 -04006198 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006199 * @phba: pointer to lpfc hba data structure.
6200 * @cmdiocb: pointer to lpfc command iocb data structure.
6201 * @rspiocb: pointer to lpfc response iocb data structure.
6202 *
6203 * This routine is the completion callback function to the issuing of a LOGO
6204 * ELS command off a vport. It frees the command IOCB and then decrement the
6205 * reference count held on ndlp for this completion function, indicating that
6206 * the reference to the ndlp is no long needed. Note that the
6207 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6208 * callback function and an additional explicit ndlp reference decrementation
6209 * will trigger the actual release of the ndlp.
6210 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006211static void
6212lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6213 struct lpfc_iocbq *rspiocb)
6214{
6215 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006216 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006217 struct lpfc_nodelist *ndlp;
6218 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006219
6220 irsp = &rspiocb->iocb;
6221 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6222 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6223 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006224
6225 lpfc_els_free_iocb(phba, cmdiocb);
6226 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006227
6228 /* Trigger the release of the ndlp after logo */
6229 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006230}
6231
James Smarte59058c2008-08-24 21:49:00 -04006232/**
James Smart3621a712009-04-06 18:47:14 -04006233 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006234 * @vport: pointer to a virtual N_Port data structure.
6235 * @ndlp: pointer to a node-list data structure.
6236 *
6237 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6238 *
6239 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6240 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6241 * will be stored into the context1 field of the IOCB for the completion
6242 * callback function to the LOGO ELS command.
6243 *
6244 * Return codes
6245 * 0 - Successfully issued logo off the @vport
6246 * 1 - Failed to issue logo off the @vport
6247 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006248int
6249lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6250{
6251 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6252 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006253 IOCB_t *icmd;
6254 struct lpfc_iocbq *elsiocb;
6255 uint8_t *pcmd;
6256 uint16_t cmdsize;
6257
6258 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6259 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6260 ELS_CMD_LOGO);
6261 if (!elsiocb)
6262 return 1;
6263
6264 icmd = &elsiocb->iocb;
6265 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6266 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6267 pcmd += sizeof(uint32_t);
6268
6269 /* Fill in LOGO payload */
6270 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6271 pcmd += sizeof(uint32_t);
6272 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6273
James Smart858c9f62007-06-17 19:56:39 -05006274 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6275 "Issue LOGO npiv did:x%x flg:x%x",
6276 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6277
James Smart92d7f7b2007-06-17 19:56:38 -05006278 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6279 spin_lock_irq(shost->host_lock);
6280 ndlp->nlp_flag |= NLP_LOGO_SND;
6281 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006282 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6283 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006284 spin_lock_irq(shost->host_lock);
6285 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6286 spin_unlock_irq(shost->host_lock);
6287 lpfc_els_free_iocb(phba, elsiocb);
6288 return 1;
6289 }
6290 return 0;
6291}
6292
James Smarte59058c2008-08-24 21:49:00 -04006293/**
James Smart3621a712009-04-06 18:47:14 -04006294 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006295 * @ptr: holder for the timer function associated data.
6296 *
6297 * This routine is invoked by the fabric iocb block timer after
6298 * timeout. It posts the fabric iocb block timeout event by setting the
6299 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6300 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6301 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6302 * posted event WORKER_FABRIC_BLOCK_TMO.
6303 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006304void
6305lpfc_fabric_block_timeout(unsigned long ptr)
6306{
6307 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6308 unsigned long iflags;
6309 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006310
James Smart92d7f7b2007-06-17 19:56:38 -05006311 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6312 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6313 if (!tmo_posted)
6314 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6315 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6316
James Smart5e9d9b82008-06-14 22:52:53 -04006317 if (!tmo_posted)
6318 lpfc_worker_wake_up(phba);
6319 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006320}
6321
James Smarte59058c2008-08-24 21:49:00 -04006322/**
James Smart3621a712009-04-06 18:47:14 -04006323 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006324 * @phba: pointer to lpfc hba data structure.
6325 *
6326 * This routine issues one fabric iocb from the driver internal list to
6327 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6328 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6329 * remove one pending fabric iocb from the driver internal list and invokes
6330 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6331 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006332static void
6333lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6334{
6335 struct lpfc_iocbq *iocb;
6336 unsigned long iflags;
6337 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006338 IOCB_t *cmd;
6339
6340repeat:
6341 iocb = NULL;
6342 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006343 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006344 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6345 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6346 list);
6347 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006348 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006349 atomic_inc(&phba->fabric_iocb_count);
6350 }
6351 spin_unlock_irqrestore(&phba->hbalock, iflags);
6352 if (iocb) {
6353 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6354 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6355 iocb->iocb_flag |= LPFC_IO_FABRIC;
6356
James Smart858c9f62007-06-17 19:56:39 -05006357 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6358 "Fabric sched1: ste:x%x",
6359 iocb->vport->port_state, 0, 0);
6360
James Smart3772a992009-05-22 14:50:54 -04006361 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006362
6363 if (ret == IOCB_ERROR) {
6364 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6365 iocb->fabric_iocb_cmpl = NULL;
6366 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6367 cmd = &iocb->iocb;
6368 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6369 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6370 iocb->iocb_cmpl(phba, iocb, iocb);
6371
6372 atomic_dec(&phba->fabric_iocb_count);
6373 goto repeat;
6374 }
6375 }
6376
6377 return;
6378}
6379
James Smarte59058c2008-08-24 21:49:00 -04006380/**
James Smart3621a712009-04-06 18:47:14 -04006381 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006382 * @phba: pointer to lpfc hba data structure.
6383 *
6384 * This routine unblocks the issuing fabric iocb command. The function
6385 * will clear the fabric iocb block bit and then invoke the routine
6386 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6387 * from the driver internal fabric iocb list.
6388 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006389void
6390lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6391{
6392 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6393
6394 lpfc_resume_fabric_iocbs(phba);
6395 return;
6396}
6397
James Smarte59058c2008-08-24 21:49:00 -04006398/**
James Smart3621a712009-04-06 18:47:14 -04006399 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006400 * @phba: pointer to lpfc hba data structure.
6401 *
6402 * This routine blocks the issuing fabric iocb for a specified amount of
6403 * time (currently 100 ms). This is done by set the fabric iocb block bit
6404 * and set up a timeout timer for 100ms. When the block bit is set, no more
6405 * fabric iocb will be issued out of the HBA.
6406 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006407static void
6408lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6409{
6410 int blocked;
6411
6412 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006413 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006414 if (!blocked)
6415 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6416
6417 return;
6418}
6419
James Smarte59058c2008-08-24 21:49:00 -04006420/**
James Smart3621a712009-04-06 18:47:14 -04006421 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006422 * @phba: pointer to lpfc hba data structure.
6423 * @cmdiocb: pointer to lpfc command iocb data structure.
6424 * @rspiocb: pointer to lpfc response iocb data structure.
6425 *
6426 * This routine is the callback function that is put to the fabric iocb's
6427 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6428 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6429 * function first restores and invokes the original iocb's callback function
6430 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6431 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6432 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006433static void
6434lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6435 struct lpfc_iocbq *rspiocb)
6436{
6437 struct ls_rjt stat;
6438
6439 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6440 BUG();
6441
6442 switch (rspiocb->iocb.ulpStatus) {
6443 case IOSTAT_NPORT_RJT:
6444 case IOSTAT_FABRIC_RJT:
6445 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6446 lpfc_block_fabric_iocbs(phba);
6447 }
6448 break;
6449
6450 case IOSTAT_NPORT_BSY:
6451 case IOSTAT_FABRIC_BSY:
6452 lpfc_block_fabric_iocbs(phba);
6453 break;
6454
6455 case IOSTAT_LS_RJT:
6456 stat.un.lsRjtError =
6457 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6458 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6459 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6460 lpfc_block_fabric_iocbs(phba);
6461 break;
6462 }
6463
6464 if (atomic_read(&phba->fabric_iocb_count) == 0)
6465 BUG();
6466
6467 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6468 cmdiocb->fabric_iocb_cmpl = NULL;
6469 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6470 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6471
6472 atomic_dec(&phba->fabric_iocb_count);
6473 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006474 /* Post any pending iocbs to HBA */
6475 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006476 }
6477}
6478
James Smarte59058c2008-08-24 21:49:00 -04006479/**
James Smart3621a712009-04-06 18:47:14 -04006480 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006481 * @phba: pointer to lpfc hba data structure.
6482 * @iocb: pointer to lpfc command iocb data structure.
6483 *
6484 * This routine is used as the top-level API for issuing a fabric iocb command
6485 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6486 * function makes sure that only one fabric bound iocb will be outstanding at
6487 * any given time. As such, this function will first check to see whether there
6488 * is already an outstanding fabric iocb on the wire. If so, it will put the
6489 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6490 * issued later. Otherwise, it will issue the iocb on the wire and update the
6491 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6492 *
6493 * Note, this implementation has a potential sending out fabric IOCBs out of
6494 * order. The problem is caused by the construction of the "ready" boolen does
6495 * not include the condition that the internal fabric IOCB list is empty. As
6496 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6497 * ahead of the fabric IOCBs in the internal list.
6498 *
6499 * Return code
6500 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6501 * IOCB_ERROR - failed to issue fabric iocb
6502 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006503static int
James Smart92d7f7b2007-06-17 19:56:38 -05006504lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6505{
6506 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006507 int ready;
6508 int ret;
6509
6510 if (atomic_read(&phba->fabric_iocb_count) > 1)
6511 BUG();
6512
6513 spin_lock_irqsave(&phba->hbalock, iflags);
6514 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6515 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6516
James Smart7f5f3d02008-02-08 18:50:14 -05006517 if (ready)
6518 /* Increment fabric iocb count to hold the position */
6519 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006520 spin_unlock_irqrestore(&phba->hbalock, iflags);
6521 if (ready) {
6522 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6523 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6524 iocb->iocb_flag |= LPFC_IO_FABRIC;
6525
James Smart858c9f62007-06-17 19:56:39 -05006526 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6527 "Fabric sched2: ste:x%x",
6528 iocb->vport->port_state, 0, 0);
6529
James Smart3772a992009-05-22 14:50:54 -04006530 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006531
6532 if (ret == IOCB_ERROR) {
6533 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6534 iocb->fabric_iocb_cmpl = NULL;
6535 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6536 atomic_dec(&phba->fabric_iocb_count);
6537 }
6538 } else {
6539 spin_lock_irqsave(&phba->hbalock, iflags);
6540 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6541 spin_unlock_irqrestore(&phba->hbalock, iflags);
6542 ret = IOCB_SUCCESS;
6543 }
6544 return ret;
6545}
6546
James Smarte59058c2008-08-24 21:49:00 -04006547/**
James Smart3621a712009-04-06 18:47:14 -04006548 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006549 * @vport: pointer to a virtual N_Port data structure.
6550 *
6551 * This routine aborts all the IOCBs associated with a @vport from the
6552 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6553 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6554 * list, removes each IOCB associated with the @vport off the list, set the
6555 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6556 * associated with the IOCB.
6557 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006558static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006559{
6560 LIST_HEAD(completions);
6561 struct lpfc_hba *phba = vport->phba;
6562 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006563
6564 spin_lock_irq(&phba->hbalock);
6565 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6566 list) {
6567
6568 if (piocb->vport != vport)
6569 continue;
6570
6571 list_move_tail(&piocb->list, &completions);
6572 }
6573 spin_unlock_irq(&phba->hbalock);
6574
James Smarta257bf92009-04-06 18:48:10 -04006575 /* Cancel all the IOCBs from the completions list */
6576 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6577 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006578}
6579
James Smarte59058c2008-08-24 21:49:00 -04006580/**
James Smart3621a712009-04-06 18:47:14 -04006581 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006582 * @ndlp: pointer to a node-list data structure.
6583 *
6584 * This routine aborts all the IOCBs associated with an @ndlp from the
6585 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6586 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6587 * list, removes each IOCB associated with the @ndlp off the list, set the
6588 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6589 * associated with the IOCB.
6590 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006591void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6592{
6593 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006594 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006595 struct lpfc_iocbq *tmp_iocb, *piocb;
6596 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006597
6598 spin_lock_irq(&phba->hbalock);
6599 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6600 list) {
6601 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6602
6603 list_move_tail(&piocb->list, &completions);
6604 }
6605 }
6606 spin_unlock_irq(&phba->hbalock);
6607
James Smarta257bf92009-04-06 18:48:10 -04006608 /* Cancel all the IOCBs from the completions list */
6609 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6610 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006611}
6612
James Smarte59058c2008-08-24 21:49:00 -04006613/**
James Smart3621a712009-04-06 18:47:14 -04006614 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006615 * @phba: pointer to lpfc hba data structure.
6616 *
6617 * This routine aborts all the IOCBs currently on the driver internal
6618 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6619 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6620 * list, removes IOCBs off the list, set the status feild to
6621 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6622 * the IOCB.
6623 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006624void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6625{
6626 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006627
6628 spin_lock_irq(&phba->hbalock);
6629 list_splice_init(&phba->fabric_iocb_list, &completions);
6630 spin_unlock_irq(&phba->hbalock);
6631
James Smarta257bf92009-04-06 18:48:10 -04006632 /* Cancel all the IOCBs from the completions list */
6633 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6634 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006635}
James Smart6fb120a2009-05-22 14:52:59 -04006636
6637/**
6638 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6639 * @phba: pointer to lpfc hba data structure.
6640 * @axri: pointer to the els xri abort wcqe structure.
6641 *
6642 * This routine is invoked by the worker thread to process a SLI4 slow-path
6643 * ELS aborted xri.
6644 **/
6645void
6646lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6647 struct sli4_wcqe_xri_aborted *axri)
6648{
6649 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6650 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6651 unsigned long iflag = 0;
6652
6653 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag);
6654 list_for_each_entry_safe(sglq_entry, sglq_next,
6655 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6656 if (sglq_entry->sli4_xritag == xri) {
6657 list_del(&sglq_entry->list);
6658 spin_unlock_irqrestore(
6659 &phba->sli4_hba.abts_sgl_list_lock,
6660 iflag);
6661 spin_lock_irqsave(&phba->hbalock, iflag);
6662
6663 list_add_tail(&sglq_entry->list,
6664 &phba->sli4_hba.lpfc_sgl_list);
6665 spin_unlock_irqrestore(&phba->hbalock, iflag);
6666 return;
6667 }
6668 }
6669 spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag);
6670}