1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * 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. *
20 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
34 #include "lpfc_sli4.h"
36 #include "lpfc_disc.h"
37 #include "lpfc_scsi.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_crtn.h"
41 #include "lpfc_vport.h"
42 #include "lpfc_debugfs.h"
44 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
49 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
50 struct lpfc_nodelist *ndlp, uint8_t retry);
51 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
52 struct lpfc_iocbq *iocb);
54 static int lpfc_max_els_tries = 3;
57 * lpfc_els_chk_latt - Check host link attention event for a vport
58 * @vport: pointer to a host virtual N_Port data structure.
60 * This routine checks whether there is an outstanding host link
61 * attention event during the discovery process with the @vport. It is done
62 * by reading the HBA's Host Attention (HA) register. If there is any host
63 * link attention events during this @vport's discovery process, the @vport
64 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
65 * be issued if the link state is not already in host link cleared state,
66 * and a return code shall indicate whether the host link attention event
69 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
70 * state in LPFC_VPORT_READY, the request for checking host link attention
71 * event will be ignored and a return code shall indicate no host link
72 * attention event had happened.
75 * 0 - no host link attention event happened
76 * 1 - host link attention event happened
79 lpfc_els_chk_latt(struct lpfc_vport *vport)
81 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
82 struct lpfc_hba *phba = vport->phba;
85 if (vport->port_state >= LPFC_VPORT_READY ||
86 phba->link_state == LPFC_LINK_DOWN ||
87 phba->sli_rev > LPFC_SLI_REV3)
90 /* Read the HBA Host Attention Register */
91 ha_copy = readl(phba->HAregaddr);
93 if (!(ha_copy & HA_LATT))
96 /* Pending Link Event during Discovery */
97 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
98 "0237 Pending Link Event during "
99 "Discovery: State x%x\n",
100 phba->pport->port_state);
102 /* CLEAR_LA should re-enable link attention events and
103 * we should then imediately take a LATT event. The
104 * LATT processing should call lpfc_linkdown() which
105 * will cleanup any left over in-progress discovery
108 spin_lock_irq(shost->host_lock);
109 vport->fc_flag |= FC_ABORT_DISCOVERY;
110 spin_unlock_irq(shost->host_lock);
112 if (phba->link_state != LPFC_CLEAR_LA)
113 lpfc_issue_clear_la(phba, vport);
119 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
120 * @vport: pointer to a host virtual N_Port data structure.
121 * @expectRsp: flag indicating whether response is expected.
122 * @cmdSize: size of the ELS command.
123 * @retry: number of retries to the command IOCB when it fails.
124 * @ndlp: pointer to a node-list data structure.
125 * @did: destination identifier.
126 * @elscmd: the ELS command code.
128 * This routine is used for allocating a lpfc-IOCB data structure from
129 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
130 * passed into the routine for discovery state machine to issue an Extended
131 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
132 * and preparation routine that is used by all the discovery state machine
133 * routines and the ELS command-specific fields will be later set up by
134 * the individual discovery machine routines after calling this routine
135 * allocating and preparing a generic IOCB data structure. It fills in the
136 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
137 * payload and response payload (if expected). The reference count on the
138 * ndlp is incremented by 1 and the reference to the ndlp is put into
139 * context1 of the IOCB data structure for this IOCB to hold the ndlp
140 * reference for the command's callback function to access later.
143 * Pointer to the newly allocated/prepared els iocb data structure
144 * NULL - when els iocb data structure allocation/preparation failed
147 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
148 uint16_t cmdSize, uint8_t retry,
149 struct lpfc_nodelist *ndlp, uint32_t did,
152 struct lpfc_hba *phba = vport->phba;
153 struct lpfc_iocbq *elsiocb;
154 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
155 struct ulp_bde64 *bpl;
159 if (!lpfc_is_link_up(phba))
162 /* Allocate buffer for command iocb */
163 elsiocb = lpfc_sli_get_iocbq(phba);
169 * If this command is for fabric controller and HBA running
170 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 if ((did == Fabric_DID) &&
173 (phba->hba_flag & HBA_FIP_SUPPORT) &&
174 ((elscmd == ELS_CMD_FLOGI) ||
175 (elscmd == ELS_CMD_FDISC) ||
176 (elscmd == ELS_CMD_LOGO)))
179 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
180 & LPFC_FIP_ELS_ID_MASK);
183 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
184 & LPFC_FIP_ELS_ID_MASK);
187 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
188 & LPFC_FIP_ELS_ID_MASK);
192 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
194 icmd = &elsiocb->iocb;
196 /* fill in BDEs for command */
197 /* Allocate buffer for command payload */
198 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
201 if (!pcmd || !pcmd->virt)
202 goto els_iocb_free_pcmb_exit;
204 INIT_LIST_HEAD(&pcmd->list);
206 /* Allocate buffer for response payload */
208 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
210 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 if (!prsp || !prsp->virt)
213 goto els_iocb_free_prsp_exit;
214 INIT_LIST_HEAD(&prsp->list);
218 /* Allocate buffer for Buffer ptr list */
219 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
221 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 if (!pbuflist || !pbuflist->virt)
224 goto els_iocb_free_pbuf_exit;
226 INIT_LIST_HEAD(&pbuflist->list);
228 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
229 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
230 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
231 icmd->un.elsreq64.remoteID = did; /* DID */
233 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
234 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
235 icmd->ulpTimeout = phba->fc_ratov * 2;
237 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
238 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 icmd->ulpBdeCount = 1;
242 icmd->ulpClass = CLASS3;
244 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
245 icmd->un.elsreq64.myID = vport->fc_myDID;
247 /* For ELS_REQUEST64_CR, use the VPI by default */
248 icmd->ulpContext = vport->vpi + phba->vpi_base;
250 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
251 if (elscmd == ELS_CMD_ECHO)
252 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 icmd->ulpCt_l = 1; /* context = VPI */
257 bpl = (struct ulp_bde64 *) pbuflist->virt;
258 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
259 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
260 bpl->tus.f.bdeSize = cmdSize;
261 bpl->tus.f.bdeFlags = 0;
262 bpl->tus.w = le32_to_cpu(bpl->tus.w);
266 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
267 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
268 bpl->tus.f.bdeSize = FCELSSIZE;
269 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
270 bpl->tus.w = le32_to_cpu(bpl->tus.w);
273 /* prevent preparing iocb with NULL ndlp reference */
274 elsiocb->context1 = lpfc_nlp_get(ndlp);
275 if (!elsiocb->context1)
276 goto els_iocb_free_pbuf_exit;
277 elsiocb->context2 = pcmd;
278 elsiocb->context3 = pbuflist;
279 elsiocb->retry = retry;
280 elsiocb->vport = vport;
281 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
284 list_add(&prsp->list, &pcmd->list);
287 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
288 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
289 "0116 Xmit ELS command x%x to remote "
290 "NPORT x%x I/O tag: x%x, port state: x%x\n",
291 elscmd, did, elsiocb->iotag,
294 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
295 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
296 "0117 Xmit ELS response x%x to remote "
297 "NPORT x%x I/O tag: x%x, size: x%x\n",
298 elscmd, ndlp->nlp_DID, elsiocb->iotag,
303 els_iocb_free_pbuf_exit:
305 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
308 els_iocb_free_prsp_exit:
309 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
312 els_iocb_free_pcmb_exit:
314 lpfc_sli_release_iocbq(phba, elsiocb);
319 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
320 * @vport: pointer to a host virtual N_Port data structure.
322 * This routine issues a fabric registration login for a @vport. An
323 * active ndlp node with Fabric_DID must already exist for this @vport.
324 * The routine invokes two mailbox commands to carry out fabric registration
325 * login through the HBA firmware: the first mailbox command requests the
326 * HBA to perform link configuration for the @vport; and the second mailbox
327 * command requests the HBA to perform the actual fabric registration login
331 * 0 - successfully issued fabric registration login for @vport
332 * -ENXIO -- failed to issue fabric registration login for @vport
335 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337 struct lpfc_hba *phba = vport->phba;
339 struct lpfc_dmabuf *mp;
340 struct lpfc_nodelist *ndlp;
341 struct serv_parm *sp;
345 sp = &phba->fc_fabparam;
346 ndlp = lpfc_findnode_did(vport, Fabric_DID);
347 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
352 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
358 vport->port_state = LPFC_FABRIC_CFG_LINK;
359 lpfc_config_link(phba, mbox);
360 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
363 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
364 if (rc == MBX_NOT_FINISHED) {
369 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
374 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
380 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 /* increment the reference count on ndlp to hold reference
383 * for the callback routine.
385 mbox->context2 = lpfc_nlp_get(ndlp);
387 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
388 if (rc == MBX_NOT_FINISHED) {
390 goto fail_issue_reg_login;
395 fail_issue_reg_login:
396 /* decrement the reference count on ndlp just incremented
397 * for the failed mbox command.
400 mp = (struct lpfc_dmabuf *) mbox->context1;
401 lpfc_mbuf_free(phba, mp->virt, mp->phys);
404 mempool_free(mbox, phba->mbox_mem_pool);
407 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
408 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
409 "0249 Cannot issue Register Fabric login: Err %d\n", err);
414 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
415 * @vport: pointer to a host virtual N_Port data structure.
417 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
418 * the @vport. This mailbox command is necessary for FCoE only.
421 * 0 - successfully issued REG_VFI for @vport
422 * A failure code otherwise.
425 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427 struct lpfc_hba *phba = vport->phba;
429 struct lpfc_nodelist *ndlp;
430 struct serv_parm *sp;
431 struct lpfc_dmabuf *dmabuf;
434 sp = &phba->fc_fabparam;
435 ndlp = lpfc_findnode_did(vport, Fabric_DID);
436 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
441 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
446 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
449 goto fail_free_dmabuf;
451 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
454 goto fail_free_coherent;
456 vport->port_state = LPFC_FABRIC_CFG_LINK;
457 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
458 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
459 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
460 mboxq->vport = vport;
461 mboxq->context1 = dmabuf;
462 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
463 if (rc == MBX_NOT_FINISHED) {
470 mempool_free(mboxq, phba->mbox_mem_pool);
472 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
476 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
477 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
478 "0289 Issue Register VFI failed: Err %d\n", rc);
483 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
484 * @vport: pointer to a host virtual N_Port data structure.
485 * @ndlp: pointer to a node-list data structure.
486 * @sp: pointer to service parameter data structure.
487 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
490 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
491 * port in a fabric topology. It properly sets up the parameters to the @ndlp
492 * from the IOCB response. It also check the newly assigned N_Port ID to the
493 * @vport against the previously assigned N_Port ID. If it is different from
494 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
495 * is invoked on all the remaining nodes with the @vport to unregister the
496 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
497 * is invoked to register login to the fabric.
500 * 0 - Success (currently, always return 0)
503 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
504 struct serv_parm *sp, IOCB_t *irsp)
506 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
507 struct lpfc_hba *phba = vport->phba;
508 struct lpfc_nodelist *np;
509 struct lpfc_nodelist *next_np;
511 spin_lock_irq(shost->host_lock);
512 vport->fc_flag |= FC_FABRIC;
513 spin_unlock_irq(shost->host_lock);
515 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
516 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
517 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521 if (phba->fc_topology == TOPOLOGY_LOOP) {
522 spin_lock_irq(shost->host_lock);
523 vport->fc_flag |= FC_PUBLIC_LOOP;
524 spin_unlock_irq(shost->host_lock);
527 * If we are a N-port connected to a Fabric, fixup sparam's so
528 * logins to devices on remote loops work.
530 vport->fc_sparam.cmn.altBbCredit = 1;
533 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
534 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
535 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
536 ndlp->nlp_class_sup = 0;
537 if (sp->cls1.classValid)
538 ndlp->nlp_class_sup |= FC_COS_CLASS1;
539 if (sp->cls2.classValid)
540 ndlp->nlp_class_sup |= FC_COS_CLASS2;
541 if (sp->cls3.classValid)
542 ndlp->nlp_class_sup |= FC_COS_CLASS3;
543 if (sp->cls4.classValid)
544 ndlp->nlp_class_sup |= FC_COS_CLASS4;
545 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
546 sp->cmn.bbRcvSizeLsb;
547 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
549 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
550 if (sp->cmn.response_multiple_NPort) {
551 lpfc_printf_vlog(vport, KERN_WARNING,
553 "1816 FLOGI NPIV supported, "
554 "response data 0x%x\n",
555 sp->cmn.response_multiple_NPort);
556 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
558 /* Because we asked f/w for NPIV it still expects us
559 to call reg_vnpid atleast for the physcial host */
560 lpfc_printf_vlog(vport, KERN_WARNING,
562 "1817 Fabric does not support NPIV "
563 "- configuring single port mode.\n");
564 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
568 if ((vport->fc_prevDID != vport->fc_myDID) &&
569 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
571 /* If our NportID changed, we need to ensure all
572 * remaining NPORTs get unreg_login'ed.
574 list_for_each_entry_safe(np, next_np,
575 &vport->fc_nodes, nlp_listp) {
576 if (!NLP_CHK_NODE_ACT(np))
578 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
579 !(np->nlp_flag & NLP_NPR_ADISC))
581 spin_lock_irq(shost->host_lock);
582 np->nlp_flag &= ~NLP_NPR_ADISC;
583 spin_unlock_irq(shost->host_lock);
584 lpfc_unreg_rpi(vport, np);
586 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
587 lpfc_mbx_unreg_vpi(vport);
588 spin_lock_irq(shost->host_lock);
589 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
590 spin_unlock_irq(shost->host_lock);
593 * If VPI is unreged, driver need to do INIT_VPI
594 * before re-registering
596 if (phba->sli_rev == LPFC_SLI_REV4) {
597 spin_lock_irq(shost->host_lock);
598 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
599 spin_unlock_irq(shost->host_lock);
603 if (phba->sli_rev < LPFC_SLI_REV4) {
604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
605 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
606 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
607 lpfc_register_new_vport(phba, vport, ndlp);
609 lpfc_issue_fabric_reglogin(vport);
611 ndlp->nlp_type |= NLP_FABRIC;
612 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
613 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
614 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
615 lpfc_start_fdiscs(phba);
616 lpfc_do_scr_ns_plogi(phba, vport);
617 } else if (vport->fc_flag & FC_VFI_REGISTERED)
618 lpfc_issue_init_vpi(vport);
620 lpfc_issue_reg_vfi(vport);
625 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
626 * @vport: pointer to a host virtual N_Port data structure.
627 * @ndlp: pointer to a node-list data structure.
628 * @sp: pointer to service parameter data structure.
630 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
631 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
632 * in a point-to-point topology. First, the @vport's N_Port Name is compared
633 * with the received N_Port Name: if the @vport's N_Port Name is greater than
634 * the received N_Port Name lexicographically, this node shall assign local
635 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
636 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
637 * this node shall just wait for the remote node to issue PLOGI and assign
645 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
646 struct serv_parm *sp)
648 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
649 struct lpfc_hba *phba = vport->phba;
653 spin_lock_irq(shost->host_lock);
654 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
655 spin_unlock_irq(shost->host_lock);
657 phba->fc_edtov = FF_DEF_EDTOV;
658 phba->fc_ratov = FF_DEF_RATOV;
659 rc = memcmp(&vport->fc_portname, &sp->portName,
660 sizeof(vport->fc_portname));
662 /* This side will initiate the PLOGI */
663 spin_lock_irq(shost->host_lock);
664 vport->fc_flag |= FC_PT2PT_PLOGI;
665 spin_unlock_irq(shost->host_lock);
668 * N_Port ID cannot be 0, set our to LocalID the other
669 * side will be RemoteID.
674 vport->fc_myDID = PT2PT_LocalID;
676 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
680 lpfc_config_link(phba, mbox);
682 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
684 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
685 if (rc == MBX_NOT_FINISHED) {
686 mempool_free(mbox, phba->mbox_mem_pool);
689 /* Decrement ndlp reference count indicating that ndlp can be
690 * safely released when other references to it are done.
694 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
697 * Cannot find existing Fabric ndlp, so allocate a
700 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
703 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
704 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
705 ndlp = lpfc_enable_node(vport, ndlp,
706 NLP_STE_UNUSED_NODE);
711 memcpy(&ndlp->nlp_portname, &sp->portName,
712 sizeof(struct lpfc_name));
713 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
714 sizeof(struct lpfc_name));
715 /* Set state will put ndlp onto node list if not already done */
716 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
717 spin_lock_irq(shost->host_lock);
718 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
719 spin_unlock_irq(shost->host_lock);
721 /* This side will wait for the PLOGI, decrement ndlp reference
722 * count indicating that ndlp can be released when other
723 * references to it are done.
727 /* If we are pt2pt with another NPort, force NPIV off! */
728 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
730 spin_lock_irq(shost->host_lock);
731 vport->fc_flag |= FC_PT2PT;
732 spin_unlock_irq(shost->host_lock);
734 /* Start discovery - this should just do CLEAR_LA */
735 lpfc_disc_start(vport);
742 * lpfc_cmpl_els_flogi - Completion callback function for flogi
743 * @phba: pointer to lpfc hba data structure.
744 * @cmdiocb: pointer to lpfc command iocb data structure.
745 * @rspiocb: pointer to lpfc response iocb data structure.
747 * This routine is the top-level completion callback function for issuing
748 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
749 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
750 * retry has been made (either immediately or delayed with lpfc_els_retry()
751 * returning 1), the command IOCB will be released and function returned.
752 * If the retry attempt has been given up (possibly reach the maximum
753 * number of retries), one additional decrement of ndlp reference shall be
754 * invoked before going out after releasing the command IOCB. This will
755 * actually release the remote node (Note, lpfc_els_free_iocb() will also
756 * invoke one decrement of ndlp reference count). If no error reported in
757 * the IOCB status, the command Port ID field is used to determine whether
758 * this is a point-to-point topology or a fabric topology: if the Port ID
759 * field is assigned, it is a fabric topology; otherwise, it is a
760 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
761 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
762 * specific topology completion conditions.
765 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
766 struct lpfc_iocbq *rspiocb)
768 struct lpfc_vport *vport = cmdiocb->vport;
769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
770 IOCB_t *irsp = &rspiocb->iocb;
771 struct lpfc_nodelist *ndlp = cmdiocb->context1;
772 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
773 struct serv_parm *sp;
776 /* Check to see if link went down during discovery */
777 if (lpfc_els_chk_latt(vport)) {
778 /* One additional decrement on node reference count to
779 * trigger the release of the node
785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
786 "FLOGI cmpl: status:x%x/x%x state:x%x",
787 irsp->ulpStatus, irsp->un.ulpWord[4],
790 if (irsp->ulpStatus) {
791 /* Check for retry */
792 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
795 /* FLOGI failed, so there is no fabric */
796 spin_lock_irq(shost->host_lock);
797 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
798 spin_unlock_irq(shost->host_lock);
800 /* If private loop, then allow max outstanding els to be
801 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
802 * alpa map would take too long otherwise.
804 if (phba->alpa_map[0] == 0) {
805 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
809 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
810 "0100 FLOGI failure Data: x%x x%x "
812 irsp->ulpStatus, irsp->un.ulpWord[4],
816 spin_lock_irq(shost->host_lock);
817 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
818 spin_unlock_irq(shost->host_lock);
821 * The FLogI succeeded. Sync the data for the CPU before
824 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
826 sp = prsp->virt + sizeof(uint32_t);
828 /* FLOGI completes successfully */
829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
830 "0101 FLOGI completes successfully "
831 "Data: x%x x%x x%x x%x\n",
832 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
833 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
835 if (vport->port_state == LPFC_FLOGI) {
837 * If Common Service Parameters indicate Nport
838 * we are point to point, if Fport we are Fabric.
841 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
843 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
852 if (!lpfc_error_lost_link(irsp)) {
853 /* FLOGI failed, so just use loop map to make discovery list */
854 lpfc_disc_list_loopmap(vport);
856 /* Start discovery */
857 lpfc_disc_start(vport);
858 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
859 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
860 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
861 (phba->link_state != LPFC_CLEAR_LA)) {
862 /* If FLOGI failed enable link interrupt. */
863 lpfc_issue_clear_la(phba, vport);
866 lpfc_els_free_iocb(phba, cmdiocb);
870 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
871 * @vport: pointer to a host virtual N_Port data structure.
872 * @ndlp: pointer to a node-list data structure.
873 * @retry: number of retries to the command IOCB.
875 * This routine issues a Fabric Login (FLOGI) Request ELS command
876 * for a @vport. The initiator service parameters are put into the payload
877 * of the FLOGI Request IOCB and the top-level callback function pointer
878 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
879 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
880 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
882 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
883 * will be incremented by 1 for holding the ndlp and the reference to ndlp
884 * will be stored into the context1 field of the IOCB for the completion
885 * callback function to the FLOGI ELS command.
888 * 0 - successfully issued flogi iocb for @vport
889 * 1 - failed to issue flogi iocb for @vport
892 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
895 struct lpfc_hba *phba = vport->phba;
896 struct serv_parm *sp;
898 struct lpfc_iocbq *elsiocb;
899 struct lpfc_sli_ring *pring;
905 pring = &phba->sli.ring[LPFC_ELS_RING];
907 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
908 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
909 ndlp->nlp_DID, ELS_CMD_FLOGI);
914 icmd = &elsiocb->iocb;
915 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
917 /* For FLOGI request, remainder of payload is service parameters */
918 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
919 pcmd += sizeof(uint32_t);
920 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
921 sp = (struct serv_parm *) pcmd;
923 /* Setup CSPs accordingly for Fabric */
925 sp->cmn.w2.r_a_tov = 0;
926 sp->cls1.classValid = 0;
927 sp->cls2.seqDelivery = 1;
928 sp->cls3.seqDelivery = 1;
929 if (sp->cmn.fcphLow < FC_PH3)
930 sp->cmn.fcphLow = FC_PH3;
931 if (sp->cmn.fcphHigh < FC_PH3)
932 sp->cmn.fcphHigh = FC_PH3;
934 if (phba->sli_rev == LPFC_SLI_REV4) {
935 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
936 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
937 /* FLOGI needs to be 3 for WQE FCFI */
938 /* Set the fcfi to the fcfi we registered with */
939 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
940 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
941 sp->cmn.request_multiple_Nport = 1;
942 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
947 if (phba->fc_topology != TOPOLOGY_LOOP) {
948 icmd->un.elsreq64.myID = 0;
949 icmd->un.elsreq64.fl = 1;
952 tmo = phba->fc_ratov;
953 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
954 lpfc_set_disctmo(vport);
955 phba->fc_ratov = tmo;
957 phba->fc_stat.elsXmitFLOGI++;
958 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
961 "Issue FLOGI: opt:x%x",
962 phba->sli3_options, 0, 0);
964 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
965 if (rc == IOCB_ERROR) {
966 lpfc_els_free_iocb(phba, elsiocb);
973 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
974 * @phba: pointer to lpfc hba data structure.
976 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
977 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
978 * list and issues an abort IOCB commond on each outstanding IOCB that
979 * contains a active Fabric_DID ndlp. Note that this function is to issue
980 * the abort IOCB command on all the outstanding IOCBs, thus when this
981 * function returns, it does not guarantee all the IOCBs are actually aborted.
984 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
987 lpfc_els_abort_flogi(struct lpfc_hba *phba)
989 struct lpfc_sli_ring *pring;
990 struct lpfc_iocbq *iocb, *next_iocb;
991 struct lpfc_nodelist *ndlp;
994 /* Abort outstanding I/O on NPort <nlp_DID> */
995 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
996 "0201 Abort outstanding I/O on NPort x%x\n",
999 pring = &phba->sli.ring[LPFC_ELS_RING];
1002 * Check the txcmplq for an iocb that matches the nport the driver is
1005 spin_lock_irq(&phba->hbalock);
1006 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1008 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1009 icmd->un.elsreq64.bdl.ulpIoTag32) {
1010 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1011 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1012 (ndlp->nlp_DID == Fabric_DID))
1013 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1016 spin_unlock_irq(&phba->hbalock);
1022 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1023 * @vport: pointer to a host virtual N_Port data structure.
1025 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1026 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1027 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1028 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1029 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1030 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1034 * 0 - failed to issue initial flogi for @vport
1035 * 1 - successfully issued initial flogi for @vport
1038 lpfc_initial_flogi(struct lpfc_vport *vport)
1040 struct lpfc_hba *phba = vport->phba;
1041 struct lpfc_nodelist *ndlp;
1043 vport->port_state = LPFC_FLOGI;
1044 lpfc_set_disctmo(vport);
1046 /* First look for the Fabric ndlp */
1047 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1049 /* Cannot find existing Fabric ndlp, so allocate a new one */
1050 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1053 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1054 /* Set the node type */
1055 ndlp->nlp_type |= NLP_FABRIC;
1056 /* Put ndlp onto node list */
1057 lpfc_enqueue_node(vport, ndlp);
1058 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1059 /* re-setup ndlp without removing from node list */
1060 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1065 if (lpfc_issue_els_flogi(vport, ndlp, 0))
1066 /* This decrement of reference count to node shall kick off
1067 * the release of the node.
1075 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1076 * @vport: pointer to a host virtual N_Port data structure.
1078 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1079 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1080 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1081 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1082 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1083 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1087 * 0 - failed to issue initial fdisc for @vport
1088 * 1 - successfully issued initial fdisc for @vport
1091 lpfc_initial_fdisc(struct lpfc_vport *vport)
1093 struct lpfc_hba *phba = vport->phba;
1094 struct lpfc_nodelist *ndlp;
1096 /* First look for the Fabric ndlp */
1097 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1099 /* Cannot find existing Fabric ndlp, so allocate a new one */
1100 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1103 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1104 /* Put ndlp onto node list */
1105 lpfc_enqueue_node(vport, ndlp);
1106 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1107 /* re-setup ndlp without removing from node list */
1108 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1113 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1114 /* decrement node reference count to trigger the release of
1124 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1125 * @vport: pointer to a host virtual N_Port data structure.
1127 * This routine checks whether there are more remaining Port Logins
1128 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1129 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1130 * to issue ELS PLOGIs up to the configured discover threads with the
1131 * @vport (@vport->cfg_discovery_threads). The function also decrement
1132 * the @vport's num_disc_node by 1 if it is not already 0.
1135 lpfc_more_plogi(struct lpfc_vport *vport)
1139 if (vport->num_disc_nodes)
1140 vport->num_disc_nodes--;
1142 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1143 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1144 "0232 Continue discovery with %d PLOGIs to go "
1145 "Data: x%x x%x x%x\n",
1146 vport->num_disc_nodes, vport->fc_plogi_cnt,
1147 vport->fc_flag, vport->port_state);
1148 /* Check to see if there are more PLOGIs to be sent */
1149 if (vport->fc_flag & FC_NLP_MORE)
1150 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1151 sentplogi = lpfc_els_disc_plogi(vport);
1157 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1158 * @phba: pointer to lpfc hba data structure.
1159 * @prsp: pointer to response IOCB payload.
1160 * @ndlp: pointer to a node-list data structure.
1162 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1163 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1164 * The following cases are considered N_Port confirmed:
1165 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1166 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1167 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1168 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1169 * 1) if there is a node on vport list other than the @ndlp with the same
1170 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1171 * on that node to release the RPI associated with the node; 2) if there is
1172 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1173 * into, a new node shall be allocated (or activated). In either case, the
1174 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1175 * be released and the new_ndlp shall be put on to the vport node list and
1176 * its pointer returned as the confirmed node.
1178 * Note that before the @ndlp got "released", the keepDID from not-matching
1179 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1180 * of the @ndlp. This is because the release of @ndlp is actually to put it
1181 * into an inactive state on the vport node list and the vport node list
1182 * management algorithm does not allow two node with a same DID.
1185 * pointer to the PLOGI N_Port @ndlp
1187 static struct lpfc_nodelist *
1188 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1189 struct lpfc_nodelist *ndlp)
1191 struct lpfc_vport *vport = ndlp->vport;
1192 struct lpfc_nodelist *new_ndlp;
1193 struct lpfc_rport_data *rdata;
1194 struct fc_rport *rport;
1195 struct serv_parm *sp;
1196 uint8_t name[sizeof(struct lpfc_name)];
1197 uint32_t rc, keepDID = 0;
1199 /* Fabric nodes can have the same WWPN so we don't bother searching
1200 * by WWPN. Just return the ndlp that was given to us.
1202 if (ndlp->nlp_type & NLP_FABRIC)
1205 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1206 memset(name, 0, sizeof(struct lpfc_name));
1208 /* Now we find out if the NPort we are logging into, matches the WWPN
1209 * we have for that ndlp. If not, we have some work to do.
1211 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1213 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1217 rc = memcmp(&ndlp->nlp_portname, name,
1218 sizeof(struct lpfc_name));
1221 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1224 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1225 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1226 rc = memcmp(&ndlp->nlp_portname, name,
1227 sizeof(struct lpfc_name));
1230 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1231 NLP_STE_UNUSED_NODE);
1234 keepDID = new_ndlp->nlp_DID;
1236 keepDID = new_ndlp->nlp_DID;
1238 lpfc_unreg_rpi(vport, new_ndlp);
1239 new_ndlp->nlp_DID = ndlp->nlp_DID;
1240 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1242 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1243 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1244 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1246 /* Set state will put new_ndlp on to node list if not already done */
1247 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1249 /* Move this back to NPR state */
1250 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1251 /* The new_ndlp is replacing ndlp totally, so we need
1252 * to put ndlp on UNUSED list and try to free it.
1255 /* Fix up the rport accordingly */
1256 rport = ndlp->rport;
1258 rdata = rport->dd_data;
1259 if (rdata->pnode == ndlp) {
1262 rdata->pnode = lpfc_nlp_get(new_ndlp);
1263 new_ndlp->rport = rport;
1265 new_ndlp->nlp_type = ndlp->nlp_type;
1267 /* We shall actually free the ndlp with both nlp_DID and
1268 * nlp_portname fields equals 0 to avoid any ndlp on the
1269 * nodelist never to be used.
1271 if (ndlp->nlp_DID == 0) {
1272 spin_lock_irq(&phba->ndlp_lock);
1273 NLP_SET_FREE_REQ(ndlp);
1274 spin_unlock_irq(&phba->ndlp_lock);
1277 /* Two ndlps cannot have the same did on the nodelist */
1278 ndlp->nlp_DID = keepDID;
1279 lpfc_drop_node(vport, ndlp);
1282 lpfc_unreg_rpi(vport, ndlp);
1283 /* Two ndlps cannot have the same did */
1284 ndlp->nlp_DID = keepDID;
1285 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1291 * lpfc_end_rscn - Check and handle more rscn for a vport
1292 * @vport: pointer to a host virtual N_Port data structure.
1294 * This routine checks whether more Registration State Change
1295 * Notifications (RSCNs) came in while the discovery state machine was in
1296 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1297 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1298 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1299 * handling the RSCNs.
1302 lpfc_end_rscn(struct lpfc_vport *vport)
1304 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1306 if (vport->fc_flag & FC_RSCN_MODE) {
1308 * Check to see if more RSCNs came in while we were
1309 * processing this one.
1311 if (vport->fc_rscn_id_cnt ||
1312 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1313 lpfc_els_handle_rscn(vport);
1315 spin_lock_irq(shost->host_lock);
1316 vport->fc_flag &= ~FC_RSCN_MODE;
1317 spin_unlock_irq(shost->host_lock);
1323 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1324 * @phba: pointer to lpfc hba data structure.
1325 * @cmdiocb: pointer to lpfc command iocb data structure.
1326 * @rspiocb: pointer to lpfc response iocb data structure.
1328 * This routine is the completion callback function for issuing the Port
1329 * Login (PLOGI) command. For PLOGI completion, there must be an active
1330 * ndlp on the vport node list that matches the remote node ID from the
1331 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1332 * ignored and command IOCB released. The PLOGI response IOCB status is
1333 * checked for error conditons. If there is error status reported, PLOGI
1334 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1335 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1336 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1337 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1338 * there are additional N_Port nodes with the vport that need to perform
1339 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1343 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1344 struct lpfc_iocbq *rspiocb)
1346 struct lpfc_vport *vport = cmdiocb->vport;
1347 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1349 struct lpfc_nodelist *ndlp;
1350 struct lpfc_dmabuf *prsp;
1351 int disc, rc, did, type;
1353 /* we pass cmdiocb to state machine which needs rspiocb as well */
1354 cmdiocb->context_un.rsp_iocb = rspiocb;
1356 irsp = &rspiocb->iocb;
1357 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1358 "PLOGI cmpl: status:x%x/x%x did:x%x",
1359 irsp->ulpStatus, irsp->un.ulpWord[4],
1360 irsp->un.elsreq64.remoteID);
1362 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1363 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1364 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1365 "0136 PLOGI completes to NPort x%x "
1366 "with no ndlp. Data: x%x x%x x%x\n",
1367 irsp->un.elsreq64.remoteID,
1368 irsp->ulpStatus, irsp->un.ulpWord[4],
1373 /* Since ndlp can be freed in the disc state machine, note if this node
1374 * is being used during discovery.
1376 spin_lock_irq(shost->host_lock);
1377 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1378 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1379 spin_unlock_irq(shost->host_lock);
1382 /* PLOGI completes to NPort <nlp_DID> */
1383 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1384 "0102 PLOGI completes to NPort x%x "
1385 "Data: x%x x%x x%x x%x x%x\n",
1386 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1387 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1388 /* Check to see if link went down during discovery */
1389 if (lpfc_els_chk_latt(vport)) {
1390 spin_lock_irq(shost->host_lock);
1391 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1392 spin_unlock_irq(shost->host_lock);
1396 /* ndlp could be freed in DSM, save these values now */
1397 type = ndlp->nlp_type;
1398 did = ndlp->nlp_DID;
1400 if (irsp->ulpStatus) {
1401 /* Check for retry */
1402 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1403 /* ELS command is being retried */
1405 spin_lock_irq(shost->host_lock);
1406 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1407 spin_unlock_irq(shost->host_lock);
1412 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1413 if (lpfc_error_lost_link(irsp))
1414 rc = NLP_STE_FREED_NODE;
1416 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1417 NLP_EVT_CMPL_PLOGI);
1419 /* Good status, call state machine */
1420 prsp = list_entry(((struct lpfc_dmabuf *)
1421 cmdiocb->context2)->list.next,
1422 struct lpfc_dmabuf, list);
1423 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1424 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1425 NLP_EVT_CMPL_PLOGI);
1428 if (disc && vport->num_disc_nodes) {
1429 /* Check to see if there are more PLOGIs to be sent */
1430 lpfc_more_plogi(vport);
1432 if (vport->num_disc_nodes == 0) {
1433 spin_lock_irq(shost->host_lock);
1434 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1435 spin_unlock_irq(shost->host_lock);
1437 lpfc_can_disctmo(vport);
1438 lpfc_end_rscn(vport);
1443 lpfc_els_free_iocb(phba, cmdiocb);
1448 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1449 * @vport: pointer to a host virtual N_Port data structure.
1450 * @did: destination port identifier.
1451 * @retry: number of retries to the command IOCB.
1453 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1454 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1455 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1456 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1457 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1459 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1460 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1461 * will be stored into the context1 field of the IOCB for the completion
1462 * callback function to the PLOGI ELS command.
1465 * 0 - Successfully issued a plogi for @vport
1466 * 1 - failed to issue a plogi for @vport
1469 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1471 struct lpfc_hba *phba = vport->phba;
1472 struct serv_parm *sp;
1474 struct lpfc_nodelist *ndlp;
1475 struct lpfc_iocbq *elsiocb;
1476 struct lpfc_sli *psli;
1483 ndlp = lpfc_findnode_did(vport, did);
1484 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1487 /* If ndlp is not NULL, we will bump the reference count on it */
1488 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1489 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1494 icmd = &elsiocb->iocb;
1495 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1497 /* For PLOGI request, remainder of payload is service parameters */
1498 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1499 pcmd += sizeof(uint32_t);
1500 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1501 sp = (struct serv_parm *) pcmd;
1503 if (sp->cmn.fcphLow < FC_PH_4_3)
1504 sp->cmn.fcphLow = FC_PH_4_3;
1506 if (sp->cmn.fcphHigh < FC_PH3)
1507 sp->cmn.fcphHigh = FC_PH3;
1509 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1510 "Issue PLOGI: did:x%x",
1513 phba->fc_stat.elsXmitPLOGI++;
1514 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1515 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1517 if (ret == IOCB_ERROR) {
1518 lpfc_els_free_iocb(phba, elsiocb);
1525 * lpfc_cmpl_els_prli - Completion callback function for prli
1526 * @phba: pointer to lpfc hba data structure.
1527 * @cmdiocb: pointer to lpfc command iocb data structure.
1528 * @rspiocb: pointer to lpfc response iocb data structure.
1530 * This routine is the completion callback function for a Process Login
1531 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1532 * status. If there is error status reported, PRLI retry shall be attempted
1533 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1534 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1535 * ndlp to mark the PRLI completion.
1538 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1539 struct lpfc_iocbq *rspiocb)
1541 struct lpfc_vport *vport = cmdiocb->vport;
1542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1544 struct lpfc_sli *psli;
1545 struct lpfc_nodelist *ndlp;
1548 /* we pass cmdiocb to state machine which needs rspiocb as well */
1549 cmdiocb->context_un.rsp_iocb = rspiocb;
1551 irsp = &(rspiocb->iocb);
1552 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1553 spin_lock_irq(shost->host_lock);
1554 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1555 spin_unlock_irq(shost->host_lock);
1557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1558 "PRLI cmpl: status:x%x/x%x did:x%x",
1559 irsp->ulpStatus, irsp->un.ulpWord[4],
1561 /* PRLI completes to NPort <nlp_DID> */
1562 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1563 "0103 PRLI completes to NPort x%x "
1564 "Data: x%x x%x x%x x%x\n",
1565 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1566 irsp->ulpTimeout, vport->num_disc_nodes);
1568 vport->fc_prli_sent--;
1569 /* Check to see if link went down during discovery */
1570 if (lpfc_els_chk_latt(vport))
1573 if (irsp->ulpStatus) {
1574 /* Check for retry */
1575 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1576 /* ELS command is being retried */
1580 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1581 if (lpfc_error_lost_link(irsp))
1584 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1587 /* Good status, call state machine */
1588 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1591 lpfc_els_free_iocb(phba, cmdiocb);
1596 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1597 * @vport: pointer to a host virtual N_Port data structure.
1598 * @ndlp: pointer to a node-list data structure.
1599 * @retry: number of retries to the command IOCB.
1601 * This routine issues a Process Login (PRLI) ELS command for the
1602 * @vport. The PRLI service parameters are set up in the payload of the
1603 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1604 * is put to the IOCB completion callback func field before invoking the
1605 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1607 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1608 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1609 * will be stored into the context1 field of the IOCB for the completion
1610 * callback function to the PRLI ELS command.
1613 * 0 - successfully issued prli iocb command for @vport
1614 * 1 - failed to issue prli iocb command for @vport
1617 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1620 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1621 struct lpfc_hba *phba = vport->phba;
1624 struct lpfc_iocbq *elsiocb;
1628 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1629 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1630 ndlp->nlp_DID, ELS_CMD_PRLI);
1634 icmd = &elsiocb->iocb;
1635 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1637 /* For PRLI request, remainder of payload is service parameters */
1638 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1639 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1640 pcmd += sizeof(uint32_t);
1642 /* For PRLI, remainder of payload is PRLI parameter page */
1643 npr = (PRLI *) pcmd;
1645 * If our firmware version is 3.20 or later,
1646 * set the following bits for FC-TAPE support.
1648 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1649 npr->ConfmComplAllowed = 1;
1651 npr->TaskRetryIdReq = 1;
1653 npr->estabImagePair = 1;
1654 npr->readXferRdyDis = 1;
1656 /* For FCP support */
1657 npr->prliType = PRLI_FCP_TYPE;
1658 npr->initiatorFunc = 1;
1660 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1661 "Issue PRLI: did:x%x",
1662 ndlp->nlp_DID, 0, 0);
1664 phba->fc_stat.elsXmitPRLI++;
1665 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1666 spin_lock_irq(shost->host_lock);
1667 ndlp->nlp_flag |= NLP_PRLI_SND;
1668 spin_unlock_irq(shost->host_lock);
1669 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1671 spin_lock_irq(shost->host_lock);
1672 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1673 spin_unlock_irq(shost->host_lock);
1674 lpfc_els_free_iocb(phba, elsiocb);
1677 vport->fc_prli_sent++;
1682 * lpfc_rscn_disc - Perform rscn discovery for a vport
1683 * @vport: pointer to a host virtual N_Port data structure.
1685 * This routine performs Registration State Change Notification (RSCN)
1686 * discovery for a @vport. If the @vport's node port recovery count is not
1687 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1688 * the nodes that need recovery. If none of the PLOGI were needed through
1689 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1690 * invoked to check and handle possible more RSCN came in during the period
1691 * of processing the current ones.
1694 lpfc_rscn_disc(struct lpfc_vport *vport)
1696 lpfc_can_disctmo(vport);
1698 /* RSCN discovery */
1699 /* go thru NPR nodes and issue ELS PLOGIs */
1700 if (vport->fc_npr_cnt)
1701 if (lpfc_els_disc_plogi(vport))
1704 lpfc_end_rscn(vport);
1708 * lpfc_adisc_done - Complete the adisc phase of discovery
1709 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1711 * This function is called when the final ADISC is completed during discovery.
1712 * This function handles clearing link attention or issuing reg_vpi depending
1713 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1715 * This function is called with no locks held.
1718 lpfc_adisc_done(struct lpfc_vport *vport)
1720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1721 struct lpfc_hba *phba = vport->phba;
1724 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1725 * and continue discovery.
1727 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1728 !(vport->fc_flag & FC_RSCN_MODE) &&
1729 (phba->sli_rev < LPFC_SLI_REV4)) {
1730 lpfc_issue_reg_vpi(phba, vport);
1734 * For SLI2, we need to set port_state to READY
1735 * and continue discovery.
1737 if (vport->port_state < LPFC_VPORT_READY) {
1738 /* If we get here, there is nothing to ADISC */
1739 if (vport->port_type == LPFC_PHYSICAL_PORT)
1740 lpfc_issue_clear_la(phba, vport);
1741 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1742 vport->num_disc_nodes = 0;
1743 /* go thru NPR list, issue ELS PLOGIs */
1744 if (vport->fc_npr_cnt)
1745 lpfc_els_disc_plogi(vport);
1746 if (!vport->num_disc_nodes) {
1747 spin_lock_irq(shost->host_lock);
1748 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1749 spin_unlock_irq(shost->host_lock);
1750 lpfc_can_disctmo(vport);
1751 lpfc_end_rscn(vport);
1754 vport->port_state = LPFC_VPORT_READY;
1756 lpfc_rscn_disc(vport);
1760 * lpfc_more_adisc - Issue more adisc as needed
1761 * @vport: pointer to a host virtual N_Port data structure.
1763 * This routine determines whether there are more ndlps on a @vport
1764 * node list need to have Address Discover (ADISC) issued. If so, it will
1765 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1766 * remaining nodes which need to have ADISC sent.
1769 lpfc_more_adisc(struct lpfc_vport *vport)
1773 if (vport->num_disc_nodes)
1774 vport->num_disc_nodes--;
1775 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1776 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1777 "0210 Continue discovery with %d ADISCs to go "
1778 "Data: x%x x%x x%x\n",
1779 vport->num_disc_nodes, vport->fc_adisc_cnt,
1780 vport->fc_flag, vport->port_state);
1781 /* Check to see if there are more ADISCs to be sent */
1782 if (vport->fc_flag & FC_NLP_MORE) {
1783 lpfc_set_disctmo(vport);
1784 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1785 sentadisc = lpfc_els_disc_adisc(vport);
1787 if (!vport->num_disc_nodes)
1788 lpfc_adisc_done(vport);
1793 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1794 * @phba: pointer to lpfc hba data structure.
1795 * @cmdiocb: pointer to lpfc command iocb data structure.
1796 * @rspiocb: pointer to lpfc response iocb data structure.
1798 * This routine is the completion function for issuing the Address Discover
1799 * (ADISC) command. It first checks to see whether link went down during
1800 * the discovery process. If so, the node will be marked as node port
1801 * recovery for issuing discover IOCB by the link attention handler and
1802 * exit. Otherwise, the response status is checked. If error was reported
1803 * in the response status, the ADISC command shall be retried by invoking
1804 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1805 * the response status, the state machine is invoked to set transition
1806 * with respect to NLP_EVT_CMPL_ADISC event.
1809 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1810 struct lpfc_iocbq *rspiocb)
1812 struct lpfc_vport *vport = cmdiocb->vport;
1813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1815 struct lpfc_nodelist *ndlp;
1818 /* we pass cmdiocb to state machine which needs rspiocb as well */
1819 cmdiocb->context_un.rsp_iocb = rspiocb;
1821 irsp = &(rspiocb->iocb);
1822 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1825 "ADISC cmpl: status:x%x/x%x did:x%x",
1826 irsp->ulpStatus, irsp->un.ulpWord[4],
1829 /* Since ndlp can be freed in the disc state machine, note if this node
1830 * is being used during discovery.
1832 spin_lock_irq(shost->host_lock);
1833 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1834 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1835 spin_unlock_irq(shost->host_lock);
1836 /* ADISC completes to NPort <nlp_DID> */
1837 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1838 "0104 ADISC completes to NPort x%x "
1839 "Data: x%x x%x x%x x%x x%x\n",
1840 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1841 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1842 /* Check to see if link went down during discovery */
1843 if (lpfc_els_chk_latt(vport)) {
1844 spin_lock_irq(shost->host_lock);
1845 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1846 spin_unlock_irq(shost->host_lock);
1850 if (irsp->ulpStatus) {
1851 /* Check for retry */
1852 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1853 /* ELS command is being retried */
1855 spin_lock_irq(shost->host_lock);
1856 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1857 spin_unlock_irq(shost->host_lock);
1858 lpfc_set_disctmo(vport);
1863 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1864 if (!lpfc_error_lost_link(irsp))
1865 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1866 NLP_EVT_CMPL_ADISC);
1868 /* Good status, call state machine */
1869 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1870 NLP_EVT_CMPL_ADISC);
1872 /* Check to see if there are more ADISCs to be sent */
1873 if (disc && vport->num_disc_nodes)
1874 lpfc_more_adisc(vport);
1876 lpfc_els_free_iocb(phba, cmdiocb);
1881 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
1882 * @vport: pointer to a virtual N_Port data structure.
1883 * @ndlp: pointer to a node-list data structure.
1884 * @retry: number of retries to the command IOCB.
1886 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1887 * @vport. It prepares the payload of the ADISC ELS command, updates the
1888 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1889 * to issue the ADISC ELS command.
1891 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1892 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1893 * will be stored into the context1 field of the IOCB for the completion
1894 * callback function to the ADISC ELS command.
1897 * 0 - successfully issued adisc
1898 * 1 - failed to issue adisc
1901 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1905 struct lpfc_hba *phba = vport->phba;
1908 struct lpfc_iocbq *elsiocb;
1912 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1913 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1914 ndlp->nlp_DID, ELS_CMD_ADISC);
1918 icmd = &elsiocb->iocb;
1919 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1921 /* For ADISC request, remainder of payload is service parameters */
1922 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1923 pcmd += sizeof(uint32_t);
1925 /* Fill in ADISC payload */
1926 ap = (ADISC *) pcmd;
1927 ap->hardAL_PA = phba->fc_pref_ALPA;
1928 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1929 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1930 ap->DID = be32_to_cpu(vport->fc_myDID);
1932 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1933 "Issue ADISC: did:x%x",
1934 ndlp->nlp_DID, 0, 0);
1936 phba->fc_stat.elsXmitADISC++;
1937 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1938 spin_lock_irq(shost->host_lock);
1939 ndlp->nlp_flag |= NLP_ADISC_SND;
1940 spin_unlock_irq(shost->host_lock);
1941 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1943 spin_lock_irq(shost->host_lock);
1944 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1945 spin_unlock_irq(shost->host_lock);
1946 lpfc_els_free_iocb(phba, elsiocb);
1953 * lpfc_cmpl_els_logo - Completion callback function for logo
1954 * @phba: pointer to lpfc hba data structure.
1955 * @cmdiocb: pointer to lpfc command iocb data structure.
1956 * @rspiocb: pointer to lpfc response iocb data structure.
1958 * This routine is the completion function for issuing the ELS Logout (LOGO)
1959 * command. If no error status was reported from the LOGO response, the
1960 * state machine of the associated ndlp shall be invoked for transition with
1961 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1962 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1965 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1966 struct lpfc_iocbq *rspiocb)
1968 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1969 struct lpfc_vport *vport = ndlp->vport;
1970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1972 struct lpfc_sli *psli;
1975 /* we pass cmdiocb to state machine which needs rspiocb as well */
1976 cmdiocb->context_un.rsp_iocb = rspiocb;
1978 irsp = &(rspiocb->iocb);
1979 spin_lock_irq(shost->host_lock);
1980 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1981 spin_unlock_irq(shost->host_lock);
1983 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1984 "LOGO cmpl: status:x%x/x%x did:x%x",
1985 irsp->ulpStatus, irsp->un.ulpWord[4],
1987 /* LOGO completes to NPort <nlp_DID> */
1988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1989 "0105 LOGO completes to NPort x%x "
1990 "Data: x%x x%x x%x x%x\n",
1991 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1992 irsp->ulpTimeout, vport->num_disc_nodes);
1993 /* Check to see if link went down during discovery */
1994 if (lpfc_els_chk_latt(vport))
1997 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1998 /* NLP_EVT_DEVICE_RM should unregister the RPI
1999 * which should abort all outstanding IOs.
2001 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2006 if (irsp->ulpStatus) {
2007 /* Check for retry */
2008 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
2009 /* ELS command is being retried */
2012 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2013 if (lpfc_error_lost_link(irsp))
2016 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2019 /* Good status, call state machine.
2020 * This will unregister the rpi if needed.
2022 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2025 lpfc_els_free_iocb(phba, cmdiocb);
2030 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2031 * @vport: pointer to a virtual N_Port data structure.
2032 * @ndlp: pointer to a node-list data structure.
2033 * @retry: number of retries to the command IOCB.
2035 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2036 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2037 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2038 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2040 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2041 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2042 * will be stored into the context1 field of the IOCB for the completion
2043 * callback function to the LOGO ELS command.
2046 * 0 - successfully issued logo
2047 * 1 - failed to issue logo
2050 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2054 struct lpfc_hba *phba = vport->phba;
2056 struct lpfc_iocbq *elsiocb;
2061 spin_lock_irq(shost->host_lock);
2062 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2063 spin_unlock_irq(shost->host_lock);
2066 spin_unlock_irq(shost->host_lock);
2068 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2069 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2070 ndlp->nlp_DID, ELS_CMD_LOGO);
2074 icmd = &elsiocb->iocb;
2075 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2076 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2077 pcmd += sizeof(uint32_t);
2079 /* Fill in LOGO payload */
2080 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2081 pcmd += sizeof(uint32_t);
2082 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2085 "Issue LOGO: did:x%x",
2086 ndlp->nlp_DID, 0, 0);
2088 phba->fc_stat.elsXmitLOGO++;
2089 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2090 spin_lock_irq(shost->host_lock);
2091 ndlp->nlp_flag |= NLP_LOGO_SND;
2092 spin_unlock_irq(shost->host_lock);
2093 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2095 if (rc == IOCB_ERROR) {
2096 spin_lock_irq(shost->host_lock);
2097 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2098 spin_unlock_irq(shost->host_lock);
2099 lpfc_els_free_iocb(phba, elsiocb);
2106 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2107 * @phba: pointer to lpfc hba data structure.
2108 * @cmdiocb: pointer to lpfc command iocb data structure.
2109 * @rspiocb: pointer to lpfc response iocb data structure.
2111 * This routine is a generic completion callback function for ELS commands.
2112 * Specifically, it is the callback function which does not need to perform
2113 * any command specific operations. It is currently used by the ELS command
2114 * issuing routines for the ELS State Change Request (SCR),
2115 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2116 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2117 * certain debug loggings, this callback function simply invokes the
2118 * lpfc_els_chk_latt() routine to check whether link went down during the
2119 * discovery process.
2122 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2123 struct lpfc_iocbq *rspiocb)
2125 struct lpfc_vport *vport = cmdiocb->vport;
2128 irsp = &rspiocb->iocb;
2130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2131 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2132 irsp->ulpStatus, irsp->un.ulpWord[4],
2133 irsp->un.elsreq64.remoteID);
2134 /* ELS cmd tag <ulpIoTag> completes */
2135 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2136 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2137 irsp->ulpIoTag, irsp->ulpStatus,
2138 irsp->un.ulpWord[4], irsp->ulpTimeout);
2139 /* Check to see if link went down during discovery */
2140 lpfc_els_chk_latt(vport);
2141 lpfc_els_free_iocb(phba, cmdiocb);
2146 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2147 * @vport: pointer to a host virtual N_Port data structure.
2148 * @nportid: N_Port identifier to the remote node.
2149 * @retry: number of retries to the command IOCB.
2151 * This routine issues a State Change Request (SCR) to a fabric node
2152 * on a @vport. The remote node @nportid is passed into the function. It
2153 * first search the @vport node list to find the matching ndlp. If no such
2154 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2155 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2156 * routine is invoked to send the SCR IOCB.
2158 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2159 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2160 * will be stored into the context1 field of the IOCB for the completion
2161 * callback function to the SCR ELS command.
2164 * 0 - Successfully issued scr command
2165 * 1 - Failed to issue scr command
2168 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2170 struct lpfc_hba *phba = vport->phba;
2172 struct lpfc_iocbq *elsiocb;
2173 struct lpfc_sli *psli;
2176 struct lpfc_nodelist *ndlp;
2179 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2181 ndlp = lpfc_findnode_did(vport, nportid);
2183 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2186 lpfc_nlp_init(vport, ndlp, nportid);
2187 lpfc_enqueue_node(vport, ndlp);
2188 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2189 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2194 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2195 ndlp->nlp_DID, ELS_CMD_SCR);
2198 /* This will trigger the release of the node just
2205 icmd = &elsiocb->iocb;
2206 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2208 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2209 pcmd += sizeof(uint32_t);
2211 /* For SCR, remainder of payload is SCR parameter page */
2212 memset(pcmd, 0, sizeof(SCR));
2213 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2215 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2216 "Issue SCR: did:x%x",
2217 ndlp->nlp_DID, 0, 0);
2219 phba->fc_stat.elsXmitSCR++;
2220 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2221 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2223 /* The additional lpfc_nlp_put will cause the following
2224 * lpfc_els_free_iocb routine to trigger the rlease of
2228 lpfc_els_free_iocb(phba, elsiocb);
2231 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2232 * trigger the release of node.
2239 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2240 * @vport: pointer to a host virtual N_Port data structure.
2241 * @nportid: N_Port identifier to the remote node.
2242 * @retry: number of retries to the command IOCB.
2244 * This routine issues a Fibre Channel Address Resolution Response
2245 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2246 * is passed into the function. It first search the @vport node list to find
2247 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2248 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2249 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2251 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2252 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2253 * will be stored into the context1 field of the IOCB for the completion
2254 * callback function to the PARPR ELS command.
2257 * 0 - Successfully issued farpr command
2258 * 1 - Failed to issue farpr command
2261 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2263 struct lpfc_hba *phba = vport->phba;
2265 struct lpfc_iocbq *elsiocb;
2266 struct lpfc_sli *psli;
2271 struct lpfc_nodelist *ondlp;
2272 struct lpfc_nodelist *ndlp;
2275 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2277 ndlp = lpfc_findnode_did(vport, nportid);
2279 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2282 lpfc_nlp_init(vport, ndlp, nportid);
2283 lpfc_enqueue_node(vport, ndlp);
2284 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2285 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2290 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2291 ndlp->nlp_DID, ELS_CMD_RNID);
2293 /* This will trigger the release of the node just
2300 icmd = &elsiocb->iocb;
2301 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2303 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2304 pcmd += sizeof(uint32_t);
2306 /* Fill in FARPR payload */
2307 fp = (FARP *) (pcmd);
2308 memset(fp, 0, sizeof(FARP));
2309 lp = (uint32_t *) pcmd;
2310 *lp++ = be32_to_cpu(nportid);
2311 *lp++ = be32_to_cpu(vport->fc_myDID);
2313 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2315 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2316 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2317 ondlp = lpfc_findnode_did(vport, nportid);
2318 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2319 memcpy(&fp->OportName, &ondlp->nlp_portname,
2320 sizeof(struct lpfc_name));
2321 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2322 sizeof(struct lpfc_name));
2325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2326 "Issue FARPR: did:x%x",
2327 ndlp->nlp_DID, 0, 0);
2329 phba->fc_stat.elsXmitFARPR++;
2330 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2331 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2333 /* The additional lpfc_nlp_put will cause the following
2334 * lpfc_els_free_iocb routine to trigger the release of
2338 lpfc_els_free_iocb(phba, elsiocb);
2341 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2342 * trigger the release of the node.
2349 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2350 * @vport: pointer to a host virtual N_Port data structure.
2351 * @nlp: pointer to a node-list data structure.
2353 * This routine cancels the timer with a delayed IOCB-command retry for
2354 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2355 * removes the ELS retry event if it presents. In addition, if the
2356 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2357 * commands are sent for the @vport's nodes that require issuing discovery
2361 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2364 struct lpfc_work_evt *evtp;
2366 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2368 spin_lock_irq(shost->host_lock);
2369 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2370 spin_unlock_irq(shost->host_lock);
2371 del_timer_sync(&nlp->nlp_delayfunc);
2372 nlp->nlp_last_elscmd = 0;
2373 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2374 list_del_init(&nlp->els_retry_evt.evt_listp);
2375 /* Decrement nlp reference count held for the delayed retry */
2376 evtp = &nlp->els_retry_evt;
2377 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2379 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2380 spin_lock_irq(shost->host_lock);
2381 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2382 spin_unlock_irq(shost->host_lock);
2383 if (vport->num_disc_nodes) {
2384 if (vport->port_state < LPFC_VPORT_READY) {
2385 /* Check if there are more ADISCs to be sent */
2386 lpfc_more_adisc(vport);
2388 /* Check if there are more PLOGIs to be sent */
2389 lpfc_more_plogi(vport);
2390 if (vport->num_disc_nodes == 0) {
2391 spin_lock_irq(shost->host_lock);
2392 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2393 spin_unlock_irq(shost->host_lock);
2394 lpfc_can_disctmo(vport);
2395 lpfc_end_rscn(vport);
2404 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2405 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2407 * This routine is invoked by the ndlp delayed-function timer to check
2408 * whether there is any pending ELS retry event(s) with the node. If not, it
2409 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2410 * adds the delayed events to the HBA work list and invokes the
2411 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2412 * event. Note that lpfc_nlp_get() is called before posting the event to
2413 * the work list to hold reference count of ndlp so that it guarantees the
2414 * reference to ndlp will still be available when the worker thread gets
2415 * to the event associated with the ndlp.
2418 lpfc_els_retry_delay(unsigned long ptr)
2420 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2421 struct lpfc_vport *vport = ndlp->vport;
2422 struct lpfc_hba *phba = vport->phba;
2423 unsigned long flags;
2424 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2426 spin_lock_irqsave(&phba->hbalock, flags);
2427 if (!list_empty(&evtp->evt_listp)) {
2428 spin_unlock_irqrestore(&phba->hbalock, flags);
2432 /* We need to hold the node by incrementing the reference
2433 * count until the queued work is done
2435 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2436 if (evtp->evt_arg1) {
2437 evtp->evt = LPFC_EVT_ELS_RETRY;
2438 list_add_tail(&evtp->evt_listp, &phba->work_list);
2439 lpfc_worker_wake_up(phba);
2441 spin_unlock_irqrestore(&phba->hbalock, flags);
2446 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2447 * @ndlp: pointer to a node-list data structure.
2449 * This routine is the worker-thread handler for processing the @ndlp delayed
2450 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2451 * the last ELS command from the associated ndlp and invokes the proper ELS
2452 * function according to the delayed ELS command to retry the command.
2455 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2457 struct lpfc_vport *vport = ndlp->vport;
2458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2459 uint32_t cmd, did, retry;
2461 spin_lock_irq(shost->host_lock);
2462 did = ndlp->nlp_DID;
2463 cmd = ndlp->nlp_last_elscmd;
2464 ndlp->nlp_last_elscmd = 0;
2466 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2467 spin_unlock_irq(shost->host_lock);
2471 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2472 spin_unlock_irq(shost->host_lock);
2474 * If a discovery event readded nlp_delayfunc after timer
2475 * firing and before processing the timer, cancel the
2478 del_timer_sync(&ndlp->nlp_delayfunc);
2479 retry = ndlp->nlp_retry;
2480 ndlp->nlp_retry = 0;
2484 lpfc_issue_els_flogi(vport, ndlp, retry);
2487 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2488 ndlp->nlp_prev_state = ndlp->nlp_state;
2489 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2493 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2494 ndlp->nlp_prev_state = ndlp->nlp_state;
2495 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2499 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2500 ndlp->nlp_prev_state = ndlp->nlp_state;
2501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2505 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2506 ndlp->nlp_prev_state = ndlp->nlp_state;
2507 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2511 lpfc_issue_els_fdisc(vport, ndlp, retry);
2518 * lpfc_els_retry - Make retry decision on an els command iocb
2519 * @phba: pointer to lpfc hba data structure.
2520 * @cmdiocb: pointer to lpfc command iocb data structure.
2521 * @rspiocb: pointer to lpfc response iocb data structure.
2523 * This routine makes a retry decision on an ELS command IOCB, which has
2524 * failed. The following ELS IOCBs use this function for retrying the command
2525 * when previously issued command responsed with error status: FLOGI, PLOGI,
2526 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2527 * returned error status, it makes the decision whether a retry shall be
2528 * issued for the command, and whether a retry shall be made immediately or
2529 * delayed. In the former case, the corresponding ELS command issuing-function
2530 * is called to retry the command. In the later case, the ELS command shall
2531 * be posted to the ndlp delayed event and delayed function timer set to the
2532 * ndlp for the delayed command issusing.
2535 * 0 - No retry of els command is made
2536 * 1 - Immediate or delayed retry of els command is made
2539 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2540 struct lpfc_iocbq *rspiocb)
2542 struct lpfc_vport *vport = cmdiocb->vport;
2543 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2544 IOCB_t *irsp = &rspiocb->iocb;
2545 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2546 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2549 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2555 /* Note: context2 may be 0 for internal driver abort
2556 * of delays ELS command.
2559 if (pcmd && pcmd->virt) {
2560 elscmd = (uint32_t *) (pcmd->virt);
2564 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2565 did = ndlp->nlp_DID;
2567 /* We should only hit this case for retrying PLOGI */
2568 did = irsp->un.elsreq64.remoteID;
2569 ndlp = lpfc_findnode_did(vport, did);
2570 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2571 && (cmd != ELS_CMD_PLOGI))
2575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2576 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2577 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2579 switch (irsp->ulpStatus) {
2580 case IOSTAT_FCP_RSP_ERROR:
2581 case IOSTAT_REMOTE_STOP:
2584 case IOSTAT_LOCAL_REJECT:
2585 switch ((irsp->un.ulpWord[4] & 0xff)) {
2586 case IOERR_LOOP_OPEN_FAILURE:
2587 if (cmd == ELS_CMD_FLOGI) {
2588 if (PCI_DEVICE_ID_HORNET ==
2589 phba->pcidev->device) {
2590 phba->fc_topology = TOPOLOGY_LOOP;
2591 phba->pport->fc_myDID = 0;
2592 phba->alpa_map[0] = 0;
2593 phba->alpa_map[1] = 0;
2596 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2601 case IOERR_ILLEGAL_COMMAND:
2602 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2603 "0124 Retry illegal cmd x%x "
2604 "retry:x%x delay:x%x\n",
2605 cmd, cmdiocb->retry, delay);
2607 /* All command's retry policy */
2609 if (cmdiocb->retry > 2)
2613 case IOERR_NO_RESOURCES:
2614 logerr = 1; /* HBA out of resources */
2616 if (cmdiocb->retry > 100)
2621 case IOERR_ILLEGAL_FRAME:
2626 case IOERR_SEQUENCE_TIMEOUT:
2627 case IOERR_INVALID_RPI:
2633 case IOSTAT_NPORT_RJT:
2634 case IOSTAT_FABRIC_RJT:
2635 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2641 case IOSTAT_NPORT_BSY:
2642 case IOSTAT_FABRIC_BSY:
2643 logerr = 1; /* Fabric / Remote NPort out of resources */
2648 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2649 /* Added for Vendor specifc support
2650 * Just keep retrying for these Rsn / Exp codes
2652 switch (stat.un.b.lsRjtRsnCode) {
2653 case LSRJT_UNABLE_TPC:
2654 if (stat.un.b.lsRjtRsnCodeExp ==
2655 LSEXP_CMD_IN_PROGRESS) {
2656 if (cmd == ELS_CMD_PLOGI) {
2663 if (cmd == ELS_CMD_PLOGI) {
2665 maxretry = lpfc_max_els_tries + 1;
2669 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2670 (cmd == ELS_CMD_FDISC) &&
2671 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2672 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2673 "0125 FDISC Failed (x%x). "
2674 "Fabric out of resources\n",
2675 stat.un.lsRjtError);
2676 lpfc_vport_set_state(vport,
2677 FC_VPORT_NO_FABRIC_RSCS);
2681 case LSRJT_LOGICAL_BSY:
2682 if ((cmd == ELS_CMD_PLOGI) ||
2683 (cmd == ELS_CMD_PRLI)) {
2686 } else if (cmd == ELS_CMD_FDISC) {
2687 /* FDISC retry policy */
2689 if (cmdiocb->retry >= 32)
2695 case LSRJT_LOGICAL_ERR:
2696 /* There are some cases where switches return this
2697 * error when they are not ready and should be returning
2698 * Logical Busy. We should delay every time.
2700 if (cmd == ELS_CMD_FDISC &&
2701 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2707 case LSRJT_PROTOCOL_ERR:
2708 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2709 (cmd == ELS_CMD_FDISC) &&
2710 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2711 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2713 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2714 "0122 FDISC Failed (x%x). "
2715 "Fabric Detected Bad WWN\n",
2716 stat.un.lsRjtError);
2717 lpfc_vport_set_state(vport,
2718 FC_VPORT_FABRIC_REJ_WWN);
2724 case IOSTAT_INTERMED_RSP:
2732 if (did == FDMI_DID)
2735 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
2736 (phba->fc_topology != TOPOLOGY_LOOP) &&
2737 !lpfc_error_lost_link(irsp)) {
2738 /* FLOGI retry policy */
2742 if (cmdiocb->retry >= 100)
2744 else if (cmdiocb->retry >= 32)
2749 if (maxretry && (cmdiocb->retry >= maxretry)) {
2750 phba->fc_stat.elsRetryExceeded++;
2754 if ((vport->load_flag & FC_UNLOADING) != 0)
2759 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2760 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2761 "0107 Retry ELS command x%x to remote "
2762 "NPORT x%x Data: x%x x%x\n",
2763 cmd, did, cmdiocb->retry, delay);
2765 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2766 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2767 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2768 /* Don't reset timer for no resources */
2770 /* If discovery / RSCN timer is running, reset it */
2771 if (timer_pending(&vport->fc_disctmo) ||
2772 (vport->fc_flag & FC_RSCN_MODE))
2773 lpfc_set_disctmo(vport);
2776 phba->fc_stat.elsXmitRetry++;
2777 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
2778 phba->fc_stat.elsDelayRetry++;
2779 ndlp->nlp_retry = cmdiocb->retry;
2781 /* delay is specified in milliseconds */
2782 mod_timer(&ndlp->nlp_delayfunc,
2783 jiffies + msecs_to_jiffies(delay));
2784 spin_lock_irq(shost->host_lock);
2785 ndlp->nlp_flag |= NLP_DELAY_TMO;
2786 spin_unlock_irq(shost->host_lock);
2788 ndlp->nlp_prev_state = ndlp->nlp_state;
2789 if (cmd == ELS_CMD_PRLI)
2790 lpfc_nlp_set_state(vport, ndlp,
2791 NLP_STE_REG_LOGIN_ISSUE);
2793 lpfc_nlp_set_state(vport, ndlp,
2795 ndlp->nlp_last_elscmd = cmd;
2801 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2804 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2807 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2808 ndlp->nlp_prev_state = ndlp->nlp_state;
2809 lpfc_nlp_set_state(vport, ndlp,
2810 NLP_STE_PLOGI_ISSUE);
2812 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2815 ndlp->nlp_prev_state = ndlp->nlp_state;
2816 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2817 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2820 ndlp->nlp_prev_state = ndlp->nlp_state;
2821 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2822 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2825 ndlp->nlp_prev_state = ndlp->nlp_state;
2826 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2827 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2831 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2833 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2834 "0137 No retry ELS command x%x to remote "
2835 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2836 cmd, did, irsp->ulpStatus,
2837 irsp->un.ulpWord[4]);
2840 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2841 "0108 No retry ELS command x%x to remote "
2842 "NPORT x%x Retried:%d Error:x%x/%x\n",
2843 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2844 irsp->un.ulpWord[4]);
2850 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
2851 * @phba: pointer to lpfc hba data structure.
2852 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2854 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2855 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2856 * checks to see whether there is a lpfc DMA buffer associated with the
2857 * response of the command IOCB. If so, it will be released before releasing
2858 * the lpfc DMA buffer associated with the IOCB itself.
2861 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2864 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2866 struct lpfc_dmabuf *buf_ptr;
2868 /* Free the response before processing the command. */
2869 if (!list_empty(&buf_ptr1->list)) {
2870 list_remove_head(&buf_ptr1->list, buf_ptr,
2873 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2876 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2882 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
2883 * @phba: pointer to lpfc hba data structure.
2884 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2886 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2887 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2891 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2894 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2896 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2902 * lpfc_els_free_iocb - Free a command iocb and its associated resources
2903 * @phba: pointer to lpfc hba data structure.
2904 * @elsiocb: pointer to lpfc els command iocb data structure.
2906 * This routine frees a command IOCB and its associated resources. The
2907 * command IOCB data structure contains the reference to various associated
2908 * resources, these fields must be set to NULL if the associated reference
2910 * context1 - reference to ndlp
2911 * context2 - reference to cmd
2912 * context2->next - reference to rsp
2913 * context3 - reference to bpl
2915 * It first properly decrements the reference count held on ndlp for the
2916 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2917 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2918 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2919 * adds the DMA buffer the @phba data structure for the delayed release.
2920 * If reference to the Buffer Pointer List (BPL) is present, the
2921 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2922 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2923 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2926 * 0 - Success (currently, always return 0)
2929 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2931 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2932 struct lpfc_nodelist *ndlp;
2934 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2936 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2939 /* If the ndlp is not being used by another discovery
2942 if (!lpfc_nlp_not_used(ndlp)) {
2943 /* If ndlp is being used by another discovery
2944 * thread, just clear NLP_DEFER_RM
2946 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2951 elsiocb->context1 = NULL;
2953 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2954 if (elsiocb->context2) {
2955 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2956 /* Firmware could still be in progress of DMAing
2957 * payload, so don't free data buffer till after
2960 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2961 buf_ptr = elsiocb->context2;
2962 elsiocb->context2 = NULL;
2965 spin_lock_irq(&phba->hbalock);
2966 if (!list_empty(&buf_ptr->list)) {
2967 list_remove_head(&buf_ptr->list,
2968 buf_ptr1, struct lpfc_dmabuf,
2970 INIT_LIST_HEAD(&buf_ptr1->list);
2971 list_add_tail(&buf_ptr1->list,
2975 INIT_LIST_HEAD(&buf_ptr->list);
2976 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2978 spin_unlock_irq(&phba->hbalock);
2981 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2982 lpfc_els_free_data(phba, buf_ptr1);
2986 if (elsiocb->context3) {
2987 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2988 lpfc_els_free_bpl(phba, buf_ptr);
2990 lpfc_sli_release_iocbq(phba, elsiocb);
2995 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
2996 * @phba: pointer to lpfc hba data structure.
2997 * @cmdiocb: pointer to lpfc command iocb data structure.
2998 * @rspiocb: pointer to lpfc response iocb data structure.
3000 * This routine is the completion callback function to the Logout (LOGO)
3001 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3002 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3003 * release the ndlp if it has the last reference remaining (reference count
3004 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3005 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3006 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3007 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3008 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3009 * IOCB data structure.
3012 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3013 struct lpfc_iocbq *rspiocb)
3015 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3016 struct lpfc_vport *vport = cmdiocb->vport;
3019 irsp = &rspiocb->iocb;
3020 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3021 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3022 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3023 /* ACC to LOGO completes to NPort <nlp_DID> */
3024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3025 "0109 ACC to LOGO completes to NPort x%x "
3026 "Data: x%x x%x x%x\n",
3027 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3030 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3031 /* NPort Recovery mode or node is just allocated */
3032 if (!lpfc_nlp_not_used(ndlp)) {
3033 /* If the ndlp is being used by another discovery
3034 * thread, just unregister the RPI.
3036 lpfc_unreg_rpi(vport, ndlp);
3038 /* Indicate the node has already released, should
3039 * not reference to it from within lpfc_els_free_iocb.
3041 cmdiocb->context1 = NULL;
3044 lpfc_els_free_iocb(phba, cmdiocb);
3049 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3050 * @phba: pointer to lpfc hba data structure.
3051 * @pmb: pointer to the driver internal queue element for mailbox command.
3053 * This routine is the completion callback function for unregister default
3054 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3055 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3056 * decrements the ndlp reference count held for this completion callback
3057 * function. After that, it invokes the lpfc_nlp_not_used() to check
3058 * whether there is only one reference left on the ndlp. If so, it will
3059 * perform one more decrement and trigger the release of the ndlp.
3062 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3064 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3065 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3068 * This routine is used to register and unregister in previous SLI
3071 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3072 (phba->sli_rev == LPFC_SLI_REV4))
3073 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3075 pmb->context1 = NULL;
3076 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3078 mempool_free(pmb, phba->mbox_mem_pool);
3079 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3081 /* This is the end of the default RPI cleanup logic for this
3082 * ndlp. If no other discovery threads are using this ndlp.
3083 * we should free all resources associated with it.
3085 lpfc_nlp_not_used(ndlp);
3092 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3093 * @phba: pointer to lpfc hba data structure.
3094 * @cmdiocb: pointer to lpfc command iocb data structure.
3095 * @rspiocb: pointer to lpfc response iocb data structure.
3097 * This routine is the completion callback function for ELS Response IOCB
3098 * command. In normal case, this callback function just properly sets the
3099 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3100 * field in the command IOCB is not NULL, the referred mailbox command will
3101 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3102 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3103 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3104 * routine shall be invoked trying to release the ndlp if no other threads
3105 * are currently referring it.
3108 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3109 struct lpfc_iocbq *rspiocb)
3111 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3112 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3113 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3116 LPFC_MBOXQ_t *mbox = NULL;
3117 struct lpfc_dmabuf *mp = NULL;
3118 uint32_t ls_rjt = 0;
3120 irsp = &rspiocb->iocb;
3122 if (cmdiocb->context_un.mbox)
3123 mbox = cmdiocb->context_un.mbox;
3125 /* First determine if this is a LS_RJT cmpl. Note, this callback
3126 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3128 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3129 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3130 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3131 /* A LS_RJT associated with Default RPI cleanup has its own
3132 * separate code path.
3134 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3138 /* Check to see if link went down during discovery */
3139 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3141 mp = (struct lpfc_dmabuf *) mbox->context1;
3143 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3146 mempool_free(mbox, phba->mbox_mem_pool);
3148 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3149 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3150 if (lpfc_nlp_not_used(ndlp)) {
3152 /* Indicate the node has already released,
3153 * should not reference to it from within
3154 * the routine lpfc_els_free_iocb.
3156 cmdiocb->context1 = NULL;
3161 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3162 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3163 irsp->ulpStatus, irsp->un.ulpWord[4],
3164 cmdiocb->iocb.un.elsreq64.remoteID);
3165 /* ELS response tag <ulpIoTag> completes */
3166 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3167 "0110 ELS response tag x%x completes "
3168 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3169 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3170 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3171 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3174 if ((rspiocb->iocb.ulpStatus == 0)
3175 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3176 lpfc_unreg_rpi(vport, ndlp);
3177 /* Increment reference count to ndlp to hold the
3178 * reference to ndlp for the callback function.
3180 mbox->context2 = lpfc_nlp_get(ndlp);
3181 mbox->vport = vport;
3182 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3183 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3184 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3187 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3188 ndlp->nlp_prev_state = ndlp->nlp_state;
3189 lpfc_nlp_set_state(vport, ndlp,
3190 NLP_STE_REG_LOGIN_ISSUE);
3192 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3193 != MBX_NOT_FINISHED)
3196 /* Decrement the ndlp reference count we
3197 * set for this failed mailbox command.
3201 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3202 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3203 "0138 ELS rsp: Cannot issue reg_login for x%x "
3204 "Data: x%x x%x x%x\n",
3205 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3208 if (lpfc_nlp_not_used(ndlp)) {
3210 /* Indicate node has already been released,
3211 * should not reference to it from within
3212 * the routine lpfc_els_free_iocb.
3214 cmdiocb->context1 = NULL;
3217 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3218 if (!lpfc_error_lost_link(irsp) &&
3219 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3220 if (lpfc_nlp_not_used(ndlp)) {
3222 /* Indicate node has already been
3223 * released, should not reference
3224 * to it from within the routine
3225 * lpfc_els_free_iocb.
3227 cmdiocb->context1 = NULL;
3231 mp = (struct lpfc_dmabuf *) mbox->context1;
3233 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3236 mempool_free(mbox, phba->mbox_mem_pool);
3239 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3240 spin_lock_irq(shost->host_lock);
3241 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3242 spin_unlock_irq(shost->host_lock);
3244 /* If the node is not being used by another discovery thread,
3245 * and we are sending a reject, we are done with it.
3246 * Release driver reference count here and free associated
3250 if (lpfc_nlp_not_used(ndlp))
3251 /* Indicate node has already been released,
3252 * should not reference to it from within
3253 * the routine lpfc_els_free_iocb.
3255 cmdiocb->context1 = NULL;
3258 lpfc_els_free_iocb(phba, cmdiocb);
3263 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3264 * @vport: pointer to a host virtual N_Port data structure.
3265 * @flag: the els command code to be accepted.
3266 * @oldiocb: pointer to the original lpfc command iocb data structure.
3267 * @ndlp: pointer to a node-list data structure.
3268 * @mbox: pointer to the driver internal queue element for mailbox command.
3270 * This routine prepares and issues an Accept (ACC) response IOCB
3271 * command. It uses the @flag to properly set up the IOCB field for the
3272 * specific ACC response command to be issued and invokes the
3273 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3274 * @mbox pointer is passed in, it will be put into the context_un.mbox
3275 * field of the IOCB for the completion callback function to issue the
3276 * mailbox command to the HBA later when callback is invoked.
3278 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3279 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3280 * will be stored into the context1 field of the IOCB for the completion
3281 * callback function to the corresponding response ELS IOCB command.
3284 * 0 - Successfully issued acc response
3285 * 1 - Failed to issue acc response
3288 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3289 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3293 struct lpfc_hba *phba = vport->phba;
3296 struct lpfc_iocbq *elsiocb;
3297 struct lpfc_sli *psli;
3301 ELS_PKT *els_pkt_ptr;
3304 oldcmd = &oldiocb->iocb;
3308 cmdsize = sizeof(uint32_t);
3309 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3310 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3312 spin_lock_irq(shost->host_lock);
3313 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3314 spin_unlock_irq(shost->host_lock);
3318 icmd = &elsiocb->iocb;
3319 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3320 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3321 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3322 pcmd += sizeof(uint32_t);
3324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3325 "Issue ACC: did:x%x flg:x%x",
3326 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3329 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3330 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3331 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3335 icmd = &elsiocb->iocb;
3336 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3337 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3340 elsiocb->context_un.mbox = mbox;
3342 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3343 pcmd += sizeof(uint32_t);
3344 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3347 "Issue ACC PLOGI: did:x%x flg:x%x",
3348 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3351 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3352 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3353 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3357 icmd = &elsiocb->iocb;
3358 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3359 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3361 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3362 sizeof(uint32_t) + sizeof(PRLO));
3363 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3364 els_pkt_ptr = (ELS_PKT *) pcmd;
3365 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3367 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3368 "Issue ACC PRLO: did:x%x flg:x%x",
3369 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3374 /* Xmit ELS ACC response tag <ulpIoTag> */
3375 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3376 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3377 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3378 elsiocb->iotag, elsiocb->iocb.ulpContext,
3379 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3381 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3382 spin_lock_irq(shost->host_lock);
3383 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3384 spin_unlock_irq(shost->host_lock);
3385 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3387 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3390 phba->fc_stat.elsXmitACC++;
3391 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3392 if (rc == IOCB_ERROR) {
3393 lpfc_els_free_iocb(phba, elsiocb);
3400 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3401 * @vport: pointer to a virtual N_Port data structure.
3403 * @oldiocb: pointer to the original lpfc command iocb data structure.
3404 * @ndlp: pointer to a node-list data structure.
3405 * @mbox: pointer to the driver internal queue element for mailbox command.
3407 * This routine prepares and issue an Reject (RJT) response IOCB
3408 * command. If a @mbox pointer is passed in, it will be put into the
3409 * context_un.mbox field of the IOCB for the completion callback function
3410 * to issue to the HBA later.
3412 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3413 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3414 * will be stored into the context1 field of the IOCB for the completion
3415 * callback function to the reject response ELS IOCB command.
3418 * 0 - Successfully issued reject response
3419 * 1 - Failed to issue reject response
3422 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3423 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3426 struct lpfc_hba *phba = vport->phba;
3429 struct lpfc_iocbq *elsiocb;
3430 struct lpfc_sli *psli;
3436 cmdsize = 2 * sizeof(uint32_t);
3437 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3438 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3442 icmd = &elsiocb->iocb;
3443 oldcmd = &oldiocb->iocb;
3444 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3445 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3447 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3448 pcmd += sizeof(uint32_t);
3449 *((uint32_t *) (pcmd)) = rejectError;
3452 elsiocb->context_un.mbox = mbox;
3454 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3455 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3456 "0129 Xmit ELS RJT x%x response tag x%x "
3457 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3459 rejectError, elsiocb->iotag,
3460 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3461 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3463 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3464 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3466 phba->fc_stat.elsXmitLSRJT++;
3467 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3468 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3470 if (rc == IOCB_ERROR) {
3471 lpfc_els_free_iocb(phba, elsiocb);
3478 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3479 * @vport: pointer to a virtual N_Port data structure.
3480 * @oldiocb: pointer to the original lpfc command iocb data structure.
3481 * @ndlp: pointer to a node-list data structure.
3483 * This routine prepares and issues an Accept (ACC) response to Address
3484 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3485 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3489 * will be stored into the context1 field of the IOCB for the completion
3490 * callback function to the ADISC Accept response ELS IOCB command.
3493 * 0 - Successfully issued acc adisc response
3494 * 1 - Failed to issue adisc acc response
3497 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3498 struct lpfc_nodelist *ndlp)
3500 struct lpfc_hba *phba = vport->phba;
3502 IOCB_t *icmd, *oldcmd;
3503 struct lpfc_iocbq *elsiocb;
3508 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3509 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3510 ndlp->nlp_DID, ELS_CMD_ACC);
3514 icmd = &elsiocb->iocb;
3515 oldcmd = &oldiocb->iocb;
3516 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3518 /* Xmit ADISC ACC response tag <ulpIoTag> */
3519 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3520 "0130 Xmit ADISC ACC response iotag x%x xri: "
3521 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3522 elsiocb->iotag, elsiocb->iocb.ulpContext,
3523 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3525 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3527 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3528 pcmd += sizeof(uint32_t);
3530 ap = (ADISC *) (pcmd);
3531 ap->hardAL_PA = phba->fc_pref_ALPA;
3532 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3533 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3534 ap->DID = be32_to_cpu(vport->fc_myDID);
3536 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3537 "Issue ACC ADISC: did:x%x flg:x%x",
3538 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3540 phba->fc_stat.elsXmitACC++;
3541 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3542 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3543 if (rc == IOCB_ERROR) {
3544 lpfc_els_free_iocb(phba, elsiocb);
3551 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3552 * @vport: pointer to a virtual N_Port data structure.
3553 * @oldiocb: pointer to the original lpfc command iocb data structure.
3554 * @ndlp: pointer to a node-list data structure.
3556 * This routine prepares and issues an Accept (ACC) response to Process
3557 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3558 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3560 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3561 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3562 * will be stored into the context1 field of the IOCB for the completion
3563 * callback function to the PRLI Accept response ELS IOCB command.
3566 * 0 - Successfully issued acc prli response
3567 * 1 - Failed to issue acc prli response
3570 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3571 struct lpfc_nodelist *ndlp)
3573 struct lpfc_hba *phba = vport->phba;
3578 struct lpfc_iocbq *elsiocb;
3579 struct lpfc_sli *psli;
3586 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3587 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3588 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3592 icmd = &elsiocb->iocb;
3593 oldcmd = &oldiocb->iocb;
3594 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3595 /* Xmit PRLI ACC response tag <ulpIoTag> */
3596 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3597 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3598 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3599 elsiocb->iotag, elsiocb->iocb.ulpContext,
3600 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3604 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3605 pcmd += sizeof(uint32_t);
3607 /* For PRLI, remainder of payload is PRLI parameter page */
3608 memset(pcmd, 0, sizeof(PRLI));
3610 npr = (PRLI *) pcmd;
3613 * If the remote port is a target and our firmware version is 3.20 or
3614 * later, set the following bits for FC-TAPE support.
3616 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3617 (vpd->rev.feaLevelHigh >= 0x02)) {
3618 npr->ConfmComplAllowed = 1;
3620 npr->TaskRetryIdReq = 1;
3623 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3624 npr->estabImagePair = 1;
3625 npr->readXferRdyDis = 1;
3626 npr->ConfmComplAllowed = 1;
3628 npr->prliType = PRLI_FCP_TYPE;
3629 npr->initiatorFunc = 1;
3631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3632 "Issue ACC PRLI: did:x%x flg:x%x",
3633 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3635 phba->fc_stat.elsXmitACC++;
3636 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3638 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3639 if (rc == IOCB_ERROR) {
3640 lpfc_els_free_iocb(phba, elsiocb);
3647 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3648 * @vport: pointer to a virtual N_Port data structure.
3649 * @format: rnid command format.
3650 * @oldiocb: pointer to the original lpfc command iocb data structure.
3651 * @ndlp: pointer to a node-list data structure.
3653 * This routine issues a Request Node Identification Data (RNID) Accept
3654 * (ACC) response. It constructs the RNID ACC response command according to
3655 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3656 * issue the response. Note that this command does not need to hold the ndlp
3657 * reference count for the callback. So, the ndlp reference count taken by
3658 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3659 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3660 * there is no ndlp reference available.
3662 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3663 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3664 * will be stored into the context1 field of the IOCB for the completion
3665 * callback function. However, for the RNID Accept Response ELS command,
3666 * this is undone later by this routine after the IOCB is allocated.
3669 * 0 - Successfully issued acc rnid response
3670 * 1 - Failed to issue acc rnid response
3673 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3674 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3676 struct lpfc_hba *phba = vport->phba;
3678 IOCB_t *icmd, *oldcmd;
3679 struct lpfc_iocbq *elsiocb;
3680 struct lpfc_sli *psli;
3686 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3687 + (2 * sizeof(struct lpfc_name));
3689 cmdsize += sizeof(RNID_TOP_DISC);
3691 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3692 ndlp->nlp_DID, ELS_CMD_ACC);
3696 icmd = &elsiocb->iocb;
3697 oldcmd = &oldiocb->iocb;
3698 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3699 /* Xmit RNID ACC response tag <ulpIoTag> */
3700 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3701 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3702 elsiocb->iotag, elsiocb->iocb.ulpContext);
3703 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3704 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3705 pcmd += sizeof(uint32_t);
3707 memset(pcmd, 0, sizeof(RNID));
3708 rn = (RNID *) (pcmd);
3709 rn->Format = format;
3710 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3711 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3712 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3715 rn->SpecificLen = 0;
3717 case RNID_TOPOLOGY_DISC:
3718 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3719 memcpy(&rn->un.topologyDisc.portName,
3720 &vport->fc_portname, sizeof(struct lpfc_name));
3721 rn->un.topologyDisc.unitType = RNID_HBA;
3722 rn->un.topologyDisc.physPort = 0;
3723 rn->un.topologyDisc.attachedNodes = 0;
3727 rn->SpecificLen = 0;
3731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3732 "Issue ACC RNID: did:x%x flg:x%x",
3733 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3735 phba->fc_stat.elsXmitACC++;
3736 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3738 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3739 * it could be freed */
3741 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3742 if (rc == IOCB_ERROR) {
3743 lpfc_els_free_iocb(phba, elsiocb);
3750 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3751 * @vport: pointer to a host virtual N_Port data structure.
3753 * This routine issues Address Discover (ADISC) ELS commands to those
3754 * N_Ports which are in node port recovery state and ADISC has not been issued
3755 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3756 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3757 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3758 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3759 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3760 * IOCBs quit for later pick up. On the other hand, after walking through
3761 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3762 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3763 * no more ADISC need to be sent.
3766 * The number of N_Ports with adisc issued.
3769 lpfc_els_disc_adisc(struct lpfc_vport *vport)
3771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3772 struct lpfc_nodelist *ndlp, *next_ndlp;
3775 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3776 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3777 if (!NLP_CHK_NODE_ACT(ndlp))
3779 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3780 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3781 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
3782 spin_lock_irq(shost->host_lock);
3783 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3784 spin_unlock_irq(shost->host_lock);
3785 ndlp->nlp_prev_state = ndlp->nlp_state;
3786 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3787 lpfc_issue_els_adisc(vport, ndlp, 0);
3789 vport->num_disc_nodes++;
3790 if (vport->num_disc_nodes >=
3791 vport->cfg_discovery_threads) {
3792 spin_lock_irq(shost->host_lock);
3793 vport->fc_flag |= FC_NLP_MORE;
3794 spin_unlock_irq(shost->host_lock);
3799 if (sentadisc == 0) {
3800 spin_lock_irq(shost->host_lock);
3801 vport->fc_flag &= ~FC_NLP_MORE;
3802 spin_unlock_irq(shost->host_lock);
3808 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
3809 * @vport: pointer to a host virtual N_Port data structure.
3811 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3812 * which are in node port recovery state, with a @vport. Each time an ELS
3813 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3814 * the per @vport number of discover count (num_disc_nodes) shall be
3815 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3816 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3817 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3818 * later pick up. On the other hand, after walking through all the ndlps with
3819 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3820 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3821 * PLOGI need to be sent.
3824 * The number of N_Ports with plogi issued.
3827 lpfc_els_disc_plogi(struct lpfc_vport *vport)
3829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3830 struct lpfc_nodelist *ndlp, *next_ndlp;
3833 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3834 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3835 if (!NLP_CHK_NODE_ACT(ndlp))
3837 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3838 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3839 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3840 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3841 ndlp->nlp_prev_state = ndlp->nlp_state;
3842 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3843 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3845 vport->num_disc_nodes++;
3846 if (vport->num_disc_nodes >=
3847 vport->cfg_discovery_threads) {
3848 spin_lock_irq(shost->host_lock);
3849 vport->fc_flag |= FC_NLP_MORE;
3850 spin_unlock_irq(shost->host_lock);
3856 lpfc_set_disctmo(vport);
3859 spin_lock_irq(shost->host_lock);
3860 vport->fc_flag &= ~FC_NLP_MORE;
3861 spin_unlock_irq(shost->host_lock);
3867 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
3868 * @vport: pointer to a host virtual N_Port data structure.
3870 * This routine cleans up any Registration State Change Notification
3871 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3872 * @vport together with the host_lock is used to prevent multiple thread
3873 * trying to access the RSCN array on a same @vport at the same time.
3876 lpfc_els_flush_rscn(struct lpfc_vport *vport)
3878 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3879 struct lpfc_hba *phba = vport->phba;
3882 spin_lock_irq(shost->host_lock);
3883 if (vport->fc_rscn_flush) {
3884 /* Another thread is walking fc_rscn_id_list on this vport */
3885 spin_unlock_irq(shost->host_lock);
3888 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3889 vport->fc_rscn_flush = 1;
3890 spin_unlock_irq(shost->host_lock);
3892 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3893 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
3894 vport->fc_rscn_id_list[i] = NULL;
3896 spin_lock_irq(shost->host_lock);
3897 vport->fc_rscn_id_cnt = 0;
3898 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3899 spin_unlock_irq(shost->host_lock);
3900 lpfc_can_disctmo(vport);
3901 /* Indicate we are done walking this fc_rscn_id_list */
3902 vport->fc_rscn_flush = 0;
3906 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
3907 * @vport: pointer to a host virtual N_Port data structure.
3908 * @did: remote destination port identifier.
3910 * This routine checks whether there is any pending Registration State
3911 * Configuration Notification (RSCN) to a @did on @vport.
3914 * None zero - The @did matched with a pending rscn
3915 * 0 - not able to match @did with a pending rscn
3918 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
3923 uint32_t payload_len, i;
3924 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3926 ns_did.un.word = did;
3928 /* Never match fabric nodes for RSCNs */
3929 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
3932 /* If we are doing a FULL RSCN rediscovery, match everything */
3933 if (vport->fc_flag & FC_RSCN_DISCOVERY)
3936 spin_lock_irq(shost->host_lock);
3937 if (vport->fc_rscn_flush) {
3938 /* Another thread is walking fc_rscn_id_list on this vport */
3939 spin_unlock_irq(shost->host_lock);
3942 /* Indicate we are walking fc_rscn_id_list on this vport */
3943 vport->fc_rscn_flush = 1;
3944 spin_unlock_irq(shost->host_lock);
3945 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
3946 lp = vport->fc_rscn_id_list[i]->virt;
3947 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3948 payload_len -= sizeof(uint32_t); /* take off word 0 */
3949 while (payload_len) {
3950 rscn_did.un.word = be32_to_cpu(*lp++);
3951 payload_len -= sizeof(uint32_t);
3952 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3953 case RSCN_ADDRESS_FORMAT_PORT:
3954 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3955 && (ns_did.un.b.area == rscn_did.un.b.area)
3956 && (ns_did.un.b.id == rscn_did.un.b.id))
3957 goto return_did_out;
3959 case RSCN_ADDRESS_FORMAT_AREA:
3960 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3961 && (ns_did.un.b.area == rscn_did.un.b.area))
3962 goto return_did_out;
3964 case RSCN_ADDRESS_FORMAT_DOMAIN:
3965 if (ns_did.un.b.domain == rscn_did.un.b.domain)
3966 goto return_did_out;
3968 case RSCN_ADDRESS_FORMAT_FABRIC:
3969 goto return_did_out;
3973 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3974 vport->fc_rscn_flush = 0;
3977 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3978 vport->fc_rscn_flush = 0;
3983 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
3984 * @vport: pointer to a host virtual N_Port data structure.
3986 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3987 * state machine for a @vport's nodes that are with pending RSCN (Registration
3988 * State Change Notification).
3991 * 0 - Successful (currently alway return 0)
3994 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
3996 struct lpfc_nodelist *ndlp = NULL;
3998 /* Move all affected nodes by pending RSCNs to NPR state. */
3999 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4000 if (!NLP_CHK_NODE_ACT(ndlp) ||
4001 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4002 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
4004 lpfc_disc_state_machine(vport, ndlp, NULL,
4005 NLP_EVT_DEVICE_RECOVERY);
4006 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4012 * lpfc_send_rscn_event - Send an RSCN event to management application
4013 * @vport: pointer to a host virtual N_Port data structure.
4014 * @cmdiocb: pointer to lpfc command iocb data structure.
4016 * lpfc_send_rscn_event sends an RSCN netlink event to management
4020 lpfc_send_rscn_event(struct lpfc_vport *vport,
4021 struct lpfc_iocbq *cmdiocb)
4023 struct lpfc_dmabuf *pcmd;
4024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4025 uint32_t *payload_ptr;
4026 uint32_t payload_len;
4027 struct lpfc_rscn_event_header *rscn_event_data;
4029 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4030 payload_ptr = (uint32_t *) pcmd->virt;
4031 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4033 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4034 payload_len, GFP_KERNEL);
4035 if (!rscn_event_data) {
4036 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4037 "0147 Failed to allocate memory for RSCN event\n");
4040 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4041 rscn_event_data->payload_length = payload_len;
4042 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4045 fc_host_post_vendor_event(shost,
4046 fc_get_event_number(),
4047 sizeof(struct lpfc_els_event_header) + payload_len,
4048 (char *)rscn_event_data,
4051 kfree(rscn_event_data);
4055 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4056 * @vport: pointer to a host virtual N_Port data structure.
4057 * @cmdiocb: pointer to lpfc command iocb data structure.
4058 * @ndlp: pointer to a node-list data structure.
4060 * This routine processes an unsolicited RSCN (Registration State Change
4061 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4062 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4063 * discover state machine is about to begin discovery, it just accepts the
4064 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4065 * contains N_Port IDs for other vports on this HBA, it just accepts the
4066 * RSCN and ignore processing it. If the state machine is in the recovery
4067 * state, the fc_rscn_id_list of this @vport is walked and the
4068 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4069 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4070 * routine is invoked to handle the RSCN event.
4073 * 0 - Just sent the acc response
4074 * 1 - Sent the acc response and waited for name server completion
4077 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4078 struct lpfc_nodelist *ndlp)
4080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4081 struct lpfc_hba *phba = vport->phba;
4082 struct lpfc_dmabuf *pcmd;
4083 uint32_t *lp, *datap;
4085 uint32_t payload_len, length, nportid, *cmd;
4087 int rscn_id = 0, hba_id = 0;
4090 icmd = &cmdiocb->iocb;
4091 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4092 lp = (uint32_t *) pcmd->virt;
4094 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4095 payload_len -= sizeof(uint32_t); /* take off word 0 */
4097 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4098 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4099 vport->fc_flag, payload_len, *lp,
4100 vport->fc_rscn_id_cnt);
4102 /* Send an RSCN event to the management application */
4103 lpfc_send_rscn_event(vport, cmdiocb);
4105 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
4106 fc_host_post_event(shost, fc_get_event_number(),
4107 FCH_EVT_RSCN, lp[i]);
4109 /* If we are about to begin discovery, just ACC the RSCN.
4110 * Discovery processing will satisfy it.
4112 if (vport->port_state <= LPFC_NS_QRY) {
4113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4114 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4115 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4117 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4121 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4122 * just ACC and ignore it.
4124 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4125 !(vport->cfg_peer_port_login)) {
4130 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4131 i -= sizeof(uint32_t);
4133 if (lpfc_find_vport_by_did(phba, nportid))
4136 if (rscn_id == hba_id) {
4137 /* ALL NPortIDs in RSCN are on HBA */
4138 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4140 "Data: x%x x%x x%x x%x\n",
4141 vport->fc_flag, payload_len,
4142 *lp, vport->fc_rscn_id_cnt);
4143 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4144 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4145 ndlp->nlp_DID, vport->port_state,
4148 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4154 spin_lock_irq(shost->host_lock);
4155 if (vport->fc_rscn_flush) {
4156 /* Another thread is walking fc_rscn_id_list on this vport */
4157 vport->fc_flag |= FC_RSCN_DISCOVERY;
4158 spin_unlock_irq(shost->host_lock);
4160 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4163 /* Indicate we are walking fc_rscn_id_list on this vport */
4164 vport->fc_rscn_flush = 1;
4165 spin_unlock_irq(shost->host_lock);
4166 /* Get the array count after successfully have the token */
4167 rscn_cnt = vport->fc_rscn_id_cnt;
4168 /* If we are already processing an RSCN, save the received
4169 * RSCN payload buffer, cmdiocb->context2 to process later.
4171 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4173 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4174 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4176 spin_lock_irq(shost->host_lock);
4177 vport->fc_flag |= FC_RSCN_DEFERRED;
4178 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4179 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4180 vport->fc_flag |= FC_RSCN_MODE;
4181 spin_unlock_irq(shost->host_lock);
4183 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4184 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4187 (payload_len + length <= LPFC_BPL_SIZE)) {
4188 *cmd &= ELS_CMD_MASK;
4189 *cmd |= cpu_to_be32(payload_len + length);
4190 memcpy(((uint8_t *)cmd) + length, lp,
4193 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4194 vport->fc_rscn_id_cnt++;
4195 /* If we zero, cmdiocb->context2, the calling
4196 * routine will not try to free it.
4198 cmdiocb->context2 = NULL;
4201 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4202 "0235 Deferred RSCN "
4203 "Data: x%x x%x x%x\n",
4204 vport->fc_rscn_id_cnt, vport->fc_flag,
4207 vport->fc_flag |= FC_RSCN_DISCOVERY;
4208 spin_unlock_irq(shost->host_lock);
4209 /* ReDiscovery RSCN */
4210 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4211 "0234 ReDiscovery RSCN "
4212 "Data: x%x x%x x%x\n",
4213 vport->fc_rscn_id_cnt, vport->fc_flag,
4216 /* Indicate we are done walking fc_rscn_id_list on this vport */
4217 vport->fc_rscn_flush = 0;
4219 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4220 /* send RECOVERY event for ALL nodes that match RSCN payload */
4221 lpfc_rscn_recovery_check(vport);
4222 spin_lock_irq(shost->host_lock);
4223 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4224 spin_unlock_irq(shost->host_lock);
4227 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4228 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4229 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4231 spin_lock_irq(shost->host_lock);
4232 vport->fc_flag |= FC_RSCN_MODE;
4233 spin_unlock_irq(shost->host_lock);
4234 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4235 /* Indicate we are done walking fc_rscn_id_list on this vport */
4236 vport->fc_rscn_flush = 0;
4238 * If we zero, cmdiocb->context2, the calling routine will
4239 * not try to free it.
4241 cmdiocb->context2 = NULL;
4242 lpfc_set_disctmo(vport);
4244 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4245 /* send RECOVERY event for ALL nodes that match RSCN payload */
4246 lpfc_rscn_recovery_check(vport);
4247 return lpfc_els_handle_rscn(vport);
4251 * lpfc_els_handle_rscn - Handle rscn for a vport
4252 * @vport: pointer to a host virtual N_Port data structure.
4254 * This routine handles the Registration State Configuration Notification
4255 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4256 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4257 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4258 * NameServer shall be issued. If CT command to the NameServer fails to be
4259 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4260 * RSCN activities with the @vport.
4263 * 0 - Cleaned up rscn on the @vport
4264 * 1 - Wait for plogi to name server before proceed
4267 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4269 struct lpfc_nodelist *ndlp;
4270 struct lpfc_hba *phba = vport->phba;
4272 /* Ignore RSCN if the port is being torn down. */
4273 if (vport->load_flag & FC_UNLOADING) {
4274 lpfc_els_flush_rscn(vport);
4278 /* Start timer for RSCN processing */
4279 lpfc_set_disctmo(vport);
4281 /* RSCN processed */
4282 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4283 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4284 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4287 /* To process RSCN, first compare RSCN data with NameServer */
4288 vport->fc_ns_retry = 0;
4289 vport->num_disc_nodes = 0;
4291 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4292 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4293 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4294 /* Good ndlp, issue CT Request to NameServer */
4295 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4296 /* Wait for NameServer query cmpl before we can
4300 /* If login to NameServer does not exist, issue one */
4301 /* Good status, issue PLOGI to NameServer */
4302 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4303 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4304 /* Wait for NameServer login cmpl before we can
4309 ndlp = lpfc_enable_node(vport, ndlp,
4310 NLP_STE_PLOGI_ISSUE);
4312 lpfc_els_flush_rscn(vport);
4315 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4317 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4319 lpfc_els_flush_rscn(vport);
4322 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4323 ndlp->nlp_prev_state = ndlp->nlp_state;
4324 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4326 ndlp->nlp_type |= NLP_FABRIC;
4327 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4328 /* Wait for NameServer login cmpl before we can
4334 lpfc_els_flush_rscn(vport);
4339 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4340 * @vport: pointer to a host virtual N_Port data structure.
4341 * @cmdiocb: pointer to lpfc command iocb data structure.
4342 * @ndlp: pointer to a node-list data structure.
4344 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4345 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4346 * point topology. As an unsolicited FLOGI should not be received in a loop
4347 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4348 * lpfc_check_sparm() routine is invoked to check the parameters in the
4349 * unsolicited FLOGI. If parameters validation failed, the routine
4350 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4351 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4352 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4353 * will initiate PLOGI. The higher lexicographical value party shall has
4354 * higher priority (as the winning port) and will initiate PLOGI and
4355 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4356 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4357 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4360 * 0 - Successfully processed the unsolicited flogi
4361 * 1 - Failed to process the unsolicited flogi
4364 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4365 struct lpfc_nodelist *ndlp)
4367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4368 struct lpfc_hba *phba = vport->phba;
4369 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4370 uint32_t *lp = (uint32_t *) pcmd->virt;
4371 IOCB_t *icmd = &cmdiocb->iocb;
4372 struct serv_parm *sp;
4379 sp = (struct serv_parm *) lp;
4381 /* FLOGI received */
4383 lpfc_set_disctmo(vport);
4385 if (phba->fc_topology == TOPOLOGY_LOOP) {
4386 /* We should never receive a FLOGI in loop mode, ignore it */
4387 did = icmd->un.elsreq64.remoteID;
4389 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4391 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4392 "0113 An FLOGI ELS command x%x was "
4393 "received from DID x%x in Loop Mode\n",
4400 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
4401 /* For a FLOGI we accept, then if our portname is greater
4402 * then the remote portname we initiate Nport login.
4405 rc = memcmp(&vport->fc_portname, &sp->portName,
4406 sizeof(struct lpfc_name));
4409 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4413 lpfc_linkdown(phba);
4414 lpfc_init_link(phba, mbox,
4416 phba->cfg_link_speed);
4417 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4418 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4419 mbox->vport = vport;
4420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4421 lpfc_set_loopback_flag(phba);
4422 if (rc == MBX_NOT_FINISHED) {
4423 mempool_free(mbox, phba->mbox_mem_pool);
4426 } else if (rc > 0) { /* greater than */
4427 spin_lock_irq(shost->host_lock);
4428 vport->fc_flag |= FC_PT2PT_PLOGI;
4429 spin_unlock_irq(shost->host_lock);
4431 spin_lock_irq(shost->host_lock);
4432 vport->fc_flag |= FC_PT2PT;
4433 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4434 spin_unlock_irq(shost->host_lock);
4436 /* Reject this request because invalid parameters */
4437 stat.un.b.lsRjtRsvd0 = 0;
4438 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4439 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4440 stat.un.b.vendorUnique = 0;
4441 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4447 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4453 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4454 * @vport: pointer to a host virtual N_Port data structure.
4455 * @cmdiocb: pointer to lpfc command iocb data structure.
4456 * @ndlp: pointer to a node-list data structure.
4458 * This routine processes Request Node Identification Data (RNID) IOCB
4459 * received as an ELS unsolicited event. Only when the RNID specified format
4460 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4461 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4462 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4463 * rejected by invoking the lpfc_els_rsp_reject() routine.
4466 * 0 - Successfully processed rnid iocb (currently always return 0)
4469 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4470 struct lpfc_nodelist *ndlp)
4472 struct lpfc_dmabuf *pcmd;
4479 icmd = &cmdiocb->iocb;
4480 did = icmd->un.elsreq64.remoteID;
4481 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4482 lp = (uint32_t *) pcmd->virt;
4489 switch (rn->Format) {
4491 case RNID_TOPOLOGY_DISC:
4493 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4496 /* Reject this request because format not supported */
4497 stat.un.b.lsRjtRsvd0 = 0;
4498 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4499 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4500 stat.un.b.vendorUnique = 0;
4501 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4508 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4509 * @vport: pointer to a host virtual N_Port data structure.
4510 * @cmdiocb: pointer to lpfc command iocb data structure.
4511 * @ndlp: pointer to a node-list data structure.
4513 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4514 * received as an ELS unsolicited event. Currently, this function just invokes
4515 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4518 * 0 - Successfully processed lirr iocb (currently always return 0)
4521 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4522 struct lpfc_nodelist *ndlp)
4526 /* For now, unconditionally reject this command */
4527 stat.un.b.lsRjtRsvd0 = 0;
4528 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4529 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4530 stat.un.b.vendorUnique = 0;
4531 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4536 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4537 * @vport: pointer to a host virtual N_Port data structure.
4538 * @cmdiocb: pointer to lpfc command iocb data structure.
4539 * @ndlp: pointer to a node-list data structure.
4541 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4542 * received as an ELS unsolicited event. A request to RRQ shall only
4543 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4544 * Nx_Port N_Port_ID of the target Exchange is the same as the
4545 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4546 * not accepted, an LS_RJT with reason code "Unable to perform
4547 * command request" and reason code explanation "Invalid Originator
4548 * S_ID" shall be returned. For now, we just unconditionally accept
4549 * RRQ from the target.
4552 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4553 struct lpfc_nodelist *ndlp)
4555 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4559 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4560 * @phba: pointer to lpfc hba data structure.
4561 * @pmb: pointer to the driver internal queue element for mailbox command.
4563 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4564 * mailbox command. This callback function is to actually send the Accept
4565 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4566 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4567 * mailbox command, constructs the RPS response with the link statistics
4568 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4569 * response to the RPS.
4571 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4572 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4573 * will be stored into the context1 field of the IOCB for the completion
4574 * callback function to the RPS Accept Response ELS IOCB command.
4578 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4584 struct lpfc_iocbq *elsiocb;
4585 struct lpfc_nodelist *ndlp;
4586 uint16_t xri, status;
4591 ndlp = (struct lpfc_nodelist *) pmb->context2;
4592 xri = (uint16_t) ((unsigned long)(pmb->context1));
4593 pmb->context1 = NULL;
4594 pmb->context2 = NULL;
4596 if (mb->mbxStatus) {
4597 mempool_free(pmb, phba->mbox_mem_pool);
4601 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
4602 mempool_free(pmb, phba->mbox_mem_pool);
4603 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4604 lpfc_max_els_tries, ndlp,
4605 ndlp->nlp_DID, ELS_CMD_ACC);
4607 /* Decrement the ndlp reference count from previous mbox command */
4613 icmd = &elsiocb->iocb;
4614 icmd->ulpContext = xri;
4616 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4617 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4618 pcmd += sizeof(uint32_t); /* Skip past command */
4619 rps_rsp = (RPS_RSP *)pcmd;
4621 if (phba->fc_topology != TOPOLOGY_LOOP)
4625 if (phba->pport->fc_flag & FC_FABRIC)
4629 rps_rsp->portStatus = cpu_to_be16(status);
4630 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4631 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4632 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4633 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4634 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4635 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4636 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4637 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4638 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4639 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4640 elsiocb->iotag, elsiocb->iocb.ulpContext,
4641 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4643 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4644 phba->fc_stat.elsXmitACC++;
4645 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4646 lpfc_els_free_iocb(phba, elsiocb);
4651 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
4652 * @vport: pointer to a host virtual N_Port data structure.
4653 * @cmdiocb: pointer to lpfc command iocb data structure.
4654 * @ndlp: pointer to a node-list data structure.
4656 * This routine processes Read Port Status (RPS) IOCB received as an
4657 * ELS unsolicited event. It first checks the remote port state. If the
4658 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4659 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4660 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4661 * for reading the HBA link statistics. It is for the callback function,
4662 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4663 * to actually sending out RPS Accept (ACC) response.
4666 * 0 - Successfully processed rps iocb (currently always return 0)
4669 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4670 struct lpfc_nodelist *ndlp)
4672 struct lpfc_hba *phba = vport->phba;
4676 struct lpfc_dmabuf *pcmd;
4680 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4681 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4682 /* reject the unsolicited RPS request and done with it */
4685 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4686 lp = (uint32_t *) pcmd->virt;
4687 flag = (be32_to_cpu(*lp++) & 0xf);
4691 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
4692 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
4693 sizeof(struct lpfc_name)) == 0))) {
4695 printk("Fix me....\n");
4697 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4699 lpfc_read_lnk_stat(phba, mbox);
4701 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
4702 mbox->context2 = lpfc_nlp_get(ndlp);
4703 mbox->vport = vport;
4704 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
4705 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4706 != MBX_NOT_FINISHED)
4707 /* Mbox completion will send ELS Response */
4709 /* Decrement reference count used for the failed mbox
4713 mempool_free(mbox, phba->mbox_mem_pool);
4718 /* issue rejection response */
4719 stat.un.b.lsRjtRsvd0 = 0;
4720 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4721 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4722 stat.un.b.vendorUnique = 0;
4723 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4728 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
4729 * @vport: pointer to a host virtual N_Port data structure.
4730 * @cmdsize: size of the ELS command.
4731 * @oldiocb: pointer to the original lpfc command iocb data structure.
4732 * @ndlp: pointer to a node-list data structure.
4734 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4735 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4737 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4738 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4739 * will be stored into the context1 field of the IOCB for the completion
4740 * callback function to the RPL Accept Response ELS command.
4743 * 0 - Successfully issued ACC RPL ELS command
4744 * 1 - Failed to issue ACC RPL ELS command
4747 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4748 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4750 struct lpfc_hba *phba = vport->phba;
4751 IOCB_t *icmd, *oldcmd;
4753 struct lpfc_iocbq *elsiocb;
4756 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4757 ndlp->nlp_DID, ELS_CMD_ACC);
4762 icmd = &elsiocb->iocb;
4763 oldcmd = &oldiocb->iocb;
4764 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4766 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4767 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4768 pcmd += sizeof(uint16_t);
4769 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4770 pcmd += sizeof(uint16_t);
4772 /* Setup the RPL ACC payload */
4773 rpl_rsp.listLen = be32_to_cpu(1);
4775 rpl_rsp.port_num_blk.portNum = 0;
4776 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4777 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
4778 sizeof(struct lpfc_name));
4779 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
4780 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
4781 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4782 "0120 Xmit ELS RPL ACC response tag x%x "
4783 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4785 elsiocb->iotag, elsiocb->iocb.ulpContext,
4786 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4788 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4789 phba->fc_stat.elsXmitACC++;
4790 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4792 lpfc_els_free_iocb(phba, elsiocb);
4799 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
4800 * @vport: pointer to a host virtual N_Port data structure.
4801 * @cmdiocb: pointer to lpfc command iocb data structure.
4802 * @ndlp: pointer to a node-list data structure.
4804 * This routine processes Read Port List (RPL) IOCB received as an ELS
4805 * unsolicited event. It first checks the remote port state. If the remote
4806 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4807 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4808 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4809 * to accept the RPL.
4812 * 0 - Successfully processed rpl iocb (currently always return 0)
4815 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4816 struct lpfc_nodelist *ndlp)
4818 struct lpfc_dmabuf *pcmd;
4825 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4826 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
4827 /* issue rejection response */
4828 stat.un.b.lsRjtRsvd0 = 0;
4829 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4830 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4831 stat.un.b.vendorUnique = 0;
4832 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4834 /* rejected the unsolicited RPL request and done with it */
4838 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4839 lp = (uint32_t *) pcmd->virt;
4840 rpl = (RPL *) (lp + 1);
4842 maxsize = be32_to_cpu(rpl->maxsize);
4844 /* We support only one port */
4845 if ((rpl->index == 0) &&
4847 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4848 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
4850 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4852 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
4858 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
4859 * @vport: pointer to a virtual N_Port data structure.
4860 * @cmdiocb: pointer to lpfc command iocb data structure.
4861 * @ndlp: pointer to a node-list data structure.
4863 * This routine processes Fibre Channel Address Resolution Protocol
4864 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4865 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4866 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4867 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4868 * remote PortName is compared against the FC PortName stored in the @vport
4869 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4870 * compared against the FC NodeName stored in the @vport data structure.
4871 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4872 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4873 * invoked to send out FARP Response to the remote node. Before sending the
4874 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4875 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4876 * routine is invoked to log into the remote port first.
4879 * 0 - Either the FARP Match Mode not supported or successfully processed
4882 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4883 struct lpfc_nodelist *ndlp)
4885 struct lpfc_dmabuf *pcmd;
4889 uint32_t cmd, cnt, did;
4891 icmd = &cmdiocb->iocb;
4892 did = icmd->un.elsreq64.remoteID;
4893 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4894 lp = (uint32_t *) pcmd->virt;
4898 /* FARP-REQ received from DID <did> */
4899 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4900 "0601 FARP-REQ received from DID x%x\n", did);
4901 /* We will only support match on WWPN or WWNN */
4902 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
4907 /* If this FARP command is searching for my portname */
4908 if (fp->Mflags & FARP_MATCH_PORT) {
4909 if (memcmp(&fp->RportName, &vport->fc_portname,
4910 sizeof(struct lpfc_name)) == 0)
4914 /* If this FARP command is searching for my nodename */
4915 if (fp->Mflags & FARP_MATCH_NODE) {
4916 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
4917 sizeof(struct lpfc_name)) == 0)
4922 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4923 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4924 /* Log back into the node before sending the FARP. */
4925 if (fp->Rflags & FARP_REQUEST_PLOGI) {
4926 ndlp->nlp_prev_state = ndlp->nlp_state;
4927 lpfc_nlp_set_state(vport, ndlp,
4928 NLP_STE_PLOGI_ISSUE);
4929 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4932 /* Send a FARP response to that node */
4933 if (fp->Rflags & FARP_REQUEST_FARPR)
4934 lpfc_issue_els_farpr(vport, did, 0);
4941 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
4942 * @vport: pointer to a host virtual N_Port data structure.
4943 * @cmdiocb: pointer to lpfc command iocb data structure.
4944 * @ndlp: pointer to a node-list data structure.
4946 * This routine processes Fibre Channel Address Resolution Protocol
4947 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4948 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4949 * the FARP response request.
4952 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4955 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4956 struct lpfc_nodelist *ndlp)
4958 struct lpfc_dmabuf *pcmd;
4963 icmd = &cmdiocb->iocb;
4964 did = icmd->un.elsreq64.remoteID;
4965 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4966 lp = (uint32_t *) pcmd->virt;
4969 /* FARP-RSP received from DID <did> */
4970 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4971 "0600 FARP-RSP received from DID x%x\n", did);
4972 /* ACCEPT the Farp resp request */
4973 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4979 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
4980 * @vport: pointer to a host virtual N_Port data structure.
4981 * @cmdiocb: pointer to lpfc command iocb data structure.
4982 * @fan_ndlp: pointer to a node-list data structure.
4984 * This routine processes a Fabric Address Notification (FAN) IOCB
4985 * command received as an ELS unsolicited event. The FAN ELS command will
4986 * only be processed on a physical port (i.e., the @vport represents the
4987 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4988 * compared against those in the phba data structure. If any of those is
4989 * different, the lpfc_initial_flogi() routine is invoked to initialize
4990 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4991 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4992 * is invoked to register login to the fabric.
4995 * 0 - Successfully processed fan iocb (currently always return 0).
4998 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4999 struct lpfc_nodelist *fan_ndlp)
5001 struct lpfc_hba *phba = vport->phba;
5005 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5006 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5008 /* FAN received; Fan does not have a reply sequence */
5009 if ((vport == phba->pport) &&
5010 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
5011 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
5012 sizeof(struct lpfc_name))) ||
5013 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
5014 sizeof(struct lpfc_name)))) {
5015 /* This port has switched fabrics. FLOGI is required */
5016 lpfc_initial_flogi(vport);
5018 /* FAN verified - skip FLOGI */
5019 vport->fc_myDID = vport->fc_prevDID;
5020 if (phba->sli_rev < LPFC_SLI_REV4)
5021 lpfc_issue_fabric_reglogin(vport);
5023 lpfc_issue_reg_vfi(vport);
5030 * lpfc_els_timeout - Handler funciton to the els timer
5031 * @ptr: holder for the timer function associated data.
5033 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5034 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5035 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5036 * up the worker thread. It is for the worker thread to invoke the routine
5037 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5040 lpfc_els_timeout(unsigned long ptr)
5042 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5043 struct lpfc_hba *phba = vport->phba;
5044 uint32_t tmo_posted;
5045 unsigned long iflag;
5047 spin_lock_irqsave(&vport->work_port_lock, iflag);
5048 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5050 vport->work_port_events |= WORKER_ELS_TMO;
5051 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
5054 lpfc_worker_wake_up(phba);
5059 * lpfc_els_timeout_handler - Process an els timeout event
5060 * @vport: pointer to a virtual N_Port data structure.
5062 * This routine is the actual handler function that processes an ELS timeout
5063 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5064 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5065 * invoking the lpfc_sli_issue_abort_iotag() routine.
5068 lpfc_els_timeout_handler(struct lpfc_vport *vport)
5070 struct lpfc_hba *phba = vport->phba;
5071 struct lpfc_sli_ring *pring;
5072 struct lpfc_iocbq *tmp_iocb, *piocb;
5074 struct lpfc_dmabuf *pcmd;
5075 uint32_t els_command = 0;
5077 uint32_t remote_ID = 0xffffffff;
5079 spin_lock_irq(&phba->hbalock);
5080 timeout = (uint32_t)(phba->fc_ratov << 1);
5082 pring = &phba->sli.ring[LPFC_ELS_RING];
5084 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5087 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5088 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5089 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
5092 if (piocb->vport != vport)
5095 pcmd = (struct lpfc_dmabuf *) piocb->context2;
5097 els_command = *(uint32_t *) (pcmd->virt);
5099 if (els_command == ELS_CMD_FARP ||
5100 els_command == ELS_CMD_FARPR ||
5101 els_command == ELS_CMD_FDISC)
5104 if (piocb->drvrTimeout > 0) {
5105 if (piocb->drvrTimeout >= timeout)
5106 piocb->drvrTimeout -= timeout;
5108 piocb->drvrTimeout = 0;
5112 remote_ID = 0xffffffff;
5113 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
5114 remote_ID = cmd->un.elsreq64.remoteID;
5116 struct lpfc_nodelist *ndlp;
5117 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
5118 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5119 remote_ID = ndlp->nlp_DID;
5121 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5122 "0127 ELS timeout Data: x%x x%x x%x "
5123 "x%x\n", els_command,
5124 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5125 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5127 spin_unlock_irq(&phba->hbalock);
5129 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5130 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
5134 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5135 * @vport: pointer to a host virtual N_Port data structure.
5137 * This routine is used to clean up all the outstanding ELS commands on a
5138 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5139 * routine. After that, it walks the ELS transmit queue to remove all the
5140 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5141 * the IOCBs with a non-NULL completion callback function, the callback
5142 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5143 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5144 * callback function, the IOCB will simply be released. Finally, it walks
5145 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5146 * completion queue IOCB that is associated with the @vport and is not
5147 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5148 * part of the discovery state machine) out to HBA by invoking the
5149 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5150 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5151 * the IOCBs are aborted when this function returns.
5154 lpfc_els_flush_cmd(struct lpfc_vport *vport)
5156 LIST_HEAD(completions);
5157 struct lpfc_hba *phba = vport->phba;
5158 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5159 struct lpfc_iocbq *tmp_iocb, *piocb;
5162 lpfc_fabric_abort_vport(vport);
5164 spin_lock_irq(&phba->hbalock);
5165 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5168 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5172 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5173 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5174 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5175 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5176 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5179 if (piocb->vport != vport)
5182 list_move_tail(&piocb->list, &completions);
5186 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5187 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5191 if (piocb->vport != vport)
5194 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5196 spin_unlock_irq(&phba->hbalock);
5198 /* Cancell all the IOCBs from the completions list */
5199 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5206 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5207 * @phba: pointer to lpfc hba data structure.
5209 * This routine is used to clean up all the outstanding ELS commands on a
5210 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5211 * routine. After that, it walks the ELS transmit queue to remove all the
5212 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5213 * the IOCBs with the completion callback function associated, the callback
5214 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5215 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5216 * callback function associated, the IOCB will simply be released. Finally,
5217 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5218 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5219 * management plane IOCBs that are not part of the discovery state machine)
5220 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5223 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5225 LIST_HEAD(completions);
5226 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5227 struct lpfc_iocbq *tmp_iocb, *piocb;
5230 lpfc_fabric_abort_hba(phba);
5231 spin_lock_irq(&phba->hbalock);
5232 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5234 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5236 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5237 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5238 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5239 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5240 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5242 list_move_tail(&piocb->list, &completions);
5245 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5246 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5248 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5250 spin_unlock_irq(&phba->hbalock);
5252 /* Cancel all the IOCBs from the completions list */
5253 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5260 * lpfc_send_els_failure_event - Posts an ELS command failure event
5261 * @phba: Pointer to hba context object.
5262 * @cmdiocbp: Pointer to command iocb which reported error.
5263 * @rspiocbp: Pointer to response iocb which reported error.
5265 * This function sends an event when there is an ELS command
5269 lpfc_send_els_failure_event(struct lpfc_hba *phba,
5270 struct lpfc_iocbq *cmdiocbp,
5271 struct lpfc_iocbq *rspiocbp)
5273 struct lpfc_vport *vport = cmdiocbp->vport;
5274 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5275 struct lpfc_lsrjt_event lsrjt_event;
5276 struct lpfc_fabric_event_header fabric_event;
5278 struct lpfc_nodelist *ndlp;
5281 ndlp = cmdiocbp->context1;
5282 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5285 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5286 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5287 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5288 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5289 sizeof(struct lpfc_name));
5290 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5291 sizeof(struct lpfc_name));
5292 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5293 cmdiocbp->context2)->virt);
5294 lsrjt_event.command = *pcmd;
5295 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5296 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5297 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5298 fc_host_post_vendor_event(shost,
5299 fc_get_event_number(),
5300 sizeof(lsrjt_event),
5301 (char *)&lsrjt_event,
5305 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5306 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5307 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5308 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5309 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5311 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5312 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5313 sizeof(struct lpfc_name));
5314 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5315 sizeof(struct lpfc_name));
5316 fc_host_post_vendor_event(shost,
5317 fc_get_event_number(),
5318 sizeof(fabric_event),
5319 (char *)&fabric_event,
5327 * lpfc_send_els_event - Posts unsolicited els event
5328 * @vport: Pointer to vport object.
5329 * @ndlp: Pointer FC node object.
5330 * @cmd: ELS command code.
5332 * This function posts an event when there is an incoming
5333 * unsolicited ELS command.
5336 lpfc_send_els_event(struct lpfc_vport *vport,
5337 struct lpfc_nodelist *ndlp,
5340 struct lpfc_els_event_header *els_data = NULL;
5341 struct lpfc_logo_event *logo_data = NULL;
5342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5344 if (*payload == ELS_CMD_LOGO) {
5345 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5347 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5348 "0148 Failed to allocate memory "
5349 "for LOGO event\n");
5352 els_data = &logo_data->header;
5354 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5357 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5358 "0149 Failed to allocate memory "
5363 els_data->event_type = FC_REG_ELS_EVENT;
5366 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
5369 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
5372 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5375 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5376 /* Copy the WWPN in the LOGO payload */
5377 memcpy(logo_data->logo_wwpn, &payload[2],
5378 sizeof(struct lpfc_name));
5384 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5385 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5386 if (*payload == ELS_CMD_LOGO) {
5387 fc_host_post_vendor_event(shost,
5388 fc_get_event_number(),
5389 sizeof(struct lpfc_logo_event),
5394 fc_host_post_vendor_event(shost,
5395 fc_get_event_number(),
5396 sizeof(struct lpfc_els_event_header),
5407 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5408 * @phba: pointer to lpfc hba data structure.
5409 * @pring: pointer to a SLI ring.
5410 * @vport: pointer to a host virtual N_Port data structure.
5411 * @elsiocb: pointer to lpfc els command iocb data structure.
5413 * This routine is used for processing the IOCB associated with a unsolicited
5414 * event. It first determines whether there is an existing ndlp that matches
5415 * the DID from the unsolicited IOCB. If not, it will create a new one with
5416 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5417 * IOCB is then used to invoke the proper routine and to set up proper state
5418 * of the discovery state machine.
5421 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5422 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
5424 struct Scsi_Host *shost;
5425 struct lpfc_nodelist *ndlp;
5428 uint32_t cmd, did, newnode, rjt_err = 0;
5429 IOCB_t *icmd = &elsiocb->iocb;
5431 if (!vport || !(elsiocb->context2))
5435 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5437 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
5438 lpfc_post_buffer(phba, pring, 1);
5440 did = icmd->un.rcvels.remoteID;
5441 if (icmd->ulpStatus) {
5442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5443 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5444 icmd->ulpStatus, icmd->un.ulpWord[4], did);
5448 /* Check to see if link went down during discovery */
5449 if (lpfc_els_chk_latt(vport))
5452 /* Ignore traffic received during vport shutdown. */
5453 if (vport->load_flag & FC_UNLOADING)
5456 ndlp = lpfc_findnode_did(vport, did);
5458 /* Cannot find existing Fabric ndlp, so allocate a new one */
5459 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5463 lpfc_nlp_init(vport, ndlp, did);
5464 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5466 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5467 ndlp->nlp_type |= NLP_FABRIC;
5468 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5469 ndlp = lpfc_enable_node(vport, ndlp,
5470 NLP_STE_UNUSED_NODE);
5473 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5475 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5476 ndlp->nlp_type |= NLP_FABRIC;
5477 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5478 /* This is similar to the new node path */
5479 ndlp = lpfc_nlp_get(ndlp);
5482 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5486 phba->fc_stat.elsRcvFrame++;
5488 elsiocb->context1 = lpfc_nlp_get(ndlp);
5489 elsiocb->vport = vport;
5491 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5492 cmd &= ELS_CMD_MASK;
5494 /* ELS command <elsCmd> received from NPORT <did> */
5495 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5496 "0112 ELS command x%x received from NPORT x%x "
5497 "Data: x%x\n", cmd, did, vport->port_state);
5500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5501 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5502 did, vport->port_state, ndlp->nlp_flag);
5504 phba->fc_stat.elsRcvPLOGI++;
5505 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5507 lpfc_send_els_event(vport, ndlp, payload);
5508 if (vport->port_state < LPFC_DISC_AUTH) {
5509 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5510 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5511 rjt_err = LSRJT_UNABLE_TPC;
5514 /* We get here, and drop thru, if we are PT2PT with
5515 * another NPort and the other side has initiated
5516 * the PLOGI before responding to our FLOGI.
5520 shost = lpfc_shost_from_vport(vport);
5521 spin_lock_irq(shost->host_lock);
5522 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5523 spin_unlock_irq(shost->host_lock);
5525 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5531 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5532 did, vport->port_state, ndlp->nlp_flag);
5534 phba->fc_stat.elsRcvFLOGI++;
5535 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
5540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5541 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5542 did, vport->port_state, ndlp->nlp_flag);
5544 phba->fc_stat.elsRcvLOGO++;
5545 lpfc_send_els_event(vport, ndlp, payload);
5546 if (vport->port_state < LPFC_DISC_AUTH) {
5547 rjt_err = LSRJT_UNABLE_TPC;
5550 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
5553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5554 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5555 did, vport->port_state, ndlp->nlp_flag);
5557 phba->fc_stat.elsRcvPRLO++;
5558 lpfc_send_els_event(vport, ndlp, payload);
5559 if (vport->port_state < LPFC_DISC_AUTH) {
5560 rjt_err = LSRJT_UNABLE_TPC;
5563 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
5566 phba->fc_stat.elsRcvRSCN++;
5567 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
5572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5573 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5574 did, vport->port_state, ndlp->nlp_flag);
5576 lpfc_send_els_event(vport, ndlp, payload);
5577 phba->fc_stat.elsRcvADISC++;
5578 if (vport->port_state < LPFC_DISC_AUTH) {
5579 rjt_err = LSRJT_UNABLE_TPC;
5582 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5587 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5588 did, vport->port_state, ndlp->nlp_flag);
5590 phba->fc_stat.elsRcvPDISC++;
5591 if (vport->port_state < LPFC_DISC_AUTH) {
5592 rjt_err = LSRJT_UNABLE_TPC;
5595 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5600 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5601 did, vport->port_state, ndlp->nlp_flag);
5603 phba->fc_stat.elsRcvFARPR++;
5604 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
5607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5608 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5609 did, vport->port_state, ndlp->nlp_flag);
5611 phba->fc_stat.elsRcvFARP++;
5612 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
5615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5616 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5617 did, vport->port_state, ndlp->nlp_flag);
5619 phba->fc_stat.elsRcvFAN++;
5620 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
5623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5624 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5625 did, vport->port_state, ndlp->nlp_flag);
5627 phba->fc_stat.elsRcvPRLI++;
5628 if (vport->port_state < LPFC_DISC_AUTH) {
5629 rjt_err = LSRJT_UNABLE_TPC;
5632 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
5635 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5636 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5637 did, vport->port_state, ndlp->nlp_flag);
5639 phba->fc_stat.elsRcvLIRR++;
5640 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
5645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5646 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5647 did, vport->port_state, ndlp->nlp_flag);
5649 phba->fc_stat.elsRcvRPS++;
5650 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
5655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5656 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5657 did, vport->port_state, ndlp->nlp_flag);
5659 phba->fc_stat.elsRcvRPL++;
5660 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
5665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5666 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5667 did, vport->port_state, ndlp->nlp_flag);
5669 phba->fc_stat.elsRcvRNID++;
5670 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
5675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5676 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5677 did, vport->port_state, ndlp->nlp_flag);
5679 phba->fc_stat.elsRcvRRQ++;
5680 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5686 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5687 cmd, did, vport->port_state);
5689 /* Unsupported ELS command, reject */
5690 rjt_err = LSRJT_INVALID_CMD;
5692 /* Unknown ELS command <elsCmd> received from NPORT <did> */
5693 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5694 "0115 Unknown ELS command x%x "
5695 "received from NPORT x%x\n", cmd, did);
5701 /* check if need to LS_RJT received ELS cmd */
5703 memset(&stat, 0, sizeof(stat));
5704 stat.un.b.lsRjtRsnCode = rjt_err;
5705 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
5706 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5710 lpfc_nlp_put(elsiocb->context1);
5711 elsiocb->context1 = NULL;
5715 if (vport && !(vport->load_flag & FC_UNLOADING))
5716 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5717 "0111 Dropping received ELS cmd "
5718 "Data: x%x x%x x%x\n",
5719 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
5720 phba->fc_stat.elsRcvDrop++;
5724 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5725 * @phba: pointer to lpfc hba data structure.
5726 * @vpi: host virtual N_Port identifier.
5728 * This routine finds a vport on a HBA (referred by @phba) through a
5729 * @vpi. The function walks the HBA's vport list and returns the address
5730 * of the vport with the matching @vpi.
5733 * NULL - No vport with the matching @vpi found
5734 * Otherwise - Address to the vport with the matching @vpi.
5737 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5739 struct lpfc_vport *vport;
5740 unsigned long flags;
5742 spin_lock_irqsave(&phba->hbalock, flags);
5743 list_for_each_entry(vport, &phba->port_list, listentry) {
5744 if (vport->vpi == vpi) {
5745 spin_unlock_irqrestore(&phba->hbalock, flags);
5749 spin_unlock_irqrestore(&phba->hbalock, flags);
5754 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
5755 * @phba: pointer to lpfc hba data structure.
5756 * @pring: pointer to a SLI ring.
5757 * @elsiocb: pointer to lpfc els iocb data structure.
5759 * This routine is used to process an unsolicited event received from a SLI
5760 * (Service Level Interface) ring. The actual processing of the data buffer
5761 * associated with the unsolicited event is done by invoking the routine
5762 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5763 * SLI ring on which the unsolicited event was received.
5766 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5767 struct lpfc_iocbq *elsiocb)
5769 struct lpfc_vport *vport = phba->pport;
5770 IOCB_t *icmd = &elsiocb->iocb;
5772 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5773 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
5775 elsiocb->context1 = NULL;
5776 elsiocb->context2 = NULL;
5777 elsiocb->context3 = NULL;
5779 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5780 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5781 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5782 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
5783 phba->fc_stat.NoRcvBuf++;
5784 /* Not enough posted buffers; Try posting more buffers */
5785 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
5786 lpfc_post_buffer(phba, pring, 0);
5790 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5791 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5792 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5793 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5794 vport = phba->pport;
5796 vport = lpfc_find_vport_by_vpid(phba,
5797 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
5799 /* If there are no BDEs associated
5800 * with this IOCB, there is nothing to do.
5802 if (icmd->ulpBdeCount == 0)
5805 /* type of ELS cmd is first 32bit word
5808 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5809 elsiocb->context2 = bdeBuf1;
5811 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5812 icmd->un.cont64[0].addrLow);
5813 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5817 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5819 * The different unsolicited event handlers would tell us
5820 * if they are done with "mp" by setting context2 to NULL.
5822 if (elsiocb->context2) {
5823 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5824 elsiocb->context2 = NULL;
5827 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
5828 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
5829 icmd->ulpBdeCount == 2) {
5830 elsiocb->context2 = bdeBuf2;
5831 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5832 /* free mp if we are done with it */
5833 if (elsiocb->context2) {
5834 lpfc_in_buf_free(phba, elsiocb->context2);
5835 elsiocb->context2 = NULL;
5841 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
5842 * @phba: pointer to lpfc hba data structure.
5843 * @vport: pointer to a virtual N_Port data structure.
5845 * This routine issues a Port Login (PLOGI) to the Name Server with
5846 * State Change Request (SCR) for a @vport. This routine will create an
5847 * ndlp for the Name Server associated to the @vport if such node does
5848 * not already exist. The PLOGI to Name Server is issued by invoking the
5849 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5850 * (FDMI) is configured to the @vport, a FDMI node will be created and
5851 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5854 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5856 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5858 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5860 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5862 if (phba->fc_topology == TOPOLOGY_LOOP) {
5863 lpfc_disc_start(vport);
5866 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5868 "0251 NameServer login: no memory\n");
5871 lpfc_nlp_init(vport, ndlp, NameServer_DID);
5872 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5873 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5875 if (phba->fc_topology == TOPOLOGY_LOOP) {
5876 lpfc_disc_start(vport);
5879 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5880 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5881 "0348 NameServer login: node freed\n");
5885 ndlp->nlp_type |= NLP_FABRIC;
5887 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5889 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5890 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5891 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5892 "0252 Cannot issue NameServer login\n");
5896 if (vport->cfg_fdmi_on) {
5897 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5900 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5901 ndlp_fdmi->nlp_type |= NLP_FABRIC;
5902 lpfc_nlp_set_state(vport, ndlp_fdmi,
5903 NLP_STE_PLOGI_ISSUE);
5904 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5912 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
5913 * @phba: pointer to lpfc hba data structure.
5914 * @pmb: pointer to the driver internal queue element for mailbox command.
5916 * This routine is the completion callback function to register new vport
5917 * mailbox command. If the new vport mailbox command completes successfully,
5918 * the fabric registration login shall be performed on physical port (the
5919 * new vport created is actually a physical port, with VPI 0) or the port
5920 * login to Name Server for State Change Request (SCR) will be performed
5921 * on virtual port (real virtual port, with VPI greater than 0).
5924 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5926 struct lpfc_vport *vport = pmb->vport;
5927 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5928 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5929 MAILBOX_t *mb = &pmb->u.mb;
5932 spin_lock_irq(shost->host_lock);
5933 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5934 spin_unlock_irq(shost->host_lock);
5936 if (mb->mbxStatus) {
5937 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5938 "0915 Register VPI failed: 0x%x\n",
5941 switch (mb->mbxStatus) {
5942 case 0x11: /* unsupported feature */
5943 case 0x9603: /* max_vpi exceeded */
5944 case 0x9602: /* Link event since CLEAR_LA */
5945 /* giving up on vport registration */
5946 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5947 spin_lock_irq(shost->host_lock);
5948 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5949 spin_unlock_irq(shost->host_lock);
5950 lpfc_can_disctmo(vport);
5952 /* If reg_vpi fail with invalid VPI status, re-init VPI */
5954 spin_lock_irq(shost->host_lock);
5955 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5956 spin_unlock_irq(shost->host_lock);
5957 lpfc_init_vpi(phba, pmb, vport->vpi);
5959 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
5960 rc = lpfc_sli_issue_mbox(phba, pmb,
5962 if (rc == MBX_NOT_FINISHED) {
5963 lpfc_printf_vlog(vport,
5965 "2732 Failed to issue INIT_VPI"
5966 " mailbox command\n");
5973 /* Try to recover from this error */
5974 lpfc_mbx_unreg_vpi(vport);
5975 spin_lock_irq(shost->host_lock);
5976 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5977 spin_unlock_irq(shost->host_lock);
5978 if (vport->port_type == LPFC_PHYSICAL_PORT)
5979 lpfc_initial_flogi(vport);
5981 lpfc_initial_fdisc(vport);
5985 spin_lock_irq(shost->host_lock);
5986 vport->vpi_state |= LPFC_VPI_REGISTERED;
5987 spin_unlock_irq(shost->host_lock);
5988 if (vport == phba->pport) {
5989 if (phba->sli_rev < LPFC_SLI_REV4)
5990 lpfc_issue_fabric_reglogin(vport);
5992 lpfc_start_fdiscs(phba);
5993 lpfc_do_scr_ns_plogi(phba, vport);
5996 lpfc_do_scr_ns_plogi(phba, vport);
5999 /* Now, we decrement the ndlp reference count held for this
6004 mempool_free(pmb, phba->mbox_mem_pool);
6009 * lpfc_register_new_vport - Register a new vport with a HBA
6010 * @phba: pointer to lpfc hba data structure.
6011 * @vport: pointer to a host virtual N_Port data structure.
6012 * @ndlp: pointer to a node-list data structure.
6014 * This routine registers the @vport as a new virtual port with a HBA.
6015 * It is done through a registering vpi mailbox command.
6018 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6019 struct lpfc_nodelist *ndlp)
6021 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6024 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6026 lpfc_reg_vpi(vport, mbox);
6027 mbox->vport = vport;
6028 mbox->context2 = lpfc_nlp_get(ndlp);
6029 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
6030 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6031 == MBX_NOT_FINISHED) {
6032 /* mailbox command not success, decrement ndlp
6033 * reference count for this command
6036 mempool_free(mbox, phba->mbox_mem_pool);
6038 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6039 "0253 Register VPI: Can't send mbox\n");
6043 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6044 "0254 Register VPI: no memory\n");
6050 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6051 spin_lock_irq(shost->host_lock);
6052 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6053 spin_unlock_irq(shost->host_lock);
6058 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6059 * @phba: pointer to lpfc hba data structure.
6061 * This routine abort all pending discovery commands and
6062 * start a timer to retry FLOGI for the physical port
6066 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6068 struct lpfc_vport **vports;
6069 struct lpfc_nodelist *ndlp;
6070 struct Scsi_Host *shost;
6072 uint32_t link_state;
6074 /* Treat this failure as linkdown for all vports */
6075 link_state = phba->link_state;
6076 lpfc_linkdown(phba);
6077 phba->link_state = link_state;
6079 vports = lpfc_create_vport_work_array(phba);
6082 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6083 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6085 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6086 lpfc_els_flush_cmd(vports[i]);
6088 lpfc_destroy_vport_work_array(phba, vports);
6091 /* If fabric require FLOGI, then re-instantiate physical login */
6092 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6097 shost = lpfc_shost_from_vport(phba->pport);
6098 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6099 spin_lock_irq(shost->host_lock);
6100 ndlp->nlp_flag |= NLP_DELAY_TMO;
6101 spin_unlock_irq(shost->host_lock);
6102 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6103 phba->pport->port_state = LPFC_FLOGI;
6108 * lpfc_fabric_login_reqd - Check if FLOGI required.
6109 * @phba: pointer to lpfc hba data structure.
6110 * @cmdiocb: pointer to FDISC command iocb.
6111 * @rspiocb: pointer to FDISC response iocb.
6113 * This routine checks if a FLOGI is reguired for FDISC
6117 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6118 struct lpfc_iocbq *cmdiocb,
6119 struct lpfc_iocbq *rspiocb)
6122 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6123 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6130 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6131 * @phba: pointer to lpfc hba data structure.
6132 * @cmdiocb: pointer to lpfc command iocb data structure.
6133 * @rspiocb: pointer to lpfc response iocb data structure.
6135 * This routine is the completion callback function to a Fabric Discover
6136 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6137 * single threaded, each FDISC completion callback function will reset
6138 * the discovery timer for all vports such that the timers will not get
6139 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6140 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6141 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6142 * assigned to the vport has been changed with the completion of the FDISC
6143 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6144 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6145 * routine is invoked to register new vport with the HBA. Otherwise, the
6146 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6147 * Server for State Change Request (SCR).
6150 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6151 struct lpfc_iocbq *rspiocb)
6153 struct lpfc_vport *vport = cmdiocb->vport;
6154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6155 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6156 struct lpfc_nodelist *np;
6157 struct lpfc_nodelist *next_np;
6158 IOCB_t *irsp = &rspiocb->iocb;
6159 struct lpfc_iocbq *piocb;
6161 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6162 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6163 irsp->ulpStatus, irsp->un.ulpWord[4],
6165 /* Since all FDISCs are being single threaded, we
6166 * must reset the discovery timer for ALL vports
6167 * waiting to send FDISC when one completes.
6169 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6170 lpfc_set_disctmo(piocb->vport);
6173 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6174 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6175 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6177 if (irsp->ulpStatus) {
6179 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6180 lpfc_retry_pport_discovery(phba);
6184 /* Check for retry */
6185 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6188 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6189 "0126 FDISC failed. (%d/%d)\n",
6190 irsp->ulpStatus, irsp->un.ulpWord[4]);
6193 spin_lock_irq(shost->host_lock);
6194 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
6195 vport->fc_flag |= FC_FABRIC;
6196 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6197 vport->fc_flag |= FC_PUBLIC_LOOP;
6198 spin_unlock_irq(shost->host_lock);
6200 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6201 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6202 if ((vport->fc_prevDID != vport->fc_myDID) &&
6203 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6204 /* If our NportID changed, we need to ensure all
6205 * remaining NPORTs get unreg_login'ed so we can
6208 list_for_each_entry_safe(np, next_np,
6209 &vport->fc_nodes, nlp_listp) {
6210 if (!NLP_CHK_NODE_ACT(ndlp) ||
6211 (np->nlp_state != NLP_STE_NPR_NODE) ||
6212 !(np->nlp_flag & NLP_NPR_ADISC))
6214 spin_lock_irq(shost->host_lock);
6215 np->nlp_flag &= ~NLP_NPR_ADISC;
6216 spin_unlock_irq(shost->host_lock);
6217 lpfc_unreg_rpi(vport, np);
6219 lpfc_mbx_unreg_vpi(vport);
6220 spin_lock_irq(shost->host_lock);
6221 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6222 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6223 spin_unlock_irq(shost->host_lock);
6226 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6227 lpfc_issue_init_vpi(vport);
6228 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
6229 lpfc_register_new_vport(phba, vport, ndlp);
6231 lpfc_do_scr_ns_plogi(phba, vport);
6234 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6235 /* Cancel discovery timer */
6236 lpfc_can_disctmo(vport);
6239 lpfc_els_free_iocb(phba, cmdiocb);
6243 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6244 * @vport: pointer to a virtual N_Port data structure.
6245 * @ndlp: pointer to a node-list data structure.
6246 * @retry: number of retries to the command IOCB.
6248 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6249 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6250 * routine to issue the IOCB, which makes sure only one outstanding fabric
6251 * IOCB will be sent off HBA at any given time.
6253 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6254 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6255 * will be stored into the context1 field of the IOCB for the completion
6256 * callback function to the FDISC ELS command.
6259 * 0 - Successfully issued fdisc iocb command
6260 * 1 - Failed to issue fdisc iocb command
6263 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6266 struct lpfc_hba *phba = vport->phba;
6268 struct lpfc_iocbq *elsiocb;
6269 struct serv_parm *sp;
6272 int did = ndlp->nlp_DID;
6275 vport->port_state = LPFC_FDISC;
6276 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6277 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6280 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6281 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6282 "0255 Issue FDISC: no IOCB\n");
6286 icmd = &elsiocb->iocb;
6287 icmd->un.elsreq64.myID = 0;
6288 icmd->un.elsreq64.fl = 1;
6290 if (phba->sli_rev == LPFC_SLI_REV4) {
6291 /* FDISC needs to be 1 for WQE VPI */
6292 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6293 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6294 /* Set the ulpContext to the vpi */
6295 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6297 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6302 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6303 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6304 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6305 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6306 sp = (struct serv_parm *) pcmd;
6307 /* Setup CSPs accordingly for Fabric */
6308 sp->cmn.e_d_tov = 0;
6309 sp->cmn.w2.r_a_tov = 0;
6310 sp->cls1.classValid = 0;
6311 sp->cls2.seqDelivery = 1;
6312 sp->cls3.seqDelivery = 1;
6314 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6315 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6316 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6317 pcmd += sizeof(uint32_t); /* Port Name */
6318 memcpy(pcmd, &vport->fc_portname, 8);
6319 pcmd += sizeof(uint32_t); /* Node Name */
6320 pcmd += sizeof(uint32_t); /* Node Name */
6321 memcpy(pcmd, &vport->fc_nodename, 8);
6323 lpfc_set_disctmo(vport);
6325 phba->fc_stat.elsXmitFDISC++;
6326 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6329 "Issue FDISC: did:x%x",
6332 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6333 if (rc == IOCB_ERROR) {
6334 lpfc_els_free_iocb(phba, elsiocb);
6335 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6336 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6337 "0256 Issue FDISC: Cannot send IOCB\n");
6340 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6345 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6346 * @phba: pointer to lpfc hba data structure.
6347 * @cmdiocb: pointer to lpfc command iocb data structure.
6348 * @rspiocb: pointer to lpfc response iocb data structure.
6350 * This routine is the completion callback function to the issuing of a LOGO
6351 * ELS command off a vport. It frees the command IOCB and then decrement the
6352 * reference count held on ndlp for this completion function, indicating that
6353 * the reference to the ndlp is no long needed. Note that the
6354 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6355 * callback function and an additional explicit ndlp reference decrementation
6356 * will trigger the actual release of the ndlp.
6359 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6360 struct lpfc_iocbq *rspiocb)
6362 struct lpfc_vport *vport = cmdiocb->vport;
6364 struct lpfc_nodelist *ndlp;
6365 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
6367 irsp = &rspiocb->iocb;
6368 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6369 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6370 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
6372 lpfc_els_free_iocb(phba, cmdiocb);
6373 vport->unreg_vpi_cmpl = VPORT_ERROR;
6375 /* Trigger the release of the ndlp after logo */
6380 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6381 * @vport: pointer to a virtual N_Port data structure.
6382 * @ndlp: pointer to a node-list data structure.
6384 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6386 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6387 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6388 * will be stored into the context1 field of the IOCB for the completion
6389 * callback function to the LOGO ELS command.
6392 * 0 - Successfully issued logo off the @vport
6393 * 1 - Failed to issue logo off the @vport
6396 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6398 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6399 struct lpfc_hba *phba = vport->phba;
6401 struct lpfc_iocbq *elsiocb;
6405 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6406 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6411 icmd = &elsiocb->iocb;
6412 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6413 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6414 pcmd += sizeof(uint32_t);
6416 /* Fill in LOGO payload */
6417 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6418 pcmd += sizeof(uint32_t);
6419 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6422 "Issue LOGO npiv did:x%x flg:x%x",
6423 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6425 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6426 spin_lock_irq(shost->host_lock);
6427 ndlp->nlp_flag |= NLP_LOGO_SND;
6428 spin_unlock_irq(shost->host_lock);
6429 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6431 spin_lock_irq(shost->host_lock);
6432 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6433 spin_unlock_irq(shost->host_lock);
6434 lpfc_els_free_iocb(phba, elsiocb);
6441 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
6442 * @ptr: holder for the timer function associated data.
6444 * This routine is invoked by the fabric iocb block timer after
6445 * timeout. It posts the fabric iocb block timeout event by setting the
6446 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6447 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6448 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6449 * posted event WORKER_FABRIC_BLOCK_TMO.
6452 lpfc_fabric_block_timeout(unsigned long ptr)
6454 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6455 unsigned long iflags;
6456 uint32_t tmo_posted;
6458 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6459 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6461 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6462 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6465 lpfc_worker_wake_up(phba);
6470 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
6471 * @phba: pointer to lpfc hba data structure.
6473 * This routine issues one fabric iocb from the driver internal list to
6474 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6475 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6476 * remove one pending fabric iocb from the driver internal list and invokes
6477 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6480 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6482 struct lpfc_iocbq *iocb;
6483 unsigned long iflags;
6489 spin_lock_irqsave(&phba->hbalock, iflags);
6490 /* Post any pending iocb to the SLI layer */
6491 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6492 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6495 /* Increment fabric iocb count to hold the position */
6496 atomic_inc(&phba->fabric_iocb_count);
6498 spin_unlock_irqrestore(&phba->hbalock, iflags);
6500 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6501 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6502 iocb->iocb_flag |= LPFC_IO_FABRIC;
6504 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6505 "Fabric sched1: ste:x%x",
6506 iocb->vport->port_state, 0, 0);
6508 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
6510 if (ret == IOCB_ERROR) {
6511 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6512 iocb->fabric_iocb_cmpl = NULL;
6513 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6515 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6516 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6517 iocb->iocb_cmpl(phba, iocb, iocb);
6519 atomic_dec(&phba->fabric_iocb_count);
6528 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
6529 * @phba: pointer to lpfc hba data structure.
6531 * This routine unblocks the issuing fabric iocb command. The function
6532 * will clear the fabric iocb block bit and then invoke the routine
6533 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6534 * from the driver internal fabric iocb list.
6537 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6539 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6541 lpfc_resume_fabric_iocbs(phba);
6546 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
6547 * @phba: pointer to lpfc hba data structure.
6549 * This routine blocks the issuing fabric iocb for a specified amount of
6550 * time (currently 100 ms). This is done by set the fabric iocb block bit
6551 * and set up a timeout timer for 100ms. When the block bit is set, no more
6552 * fabric iocb will be issued out of the HBA.
6555 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6559 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6560 /* Start a timer to unblock fabric iocbs after 100ms */
6562 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6568 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
6569 * @phba: pointer to lpfc hba data structure.
6570 * @cmdiocb: pointer to lpfc command iocb data structure.
6571 * @rspiocb: pointer to lpfc response iocb data structure.
6573 * This routine is the callback function that is put to the fabric iocb's
6574 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6575 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6576 * function first restores and invokes the original iocb's callback function
6577 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6578 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6581 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6582 struct lpfc_iocbq *rspiocb)
6586 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6589 switch (rspiocb->iocb.ulpStatus) {
6590 case IOSTAT_NPORT_RJT:
6591 case IOSTAT_FABRIC_RJT:
6592 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6593 lpfc_block_fabric_iocbs(phba);
6597 case IOSTAT_NPORT_BSY:
6598 case IOSTAT_FABRIC_BSY:
6599 lpfc_block_fabric_iocbs(phba);
6603 stat.un.lsRjtError =
6604 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6605 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6606 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6607 lpfc_block_fabric_iocbs(phba);
6611 if (atomic_read(&phba->fabric_iocb_count) == 0)
6614 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6615 cmdiocb->fabric_iocb_cmpl = NULL;
6616 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6617 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6619 atomic_dec(&phba->fabric_iocb_count);
6620 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
6621 /* Post any pending iocbs to HBA */
6622 lpfc_resume_fabric_iocbs(phba);
6627 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
6628 * @phba: pointer to lpfc hba data structure.
6629 * @iocb: pointer to lpfc command iocb data structure.
6631 * This routine is used as the top-level API for issuing a fabric iocb command
6632 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6633 * function makes sure that only one fabric bound iocb will be outstanding at
6634 * any given time. As such, this function will first check to see whether there
6635 * is already an outstanding fabric iocb on the wire. If so, it will put the
6636 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6637 * issued later. Otherwise, it will issue the iocb on the wire and update the
6638 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6640 * Note, this implementation has a potential sending out fabric IOCBs out of
6641 * order. The problem is caused by the construction of the "ready" boolen does
6642 * not include the condition that the internal fabric IOCB list is empty. As
6643 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6644 * ahead of the fabric IOCBs in the internal list.
6647 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6648 * IOCB_ERROR - failed to issue fabric iocb
6651 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6653 unsigned long iflags;
6657 if (atomic_read(&phba->fabric_iocb_count) > 1)
6660 spin_lock_irqsave(&phba->hbalock, iflags);
6661 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6662 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6665 /* Increment fabric iocb count to hold the position */
6666 atomic_inc(&phba->fabric_iocb_count);
6667 spin_unlock_irqrestore(&phba->hbalock, iflags);
6669 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6670 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6671 iocb->iocb_flag |= LPFC_IO_FABRIC;
6673 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6674 "Fabric sched2: ste:x%x",
6675 iocb->vport->port_state, 0, 0);
6677 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
6679 if (ret == IOCB_ERROR) {
6680 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6681 iocb->fabric_iocb_cmpl = NULL;
6682 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6683 atomic_dec(&phba->fabric_iocb_count);
6686 spin_lock_irqsave(&phba->hbalock, iflags);
6687 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6688 spin_unlock_irqrestore(&phba->hbalock, iflags);
6695 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
6696 * @vport: pointer to a virtual N_Port data structure.
6698 * This routine aborts all the IOCBs associated with a @vport from the
6699 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6700 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6701 * list, removes each IOCB associated with the @vport off the list, set the
6702 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6703 * associated with the IOCB.
6705 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
6707 LIST_HEAD(completions);
6708 struct lpfc_hba *phba = vport->phba;
6709 struct lpfc_iocbq *tmp_iocb, *piocb;
6711 spin_lock_irq(&phba->hbalock);
6712 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6715 if (piocb->vport != vport)
6718 list_move_tail(&piocb->list, &completions);
6720 spin_unlock_irq(&phba->hbalock);
6722 /* Cancel all the IOCBs from the completions list */
6723 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6728 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
6729 * @ndlp: pointer to a node-list data structure.
6731 * This routine aborts all the IOCBs associated with an @ndlp from the
6732 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6733 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6734 * list, removes each IOCB associated with the @ndlp off the list, set the
6735 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6736 * associated with the IOCB.
6738 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6740 LIST_HEAD(completions);
6741 struct lpfc_hba *phba = ndlp->phba;
6742 struct lpfc_iocbq *tmp_iocb, *piocb;
6743 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6745 spin_lock_irq(&phba->hbalock);
6746 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6748 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6750 list_move_tail(&piocb->list, &completions);
6753 spin_unlock_irq(&phba->hbalock);
6755 /* Cancel all the IOCBs from the completions list */
6756 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6761 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
6762 * @phba: pointer to lpfc hba data structure.
6764 * This routine aborts all the IOCBs currently on the driver internal
6765 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6766 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6767 * list, removes IOCBs off the list, set the status feild to
6768 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6771 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6773 LIST_HEAD(completions);
6775 spin_lock_irq(&phba->hbalock);
6776 list_splice_init(&phba->fabric_iocb_list, &completions);
6777 spin_unlock_irq(&phba->hbalock);
6779 /* Cancel all the IOCBs from the completions list */
6780 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6785 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6786 * @phba: pointer to lpfc hba data structure.
6787 * @axri: pointer to the els xri abort wcqe structure.
6789 * This routine is invoked by the worker thread to process a SLI4 slow-path
6793 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6794 struct sli4_wcqe_xri_aborted *axri)
6796 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6797 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6798 unsigned long iflag = 0;
6800 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag);
6801 list_for_each_entry_safe(sglq_entry, sglq_next,
6802 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6803 if (sglq_entry->sli4_xritag == xri) {
6804 list_del(&sglq_entry->list);
6805 spin_unlock_irqrestore(
6806 &phba->sli4_hba.abts_sgl_list_lock,
6808 spin_lock_irqsave(&phba->hbalock, iflag);
6810 list_add_tail(&sglq_entry->list,
6811 &phba->sli4_hba.lpfc_sgl_list);
6812 spin_unlock_irqrestore(&phba->hbalock, iflag);
6816 spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag);