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/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
47 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
55 static int lpfc_max_els_tries = 3;
58 * lpfc_els_chk_latt - Check host link attention event for a vport
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
80 lpfc_els_chk_latt(struct lpfc_vport *vport)
82 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
86 if (vport->port_state >= LPFC_VPORT_READY ||
87 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
91 /* Read the HBA Host Attention Register */
92 ha_copy = readl(phba->HAregaddr);
94 if (!(ha_copy & HA_LATT))
97 /* Pending Link Event during Discovery */
98 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
113 if (phba->link_state != LPFC_CLEAR_LA)
114 lpfc_issue_clear_la(phba, vport);
120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
148 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
153 struct lpfc_hba *phba = vport->phba;
154 struct lpfc_iocbq *elsiocb;
155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
160 if (!lpfc_is_link_up(phba))
163 /* Allocate buffer for command iocb */
164 elsiocb = lpfc_sli_get_iocbq(phba);
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 if ((did == Fabric_DID) &&
174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
180 elsiocb->iocb_flag |=
181 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
182 & LPFC_FIP_ELS_ID_MASK);
185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
187 & LPFC_FIP_ELS_ID_MASK);
190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
192 & LPFC_FIP_ELS_ID_MASK);
196 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
198 icmd = &elsiocb->iocb;
200 /* fill in BDEs for command */
201 /* Allocate buffer for command payload */
202 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
204 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
205 if (!pcmd || !pcmd->virt)
206 goto els_iocb_free_pcmb_exit;
208 INIT_LIST_HEAD(&pcmd->list);
210 /* Allocate buffer for response payload */
212 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
214 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
216 if (!prsp || !prsp->virt)
217 goto els_iocb_free_prsp_exit;
218 INIT_LIST_HEAD(&prsp->list);
222 /* Allocate buffer for Buffer ptr list */
223 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
225 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 if (!pbuflist || !pbuflist->virt)
228 goto els_iocb_free_pbuf_exit;
230 INIT_LIST_HEAD(&pbuflist->list);
232 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
233 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
234 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
235 icmd->un.elsreq64.remoteID = did; /* DID */
237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
238 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
239 icmd->ulpTimeout = phba->fc_ratov * 2;
241 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
242 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
244 icmd->ulpBdeCount = 1;
246 icmd->ulpClass = CLASS3;
248 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
249 icmd->un.elsreq64.myID = vport->fc_myDID;
251 /* For ELS_REQUEST64_CR, use the VPI by default */
252 icmd->ulpContext = vport->vpi + phba->vpi_base;
254 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
255 if (elscmd == ELS_CMD_ECHO)
256 icmd->ulpCt_l = 0; /* context = invalid RPI */
258 icmd->ulpCt_l = 1; /* context = VPI */
261 bpl = (struct ulp_bde64 *) pbuflist->virt;
262 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
263 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
264 bpl->tus.f.bdeSize = cmdSize;
265 bpl->tus.f.bdeFlags = 0;
266 bpl->tus.w = le32_to_cpu(bpl->tus.w);
270 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
271 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
272 bpl->tus.f.bdeSize = FCELSSIZE;
273 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
274 bpl->tus.w = le32_to_cpu(bpl->tus.w);
277 /* prevent preparing iocb with NULL ndlp reference */
278 elsiocb->context1 = lpfc_nlp_get(ndlp);
279 if (!elsiocb->context1)
280 goto els_iocb_free_pbuf_exit;
281 elsiocb->context2 = pcmd;
282 elsiocb->context3 = pbuflist;
283 elsiocb->retry = retry;
284 elsiocb->vport = vport;
285 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
288 list_add(&prsp->list, &pcmd->list);
291 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
293 "0116 Xmit ELS command x%x to remote "
294 "NPORT x%x I/O tag: x%x, port state: x%x\n",
295 elscmd, did, elsiocb->iotag,
298 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
299 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
300 "0117 Xmit ELS response x%x to remote "
301 "NPORT x%x I/O tag: x%x, size: x%x\n",
302 elscmd, ndlp->nlp_DID, elsiocb->iotag,
307 els_iocb_free_pbuf_exit:
309 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
312 els_iocb_free_prsp_exit:
313 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
316 els_iocb_free_pcmb_exit:
318 lpfc_sli_release_iocbq(phba, elsiocb);
323 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
324 * @vport: pointer to a host virtual N_Port data structure.
326 * This routine issues a fabric registration login for a @vport. An
327 * active ndlp node with Fabric_DID must already exist for this @vport.
328 * The routine invokes two mailbox commands to carry out fabric registration
329 * login through the HBA firmware: the first mailbox command requests the
330 * HBA to perform link configuration for the @vport; and the second mailbox
331 * command requests the HBA to perform the actual fabric registration login
335 * 0 - successfully issued fabric registration login for @vport
336 * -ENXIO -- failed to issue fabric registration login for @vport
339 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
341 struct lpfc_hba *phba = vport->phba;
343 struct lpfc_dmabuf *mp;
344 struct lpfc_nodelist *ndlp;
345 struct serv_parm *sp;
349 sp = &phba->fc_fabparam;
350 ndlp = lpfc_findnode_did(vport, Fabric_DID);
351 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
362 vport->port_state = LPFC_FABRIC_CFG_LINK;
363 lpfc_config_link(phba, mbox);
364 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
367 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
368 if (rc == MBX_NOT_FINISHED) {
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
378 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
384 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
386 /* increment the reference count on ndlp to hold reference
387 * for the callback routine.
389 mbox->context2 = lpfc_nlp_get(ndlp);
391 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
392 if (rc == MBX_NOT_FINISHED) {
394 goto fail_issue_reg_login;
399 fail_issue_reg_login:
400 /* decrement the reference count on ndlp just incremented
401 * for the failed mbox command.
404 mp = (struct lpfc_dmabuf *) mbox->context1;
405 lpfc_mbuf_free(phba, mp->virt, mp->phys);
408 mempool_free(mbox, phba->mbox_mem_pool);
411 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
412 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
413 "0249 Cannot issue Register Fabric login: Err %d\n", err);
418 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
419 * @vport: pointer to a host virtual N_Port data structure.
421 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
422 * the @vport. This mailbox command is necessary for FCoE only.
425 * 0 - successfully issued REG_VFI for @vport
426 * A failure code otherwise.
429 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
431 struct lpfc_hba *phba = vport->phba;
433 struct lpfc_nodelist *ndlp;
434 struct serv_parm *sp;
435 struct lpfc_dmabuf *dmabuf;
438 sp = &phba->fc_fabparam;
439 ndlp = lpfc_findnode_did(vport, Fabric_DID);
440 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
445 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
450 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
453 goto fail_free_dmabuf;
455 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
458 goto fail_free_coherent;
460 vport->port_state = LPFC_FABRIC_CFG_LINK;
461 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
462 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
463 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
464 mboxq->vport = vport;
465 mboxq->context1 = dmabuf;
466 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
467 if (rc == MBX_NOT_FINISHED) {
474 mempool_free(mboxq, phba->mbox_mem_pool);
476 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
480 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
481 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
482 "0289 Issue Register VFI failed: Err %d\n", rc);
487 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
488 * @vport: pointer to a host virtual N_Port data structure.
489 * @ndlp: pointer to a node-list data structure.
490 * @sp: pointer to service parameter data structure.
491 * @irsp: pointer to the IOCB within the lpfc response IOCB.
493 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
494 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
495 * port in a fabric topology. It properly sets up the parameters to the @ndlp
496 * from the IOCB response. It also check the newly assigned N_Port ID to the
497 * @vport against the previously assigned N_Port ID. If it is different from
498 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
499 * is invoked on all the remaining nodes with the @vport to unregister the
500 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
501 * is invoked to register login to the fabric.
504 * 0 - Success (currently, always return 0)
507 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
508 struct serv_parm *sp, IOCB_t *irsp)
510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
511 struct lpfc_hba *phba = vport->phba;
512 struct lpfc_nodelist *np;
513 struct lpfc_nodelist *next_np;
515 spin_lock_irq(shost->host_lock);
516 vport->fc_flag |= FC_FABRIC;
517 spin_unlock_irq(shost->host_lock);
519 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
520 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
521 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
523 phba->fc_edtovResol = sp->cmn.edtovResolution;
524 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
526 if (phba->fc_topology == TOPOLOGY_LOOP) {
527 spin_lock_irq(shost->host_lock);
528 vport->fc_flag |= FC_PUBLIC_LOOP;
529 spin_unlock_irq(shost->host_lock);
532 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
533 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
534 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
535 ndlp->nlp_class_sup = 0;
536 if (sp->cls1.classValid)
537 ndlp->nlp_class_sup |= FC_COS_CLASS1;
538 if (sp->cls2.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS2;
540 if (sp->cls3.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS3;
542 if (sp->cls4.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS4;
544 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
545 sp->cmn.bbRcvSizeLsb;
546 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
548 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
549 if (sp->cmn.response_multiple_NPort) {
550 lpfc_printf_vlog(vport, KERN_WARNING,
552 "1816 FLOGI NPIV supported, "
553 "response data 0x%x\n",
554 sp->cmn.response_multiple_NPort);
555 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
557 /* Because we asked f/w for NPIV it still expects us
558 to call reg_vnpid atleast for the physcial host */
559 lpfc_printf_vlog(vport, KERN_WARNING,
561 "1817 Fabric does not support NPIV "
562 "- configuring single port mode.\n");
563 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
567 if ((vport->fc_prevDID != vport->fc_myDID) &&
568 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
570 /* If our NportID changed, we need to ensure all
571 * remaining NPORTs get unreg_login'ed.
573 list_for_each_entry_safe(np, next_np,
574 &vport->fc_nodes, nlp_listp) {
575 if (!NLP_CHK_NODE_ACT(np))
577 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
578 !(np->nlp_flag & NLP_NPR_ADISC))
580 spin_lock_irq(shost->host_lock);
581 np->nlp_flag &= ~NLP_NPR_ADISC;
582 spin_unlock_irq(shost->host_lock);
583 lpfc_unreg_rpi(vport, np);
585 lpfc_cleanup_pending_mbox(vport);
587 if (phba->sli_rev == LPFC_SLI_REV4)
588 lpfc_sli4_unreg_all_rpis(vport);
590 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
591 lpfc_mbx_unreg_vpi(vport);
592 spin_lock_irq(shost->host_lock);
593 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
594 spin_unlock_irq(shost->host_lock);
597 * If VPI is unreged, driver need to do INIT_VPI
598 * before re-registering
600 if (phba->sli_rev == LPFC_SLI_REV4) {
601 spin_lock_irq(shost->host_lock);
602 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
603 spin_unlock_irq(shost->host_lock);
605 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
606 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
608 * Driver needs to re-reg VPI in order for f/w
609 * to update the MAC address.
611 lpfc_register_new_vport(phba, vport, ndlp);
615 if (phba->sli_rev < LPFC_SLI_REV4) {
616 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
617 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
618 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
619 lpfc_register_new_vport(phba, vport, ndlp);
621 lpfc_issue_fabric_reglogin(vport);
623 ndlp->nlp_type |= NLP_FABRIC;
624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
625 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
626 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
627 lpfc_start_fdiscs(phba);
628 lpfc_do_scr_ns_plogi(phba, vport);
629 } else if (vport->fc_flag & FC_VFI_REGISTERED)
630 lpfc_issue_init_vpi(vport);
632 lpfc_issue_reg_vfi(vport);
637 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
638 * @vport: pointer to a host virtual N_Port data structure.
639 * @ndlp: pointer to a node-list data structure.
640 * @sp: pointer to service parameter data structure.
642 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
643 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
644 * in a point-to-point topology. First, the @vport's N_Port Name is compared
645 * with the received N_Port Name: if the @vport's N_Port Name is greater than
646 * the received N_Port Name lexicographically, this node shall assign local
647 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
648 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
649 * this node shall just wait for the remote node to issue PLOGI and assign
657 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 struct serv_parm *sp)
660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
661 struct lpfc_hba *phba = vport->phba;
665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
667 spin_unlock_irq(shost->host_lock);
669 phba->fc_edtov = FF_DEF_EDTOV;
670 phba->fc_ratov = FF_DEF_RATOV;
671 rc = memcmp(&vport->fc_portname, &sp->portName,
672 sizeof(vport->fc_portname));
674 /* This side will initiate the PLOGI */
675 spin_lock_irq(shost->host_lock);
676 vport->fc_flag |= FC_PT2PT_PLOGI;
677 spin_unlock_irq(shost->host_lock);
680 * N_Port ID cannot be 0, set our to LocalID the other
681 * side will be RemoteID.
686 vport->fc_myDID = PT2PT_LocalID;
688 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
692 lpfc_config_link(phba, mbox);
694 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
696 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
697 if (rc == MBX_NOT_FINISHED) {
698 mempool_free(mbox, phba->mbox_mem_pool);
701 /* Decrement ndlp reference count indicating that ndlp can be
702 * safely released when other references to it are done.
706 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
709 * Cannot find existing Fabric ndlp, so allocate a
712 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
715 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
716 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
717 ndlp = lpfc_enable_node(vport, ndlp,
718 NLP_STE_UNUSED_NODE);
723 memcpy(&ndlp->nlp_portname, &sp->portName,
724 sizeof(struct lpfc_name));
725 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
726 sizeof(struct lpfc_name));
727 /* Set state will put ndlp onto node list if not already done */
728 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
729 spin_lock_irq(shost->host_lock);
730 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
731 spin_unlock_irq(shost->host_lock);
733 /* This side will wait for the PLOGI, decrement ndlp reference
734 * count indicating that ndlp can be released when other
735 * references to it are done.
739 /* If we are pt2pt with another NPort, force NPIV off! */
740 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
742 spin_lock_irq(shost->host_lock);
743 vport->fc_flag |= FC_PT2PT;
744 spin_unlock_irq(shost->host_lock);
746 /* Start discovery - this should just do CLEAR_LA */
747 lpfc_disc_start(vport);
754 * lpfc_cmpl_els_flogi - Completion callback function for flogi
755 * @phba: pointer to lpfc hba data structure.
756 * @cmdiocb: pointer to lpfc command iocb data structure.
757 * @rspiocb: pointer to lpfc response iocb data structure.
759 * This routine is the top-level completion callback function for issuing
760 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
761 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
762 * retry has been made (either immediately or delayed with lpfc_els_retry()
763 * returning 1), the command IOCB will be released and function returned.
764 * If the retry attempt has been given up (possibly reach the maximum
765 * number of retries), one additional decrement of ndlp reference shall be
766 * invoked before going out after releasing the command IOCB. This will
767 * actually release the remote node (Note, lpfc_els_free_iocb() will also
768 * invoke one decrement of ndlp reference count). If no error reported in
769 * the IOCB status, the command Port ID field is used to determine whether
770 * this is a point-to-point topology or a fabric topology: if the Port ID
771 * field is assigned, it is a fabric topology; otherwise, it is a
772 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
773 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
774 * specific topology completion conditions.
777 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
778 struct lpfc_iocbq *rspiocb)
780 struct lpfc_vport *vport = cmdiocb->vport;
781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
782 IOCB_t *irsp = &rspiocb->iocb;
783 struct lpfc_nodelist *ndlp = cmdiocb->context1;
784 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
785 struct serv_parm *sp;
789 /* Check to see if link went down during discovery */
790 if (lpfc_els_chk_latt(vport)) {
791 /* One additional decrement on node reference count to
792 * trigger the release of the node
798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
799 "FLOGI cmpl: status:x%x/x%x state:x%x",
800 irsp->ulpStatus, irsp->un.ulpWord[4],
803 if (irsp->ulpStatus) {
805 * In case of FIP mode, perform roundrobin FCF failover
806 * due to new FCF discovery
808 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
809 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
810 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
811 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
812 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
813 "2611 FLOGI failed on FCF (x%x), "
814 "status:x%x/x%x, tmo:x%x, perform "
815 "roundrobin FCF failover\n",
816 phba->fcf.current_rec.fcf_indx,
817 irsp->ulpStatus, irsp->un.ulpWord[4],
819 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
820 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
826 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
827 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
828 irsp->ulpStatus, irsp->un.ulpWord[4],
831 /* Check for retry */
832 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
835 /* FLOGI failed, so there is no fabric */
836 spin_lock_irq(shost->host_lock);
837 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
838 spin_unlock_irq(shost->host_lock);
840 /* If private loop, then allow max outstanding els to be
841 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
842 * alpa map would take too long otherwise.
844 if (phba->alpa_map[0] == 0) {
845 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
849 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
850 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
851 irsp->ulpStatus, irsp->un.ulpWord[4],
855 spin_lock_irq(shost->host_lock);
856 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
857 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
858 spin_unlock_irq(shost->host_lock);
861 * The FLogI succeeded. Sync the data for the CPU before
864 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
866 sp = prsp->virt + sizeof(uint32_t);
868 /* FLOGI completes successfully */
869 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
870 "0101 FLOGI completes successfully "
871 "Data: x%x x%x x%x x%x\n",
872 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
873 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
875 if (vport->port_state == LPFC_FLOGI) {
877 * If Common Service Parameters indicate Nport
878 * we are point to point, if Fport we are Fabric.
881 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
882 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
883 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
885 lpfc_printf_vlog(vport, KERN_ERR,
887 "2831 FLOGI response with cleared Fabric "
888 "bit fcf_index 0x%x "
889 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
891 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
892 phba->fcf.current_rec.fcf_indx,
893 phba->fcf.current_rec.switch_name[0],
894 phba->fcf.current_rec.switch_name[1],
895 phba->fcf.current_rec.switch_name[2],
896 phba->fcf.current_rec.switch_name[3],
897 phba->fcf.current_rec.switch_name[4],
898 phba->fcf.current_rec.switch_name[5],
899 phba->fcf.current_rec.switch_name[6],
900 phba->fcf.current_rec.switch_name[7],
901 phba->fcf.current_rec.fabric_name[0],
902 phba->fcf.current_rec.fabric_name[1],
903 phba->fcf.current_rec.fabric_name[2],
904 phba->fcf.current_rec.fabric_name[3],
905 phba->fcf.current_rec.fabric_name[4],
906 phba->fcf.current_rec.fabric_name[5],
907 phba->fcf.current_rec.fabric_name[6],
908 phba->fcf.current_rec.fabric_name[7]);
910 spin_lock_irq(&phba->hbalock);
911 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
912 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
913 spin_unlock_irq(&phba->hbalock);
917 /* Mark the FCF discovery process done */
918 if (phba->hba_flag & HBA_FIP_SUPPORT)
919 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
921 "2769 FLOGI to FCF (x%x) "
922 "completed successfully\n",
923 phba->fcf.current_rec.fcf_indx);
924 spin_lock_irq(&phba->hbalock);
925 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
926 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
927 spin_unlock_irq(&phba->hbalock);
935 if (!lpfc_error_lost_link(irsp)) {
936 /* FLOGI failed, so just use loop map to make discovery list */
937 lpfc_disc_list_loopmap(vport);
939 /* Start discovery */
940 lpfc_disc_start(vport);
941 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
942 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
943 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
944 (phba->link_state != LPFC_CLEAR_LA)) {
945 /* If FLOGI failed enable link interrupt. */
946 lpfc_issue_clear_la(phba, vport);
949 lpfc_els_free_iocb(phba, cmdiocb);
953 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
954 * @vport: pointer to a host virtual N_Port data structure.
955 * @ndlp: pointer to a node-list data structure.
956 * @retry: number of retries to the command IOCB.
958 * This routine issues a Fabric Login (FLOGI) Request ELS command
959 * for a @vport. The initiator service parameters are put into the payload
960 * of the FLOGI Request IOCB and the top-level callback function pointer
961 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
962 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
963 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
965 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
966 * will be incremented by 1 for holding the ndlp and the reference to ndlp
967 * will be stored into the context1 field of the IOCB for the completion
968 * callback function to the FLOGI ELS command.
971 * 0 - successfully issued flogi iocb for @vport
972 * 1 - failed to issue flogi iocb for @vport
975 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
978 struct lpfc_hba *phba = vport->phba;
979 struct serv_parm *sp;
981 struct lpfc_iocbq *elsiocb;
982 struct lpfc_sli_ring *pring;
988 pring = &phba->sli.ring[LPFC_ELS_RING];
990 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
991 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
992 ndlp->nlp_DID, ELS_CMD_FLOGI);
997 icmd = &elsiocb->iocb;
998 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1000 /* For FLOGI request, remainder of payload is service parameters */
1001 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1002 pcmd += sizeof(uint32_t);
1003 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1004 sp = (struct serv_parm *) pcmd;
1006 /* Setup CSPs accordingly for Fabric */
1007 sp->cmn.e_d_tov = 0;
1008 sp->cmn.w2.r_a_tov = 0;
1009 sp->cls1.classValid = 0;
1010 sp->cls2.seqDelivery = 1;
1011 sp->cls3.seqDelivery = 1;
1012 if (sp->cmn.fcphLow < FC_PH3)
1013 sp->cmn.fcphLow = FC_PH3;
1014 if (sp->cmn.fcphHigh < FC_PH3)
1015 sp->cmn.fcphHigh = FC_PH3;
1017 if (phba->sli_rev == LPFC_SLI_REV4) {
1018 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1019 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1020 /* FLOGI needs to be 3 for WQE FCFI */
1021 /* Set the fcfi to the fcfi we registered with */
1022 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1023 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1024 sp->cmn.request_multiple_Nport = 1;
1025 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1030 if (phba->fc_topology != TOPOLOGY_LOOP) {
1031 icmd->un.elsreq64.myID = 0;
1032 icmd->un.elsreq64.fl = 1;
1035 tmo = phba->fc_ratov;
1036 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1037 lpfc_set_disctmo(vport);
1038 phba->fc_ratov = tmo;
1040 phba->fc_stat.elsXmitFLOGI++;
1041 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1044 "Issue FLOGI: opt:x%x",
1045 phba->sli3_options, 0, 0);
1047 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1048 if (rc == IOCB_ERROR) {
1049 lpfc_els_free_iocb(phba, elsiocb);
1056 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1057 * @phba: pointer to lpfc hba data structure.
1059 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1060 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1061 * list and issues an abort IOCB commond on each outstanding IOCB that
1062 * contains a active Fabric_DID ndlp. Note that this function is to issue
1063 * the abort IOCB command on all the outstanding IOCBs, thus when this
1064 * function returns, it does not guarantee all the IOCBs are actually aborted.
1067 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1070 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1072 struct lpfc_sli_ring *pring;
1073 struct lpfc_iocbq *iocb, *next_iocb;
1074 struct lpfc_nodelist *ndlp;
1077 /* Abort outstanding I/O on NPort <nlp_DID> */
1078 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1079 "0201 Abort outstanding I/O on NPort x%x\n",
1082 pring = &phba->sli.ring[LPFC_ELS_RING];
1085 * Check the txcmplq for an iocb that matches the nport the driver is
1088 spin_lock_irq(&phba->hbalock);
1089 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1091 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1092 icmd->un.elsreq64.bdl.ulpIoTag32) {
1093 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1094 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1095 (ndlp->nlp_DID == Fabric_DID))
1096 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1099 spin_unlock_irq(&phba->hbalock);
1105 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1106 * @vport: pointer to a host virtual N_Port data structure.
1108 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1109 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1110 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1111 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1112 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1113 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1117 * 0 - failed to issue initial flogi for @vport
1118 * 1 - successfully issued initial flogi for @vport
1121 lpfc_initial_flogi(struct lpfc_vport *vport)
1123 struct lpfc_hba *phba = vport->phba;
1124 struct lpfc_nodelist *ndlp;
1126 vport->port_state = LPFC_FLOGI;
1127 lpfc_set_disctmo(vport);
1129 /* First look for the Fabric ndlp */
1130 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1132 /* Cannot find existing Fabric ndlp, so allocate a new one */
1133 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1136 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1137 /* Set the node type */
1138 ndlp->nlp_type |= NLP_FABRIC;
1139 /* Put ndlp onto node list */
1140 lpfc_enqueue_node(vport, ndlp);
1141 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1142 /* re-setup ndlp without removing from node list */
1143 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1148 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1149 /* This decrement of reference count to node shall kick off
1150 * the release of the node.
1159 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1160 * @vport: pointer to a host virtual N_Port data structure.
1162 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1163 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1164 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1165 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1166 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1167 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1171 * 0 - failed to issue initial fdisc for @vport
1172 * 1 - successfully issued initial fdisc for @vport
1175 lpfc_initial_fdisc(struct lpfc_vport *vport)
1177 struct lpfc_hba *phba = vport->phba;
1178 struct lpfc_nodelist *ndlp;
1180 /* First look for the Fabric ndlp */
1181 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1183 /* Cannot find existing Fabric ndlp, so allocate a new one */
1184 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1187 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1188 /* Put ndlp onto node list */
1189 lpfc_enqueue_node(vport, ndlp);
1190 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1191 /* re-setup ndlp without removing from node list */
1192 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1197 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1198 /* decrement node reference count to trigger the release of
1208 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1209 * @vport: pointer to a host virtual N_Port data structure.
1211 * This routine checks whether there are more remaining Port Logins
1212 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1213 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1214 * to issue ELS PLOGIs up to the configured discover threads with the
1215 * @vport (@vport->cfg_discovery_threads). The function also decrement
1216 * the @vport's num_disc_node by 1 if it is not already 0.
1219 lpfc_more_plogi(struct lpfc_vport *vport)
1223 if (vport->num_disc_nodes)
1224 vport->num_disc_nodes--;
1226 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1227 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1228 "0232 Continue discovery with %d PLOGIs to go "
1229 "Data: x%x x%x x%x\n",
1230 vport->num_disc_nodes, vport->fc_plogi_cnt,
1231 vport->fc_flag, vport->port_state);
1232 /* Check to see if there are more PLOGIs to be sent */
1233 if (vport->fc_flag & FC_NLP_MORE)
1234 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1235 sentplogi = lpfc_els_disc_plogi(vport);
1241 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1242 * @phba: pointer to lpfc hba data structure.
1243 * @prsp: pointer to response IOCB payload.
1244 * @ndlp: pointer to a node-list data structure.
1246 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1247 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1248 * The following cases are considered N_Port confirmed:
1249 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1250 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1251 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1252 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1253 * 1) if there is a node on vport list other than the @ndlp with the same
1254 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1255 * on that node to release the RPI associated with the node; 2) if there is
1256 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1257 * into, a new node shall be allocated (or activated). In either case, the
1258 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1259 * be released and the new_ndlp shall be put on to the vport node list and
1260 * its pointer returned as the confirmed node.
1262 * Note that before the @ndlp got "released", the keepDID from not-matching
1263 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1264 * of the @ndlp. This is because the release of @ndlp is actually to put it
1265 * into an inactive state on the vport node list and the vport node list
1266 * management algorithm does not allow two node with a same DID.
1269 * pointer to the PLOGI N_Port @ndlp
1271 static struct lpfc_nodelist *
1272 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1273 struct lpfc_nodelist *ndlp)
1275 struct lpfc_vport *vport = ndlp->vport;
1276 struct lpfc_nodelist *new_ndlp;
1277 struct lpfc_rport_data *rdata;
1278 struct fc_rport *rport;
1279 struct serv_parm *sp;
1280 uint8_t name[sizeof(struct lpfc_name)];
1281 uint32_t rc, keepDID = 0;
1285 /* Fabric nodes can have the same WWPN so we don't bother searching
1286 * by WWPN. Just return the ndlp that was given to us.
1288 if (ndlp->nlp_type & NLP_FABRIC)
1291 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1292 memset(name, 0, sizeof(struct lpfc_name));
1294 /* Now we find out if the NPort we are logging into, matches the WWPN
1295 * we have for that ndlp. If not, we have some work to do.
1297 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1299 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1303 rc = memcmp(&ndlp->nlp_portname, name,
1304 sizeof(struct lpfc_name));
1307 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1310 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1311 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1312 rc = memcmp(&ndlp->nlp_portname, name,
1313 sizeof(struct lpfc_name));
1316 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1317 NLP_STE_UNUSED_NODE);
1320 keepDID = new_ndlp->nlp_DID;
1322 keepDID = new_ndlp->nlp_DID;
1324 lpfc_unreg_rpi(vport, new_ndlp);
1325 new_ndlp->nlp_DID = ndlp->nlp_DID;
1326 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1328 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1329 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1330 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1332 /* Set state will put new_ndlp on to node list if not already done */
1333 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1335 /* Move this back to NPR state */
1336 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1337 /* The new_ndlp is replacing ndlp totally, so we need
1338 * to put ndlp on UNUSED list and try to free it.
1341 /* Fix up the rport accordingly */
1342 rport = ndlp->rport;
1344 rdata = rport->dd_data;
1345 if (rdata->pnode == ndlp) {
1348 rdata->pnode = lpfc_nlp_get(new_ndlp);
1349 new_ndlp->rport = rport;
1351 new_ndlp->nlp_type = ndlp->nlp_type;
1353 /* We shall actually free the ndlp with both nlp_DID and
1354 * nlp_portname fields equals 0 to avoid any ndlp on the
1355 * nodelist never to be used.
1357 if (ndlp->nlp_DID == 0) {
1358 spin_lock_irq(&phba->ndlp_lock);
1359 NLP_SET_FREE_REQ(ndlp);
1360 spin_unlock_irq(&phba->ndlp_lock);
1363 /* Two ndlps cannot have the same did on the nodelist */
1364 ndlp->nlp_DID = keepDID;
1365 lpfc_drop_node(vport, ndlp);
1368 lpfc_unreg_rpi(vport, ndlp);
1369 /* Two ndlps cannot have the same did */
1370 ndlp->nlp_DID = keepDID;
1371 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1372 /* Since we are swapping the ndlp passed in with the new one
1373 * and the did has already been swapped, copy over the
1376 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1377 sizeof(struct lpfc_name));
1378 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1379 sizeof(struct lpfc_name));
1380 new_ndlp->nlp_state = ndlp->nlp_state;
1381 /* Fix up the rport accordingly */
1382 rport = ndlp->rport;
1384 rdata = rport->dd_data;
1385 put_node = rdata->pnode != NULL;
1386 put_rport = ndlp->rport != NULL;
1387 rdata->pnode = NULL;
1392 put_device(&rport->dev);
1399 * lpfc_end_rscn - Check and handle more rscn for a vport
1400 * @vport: pointer to a host virtual N_Port data structure.
1402 * This routine checks whether more Registration State Change
1403 * Notifications (RSCNs) came in while the discovery state machine was in
1404 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1405 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1406 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1407 * handling the RSCNs.
1410 lpfc_end_rscn(struct lpfc_vport *vport)
1412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1414 if (vport->fc_flag & FC_RSCN_MODE) {
1416 * Check to see if more RSCNs came in while we were
1417 * processing this one.
1419 if (vport->fc_rscn_id_cnt ||
1420 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1421 lpfc_els_handle_rscn(vport);
1423 spin_lock_irq(shost->host_lock);
1424 vport->fc_flag &= ~FC_RSCN_MODE;
1425 spin_unlock_irq(shost->host_lock);
1431 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1432 * @phba: pointer to lpfc hba data structure.
1433 * @cmdiocb: pointer to lpfc command iocb data structure.
1434 * @rspiocb: pointer to lpfc response iocb data structure.
1436 * This routine is the completion callback function for issuing the Port
1437 * Login (PLOGI) command. For PLOGI completion, there must be an active
1438 * ndlp on the vport node list that matches the remote node ID from the
1439 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1440 * ignored and command IOCB released. The PLOGI response IOCB status is
1441 * checked for error conditons. If there is error status reported, PLOGI
1442 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1443 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1444 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1445 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1446 * there are additional N_Port nodes with the vport that need to perform
1447 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1451 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1452 struct lpfc_iocbq *rspiocb)
1454 struct lpfc_vport *vport = cmdiocb->vport;
1455 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1457 struct lpfc_nodelist *ndlp;
1458 struct lpfc_dmabuf *prsp;
1459 int disc, rc, did, type;
1461 /* we pass cmdiocb to state machine which needs rspiocb as well */
1462 cmdiocb->context_un.rsp_iocb = rspiocb;
1464 irsp = &rspiocb->iocb;
1465 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1466 "PLOGI cmpl: status:x%x/x%x did:x%x",
1467 irsp->ulpStatus, irsp->un.ulpWord[4],
1468 irsp->un.elsreq64.remoteID);
1470 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1471 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1472 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1473 "0136 PLOGI completes to NPort x%x "
1474 "with no ndlp. Data: x%x x%x x%x\n",
1475 irsp->un.elsreq64.remoteID,
1476 irsp->ulpStatus, irsp->un.ulpWord[4],
1481 /* Since ndlp can be freed in the disc state machine, note if this node
1482 * is being used during discovery.
1484 spin_lock_irq(shost->host_lock);
1485 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1486 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1487 spin_unlock_irq(shost->host_lock);
1490 /* PLOGI completes to NPort <nlp_DID> */
1491 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1492 "0102 PLOGI completes to NPort x%x "
1493 "Data: x%x x%x x%x x%x x%x\n",
1494 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1495 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1496 /* Check to see if link went down during discovery */
1497 if (lpfc_els_chk_latt(vport)) {
1498 spin_lock_irq(shost->host_lock);
1499 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1500 spin_unlock_irq(shost->host_lock);
1504 /* ndlp could be freed in DSM, save these values now */
1505 type = ndlp->nlp_type;
1506 did = ndlp->nlp_DID;
1508 if (irsp->ulpStatus) {
1509 /* Check for retry */
1510 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1511 /* ELS command is being retried */
1513 spin_lock_irq(shost->host_lock);
1514 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1515 spin_unlock_irq(shost->host_lock);
1519 /* PLOGI failed Don't print the vport to vport rjts */
1520 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1521 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1522 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1523 (phba)->pport->cfg_log_verbose & LOG_ELS)
1524 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1525 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1526 ndlp->nlp_DID, irsp->ulpStatus,
1527 irsp->un.ulpWord[4]);
1528 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1529 if (lpfc_error_lost_link(irsp))
1530 rc = NLP_STE_FREED_NODE;
1532 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1533 NLP_EVT_CMPL_PLOGI);
1535 /* Good status, call state machine */
1536 prsp = list_entry(((struct lpfc_dmabuf *)
1537 cmdiocb->context2)->list.next,
1538 struct lpfc_dmabuf, list);
1539 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1540 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1541 NLP_EVT_CMPL_PLOGI);
1544 if (disc && vport->num_disc_nodes) {
1545 /* Check to see if there are more PLOGIs to be sent */
1546 lpfc_more_plogi(vport);
1548 if (vport->num_disc_nodes == 0) {
1549 spin_lock_irq(shost->host_lock);
1550 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1551 spin_unlock_irq(shost->host_lock);
1553 lpfc_can_disctmo(vport);
1554 lpfc_end_rscn(vport);
1559 lpfc_els_free_iocb(phba, cmdiocb);
1564 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1565 * @vport: pointer to a host virtual N_Port data structure.
1566 * @did: destination port identifier.
1567 * @retry: number of retries to the command IOCB.
1569 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1570 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1571 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1572 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1573 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1575 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1576 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1577 * will be stored into the context1 field of the IOCB for the completion
1578 * callback function to the PLOGI ELS command.
1581 * 0 - Successfully issued a plogi for @vport
1582 * 1 - failed to issue a plogi for @vport
1585 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1587 struct lpfc_hba *phba = vport->phba;
1588 struct serv_parm *sp;
1590 struct lpfc_nodelist *ndlp;
1591 struct lpfc_iocbq *elsiocb;
1592 struct lpfc_sli *psli;
1599 ndlp = lpfc_findnode_did(vport, did);
1600 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1603 /* If ndlp is not NULL, we will bump the reference count on it */
1604 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1605 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1610 icmd = &elsiocb->iocb;
1611 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1613 /* For PLOGI request, remainder of payload is service parameters */
1614 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1615 pcmd += sizeof(uint32_t);
1616 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1617 sp = (struct serv_parm *) pcmd;
1620 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1621 * to device on remote loops work.
1623 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1624 sp->cmn.altBbCredit = 1;
1626 if (sp->cmn.fcphLow < FC_PH_4_3)
1627 sp->cmn.fcphLow = FC_PH_4_3;
1629 if (sp->cmn.fcphHigh < FC_PH3)
1630 sp->cmn.fcphHigh = FC_PH3;
1632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1633 "Issue PLOGI: did:x%x",
1636 phba->fc_stat.elsXmitPLOGI++;
1637 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1638 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1640 if (ret == IOCB_ERROR) {
1641 lpfc_els_free_iocb(phba, elsiocb);
1648 * lpfc_cmpl_els_prli - Completion callback function for prli
1649 * @phba: pointer to lpfc hba data structure.
1650 * @cmdiocb: pointer to lpfc command iocb data structure.
1651 * @rspiocb: pointer to lpfc response iocb data structure.
1653 * This routine is the completion callback function for a Process Login
1654 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1655 * status. If there is error status reported, PRLI retry shall be attempted
1656 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1657 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1658 * ndlp to mark the PRLI completion.
1661 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1662 struct lpfc_iocbq *rspiocb)
1664 struct lpfc_vport *vport = cmdiocb->vport;
1665 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1667 struct lpfc_sli *psli;
1668 struct lpfc_nodelist *ndlp;
1671 /* we pass cmdiocb to state machine which needs rspiocb as well */
1672 cmdiocb->context_un.rsp_iocb = rspiocb;
1674 irsp = &(rspiocb->iocb);
1675 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1676 spin_lock_irq(shost->host_lock);
1677 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1678 spin_unlock_irq(shost->host_lock);
1680 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1681 "PRLI cmpl: status:x%x/x%x did:x%x",
1682 irsp->ulpStatus, irsp->un.ulpWord[4],
1684 /* PRLI completes to NPort <nlp_DID> */
1685 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1686 "0103 PRLI completes to NPort x%x "
1687 "Data: x%x x%x x%x x%x\n",
1688 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1689 irsp->ulpTimeout, vport->num_disc_nodes);
1691 vport->fc_prli_sent--;
1692 /* Check to see if link went down during discovery */
1693 if (lpfc_els_chk_latt(vport))
1696 if (irsp->ulpStatus) {
1697 /* Check for retry */
1698 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1699 /* ELS command is being retried */
1703 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1704 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1705 ndlp->nlp_DID, irsp->ulpStatus,
1706 irsp->un.ulpWord[4]);
1707 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1708 if (lpfc_error_lost_link(irsp))
1711 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1714 /* Good status, call state machine */
1715 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1718 lpfc_els_free_iocb(phba, cmdiocb);
1723 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1724 * @vport: pointer to a host virtual N_Port data structure.
1725 * @ndlp: pointer to a node-list data structure.
1726 * @retry: number of retries to the command IOCB.
1728 * This routine issues a Process Login (PRLI) ELS command for the
1729 * @vport. The PRLI service parameters are set up in the payload of the
1730 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1731 * is put to the IOCB completion callback func field before invoking the
1732 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1734 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1735 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1736 * will be stored into the context1 field of the IOCB for the completion
1737 * callback function to the PRLI ELS command.
1740 * 0 - successfully issued prli iocb command for @vport
1741 * 1 - failed to issue prli iocb command for @vport
1744 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1747 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1748 struct lpfc_hba *phba = vport->phba;
1751 struct lpfc_iocbq *elsiocb;
1755 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1756 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1757 ndlp->nlp_DID, ELS_CMD_PRLI);
1761 icmd = &elsiocb->iocb;
1762 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1764 /* For PRLI request, remainder of payload is service parameters */
1765 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1766 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1767 pcmd += sizeof(uint32_t);
1769 /* For PRLI, remainder of payload is PRLI parameter page */
1770 npr = (PRLI *) pcmd;
1772 * If our firmware version is 3.20 or later,
1773 * set the following bits for FC-TAPE support.
1775 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1776 npr->ConfmComplAllowed = 1;
1778 npr->TaskRetryIdReq = 1;
1780 npr->estabImagePair = 1;
1781 npr->readXferRdyDis = 1;
1783 /* For FCP support */
1784 npr->prliType = PRLI_FCP_TYPE;
1785 npr->initiatorFunc = 1;
1787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1788 "Issue PRLI: did:x%x",
1789 ndlp->nlp_DID, 0, 0);
1791 phba->fc_stat.elsXmitPRLI++;
1792 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1793 spin_lock_irq(shost->host_lock);
1794 ndlp->nlp_flag |= NLP_PRLI_SND;
1795 spin_unlock_irq(shost->host_lock);
1796 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1798 spin_lock_irq(shost->host_lock);
1799 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1800 spin_unlock_irq(shost->host_lock);
1801 lpfc_els_free_iocb(phba, elsiocb);
1804 vport->fc_prli_sent++;
1809 * lpfc_rscn_disc - Perform rscn discovery for a vport
1810 * @vport: pointer to a host virtual N_Port data structure.
1812 * This routine performs Registration State Change Notification (RSCN)
1813 * discovery for a @vport. If the @vport's node port recovery count is not
1814 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1815 * the nodes that need recovery. If none of the PLOGI were needed through
1816 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1817 * invoked to check and handle possible more RSCN came in during the period
1818 * of processing the current ones.
1821 lpfc_rscn_disc(struct lpfc_vport *vport)
1823 lpfc_can_disctmo(vport);
1825 /* RSCN discovery */
1826 /* go thru NPR nodes and issue ELS PLOGIs */
1827 if (vport->fc_npr_cnt)
1828 if (lpfc_els_disc_plogi(vport))
1831 lpfc_end_rscn(vport);
1835 * lpfc_adisc_done - Complete the adisc phase of discovery
1836 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1838 * This function is called when the final ADISC is completed during discovery.
1839 * This function handles clearing link attention or issuing reg_vpi depending
1840 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1842 * This function is called with no locks held.
1845 lpfc_adisc_done(struct lpfc_vport *vport)
1847 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1848 struct lpfc_hba *phba = vport->phba;
1851 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1852 * and continue discovery.
1854 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1855 !(vport->fc_flag & FC_RSCN_MODE) &&
1856 (phba->sli_rev < LPFC_SLI_REV4)) {
1857 lpfc_issue_reg_vpi(phba, vport);
1861 * For SLI2, we need to set port_state to READY
1862 * and continue discovery.
1864 if (vport->port_state < LPFC_VPORT_READY) {
1865 /* If we get here, there is nothing to ADISC */
1866 if (vport->port_type == LPFC_PHYSICAL_PORT)
1867 lpfc_issue_clear_la(phba, vport);
1868 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1869 vport->num_disc_nodes = 0;
1870 /* go thru NPR list, issue ELS PLOGIs */
1871 if (vport->fc_npr_cnt)
1872 lpfc_els_disc_plogi(vport);
1873 if (!vport->num_disc_nodes) {
1874 spin_lock_irq(shost->host_lock);
1875 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1876 spin_unlock_irq(shost->host_lock);
1877 lpfc_can_disctmo(vport);
1878 lpfc_end_rscn(vport);
1881 vport->port_state = LPFC_VPORT_READY;
1883 lpfc_rscn_disc(vport);
1887 * lpfc_more_adisc - Issue more adisc as needed
1888 * @vport: pointer to a host virtual N_Port data structure.
1890 * This routine determines whether there are more ndlps on a @vport
1891 * node list need to have Address Discover (ADISC) issued. If so, it will
1892 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1893 * remaining nodes which need to have ADISC sent.
1896 lpfc_more_adisc(struct lpfc_vport *vport)
1900 if (vport->num_disc_nodes)
1901 vport->num_disc_nodes--;
1902 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1903 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1904 "0210 Continue discovery with %d ADISCs to go "
1905 "Data: x%x x%x x%x\n",
1906 vport->num_disc_nodes, vport->fc_adisc_cnt,
1907 vport->fc_flag, vport->port_state);
1908 /* Check to see if there are more ADISCs to be sent */
1909 if (vport->fc_flag & FC_NLP_MORE) {
1910 lpfc_set_disctmo(vport);
1911 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1912 sentadisc = lpfc_els_disc_adisc(vport);
1914 if (!vport->num_disc_nodes)
1915 lpfc_adisc_done(vport);
1920 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1921 * @phba: pointer to lpfc hba data structure.
1922 * @cmdiocb: pointer to lpfc command iocb data structure.
1923 * @rspiocb: pointer to lpfc response iocb data structure.
1925 * This routine is the completion function for issuing the Address Discover
1926 * (ADISC) command. It first checks to see whether link went down during
1927 * the discovery process. If so, the node will be marked as node port
1928 * recovery for issuing discover IOCB by the link attention handler and
1929 * exit. Otherwise, the response status is checked. If error was reported
1930 * in the response status, the ADISC command shall be retried by invoking
1931 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1932 * the response status, the state machine is invoked to set transition
1933 * with respect to NLP_EVT_CMPL_ADISC event.
1936 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1937 struct lpfc_iocbq *rspiocb)
1939 struct lpfc_vport *vport = cmdiocb->vport;
1940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1942 struct lpfc_nodelist *ndlp;
1945 /* we pass cmdiocb to state machine which needs rspiocb as well */
1946 cmdiocb->context_un.rsp_iocb = rspiocb;
1948 irsp = &(rspiocb->iocb);
1949 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1951 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1952 "ADISC cmpl: status:x%x/x%x did:x%x",
1953 irsp->ulpStatus, irsp->un.ulpWord[4],
1956 /* Since ndlp can be freed in the disc state machine, note if this node
1957 * is being used during discovery.
1959 spin_lock_irq(shost->host_lock);
1960 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1961 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1962 spin_unlock_irq(shost->host_lock);
1963 /* ADISC completes to NPort <nlp_DID> */
1964 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1965 "0104 ADISC completes to NPort x%x "
1966 "Data: x%x x%x x%x x%x x%x\n",
1967 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1968 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1969 /* Check to see if link went down during discovery */
1970 if (lpfc_els_chk_latt(vport)) {
1971 spin_lock_irq(shost->host_lock);
1972 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1973 spin_unlock_irq(shost->host_lock);
1977 if (irsp->ulpStatus) {
1978 /* Check for retry */
1979 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1980 /* ELS command is being retried */
1982 spin_lock_irq(shost->host_lock);
1983 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1984 spin_unlock_irq(shost->host_lock);
1985 lpfc_set_disctmo(vport);
1990 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1991 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1992 ndlp->nlp_DID, irsp->ulpStatus,
1993 irsp->un.ulpWord[4]);
1994 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1995 if (!lpfc_error_lost_link(irsp))
1996 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1997 NLP_EVT_CMPL_ADISC);
1999 /* Good status, call state machine */
2000 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2001 NLP_EVT_CMPL_ADISC);
2003 /* Check to see if there are more ADISCs to be sent */
2004 if (disc && vport->num_disc_nodes)
2005 lpfc_more_adisc(vport);
2007 lpfc_els_free_iocb(phba, cmdiocb);
2012 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2013 * @vport: pointer to a virtual N_Port data structure.
2014 * @ndlp: pointer to a node-list data structure.
2015 * @retry: number of retries to the command IOCB.
2017 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2018 * @vport. It prepares the payload of the ADISC ELS command, updates the
2019 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2020 * to issue the ADISC ELS command.
2022 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2023 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2024 * will be stored into the context1 field of the IOCB for the completion
2025 * callback function to the ADISC ELS command.
2028 * 0 - successfully issued adisc
2029 * 1 - failed to issue adisc
2032 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2035 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2036 struct lpfc_hba *phba = vport->phba;
2039 struct lpfc_iocbq *elsiocb;
2043 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2044 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2045 ndlp->nlp_DID, ELS_CMD_ADISC);
2049 icmd = &elsiocb->iocb;
2050 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2052 /* For ADISC request, remainder of payload is service parameters */
2053 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2054 pcmd += sizeof(uint32_t);
2056 /* Fill in ADISC payload */
2057 ap = (ADISC *) pcmd;
2058 ap->hardAL_PA = phba->fc_pref_ALPA;
2059 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2060 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2061 ap->DID = be32_to_cpu(vport->fc_myDID);
2063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2064 "Issue ADISC: did:x%x",
2065 ndlp->nlp_DID, 0, 0);
2067 phba->fc_stat.elsXmitADISC++;
2068 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2069 spin_lock_irq(shost->host_lock);
2070 ndlp->nlp_flag |= NLP_ADISC_SND;
2071 spin_unlock_irq(shost->host_lock);
2072 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2074 spin_lock_irq(shost->host_lock);
2075 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2076 spin_unlock_irq(shost->host_lock);
2077 lpfc_els_free_iocb(phba, elsiocb);
2084 * lpfc_cmpl_els_logo - Completion callback function for logo
2085 * @phba: pointer to lpfc hba data structure.
2086 * @cmdiocb: pointer to lpfc command iocb data structure.
2087 * @rspiocb: pointer to lpfc response iocb data structure.
2089 * This routine is the completion function for issuing the ELS Logout (LOGO)
2090 * command. If no error status was reported from the LOGO response, the
2091 * state machine of the associated ndlp shall be invoked for transition with
2092 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2093 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2096 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2097 struct lpfc_iocbq *rspiocb)
2099 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2100 struct lpfc_vport *vport = ndlp->vport;
2101 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2103 struct lpfc_sli *psli;
2106 /* we pass cmdiocb to state machine which needs rspiocb as well */
2107 cmdiocb->context_un.rsp_iocb = rspiocb;
2109 irsp = &(rspiocb->iocb);
2110 spin_lock_irq(shost->host_lock);
2111 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2112 spin_unlock_irq(shost->host_lock);
2114 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2115 "LOGO cmpl: status:x%x/x%x did:x%x",
2116 irsp->ulpStatus, irsp->un.ulpWord[4],
2118 /* LOGO completes to NPort <nlp_DID> */
2119 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2120 "0105 LOGO completes to NPort x%x "
2121 "Data: x%x x%x x%x x%x\n",
2122 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2123 irsp->ulpTimeout, vport->num_disc_nodes);
2124 /* Check to see if link went down during discovery */
2125 if (lpfc_els_chk_latt(vport))
2128 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2129 /* NLP_EVT_DEVICE_RM should unregister the RPI
2130 * which should abort all outstanding IOs.
2132 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2137 if (irsp->ulpStatus) {
2138 /* Check for retry */
2139 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
2140 /* ELS command is being retried */
2143 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2144 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2145 ndlp->nlp_DID, irsp->ulpStatus,
2146 irsp->un.ulpWord[4]);
2147 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2148 if (lpfc_error_lost_link(irsp))
2151 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2154 /* Good status, call state machine.
2155 * This will unregister the rpi if needed.
2157 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2160 lpfc_els_free_iocb(phba, cmdiocb);
2165 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2166 * @vport: pointer to a virtual N_Port data structure.
2167 * @ndlp: pointer to a node-list data structure.
2168 * @retry: number of retries to the command IOCB.
2170 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2171 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2172 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2173 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2175 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2176 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2177 * will be stored into the context1 field of the IOCB for the completion
2178 * callback function to the LOGO ELS command.
2181 * 0 - successfully issued logo
2182 * 1 - failed to issue logo
2185 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2188 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2189 struct lpfc_hba *phba = vport->phba;
2191 struct lpfc_iocbq *elsiocb;
2196 spin_lock_irq(shost->host_lock);
2197 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2198 spin_unlock_irq(shost->host_lock);
2201 spin_unlock_irq(shost->host_lock);
2203 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2204 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2205 ndlp->nlp_DID, ELS_CMD_LOGO);
2209 icmd = &elsiocb->iocb;
2210 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2211 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2212 pcmd += sizeof(uint32_t);
2214 /* Fill in LOGO payload */
2215 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2216 pcmd += sizeof(uint32_t);
2217 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2219 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2220 "Issue LOGO: did:x%x",
2221 ndlp->nlp_DID, 0, 0);
2223 phba->fc_stat.elsXmitLOGO++;
2224 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2225 spin_lock_irq(shost->host_lock);
2226 ndlp->nlp_flag |= NLP_LOGO_SND;
2227 spin_unlock_irq(shost->host_lock);
2228 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2230 if (rc == IOCB_ERROR) {
2231 spin_lock_irq(shost->host_lock);
2232 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2233 spin_unlock_irq(shost->host_lock);
2234 lpfc_els_free_iocb(phba, elsiocb);
2241 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2242 * @phba: pointer to lpfc hba data structure.
2243 * @cmdiocb: pointer to lpfc command iocb data structure.
2244 * @rspiocb: pointer to lpfc response iocb data structure.
2246 * This routine is a generic completion callback function for ELS commands.
2247 * Specifically, it is the callback function which does not need to perform
2248 * any command specific operations. It is currently used by the ELS command
2249 * issuing routines for the ELS State Change Request (SCR),
2250 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2251 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2252 * certain debug loggings, this callback function simply invokes the
2253 * lpfc_els_chk_latt() routine to check whether link went down during the
2254 * discovery process.
2257 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2258 struct lpfc_iocbq *rspiocb)
2260 struct lpfc_vport *vport = cmdiocb->vport;
2263 irsp = &rspiocb->iocb;
2265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2266 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2267 irsp->ulpStatus, irsp->un.ulpWord[4],
2268 irsp->un.elsreq64.remoteID);
2269 /* ELS cmd tag <ulpIoTag> completes */
2270 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2271 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2272 irsp->ulpIoTag, irsp->ulpStatus,
2273 irsp->un.ulpWord[4], irsp->ulpTimeout);
2274 /* Check to see if link went down during discovery */
2275 lpfc_els_chk_latt(vport);
2276 lpfc_els_free_iocb(phba, cmdiocb);
2281 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2282 * @vport: pointer to a host virtual N_Port data structure.
2283 * @nportid: N_Port identifier to the remote node.
2284 * @retry: number of retries to the command IOCB.
2286 * This routine issues a State Change Request (SCR) to a fabric node
2287 * on a @vport. The remote node @nportid is passed into the function. It
2288 * first search the @vport node list to find the matching ndlp. If no such
2289 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2290 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2291 * routine is invoked to send the SCR IOCB.
2293 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2294 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2295 * will be stored into the context1 field of the IOCB for the completion
2296 * callback function to the SCR ELS command.
2299 * 0 - Successfully issued scr command
2300 * 1 - Failed to issue scr command
2303 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2305 struct lpfc_hba *phba = vport->phba;
2307 struct lpfc_iocbq *elsiocb;
2308 struct lpfc_sli *psli;
2311 struct lpfc_nodelist *ndlp;
2314 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2316 ndlp = lpfc_findnode_did(vport, nportid);
2318 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2321 lpfc_nlp_init(vport, ndlp, nportid);
2322 lpfc_enqueue_node(vport, ndlp);
2323 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2324 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2329 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2330 ndlp->nlp_DID, ELS_CMD_SCR);
2333 /* This will trigger the release of the node just
2340 icmd = &elsiocb->iocb;
2341 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2343 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2344 pcmd += sizeof(uint32_t);
2346 /* For SCR, remainder of payload is SCR parameter page */
2347 memset(pcmd, 0, sizeof(SCR));
2348 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2351 "Issue SCR: did:x%x",
2352 ndlp->nlp_DID, 0, 0);
2354 phba->fc_stat.elsXmitSCR++;
2355 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2356 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2358 /* The additional lpfc_nlp_put will cause the following
2359 * lpfc_els_free_iocb routine to trigger the rlease of
2363 lpfc_els_free_iocb(phba, elsiocb);
2366 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2367 * trigger the release of node.
2374 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2375 * @vport: pointer to a host virtual N_Port data structure.
2376 * @nportid: N_Port identifier to the remote node.
2377 * @retry: number of retries to the command IOCB.
2379 * This routine issues a Fibre Channel Address Resolution Response
2380 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2381 * is passed into the function. It first search the @vport node list to find
2382 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2383 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2384 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2386 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2387 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2388 * will be stored into the context1 field of the IOCB for the completion
2389 * callback function to the PARPR ELS command.
2392 * 0 - Successfully issued farpr command
2393 * 1 - Failed to issue farpr command
2396 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2398 struct lpfc_hba *phba = vport->phba;
2400 struct lpfc_iocbq *elsiocb;
2401 struct lpfc_sli *psli;
2406 struct lpfc_nodelist *ondlp;
2407 struct lpfc_nodelist *ndlp;
2410 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2412 ndlp = lpfc_findnode_did(vport, nportid);
2414 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2417 lpfc_nlp_init(vport, ndlp, nportid);
2418 lpfc_enqueue_node(vport, ndlp);
2419 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2420 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2425 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2426 ndlp->nlp_DID, ELS_CMD_RNID);
2428 /* This will trigger the release of the node just
2435 icmd = &elsiocb->iocb;
2436 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2438 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2439 pcmd += sizeof(uint32_t);
2441 /* Fill in FARPR payload */
2442 fp = (FARP *) (pcmd);
2443 memset(fp, 0, sizeof(FARP));
2444 lp = (uint32_t *) pcmd;
2445 *lp++ = be32_to_cpu(nportid);
2446 *lp++ = be32_to_cpu(vport->fc_myDID);
2448 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2450 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2451 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2452 ondlp = lpfc_findnode_did(vport, nportid);
2453 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2454 memcpy(&fp->OportName, &ondlp->nlp_portname,
2455 sizeof(struct lpfc_name));
2456 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2457 sizeof(struct lpfc_name));
2460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2461 "Issue FARPR: did:x%x",
2462 ndlp->nlp_DID, 0, 0);
2464 phba->fc_stat.elsXmitFARPR++;
2465 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2466 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2468 /* The additional lpfc_nlp_put will cause the following
2469 * lpfc_els_free_iocb routine to trigger the release of
2473 lpfc_els_free_iocb(phba, elsiocb);
2476 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2477 * trigger the release of the node.
2484 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2485 * @vport: pointer to a host virtual N_Port data structure.
2486 * @nlp: pointer to a node-list data structure.
2488 * This routine cancels the timer with a delayed IOCB-command retry for
2489 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2490 * removes the ELS retry event if it presents. In addition, if the
2491 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2492 * commands are sent for the @vport's nodes that require issuing discovery
2496 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2498 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2499 struct lpfc_work_evt *evtp;
2501 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2503 spin_lock_irq(shost->host_lock);
2504 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2505 spin_unlock_irq(shost->host_lock);
2506 del_timer_sync(&nlp->nlp_delayfunc);
2507 nlp->nlp_last_elscmd = 0;
2508 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2509 list_del_init(&nlp->els_retry_evt.evt_listp);
2510 /* Decrement nlp reference count held for the delayed retry */
2511 evtp = &nlp->els_retry_evt;
2512 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2514 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2515 spin_lock_irq(shost->host_lock);
2516 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2517 spin_unlock_irq(shost->host_lock);
2518 if (vport->num_disc_nodes) {
2519 if (vport->port_state < LPFC_VPORT_READY) {
2520 /* Check if there are more ADISCs to be sent */
2521 lpfc_more_adisc(vport);
2523 /* Check if there are more PLOGIs to be sent */
2524 lpfc_more_plogi(vport);
2525 if (vport->num_disc_nodes == 0) {
2526 spin_lock_irq(shost->host_lock);
2527 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2528 spin_unlock_irq(shost->host_lock);
2529 lpfc_can_disctmo(vport);
2530 lpfc_end_rscn(vport);
2539 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2540 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2542 * This routine is invoked by the ndlp delayed-function timer to check
2543 * whether there is any pending ELS retry event(s) with the node. If not, it
2544 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2545 * adds the delayed events to the HBA work list and invokes the
2546 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2547 * event. Note that lpfc_nlp_get() is called before posting the event to
2548 * the work list to hold reference count of ndlp so that it guarantees the
2549 * reference to ndlp will still be available when the worker thread gets
2550 * to the event associated with the ndlp.
2553 lpfc_els_retry_delay(unsigned long ptr)
2555 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2556 struct lpfc_vport *vport = ndlp->vport;
2557 struct lpfc_hba *phba = vport->phba;
2558 unsigned long flags;
2559 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2561 spin_lock_irqsave(&phba->hbalock, flags);
2562 if (!list_empty(&evtp->evt_listp)) {
2563 spin_unlock_irqrestore(&phba->hbalock, flags);
2567 /* We need to hold the node by incrementing the reference
2568 * count until the queued work is done
2570 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2571 if (evtp->evt_arg1) {
2572 evtp->evt = LPFC_EVT_ELS_RETRY;
2573 list_add_tail(&evtp->evt_listp, &phba->work_list);
2574 lpfc_worker_wake_up(phba);
2576 spin_unlock_irqrestore(&phba->hbalock, flags);
2581 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2582 * @ndlp: pointer to a node-list data structure.
2584 * This routine is the worker-thread handler for processing the @ndlp delayed
2585 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2586 * the last ELS command from the associated ndlp and invokes the proper ELS
2587 * function according to the delayed ELS command to retry the command.
2590 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2592 struct lpfc_vport *vport = ndlp->vport;
2593 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2594 uint32_t cmd, did, retry;
2596 spin_lock_irq(shost->host_lock);
2597 did = ndlp->nlp_DID;
2598 cmd = ndlp->nlp_last_elscmd;
2599 ndlp->nlp_last_elscmd = 0;
2601 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2602 spin_unlock_irq(shost->host_lock);
2606 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2607 spin_unlock_irq(shost->host_lock);
2609 * If a discovery event readded nlp_delayfunc after timer
2610 * firing and before processing the timer, cancel the
2613 del_timer_sync(&ndlp->nlp_delayfunc);
2614 retry = ndlp->nlp_retry;
2615 ndlp->nlp_retry = 0;
2619 lpfc_issue_els_flogi(vport, ndlp, retry);
2622 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2623 ndlp->nlp_prev_state = ndlp->nlp_state;
2624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2628 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2629 ndlp->nlp_prev_state = ndlp->nlp_state;
2630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2634 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2635 ndlp->nlp_prev_state = ndlp->nlp_state;
2636 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2640 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2641 ndlp->nlp_prev_state = ndlp->nlp_state;
2642 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2646 lpfc_issue_els_fdisc(vport, ndlp, retry);
2653 * lpfc_els_retry - Make retry decision on an els command iocb
2654 * @phba: pointer to lpfc hba data structure.
2655 * @cmdiocb: pointer to lpfc command iocb data structure.
2656 * @rspiocb: pointer to lpfc response iocb data structure.
2658 * This routine makes a retry decision on an ELS command IOCB, which has
2659 * failed. The following ELS IOCBs use this function for retrying the command
2660 * when previously issued command responsed with error status: FLOGI, PLOGI,
2661 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2662 * returned error status, it makes the decision whether a retry shall be
2663 * issued for the command, and whether a retry shall be made immediately or
2664 * delayed. In the former case, the corresponding ELS command issuing-function
2665 * is called to retry the command. In the later case, the ELS command shall
2666 * be posted to the ndlp delayed event and delayed function timer set to the
2667 * ndlp for the delayed command issusing.
2670 * 0 - No retry of els command is made
2671 * 1 - Immediate or delayed retry of els command is made
2674 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2675 struct lpfc_iocbq *rspiocb)
2677 struct lpfc_vport *vport = cmdiocb->vport;
2678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2679 IOCB_t *irsp = &rspiocb->iocb;
2680 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2681 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2684 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2690 /* Note: context2 may be 0 for internal driver abort
2691 * of delays ELS command.
2694 if (pcmd && pcmd->virt) {
2695 elscmd = (uint32_t *) (pcmd->virt);
2699 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2700 did = ndlp->nlp_DID;
2702 /* We should only hit this case for retrying PLOGI */
2703 did = irsp->un.elsreq64.remoteID;
2704 ndlp = lpfc_findnode_did(vport, did);
2705 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2706 && (cmd != ELS_CMD_PLOGI))
2710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2711 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2712 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2714 switch (irsp->ulpStatus) {
2715 case IOSTAT_FCP_RSP_ERROR:
2716 case IOSTAT_REMOTE_STOP:
2719 case IOSTAT_LOCAL_REJECT:
2720 switch ((irsp->un.ulpWord[4] & 0xff)) {
2721 case IOERR_LOOP_OPEN_FAILURE:
2722 if (cmd == ELS_CMD_FLOGI) {
2723 if (PCI_DEVICE_ID_HORNET ==
2724 phba->pcidev->device) {
2725 phba->fc_topology = TOPOLOGY_LOOP;
2726 phba->pport->fc_myDID = 0;
2727 phba->alpa_map[0] = 0;
2728 phba->alpa_map[1] = 0;
2731 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2736 case IOERR_ILLEGAL_COMMAND:
2737 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2738 "0124 Retry illegal cmd x%x "
2739 "retry:x%x delay:x%x\n",
2740 cmd, cmdiocb->retry, delay);
2742 /* All command's retry policy */
2744 if (cmdiocb->retry > 2)
2748 case IOERR_NO_RESOURCES:
2749 logerr = 1; /* HBA out of resources */
2751 if (cmdiocb->retry > 100)
2756 case IOERR_ILLEGAL_FRAME:
2761 case IOERR_SEQUENCE_TIMEOUT:
2762 case IOERR_INVALID_RPI:
2768 case IOSTAT_NPORT_RJT:
2769 case IOSTAT_FABRIC_RJT:
2770 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2776 case IOSTAT_NPORT_BSY:
2777 case IOSTAT_FABRIC_BSY:
2778 logerr = 1; /* Fabric / Remote NPort out of resources */
2783 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2784 /* Added for Vendor specifc support
2785 * Just keep retrying for these Rsn / Exp codes
2787 switch (stat.un.b.lsRjtRsnCode) {
2788 case LSRJT_UNABLE_TPC:
2789 if (stat.un.b.lsRjtRsnCodeExp ==
2790 LSEXP_CMD_IN_PROGRESS) {
2791 if (cmd == ELS_CMD_PLOGI) {
2798 if (stat.un.b.lsRjtRsnCodeExp ==
2799 LSEXP_CANT_GIVE_DATA) {
2800 if (cmd == ELS_CMD_PLOGI) {
2807 if (cmd == ELS_CMD_PLOGI) {
2809 maxretry = lpfc_max_els_tries + 1;
2813 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2814 (cmd == ELS_CMD_FDISC) &&
2815 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2816 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2817 "0125 FDISC Failed (x%x). "
2818 "Fabric out of resources\n",
2819 stat.un.lsRjtError);
2820 lpfc_vport_set_state(vport,
2821 FC_VPORT_NO_FABRIC_RSCS);
2825 case LSRJT_LOGICAL_BSY:
2826 if ((cmd == ELS_CMD_PLOGI) ||
2827 (cmd == ELS_CMD_PRLI)) {
2830 } else if (cmd == ELS_CMD_FDISC) {
2831 /* FDISC retry policy */
2833 if (cmdiocb->retry >= 32)
2839 case LSRJT_LOGICAL_ERR:
2840 /* There are some cases where switches return this
2841 * error when they are not ready and should be returning
2842 * Logical Busy. We should delay every time.
2844 if (cmd == ELS_CMD_FDISC &&
2845 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2851 case LSRJT_PROTOCOL_ERR:
2852 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2853 (cmd == ELS_CMD_FDISC) &&
2854 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2855 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2857 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2858 "0122 FDISC Failed (x%x). "
2859 "Fabric Detected Bad WWN\n",
2860 stat.un.lsRjtError);
2861 lpfc_vport_set_state(vport,
2862 FC_VPORT_FABRIC_REJ_WWN);
2868 case IOSTAT_INTERMED_RSP:
2876 if (did == FDMI_DID)
2879 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
2880 (phba->fc_topology != TOPOLOGY_LOOP) &&
2881 !lpfc_error_lost_link(irsp)) {
2882 /* FLOGI retry policy */
2886 if (cmdiocb->retry >= 100)
2888 else if (cmdiocb->retry >= 32)
2893 if (maxretry && (cmdiocb->retry >= maxretry)) {
2894 phba->fc_stat.elsRetryExceeded++;
2898 if ((vport->load_flag & FC_UNLOADING) != 0)
2902 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2903 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2904 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2905 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2906 "2849 Stop retry ELS command "
2907 "x%x to remote NPORT x%x, "
2908 "Data: x%x x%x\n", cmd, did,
2909 cmdiocb->retry, delay);
2914 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2915 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2916 "0107 Retry ELS command x%x to remote "
2917 "NPORT x%x Data: x%x x%x\n",
2918 cmd, did, cmdiocb->retry, delay);
2920 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2921 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2922 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2923 /* Don't reset timer for no resources */
2925 /* If discovery / RSCN timer is running, reset it */
2926 if (timer_pending(&vport->fc_disctmo) ||
2927 (vport->fc_flag & FC_RSCN_MODE))
2928 lpfc_set_disctmo(vport);
2931 phba->fc_stat.elsXmitRetry++;
2932 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
2933 phba->fc_stat.elsDelayRetry++;
2934 ndlp->nlp_retry = cmdiocb->retry;
2936 /* delay is specified in milliseconds */
2937 mod_timer(&ndlp->nlp_delayfunc,
2938 jiffies + msecs_to_jiffies(delay));
2939 spin_lock_irq(shost->host_lock);
2940 ndlp->nlp_flag |= NLP_DELAY_TMO;
2941 spin_unlock_irq(shost->host_lock);
2943 ndlp->nlp_prev_state = ndlp->nlp_state;
2944 if (cmd == ELS_CMD_PRLI)
2945 lpfc_nlp_set_state(vport, ndlp,
2946 NLP_STE_REG_LOGIN_ISSUE);
2948 lpfc_nlp_set_state(vport, ndlp,
2950 ndlp->nlp_last_elscmd = cmd;
2956 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2959 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2962 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2963 ndlp->nlp_prev_state = ndlp->nlp_state;
2964 lpfc_nlp_set_state(vport, ndlp,
2965 NLP_STE_PLOGI_ISSUE);
2967 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2970 ndlp->nlp_prev_state = ndlp->nlp_state;
2971 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2972 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2975 ndlp->nlp_prev_state = ndlp->nlp_state;
2976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2977 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2980 ndlp->nlp_prev_state = ndlp->nlp_state;
2981 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2982 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2986 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2988 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2989 "0137 No retry ELS command x%x to remote "
2990 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2991 cmd, did, irsp->ulpStatus,
2992 irsp->un.ulpWord[4]);
2995 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2996 "0108 No retry ELS command x%x to remote "
2997 "NPORT x%x Retried:%d Error:x%x/%x\n",
2998 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2999 irsp->un.ulpWord[4]);
3005 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3006 * @phba: pointer to lpfc hba data structure.
3007 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3009 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3010 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3011 * checks to see whether there is a lpfc DMA buffer associated with the
3012 * response of the command IOCB. If so, it will be released before releasing
3013 * the lpfc DMA buffer associated with the IOCB itself.
3016 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3019 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3021 struct lpfc_dmabuf *buf_ptr;
3023 /* Free the response before processing the command. */
3024 if (!list_empty(&buf_ptr1->list)) {
3025 list_remove_head(&buf_ptr1->list, buf_ptr,
3028 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3031 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3037 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3038 * @phba: pointer to lpfc hba data structure.
3039 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3041 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3042 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3046 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3049 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3051 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3057 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3058 * @phba: pointer to lpfc hba data structure.
3059 * @elsiocb: pointer to lpfc els command iocb data structure.
3061 * This routine frees a command IOCB and its associated resources. The
3062 * command IOCB data structure contains the reference to various associated
3063 * resources, these fields must be set to NULL if the associated reference
3065 * context1 - reference to ndlp
3066 * context2 - reference to cmd
3067 * context2->next - reference to rsp
3068 * context3 - reference to bpl
3070 * It first properly decrements the reference count held on ndlp for the
3071 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3072 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3073 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3074 * adds the DMA buffer the @phba data structure for the delayed release.
3075 * If reference to the Buffer Pointer List (BPL) is present, the
3076 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3077 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3078 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3081 * 0 - Success (currently, always return 0)
3084 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3086 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3087 struct lpfc_nodelist *ndlp;
3089 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3091 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3094 /* If the ndlp is not being used by another discovery
3097 if (!lpfc_nlp_not_used(ndlp)) {
3098 /* If ndlp is being used by another discovery
3099 * thread, just clear NLP_DEFER_RM
3101 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3106 elsiocb->context1 = NULL;
3108 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3109 if (elsiocb->context2) {
3110 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3111 /* Firmware could still be in progress of DMAing
3112 * payload, so don't free data buffer till after
3115 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3116 buf_ptr = elsiocb->context2;
3117 elsiocb->context2 = NULL;
3120 spin_lock_irq(&phba->hbalock);
3121 if (!list_empty(&buf_ptr->list)) {
3122 list_remove_head(&buf_ptr->list,
3123 buf_ptr1, struct lpfc_dmabuf,
3125 INIT_LIST_HEAD(&buf_ptr1->list);
3126 list_add_tail(&buf_ptr1->list,
3130 INIT_LIST_HEAD(&buf_ptr->list);
3131 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3133 spin_unlock_irq(&phba->hbalock);
3136 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3137 lpfc_els_free_data(phba, buf_ptr1);
3141 if (elsiocb->context3) {
3142 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3143 lpfc_els_free_bpl(phba, buf_ptr);
3145 lpfc_sli_release_iocbq(phba, elsiocb);
3150 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3151 * @phba: pointer to lpfc hba data structure.
3152 * @cmdiocb: pointer to lpfc command iocb data structure.
3153 * @rspiocb: pointer to lpfc response iocb data structure.
3155 * This routine is the completion callback function to the Logout (LOGO)
3156 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3157 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3158 * release the ndlp if it has the last reference remaining (reference count
3159 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3160 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3161 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3162 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3163 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3164 * IOCB data structure.
3167 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3168 struct lpfc_iocbq *rspiocb)
3170 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3171 struct lpfc_vport *vport = cmdiocb->vport;
3174 irsp = &rspiocb->iocb;
3175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3176 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3177 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3178 /* ACC to LOGO completes to NPort <nlp_DID> */
3179 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3180 "0109 ACC to LOGO completes to NPort x%x "
3181 "Data: x%x x%x x%x\n",
3182 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3185 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3186 /* NPort Recovery mode or node is just allocated */
3187 if (!lpfc_nlp_not_used(ndlp)) {
3188 /* If the ndlp is being used by another discovery
3189 * thread, just unregister the RPI.
3191 lpfc_unreg_rpi(vport, ndlp);
3193 /* Indicate the node has already released, should
3194 * not reference to it from within lpfc_els_free_iocb.
3196 cmdiocb->context1 = NULL;
3199 lpfc_els_free_iocb(phba, cmdiocb);
3204 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3205 * @phba: pointer to lpfc hba data structure.
3206 * @pmb: pointer to the driver internal queue element for mailbox command.
3208 * This routine is the completion callback function for unregister default
3209 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3210 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3211 * decrements the ndlp reference count held for this completion callback
3212 * function. After that, it invokes the lpfc_nlp_not_used() to check
3213 * whether there is only one reference left on the ndlp. If so, it will
3214 * perform one more decrement and trigger the release of the ndlp.
3217 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3219 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3220 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3223 * This routine is used to register and unregister in previous SLI
3226 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3227 (phba->sli_rev == LPFC_SLI_REV4))
3228 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3230 pmb->context1 = NULL;
3231 pmb->context2 = NULL;
3233 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3235 mempool_free(pmb, phba->mbox_mem_pool);
3236 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3238 /* This is the end of the default RPI cleanup logic for this
3239 * ndlp. If no other discovery threads are using this ndlp.
3240 * we should free all resources associated with it.
3242 lpfc_nlp_not_used(ndlp);
3249 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3250 * @phba: pointer to lpfc hba data structure.
3251 * @cmdiocb: pointer to lpfc command iocb data structure.
3252 * @rspiocb: pointer to lpfc response iocb data structure.
3254 * This routine is the completion callback function for ELS Response IOCB
3255 * command. In normal case, this callback function just properly sets the
3256 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3257 * field in the command IOCB is not NULL, the referred mailbox command will
3258 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3259 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3260 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3261 * routine shall be invoked trying to release the ndlp if no other threads
3262 * are currently referring it.
3265 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3266 struct lpfc_iocbq *rspiocb)
3268 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3269 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3270 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3273 LPFC_MBOXQ_t *mbox = NULL;
3274 struct lpfc_dmabuf *mp = NULL;
3275 uint32_t ls_rjt = 0;
3277 irsp = &rspiocb->iocb;
3279 if (cmdiocb->context_un.mbox)
3280 mbox = cmdiocb->context_un.mbox;
3282 /* First determine if this is a LS_RJT cmpl. Note, this callback
3283 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3285 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3286 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3287 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3288 /* A LS_RJT associated with Default RPI cleanup has its own
3289 * separate code path.
3291 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3295 /* Check to see if link went down during discovery */
3296 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3298 mp = (struct lpfc_dmabuf *) mbox->context1;
3300 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3303 mempool_free(mbox, phba->mbox_mem_pool);
3305 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3306 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3307 if (lpfc_nlp_not_used(ndlp)) {
3309 /* Indicate the node has already released,
3310 * should not reference to it from within
3311 * the routine lpfc_els_free_iocb.
3313 cmdiocb->context1 = NULL;
3318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3319 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3320 irsp->ulpStatus, irsp->un.ulpWord[4],
3321 cmdiocb->iocb.un.elsreq64.remoteID);
3322 /* ELS response tag <ulpIoTag> completes */
3323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3324 "0110 ELS response tag x%x completes "
3325 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3326 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3327 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3328 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3331 if ((rspiocb->iocb.ulpStatus == 0)
3332 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3333 lpfc_unreg_rpi(vport, ndlp);
3334 /* Increment reference count to ndlp to hold the
3335 * reference to ndlp for the callback function.
3337 mbox->context2 = lpfc_nlp_get(ndlp);
3338 mbox->vport = vport;
3339 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3340 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3341 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3344 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3345 ndlp->nlp_prev_state = ndlp->nlp_state;
3346 lpfc_nlp_set_state(vport, ndlp,
3347 NLP_STE_REG_LOGIN_ISSUE);
3349 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3350 != MBX_NOT_FINISHED)
3353 /* Decrement the ndlp reference count we
3354 * set for this failed mailbox command.
3358 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3359 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3360 "0138 ELS rsp: Cannot issue reg_login for x%x "
3361 "Data: x%x x%x x%x\n",
3362 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3365 if (lpfc_nlp_not_used(ndlp)) {
3367 /* Indicate node has already been released,
3368 * should not reference to it from within
3369 * the routine lpfc_els_free_iocb.
3371 cmdiocb->context1 = NULL;
3374 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3375 if (!lpfc_error_lost_link(irsp) &&
3376 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3377 if (lpfc_nlp_not_used(ndlp)) {
3379 /* Indicate node has already been
3380 * released, should not reference
3381 * to it from within the routine
3382 * lpfc_els_free_iocb.
3384 cmdiocb->context1 = NULL;
3388 mp = (struct lpfc_dmabuf *) mbox->context1;
3390 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3393 mempool_free(mbox, phba->mbox_mem_pool);
3396 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3397 spin_lock_irq(shost->host_lock);
3398 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3399 spin_unlock_irq(shost->host_lock);
3401 /* If the node is not being used by another discovery thread,
3402 * and we are sending a reject, we are done with it.
3403 * Release driver reference count here and free associated
3407 if (lpfc_nlp_not_used(ndlp))
3408 /* Indicate node has already been released,
3409 * should not reference to it from within
3410 * the routine lpfc_els_free_iocb.
3412 cmdiocb->context1 = NULL;
3415 lpfc_els_free_iocb(phba, cmdiocb);
3420 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3421 * @vport: pointer to a host virtual N_Port data structure.
3422 * @flag: the els command code to be accepted.
3423 * @oldiocb: pointer to the original lpfc command iocb data structure.
3424 * @ndlp: pointer to a node-list data structure.
3425 * @mbox: pointer to the driver internal queue element for mailbox command.
3427 * This routine prepares and issues an Accept (ACC) response IOCB
3428 * command. It uses the @flag to properly set up the IOCB field for the
3429 * specific ACC response command to be issued and invokes the
3430 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3431 * @mbox pointer is passed in, it will be put into the context_un.mbox
3432 * field of the IOCB for the completion callback function to issue the
3433 * mailbox command to the HBA later when callback is invoked.
3435 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3436 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3437 * will be stored into the context1 field of the IOCB for the completion
3438 * callback function to the corresponding response ELS IOCB command.
3441 * 0 - Successfully issued acc response
3442 * 1 - Failed to issue acc response
3445 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3446 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3449 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3450 struct lpfc_hba *phba = vport->phba;
3453 struct lpfc_iocbq *elsiocb;
3454 struct lpfc_sli *psli;
3458 ELS_PKT *els_pkt_ptr;
3461 oldcmd = &oldiocb->iocb;
3465 cmdsize = sizeof(uint32_t);
3466 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3467 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3469 spin_lock_irq(shost->host_lock);
3470 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3471 spin_unlock_irq(shost->host_lock);
3475 icmd = &elsiocb->iocb;
3476 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3477 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3478 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3479 pcmd += sizeof(uint32_t);
3481 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3482 "Issue ACC: did:x%x flg:x%x",
3483 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3486 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3487 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3488 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3492 icmd = &elsiocb->iocb;
3493 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3494 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3497 elsiocb->context_un.mbox = mbox;
3499 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3500 pcmd += sizeof(uint32_t);
3501 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3504 "Issue ACC PLOGI: did:x%x flg:x%x",
3505 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3508 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3509 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3510 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3514 icmd = &elsiocb->iocb;
3515 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3516 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3518 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3519 sizeof(uint32_t) + sizeof(PRLO));
3520 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3521 els_pkt_ptr = (ELS_PKT *) pcmd;
3522 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3525 "Issue ACC PRLO: did:x%x flg:x%x",
3526 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3531 /* Xmit ELS ACC response tag <ulpIoTag> */
3532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3533 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3534 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3535 elsiocb->iotag, elsiocb->iocb.ulpContext,
3536 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3538 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3539 spin_lock_irq(shost->host_lock);
3540 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3541 spin_unlock_irq(shost->host_lock);
3542 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3544 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3547 phba->fc_stat.elsXmitACC++;
3548 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3549 if (rc == IOCB_ERROR) {
3550 lpfc_els_free_iocb(phba, elsiocb);
3557 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3558 * @vport: pointer to a virtual N_Port data structure.
3560 * @oldiocb: pointer to the original lpfc command iocb data structure.
3561 * @ndlp: pointer to a node-list data structure.
3562 * @mbox: pointer to the driver internal queue element for mailbox command.
3564 * This routine prepares and issue an Reject (RJT) response IOCB
3565 * command. If a @mbox pointer is passed in, it will be put into the
3566 * context_un.mbox field of the IOCB for the completion callback function
3567 * to issue to the HBA later.
3569 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3570 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3571 * will be stored into the context1 field of the IOCB for the completion
3572 * callback function to the reject response ELS IOCB command.
3575 * 0 - Successfully issued reject response
3576 * 1 - Failed to issue reject response
3579 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3580 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3583 struct lpfc_hba *phba = vport->phba;
3586 struct lpfc_iocbq *elsiocb;
3587 struct lpfc_sli *psli;
3593 cmdsize = 2 * sizeof(uint32_t);
3594 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3595 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3599 icmd = &elsiocb->iocb;
3600 oldcmd = &oldiocb->iocb;
3601 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3604 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3605 pcmd += sizeof(uint32_t);
3606 *((uint32_t *) (pcmd)) = rejectError;
3609 elsiocb->context_un.mbox = mbox;
3611 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3612 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3613 "0129 Xmit ELS RJT x%x response tag x%x "
3614 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3616 rejectError, elsiocb->iotag,
3617 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3618 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3620 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3621 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3623 phba->fc_stat.elsXmitLSRJT++;
3624 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3625 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3627 if (rc == IOCB_ERROR) {
3628 lpfc_els_free_iocb(phba, elsiocb);
3635 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3636 * @vport: pointer to a virtual N_Port data structure.
3637 * @oldiocb: pointer to the original lpfc command iocb data structure.
3638 * @ndlp: pointer to a node-list data structure.
3640 * This routine prepares and issues an Accept (ACC) response to Address
3641 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3642 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3644 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3645 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3646 * will be stored into the context1 field of the IOCB for the completion
3647 * callback function to the ADISC Accept response ELS IOCB command.
3650 * 0 - Successfully issued acc adisc response
3651 * 1 - Failed to issue adisc acc response
3654 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3655 struct lpfc_nodelist *ndlp)
3657 struct lpfc_hba *phba = vport->phba;
3659 IOCB_t *icmd, *oldcmd;
3660 struct lpfc_iocbq *elsiocb;
3665 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3666 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3667 ndlp->nlp_DID, ELS_CMD_ACC);
3671 icmd = &elsiocb->iocb;
3672 oldcmd = &oldiocb->iocb;
3673 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3675 /* Xmit ADISC ACC response tag <ulpIoTag> */
3676 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3677 "0130 Xmit ADISC ACC response iotag x%x xri: "
3678 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3679 elsiocb->iotag, elsiocb->iocb.ulpContext,
3680 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3682 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3684 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3685 pcmd += sizeof(uint32_t);
3687 ap = (ADISC *) (pcmd);
3688 ap->hardAL_PA = phba->fc_pref_ALPA;
3689 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3690 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3691 ap->DID = be32_to_cpu(vport->fc_myDID);
3693 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3694 "Issue ACC ADISC: did:x%x flg:x%x",
3695 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3697 phba->fc_stat.elsXmitACC++;
3698 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3699 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3700 if (rc == IOCB_ERROR) {
3701 lpfc_els_free_iocb(phba, elsiocb);
3708 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3709 * @vport: pointer to a virtual N_Port data structure.
3710 * @oldiocb: pointer to the original lpfc command iocb data structure.
3711 * @ndlp: pointer to a node-list data structure.
3713 * This routine prepares and issues an Accept (ACC) response to Process
3714 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3715 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3717 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3718 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3719 * will be stored into the context1 field of the IOCB for the completion
3720 * callback function to the PRLI Accept response ELS IOCB command.
3723 * 0 - Successfully issued acc prli response
3724 * 1 - Failed to issue acc prli response
3727 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3728 struct lpfc_nodelist *ndlp)
3730 struct lpfc_hba *phba = vport->phba;
3735 struct lpfc_iocbq *elsiocb;
3736 struct lpfc_sli *psli;
3743 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3744 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3745 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3749 icmd = &elsiocb->iocb;
3750 oldcmd = &oldiocb->iocb;
3751 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3752 /* Xmit PRLI ACC response tag <ulpIoTag> */
3753 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3754 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3755 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3756 elsiocb->iotag, elsiocb->iocb.ulpContext,
3757 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3759 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3761 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3762 pcmd += sizeof(uint32_t);
3764 /* For PRLI, remainder of payload is PRLI parameter page */
3765 memset(pcmd, 0, sizeof(PRLI));
3767 npr = (PRLI *) pcmd;
3770 * If the remote port is a target and our firmware version is 3.20 or
3771 * later, set the following bits for FC-TAPE support.
3773 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3774 (vpd->rev.feaLevelHigh >= 0x02)) {
3775 npr->ConfmComplAllowed = 1;
3777 npr->TaskRetryIdReq = 1;
3780 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3781 npr->estabImagePair = 1;
3782 npr->readXferRdyDis = 1;
3783 npr->ConfmComplAllowed = 1;
3785 npr->prliType = PRLI_FCP_TYPE;
3786 npr->initiatorFunc = 1;
3788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3789 "Issue ACC PRLI: did:x%x flg:x%x",
3790 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3792 phba->fc_stat.elsXmitACC++;
3793 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3795 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3796 if (rc == IOCB_ERROR) {
3797 lpfc_els_free_iocb(phba, elsiocb);
3804 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3805 * @vport: pointer to a virtual N_Port data structure.
3806 * @format: rnid command format.
3807 * @oldiocb: pointer to the original lpfc command iocb data structure.
3808 * @ndlp: pointer to a node-list data structure.
3810 * This routine issues a Request Node Identification Data (RNID) Accept
3811 * (ACC) response. It constructs the RNID ACC response command according to
3812 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3813 * issue the response. Note that this command does not need to hold the ndlp
3814 * reference count for the callback. So, the ndlp reference count taken by
3815 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3816 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3817 * there is no ndlp reference available.
3819 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3820 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3821 * will be stored into the context1 field of the IOCB for the completion
3822 * callback function. However, for the RNID Accept Response ELS command,
3823 * this is undone later by this routine after the IOCB is allocated.
3826 * 0 - Successfully issued acc rnid response
3827 * 1 - Failed to issue acc rnid response
3830 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3831 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3833 struct lpfc_hba *phba = vport->phba;
3835 IOCB_t *icmd, *oldcmd;
3836 struct lpfc_iocbq *elsiocb;
3837 struct lpfc_sli *psli;
3843 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3844 + (2 * sizeof(struct lpfc_name));
3846 cmdsize += sizeof(RNID_TOP_DISC);
3848 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3849 ndlp->nlp_DID, ELS_CMD_ACC);
3853 icmd = &elsiocb->iocb;
3854 oldcmd = &oldiocb->iocb;
3855 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3856 /* Xmit RNID ACC response tag <ulpIoTag> */
3857 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3858 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3859 elsiocb->iotag, elsiocb->iocb.ulpContext);
3860 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3861 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3862 pcmd += sizeof(uint32_t);
3864 memset(pcmd, 0, sizeof(RNID));
3865 rn = (RNID *) (pcmd);
3866 rn->Format = format;
3867 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3868 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3869 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3872 rn->SpecificLen = 0;
3874 case RNID_TOPOLOGY_DISC:
3875 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3876 memcpy(&rn->un.topologyDisc.portName,
3877 &vport->fc_portname, sizeof(struct lpfc_name));
3878 rn->un.topologyDisc.unitType = RNID_HBA;
3879 rn->un.topologyDisc.physPort = 0;
3880 rn->un.topologyDisc.attachedNodes = 0;
3884 rn->SpecificLen = 0;
3888 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3889 "Issue ACC RNID: did:x%x flg:x%x",
3890 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3892 phba->fc_stat.elsXmitACC++;
3893 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3895 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3896 * it could be freed */
3898 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3899 if (rc == IOCB_ERROR) {
3900 lpfc_els_free_iocb(phba, elsiocb);
3907 * lpfc_els_rsp_echo_acc - Issue echo acc response
3908 * @vport: pointer to a virtual N_Port data structure.
3909 * @data: pointer to echo data to return in the accept.
3910 * @oldiocb: pointer to the original lpfc command iocb data structure.
3911 * @ndlp: pointer to a node-list data structure.
3914 * 0 - Successfully issued acc echo response
3915 * 1 - Failed to issue acc echo response
3918 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3919 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3921 struct lpfc_hba *phba = vport->phba;
3922 struct lpfc_iocbq *elsiocb;
3923 struct lpfc_sli *psli;
3929 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3931 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3932 ndlp->nlp_DID, ELS_CMD_ACC);
3936 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3937 /* Xmit ECHO ACC response tag <ulpIoTag> */
3938 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3939 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3940 elsiocb->iotag, elsiocb->iocb.ulpContext);
3941 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3942 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3943 pcmd += sizeof(uint32_t);
3944 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3946 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3947 "Issue ACC ECHO: did:x%x flg:x%x",
3948 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3950 phba->fc_stat.elsXmitACC++;
3951 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3953 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3954 * it could be freed */
3956 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3957 if (rc == IOCB_ERROR) {
3958 lpfc_els_free_iocb(phba, elsiocb);
3965 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3966 * @vport: pointer to a host virtual N_Port data structure.
3968 * This routine issues Address Discover (ADISC) ELS commands to those
3969 * N_Ports which are in node port recovery state and ADISC has not been issued
3970 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3971 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3972 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3973 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3974 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3975 * IOCBs quit for later pick up. On the other hand, after walking through
3976 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3977 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3978 * no more ADISC need to be sent.
3981 * The number of N_Ports with adisc issued.
3984 lpfc_els_disc_adisc(struct lpfc_vport *vport)
3986 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3987 struct lpfc_nodelist *ndlp, *next_ndlp;
3990 /* go thru NPR nodes and issue any remaining ELS ADISCs */
3991 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3992 if (!NLP_CHK_NODE_ACT(ndlp))
3994 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3995 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3996 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
3997 spin_lock_irq(shost->host_lock);
3998 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3999 spin_unlock_irq(shost->host_lock);
4000 ndlp->nlp_prev_state = ndlp->nlp_state;
4001 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4002 lpfc_issue_els_adisc(vport, ndlp, 0);
4004 vport->num_disc_nodes++;
4005 if (vport->num_disc_nodes >=
4006 vport->cfg_discovery_threads) {
4007 spin_lock_irq(shost->host_lock);
4008 vport->fc_flag |= FC_NLP_MORE;
4009 spin_unlock_irq(shost->host_lock);
4014 if (sentadisc == 0) {
4015 spin_lock_irq(shost->host_lock);
4016 vport->fc_flag &= ~FC_NLP_MORE;
4017 spin_unlock_irq(shost->host_lock);
4023 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4024 * @vport: pointer to a host virtual N_Port data structure.
4026 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4027 * which are in node port recovery state, with a @vport. Each time an ELS
4028 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4029 * the per @vport number of discover count (num_disc_nodes) shall be
4030 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4031 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4032 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4033 * later pick up. On the other hand, after walking through all the ndlps with
4034 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4035 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4036 * PLOGI need to be sent.
4039 * The number of N_Ports with plogi issued.
4042 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4045 struct lpfc_nodelist *ndlp, *next_ndlp;
4048 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4049 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4050 if (!NLP_CHK_NODE_ACT(ndlp))
4052 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4053 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4054 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4055 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4056 ndlp->nlp_prev_state = ndlp->nlp_state;
4057 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4058 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4060 vport->num_disc_nodes++;
4061 if (vport->num_disc_nodes >=
4062 vport->cfg_discovery_threads) {
4063 spin_lock_irq(shost->host_lock);
4064 vport->fc_flag |= FC_NLP_MORE;
4065 spin_unlock_irq(shost->host_lock);
4071 lpfc_set_disctmo(vport);
4074 spin_lock_irq(shost->host_lock);
4075 vport->fc_flag &= ~FC_NLP_MORE;
4076 spin_unlock_irq(shost->host_lock);
4082 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4083 * @vport: pointer to a host virtual N_Port data structure.
4085 * This routine cleans up any Registration State Change Notification
4086 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4087 * @vport together with the host_lock is used to prevent multiple thread
4088 * trying to access the RSCN array on a same @vport at the same time.
4091 lpfc_els_flush_rscn(struct lpfc_vport *vport)
4093 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4094 struct lpfc_hba *phba = vport->phba;
4097 spin_lock_irq(shost->host_lock);
4098 if (vport->fc_rscn_flush) {
4099 /* Another thread is walking fc_rscn_id_list on this vport */
4100 spin_unlock_irq(shost->host_lock);
4103 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4104 vport->fc_rscn_flush = 1;
4105 spin_unlock_irq(shost->host_lock);
4107 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4108 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
4109 vport->fc_rscn_id_list[i] = NULL;
4111 spin_lock_irq(shost->host_lock);
4112 vport->fc_rscn_id_cnt = 0;
4113 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4114 spin_unlock_irq(shost->host_lock);
4115 lpfc_can_disctmo(vport);
4116 /* Indicate we are done walking this fc_rscn_id_list */
4117 vport->fc_rscn_flush = 0;
4121 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4122 * @vport: pointer to a host virtual N_Port data structure.
4123 * @did: remote destination port identifier.
4125 * This routine checks whether there is any pending Registration State
4126 * Configuration Notification (RSCN) to a @did on @vport.
4129 * None zero - The @did matched with a pending rscn
4130 * 0 - not able to match @did with a pending rscn
4133 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
4138 uint32_t payload_len, i;
4139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4141 ns_did.un.word = did;
4143 /* Never match fabric nodes for RSCNs */
4144 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
4147 /* If we are doing a FULL RSCN rediscovery, match everything */
4148 if (vport->fc_flag & FC_RSCN_DISCOVERY)
4151 spin_lock_irq(shost->host_lock);
4152 if (vport->fc_rscn_flush) {
4153 /* Another thread is walking fc_rscn_id_list on this vport */
4154 spin_unlock_irq(shost->host_lock);
4157 /* Indicate we are walking fc_rscn_id_list on this vport */
4158 vport->fc_rscn_flush = 1;
4159 spin_unlock_irq(shost->host_lock);
4160 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4161 lp = vport->fc_rscn_id_list[i]->virt;
4162 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4163 payload_len -= sizeof(uint32_t); /* take off word 0 */
4164 while (payload_len) {
4165 rscn_did.un.word = be32_to_cpu(*lp++);
4166 payload_len -= sizeof(uint32_t);
4167 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4168 case RSCN_ADDRESS_FORMAT_PORT:
4169 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4170 && (ns_did.un.b.area == rscn_did.un.b.area)
4171 && (ns_did.un.b.id == rscn_did.un.b.id))
4172 goto return_did_out;
4174 case RSCN_ADDRESS_FORMAT_AREA:
4175 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4176 && (ns_did.un.b.area == rscn_did.un.b.area))
4177 goto return_did_out;
4179 case RSCN_ADDRESS_FORMAT_DOMAIN:
4180 if (ns_did.un.b.domain == rscn_did.un.b.domain)
4181 goto return_did_out;
4183 case RSCN_ADDRESS_FORMAT_FABRIC:
4184 goto return_did_out;
4188 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4189 vport->fc_rscn_flush = 0;
4192 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4193 vport->fc_rscn_flush = 0;
4198 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4199 * @vport: pointer to a host virtual N_Port data structure.
4201 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4202 * state machine for a @vport's nodes that are with pending RSCN (Registration
4203 * State Change Notification).
4206 * 0 - Successful (currently alway return 0)
4209 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
4211 struct lpfc_nodelist *ndlp = NULL;
4213 /* Move all affected nodes by pending RSCNs to NPR state. */
4214 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4215 if (!NLP_CHK_NODE_ACT(ndlp) ||
4216 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4217 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
4219 lpfc_disc_state_machine(vport, ndlp, NULL,
4220 NLP_EVT_DEVICE_RECOVERY);
4221 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4227 * lpfc_send_rscn_event - Send an RSCN event to management application
4228 * @vport: pointer to a host virtual N_Port data structure.
4229 * @cmdiocb: pointer to lpfc command iocb data structure.
4231 * lpfc_send_rscn_event sends an RSCN netlink event to management
4235 lpfc_send_rscn_event(struct lpfc_vport *vport,
4236 struct lpfc_iocbq *cmdiocb)
4238 struct lpfc_dmabuf *pcmd;
4239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4240 uint32_t *payload_ptr;
4241 uint32_t payload_len;
4242 struct lpfc_rscn_event_header *rscn_event_data;
4244 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4245 payload_ptr = (uint32_t *) pcmd->virt;
4246 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4248 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4249 payload_len, GFP_KERNEL);
4250 if (!rscn_event_data) {
4251 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4252 "0147 Failed to allocate memory for RSCN event\n");
4255 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4256 rscn_event_data->payload_length = payload_len;
4257 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4260 fc_host_post_vendor_event(shost,
4261 fc_get_event_number(),
4262 sizeof(struct lpfc_els_event_header) + payload_len,
4263 (char *)rscn_event_data,
4266 kfree(rscn_event_data);
4270 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4271 * @vport: pointer to a host virtual N_Port data structure.
4272 * @cmdiocb: pointer to lpfc command iocb data structure.
4273 * @ndlp: pointer to a node-list data structure.
4275 * This routine processes an unsolicited RSCN (Registration State Change
4276 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4277 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4278 * discover state machine is about to begin discovery, it just accepts the
4279 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4280 * contains N_Port IDs for other vports on this HBA, it just accepts the
4281 * RSCN and ignore processing it. If the state machine is in the recovery
4282 * state, the fc_rscn_id_list of this @vport is walked and the
4283 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4284 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4285 * routine is invoked to handle the RSCN event.
4288 * 0 - Just sent the acc response
4289 * 1 - Sent the acc response and waited for name server completion
4292 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4293 struct lpfc_nodelist *ndlp)
4295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4296 struct lpfc_hba *phba = vport->phba;
4297 struct lpfc_dmabuf *pcmd;
4298 uint32_t *lp, *datap;
4300 uint32_t payload_len, length, nportid, *cmd;
4302 int rscn_id = 0, hba_id = 0;
4305 icmd = &cmdiocb->iocb;
4306 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4307 lp = (uint32_t *) pcmd->virt;
4309 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4310 payload_len -= sizeof(uint32_t); /* take off word 0 */
4312 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4313 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4314 vport->fc_flag, payload_len, *lp,
4315 vport->fc_rscn_id_cnt);
4317 /* Send an RSCN event to the management application */
4318 lpfc_send_rscn_event(vport, cmdiocb);
4320 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
4321 fc_host_post_event(shost, fc_get_event_number(),
4322 FCH_EVT_RSCN, lp[i]);
4324 /* If we are about to begin discovery, just ACC the RSCN.
4325 * Discovery processing will satisfy it.
4327 if (vport->port_state <= LPFC_NS_QRY) {
4328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4329 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4330 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4332 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4336 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4337 * just ACC and ignore it.
4339 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4340 !(vport->cfg_peer_port_login)) {
4345 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4346 i -= sizeof(uint32_t);
4348 if (lpfc_find_vport_by_did(phba, nportid))
4351 if (rscn_id == hba_id) {
4352 /* ALL NPortIDs in RSCN are on HBA */
4353 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4355 "Data: x%x x%x x%x x%x\n",
4356 vport->fc_flag, payload_len,
4357 *lp, vport->fc_rscn_id_cnt);
4358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4359 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4360 ndlp->nlp_DID, vport->port_state,
4363 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4369 spin_lock_irq(shost->host_lock);
4370 if (vport->fc_rscn_flush) {
4371 /* Another thread is walking fc_rscn_id_list on this vport */
4372 vport->fc_flag |= FC_RSCN_DISCOVERY;
4373 spin_unlock_irq(shost->host_lock);
4375 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4378 /* Indicate we are walking fc_rscn_id_list on this vport */
4379 vport->fc_rscn_flush = 1;
4380 spin_unlock_irq(shost->host_lock);
4381 /* Get the array count after successfully have the token */
4382 rscn_cnt = vport->fc_rscn_id_cnt;
4383 /* If we are already processing an RSCN, save the received
4384 * RSCN payload buffer, cmdiocb->context2 to process later.
4386 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4387 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4388 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4389 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4391 spin_lock_irq(shost->host_lock);
4392 vport->fc_flag |= FC_RSCN_DEFERRED;
4393 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4394 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4395 vport->fc_flag |= FC_RSCN_MODE;
4396 spin_unlock_irq(shost->host_lock);
4398 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4399 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4402 (payload_len + length <= LPFC_BPL_SIZE)) {
4403 *cmd &= ELS_CMD_MASK;
4404 *cmd |= cpu_to_be32(payload_len + length);
4405 memcpy(((uint8_t *)cmd) + length, lp,
4408 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4409 vport->fc_rscn_id_cnt++;
4410 /* If we zero, cmdiocb->context2, the calling
4411 * routine will not try to free it.
4413 cmdiocb->context2 = NULL;
4416 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4417 "0235 Deferred RSCN "
4418 "Data: x%x x%x x%x\n",
4419 vport->fc_rscn_id_cnt, vport->fc_flag,
4422 vport->fc_flag |= FC_RSCN_DISCOVERY;
4423 spin_unlock_irq(shost->host_lock);
4424 /* ReDiscovery RSCN */
4425 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4426 "0234 ReDiscovery RSCN "
4427 "Data: x%x x%x x%x\n",
4428 vport->fc_rscn_id_cnt, vport->fc_flag,
4431 /* Indicate we are done walking fc_rscn_id_list on this vport */
4432 vport->fc_rscn_flush = 0;
4434 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4435 /* send RECOVERY event for ALL nodes that match RSCN payload */
4436 lpfc_rscn_recovery_check(vport);
4437 spin_lock_irq(shost->host_lock);
4438 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4439 spin_unlock_irq(shost->host_lock);
4442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4443 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4444 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4446 spin_lock_irq(shost->host_lock);
4447 vport->fc_flag |= FC_RSCN_MODE;
4448 spin_unlock_irq(shost->host_lock);
4449 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4450 /* Indicate we are done walking fc_rscn_id_list on this vport */
4451 vport->fc_rscn_flush = 0;
4453 * If we zero, cmdiocb->context2, the calling routine will
4454 * not try to free it.
4456 cmdiocb->context2 = NULL;
4457 lpfc_set_disctmo(vport);
4459 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4460 /* send RECOVERY event for ALL nodes that match RSCN payload */
4461 lpfc_rscn_recovery_check(vport);
4462 return lpfc_els_handle_rscn(vport);
4466 * lpfc_els_handle_rscn - Handle rscn for a vport
4467 * @vport: pointer to a host virtual N_Port data structure.
4469 * This routine handles the Registration State Configuration Notification
4470 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4471 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4472 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4473 * NameServer shall be issued. If CT command to the NameServer fails to be
4474 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4475 * RSCN activities with the @vport.
4478 * 0 - Cleaned up rscn on the @vport
4479 * 1 - Wait for plogi to name server before proceed
4482 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4484 struct lpfc_nodelist *ndlp;
4485 struct lpfc_hba *phba = vport->phba;
4487 /* Ignore RSCN if the port is being torn down. */
4488 if (vport->load_flag & FC_UNLOADING) {
4489 lpfc_els_flush_rscn(vport);
4493 /* Start timer for RSCN processing */
4494 lpfc_set_disctmo(vport);
4496 /* RSCN processed */
4497 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4498 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4499 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4502 /* To process RSCN, first compare RSCN data with NameServer */
4503 vport->fc_ns_retry = 0;
4504 vport->num_disc_nodes = 0;
4506 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4507 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4508 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4509 /* Good ndlp, issue CT Request to NameServer */
4510 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4511 /* Wait for NameServer query cmpl before we can
4515 /* If login to NameServer does not exist, issue one */
4516 /* Good status, issue PLOGI to NameServer */
4517 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4518 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4519 /* Wait for NameServer login cmpl before we can
4524 ndlp = lpfc_enable_node(vport, ndlp,
4525 NLP_STE_PLOGI_ISSUE);
4527 lpfc_els_flush_rscn(vport);
4530 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4532 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4534 lpfc_els_flush_rscn(vport);
4537 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4538 ndlp->nlp_prev_state = ndlp->nlp_state;
4539 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4541 ndlp->nlp_type |= NLP_FABRIC;
4542 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4543 /* Wait for NameServer login cmpl before we can
4549 lpfc_els_flush_rscn(vport);
4554 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4555 * @vport: pointer to a host virtual N_Port data structure.
4556 * @cmdiocb: pointer to lpfc command iocb data structure.
4557 * @ndlp: pointer to a node-list data structure.
4559 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4560 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4561 * point topology. As an unsolicited FLOGI should not be received in a loop
4562 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4563 * lpfc_check_sparm() routine is invoked to check the parameters in the
4564 * unsolicited FLOGI. If parameters validation failed, the routine
4565 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4566 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4567 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4568 * will initiate PLOGI. The higher lexicographical value party shall has
4569 * higher priority (as the winning port) and will initiate PLOGI and
4570 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4571 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4572 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4575 * 0 - Successfully processed the unsolicited flogi
4576 * 1 - Failed to process the unsolicited flogi
4579 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4580 struct lpfc_nodelist *ndlp)
4582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4583 struct lpfc_hba *phba = vport->phba;
4584 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4585 uint32_t *lp = (uint32_t *) pcmd->virt;
4586 IOCB_t *icmd = &cmdiocb->iocb;
4587 struct serv_parm *sp;
4594 sp = (struct serv_parm *) lp;
4596 /* FLOGI received */
4598 lpfc_set_disctmo(vport);
4600 if (phba->fc_topology == TOPOLOGY_LOOP) {
4601 /* We should never receive a FLOGI in loop mode, ignore it */
4602 did = icmd->un.elsreq64.remoteID;
4604 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4606 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4607 "0113 An FLOGI ELS command x%x was "
4608 "received from DID x%x in Loop Mode\n",
4615 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
4616 /* For a FLOGI we accept, then if our portname is greater
4617 * then the remote portname we initiate Nport login.
4620 rc = memcmp(&vport->fc_portname, &sp->portName,
4621 sizeof(struct lpfc_name));
4624 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4628 lpfc_linkdown(phba);
4629 lpfc_init_link(phba, mbox,
4631 phba->cfg_link_speed);
4632 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4633 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4634 mbox->vport = vport;
4635 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4636 lpfc_set_loopback_flag(phba);
4637 if (rc == MBX_NOT_FINISHED) {
4638 mempool_free(mbox, phba->mbox_mem_pool);
4641 } else if (rc > 0) { /* greater than */
4642 spin_lock_irq(shost->host_lock);
4643 vport->fc_flag |= FC_PT2PT_PLOGI;
4644 spin_unlock_irq(shost->host_lock);
4646 spin_lock_irq(shost->host_lock);
4647 vport->fc_flag |= FC_PT2PT;
4648 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4649 spin_unlock_irq(shost->host_lock);
4651 /* Reject this request because invalid parameters */
4652 stat.un.b.lsRjtRsvd0 = 0;
4653 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4654 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4655 stat.un.b.vendorUnique = 0;
4656 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4662 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4668 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4669 * @vport: pointer to a host virtual N_Port data structure.
4670 * @cmdiocb: pointer to lpfc command iocb data structure.
4671 * @ndlp: pointer to a node-list data structure.
4673 * This routine processes Request Node Identification Data (RNID) IOCB
4674 * received as an ELS unsolicited event. Only when the RNID specified format
4675 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4676 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4677 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4678 * rejected by invoking the lpfc_els_rsp_reject() routine.
4681 * 0 - Successfully processed rnid iocb (currently always return 0)
4684 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4685 struct lpfc_nodelist *ndlp)
4687 struct lpfc_dmabuf *pcmd;
4694 icmd = &cmdiocb->iocb;
4695 did = icmd->un.elsreq64.remoteID;
4696 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4697 lp = (uint32_t *) pcmd->virt;
4704 switch (rn->Format) {
4706 case RNID_TOPOLOGY_DISC:
4708 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4711 /* Reject this request because format not supported */
4712 stat.un.b.lsRjtRsvd0 = 0;
4713 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4714 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4715 stat.un.b.vendorUnique = 0;
4716 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4723 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4724 * @vport: pointer to a host virtual N_Port data structure.
4725 * @cmdiocb: pointer to lpfc command iocb data structure.
4726 * @ndlp: pointer to a node-list data structure.
4729 * 0 - Successfully processed echo iocb (currently always return 0)
4732 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4733 struct lpfc_nodelist *ndlp)
4737 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4739 /* skip over first word of echo command to find echo data */
4740 pcmd += sizeof(uint32_t);
4742 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4747 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4748 * @vport: pointer to a host virtual N_Port data structure.
4749 * @cmdiocb: pointer to lpfc command iocb data structure.
4750 * @ndlp: pointer to a node-list data structure.
4752 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4753 * received as an ELS unsolicited event. Currently, this function just invokes
4754 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4757 * 0 - Successfully processed lirr iocb (currently always return 0)
4760 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4761 struct lpfc_nodelist *ndlp)
4765 /* For now, unconditionally reject this command */
4766 stat.un.b.lsRjtRsvd0 = 0;
4767 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4768 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4769 stat.un.b.vendorUnique = 0;
4770 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4775 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4776 * @vport: pointer to a host virtual N_Port data structure.
4777 * @cmdiocb: pointer to lpfc command iocb data structure.
4778 * @ndlp: pointer to a node-list data structure.
4780 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4781 * received as an ELS unsolicited event. A request to RRQ shall only
4782 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4783 * Nx_Port N_Port_ID of the target Exchange is the same as the
4784 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4785 * not accepted, an LS_RJT with reason code "Unable to perform
4786 * command request" and reason code explanation "Invalid Originator
4787 * S_ID" shall be returned. For now, we just unconditionally accept
4788 * RRQ from the target.
4791 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4792 struct lpfc_nodelist *ndlp)
4794 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4798 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4799 * @phba: pointer to lpfc hba data structure.
4800 * @pmb: pointer to the driver internal queue element for mailbox command.
4802 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4803 * mailbox command. This callback function is to actually send the Accept
4804 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4805 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4806 * mailbox command, constructs the RPS response with the link statistics
4807 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4808 * response to the RPS.
4810 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4811 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4812 * will be stored into the context1 field of the IOCB for the completion
4813 * callback function to the RPS Accept Response ELS IOCB command.
4817 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4821 struct RLS_RSP *rls_rsp;
4823 struct lpfc_iocbq *elsiocb;
4824 struct lpfc_nodelist *ndlp;
4830 ndlp = (struct lpfc_nodelist *) pmb->context2;
4831 xri = (uint16_t) ((unsigned long)(pmb->context1));
4832 pmb->context1 = NULL;
4833 pmb->context2 = NULL;
4835 if (mb->mbxStatus) {
4836 mempool_free(pmb, phba->mbox_mem_pool);
4840 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4841 mempool_free(pmb, phba->mbox_mem_pool);
4842 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4843 lpfc_max_els_tries, ndlp,
4844 ndlp->nlp_DID, ELS_CMD_ACC);
4846 /* Decrement the ndlp reference count from previous mbox command */
4852 icmd = &elsiocb->iocb;
4853 icmd->ulpContext = xri;
4855 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4856 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4857 pcmd += sizeof(uint32_t); /* Skip past command */
4858 rls_rsp = (struct RLS_RSP *)pcmd;
4860 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4861 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4862 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4863 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4864 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4865 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4867 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4868 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4869 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4870 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4871 elsiocb->iotag, elsiocb->iocb.ulpContext,
4872 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4874 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4875 phba->fc_stat.elsXmitACC++;
4876 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4877 lpfc_els_free_iocb(phba, elsiocb);
4881 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4882 * @phba: pointer to lpfc hba data structure.
4883 * @pmb: pointer to the driver internal queue element for mailbox command.
4885 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4886 * mailbox command. This callback function is to actually send the Accept
4887 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4888 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4889 * mailbox command, constructs the RPS response with the link statistics
4890 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4891 * response to the RPS.
4893 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4894 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4895 * will be stored into the context1 field of the IOCB for the completion
4896 * callback function to the RPS Accept Response ELS IOCB command.
4900 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4906 struct lpfc_iocbq *elsiocb;
4907 struct lpfc_nodelist *ndlp;
4908 uint16_t xri, status;
4913 ndlp = (struct lpfc_nodelist *) pmb->context2;
4914 xri = (uint16_t) ((unsigned long)(pmb->context1));
4915 pmb->context1 = NULL;
4916 pmb->context2 = NULL;
4918 if (mb->mbxStatus) {
4919 mempool_free(pmb, phba->mbox_mem_pool);
4923 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
4924 mempool_free(pmb, phba->mbox_mem_pool);
4925 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4926 lpfc_max_els_tries, ndlp,
4927 ndlp->nlp_DID, ELS_CMD_ACC);
4929 /* Decrement the ndlp reference count from previous mbox command */
4935 icmd = &elsiocb->iocb;
4936 icmd->ulpContext = xri;
4938 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4939 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4940 pcmd += sizeof(uint32_t); /* Skip past command */
4941 rps_rsp = (RPS_RSP *)pcmd;
4943 if (phba->fc_topology != TOPOLOGY_LOOP)
4947 if (phba->pport->fc_flag & FC_FABRIC)
4951 rps_rsp->portStatus = cpu_to_be16(status);
4952 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4953 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4954 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4955 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4956 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4957 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4958 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4959 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4960 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4961 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4962 elsiocb->iotag, elsiocb->iocb.ulpContext,
4963 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4965 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4966 phba->fc_stat.elsXmitACC++;
4967 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4968 lpfc_els_free_iocb(phba, elsiocb);
4973 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4974 * @vport: pointer to a host virtual N_Port data structure.
4975 * @cmdiocb: pointer to lpfc command iocb data structure.
4976 * @ndlp: pointer to a node-list data structure.
4978 * This routine processes Read Port Status (RPL) IOCB received as an
4979 * ELS unsolicited event. It first checks the remote port state. If the
4980 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4981 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
4982 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4983 * for reading the HBA link statistics. It is for the callback function,
4984 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
4985 * to actually sending out RPL Accept (ACC) response.
4988 * 0 - Successfully processed rls iocb (currently always return 0)
4991 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4992 struct lpfc_nodelist *ndlp)
4994 struct lpfc_hba *phba = vport->phba;
4996 struct lpfc_dmabuf *pcmd;
4999 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5000 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5001 /* reject the unsolicited RPS request and done with it */
5004 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5006 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5008 lpfc_read_lnk_stat(phba, mbox);
5010 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5011 mbox->context2 = lpfc_nlp_get(ndlp);
5012 mbox->vport = vport;
5013 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5014 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5015 != MBX_NOT_FINISHED)
5016 /* Mbox completion will send ELS Response */
5018 /* Decrement reference count used for the failed mbox
5022 mempool_free(mbox, phba->mbox_mem_pool);
5025 /* issue rejection response */
5026 stat.un.b.lsRjtRsvd0 = 0;
5027 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5028 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5029 stat.un.b.vendorUnique = 0;
5030 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5035 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5036 * @vport: pointer to a host virtual N_Port data structure.
5037 * @cmdiocb: pointer to lpfc command iocb data structure.
5038 * @ndlp: pointer to a node-list data structure.
5040 * This routine processes Read Timout Value (RTV) IOCB received as an
5041 * ELS unsolicited event. It first checks the remote port state. If the
5042 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5043 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5044 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5045 * Value (RTV) unsolicited IOCB event.
5047 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5048 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5049 * will be stored into the context1 field of the IOCB for the completion
5050 * callback function to the RPS Accept Response ELS IOCB command.
5053 * 0 - Successfully processed rtv iocb (currently always return 0)
5056 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5057 struct lpfc_nodelist *ndlp)
5059 struct lpfc_hba *phba = vport->phba;
5061 struct RTV_RSP *rtv_rsp;
5063 struct lpfc_iocbq *elsiocb;
5067 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5068 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5069 /* reject the unsolicited RPS request and done with it */
5072 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5073 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5074 lpfc_max_els_tries, ndlp,
5075 ndlp->nlp_DID, ELS_CMD_ACC);
5080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5081 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5082 pcmd += sizeof(uint32_t); /* Skip past command */
5084 /* use the command's xri in the response */
5085 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5087 rtv_rsp = (struct RTV_RSP *)pcmd;
5089 /* populate RTV payload */
5090 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5091 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5092 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5093 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5094 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5096 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5097 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5098 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5099 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5100 "Data: x%x x%x x%x\n",
5101 elsiocb->iotag, elsiocb->iocb.ulpContext,
5102 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5104 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5105 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5106 phba->fc_stat.elsXmitACC++;
5107 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5108 lpfc_els_free_iocb(phba, elsiocb);
5112 /* issue rejection response */
5113 stat.un.b.lsRjtRsvd0 = 0;
5114 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5115 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5116 stat.un.b.vendorUnique = 0;
5117 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5121 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5122 * @vport: pointer to a host virtual N_Port data structure.
5123 * @cmdiocb: pointer to lpfc command iocb data structure.
5124 * @ndlp: pointer to a node-list data structure.
5126 * This routine processes Read Port Status (RPS) IOCB received as an
5127 * ELS unsolicited event. It first checks the remote port state. If the
5128 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5129 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5130 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5131 * for reading the HBA link statistics. It is for the callback function,
5132 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5133 * to actually sending out RPS Accept (ACC) response.
5136 * 0 - Successfully processed rps iocb (currently always return 0)
5139 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5140 struct lpfc_nodelist *ndlp)
5142 struct lpfc_hba *phba = vport->phba;
5146 struct lpfc_dmabuf *pcmd;
5150 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5151 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5152 /* reject the unsolicited RPS request and done with it */
5155 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5156 lp = (uint32_t *) pcmd->virt;
5157 flag = (be32_to_cpu(*lp++) & 0xf);
5161 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
5162 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
5163 sizeof(struct lpfc_name)) == 0))) {
5165 printk("Fix me....\n");
5167 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5169 lpfc_read_lnk_stat(phba, mbox);
5171 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5172 mbox->context2 = lpfc_nlp_get(ndlp);
5173 mbox->vport = vport;
5174 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
5175 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5176 != MBX_NOT_FINISHED)
5177 /* Mbox completion will send ELS Response */
5179 /* Decrement reference count used for the failed mbox
5183 mempool_free(mbox, phba->mbox_mem_pool);
5188 /* issue rejection response */
5189 stat.un.b.lsRjtRsvd0 = 0;
5190 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5191 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5192 stat.un.b.vendorUnique = 0;
5193 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5198 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5199 * @vport: pointer to a host virtual N_Port data structure.
5200 * @cmdsize: size of the ELS command.
5201 * @oldiocb: pointer to the original lpfc command iocb data structure.
5202 * @ndlp: pointer to a node-list data structure.
5204 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5205 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5207 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5208 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5209 * will be stored into the context1 field of the IOCB for the completion
5210 * callback function to the RPL Accept Response ELS command.
5213 * 0 - Successfully issued ACC RPL ELS command
5214 * 1 - Failed to issue ACC RPL ELS command
5217 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5218 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5220 struct lpfc_hba *phba = vport->phba;
5221 IOCB_t *icmd, *oldcmd;
5223 struct lpfc_iocbq *elsiocb;
5226 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5227 ndlp->nlp_DID, ELS_CMD_ACC);
5232 icmd = &elsiocb->iocb;
5233 oldcmd = &oldiocb->iocb;
5234 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5236 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5237 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5238 pcmd += sizeof(uint16_t);
5239 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5240 pcmd += sizeof(uint16_t);
5242 /* Setup the RPL ACC payload */
5243 rpl_rsp.listLen = be32_to_cpu(1);
5245 rpl_rsp.port_num_blk.portNum = 0;
5246 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5247 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
5248 sizeof(struct lpfc_name));
5249 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
5250 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5251 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5252 "0120 Xmit ELS RPL ACC response tag x%x "
5253 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5255 elsiocb->iotag, elsiocb->iocb.ulpContext,
5256 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5258 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5259 phba->fc_stat.elsXmitACC++;
5260 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5262 lpfc_els_free_iocb(phba, elsiocb);
5269 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5270 * @vport: pointer to a host virtual N_Port data structure.
5271 * @cmdiocb: pointer to lpfc command iocb data structure.
5272 * @ndlp: pointer to a node-list data structure.
5274 * This routine processes Read Port List (RPL) IOCB received as an ELS
5275 * unsolicited event. It first checks the remote port state. If the remote
5276 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5277 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5278 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5279 * to accept the RPL.
5282 * 0 - Successfully processed rpl iocb (currently always return 0)
5285 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5286 struct lpfc_nodelist *ndlp)
5288 struct lpfc_dmabuf *pcmd;
5295 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5296 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
5297 /* issue rejection response */
5298 stat.un.b.lsRjtRsvd0 = 0;
5299 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5300 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5301 stat.un.b.vendorUnique = 0;
5302 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5304 /* rejected the unsolicited RPL request and done with it */
5308 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5309 lp = (uint32_t *) pcmd->virt;
5310 rpl = (RPL *) (lp + 1);
5311 maxsize = be32_to_cpu(rpl->maxsize);
5313 /* We support only one port */
5314 if ((rpl->index == 0) &&
5316 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5317 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
5319 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5321 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
5327 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5328 * @vport: pointer to a virtual N_Port data structure.
5329 * @cmdiocb: pointer to lpfc command iocb data structure.
5330 * @ndlp: pointer to a node-list data structure.
5332 * This routine processes Fibre Channel Address Resolution Protocol
5333 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5334 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5335 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5336 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5337 * remote PortName is compared against the FC PortName stored in the @vport
5338 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5339 * compared against the FC NodeName stored in the @vport data structure.
5340 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5341 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5342 * invoked to send out FARP Response to the remote node. Before sending the
5343 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5344 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5345 * routine is invoked to log into the remote port first.
5348 * 0 - Either the FARP Match Mode not supported or successfully processed
5351 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5352 struct lpfc_nodelist *ndlp)
5354 struct lpfc_dmabuf *pcmd;
5358 uint32_t cmd, cnt, did;
5360 icmd = &cmdiocb->iocb;
5361 did = icmd->un.elsreq64.remoteID;
5362 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5363 lp = (uint32_t *) pcmd->virt;
5367 /* FARP-REQ received from DID <did> */
5368 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5369 "0601 FARP-REQ received from DID x%x\n", did);
5370 /* We will only support match on WWPN or WWNN */
5371 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
5376 /* If this FARP command is searching for my portname */
5377 if (fp->Mflags & FARP_MATCH_PORT) {
5378 if (memcmp(&fp->RportName, &vport->fc_portname,
5379 sizeof(struct lpfc_name)) == 0)
5383 /* If this FARP command is searching for my nodename */
5384 if (fp->Mflags & FARP_MATCH_NODE) {
5385 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
5386 sizeof(struct lpfc_name)) == 0)
5391 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5392 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5393 /* Log back into the node before sending the FARP. */
5394 if (fp->Rflags & FARP_REQUEST_PLOGI) {
5395 ndlp->nlp_prev_state = ndlp->nlp_state;
5396 lpfc_nlp_set_state(vport, ndlp,
5397 NLP_STE_PLOGI_ISSUE);
5398 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5401 /* Send a FARP response to that node */
5402 if (fp->Rflags & FARP_REQUEST_FARPR)
5403 lpfc_issue_els_farpr(vport, did, 0);
5410 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5411 * @vport: pointer to a host virtual N_Port data structure.
5412 * @cmdiocb: pointer to lpfc command iocb data structure.
5413 * @ndlp: pointer to a node-list data structure.
5415 * This routine processes Fibre Channel Address Resolution Protocol
5416 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5417 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5418 * the FARP response request.
5421 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5424 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5425 struct lpfc_nodelist *ndlp)
5427 struct lpfc_dmabuf *pcmd;
5432 icmd = &cmdiocb->iocb;
5433 did = icmd->un.elsreq64.remoteID;
5434 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5435 lp = (uint32_t *) pcmd->virt;
5438 /* FARP-RSP received from DID <did> */
5439 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5440 "0600 FARP-RSP received from DID x%x\n", did);
5441 /* ACCEPT the Farp resp request */
5442 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5448 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5449 * @vport: pointer to a host virtual N_Port data structure.
5450 * @cmdiocb: pointer to lpfc command iocb data structure.
5451 * @fan_ndlp: pointer to a node-list data structure.
5453 * This routine processes a Fabric Address Notification (FAN) IOCB
5454 * command received as an ELS unsolicited event. The FAN ELS command will
5455 * only be processed on a physical port (i.e., the @vport represents the
5456 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5457 * compared against those in the phba data structure. If any of those is
5458 * different, the lpfc_initial_flogi() routine is invoked to initialize
5459 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5460 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5461 * is invoked to register login to the fabric.
5464 * 0 - Successfully processed fan iocb (currently always return 0).
5467 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5468 struct lpfc_nodelist *fan_ndlp)
5470 struct lpfc_hba *phba = vport->phba;
5474 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5475 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5477 /* FAN received; Fan does not have a reply sequence */
5478 if ((vport == phba->pport) &&
5479 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
5480 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
5481 sizeof(struct lpfc_name))) ||
5482 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
5483 sizeof(struct lpfc_name)))) {
5484 /* This port has switched fabrics. FLOGI is required */
5485 lpfc_initial_flogi(vport);
5487 /* FAN verified - skip FLOGI */
5488 vport->fc_myDID = vport->fc_prevDID;
5489 if (phba->sli_rev < LPFC_SLI_REV4)
5490 lpfc_issue_fabric_reglogin(vport);
5492 lpfc_issue_reg_vfi(vport);
5499 * lpfc_els_timeout - Handler funciton to the els timer
5500 * @ptr: holder for the timer function associated data.
5502 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5503 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5504 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5505 * up the worker thread. It is for the worker thread to invoke the routine
5506 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5509 lpfc_els_timeout(unsigned long ptr)
5511 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5512 struct lpfc_hba *phba = vport->phba;
5513 uint32_t tmo_posted;
5514 unsigned long iflag;
5516 spin_lock_irqsave(&vport->work_port_lock, iflag);
5517 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5519 vport->work_port_events |= WORKER_ELS_TMO;
5520 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
5523 lpfc_worker_wake_up(phba);
5529 * lpfc_els_timeout_handler - Process an els timeout event
5530 * @vport: pointer to a virtual N_Port data structure.
5532 * This routine is the actual handler function that processes an ELS timeout
5533 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5534 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5535 * invoking the lpfc_sli_issue_abort_iotag() routine.
5538 lpfc_els_timeout_handler(struct lpfc_vport *vport)
5540 struct lpfc_hba *phba = vport->phba;
5541 struct lpfc_sli_ring *pring;
5542 struct lpfc_iocbq *tmp_iocb, *piocb;
5544 struct lpfc_dmabuf *pcmd;
5545 uint32_t els_command = 0;
5547 uint32_t remote_ID = 0xffffffff;
5548 LIST_HEAD(txcmplq_completions);
5549 LIST_HEAD(abort_list);
5552 timeout = (uint32_t)(phba->fc_ratov << 1);
5554 pring = &phba->sli.ring[LPFC_ELS_RING];
5556 spin_lock_irq(&phba->hbalock);
5557 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5558 spin_unlock_irq(&phba->hbalock);
5560 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
5563 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5564 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5565 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
5568 if (piocb->vport != vport)
5571 pcmd = (struct lpfc_dmabuf *) piocb->context2;
5573 els_command = *(uint32_t *) (pcmd->virt);
5575 if (els_command == ELS_CMD_FARP ||
5576 els_command == ELS_CMD_FARPR ||
5577 els_command == ELS_CMD_FDISC)
5580 if (piocb->drvrTimeout > 0) {
5581 if (piocb->drvrTimeout >= timeout)
5582 piocb->drvrTimeout -= timeout;
5584 piocb->drvrTimeout = 0;
5588 remote_ID = 0xffffffff;
5589 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
5590 remote_ID = cmd->un.elsreq64.remoteID;
5592 struct lpfc_nodelist *ndlp;
5593 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
5594 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5595 remote_ID = ndlp->nlp_DID;
5597 list_add_tail(&piocb->dlist, &abort_list);
5599 spin_lock_irq(&phba->hbalock);
5600 list_splice(&txcmplq_completions, &pring->txcmplq);
5601 spin_unlock_irq(&phba->hbalock);
5603 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5604 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5605 "0127 ELS timeout Data: x%x x%x x%x "
5606 "x%x\n", els_command,
5607 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5608 spin_lock_irq(&phba->hbalock);
5609 list_del_init(&piocb->dlist);
5610 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5611 spin_unlock_irq(&phba->hbalock);
5614 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5615 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
5619 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5620 * @vport: pointer to a host virtual N_Port data structure.
5622 * This routine is used to clean up all the outstanding ELS commands on a
5623 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5624 * routine. After that, it walks the ELS transmit queue to remove all the
5625 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5626 * the IOCBs with a non-NULL completion callback function, the callback
5627 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5628 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5629 * callback function, the IOCB will simply be released. Finally, it walks
5630 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5631 * completion queue IOCB that is associated with the @vport and is not
5632 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5633 * part of the discovery state machine) out to HBA by invoking the
5634 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5635 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5636 * the IOCBs are aborted when this function returns.
5639 lpfc_els_flush_cmd(struct lpfc_vport *vport)
5641 LIST_HEAD(completions);
5642 struct lpfc_hba *phba = vport->phba;
5643 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5644 struct lpfc_iocbq *tmp_iocb, *piocb;
5647 lpfc_fabric_abort_vport(vport);
5649 spin_lock_irq(&phba->hbalock);
5650 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5653 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5657 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5658 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5659 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5660 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5661 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5664 if (piocb->vport != vport)
5667 list_move_tail(&piocb->list, &completions);
5671 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5672 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5676 if (piocb->vport != vport)
5679 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5681 spin_unlock_irq(&phba->hbalock);
5683 /* Cancell all the IOCBs from the completions list */
5684 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5691 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5692 * @phba: pointer to lpfc hba data structure.
5694 * This routine is used to clean up all the outstanding ELS commands on a
5695 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5696 * routine. After that, it walks the ELS transmit queue to remove all the
5697 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5698 * the IOCBs with the completion callback function associated, the callback
5699 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5700 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5701 * callback function associated, the IOCB will simply be released. Finally,
5702 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5703 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5704 * management plane IOCBs that are not part of the discovery state machine)
5705 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5708 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5710 LIST_HEAD(completions);
5711 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5712 struct lpfc_iocbq *tmp_iocb, *piocb;
5715 lpfc_fabric_abort_hba(phba);
5716 spin_lock_irq(&phba->hbalock);
5717 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5719 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5721 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5722 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5723 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5724 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5725 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5727 list_move_tail(&piocb->list, &completions);
5730 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5731 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5733 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5735 spin_unlock_irq(&phba->hbalock);
5737 /* Cancel all the IOCBs from the completions list */
5738 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5745 * lpfc_send_els_failure_event - Posts an ELS command failure event
5746 * @phba: Pointer to hba context object.
5747 * @cmdiocbp: Pointer to command iocb which reported error.
5748 * @rspiocbp: Pointer to response iocb which reported error.
5750 * This function sends an event when there is an ELS command
5754 lpfc_send_els_failure_event(struct lpfc_hba *phba,
5755 struct lpfc_iocbq *cmdiocbp,
5756 struct lpfc_iocbq *rspiocbp)
5758 struct lpfc_vport *vport = cmdiocbp->vport;
5759 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5760 struct lpfc_lsrjt_event lsrjt_event;
5761 struct lpfc_fabric_event_header fabric_event;
5763 struct lpfc_nodelist *ndlp;
5766 ndlp = cmdiocbp->context1;
5767 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5770 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5771 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5772 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5773 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5774 sizeof(struct lpfc_name));
5775 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5776 sizeof(struct lpfc_name));
5777 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5778 cmdiocbp->context2)->virt);
5779 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
5780 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5781 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5782 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5783 fc_host_post_vendor_event(shost,
5784 fc_get_event_number(),
5785 sizeof(lsrjt_event),
5786 (char *)&lsrjt_event,
5790 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5791 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5792 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5793 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5794 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5796 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5797 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5798 sizeof(struct lpfc_name));
5799 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5800 sizeof(struct lpfc_name));
5801 fc_host_post_vendor_event(shost,
5802 fc_get_event_number(),
5803 sizeof(fabric_event),
5804 (char *)&fabric_event,
5812 * lpfc_send_els_event - Posts unsolicited els event
5813 * @vport: Pointer to vport object.
5814 * @ndlp: Pointer FC node object.
5815 * @cmd: ELS command code.
5817 * This function posts an event when there is an incoming
5818 * unsolicited ELS command.
5821 lpfc_send_els_event(struct lpfc_vport *vport,
5822 struct lpfc_nodelist *ndlp,
5825 struct lpfc_els_event_header *els_data = NULL;
5826 struct lpfc_logo_event *logo_data = NULL;
5827 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5829 if (*payload == ELS_CMD_LOGO) {
5830 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5832 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5833 "0148 Failed to allocate memory "
5834 "for LOGO event\n");
5837 els_data = &logo_data->header;
5839 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5842 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5843 "0149 Failed to allocate memory "
5848 els_data->event_type = FC_REG_ELS_EVENT;
5851 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
5854 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
5857 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5860 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5861 /* Copy the WWPN in the LOGO payload */
5862 memcpy(logo_data->logo_wwpn, &payload[2],
5863 sizeof(struct lpfc_name));
5869 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5870 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5871 if (*payload == ELS_CMD_LOGO) {
5872 fc_host_post_vendor_event(shost,
5873 fc_get_event_number(),
5874 sizeof(struct lpfc_logo_event),
5879 fc_host_post_vendor_event(shost,
5880 fc_get_event_number(),
5881 sizeof(struct lpfc_els_event_header),
5892 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5893 * @phba: pointer to lpfc hba data structure.
5894 * @pring: pointer to a SLI ring.
5895 * @vport: pointer to a host virtual N_Port data structure.
5896 * @elsiocb: pointer to lpfc els command iocb data structure.
5898 * This routine is used for processing the IOCB associated with a unsolicited
5899 * event. It first determines whether there is an existing ndlp that matches
5900 * the DID from the unsolicited IOCB. If not, it will create a new one with
5901 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5902 * IOCB is then used to invoke the proper routine and to set up proper state
5903 * of the discovery state machine.
5906 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5907 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
5909 struct Scsi_Host *shost;
5910 struct lpfc_nodelist *ndlp;
5913 uint32_t cmd, did, newnode, rjt_err = 0;
5914 IOCB_t *icmd = &elsiocb->iocb;
5916 if (!vport || !(elsiocb->context2))
5920 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5922 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
5923 lpfc_post_buffer(phba, pring, 1);
5925 did = icmd->un.rcvels.remoteID;
5926 if (icmd->ulpStatus) {
5927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5928 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5929 icmd->ulpStatus, icmd->un.ulpWord[4], did);
5933 /* Check to see if link went down during discovery */
5934 if (lpfc_els_chk_latt(vport))
5937 /* Ignore traffic received during vport shutdown. */
5938 if (vport->load_flag & FC_UNLOADING)
5941 ndlp = lpfc_findnode_did(vport, did);
5943 /* Cannot find existing Fabric ndlp, so allocate a new one */
5944 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5948 lpfc_nlp_init(vport, ndlp, did);
5949 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5951 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5952 ndlp->nlp_type |= NLP_FABRIC;
5953 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5954 ndlp = lpfc_enable_node(vport, ndlp,
5955 NLP_STE_UNUSED_NODE);
5958 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5960 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5961 ndlp->nlp_type |= NLP_FABRIC;
5962 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5963 /* This is similar to the new node path */
5964 ndlp = lpfc_nlp_get(ndlp);
5967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5971 phba->fc_stat.elsRcvFrame++;
5973 elsiocb->context1 = lpfc_nlp_get(ndlp);
5974 elsiocb->vport = vport;
5976 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5977 cmd &= ELS_CMD_MASK;
5979 /* ELS command <elsCmd> received from NPORT <did> */
5980 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5981 "0112 ELS command x%x received from NPORT x%x "
5982 "Data: x%x\n", cmd, did, vport->port_state);
5985 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5986 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5987 did, vport->port_state, ndlp->nlp_flag);
5989 phba->fc_stat.elsRcvPLOGI++;
5990 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5992 lpfc_send_els_event(vport, ndlp, payload);
5993 if (vport->port_state < LPFC_DISC_AUTH) {
5994 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5995 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5996 rjt_err = LSRJT_UNABLE_TPC;
5999 /* We get here, and drop thru, if we are PT2PT with
6000 * another NPort and the other side has initiated
6001 * the PLOGI before responding to our FLOGI.
6005 shost = lpfc_shost_from_vport(vport);
6006 spin_lock_irq(shost->host_lock);
6007 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6008 spin_unlock_irq(shost->host_lock);
6010 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6015 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6016 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6017 did, vport->port_state, ndlp->nlp_flag);
6019 phba->fc_stat.elsRcvFLOGI++;
6020 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
6025 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6026 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6027 did, vport->port_state, ndlp->nlp_flag);
6029 phba->fc_stat.elsRcvLOGO++;
6030 lpfc_send_els_event(vport, ndlp, payload);
6031 if (vport->port_state < LPFC_DISC_AUTH) {
6032 rjt_err = LSRJT_UNABLE_TPC;
6035 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
6038 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6039 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6040 did, vport->port_state, ndlp->nlp_flag);
6042 phba->fc_stat.elsRcvPRLO++;
6043 lpfc_send_els_event(vport, ndlp, payload);
6044 if (vport->port_state < LPFC_DISC_AUTH) {
6045 rjt_err = LSRJT_UNABLE_TPC;
6048 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
6051 phba->fc_stat.elsRcvRSCN++;
6052 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
6057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6058 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6059 did, vport->port_state, ndlp->nlp_flag);
6061 lpfc_send_els_event(vport, ndlp, payload);
6062 phba->fc_stat.elsRcvADISC++;
6063 if (vport->port_state < LPFC_DISC_AUTH) {
6064 rjt_err = LSRJT_UNABLE_TPC;
6067 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6072 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6073 did, vport->port_state, ndlp->nlp_flag);
6075 phba->fc_stat.elsRcvPDISC++;
6076 if (vport->port_state < LPFC_DISC_AUTH) {
6077 rjt_err = LSRJT_UNABLE_TPC;
6080 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6085 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6086 did, vport->port_state, ndlp->nlp_flag);
6088 phba->fc_stat.elsRcvFARPR++;
6089 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
6092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6093 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6094 did, vport->port_state, ndlp->nlp_flag);
6096 phba->fc_stat.elsRcvFARP++;
6097 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
6100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6101 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6102 did, vport->port_state, ndlp->nlp_flag);
6104 phba->fc_stat.elsRcvFAN++;
6105 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
6108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6109 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6110 did, vport->port_state, ndlp->nlp_flag);
6112 phba->fc_stat.elsRcvPRLI++;
6113 if (vport->port_state < LPFC_DISC_AUTH) {
6114 rjt_err = LSRJT_UNABLE_TPC;
6117 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
6120 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6121 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6122 did, vport->port_state, ndlp->nlp_flag);
6124 phba->fc_stat.elsRcvLIRR++;
6125 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
6130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6131 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6132 did, vport->port_state, ndlp->nlp_flag);
6134 phba->fc_stat.elsRcvRLS++;
6135 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6141 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6142 did, vport->port_state, ndlp->nlp_flag);
6144 phba->fc_stat.elsRcvRPS++;
6145 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
6150 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6151 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6152 did, vport->port_state, ndlp->nlp_flag);
6154 phba->fc_stat.elsRcvRPL++;
6155 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
6160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6161 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6162 did, vport->port_state, ndlp->nlp_flag);
6164 phba->fc_stat.elsRcvRNID++;
6165 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
6170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6171 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6172 did, vport->port_state, ndlp->nlp_flag);
6173 phba->fc_stat.elsRcvRTV++;
6174 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6180 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6181 did, vport->port_state, ndlp->nlp_flag);
6183 phba->fc_stat.elsRcvRRQ++;
6184 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6190 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6191 did, vport->port_state, ndlp->nlp_flag);
6193 phba->fc_stat.elsRcvECHO++;
6194 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6200 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6201 cmd, did, vport->port_state);
6203 /* Unsupported ELS command, reject */
6204 rjt_err = LSRJT_INVALID_CMD;
6206 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6207 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6208 "0115 Unknown ELS command x%x "
6209 "received from NPORT x%x\n", cmd, did);
6215 /* check if need to LS_RJT received ELS cmd */
6217 memset(&stat, 0, sizeof(stat));
6218 stat.un.b.lsRjtRsnCode = rjt_err;
6219 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
6220 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6224 lpfc_nlp_put(elsiocb->context1);
6225 elsiocb->context1 = NULL;
6229 if (vport && !(vport->load_flag & FC_UNLOADING))
6230 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6231 "0111 Dropping received ELS cmd "
6232 "Data: x%x x%x x%x\n",
6233 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
6234 phba->fc_stat.elsRcvDrop++;
6238 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6239 * @phba: pointer to lpfc hba data structure.
6240 * @vpi: host virtual N_Port identifier.
6242 * This routine finds a vport on a HBA (referred by @phba) through a
6243 * @vpi. The function walks the HBA's vport list and returns the address
6244 * of the vport with the matching @vpi.
6247 * NULL - No vport with the matching @vpi found
6248 * Otherwise - Address to the vport with the matching @vpi.
6251 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6253 struct lpfc_vport *vport;
6254 unsigned long flags;
6256 spin_lock_irqsave(&phba->hbalock, flags);
6257 list_for_each_entry(vport, &phba->port_list, listentry) {
6258 if (vport->vpi == vpi) {
6259 spin_unlock_irqrestore(&phba->hbalock, flags);
6263 spin_unlock_irqrestore(&phba->hbalock, flags);
6268 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6269 * @phba: pointer to lpfc hba data structure.
6270 * @pring: pointer to a SLI ring.
6271 * @elsiocb: pointer to lpfc els iocb data structure.
6273 * This routine is used to process an unsolicited event received from a SLI
6274 * (Service Level Interface) ring. The actual processing of the data buffer
6275 * associated with the unsolicited event is done by invoking the routine
6276 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6277 * SLI ring on which the unsolicited event was received.
6280 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6281 struct lpfc_iocbq *elsiocb)
6283 struct lpfc_vport *vport = phba->pport;
6284 IOCB_t *icmd = &elsiocb->iocb;
6286 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6287 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
6289 elsiocb->context1 = NULL;
6290 elsiocb->context2 = NULL;
6291 elsiocb->context3 = NULL;
6293 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6294 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6295 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6296 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
6297 phba->fc_stat.NoRcvBuf++;
6298 /* Not enough posted buffers; Try posting more buffers */
6299 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
6300 lpfc_post_buffer(phba, pring, 0);
6304 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6305 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6306 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6307 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6308 vport = phba->pport;
6310 vport = lpfc_find_vport_by_vpid(phba,
6311 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
6313 /* If there are no BDEs associated
6314 * with this IOCB, there is nothing to do.
6316 if (icmd->ulpBdeCount == 0)
6319 /* type of ELS cmd is first 32bit word
6322 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
6323 elsiocb->context2 = bdeBuf1;
6325 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6326 icmd->un.cont64[0].addrLow);
6327 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6331 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6333 * The different unsolicited event handlers would tell us
6334 * if they are done with "mp" by setting context2 to NULL.
6336 if (elsiocb->context2) {
6337 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6338 elsiocb->context2 = NULL;
6341 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6342 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
6343 icmd->ulpBdeCount == 2) {
6344 elsiocb->context2 = bdeBuf2;
6345 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6346 /* free mp if we are done with it */
6347 if (elsiocb->context2) {
6348 lpfc_in_buf_free(phba, elsiocb->context2);
6349 elsiocb->context2 = NULL;
6355 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6356 * @phba: pointer to lpfc hba data structure.
6357 * @vport: pointer to a virtual N_Port data structure.
6359 * This routine issues a Port Login (PLOGI) to the Name Server with
6360 * State Change Request (SCR) for a @vport. This routine will create an
6361 * ndlp for the Name Server associated to the @vport if such node does
6362 * not already exist. The PLOGI to Name Server is issued by invoking the
6363 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6364 * (FDMI) is configured to the @vport, a FDMI node will be created and
6365 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6368 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6370 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6372 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6374 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6376 if (phba->fc_topology == TOPOLOGY_LOOP) {
6377 lpfc_disc_start(vport);
6380 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6381 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6382 "0251 NameServer login: no memory\n");
6385 lpfc_nlp_init(vport, ndlp, NameServer_DID);
6386 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6387 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6389 if (phba->fc_topology == TOPOLOGY_LOOP) {
6390 lpfc_disc_start(vport);
6393 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6394 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6395 "0348 NameServer login: node freed\n");
6399 ndlp->nlp_type |= NLP_FABRIC;
6401 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6403 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6404 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6405 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6406 "0252 Cannot issue NameServer login\n");
6410 if (vport->cfg_fdmi_on) {
6411 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6414 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6415 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6416 lpfc_nlp_set_state(vport, ndlp_fdmi,
6417 NLP_STE_PLOGI_ISSUE);
6418 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6426 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6427 * @phba: pointer to lpfc hba data structure.
6428 * @pmb: pointer to the driver internal queue element for mailbox command.
6430 * This routine is the completion callback function to register new vport
6431 * mailbox command. If the new vport mailbox command completes successfully,
6432 * the fabric registration login shall be performed on physical port (the
6433 * new vport created is actually a physical port, with VPI 0) or the port
6434 * login to Name Server for State Change Request (SCR) will be performed
6435 * on virtual port (real virtual port, with VPI greater than 0).
6438 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6440 struct lpfc_vport *vport = pmb->vport;
6441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6442 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
6443 MAILBOX_t *mb = &pmb->u.mb;
6446 spin_lock_irq(shost->host_lock);
6447 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6448 spin_unlock_irq(shost->host_lock);
6450 if (mb->mbxStatus) {
6451 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6452 "0915 Register VPI failed : Status: x%x"
6453 " upd bit: x%x \n", mb->mbxStatus,
6454 mb->un.varRegVpi.upd);
6455 if (phba->sli_rev == LPFC_SLI_REV4 &&
6456 mb->un.varRegVpi.upd)
6457 goto mbox_err_exit ;
6459 switch (mb->mbxStatus) {
6460 case 0x11: /* unsupported feature */
6461 case 0x9603: /* max_vpi exceeded */
6462 case 0x9602: /* Link event since CLEAR_LA */
6463 /* giving up on vport registration */
6464 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6465 spin_lock_irq(shost->host_lock);
6466 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6467 spin_unlock_irq(shost->host_lock);
6468 lpfc_can_disctmo(vport);
6470 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6472 spin_lock_irq(shost->host_lock);
6473 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6474 spin_unlock_irq(shost->host_lock);
6475 lpfc_init_vpi(phba, pmb, vport->vpi);
6477 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6478 rc = lpfc_sli_issue_mbox(phba, pmb,
6480 if (rc == MBX_NOT_FINISHED) {
6481 lpfc_printf_vlog(vport,
6483 "2732 Failed to issue INIT_VPI"
6484 " mailbox command\n");
6491 /* Try to recover from this error */
6492 if (phba->sli_rev == LPFC_SLI_REV4)
6493 lpfc_sli4_unreg_all_rpis(vport);
6494 lpfc_mbx_unreg_vpi(vport);
6495 spin_lock_irq(shost->host_lock);
6496 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6497 spin_unlock_irq(shost->host_lock);
6498 if (vport->port_type == LPFC_PHYSICAL_PORT
6499 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
6500 lpfc_initial_flogi(vport);
6502 lpfc_initial_fdisc(vport);
6506 spin_lock_irq(shost->host_lock);
6507 vport->vpi_state |= LPFC_VPI_REGISTERED;
6508 spin_unlock_irq(shost->host_lock);
6509 if (vport == phba->pport) {
6510 if (phba->sli_rev < LPFC_SLI_REV4)
6511 lpfc_issue_fabric_reglogin(vport);
6514 * If the physical port is instantiated using
6515 * FDISC, do not start vport discovery.
6517 if (vport->port_state != LPFC_FDISC)
6518 lpfc_start_fdiscs(phba);
6519 lpfc_do_scr_ns_plogi(phba, vport);
6522 lpfc_do_scr_ns_plogi(phba, vport);
6525 /* Now, we decrement the ndlp reference count held for this
6530 mempool_free(pmb, phba->mbox_mem_pool);
6535 * lpfc_register_new_vport - Register a new vport with a HBA
6536 * @phba: pointer to lpfc hba data structure.
6537 * @vport: pointer to a host virtual N_Port data structure.
6538 * @ndlp: pointer to a node-list data structure.
6540 * This routine registers the @vport as a new virtual port with a HBA.
6541 * It is done through a registering vpi mailbox command.
6544 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6545 struct lpfc_nodelist *ndlp)
6547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6550 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6552 lpfc_reg_vpi(vport, mbox);
6553 mbox->vport = vport;
6554 mbox->context2 = lpfc_nlp_get(ndlp);
6555 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
6556 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6557 == MBX_NOT_FINISHED) {
6558 /* mailbox command not success, decrement ndlp
6559 * reference count for this command
6562 mempool_free(mbox, phba->mbox_mem_pool);
6564 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6565 "0253 Register VPI: Can't send mbox\n");
6569 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6570 "0254 Register VPI: no memory\n");
6576 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6577 spin_lock_irq(shost->host_lock);
6578 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6579 spin_unlock_irq(shost->host_lock);
6584 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6585 * @phba: pointer to lpfc hba data structure.
6587 * This routine cancels the retry delay timers to all the vports.
6590 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
6592 struct lpfc_vport **vports;
6593 struct lpfc_nodelist *ndlp;
6594 uint32_t link_state;
6597 /* Treat this failure as linkdown for all vports */
6598 link_state = phba->link_state;
6599 lpfc_linkdown(phba);
6600 phba->link_state = link_state;
6602 vports = lpfc_create_vport_work_array(phba);
6605 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6606 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6608 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6609 lpfc_els_flush_cmd(vports[i]);
6611 lpfc_destroy_vport_work_array(phba, vports);
6616 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6617 * @phba: pointer to lpfc hba data structure.
6619 * This routine abort all pending discovery commands and
6620 * start a timer to retry FLOGI for the physical port
6624 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6626 struct lpfc_nodelist *ndlp;
6627 struct Scsi_Host *shost;
6629 /* Cancel the all vports retry delay retry timers */
6630 lpfc_cancel_all_vport_retry_delay_timer(phba);
6632 /* If fabric require FLOGI, then re-instantiate physical login */
6633 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6637 shost = lpfc_shost_from_vport(phba->pport);
6638 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6639 spin_lock_irq(shost->host_lock);
6640 ndlp->nlp_flag |= NLP_DELAY_TMO;
6641 spin_unlock_irq(shost->host_lock);
6642 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6643 phba->pport->port_state = LPFC_FLOGI;
6648 * lpfc_fabric_login_reqd - Check if FLOGI required.
6649 * @phba: pointer to lpfc hba data structure.
6650 * @cmdiocb: pointer to FDISC command iocb.
6651 * @rspiocb: pointer to FDISC response iocb.
6653 * This routine checks if a FLOGI is reguired for FDISC
6657 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6658 struct lpfc_iocbq *cmdiocb,
6659 struct lpfc_iocbq *rspiocb)
6662 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6663 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6670 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6671 * @phba: pointer to lpfc hba data structure.
6672 * @cmdiocb: pointer to lpfc command iocb data structure.
6673 * @rspiocb: pointer to lpfc response iocb data structure.
6675 * This routine is the completion callback function to a Fabric Discover
6676 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6677 * single threaded, each FDISC completion callback function will reset
6678 * the discovery timer for all vports such that the timers will not get
6679 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6680 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6681 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6682 * assigned to the vport has been changed with the completion of the FDISC
6683 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6684 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6685 * routine is invoked to register new vport with the HBA. Otherwise, the
6686 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6687 * Server for State Change Request (SCR).
6690 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6691 struct lpfc_iocbq *rspiocb)
6693 struct lpfc_vport *vport = cmdiocb->vport;
6694 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6695 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6696 struct lpfc_nodelist *np;
6697 struct lpfc_nodelist *next_np;
6698 IOCB_t *irsp = &rspiocb->iocb;
6699 struct lpfc_iocbq *piocb;
6701 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6702 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6703 irsp->ulpStatus, irsp->un.ulpWord[4],
6705 /* Since all FDISCs are being single threaded, we
6706 * must reset the discovery timer for ALL vports
6707 * waiting to send FDISC when one completes.
6709 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6710 lpfc_set_disctmo(piocb->vport);
6713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6714 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6715 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6717 if (irsp->ulpStatus) {
6719 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6720 lpfc_retry_pport_discovery(phba);
6724 /* Check for retry */
6725 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6728 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6729 "0126 FDISC failed. (%d/%d)\n",
6730 irsp->ulpStatus, irsp->un.ulpWord[4]);
6733 spin_lock_irq(shost->host_lock);
6734 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
6735 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
6736 vport->fc_flag |= FC_FABRIC;
6737 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6738 vport->fc_flag |= FC_PUBLIC_LOOP;
6739 spin_unlock_irq(shost->host_lock);
6741 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6742 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6743 if ((vport->fc_prevDID != vport->fc_myDID) &&
6744 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6745 /* If our NportID changed, we need to ensure all
6746 * remaining NPORTs get unreg_login'ed so we can
6749 list_for_each_entry_safe(np, next_np,
6750 &vport->fc_nodes, nlp_listp) {
6751 if (!NLP_CHK_NODE_ACT(ndlp) ||
6752 (np->nlp_state != NLP_STE_NPR_NODE) ||
6753 !(np->nlp_flag & NLP_NPR_ADISC))
6755 spin_lock_irq(shost->host_lock);
6756 np->nlp_flag &= ~NLP_NPR_ADISC;
6757 spin_unlock_irq(shost->host_lock);
6758 lpfc_unreg_rpi(vport, np);
6760 lpfc_cleanup_pending_mbox(vport);
6762 if (phba->sli_rev == LPFC_SLI_REV4)
6763 lpfc_sli4_unreg_all_rpis(vport);
6765 lpfc_mbx_unreg_vpi(vport);
6766 spin_lock_irq(shost->host_lock);
6767 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6768 if (phba->sli_rev == LPFC_SLI_REV4)
6769 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6771 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
6772 spin_unlock_irq(shost->host_lock);
6773 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6774 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6776 * Driver needs to re-reg VPI in order for f/w
6777 * to update the MAC address.
6779 lpfc_register_new_vport(phba, vport, ndlp);
6783 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6784 lpfc_issue_init_vpi(vport);
6785 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
6786 lpfc_register_new_vport(phba, vport, ndlp);
6788 lpfc_do_scr_ns_plogi(phba, vport);
6791 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6792 /* Cancel discovery timer */
6793 lpfc_can_disctmo(vport);
6796 lpfc_els_free_iocb(phba, cmdiocb);
6800 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6801 * @vport: pointer to a virtual N_Port data structure.
6802 * @ndlp: pointer to a node-list data structure.
6803 * @retry: number of retries to the command IOCB.
6805 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6806 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6807 * routine to issue the IOCB, which makes sure only one outstanding fabric
6808 * IOCB will be sent off HBA at any given time.
6810 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6811 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6812 * will be stored into the context1 field of the IOCB for the completion
6813 * callback function to the FDISC ELS command.
6816 * 0 - Successfully issued fdisc iocb command
6817 * 1 - Failed to issue fdisc iocb command
6820 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6823 struct lpfc_hba *phba = vport->phba;
6825 struct lpfc_iocbq *elsiocb;
6826 struct serv_parm *sp;
6829 int did = ndlp->nlp_DID;
6832 vport->port_state = LPFC_FDISC;
6833 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6834 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6837 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6839 "0255 Issue FDISC: no IOCB\n");
6843 icmd = &elsiocb->iocb;
6844 icmd->un.elsreq64.myID = 0;
6845 icmd->un.elsreq64.fl = 1;
6847 if (phba->sli_rev == LPFC_SLI_REV4) {
6848 /* FDISC needs to be 1 for WQE VPI */
6849 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6850 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6851 /* Set the ulpContext to the vpi */
6852 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6854 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6859 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6860 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6861 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6862 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6863 sp = (struct serv_parm *) pcmd;
6864 /* Setup CSPs accordingly for Fabric */
6865 sp->cmn.e_d_tov = 0;
6866 sp->cmn.w2.r_a_tov = 0;
6867 sp->cls1.classValid = 0;
6868 sp->cls2.seqDelivery = 1;
6869 sp->cls3.seqDelivery = 1;
6871 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6872 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6873 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6874 pcmd += sizeof(uint32_t); /* Port Name */
6875 memcpy(pcmd, &vport->fc_portname, 8);
6876 pcmd += sizeof(uint32_t); /* Node Name */
6877 pcmd += sizeof(uint32_t); /* Node Name */
6878 memcpy(pcmd, &vport->fc_nodename, 8);
6880 lpfc_set_disctmo(vport);
6882 phba->fc_stat.elsXmitFDISC++;
6883 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6886 "Issue FDISC: did:x%x",
6889 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6890 if (rc == IOCB_ERROR) {
6891 lpfc_els_free_iocb(phba, elsiocb);
6892 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6893 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6894 "0256 Issue FDISC: Cannot send IOCB\n");
6897 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6902 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6903 * @phba: pointer to lpfc hba data structure.
6904 * @cmdiocb: pointer to lpfc command iocb data structure.
6905 * @rspiocb: pointer to lpfc response iocb data structure.
6907 * This routine is the completion callback function to the issuing of a LOGO
6908 * ELS command off a vport. It frees the command IOCB and then decrement the
6909 * reference count held on ndlp for this completion function, indicating that
6910 * the reference to the ndlp is no long needed. Note that the
6911 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6912 * callback function and an additional explicit ndlp reference decrementation
6913 * will trigger the actual release of the ndlp.
6916 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6917 struct lpfc_iocbq *rspiocb)
6919 struct lpfc_vport *vport = cmdiocb->vport;
6921 struct lpfc_nodelist *ndlp;
6922 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
6924 irsp = &rspiocb->iocb;
6925 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6926 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6927 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
6929 lpfc_els_free_iocb(phba, cmdiocb);
6930 vport->unreg_vpi_cmpl = VPORT_ERROR;
6932 /* Trigger the release of the ndlp after logo */
6937 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6938 * @vport: pointer to a virtual N_Port data structure.
6939 * @ndlp: pointer to a node-list data structure.
6941 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6943 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6944 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6945 * will be stored into the context1 field of the IOCB for the completion
6946 * callback function to the LOGO ELS command.
6949 * 0 - Successfully issued logo off the @vport
6950 * 1 - Failed to issue logo off the @vport
6953 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6955 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6956 struct lpfc_hba *phba = vport->phba;
6958 struct lpfc_iocbq *elsiocb;
6962 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6963 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6968 icmd = &elsiocb->iocb;
6969 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6970 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6971 pcmd += sizeof(uint32_t);
6973 /* Fill in LOGO payload */
6974 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6975 pcmd += sizeof(uint32_t);
6976 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6979 "Issue LOGO npiv did:x%x flg:x%x",
6980 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6982 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6983 spin_lock_irq(shost->host_lock);
6984 ndlp->nlp_flag |= NLP_LOGO_SND;
6985 spin_unlock_irq(shost->host_lock);
6986 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6988 spin_lock_irq(shost->host_lock);
6989 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6990 spin_unlock_irq(shost->host_lock);
6991 lpfc_els_free_iocb(phba, elsiocb);
6998 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
6999 * @ptr: holder for the timer function associated data.
7001 * This routine is invoked by the fabric iocb block timer after
7002 * timeout. It posts the fabric iocb block timeout event by setting the
7003 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7004 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7005 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7006 * posted event WORKER_FABRIC_BLOCK_TMO.
7009 lpfc_fabric_block_timeout(unsigned long ptr)
7011 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7012 unsigned long iflags;
7013 uint32_t tmo_posted;
7015 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7016 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7018 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7019 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7022 lpfc_worker_wake_up(phba);
7027 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7028 * @phba: pointer to lpfc hba data structure.
7030 * This routine issues one fabric iocb from the driver internal list to
7031 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7032 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7033 * remove one pending fabric iocb from the driver internal list and invokes
7034 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7037 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7039 struct lpfc_iocbq *iocb;
7040 unsigned long iflags;
7046 spin_lock_irqsave(&phba->hbalock, iflags);
7047 /* Post any pending iocb to the SLI layer */
7048 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7049 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7052 /* Increment fabric iocb count to hold the position */
7053 atomic_inc(&phba->fabric_iocb_count);
7055 spin_unlock_irqrestore(&phba->hbalock, iflags);
7057 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7058 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7059 iocb->iocb_flag |= LPFC_IO_FABRIC;
7061 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7062 "Fabric sched1: ste:x%x",
7063 iocb->vport->port_state, 0, 0);
7065 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7067 if (ret == IOCB_ERROR) {
7068 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7069 iocb->fabric_iocb_cmpl = NULL;
7070 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7072 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7073 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7074 iocb->iocb_cmpl(phba, iocb, iocb);
7076 atomic_dec(&phba->fabric_iocb_count);
7085 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7086 * @phba: pointer to lpfc hba data structure.
7088 * This routine unblocks the issuing fabric iocb command. The function
7089 * will clear the fabric iocb block bit and then invoke the routine
7090 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7091 * from the driver internal fabric iocb list.
7094 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7096 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7098 lpfc_resume_fabric_iocbs(phba);
7103 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7104 * @phba: pointer to lpfc hba data structure.
7106 * This routine blocks the issuing fabric iocb for a specified amount of
7107 * time (currently 100 ms). This is done by set the fabric iocb block bit
7108 * and set up a timeout timer for 100ms. When the block bit is set, no more
7109 * fabric iocb will be issued out of the HBA.
7112 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7116 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7117 /* Start a timer to unblock fabric iocbs after 100ms */
7119 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7125 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7126 * @phba: pointer to lpfc hba data structure.
7127 * @cmdiocb: pointer to lpfc command iocb data structure.
7128 * @rspiocb: pointer to lpfc response iocb data structure.
7130 * This routine is the callback function that is put to the fabric iocb's
7131 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7132 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7133 * function first restores and invokes the original iocb's callback function
7134 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7135 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7138 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7139 struct lpfc_iocbq *rspiocb)
7143 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7146 switch (rspiocb->iocb.ulpStatus) {
7147 case IOSTAT_NPORT_RJT:
7148 case IOSTAT_FABRIC_RJT:
7149 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7150 lpfc_block_fabric_iocbs(phba);
7154 case IOSTAT_NPORT_BSY:
7155 case IOSTAT_FABRIC_BSY:
7156 lpfc_block_fabric_iocbs(phba);
7160 stat.un.lsRjtError =
7161 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7162 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7163 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7164 lpfc_block_fabric_iocbs(phba);
7168 if (atomic_read(&phba->fabric_iocb_count) == 0)
7171 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7172 cmdiocb->fabric_iocb_cmpl = NULL;
7173 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7174 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7176 atomic_dec(&phba->fabric_iocb_count);
7177 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
7178 /* Post any pending iocbs to HBA */
7179 lpfc_resume_fabric_iocbs(phba);
7184 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7185 * @phba: pointer to lpfc hba data structure.
7186 * @iocb: pointer to lpfc command iocb data structure.
7188 * This routine is used as the top-level API for issuing a fabric iocb command
7189 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7190 * function makes sure that only one fabric bound iocb will be outstanding at
7191 * any given time. As such, this function will first check to see whether there
7192 * is already an outstanding fabric iocb on the wire. If so, it will put the
7193 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7194 * issued later. Otherwise, it will issue the iocb on the wire and update the
7195 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7197 * Note, this implementation has a potential sending out fabric IOCBs out of
7198 * order. The problem is caused by the construction of the "ready" boolen does
7199 * not include the condition that the internal fabric IOCB list is empty. As
7200 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7201 * ahead of the fabric IOCBs in the internal list.
7204 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7205 * IOCB_ERROR - failed to issue fabric iocb
7208 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7210 unsigned long iflags;
7214 if (atomic_read(&phba->fabric_iocb_count) > 1)
7217 spin_lock_irqsave(&phba->hbalock, iflags);
7218 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7219 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7222 /* Increment fabric iocb count to hold the position */
7223 atomic_inc(&phba->fabric_iocb_count);
7224 spin_unlock_irqrestore(&phba->hbalock, iflags);
7226 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7227 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7228 iocb->iocb_flag |= LPFC_IO_FABRIC;
7230 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7231 "Fabric sched2: ste:x%x",
7232 iocb->vport->port_state, 0, 0);
7234 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7236 if (ret == IOCB_ERROR) {
7237 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7238 iocb->fabric_iocb_cmpl = NULL;
7239 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7240 atomic_dec(&phba->fabric_iocb_count);
7243 spin_lock_irqsave(&phba->hbalock, iflags);
7244 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7245 spin_unlock_irqrestore(&phba->hbalock, iflags);
7252 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7253 * @vport: pointer to a virtual N_Port data structure.
7255 * This routine aborts all the IOCBs associated with a @vport from the
7256 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7257 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7258 * list, removes each IOCB associated with the @vport off the list, set the
7259 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7260 * associated with the IOCB.
7262 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
7264 LIST_HEAD(completions);
7265 struct lpfc_hba *phba = vport->phba;
7266 struct lpfc_iocbq *tmp_iocb, *piocb;
7268 spin_lock_irq(&phba->hbalock);
7269 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7272 if (piocb->vport != vport)
7275 list_move_tail(&piocb->list, &completions);
7277 spin_unlock_irq(&phba->hbalock);
7279 /* Cancel all the IOCBs from the completions list */
7280 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7285 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7286 * @ndlp: pointer to a node-list data structure.
7288 * This routine aborts all the IOCBs associated with an @ndlp from the
7289 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7290 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7291 * list, removes each IOCB associated with the @ndlp off the list, set the
7292 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7293 * associated with the IOCB.
7295 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7297 LIST_HEAD(completions);
7298 struct lpfc_hba *phba = ndlp->phba;
7299 struct lpfc_iocbq *tmp_iocb, *piocb;
7300 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7302 spin_lock_irq(&phba->hbalock);
7303 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7305 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7307 list_move_tail(&piocb->list, &completions);
7310 spin_unlock_irq(&phba->hbalock);
7312 /* Cancel all the IOCBs from the completions list */
7313 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7318 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7319 * @phba: pointer to lpfc hba data structure.
7321 * This routine aborts all the IOCBs currently on the driver internal
7322 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7323 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7324 * list, removes IOCBs off the list, set the status feild to
7325 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7328 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7330 LIST_HEAD(completions);
7332 spin_lock_irq(&phba->hbalock);
7333 list_splice_init(&phba->fabric_iocb_list, &completions);
7334 spin_unlock_irq(&phba->hbalock);
7336 /* Cancel all the IOCBs from the completions list */
7337 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7342 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7343 * @phba: pointer to lpfc hba data structure.
7344 * @axri: pointer to the els xri abort wcqe structure.
7346 * This routine is invoked by the worker thread to process a SLI4 slow-path
7350 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7351 struct sli4_wcqe_xri_aborted *axri)
7353 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7354 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7355 unsigned long iflag = 0;
7356 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7358 spin_lock_irqsave(&phba->hbalock, iflag);
7359 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7360 list_for_each_entry_safe(sglq_entry, sglq_next,
7361 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7362 if (sglq_entry->sli4_xritag == xri) {
7363 list_del(&sglq_entry->list);
7364 list_add_tail(&sglq_entry->list,
7365 &phba->sli4_hba.lpfc_sgl_list);
7366 sglq_entry->state = SGL_FREED;
7367 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7368 spin_unlock_irqrestore(&phba->hbalock, iflag);
7370 /* Check if TXQ queue needs to be serviced */
7372 lpfc_worker_wake_up(phba);
7376 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7377 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7378 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7379 spin_unlock_irqrestore(&phba->hbalock, iflag);
7382 sglq_entry->state = SGL_XRI_ABORTED;
7383 spin_unlock_irqrestore(&phba->hbalock, iflag);