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 == LPFC_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))
836 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
837 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
838 irsp->ulpStatus, irsp->un.ulpWord[4],
841 /* FLOGI failed, so there is no fabric */
842 spin_lock_irq(shost->host_lock);
843 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
844 spin_unlock_irq(shost->host_lock);
846 /* If private loop, then allow max outstanding els to be
847 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
848 * alpa map would take too long otherwise.
850 if (phba->alpa_map[0] == 0) {
851 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
852 if ((phba->sli_rev == LPFC_SLI_REV4) &&
853 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
854 (vport->fc_prevDID != vport->fc_myDID))) {
855 if (vport->fc_flag & FC_VFI_REGISTERED)
856 lpfc_sli4_unreg_all_rpis(vport);
857 lpfc_issue_reg_vfi(vport);
864 spin_lock_irq(shost->host_lock);
865 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
866 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
867 spin_unlock_irq(shost->host_lock);
870 * The FLogI succeeded. Sync the data for the CPU before
873 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
875 sp = prsp->virt + sizeof(uint32_t);
877 /* FLOGI completes successfully */
878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
879 "0101 FLOGI completes successfully "
880 "Data: x%x x%x x%x x%x\n",
881 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
882 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
884 if (vport->port_state == LPFC_FLOGI) {
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
890 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
891 else if (!(phba->hba_flag & HBA_FCOE_MODE))
892 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
894 lpfc_printf_vlog(vport, KERN_ERR,
896 "2831 FLOGI response with cleared Fabric "
897 "bit fcf_index 0x%x "
898 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
900 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
901 phba->fcf.current_rec.fcf_indx,
902 phba->fcf.current_rec.switch_name[0],
903 phba->fcf.current_rec.switch_name[1],
904 phba->fcf.current_rec.switch_name[2],
905 phba->fcf.current_rec.switch_name[3],
906 phba->fcf.current_rec.switch_name[4],
907 phba->fcf.current_rec.switch_name[5],
908 phba->fcf.current_rec.switch_name[6],
909 phba->fcf.current_rec.switch_name[7],
910 phba->fcf.current_rec.fabric_name[0],
911 phba->fcf.current_rec.fabric_name[1],
912 phba->fcf.current_rec.fabric_name[2],
913 phba->fcf.current_rec.fabric_name[3],
914 phba->fcf.current_rec.fabric_name[4],
915 phba->fcf.current_rec.fabric_name[5],
916 phba->fcf.current_rec.fabric_name[6],
917 phba->fcf.current_rec.fabric_name[7]);
919 spin_lock_irq(&phba->hbalock);
920 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
921 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
922 spin_unlock_irq(&phba->hbalock);
926 /* Mark the FCF discovery process done */
927 if (phba->hba_flag & HBA_FIP_SUPPORT)
928 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
930 "2769 FLOGI to FCF (x%x) "
931 "completed successfully\n",
932 phba->fcf.current_rec.fcf_indx);
933 spin_lock_irq(&phba->hbalock);
934 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
935 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
936 spin_unlock_irq(&phba->hbalock);
944 if (!lpfc_error_lost_link(irsp)) {
945 /* FLOGI failed, so just use loop map to make discovery list */
946 lpfc_disc_list_loopmap(vport);
948 /* Start discovery */
949 lpfc_disc_start(vport);
950 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
951 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
952 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
953 (phba->link_state != LPFC_CLEAR_LA)) {
954 /* If FLOGI failed enable link interrupt. */
955 lpfc_issue_clear_la(phba, vport);
958 lpfc_els_free_iocb(phba, cmdiocb);
962 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
963 * @vport: pointer to a host virtual N_Port data structure.
964 * @ndlp: pointer to a node-list data structure.
965 * @retry: number of retries to the command IOCB.
967 * This routine issues a Fabric Login (FLOGI) Request ELS command
968 * for a @vport. The initiator service parameters are put into the payload
969 * of the FLOGI Request IOCB and the top-level callback function pointer
970 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
971 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
972 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
974 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
975 * will be incremented by 1 for holding the ndlp and the reference to ndlp
976 * will be stored into the context1 field of the IOCB for the completion
977 * callback function to the FLOGI ELS command.
980 * 0 - successfully issued flogi iocb for @vport
981 * 1 - failed to issue flogi iocb for @vport
984 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
987 struct lpfc_hba *phba = vport->phba;
988 struct serv_parm *sp;
990 struct lpfc_iocbq *elsiocb;
991 struct lpfc_sli_ring *pring;
997 pring = &phba->sli.ring[LPFC_ELS_RING];
999 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1000 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1001 ndlp->nlp_DID, ELS_CMD_FLOGI);
1006 icmd = &elsiocb->iocb;
1007 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1009 /* For FLOGI request, remainder of payload is service parameters */
1010 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1011 pcmd += sizeof(uint32_t);
1012 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1013 sp = (struct serv_parm *) pcmd;
1015 /* Setup CSPs accordingly for Fabric */
1016 sp->cmn.e_d_tov = 0;
1017 sp->cmn.w2.r_a_tov = 0;
1018 sp->cls1.classValid = 0;
1019 sp->cls2.seqDelivery = 1;
1020 sp->cls3.seqDelivery = 1;
1021 if (sp->cmn.fcphLow < FC_PH3)
1022 sp->cmn.fcphLow = FC_PH3;
1023 if (sp->cmn.fcphHigh < FC_PH3)
1024 sp->cmn.fcphHigh = FC_PH3;
1026 if (phba->sli_rev == LPFC_SLI_REV4) {
1027 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1028 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1029 /* FLOGI needs to be 3 for WQE FCFI */
1030 /* Set the fcfi to the fcfi we registered with */
1031 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1032 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1033 sp->cmn.request_multiple_Nport = 1;
1034 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1039 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1040 icmd->un.elsreq64.myID = 0;
1041 icmd->un.elsreq64.fl = 1;
1044 tmo = phba->fc_ratov;
1045 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1046 lpfc_set_disctmo(vport);
1047 phba->fc_ratov = tmo;
1049 phba->fc_stat.elsXmitFLOGI++;
1050 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1052 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1053 "Issue FLOGI: opt:x%x",
1054 phba->sli3_options, 0, 0);
1056 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1057 if (rc == IOCB_ERROR) {
1058 lpfc_els_free_iocb(phba, elsiocb);
1065 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1066 * @phba: pointer to lpfc hba data structure.
1068 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1069 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1070 * list and issues an abort IOCB commond on each outstanding IOCB that
1071 * contains a active Fabric_DID ndlp. Note that this function is to issue
1072 * the abort IOCB command on all the outstanding IOCBs, thus when this
1073 * function returns, it does not guarantee all the IOCBs are actually aborted.
1076 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1079 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1081 struct lpfc_sli_ring *pring;
1082 struct lpfc_iocbq *iocb, *next_iocb;
1083 struct lpfc_nodelist *ndlp;
1086 /* Abort outstanding I/O on NPort <nlp_DID> */
1087 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1088 "0201 Abort outstanding I/O on NPort x%x\n",
1091 pring = &phba->sli.ring[LPFC_ELS_RING];
1094 * Check the txcmplq for an iocb that matches the nport the driver is
1097 spin_lock_irq(&phba->hbalock);
1098 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1100 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1101 icmd->un.elsreq64.bdl.ulpIoTag32) {
1102 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1103 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1104 (ndlp->nlp_DID == Fabric_DID))
1105 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1108 spin_unlock_irq(&phba->hbalock);
1114 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1115 * @vport: pointer to a host virtual N_Port data structure.
1117 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1118 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1119 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1120 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1121 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1122 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1126 * 0 - failed to issue initial flogi for @vport
1127 * 1 - successfully issued initial flogi for @vport
1130 lpfc_initial_flogi(struct lpfc_vport *vport)
1132 struct lpfc_hba *phba = vport->phba;
1133 struct lpfc_nodelist *ndlp;
1135 vport->port_state = LPFC_FLOGI;
1136 lpfc_set_disctmo(vport);
1138 /* First look for the Fabric ndlp */
1139 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1141 /* Cannot find existing Fabric ndlp, so allocate a new one */
1142 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1145 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1146 /* Set the node type */
1147 ndlp->nlp_type |= NLP_FABRIC;
1148 /* Put ndlp onto node list */
1149 lpfc_enqueue_node(vport, ndlp);
1150 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1151 /* re-setup ndlp without removing from node list */
1152 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1157 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1158 /* This decrement of reference count to node shall kick off
1159 * the release of the node.
1168 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1169 * @vport: pointer to a host virtual N_Port data structure.
1171 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1172 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1173 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1174 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1175 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1176 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1180 * 0 - failed to issue initial fdisc for @vport
1181 * 1 - successfully issued initial fdisc for @vport
1184 lpfc_initial_fdisc(struct lpfc_vport *vport)
1186 struct lpfc_hba *phba = vport->phba;
1187 struct lpfc_nodelist *ndlp;
1189 /* First look for the Fabric ndlp */
1190 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1192 /* Cannot find existing Fabric ndlp, so allocate a new one */
1193 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1196 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1197 /* Put ndlp onto node list */
1198 lpfc_enqueue_node(vport, ndlp);
1199 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1200 /* re-setup ndlp without removing from node list */
1201 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1206 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1207 /* decrement node reference count to trigger the release of
1217 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1218 * @vport: pointer to a host virtual N_Port data structure.
1220 * This routine checks whether there are more remaining Port Logins
1221 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1222 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1223 * to issue ELS PLOGIs up to the configured discover threads with the
1224 * @vport (@vport->cfg_discovery_threads). The function also decrement
1225 * the @vport's num_disc_node by 1 if it is not already 0.
1228 lpfc_more_plogi(struct lpfc_vport *vport)
1232 if (vport->num_disc_nodes)
1233 vport->num_disc_nodes--;
1235 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1236 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1237 "0232 Continue discovery with %d PLOGIs to go "
1238 "Data: x%x x%x x%x\n",
1239 vport->num_disc_nodes, vport->fc_plogi_cnt,
1240 vport->fc_flag, vport->port_state);
1241 /* Check to see if there are more PLOGIs to be sent */
1242 if (vport->fc_flag & FC_NLP_MORE)
1243 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1244 sentplogi = lpfc_els_disc_plogi(vport);
1250 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1251 * @phba: pointer to lpfc hba data structure.
1252 * @prsp: pointer to response IOCB payload.
1253 * @ndlp: pointer to a node-list data structure.
1255 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1256 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1257 * The following cases are considered N_Port confirmed:
1258 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1259 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1260 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1261 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1262 * 1) if there is a node on vport list other than the @ndlp with the same
1263 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1264 * on that node to release the RPI associated with the node; 2) if there is
1265 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1266 * into, a new node shall be allocated (or activated). In either case, the
1267 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1268 * be released and the new_ndlp shall be put on to the vport node list and
1269 * its pointer returned as the confirmed node.
1271 * Note that before the @ndlp got "released", the keepDID from not-matching
1272 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1273 * of the @ndlp. This is because the release of @ndlp is actually to put it
1274 * into an inactive state on the vport node list and the vport node list
1275 * management algorithm does not allow two node with a same DID.
1278 * pointer to the PLOGI N_Port @ndlp
1280 static struct lpfc_nodelist *
1281 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1282 struct lpfc_nodelist *ndlp)
1284 struct lpfc_vport *vport = ndlp->vport;
1285 struct lpfc_nodelist *new_ndlp;
1286 struct lpfc_rport_data *rdata;
1287 struct fc_rport *rport;
1288 struct serv_parm *sp;
1289 uint8_t name[sizeof(struct lpfc_name)];
1290 uint32_t rc, keepDID = 0;
1294 /* Fabric nodes can have the same WWPN so we don't bother searching
1295 * by WWPN. Just return the ndlp that was given to us.
1297 if (ndlp->nlp_type & NLP_FABRIC)
1300 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1301 memset(name, 0, sizeof(struct lpfc_name));
1303 /* Now we find out if the NPort we are logging into, matches the WWPN
1304 * we have for that ndlp. If not, we have some work to do.
1306 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1308 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1312 rc = memcmp(&ndlp->nlp_portname, name,
1313 sizeof(struct lpfc_name));
1316 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1319 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1320 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1321 rc = memcmp(&ndlp->nlp_portname, name,
1322 sizeof(struct lpfc_name));
1325 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1326 NLP_STE_UNUSED_NODE);
1329 keepDID = new_ndlp->nlp_DID;
1331 keepDID = new_ndlp->nlp_DID;
1333 lpfc_unreg_rpi(vport, new_ndlp);
1334 new_ndlp->nlp_DID = ndlp->nlp_DID;
1335 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1337 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1338 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1339 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1341 /* Set state will put new_ndlp on to node list if not already done */
1342 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1344 /* Move this back to NPR state */
1345 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1346 /* The new_ndlp is replacing ndlp totally, so we need
1347 * to put ndlp on UNUSED list and try to free it.
1350 /* Fix up the rport accordingly */
1351 rport = ndlp->rport;
1353 rdata = rport->dd_data;
1354 if (rdata->pnode == ndlp) {
1357 rdata->pnode = lpfc_nlp_get(new_ndlp);
1358 new_ndlp->rport = rport;
1360 new_ndlp->nlp_type = ndlp->nlp_type;
1362 /* We shall actually free the ndlp with both nlp_DID and
1363 * nlp_portname fields equals 0 to avoid any ndlp on the
1364 * nodelist never to be used.
1366 if (ndlp->nlp_DID == 0) {
1367 spin_lock_irq(&phba->ndlp_lock);
1368 NLP_SET_FREE_REQ(ndlp);
1369 spin_unlock_irq(&phba->ndlp_lock);
1372 /* Two ndlps cannot have the same did on the nodelist */
1373 ndlp->nlp_DID = keepDID;
1374 lpfc_drop_node(vport, ndlp);
1377 lpfc_unreg_rpi(vport, ndlp);
1378 /* Two ndlps cannot have the same did */
1379 ndlp->nlp_DID = keepDID;
1380 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1381 /* Since we are swapping the ndlp passed in with the new one
1382 * and the did has already been swapped, copy over the
1385 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1386 sizeof(struct lpfc_name));
1387 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1388 sizeof(struct lpfc_name));
1389 new_ndlp->nlp_state = ndlp->nlp_state;
1390 /* Fix up the rport accordingly */
1391 rport = ndlp->rport;
1393 rdata = rport->dd_data;
1394 put_node = rdata->pnode != NULL;
1395 put_rport = ndlp->rport != NULL;
1396 rdata->pnode = NULL;
1401 put_device(&rport->dev);
1408 * lpfc_end_rscn - Check and handle more rscn for a vport
1409 * @vport: pointer to a host virtual N_Port data structure.
1411 * This routine checks whether more Registration State Change
1412 * Notifications (RSCNs) came in while the discovery state machine was in
1413 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1414 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1415 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1416 * handling the RSCNs.
1419 lpfc_end_rscn(struct lpfc_vport *vport)
1421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1423 if (vport->fc_flag & FC_RSCN_MODE) {
1425 * Check to see if more RSCNs came in while we were
1426 * processing this one.
1428 if (vport->fc_rscn_id_cnt ||
1429 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1430 lpfc_els_handle_rscn(vport);
1432 spin_lock_irq(shost->host_lock);
1433 vport->fc_flag &= ~FC_RSCN_MODE;
1434 spin_unlock_irq(shost->host_lock);
1440 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1441 * @phba: pointer to lpfc hba data structure.
1442 * @cmdiocb: pointer to lpfc command iocb data structure.
1443 * @rspiocb: pointer to lpfc response iocb data structure.
1445 * This routine is the completion callback function for issuing the Port
1446 * Login (PLOGI) command. For PLOGI completion, there must be an active
1447 * ndlp on the vport node list that matches the remote node ID from the
1448 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1449 * ignored and command IOCB released. The PLOGI response IOCB status is
1450 * checked for error conditons. If there is error status reported, PLOGI
1451 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1452 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1453 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1454 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1455 * there are additional N_Port nodes with the vport that need to perform
1456 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1460 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1461 struct lpfc_iocbq *rspiocb)
1463 struct lpfc_vport *vport = cmdiocb->vport;
1464 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1466 struct lpfc_nodelist *ndlp;
1467 struct lpfc_dmabuf *prsp;
1468 int disc, rc, did, type;
1470 /* we pass cmdiocb to state machine which needs rspiocb as well */
1471 cmdiocb->context_un.rsp_iocb = rspiocb;
1473 irsp = &rspiocb->iocb;
1474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1475 "PLOGI cmpl: status:x%x/x%x did:x%x",
1476 irsp->ulpStatus, irsp->un.ulpWord[4],
1477 irsp->un.elsreq64.remoteID);
1479 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1480 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1481 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1482 "0136 PLOGI completes to NPort x%x "
1483 "with no ndlp. Data: x%x x%x x%x\n",
1484 irsp->un.elsreq64.remoteID,
1485 irsp->ulpStatus, irsp->un.ulpWord[4],
1490 /* Since ndlp can be freed in the disc state machine, note if this node
1491 * is being used during discovery.
1493 spin_lock_irq(shost->host_lock);
1494 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1495 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1496 spin_unlock_irq(shost->host_lock);
1499 /* PLOGI completes to NPort <nlp_DID> */
1500 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1501 "0102 PLOGI completes to NPort x%x "
1502 "Data: x%x x%x x%x x%x x%x\n",
1503 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1504 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1505 /* Check to see if link went down during discovery */
1506 if (lpfc_els_chk_latt(vport)) {
1507 spin_lock_irq(shost->host_lock);
1508 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1509 spin_unlock_irq(shost->host_lock);
1513 /* ndlp could be freed in DSM, save these values now */
1514 type = ndlp->nlp_type;
1515 did = ndlp->nlp_DID;
1517 if (irsp->ulpStatus) {
1518 /* Check for retry */
1519 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1520 /* ELS command is being retried */
1522 spin_lock_irq(shost->host_lock);
1523 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1524 spin_unlock_irq(shost->host_lock);
1528 /* PLOGI failed Don't print the vport to vport rjts */
1529 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1530 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1531 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1532 (phba)->pport->cfg_log_verbose & LOG_ELS)
1533 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1534 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1535 ndlp->nlp_DID, irsp->ulpStatus,
1536 irsp->un.ulpWord[4]);
1537 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1538 if (lpfc_error_lost_link(irsp))
1539 rc = NLP_STE_FREED_NODE;
1541 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1542 NLP_EVT_CMPL_PLOGI);
1544 /* Good status, call state machine */
1545 prsp = list_entry(((struct lpfc_dmabuf *)
1546 cmdiocb->context2)->list.next,
1547 struct lpfc_dmabuf, list);
1548 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1549 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1550 NLP_EVT_CMPL_PLOGI);
1553 if (disc && vport->num_disc_nodes) {
1554 /* Check to see if there are more PLOGIs to be sent */
1555 lpfc_more_plogi(vport);
1557 if (vport->num_disc_nodes == 0) {
1558 spin_lock_irq(shost->host_lock);
1559 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1560 spin_unlock_irq(shost->host_lock);
1562 lpfc_can_disctmo(vport);
1563 lpfc_end_rscn(vport);
1568 lpfc_els_free_iocb(phba, cmdiocb);
1573 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1574 * @vport: pointer to a host virtual N_Port data structure.
1575 * @did: destination port identifier.
1576 * @retry: number of retries to the command IOCB.
1578 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1579 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1580 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1581 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1582 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1584 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1585 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1586 * will be stored into the context1 field of the IOCB for the completion
1587 * callback function to the PLOGI ELS command.
1590 * 0 - Successfully issued a plogi for @vport
1591 * 1 - failed to issue a plogi for @vport
1594 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1596 struct lpfc_hba *phba = vport->phba;
1597 struct serv_parm *sp;
1599 struct lpfc_nodelist *ndlp;
1600 struct lpfc_iocbq *elsiocb;
1601 struct lpfc_sli *psli;
1608 ndlp = lpfc_findnode_did(vport, did);
1609 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1612 /* If ndlp is not NULL, we will bump the reference count on it */
1613 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1614 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1619 icmd = &elsiocb->iocb;
1620 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1622 /* For PLOGI request, remainder of payload is service parameters */
1623 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1624 pcmd += sizeof(uint32_t);
1625 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1626 sp = (struct serv_parm *) pcmd;
1629 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1630 * to device on remote loops work.
1632 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1633 sp->cmn.altBbCredit = 1;
1635 if (sp->cmn.fcphLow < FC_PH_4_3)
1636 sp->cmn.fcphLow = FC_PH_4_3;
1638 if (sp->cmn.fcphHigh < FC_PH3)
1639 sp->cmn.fcphHigh = FC_PH3;
1641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1642 "Issue PLOGI: did:x%x",
1645 phba->fc_stat.elsXmitPLOGI++;
1646 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1647 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1649 if (ret == IOCB_ERROR) {
1650 lpfc_els_free_iocb(phba, elsiocb);
1657 * lpfc_cmpl_els_prli - Completion callback function for prli
1658 * @phba: pointer to lpfc hba data structure.
1659 * @cmdiocb: pointer to lpfc command iocb data structure.
1660 * @rspiocb: pointer to lpfc response iocb data structure.
1662 * This routine is the completion callback function for a Process Login
1663 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1664 * status. If there is error status reported, PRLI retry shall be attempted
1665 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1666 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1667 * ndlp to mark the PRLI completion.
1670 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1671 struct lpfc_iocbq *rspiocb)
1673 struct lpfc_vport *vport = cmdiocb->vport;
1674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1676 struct lpfc_sli *psli;
1677 struct lpfc_nodelist *ndlp;
1680 /* we pass cmdiocb to state machine which needs rspiocb as well */
1681 cmdiocb->context_un.rsp_iocb = rspiocb;
1683 irsp = &(rspiocb->iocb);
1684 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1685 spin_lock_irq(shost->host_lock);
1686 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1687 spin_unlock_irq(shost->host_lock);
1689 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1690 "PRLI cmpl: status:x%x/x%x did:x%x",
1691 irsp->ulpStatus, irsp->un.ulpWord[4],
1693 /* PRLI completes to NPort <nlp_DID> */
1694 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1695 "0103 PRLI completes to NPort x%x "
1696 "Data: x%x x%x x%x x%x\n",
1697 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1698 irsp->ulpTimeout, vport->num_disc_nodes);
1700 vport->fc_prli_sent--;
1701 /* Check to see if link went down during discovery */
1702 if (lpfc_els_chk_latt(vport))
1705 if (irsp->ulpStatus) {
1706 /* Check for retry */
1707 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1708 /* ELS command is being retried */
1712 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1713 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1714 ndlp->nlp_DID, irsp->ulpStatus,
1715 irsp->un.ulpWord[4]);
1716 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1717 if (lpfc_error_lost_link(irsp))
1720 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1723 /* Good status, call state machine */
1724 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1727 lpfc_els_free_iocb(phba, cmdiocb);
1732 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1733 * @vport: pointer to a host virtual N_Port data structure.
1734 * @ndlp: pointer to a node-list data structure.
1735 * @retry: number of retries to the command IOCB.
1737 * This routine issues a Process Login (PRLI) ELS command for the
1738 * @vport. The PRLI service parameters are set up in the payload of the
1739 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1740 * is put to the IOCB completion callback func field before invoking the
1741 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1743 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1744 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1745 * will be stored into the context1 field of the IOCB for the completion
1746 * callback function to the PRLI ELS command.
1749 * 0 - successfully issued prli iocb command for @vport
1750 * 1 - failed to issue prli iocb command for @vport
1753 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1757 struct lpfc_hba *phba = vport->phba;
1760 struct lpfc_iocbq *elsiocb;
1764 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1765 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1766 ndlp->nlp_DID, ELS_CMD_PRLI);
1770 icmd = &elsiocb->iocb;
1771 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1773 /* For PRLI request, remainder of payload is service parameters */
1774 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1775 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1776 pcmd += sizeof(uint32_t);
1778 /* For PRLI, remainder of payload is PRLI parameter page */
1779 npr = (PRLI *) pcmd;
1781 * If our firmware version is 3.20 or later,
1782 * set the following bits for FC-TAPE support.
1784 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1785 npr->ConfmComplAllowed = 1;
1787 npr->TaskRetryIdReq = 1;
1789 npr->estabImagePair = 1;
1790 npr->readXferRdyDis = 1;
1792 /* For FCP support */
1793 npr->prliType = PRLI_FCP_TYPE;
1794 npr->initiatorFunc = 1;
1796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1797 "Issue PRLI: did:x%x",
1798 ndlp->nlp_DID, 0, 0);
1800 phba->fc_stat.elsXmitPRLI++;
1801 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1802 spin_lock_irq(shost->host_lock);
1803 ndlp->nlp_flag |= NLP_PRLI_SND;
1804 spin_unlock_irq(shost->host_lock);
1805 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1807 spin_lock_irq(shost->host_lock);
1808 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1809 spin_unlock_irq(shost->host_lock);
1810 lpfc_els_free_iocb(phba, elsiocb);
1813 vport->fc_prli_sent++;
1818 * lpfc_rscn_disc - Perform rscn discovery for a vport
1819 * @vport: pointer to a host virtual N_Port data structure.
1821 * This routine performs Registration State Change Notification (RSCN)
1822 * discovery for a @vport. If the @vport's node port recovery count is not
1823 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1824 * the nodes that need recovery. If none of the PLOGI were needed through
1825 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1826 * invoked to check and handle possible more RSCN came in during the period
1827 * of processing the current ones.
1830 lpfc_rscn_disc(struct lpfc_vport *vport)
1832 lpfc_can_disctmo(vport);
1834 /* RSCN discovery */
1835 /* go thru NPR nodes and issue ELS PLOGIs */
1836 if (vport->fc_npr_cnt)
1837 if (lpfc_els_disc_plogi(vport))
1840 lpfc_end_rscn(vport);
1844 * lpfc_adisc_done - Complete the adisc phase of discovery
1845 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1847 * This function is called when the final ADISC is completed during discovery.
1848 * This function handles clearing link attention or issuing reg_vpi depending
1849 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1851 * This function is called with no locks held.
1854 lpfc_adisc_done(struct lpfc_vport *vport)
1856 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1857 struct lpfc_hba *phba = vport->phba;
1860 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1861 * and continue discovery.
1863 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1864 !(vport->fc_flag & FC_RSCN_MODE) &&
1865 (phba->sli_rev < LPFC_SLI_REV4)) {
1866 lpfc_issue_reg_vpi(phba, vport);
1870 * For SLI2, we need to set port_state to READY
1871 * and continue discovery.
1873 if (vport->port_state < LPFC_VPORT_READY) {
1874 /* If we get here, there is nothing to ADISC */
1875 if (vport->port_type == LPFC_PHYSICAL_PORT)
1876 lpfc_issue_clear_la(phba, vport);
1877 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1878 vport->num_disc_nodes = 0;
1879 /* go thru NPR list, issue ELS PLOGIs */
1880 if (vport->fc_npr_cnt)
1881 lpfc_els_disc_plogi(vport);
1882 if (!vport->num_disc_nodes) {
1883 spin_lock_irq(shost->host_lock);
1884 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1885 spin_unlock_irq(shost->host_lock);
1886 lpfc_can_disctmo(vport);
1887 lpfc_end_rscn(vport);
1890 vport->port_state = LPFC_VPORT_READY;
1892 lpfc_rscn_disc(vport);
1896 * lpfc_more_adisc - Issue more adisc as needed
1897 * @vport: pointer to a host virtual N_Port data structure.
1899 * This routine determines whether there are more ndlps on a @vport
1900 * node list need to have Address Discover (ADISC) issued. If so, it will
1901 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1902 * remaining nodes which need to have ADISC sent.
1905 lpfc_more_adisc(struct lpfc_vport *vport)
1909 if (vport->num_disc_nodes)
1910 vport->num_disc_nodes--;
1911 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1912 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1913 "0210 Continue discovery with %d ADISCs to go "
1914 "Data: x%x x%x x%x\n",
1915 vport->num_disc_nodes, vport->fc_adisc_cnt,
1916 vport->fc_flag, vport->port_state);
1917 /* Check to see if there are more ADISCs to be sent */
1918 if (vport->fc_flag & FC_NLP_MORE) {
1919 lpfc_set_disctmo(vport);
1920 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1921 sentadisc = lpfc_els_disc_adisc(vport);
1923 if (!vport->num_disc_nodes)
1924 lpfc_adisc_done(vport);
1929 * lpfc_cmpl_els_adisc - Completion callback function for adisc
1930 * @phba: pointer to lpfc hba data structure.
1931 * @cmdiocb: pointer to lpfc command iocb data structure.
1932 * @rspiocb: pointer to lpfc response iocb data structure.
1934 * This routine is the completion function for issuing the Address Discover
1935 * (ADISC) command. It first checks to see whether link went down during
1936 * the discovery process. If so, the node will be marked as node port
1937 * recovery for issuing discover IOCB by the link attention handler and
1938 * exit. Otherwise, the response status is checked. If error was reported
1939 * in the response status, the ADISC command shall be retried by invoking
1940 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1941 * the response status, the state machine is invoked to set transition
1942 * with respect to NLP_EVT_CMPL_ADISC event.
1945 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1946 struct lpfc_iocbq *rspiocb)
1948 struct lpfc_vport *vport = cmdiocb->vport;
1949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1951 struct lpfc_nodelist *ndlp;
1954 /* we pass cmdiocb to state machine which needs rspiocb as well */
1955 cmdiocb->context_un.rsp_iocb = rspiocb;
1957 irsp = &(rspiocb->iocb);
1958 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1961 "ADISC cmpl: status:x%x/x%x did:x%x",
1962 irsp->ulpStatus, irsp->un.ulpWord[4],
1965 /* Since ndlp can be freed in the disc state machine, note if this node
1966 * is being used during discovery.
1968 spin_lock_irq(shost->host_lock);
1969 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1970 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1971 spin_unlock_irq(shost->host_lock);
1972 /* ADISC completes to NPort <nlp_DID> */
1973 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1974 "0104 ADISC completes to NPort x%x "
1975 "Data: x%x x%x x%x x%x x%x\n",
1976 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1977 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1978 /* Check to see if link went down during discovery */
1979 if (lpfc_els_chk_latt(vport)) {
1980 spin_lock_irq(shost->host_lock);
1981 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1982 spin_unlock_irq(shost->host_lock);
1986 if (irsp->ulpStatus) {
1987 /* Check for retry */
1988 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1989 /* ELS command is being retried */
1991 spin_lock_irq(shost->host_lock);
1992 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1993 spin_unlock_irq(shost->host_lock);
1994 lpfc_set_disctmo(vport);
1999 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2000 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2001 ndlp->nlp_DID, irsp->ulpStatus,
2002 irsp->un.ulpWord[4]);
2003 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2004 if (!lpfc_error_lost_link(irsp))
2005 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2006 NLP_EVT_CMPL_ADISC);
2008 /* Good status, call state machine */
2009 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2010 NLP_EVT_CMPL_ADISC);
2012 /* Check to see if there are more ADISCs to be sent */
2013 if (disc && vport->num_disc_nodes)
2014 lpfc_more_adisc(vport);
2016 lpfc_els_free_iocb(phba, cmdiocb);
2021 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2022 * @vport: pointer to a virtual N_Port data structure.
2023 * @ndlp: pointer to a node-list data structure.
2024 * @retry: number of retries to the command IOCB.
2026 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2027 * @vport. It prepares the payload of the ADISC ELS command, updates the
2028 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2029 * to issue the ADISC ELS command.
2031 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2032 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2033 * will be stored into the context1 field of the IOCB for the completion
2034 * callback function to the ADISC ELS command.
2037 * 0 - successfully issued adisc
2038 * 1 - failed to issue adisc
2041 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2045 struct lpfc_hba *phba = vport->phba;
2048 struct lpfc_iocbq *elsiocb;
2052 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2053 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2054 ndlp->nlp_DID, ELS_CMD_ADISC);
2058 icmd = &elsiocb->iocb;
2059 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2061 /* For ADISC request, remainder of payload is service parameters */
2062 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2063 pcmd += sizeof(uint32_t);
2065 /* Fill in ADISC payload */
2066 ap = (ADISC *) pcmd;
2067 ap->hardAL_PA = phba->fc_pref_ALPA;
2068 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2069 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2070 ap->DID = be32_to_cpu(vport->fc_myDID);
2072 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2073 "Issue ADISC: did:x%x",
2074 ndlp->nlp_DID, 0, 0);
2076 phba->fc_stat.elsXmitADISC++;
2077 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2078 spin_lock_irq(shost->host_lock);
2079 ndlp->nlp_flag |= NLP_ADISC_SND;
2080 spin_unlock_irq(shost->host_lock);
2081 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2083 spin_lock_irq(shost->host_lock);
2084 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2085 spin_unlock_irq(shost->host_lock);
2086 lpfc_els_free_iocb(phba, elsiocb);
2093 * lpfc_cmpl_els_logo - Completion callback function for logo
2094 * @phba: pointer to lpfc hba data structure.
2095 * @cmdiocb: pointer to lpfc command iocb data structure.
2096 * @rspiocb: pointer to lpfc response iocb data structure.
2098 * This routine is the completion function for issuing the ELS Logout (LOGO)
2099 * command. If no error status was reported from the LOGO response, the
2100 * state machine of the associated ndlp shall be invoked for transition with
2101 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2102 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2105 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2106 struct lpfc_iocbq *rspiocb)
2108 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2109 struct lpfc_vport *vport = ndlp->vport;
2110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2112 struct lpfc_sli *psli;
2115 /* we pass cmdiocb to state machine which needs rspiocb as well */
2116 cmdiocb->context_un.rsp_iocb = rspiocb;
2118 irsp = &(rspiocb->iocb);
2119 spin_lock_irq(shost->host_lock);
2120 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2121 spin_unlock_irq(shost->host_lock);
2123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2124 "LOGO cmpl: status:x%x/x%x did:x%x",
2125 irsp->ulpStatus, irsp->un.ulpWord[4],
2127 /* LOGO completes to NPort <nlp_DID> */
2128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2129 "0105 LOGO completes to NPort x%x "
2130 "Data: x%x x%x x%x x%x\n",
2131 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2132 irsp->ulpTimeout, vport->num_disc_nodes);
2133 /* Check to see if link went down during discovery */
2134 if (lpfc_els_chk_latt(vport))
2137 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2138 /* NLP_EVT_DEVICE_RM should unregister the RPI
2139 * which should abort all outstanding IOs.
2141 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2146 if (irsp->ulpStatus) {
2147 /* Check for retry */
2148 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
2149 /* ELS command is being retried */
2152 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2153 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2154 ndlp->nlp_DID, irsp->ulpStatus,
2155 irsp->un.ulpWord[4]);
2156 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2157 if (lpfc_error_lost_link(irsp))
2160 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2163 /* Good status, call state machine.
2164 * This will unregister the rpi if needed.
2166 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2169 lpfc_els_free_iocb(phba, cmdiocb);
2174 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2175 * @vport: pointer to a virtual N_Port data structure.
2176 * @ndlp: pointer to a node-list data structure.
2177 * @retry: number of retries to the command IOCB.
2179 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2180 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2181 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2182 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2184 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2185 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2186 * will be stored into the context1 field of the IOCB for the completion
2187 * callback function to the LOGO ELS command.
2190 * 0 - successfully issued logo
2191 * 1 - failed to issue logo
2194 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2198 struct lpfc_hba *phba = vport->phba;
2200 struct lpfc_iocbq *elsiocb;
2205 spin_lock_irq(shost->host_lock);
2206 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2207 spin_unlock_irq(shost->host_lock);
2210 spin_unlock_irq(shost->host_lock);
2212 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2213 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2214 ndlp->nlp_DID, ELS_CMD_LOGO);
2218 icmd = &elsiocb->iocb;
2219 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2220 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2221 pcmd += sizeof(uint32_t);
2223 /* Fill in LOGO payload */
2224 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2225 pcmd += sizeof(uint32_t);
2226 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2229 "Issue LOGO: did:x%x",
2230 ndlp->nlp_DID, 0, 0);
2232 phba->fc_stat.elsXmitLOGO++;
2233 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2234 spin_lock_irq(shost->host_lock);
2235 ndlp->nlp_flag |= NLP_LOGO_SND;
2236 spin_unlock_irq(shost->host_lock);
2237 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2239 if (rc == IOCB_ERROR) {
2240 spin_lock_irq(shost->host_lock);
2241 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2242 spin_unlock_irq(shost->host_lock);
2243 lpfc_els_free_iocb(phba, elsiocb);
2250 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2251 * @phba: pointer to lpfc hba data structure.
2252 * @cmdiocb: pointer to lpfc command iocb data structure.
2253 * @rspiocb: pointer to lpfc response iocb data structure.
2255 * This routine is a generic completion callback function for ELS commands.
2256 * Specifically, it is the callback function which does not need to perform
2257 * any command specific operations. It is currently used by the ELS command
2258 * issuing routines for the ELS State Change Request (SCR),
2259 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2260 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2261 * certain debug loggings, this callback function simply invokes the
2262 * lpfc_els_chk_latt() routine to check whether link went down during the
2263 * discovery process.
2266 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2267 struct lpfc_iocbq *rspiocb)
2269 struct lpfc_vport *vport = cmdiocb->vport;
2272 irsp = &rspiocb->iocb;
2274 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2275 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2276 irsp->ulpStatus, irsp->un.ulpWord[4],
2277 irsp->un.elsreq64.remoteID);
2278 /* ELS cmd tag <ulpIoTag> completes */
2279 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2280 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2281 irsp->ulpIoTag, irsp->ulpStatus,
2282 irsp->un.ulpWord[4], irsp->ulpTimeout);
2283 /* Check to see if link went down during discovery */
2284 lpfc_els_chk_latt(vport);
2285 lpfc_els_free_iocb(phba, cmdiocb);
2290 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2291 * @vport: pointer to a host virtual N_Port data structure.
2292 * @nportid: N_Port identifier to the remote node.
2293 * @retry: number of retries to the command IOCB.
2295 * This routine issues a State Change Request (SCR) to a fabric node
2296 * on a @vport. The remote node @nportid is passed into the function. It
2297 * first search the @vport node list to find the matching ndlp. If no such
2298 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2299 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2300 * routine is invoked to send the SCR IOCB.
2302 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2303 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2304 * will be stored into the context1 field of the IOCB for the completion
2305 * callback function to the SCR ELS command.
2308 * 0 - Successfully issued scr command
2309 * 1 - Failed to issue scr command
2312 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2314 struct lpfc_hba *phba = vport->phba;
2316 struct lpfc_iocbq *elsiocb;
2317 struct lpfc_sli *psli;
2320 struct lpfc_nodelist *ndlp;
2323 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2325 ndlp = lpfc_findnode_did(vport, nportid);
2327 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2330 lpfc_nlp_init(vport, ndlp, nportid);
2331 lpfc_enqueue_node(vport, ndlp);
2332 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2333 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2338 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2339 ndlp->nlp_DID, ELS_CMD_SCR);
2342 /* This will trigger the release of the node just
2349 icmd = &elsiocb->iocb;
2350 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2352 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2353 pcmd += sizeof(uint32_t);
2355 /* For SCR, remainder of payload is SCR parameter page */
2356 memset(pcmd, 0, sizeof(SCR));
2357 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2359 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2360 "Issue SCR: did:x%x",
2361 ndlp->nlp_DID, 0, 0);
2363 phba->fc_stat.elsXmitSCR++;
2364 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2365 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2367 /* The additional lpfc_nlp_put will cause the following
2368 * lpfc_els_free_iocb routine to trigger the rlease of
2372 lpfc_els_free_iocb(phba, elsiocb);
2375 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2376 * trigger the release of node.
2383 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2384 * @vport: pointer to a host virtual N_Port data structure.
2385 * @nportid: N_Port identifier to the remote node.
2386 * @retry: number of retries to the command IOCB.
2388 * This routine issues a Fibre Channel Address Resolution Response
2389 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2390 * is passed into the function. It first search the @vport node list to find
2391 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2392 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2393 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2395 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2396 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2397 * will be stored into the context1 field of the IOCB for the completion
2398 * callback function to the PARPR ELS command.
2401 * 0 - Successfully issued farpr command
2402 * 1 - Failed to issue farpr command
2405 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2407 struct lpfc_hba *phba = vport->phba;
2409 struct lpfc_iocbq *elsiocb;
2410 struct lpfc_sli *psli;
2415 struct lpfc_nodelist *ondlp;
2416 struct lpfc_nodelist *ndlp;
2419 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2421 ndlp = lpfc_findnode_did(vport, nportid);
2423 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2426 lpfc_nlp_init(vport, ndlp, nportid);
2427 lpfc_enqueue_node(vport, ndlp);
2428 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2429 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2434 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2435 ndlp->nlp_DID, ELS_CMD_RNID);
2437 /* This will trigger the release of the node just
2444 icmd = &elsiocb->iocb;
2445 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2447 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2448 pcmd += sizeof(uint32_t);
2450 /* Fill in FARPR payload */
2451 fp = (FARP *) (pcmd);
2452 memset(fp, 0, sizeof(FARP));
2453 lp = (uint32_t *) pcmd;
2454 *lp++ = be32_to_cpu(nportid);
2455 *lp++ = be32_to_cpu(vport->fc_myDID);
2457 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2459 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2460 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2461 ondlp = lpfc_findnode_did(vport, nportid);
2462 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2463 memcpy(&fp->OportName, &ondlp->nlp_portname,
2464 sizeof(struct lpfc_name));
2465 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2466 sizeof(struct lpfc_name));
2469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2470 "Issue FARPR: did:x%x",
2471 ndlp->nlp_DID, 0, 0);
2473 phba->fc_stat.elsXmitFARPR++;
2474 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2475 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2477 /* The additional lpfc_nlp_put will cause the following
2478 * lpfc_els_free_iocb routine to trigger the release of
2482 lpfc_els_free_iocb(phba, elsiocb);
2485 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2486 * trigger the release of the node.
2493 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2494 * @vport: pointer to a host virtual N_Port data structure.
2495 * @nlp: pointer to a node-list data structure.
2497 * This routine cancels the timer with a delayed IOCB-command retry for
2498 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2499 * removes the ELS retry event if it presents. In addition, if the
2500 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2501 * commands are sent for the @vport's nodes that require issuing discovery
2505 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2508 struct lpfc_work_evt *evtp;
2510 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2512 spin_lock_irq(shost->host_lock);
2513 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2514 spin_unlock_irq(shost->host_lock);
2515 del_timer_sync(&nlp->nlp_delayfunc);
2516 nlp->nlp_last_elscmd = 0;
2517 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2518 list_del_init(&nlp->els_retry_evt.evt_listp);
2519 /* Decrement nlp reference count held for the delayed retry */
2520 evtp = &nlp->els_retry_evt;
2521 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2523 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2524 spin_lock_irq(shost->host_lock);
2525 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2526 spin_unlock_irq(shost->host_lock);
2527 if (vport->num_disc_nodes) {
2528 if (vport->port_state < LPFC_VPORT_READY) {
2529 /* Check if there are more ADISCs to be sent */
2530 lpfc_more_adisc(vport);
2532 /* Check if there are more PLOGIs to be sent */
2533 lpfc_more_plogi(vport);
2534 if (vport->num_disc_nodes == 0) {
2535 spin_lock_irq(shost->host_lock);
2536 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2537 spin_unlock_irq(shost->host_lock);
2538 lpfc_can_disctmo(vport);
2539 lpfc_end_rscn(vport);
2548 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2549 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2551 * This routine is invoked by the ndlp delayed-function timer to check
2552 * whether there is any pending ELS retry event(s) with the node. If not, it
2553 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2554 * adds the delayed events to the HBA work list and invokes the
2555 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2556 * event. Note that lpfc_nlp_get() is called before posting the event to
2557 * the work list to hold reference count of ndlp so that it guarantees the
2558 * reference to ndlp will still be available when the worker thread gets
2559 * to the event associated with the ndlp.
2562 lpfc_els_retry_delay(unsigned long ptr)
2564 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2565 struct lpfc_vport *vport = ndlp->vport;
2566 struct lpfc_hba *phba = vport->phba;
2567 unsigned long flags;
2568 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2570 spin_lock_irqsave(&phba->hbalock, flags);
2571 if (!list_empty(&evtp->evt_listp)) {
2572 spin_unlock_irqrestore(&phba->hbalock, flags);
2576 /* We need to hold the node by incrementing the reference
2577 * count until the queued work is done
2579 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2580 if (evtp->evt_arg1) {
2581 evtp->evt = LPFC_EVT_ELS_RETRY;
2582 list_add_tail(&evtp->evt_listp, &phba->work_list);
2583 lpfc_worker_wake_up(phba);
2585 spin_unlock_irqrestore(&phba->hbalock, flags);
2590 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2591 * @ndlp: pointer to a node-list data structure.
2593 * This routine is the worker-thread handler for processing the @ndlp delayed
2594 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2595 * the last ELS command from the associated ndlp and invokes the proper ELS
2596 * function according to the delayed ELS command to retry the command.
2599 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2601 struct lpfc_vport *vport = ndlp->vport;
2602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2603 uint32_t cmd, did, retry;
2605 spin_lock_irq(shost->host_lock);
2606 did = ndlp->nlp_DID;
2607 cmd = ndlp->nlp_last_elscmd;
2608 ndlp->nlp_last_elscmd = 0;
2610 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2611 spin_unlock_irq(shost->host_lock);
2615 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2616 spin_unlock_irq(shost->host_lock);
2618 * If a discovery event readded nlp_delayfunc after timer
2619 * firing and before processing the timer, cancel the
2622 del_timer_sync(&ndlp->nlp_delayfunc);
2623 retry = ndlp->nlp_retry;
2624 ndlp->nlp_retry = 0;
2628 lpfc_issue_els_flogi(vport, ndlp, retry);
2631 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2632 ndlp->nlp_prev_state = ndlp->nlp_state;
2633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2637 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2638 ndlp->nlp_prev_state = ndlp->nlp_state;
2639 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2643 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2644 ndlp->nlp_prev_state = ndlp->nlp_state;
2645 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2649 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2650 ndlp->nlp_prev_state = ndlp->nlp_state;
2651 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2655 lpfc_issue_els_fdisc(vport, ndlp, retry);
2662 * lpfc_els_retry - Make retry decision on an els command iocb
2663 * @phba: pointer to lpfc hba data structure.
2664 * @cmdiocb: pointer to lpfc command iocb data structure.
2665 * @rspiocb: pointer to lpfc response iocb data structure.
2667 * This routine makes a retry decision on an ELS command IOCB, which has
2668 * failed. The following ELS IOCBs use this function for retrying the command
2669 * when previously issued command responsed with error status: FLOGI, PLOGI,
2670 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2671 * returned error status, it makes the decision whether a retry shall be
2672 * issued for the command, and whether a retry shall be made immediately or
2673 * delayed. In the former case, the corresponding ELS command issuing-function
2674 * is called to retry the command. In the later case, the ELS command shall
2675 * be posted to the ndlp delayed event and delayed function timer set to the
2676 * ndlp for the delayed command issusing.
2679 * 0 - No retry of els command is made
2680 * 1 - Immediate or delayed retry of els command is made
2683 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2684 struct lpfc_iocbq *rspiocb)
2686 struct lpfc_vport *vport = cmdiocb->vport;
2687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2688 IOCB_t *irsp = &rspiocb->iocb;
2689 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2690 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2693 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2699 /* Note: context2 may be 0 for internal driver abort
2700 * of delays ELS command.
2703 if (pcmd && pcmd->virt) {
2704 elscmd = (uint32_t *) (pcmd->virt);
2708 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2709 did = ndlp->nlp_DID;
2711 /* We should only hit this case for retrying PLOGI */
2712 did = irsp->un.elsreq64.remoteID;
2713 ndlp = lpfc_findnode_did(vport, did);
2714 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2715 && (cmd != ELS_CMD_PLOGI))
2719 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2720 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2721 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2723 switch (irsp->ulpStatus) {
2724 case IOSTAT_FCP_RSP_ERROR:
2725 case IOSTAT_REMOTE_STOP:
2728 case IOSTAT_LOCAL_REJECT:
2729 switch ((irsp->un.ulpWord[4] & 0xff)) {
2730 case IOERR_LOOP_OPEN_FAILURE:
2731 if (cmd == ELS_CMD_FLOGI) {
2732 if (PCI_DEVICE_ID_HORNET ==
2733 phba->pcidev->device) {
2734 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
2735 phba->pport->fc_myDID = 0;
2736 phba->alpa_map[0] = 0;
2737 phba->alpa_map[1] = 0;
2740 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2745 case IOERR_ILLEGAL_COMMAND:
2746 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2747 "0124 Retry illegal cmd x%x "
2748 "retry:x%x delay:x%x\n",
2749 cmd, cmdiocb->retry, delay);
2751 /* All command's retry policy */
2753 if (cmdiocb->retry > 2)
2757 case IOERR_NO_RESOURCES:
2758 logerr = 1; /* HBA out of resources */
2760 if (cmdiocb->retry > 100)
2765 case IOERR_ILLEGAL_FRAME:
2770 case IOERR_SEQUENCE_TIMEOUT:
2771 case IOERR_INVALID_RPI:
2777 case IOSTAT_NPORT_RJT:
2778 case IOSTAT_FABRIC_RJT:
2779 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2785 case IOSTAT_NPORT_BSY:
2786 case IOSTAT_FABRIC_BSY:
2787 logerr = 1; /* Fabric / Remote NPort out of resources */
2792 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2793 /* Added for Vendor specifc support
2794 * Just keep retrying for these Rsn / Exp codes
2796 switch (stat.un.b.lsRjtRsnCode) {
2797 case LSRJT_UNABLE_TPC:
2798 if (stat.un.b.lsRjtRsnCodeExp ==
2799 LSEXP_CMD_IN_PROGRESS) {
2800 if (cmd == ELS_CMD_PLOGI) {
2807 if (stat.un.b.lsRjtRsnCodeExp ==
2808 LSEXP_CANT_GIVE_DATA) {
2809 if (cmd == ELS_CMD_PLOGI) {
2816 if (cmd == ELS_CMD_PLOGI) {
2818 maxretry = lpfc_max_els_tries + 1;
2822 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2823 (cmd == ELS_CMD_FDISC) &&
2824 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2825 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2826 "0125 FDISC Failed (x%x). "
2827 "Fabric out of resources\n",
2828 stat.un.lsRjtError);
2829 lpfc_vport_set_state(vport,
2830 FC_VPORT_NO_FABRIC_RSCS);
2834 case LSRJT_LOGICAL_BSY:
2835 if ((cmd == ELS_CMD_PLOGI) ||
2836 (cmd == ELS_CMD_PRLI)) {
2839 } else if (cmd == ELS_CMD_FDISC) {
2840 /* FDISC retry policy */
2842 if (cmdiocb->retry >= 32)
2848 case LSRJT_LOGICAL_ERR:
2849 /* There are some cases where switches return this
2850 * error when they are not ready and should be returning
2851 * Logical Busy. We should delay every time.
2853 if (cmd == ELS_CMD_FDISC &&
2854 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2860 case LSRJT_PROTOCOL_ERR:
2861 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2862 (cmd == ELS_CMD_FDISC) &&
2863 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2864 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2866 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2867 "0122 FDISC Failed (x%x). "
2868 "Fabric Detected Bad WWN\n",
2869 stat.un.lsRjtError);
2870 lpfc_vport_set_state(vport,
2871 FC_VPORT_FABRIC_REJ_WWN);
2877 case IOSTAT_INTERMED_RSP:
2885 if (did == FDMI_DID)
2888 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
2889 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
2890 !lpfc_error_lost_link(irsp)) {
2891 /* FLOGI retry policy */
2895 if (cmdiocb->retry >= 100)
2897 else if (cmdiocb->retry >= 32)
2902 if (maxretry && (cmdiocb->retry >= maxretry)) {
2903 phba->fc_stat.elsRetryExceeded++;
2907 if ((vport->load_flag & FC_UNLOADING) != 0)
2911 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2912 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2913 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2914 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2915 "2849 Stop retry ELS command "
2916 "x%x to remote NPORT x%x, "
2917 "Data: x%x x%x\n", cmd, did,
2918 cmdiocb->retry, delay);
2923 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2924 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2925 "0107 Retry ELS command x%x to remote "
2926 "NPORT x%x Data: x%x x%x\n",
2927 cmd, did, cmdiocb->retry, delay);
2929 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2930 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2931 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2932 /* Don't reset timer for no resources */
2934 /* If discovery / RSCN timer is running, reset it */
2935 if (timer_pending(&vport->fc_disctmo) ||
2936 (vport->fc_flag & FC_RSCN_MODE))
2937 lpfc_set_disctmo(vport);
2940 phba->fc_stat.elsXmitRetry++;
2941 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
2942 phba->fc_stat.elsDelayRetry++;
2943 ndlp->nlp_retry = cmdiocb->retry;
2945 /* delay is specified in milliseconds */
2946 mod_timer(&ndlp->nlp_delayfunc,
2947 jiffies + msecs_to_jiffies(delay));
2948 spin_lock_irq(shost->host_lock);
2949 ndlp->nlp_flag |= NLP_DELAY_TMO;
2950 spin_unlock_irq(shost->host_lock);
2952 ndlp->nlp_prev_state = ndlp->nlp_state;
2953 if (cmd == ELS_CMD_PRLI)
2954 lpfc_nlp_set_state(vport, ndlp,
2955 NLP_STE_REG_LOGIN_ISSUE);
2957 lpfc_nlp_set_state(vport, ndlp,
2959 ndlp->nlp_last_elscmd = cmd;
2965 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2968 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2971 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2972 ndlp->nlp_prev_state = ndlp->nlp_state;
2973 lpfc_nlp_set_state(vport, ndlp,
2974 NLP_STE_PLOGI_ISSUE);
2976 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2979 ndlp->nlp_prev_state = ndlp->nlp_state;
2980 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2981 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2984 ndlp->nlp_prev_state = ndlp->nlp_state;
2985 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2986 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2989 ndlp->nlp_prev_state = ndlp->nlp_state;
2990 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2991 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2995 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2997 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2998 "0137 No retry ELS command x%x to remote "
2999 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3000 cmd, did, irsp->ulpStatus,
3001 irsp->un.ulpWord[4]);
3004 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3005 "0108 No retry ELS command x%x to remote "
3006 "NPORT x%x Retried:%d Error:x%x/%x\n",
3007 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3008 irsp->un.ulpWord[4]);
3014 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3015 * @phba: pointer to lpfc hba data structure.
3016 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3018 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3019 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3020 * checks to see whether there is a lpfc DMA buffer associated with the
3021 * response of the command IOCB. If so, it will be released before releasing
3022 * the lpfc DMA buffer associated with the IOCB itself.
3025 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3028 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3030 struct lpfc_dmabuf *buf_ptr;
3032 /* Free the response before processing the command. */
3033 if (!list_empty(&buf_ptr1->list)) {
3034 list_remove_head(&buf_ptr1->list, buf_ptr,
3037 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3040 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3046 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3047 * @phba: pointer to lpfc hba data structure.
3048 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3050 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3051 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3055 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3058 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3060 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3066 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3067 * @phba: pointer to lpfc hba data structure.
3068 * @elsiocb: pointer to lpfc els command iocb data structure.
3070 * This routine frees a command IOCB and its associated resources. The
3071 * command IOCB data structure contains the reference to various associated
3072 * resources, these fields must be set to NULL if the associated reference
3074 * context1 - reference to ndlp
3075 * context2 - reference to cmd
3076 * context2->next - reference to rsp
3077 * context3 - reference to bpl
3079 * It first properly decrements the reference count held on ndlp for the
3080 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3081 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3082 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3083 * adds the DMA buffer the @phba data structure for the delayed release.
3084 * If reference to the Buffer Pointer List (BPL) is present, the
3085 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3086 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3087 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3090 * 0 - Success (currently, always return 0)
3093 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3095 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3096 struct lpfc_nodelist *ndlp;
3098 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3100 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3103 /* If the ndlp is not being used by another discovery
3106 if (!lpfc_nlp_not_used(ndlp)) {
3107 /* If ndlp is being used by another discovery
3108 * thread, just clear NLP_DEFER_RM
3110 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3115 elsiocb->context1 = NULL;
3117 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3118 if (elsiocb->context2) {
3119 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3120 /* Firmware could still be in progress of DMAing
3121 * payload, so don't free data buffer till after
3124 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3125 buf_ptr = elsiocb->context2;
3126 elsiocb->context2 = NULL;
3129 spin_lock_irq(&phba->hbalock);
3130 if (!list_empty(&buf_ptr->list)) {
3131 list_remove_head(&buf_ptr->list,
3132 buf_ptr1, struct lpfc_dmabuf,
3134 INIT_LIST_HEAD(&buf_ptr1->list);
3135 list_add_tail(&buf_ptr1->list,
3139 INIT_LIST_HEAD(&buf_ptr->list);
3140 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3142 spin_unlock_irq(&phba->hbalock);
3145 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3146 lpfc_els_free_data(phba, buf_ptr1);
3150 if (elsiocb->context3) {
3151 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3152 lpfc_els_free_bpl(phba, buf_ptr);
3154 lpfc_sli_release_iocbq(phba, elsiocb);
3159 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3160 * @phba: pointer to lpfc hba data structure.
3161 * @cmdiocb: pointer to lpfc command iocb data structure.
3162 * @rspiocb: pointer to lpfc response iocb data structure.
3164 * This routine is the completion callback function to the Logout (LOGO)
3165 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3166 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3167 * release the ndlp if it has the last reference remaining (reference count
3168 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3169 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3170 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3171 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3172 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3173 * IOCB data structure.
3176 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3177 struct lpfc_iocbq *rspiocb)
3179 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3180 struct lpfc_vport *vport = cmdiocb->vport;
3183 irsp = &rspiocb->iocb;
3184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3185 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3186 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3187 /* ACC to LOGO completes to NPort <nlp_DID> */
3188 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3189 "0109 ACC to LOGO completes to NPort x%x "
3190 "Data: x%x x%x x%x\n",
3191 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3194 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3195 /* NPort Recovery mode or node is just allocated */
3196 if (!lpfc_nlp_not_used(ndlp)) {
3197 /* If the ndlp is being used by another discovery
3198 * thread, just unregister the RPI.
3200 lpfc_unreg_rpi(vport, ndlp);
3202 /* Indicate the node has already released, should
3203 * not reference to it from within lpfc_els_free_iocb.
3205 cmdiocb->context1 = NULL;
3208 lpfc_els_free_iocb(phba, cmdiocb);
3213 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3214 * @phba: pointer to lpfc hba data structure.
3215 * @pmb: pointer to the driver internal queue element for mailbox command.
3217 * This routine is the completion callback function for unregister default
3218 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3219 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3220 * decrements the ndlp reference count held for this completion callback
3221 * function. After that, it invokes the lpfc_nlp_not_used() to check
3222 * whether there is only one reference left on the ndlp. If so, it will
3223 * perform one more decrement and trigger the release of the ndlp.
3226 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3228 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3229 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3232 * This routine is used to register and unregister in previous SLI
3235 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3236 (phba->sli_rev == LPFC_SLI_REV4))
3237 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3239 pmb->context1 = NULL;
3240 pmb->context2 = NULL;
3242 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3244 mempool_free(pmb, phba->mbox_mem_pool);
3245 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3247 /* This is the end of the default RPI cleanup logic for this
3248 * ndlp. If no other discovery threads are using this ndlp.
3249 * we should free all resources associated with it.
3251 lpfc_nlp_not_used(ndlp);
3258 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3259 * @phba: pointer to lpfc hba data structure.
3260 * @cmdiocb: pointer to lpfc command iocb data structure.
3261 * @rspiocb: pointer to lpfc response iocb data structure.
3263 * This routine is the completion callback function for ELS Response IOCB
3264 * command. In normal case, this callback function just properly sets the
3265 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3266 * field in the command IOCB is not NULL, the referred mailbox command will
3267 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3268 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3269 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3270 * routine shall be invoked trying to release the ndlp if no other threads
3271 * are currently referring it.
3274 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3275 struct lpfc_iocbq *rspiocb)
3277 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3278 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3279 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3282 LPFC_MBOXQ_t *mbox = NULL;
3283 struct lpfc_dmabuf *mp = NULL;
3284 uint32_t ls_rjt = 0;
3286 irsp = &rspiocb->iocb;
3288 if (cmdiocb->context_un.mbox)
3289 mbox = cmdiocb->context_un.mbox;
3291 /* First determine if this is a LS_RJT cmpl. Note, this callback
3292 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3294 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3295 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3296 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3297 /* A LS_RJT associated with Default RPI cleanup has its own
3298 * separate code path.
3300 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3304 /* Check to see if link went down during discovery */
3305 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3307 mp = (struct lpfc_dmabuf *) mbox->context1;
3309 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3312 mempool_free(mbox, phba->mbox_mem_pool);
3314 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3315 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3316 if (lpfc_nlp_not_used(ndlp)) {
3318 /* Indicate the node has already released,
3319 * should not reference to it from within
3320 * the routine lpfc_els_free_iocb.
3322 cmdiocb->context1 = NULL;
3327 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3328 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3329 irsp->ulpStatus, irsp->un.ulpWord[4],
3330 cmdiocb->iocb.un.elsreq64.remoteID);
3331 /* ELS response tag <ulpIoTag> completes */
3332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3333 "0110 ELS response tag x%x completes "
3334 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3335 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3336 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3337 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3340 if ((rspiocb->iocb.ulpStatus == 0)
3341 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3342 lpfc_unreg_rpi(vport, ndlp);
3343 /* Increment reference count to ndlp to hold the
3344 * reference to ndlp for the callback function.
3346 mbox->context2 = lpfc_nlp_get(ndlp);
3347 mbox->vport = vport;
3348 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3349 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3350 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3353 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3354 ndlp->nlp_prev_state = ndlp->nlp_state;
3355 lpfc_nlp_set_state(vport, ndlp,
3356 NLP_STE_REG_LOGIN_ISSUE);
3358 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3359 != MBX_NOT_FINISHED)
3362 /* Decrement the ndlp reference count we
3363 * set for this failed mailbox command.
3367 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3368 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3369 "0138 ELS rsp: Cannot issue reg_login for x%x "
3370 "Data: x%x x%x x%x\n",
3371 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3374 if (lpfc_nlp_not_used(ndlp)) {
3376 /* Indicate node has already been released,
3377 * should not reference to it from within
3378 * the routine lpfc_els_free_iocb.
3380 cmdiocb->context1 = NULL;
3383 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3384 if (!lpfc_error_lost_link(irsp) &&
3385 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3386 if (lpfc_nlp_not_used(ndlp)) {
3388 /* Indicate node has already been
3389 * released, should not reference
3390 * to it from within the routine
3391 * lpfc_els_free_iocb.
3393 cmdiocb->context1 = NULL;
3397 mp = (struct lpfc_dmabuf *) mbox->context1;
3399 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3402 mempool_free(mbox, phba->mbox_mem_pool);
3405 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3406 spin_lock_irq(shost->host_lock);
3407 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3408 spin_unlock_irq(shost->host_lock);
3410 /* If the node is not being used by another discovery thread,
3411 * and we are sending a reject, we are done with it.
3412 * Release driver reference count here and free associated
3416 if (lpfc_nlp_not_used(ndlp))
3417 /* Indicate node has already been released,
3418 * should not reference to it from within
3419 * the routine lpfc_els_free_iocb.
3421 cmdiocb->context1 = NULL;
3424 lpfc_els_free_iocb(phba, cmdiocb);
3429 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3430 * @vport: pointer to a host virtual N_Port data structure.
3431 * @flag: the els command code to be accepted.
3432 * @oldiocb: pointer to the original lpfc command iocb data structure.
3433 * @ndlp: pointer to a node-list data structure.
3434 * @mbox: pointer to the driver internal queue element for mailbox command.
3436 * This routine prepares and issues an Accept (ACC) response IOCB
3437 * command. It uses the @flag to properly set up the IOCB field for the
3438 * specific ACC response command to be issued and invokes the
3439 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3440 * @mbox pointer is passed in, it will be put into the context_un.mbox
3441 * field of the IOCB for the completion callback function to issue the
3442 * mailbox command to the HBA later when callback is invoked.
3444 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3445 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3446 * will be stored into the context1 field of the IOCB for the completion
3447 * callback function to the corresponding response ELS IOCB command.
3450 * 0 - Successfully issued acc response
3451 * 1 - Failed to issue acc response
3454 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3455 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3459 struct lpfc_hba *phba = vport->phba;
3462 struct lpfc_iocbq *elsiocb;
3463 struct lpfc_sli *psli;
3467 ELS_PKT *els_pkt_ptr;
3470 oldcmd = &oldiocb->iocb;
3474 cmdsize = sizeof(uint32_t);
3475 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3476 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3478 spin_lock_irq(shost->host_lock);
3479 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3480 spin_unlock_irq(shost->host_lock);
3484 icmd = &elsiocb->iocb;
3485 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3486 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3487 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3488 pcmd += sizeof(uint32_t);
3490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3491 "Issue ACC: did:x%x flg:x%x",
3492 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3495 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3496 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3497 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3501 icmd = &elsiocb->iocb;
3502 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3503 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3506 elsiocb->context_un.mbox = mbox;
3508 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3509 pcmd += sizeof(uint32_t);
3510 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3513 "Issue ACC PLOGI: did:x%x flg:x%x",
3514 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3517 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3518 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3519 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3523 icmd = &elsiocb->iocb;
3524 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3525 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3527 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3528 sizeof(uint32_t) + sizeof(PRLO));
3529 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3530 els_pkt_ptr = (ELS_PKT *) pcmd;
3531 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3534 "Issue ACC PRLO: did:x%x flg:x%x",
3535 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3540 /* Xmit ELS ACC response tag <ulpIoTag> */
3541 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3542 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3543 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3544 elsiocb->iotag, elsiocb->iocb.ulpContext,
3545 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3547 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3548 spin_lock_irq(shost->host_lock);
3549 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3550 spin_unlock_irq(shost->host_lock);
3551 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3553 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3556 phba->fc_stat.elsXmitACC++;
3557 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3558 if (rc == IOCB_ERROR) {
3559 lpfc_els_free_iocb(phba, elsiocb);
3566 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3567 * @vport: pointer to a virtual N_Port data structure.
3569 * @oldiocb: pointer to the original lpfc command iocb data structure.
3570 * @ndlp: pointer to a node-list data structure.
3571 * @mbox: pointer to the driver internal queue element for mailbox command.
3573 * This routine prepares and issue an Reject (RJT) response IOCB
3574 * command. If a @mbox pointer is passed in, it will be put into the
3575 * context_un.mbox field of the IOCB for the completion callback function
3576 * to issue to the HBA later.
3578 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3579 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3580 * will be stored into the context1 field of the IOCB for the completion
3581 * callback function to the reject response ELS IOCB command.
3584 * 0 - Successfully issued reject response
3585 * 1 - Failed to issue reject response
3588 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3589 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3592 struct lpfc_hba *phba = vport->phba;
3595 struct lpfc_iocbq *elsiocb;
3596 struct lpfc_sli *psli;
3602 cmdsize = 2 * sizeof(uint32_t);
3603 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3604 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3608 icmd = &elsiocb->iocb;
3609 oldcmd = &oldiocb->iocb;
3610 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3611 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3613 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3614 pcmd += sizeof(uint32_t);
3615 *((uint32_t *) (pcmd)) = rejectError;
3618 elsiocb->context_un.mbox = mbox;
3620 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3621 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3622 "0129 Xmit ELS RJT x%x response tag x%x "
3623 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3625 rejectError, elsiocb->iotag,
3626 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3627 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3628 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3629 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3630 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3632 phba->fc_stat.elsXmitLSRJT++;
3633 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3634 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3636 if (rc == IOCB_ERROR) {
3637 lpfc_els_free_iocb(phba, elsiocb);
3644 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3645 * @vport: pointer to a virtual N_Port data structure.
3646 * @oldiocb: pointer to the original lpfc command iocb data structure.
3647 * @ndlp: pointer to a node-list data structure.
3649 * This routine prepares and issues an Accept (ACC) response to Address
3650 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3651 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3653 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3654 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3655 * will be stored into the context1 field of the IOCB for the completion
3656 * callback function to the ADISC Accept response ELS IOCB command.
3659 * 0 - Successfully issued acc adisc response
3660 * 1 - Failed to issue adisc acc response
3663 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3664 struct lpfc_nodelist *ndlp)
3666 struct lpfc_hba *phba = vport->phba;
3668 IOCB_t *icmd, *oldcmd;
3669 struct lpfc_iocbq *elsiocb;
3674 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3675 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3676 ndlp->nlp_DID, ELS_CMD_ACC);
3680 icmd = &elsiocb->iocb;
3681 oldcmd = &oldiocb->iocb;
3682 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3684 /* Xmit ADISC ACC response tag <ulpIoTag> */
3685 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3686 "0130 Xmit ADISC ACC response iotag x%x xri: "
3687 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3688 elsiocb->iotag, elsiocb->iocb.ulpContext,
3689 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3691 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3693 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3694 pcmd += sizeof(uint32_t);
3696 ap = (ADISC *) (pcmd);
3697 ap->hardAL_PA = phba->fc_pref_ALPA;
3698 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3699 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3700 ap->DID = be32_to_cpu(vport->fc_myDID);
3702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3703 "Issue ACC ADISC: did:x%x flg:x%x",
3704 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3706 phba->fc_stat.elsXmitACC++;
3707 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3708 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3709 if (rc == IOCB_ERROR) {
3710 lpfc_els_free_iocb(phba, elsiocb);
3717 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3718 * @vport: pointer to a virtual N_Port data structure.
3719 * @oldiocb: pointer to the original lpfc command iocb data structure.
3720 * @ndlp: pointer to a node-list data structure.
3722 * This routine prepares and issues an Accept (ACC) response to Process
3723 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3724 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3726 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3727 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3728 * will be stored into the context1 field of the IOCB for the completion
3729 * callback function to the PRLI Accept response ELS IOCB command.
3732 * 0 - Successfully issued acc prli response
3733 * 1 - Failed to issue acc prli response
3736 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3737 struct lpfc_nodelist *ndlp)
3739 struct lpfc_hba *phba = vport->phba;
3744 struct lpfc_iocbq *elsiocb;
3745 struct lpfc_sli *psli;
3752 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3753 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3754 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3758 icmd = &elsiocb->iocb;
3759 oldcmd = &oldiocb->iocb;
3760 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3761 /* Xmit PRLI ACC response tag <ulpIoTag> */
3762 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3763 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3764 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3765 elsiocb->iotag, elsiocb->iocb.ulpContext,
3766 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3768 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3770 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3771 pcmd += sizeof(uint32_t);
3773 /* For PRLI, remainder of payload is PRLI parameter page */
3774 memset(pcmd, 0, sizeof(PRLI));
3776 npr = (PRLI *) pcmd;
3779 * If the remote port is a target and our firmware version is 3.20 or
3780 * later, set the following bits for FC-TAPE support.
3782 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3783 (vpd->rev.feaLevelHigh >= 0x02)) {
3784 npr->ConfmComplAllowed = 1;
3786 npr->TaskRetryIdReq = 1;
3789 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3790 npr->estabImagePair = 1;
3791 npr->readXferRdyDis = 1;
3792 npr->ConfmComplAllowed = 1;
3794 npr->prliType = PRLI_FCP_TYPE;
3795 npr->initiatorFunc = 1;
3797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3798 "Issue ACC PRLI: did:x%x flg:x%x",
3799 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3801 phba->fc_stat.elsXmitACC++;
3802 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3804 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3805 if (rc == IOCB_ERROR) {
3806 lpfc_els_free_iocb(phba, elsiocb);
3813 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3814 * @vport: pointer to a virtual N_Port data structure.
3815 * @format: rnid command format.
3816 * @oldiocb: pointer to the original lpfc command iocb data structure.
3817 * @ndlp: pointer to a node-list data structure.
3819 * This routine issues a Request Node Identification Data (RNID) Accept
3820 * (ACC) response. It constructs the RNID ACC response command according to
3821 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3822 * issue the response. Note that this command does not need to hold the ndlp
3823 * reference count for the callback. So, the ndlp reference count taken by
3824 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3825 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3826 * there is no ndlp reference available.
3828 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3829 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3830 * will be stored into the context1 field of the IOCB for the completion
3831 * callback function. However, for the RNID Accept Response ELS command,
3832 * this is undone later by this routine after the IOCB is allocated.
3835 * 0 - Successfully issued acc rnid response
3836 * 1 - Failed to issue acc rnid response
3839 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3840 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3842 struct lpfc_hba *phba = vport->phba;
3844 IOCB_t *icmd, *oldcmd;
3845 struct lpfc_iocbq *elsiocb;
3846 struct lpfc_sli *psli;
3852 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3853 + (2 * sizeof(struct lpfc_name));
3855 cmdsize += sizeof(RNID_TOP_DISC);
3857 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3858 ndlp->nlp_DID, ELS_CMD_ACC);
3862 icmd = &elsiocb->iocb;
3863 oldcmd = &oldiocb->iocb;
3864 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3865 /* Xmit RNID ACC response tag <ulpIoTag> */
3866 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3867 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3868 elsiocb->iotag, elsiocb->iocb.ulpContext);
3869 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3870 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3871 pcmd += sizeof(uint32_t);
3873 memset(pcmd, 0, sizeof(RNID));
3874 rn = (RNID *) (pcmd);
3875 rn->Format = format;
3876 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3877 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3878 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3881 rn->SpecificLen = 0;
3883 case RNID_TOPOLOGY_DISC:
3884 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3885 memcpy(&rn->un.topologyDisc.portName,
3886 &vport->fc_portname, sizeof(struct lpfc_name));
3887 rn->un.topologyDisc.unitType = RNID_HBA;
3888 rn->un.topologyDisc.physPort = 0;
3889 rn->un.topologyDisc.attachedNodes = 0;
3893 rn->SpecificLen = 0;
3897 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3898 "Issue ACC RNID: did:x%x flg:x%x",
3899 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3901 phba->fc_stat.elsXmitACC++;
3902 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3904 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3905 * it could be freed */
3907 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3908 if (rc == IOCB_ERROR) {
3909 lpfc_els_free_iocb(phba, elsiocb);
3916 * lpfc_els_rsp_echo_acc - Issue echo acc response
3917 * @vport: pointer to a virtual N_Port data structure.
3918 * @data: pointer to echo data to return in the accept.
3919 * @oldiocb: pointer to the original lpfc command iocb data structure.
3920 * @ndlp: pointer to a node-list data structure.
3923 * 0 - Successfully issued acc echo response
3924 * 1 - Failed to issue acc echo response
3927 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3928 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3930 struct lpfc_hba *phba = vport->phba;
3931 struct lpfc_iocbq *elsiocb;
3932 struct lpfc_sli *psli;
3938 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3940 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3941 ndlp->nlp_DID, ELS_CMD_ACC);
3945 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3946 /* Xmit ECHO ACC response tag <ulpIoTag> */
3947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3948 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3949 elsiocb->iotag, elsiocb->iocb.ulpContext);
3950 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3951 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3952 pcmd += sizeof(uint32_t);
3953 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3955 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3956 "Issue ACC ECHO: did:x%x flg:x%x",
3957 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3959 phba->fc_stat.elsXmitACC++;
3960 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3962 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3963 * it could be freed */
3965 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3966 if (rc == IOCB_ERROR) {
3967 lpfc_els_free_iocb(phba, elsiocb);
3974 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3975 * @vport: pointer to a host virtual N_Port data structure.
3977 * This routine issues Address Discover (ADISC) ELS commands to those
3978 * N_Ports which are in node port recovery state and ADISC has not been issued
3979 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3980 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3981 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3982 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3983 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3984 * IOCBs quit for later pick up. On the other hand, after walking through
3985 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3986 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3987 * no more ADISC need to be sent.
3990 * The number of N_Ports with adisc issued.
3993 lpfc_els_disc_adisc(struct lpfc_vport *vport)
3995 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3996 struct lpfc_nodelist *ndlp, *next_ndlp;
3999 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4000 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4001 if (!NLP_CHK_NODE_ACT(ndlp))
4003 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4004 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4005 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4006 spin_lock_irq(shost->host_lock);
4007 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4008 spin_unlock_irq(shost->host_lock);
4009 ndlp->nlp_prev_state = ndlp->nlp_state;
4010 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4011 lpfc_issue_els_adisc(vport, ndlp, 0);
4013 vport->num_disc_nodes++;
4014 if (vport->num_disc_nodes >=
4015 vport->cfg_discovery_threads) {
4016 spin_lock_irq(shost->host_lock);
4017 vport->fc_flag |= FC_NLP_MORE;
4018 spin_unlock_irq(shost->host_lock);
4023 if (sentadisc == 0) {
4024 spin_lock_irq(shost->host_lock);
4025 vport->fc_flag &= ~FC_NLP_MORE;
4026 spin_unlock_irq(shost->host_lock);
4032 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4033 * @vport: pointer to a host virtual N_Port data structure.
4035 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4036 * which are in node port recovery state, with a @vport. Each time an ELS
4037 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4038 * the per @vport number of discover count (num_disc_nodes) shall be
4039 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4040 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4041 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4042 * later pick up. On the other hand, after walking through all the ndlps with
4043 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4044 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4045 * PLOGI need to be sent.
4048 * The number of N_Ports with plogi issued.
4051 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4054 struct lpfc_nodelist *ndlp, *next_ndlp;
4057 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4058 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4059 if (!NLP_CHK_NODE_ACT(ndlp))
4061 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4062 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4063 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4064 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4065 ndlp->nlp_prev_state = ndlp->nlp_state;
4066 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4067 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4069 vport->num_disc_nodes++;
4070 if (vport->num_disc_nodes >=
4071 vport->cfg_discovery_threads) {
4072 spin_lock_irq(shost->host_lock);
4073 vport->fc_flag |= FC_NLP_MORE;
4074 spin_unlock_irq(shost->host_lock);
4080 lpfc_set_disctmo(vport);
4083 spin_lock_irq(shost->host_lock);
4084 vport->fc_flag &= ~FC_NLP_MORE;
4085 spin_unlock_irq(shost->host_lock);
4091 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4092 * @vport: pointer to a host virtual N_Port data structure.
4094 * This routine cleans up any Registration State Change Notification
4095 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4096 * @vport together with the host_lock is used to prevent multiple thread
4097 * trying to access the RSCN array on a same @vport at the same time.
4100 lpfc_els_flush_rscn(struct lpfc_vport *vport)
4102 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4103 struct lpfc_hba *phba = vport->phba;
4106 spin_lock_irq(shost->host_lock);
4107 if (vport->fc_rscn_flush) {
4108 /* Another thread is walking fc_rscn_id_list on this vport */
4109 spin_unlock_irq(shost->host_lock);
4112 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4113 vport->fc_rscn_flush = 1;
4114 spin_unlock_irq(shost->host_lock);
4116 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4117 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
4118 vport->fc_rscn_id_list[i] = NULL;
4120 spin_lock_irq(shost->host_lock);
4121 vport->fc_rscn_id_cnt = 0;
4122 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4123 spin_unlock_irq(shost->host_lock);
4124 lpfc_can_disctmo(vport);
4125 /* Indicate we are done walking this fc_rscn_id_list */
4126 vport->fc_rscn_flush = 0;
4130 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4131 * @vport: pointer to a host virtual N_Port data structure.
4132 * @did: remote destination port identifier.
4134 * This routine checks whether there is any pending Registration State
4135 * Configuration Notification (RSCN) to a @did on @vport.
4138 * None zero - The @did matched with a pending rscn
4139 * 0 - not able to match @did with a pending rscn
4142 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
4147 uint32_t payload_len, i;
4148 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4150 ns_did.un.word = did;
4152 /* Never match fabric nodes for RSCNs */
4153 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
4156 /* If we are doing a FULL RSCN rediscovery, match everything */
4157 if (vport->fc_flag & FC_RSCN_DISCOVERY)
4160 spin_lock_irq(shost->host_lock);
4161 if (vport->fc_rscn_flush) {
4162 /* Another thread is walking fc_rscn_id_list on this vport */
4163 spin_unlock_irq(shost->host_lock);
4166 /* Indicate we are walking fc_rscn_id_list on this vport */
4167 vport->fc_rscn_flush = 1;
4168 spin_unlock_irq(shost->host_lock);
4169 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4170 lp = vport->fc_rscn_id_list[i]->virt;
4171 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4172 payload_len -= sizeof(uint32_t); /* take off word 0 */
4173 while (payload_len) {
4174 rscn_did.un.word = be32_to_cpu(*lp++);
4175 payload_len -= sizeof(uint32_t);
4176 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4177 case RSCN_ADDRESS_FORMAT_PORT:
4178 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4179 && (ns_did.un.b.area == rscn_did.un.b.area)
4180 && (ns_did.un.b.id == rscn_did.un.b.id))
4181 goto return_did_out;
4183 case RSCN_ADDRESS_FORMAT_AREA:
4184 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4185 && (ns_did.un.b.area == rscn_did.un.b.area))
4186 goto return_did_out;
4188 case RSCN_ADDRESS_FORMAT_DOMAIN:
4189 if (ns_did.un.b.domain == rscn_did.un.b.domain)
4190 goto return_did_out;
4192 case RSCN_ADDRESS_FORMAT_FABRIC:
4193 goto return_did_out;
4197 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4198 vport->fc_rscn_flush = 0;
4201 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4202 vport->fc_rscn_flush = 0;
4207 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4208 * @vport: pointer to a host virtual N_Port data structure.
4210 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4211 * state machine for a @vport's nodes that are with pending RSCN (Registration
4212 * State Change Notification).
4215 * 0 - Successful (currently alway return 0)
4218 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
4220 struct lpfc_nodelist *ndlp = NULL;
4222 /* Move all affected nodes by pending RSCNs to NPR state. */
4223 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4224 if (!NLP_CHK_NODE_ACT(ndlp) ||
4225 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4226 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
4228 lpfc_disc_state_machine(vport, ndlp, NULL,
4229 NLP_EVT_DEVICE_RECOVERY);
4230 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4236 * lpfc_send_rscn_event - Send an RSCN event to management application
4237 * @vport: pointer to a host virtual N_Port data structure.
4238 * @cmdiocb: pointer to lpfc command iocb data structure.
4240 * lpfc_send_rscn_event sends an RSCN netlink event to management
4244 lpfc_send_rscn_event(struct lpfc_vport *vport,
4245 struct lpfc_iocbq *cmdiocb)
4247 struct lpfc_dmabuf *pcmd;
4248 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4249 uint32_t *payload_ptr;
4250 uint32_t payload_len;
4251 struct lpfc_rscn_event_header *rscn_event_data;
4253 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4254 payload_ptr = (uint32_t *) pcmd->virt;
4255 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4257 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4258 payload_len, GFP_KERNEL);
4259 if (!rscn_event_data) {
4260 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4261 "0147 Failed to allocate memory for RSCN event\n");
4264 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4265 rscn_event_data->payload_length = payload_len;
4266 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4269 fc_host_post_vendor_event(shost,
4270 fc_get_event_number(),
4271 sizeof(struct lpfc_els_event_header) + payload_len,
4272 (char *)rscn_event_data,
4275 kfree(rscn_event_data);
4279 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4280 * @vport: pointer to a host virtual N_Port data structure.
4281 * @cmdiocb: pointer to lpfc command iocb data structure.
4282 * @ndlp: pointer to a node-list data structure.
4284 * This routine processes an unsolicited RSCN (Registration State Change
4285 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4286 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4287 * discover state machine is about to begin discovery, it just accepts the
4288 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4289 * contains N_Port IDs for other vports on this HBA, it just accepts the
4290 * RSCN and ignore processing it. If the state machine is in the recovery
4291 * state, the fc_rscn_id_list of this @vport is walked and the
4292 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4293 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4294 * routine is invoked to handle the RSCN event.
4297 * 0 - Just sent the acc response
4298 * 1 - Sent the acc response and waited for name server completion
4301 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4302 struct lpfc_nodelist *ndlp)
4304 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4305 struct lpfc_hba *phba = vport->phba;
4306 struct lpfc_dmabuf *pcmd;
4307 uint32_t *lp, *datap;
4309 uint32_t payload_len, length, nportid, *cmd;
4311 int rscn_id = 0, hba_id = 0;
4314 icmd = &cmdiocb->iocb;
4315 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4316 lp = (uint32_t *) pcmd->virt;
4318 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4319 payload_len -= sizeof(uint32_t); /* take off word 0 */
4321 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4322 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4323 vport->fc_flag, payload_len, *lp,
4324 vport->fc_rscn_id_cnt);
4326 /* Send an RSCN event to the management application */
4327 lpfc_send_rscn_event(vport, cmdiocb);
4329 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
4330 fc_host_post_event(shost, fc_get_event_number(),
4331 FCH_EVT_RSCN, lp[i]);
4333 /* If we are about to begin discovery, just ACC the RSCN.
4334 * Discovery processing will satisfy it.
4336 if (vport->port_state <= LPFC_NS_QRY) {
4337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4338 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4339 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4341 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4345 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4346 * just ACC and ignore it.
4348 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4349 !(vport->cfg_peer_port_login)) {
4354 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4355 i -= sizeof(uint32_t);
4357 if (lpfc_find_vport_by_did(phba, nportid))
4360 if (rscn_id == hba_id) {
4361 /* ALL NPortIDs in RSCN are on HBA */
4362 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4364 "Data: x%x x%x x%x x%x\n",
4365 vport->fc_flag, payload_len,
4366 *lp, vport->fc_rscn_id_cnt);
4367 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4368 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4369 ndlp->nlp_DID, vport->port_state,
4372 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4378 spin_lock_irq(shost->host_lock);
4379 if (vport->fc_rscn_flush) {
4380 /* Another thread is walking fc_rscn_id_list on this vport */
4381 vport->fc_flag |= FC_RSCN_DISCOVERY;
4382 spin_unlock_irq(shost->host_lock);
4384 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4387 /* Indicate we are walking fc_rscn_id_list on this vport */
4388 vport->fc_rscn_flush = 1;
4389 spin_unlock_irq(shost->host_lock);
4390 /* Get the array count after successfully have the token */
4391 rscn_cnt = vport->fc_rscn_id_cnt;
4392 /* If we are already processing an RSCN, save the received
4393 * RSCN payload buffer, cmdiocb->context2 to process later.
4395 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4396 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4397 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4398 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4400 spin_lock_irq(shost->host_lock);
4401 vport->fc_flag |= FC_RSCN_DEFERRED;
4402 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4403 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4404 vport->fc_flag |= FC_RSCN_MODE;
4405 spin_unlock_irq(shost->host_lock);
4407 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4408 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4411 (payload_len + length <= LPFC_BPL_SIZE)) {
4412 *cmd &= ELS_CMD_MASK;
4413 *cmd |= cpu_to_be32(payload_len + length);
4414 memcpy(((uint8_t *)cmd) + length, lp,
4417 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4418 vport->fc_rscn_id_cnt++;
4419 /* If we zero, cmdiocb->context2, the calling
4420 * routine will not try to free it.
4422 cmdiocb->context2 = NULL;
4425 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4426 "0235 Deferred RSCN "
4427 "Data: x%x x%x x%x\n",
4428 vport->fc_rscn_id_cnt, vport->fc_flag,
4431 vport->fc_flag |= FC_RSCN_DISCOVERY;
4432 spin_unlock_irq(shost->host_lock);
4433 /* ReDiscovery RSCN */
4434 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4435 "0234 ReDiscovery RSCN "
4436 "Data: x%x x%x x%x\n",
4437 vport->fc_rscn_id_cnt, vport->fc_flag,
4440 /* Indicate we are done walking fc_rscn_id_list on this vport */
4441 vport->fc_rscn_flush = 0;
4443 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4444 /* send RECOVERY event for ALL nodes that match RSCN payload */
4445 lpfc_rscn_recovery_check(vport);
4446 spin_lock_irq(shost->host_lock);
4447 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4448 spin_unlock_irq(shost->host_lock);
4451 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4452 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4453 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4455 spin_lock_irq(shost->host_lock);
4456 vport->fc_flag |= FC_RSCN_MODE;
4457 spin_unlock_irq(shost->host_lock);
4458 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4459 /* Indicate we are done walking fc_rscn_id_list on this vport */
4460 vport->fc_rscn_flush = 0;
4462 * If we zero, cmdiocb->context2, the calling routine will
4463 * not try to free it.
4465 cmdiocb->context2 = NULL;
4466 lpfc_set_disctmo(vport);
4468 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4469 /* send RECOVERY event for ALL nodes that match RSCN payload */
4470 lpfc_rscn_recovery_check(vport);
4471 return lpfc_els_handle_rscn(vport);
4475 * lpfc_els_handle_rscn - Handle rscn for a vport
4476 * @vport: pointer to a host virtual N_Port data structure.
4478 * This routine handles the Registration State Configuration Notification
4479 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4480 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4481 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4482 * NameServer shall be issued. If CT command to the NameServer fails to be
4483 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4484 * RSCN activities with the @vport.
4487 * 0 - Cleaned up rscn on the @vport
4488 * 1 - Wait for plogi to name server before proceed
4491 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4493 struct lpfc_nodelist *ndlp;
4494 struct lpfc_hba *phba = vport->phba;
4496 /* Ignore RSCN if the port is being torn down. */
4497 if (vport->load_flag & FC_UNLOADING) {
4498 lpfc_els_flush_rscn(vport);
4502 /* Start timer for RSCN processing */
4503 lpfc_set_disctmo(vport);
4505 /* RSCN processed */
4506 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4507 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4508 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4511 /* To process RSCN, first compare RSCN data with NameServer */
4512 vport->fc_ns_retry = 0;
4513 vport->num_disc_nodes = 0;
4515 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4516 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4517 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4518 /* Good ndlp, issue CT Request to NameServer */
4519 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4520 /* Wait for NameServer query cmpl before we can
4524 /* If login to NameServer does not exist, issue one */
4525 /* Good status, issue PLOGI to NameServer */
4526 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4527 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4528 /* Wait for NameServer login cmpl before we can
4533 ndlp = lpfc_enable_node(vport, ndlp,
4534 NLP_STE_PLOGI_ISSUE);
4536 lpfc_els_flush_rscn(vport);
4539 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4541 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4543 lpfc_els_flush_rscn(vport);
4546 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4547 ndlp->nlp_prev_state = ndlp->nlp_state;
4548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4550 ndlp->nlp_type |= NLP_FABRIC;
4551 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4552 /* Wait for NameServer login cmpl before we can
4558 lpfc_els_flush_rscn(vport);
4563 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4564 * @vport: pointer to a host virtual N_Port data structure.
4565 * @cmdiocb: pointer to lpfc command iocb data structure.
4566 * @ndlp: pointer to a node-list data structure.
4568 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4569 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4570 * point topology. As an unsolicited FLOGI should not be received in a loop
4571 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4572 * lpfc_check_sparm() routine is invoked to check the parameters in the
4573 * unsolicited FLOGI. If parameters validation failed, the routine
4574 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4575 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4576 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4577 * will initiate PLOGI. The higher lexicographical value party shall has
4578 * higher priority (as the winning port) and will initiate PLOGI and
4579 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4580 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4581 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4584 * 0 - Successfully processed the unsolicited flogi
4585 * 1 - Failed to process the unsolicited flogi
4588 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4589 struct lpfc_nodelist *ndlp)
4591 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4592 struct lpfc_hba *phba = vport->phba;
4593 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4594 uint32_t *lp = (uint32_t *) pcmd->virt;
4595 IOCB_t *icmd = &cmdiocb->iocb;
4596 struct serv_parm *sp;
4603 sp = (struct serv_parm *) lp;
4605 /* FLOGI received */
4607 lpfc_set_disctmo(vport);
4609 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4610 /* We should never receive a FLOGI in loop mode, ignore it */
4611 did = icmd->un.elsreq64.remoteID;
4613 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4615 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4616 "0113 An FLOGI ELS command x%x was "
4617 "received from DID x%x in Loop Mode\n",
4624 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
4625 /* For a FLOGI we accept, then if our portname is greater
4626 * then the remote portname we initiate Nport login.
4629 rc = memcmp(&vport->fc_portname, &sp->portName,
4630 sizeof(struct lpfc_name));
4633 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4637 lpfc_linkdown(phba);
4638 lpfc_init_link(phba, mbox,
4640 phba->cfg_link_speed);
4641 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4642 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4643 mbox->vport = vport;
4644 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4645 lpfc_set_loopback_flag(phba);
4646 if (rc == MBX_NOT_FINISHED) {
4647 mempool_free(mbox, phba->mbox_mem_pool);
4650 } else if (rc > 0) { /* greater than */
4651 spin_lock_irq(shost->host_lock);
4652 vport->fc_flag |= FC_PT2PT_PLOGI;
4653 spin_unlock_irq(shost->host_lock);
4655 spin_lock_irq(shost->host_lock);
4656 vport->fc_flag |= FC_PT2PT;
4657 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4658 spin_unlock_irq(shost->host_lock);
4660 /* Reject this request because invalid parameters */
4661 stat.un.b.lsRjtRsvd0 = 0;
4662 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4663 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4664 stat.un.b.vendorUnique = 0;
4665 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4671 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4677 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4678 * @vport: pointer to a host virtual N_Port data structure.
4679 * @cmdiocb: pointer to lpfc command iocb data structure.
4680 * @ndlp: pointer to a node-list data structure.
4682 * This routine processes Request Node Identification Data (RNID) IOCB
4683 * received as an ELS unsolicited event. Only when the RNID specified format
4684 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4685 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4686 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4687 * rejected by invoking the lpfc_els_rsp_reject() routine.
4690 * 0 - Successfully processed rnid iocb (currently always return 0)
4693 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4694 struct lpfc_nodelist *ndlp)
4696 struct lpfc_dmabuf *pcmd;
4703 icmd = &cmdiocb->iocb;
4704 did = icmd->un.elsreq64.remoteID;
4705 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4706 lp = (uint32_t *) pcmd->virt;
4713 switch (rn->Format) {
4715 case RNID_TOPOLOGY_DISC:
4717 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4720 /* Reject this request because format not supported */
4721 stat.un.b.lsRjtRsvd0 = 0;
4722 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4723 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4724 stat.un.b.vendorUnique = 0;
4725 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4732 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4733 * @vport: pointer to a host virtual N_Port data structure.
4734 * @cmdiocb: pointer to lpfc command iocb data structure.
4735 * @ndlp: pointer to a node-list data structure.
4738 * 0 - Successfully processed echo iocb (currently always return 0)
4741 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4742 struct lpfc_nodelist *ndlp)
4746 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4748 /* skip over first word of echo command to find echo data */
4749 pcmd += sizeof(uint32_t);
4751 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4756 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4757 * @vport: pointer to a host virtual N_Port data structure.
4758 * @cmdiocb: pointer to lpfc command iocb data structure.
4759 * @ndlp: pointer to a node-list data structure.
4761 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4762 * received as an ELS unsolicited event. Currently, this function just invokes
4763 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4766 * 0 - Successfully processed lirr iocb (currently always return 0)
4769 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4770 struct lpfc_nodelist *ndlp)
4774 /* For now, unconditionally reject this command */
4775 stat.un.b.lsRjtRsvd0 = 0;
4776 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4777 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4778 stat.un.b.vendorUnique = 0;
4779 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4784 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4785 * @vport: pointer to a host virtual N_Port data structure.
4786 * @cmdiocb: pointer to lpfc command iocb data structure.
4787 * @ndlp: pointer to a node-list data structure.
4789 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4790 * received as an ELS unsolicited event. A request to RRQ shall only
4791 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4792 * Nx_Port N_Port_ID of the target Exchange is the same as the
4793 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4794 * not accepted, an LS_RJT with reason code "Unable to perform
4795 * command request" and reason code explanation "Invalid Originator
4796 * S_ID" shall be returned. For now, we just unconditionally accept
4797 * RRQ from the target.
4800 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4801 struct lpfc_nodelist *ndlp)
4803 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4807 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4808 * @phba: pointer to lpfc hba data structure.
4809 * @pmb: pointer to the driver internal queue element for mailbox command.
4811 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4812 * mailbox command. This callback function is to actually send the Accept
4813 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4814 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4815 * mailbox command, constructs the RPS response with the link statistics
4816 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4817 * response to the RPS.
4819 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4820 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4821 * will be stored into the context1 field of the IOCB for the completion
4822 * callback function to the RPS Accept Response ELS IOCB command.
4826 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4830 struct RLS_RSP *rls_rsp;
4832 struct lpfc_iocbq *elsiocb;
4833 struct lpfc_nodelist *ndlp;
4839 ndlp = (struct lpfc_nodelist *) pmb->context2;
4840 xri = (uint16_t) ((unsigned long)(pmb->context1));
4841 pmb->context1 = NULL;
4842 pmb->context2 = NULL;
4844 if (mb->mbxStatus) {
4845 mempool_free(pmb, phba->mbox_mem_pool);
4849 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4850 mempool_free(pmb, phba->mbox_mem_pool);
4851 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4852 lpfc_max_els_tries, ndlp,
4853 ndlp->nlp_DID, ELS_CMD_ACC);
4855 /* Decrement the ndlp reference count from previous mbox command */
4861 icmd = &elsiocb->iocb;
4862 icmd->ulpContext = xri;
4864 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4865 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4866 pcmd += sizeof(uint32_t); /* Skip past command */
4867 rls_rsp = (struct RLS_RSP *)pcmd;
4869 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4870 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4871 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4872 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4873 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4874 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4876 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4877 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4878 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4879 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4880 elsiocb->iotag, elsiocb->iocb.ulpContext,
4881 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4883 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4884 phba->fc_stat.elsXmitACC++;
4885 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4886 lpfc_els_free_iocb(phba, elsiocb);
4890 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4891 * @phba: pointer to lpfc hba data structure.
4892 * @pmb: pointer to the driver internal queue element for mailbox command.
4894 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4895 * mailbox command. This callback function is to actually send the Accept
4896 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4897 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4898 * mailbox command, constructs the RPS response with the link statistics
4899 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4900 * response to the RPS.
4902 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4903 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4904 * will be stored into the context1 field of the IOCB for the completion
4905 * callback function to the RPS Accept Response ELS IOCB command.
4909 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4915 struct lpfc_iocbq *elsiocb;
4916 struct lpfc_nodelist *ndlp;
4917 uint16_t xri, status;
4922 ndlp = (struct lpfc_nodelist *) pmb->context2;
4923 xri = (uint16_t) ((unsigned long)(pmb->context1));
4924 pmb->context1 = NULL;
4925 pmb->context2 = NULL;
4927 if (mb->mbxStatus) {
4928 mempool_free(pmb, phba->mbox_mem_pool);
4932 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
4933 mempool_free(pmb, phba->mbox_mem_pool);
4934 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4935 lpfc_max_els_tries, ndlp,
4936 ndlp->nlp_DID, ELS_CMD_ACC);
4938 /* Decrement the ndlp reference count from previous mbox command */
4944 icmd = &elsiocb->iocb;
4945 icmd->ulpContext = xri;
4947 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4948 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4949 pcmd += sizeof(uint32_t); /* Skip past command */
4950 rps_rsp = (RPS_RSP *)pcmd;
4952 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
4956 if (phba->pport->fc_flag & FC_FABRIC)
4960 rps_rsp->portStatus = cpu_to_be16(status);
4961 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4962 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4963 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4964 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4965 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4966 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4967 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
4968 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4969 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4970 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4971 elsiocb->iotag, elsiocb->iocb.ulpContext,
4972 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4974 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4975 phba->fc_stat.elsXmitACC++;
4976 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4977 lpfc_els_free_iocb(phba, elsiocb);
4982 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4983 * @vport: pointer to a host virtual N_Port data structure.
4984 * @cmdiocb: pointer to lpfc command iocb data structure.
4985 * @ndlp: pointer to a node-list data structure.
4987 * This routine processes Read Port Status (RPL) IOCB received as an
4988 * ELS unsolicited event. It first checks the remote port state. If the
4989 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4990 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
4991 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4992 * for reading the HBA link statistics. It is for the callback function,
4993 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
4994 * to actually sending out RPL Accept (ACC) response.
4997 * 0 - Successfully processed rls iocb (currently always return 0)
5000 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5001 struct lpfc_nodelist *ndlp)
5003 struct lpfc_hba *phba = vport->phba;
5005 struct lpfc_dmabuf *pcmd;
5008 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5009 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5010 /* reject the unsolicited RPS request and done with it */
5013 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5015 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5017 lpfc_read_lnk_stat(phba, mbox);
5019 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5020 mbox->context2 = lpfc_nlp_get(ndlp);
5021 mbox->vport = vport;
5022 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5023 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5024 != MBX_NOT_FINISHED)
5025 /* Mbox completion will send ELS Response */
5027 /* Decrement reference count used for the failed mbox
5031 mempool_free(mbox, phba->mbox_mem_pool);
5034 /* issue rejection response */
5035 stat.un.b.lsRjtRsvd0 = 0;
5036 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5037 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5038 stat.un.b.vendorUnique = 0;
5039 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5044 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5045 * @vport: pointer to a host virtual N_Port data structure.
5046 * @cmdiocb: pointer to lpfc command iocb data structure.
5047 * @ndlp: pointer to a node-list data structure.
5049 * This routine processes Read Timout Value (RTV) IOCB received as an
5050 * ELS unsolicited event. It first checks the remote port state. If the
5051 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5052 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5053 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5054 * Value (RTV) unsolicited IOCB event.
5056 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5057 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5058 * will be stored into the context1 field of the IOCB for the completion
5059 * callback function to the RPS Accept Response ELS IOCB command.
5062 * 0 - Successfully processed rtv iocb (currently always return 0)
5065 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5066 struct lpfc_nodelist *ndlp)
5068 struct lpfc_hba *phba = vport->phba;
5070 struct RTV_RSP *rtv_rsp;
5072 struct lpfc_iocbq *elsiocb;
5076 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5077 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5078 /* reject the unsolicited RPS request and done with it */
5081 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5082 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5083 lpfc_max_els_tries, ndlp,
5084 ndlp->nlp_DID, ELS_CMD_ACC);
5089 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5090 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5091 pcmd += sizeof(uint32_t); /* Skip past command */
5093 /* use the command's xri in the response */
5094 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5096 rtv_rsp = (struct RTV_RSP *)pcmd;
5098 /* populate RTV payload */
5099 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5100 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5101 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5102 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5103 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5105 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5106 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5107 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5108 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5109 "Data: x%x x%x x%x\n",
5110 elsiocb->iotag, elsiocb->iocb.ulpContext,
5111 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5113 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5114 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5115 phba->fc_stat.elsXmitACC++;
5116 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5117 lpfc_els_free_iocb(phba, elsiocb);
5121 /* issue rejection response */
5122 stat.un.b.lsRjtRsvd0 = 0;
5123 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5124 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5125 stat.un.b.vendorUnique = 0;
5126 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5130 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5131 * @vport: pointer to a host virtual N_Port data structure.
5132 * @cmdiocb: pointer to lpfc command iocb data structure.
5133 * @ndlp: pointer to a node-list data structure.
5135 * This routine processes Read Port Status (RPS) IOCB received as an
5136 * ELS unsolicited event. It first checks the remote port state. If the
5137 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5138 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5139 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5140 * for reading the HBA link statistics. It is for the callback function,
5141 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5142 * to actually sending out RPS Accept (ACC) response.
5145 * 0 - Successfully processed rps iocb (currently always return 0)
5148 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5149 struct lpfc_nodelist *ndlp)
5151 struct lpfc_hba *phba = vport->phba;
5155 struct lpfc_dmabuf *pcmd;
5159 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5160 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5161 /* reject the unsolicited RPS request and done with it */
5164 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5165 lp = (uint32_t *) pcmd->virt;
5166 flag = (be32_to_cpu(*lp++) & 0xf);
5170 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
5171 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
5172 sizeof(struct lpfc_name)) == 0))) {
5174 printk("Fix me....\n");
5176 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5178 lpfc_read_lnk_stat(phba, mbox);
5180 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5181 mbox->context2 = lpfc_nlp_get(ndlp);
5182 mbox->vport = vport;
5183 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
5184 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5185 != MBX_NOT_FINISHED)
5186 /* Mbox completion will send ELS Response */
5188 /* Decrement reference count used for the failed mbox
5192 mempool_free(mbox, phba->mbox_mem_pool);
5197 /* issue rejection response */
5198 stat.un.b.lsRjtRsvd0 = 0;
5199 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5200 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5201 stat.un.b.vendorUnique = 0;
5202 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5207 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5208 * @vport: pointer to a host virtual N_Port data structure.
5209 * @cmdsize: size of the ELS command.
5210 * @oldiocb: pointer to the original lpfc command iocb data structure.
5211 * @ndlp: pointer to a node-list data structure.
5213 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5214 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5216 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5217 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5218 * will be stored into the context1 field of the IOCB for the completion
5219 * callback function to the RPL Accept Response ELS command.
5222 * 0 - Successfully issued ACC RPL ELS command
5223 * 1 - Failed to issue ACC RPL ELS command
5226 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5227 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5229 struct lpfc_hba *phba = vport->phba;
5230 IOCB_t *icmd, *oldcmd;
5232 struct lpfc_iocbq *elsiocb;
5235 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5236 ndlp->nlp_DID, ELS_CMD_ACC);
5241 icmd = &elsiocb->iocb;
5242 oldcmd = &oldiocb->iocb;
5243 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5245 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5246 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5247 pcmd += sizeof(uint16_t);
5248 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5249 pcmd += sizeof(uint16_t);
5251 /* Setup the RPL ACC payload */
5252 rpl_rsp.listLen = be32_to_cpu(1);
5254 rpl_rsp.port_num_blk.portNum = 0;
5255 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5256 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
5257 sizeof(struct lpfc_name));
5258 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
5259 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5261 "0120 Xmit ELS RPL ACC response tag x%x "
5262 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5264 elsiocb->iotag, elsiocb->iocb.ulpContext,
5265 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5267 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5268 phba->fc_stat.elsXmitACC++;
5269 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5271 lpfc_els_free_iocb(phba, elsiocb);
5278 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5279 * @vport: pointer to a host virtual N_Port data structure.
5280 * @cmdiocb: pointer to lpfc command iocb data structure.
5281 * @ndlp: pointer to a node-list data structure.
5283 * This routine processes Read Port List (RPL) IOCB received as an ELS
5284 * unsolicited event. It first checks the remote port state. If the remote
5285 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5286 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5287 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5288 * to accept the RPL.
5291 * 0 - Successfully processed rpl iocb (currently always return 0)
5294 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5295 struct lpfc_nodelist *ndlp)
5297 struct lpfc_dmabuf *pcmd;
5304 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5305 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
5306 /* issue rejection response */
5307 stat.un.b.lsRjtRsvd0 = 0;
5308 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5309 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5310 stat.un.b.vendorUnique = 0;
5311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5313 /* rejected the unsolicited RPL request and done with it */
5317 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5318 lp = (uint32_t *) pcmd->virt;
5319 rpl = (RPL *) (lp + 1);
5320 maxsize = be32_to_cpu(rpl->maxsize);
5322 /* We support only one port */
5323 if ((rpl->index == 0) &&
5325 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5326 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
5328 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5330 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
5336 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5337 * @vport: pointer to a virtual N_Port data structure.
5338 * @cmdiocb: pointer to lpfc command iocb data structure.
5339 * @ndlp: pointer to a node-list data structure.
5341 * This routine processes Fibre Channel Address Resolution Protocol
5342 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5343 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5344 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5345 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5346 * remote PortName is compared against the FC PortName stored in the @vport
5347 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5348 * compared against the FC NodeName stored in the @vport data structure.
5349 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5350 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5351 * invoked to send out FARP Response to the remote node. Before sending the
5352 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5353 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5354 * routine is invoked to log into the remote port first.
5357 * 0 - Either the FARP Match Mode not supported or successfully processed
5360 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5361 struct lpfc_nodelist *ndlp)
5363 struct lpfc_dmabuf *pcmd;
5367 uint32_t cmd, cnt, did;
5369 icmd = &cmdiocb->iocb;
5370 did = icmd->un.elsreq64.remoteID;
5371 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5372 lp = (uint32_t *) pcmd->virt;
5376 /* FARP-REQ received from DID <did> */
5377 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5378 "0601 FARP-REQ received from DID x%x\n", did);
5379 /* We will only support match on WWPN or WWNN */
5380 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
5385 /* If this FARP command is searching for my portname */
5386 if (fp->Mflags & FARP_MATCH_PORT) {
5387 if (memcmp(&fp->RportName, &vport->fc_portname,
5388 sizeof(struct lpfc_name)) == 0)
5392 /* If this FARP command is searching for my nodename */
5393 if (fp->Mflags & FARP_MATCH_NODE) {
5394 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
5395 sizeof(struct lpfc_name)) == 0)
5400 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5401 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5402 /* Log back into the node before sending the FARP. */
5403 if (fp->Rflags & FARP_REQUEST_PLOGI) {
5404 ndlp->nlp_prev_state = ndlp->nlp_state;
5405 lpfc_nlp_set_state(vport, ndlp,
5406 NLP_STE_PLOGI_ISSUE);
5407 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5410 /* Send a FARP response to that node */
5411 if (fp->Rflags & FARP_REQUEST_FARPR)
5412 lpfc_issue_els_farpr(vport, did, 0);
5419 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5420 * @vport: pointer to a host virtual N_Port data structure.
5421 * @cmdiocb: pointer to lpfc command iocb data structure.
5422 * @ndlp: pointer to a node-list data structure.
5424 * This routine processes Fibre Channel Address Resolution Protocol
5425 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5426 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5427 * the FARP response request.
5430 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5433 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5434 struct lpfc_nodelist *ndlp)
5436 struct lpfc_dmabuf *pcmd;
5441 icmd = &cmdiocb->iocb;
5442 did = icmd->un.elsreq64.remoteID;
5443 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5444 lp = (uint32_t *) pcmd->virt;
5447 /* FARP-RSP received from DID <did> */
5448 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5449 "0600 FARP-RSP received from DID x%x\n", did);
5450 /* ACCEPT the Farp resp request */
5451 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5457 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5458 * @vport: pointer to a host virtual N_Port data structure.
5459 * @cmdiocb: pointer to lpfc command iocb data structure.
5460 * @fan_ndlp: pointer to a node-list data structure.
5462 * This routine processes a Fabric Address Notification (FAN) IOCB
5463 * command received as an ELS unsolicited event. The FAN ELS command will
5464 * only be processed on a physical port (i.e., the @vport represents the
5465 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5466 * compared against those in the phba data structure. If any of those is
5467 * different, the lpfc_initial_flogi() routine is invoked to initialize
5468 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5469 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5470 * is invoked to register login to the fabric.
5473 * 0 - Successfully processed fan iocb (currently always return 0).
5476 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5477 struct lpfc_nodelist *fan_ndlp)
5479 struct lpfc_hba *phba = vport->phba;
5483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5484 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5486 /* FAN received; Fan does not have a reply sequence */
5487 if ((vport == phba->pport) &&
5488 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
5489 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
5490 sizeof(struct lpfc_name))) ||
5491 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
5492 sizeof(struct lpfc_name)))) {
5493 /* This port has switched fabrics. FLOGI is required */
5494 lpfc_issue_init_vfi(vport);
5496 /* FAN verified - skip FLOGI */
5497 vport->fc_myDID = vport->fc_prevDID;
5498 if (phba->sli_rev < LPFC_SLI_REV4)
5499 lpfc_issue_fabric_reglogin(vport);
5501 lpfc_issue_reg_vfi(vport);
5508 * lpfc_els_timeout - Handler funciton to the els timer
5509 * @ptr: holder for the timer function associated data.
5511 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5512 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5513 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5514 * up the worker thread. It is for the worker thread to invoke the routine
5515 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5518 lpfc_els_timeout(unsigned long ptr)
5520 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5521 struct lpfc_hba *phba = vport->phba;
5522 uint32_t tmo_posted;
5523 unsigned long iflag;
5525 spin_lock_irqsave(&vport->work_port_lock, iflag);
5526 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5528 vport->work_port_events |= WORKER_ELS_TMO;
5529 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
5532 lpfc_worker_wake_up(phba);
5538 * lpfc_els_timeout_handler - Process an els timeout event
5539 * @vport: pointer to a virtual N_Port data structure.
5541 * This routine is the actual handler function that processes an ELS timeout
5542 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5543 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5544 * invoking the lpfc_sli_issue_abort_iotag() routine.
5547 lpfc_els_timeout_handler(struct lpfc_vport *vport)
5549 struct lpfc_hba *phba = vport->phba;
5550 struct lpfc_sli_ring *pring;
5551 struct lpfc_iocbq *tmp_iocb, *piocb;
5553 struct lpfc_dmabuf *pcmd;
5554 uint32_t els_command = 0;
5556 uint32_t remote_ID = 0xffffffff;
5557 LIST_HEAD(txcmplq_completions);
5558 LIST_HEAD(abort_list);
5561 timeout = (uint32_t)(phba->fc_ratov << 1);
5563 pring = &phba->sli.ring[LPFC_ELS_RING];
5565 spin_lock_irq(&phba->hbalock);
5566 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5567 spin_unlock_irq(&phba->hbalock);
5569 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
5572 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5573 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5574 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
5577 if (piocb->vport != vport)
5580 pcmd = (struct lpfc_dmabuf *) piocb->context2;
5582 els_command = *(uint32_t *) (pcmd->virt);
5584 if (els_command == ELS_CMD_FARP ||
5585 els_command == ELS_CMD_FARPR ||
5586 els_command == ELS_CMD_FDISC)
5589 if (piocb->drvrTimeout > 0) {
5590 if (piocb->drvrTimeout >= timeout)
5591 piocb->drvrTimeout -= timeout;
5593 piocb->drvrTimeout = 0;
5597 remote_ID = 0xffffffff;
5598 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
5599 remote_ID = cmd->un.elsreq64.remoteID;
5601 struct lpfc_nodelist *ndlp;
5602 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
5603 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5604 remote_ID = ndlp->nlp_DID;
5606 list_add_tail(&piocb->dlist, &abort_list);
5608 spin_lock_irq(&phba->hbalock);
5609 list_splice(&txcmplq_completions, &pring->txcmplq);
5610 spin_unlock_irq(&phba->hbalock);
5612 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5613 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5614 "0127 ELS timeout Data: x%x x%x x%x "
5615 "x%x\n", els_command,
5616 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5617 spin_lock_irq(&phba->hbalock);
5618 list_del_init(&piocb->dlist);
5619 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5620 spin_unlock_irq(&phba->hbalock);
5623 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5624 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
5628 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5629 * @vport: pointer to a host virtual N_Port data structure.
5631 * This routine is used to clean up all the outstanding ELS commands on a
5632 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5633 * routine. After that, it walks the ELS transmit queue to remove all the
5634 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5635 * the IOCBs with a non-NULL completion callback function, the callback
5636 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5637 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5638 * callback function, the IOCB will simply be released. Finally, it walks
5639 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5640 * completion queue IOCB that is associated with the @vport and is not
5641 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5642 * part of the discovery state machine) out to HBA by invoking the
5643 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5644 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5645 * the IOCBs are aborted when this function returns.
5648 lpfc_els_flush_cmd(struct lpfc_vport *vport)
5650 LIST_HEAD(completions);
5651 struct lpfc_hba *phba = vport->phba;
5652 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5653 struct lpfc_iocbq *tmp_iocb, *piocb;
5656 lpfc_fabric_abort_vport(vport);
5658 spin_lock_irq(&phba->hbalock);
5659 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5662 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5666 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5667 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5668 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5669 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5670 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5673 if (piocb->vport != vport)
5676 list_move_tail(&piocb->list, &completions);
5680 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5681 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5685 if (piocb->vport != vport)
5688 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5690 spin_unlock_irq(&phba->hbalock);
5692 /* Cancell all the IOCBs from the completions list */
5693 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5700 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5701 * @phba: pointer to lpfc hba data structure.
5703 * This routine is used to clean up all the outstanding ELS commands on a
5704 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5705 * routine. After that, it walks the ELS transmit queue to remove all the
5706 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5707 * the IOCBs with the completion callback function associated, the callback
5708 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5709 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5710 * callback function associated, the IOCB will simply be released. Finally,
5711 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5712 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5713 * management plane IOCBs that are not part of the discovery state machine)
5714 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5717 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5719 LIST_HEAD(completions);
5720 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5721 struct lpfc_iocbq *tmp_iocb, *piocb;
5724 lpfc_fabric_abort_hba(phba);
5725 spin_lock_irq(&phba->hbalock);
5726 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5728 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5730 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5731 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5732 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5733 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5734 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5736 list_move_tail(&piocb->list, &completions);
5739 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5740 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5742 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5744 spin_unlock_irq(&phba->hbalock);
5746 /* Cancel all the IOCBs from the completions list */
5747 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5754 * lpfc_send_els_failure_event - Posts an ELS command failure event
5755 * @phba: Pointer to hba context object.
5756 * @cmdiocbp: Pointer to command iocb which reported error.
5757 * @rspiocbp: Pointer to response iocb which reported error.
5759 * This function sends an event when there is an ELS command
5763 lpfc_send_els_failure_event(struct lpfc_hba *phba,
5764 struct lpfc_iocbq *cmdiocbp,
5765 struct lpfc_iocbq *rspiocbp)
5767 struct lpfc_vport *vport = cmdiocbp->vport;
5768 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5769 struct lpfc_lsrjt_event lsrjt_event;
5770 struct lpfc_fabric_event_header fabric_event;
5772 struct lpfc_nodelist *ndlp;
5775 ndlp = cmdiocbp->context1;
5776 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5779 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5780 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5781 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5782 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5783 sizeof(struct lpfc_name));
5784 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5785 sizeof(struct lpfc_name));
5786 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5787 cmdiocbp->context2)->virt);
5788 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
5789 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5790 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5791 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5792 fc_host_post_vendor_event(shost,
5793 fc_get_event_number(),
5794 sizeof(lsrjt_event),
5795 (char *)&lsrjt_event,
5799 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5800 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5801 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5802 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5803 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5805 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5806 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5807 sizeof(struct lpfc_name));
5808 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5809 sizeof(struct lpfc_name));
5810 fc_host_post_vendor_event(shost,
5811 fc_get_event_number(),
5812 sizeof(fabric_event),
5813 (char *)&fabric_event,
5821 * lpfc_send_els_event - Posts unsolicited els event
5822 * @vport: Pointer to vport object.
5823 * @ndlp: Pointer FC node object.
5824 * @cmd: ELS command code.
5826 * This function posts an event when there is an incoming
5827 * unsolicited ELS command.
5830 lpfc_send_els_event(struct lpfc_vport *vport,
5831 struct lpfc_nodelist *ndlp,
5834 struct lpfc_els_event_header *els_data = NULL;
5835 struct lpfc_logo_event *logo_data = NULL;
5836 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5838 if (*payload == ELS_CMD_LOGO) {
5839 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5841 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5842 "0148 Failed to allocate memory "
5843 "for LOGO event\n");
5846 els_data = &logo_data->header;
5848 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5851 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5852 "0149 Failed to allocate memory "
5857 els_data->event_type = FC_REG_ELS_EVENT;
5860 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
5863 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
5866 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5869 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5870 /* Copy the WWPN in the LOGO payload */
5871 memcpy(logo_data->logo_wwpn, &payload[2],
5872 sizeof(struct lpfc_name));
5878 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5879 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5880 if (*payload == ELS_CMD_LOGO) {
5881 fc_host_post_vendor_event(shost,
5882 fc_get_event_number(),
5883 sizeof(struct lpfc_logo_event),
5888 fc_host_post_vendor_event(shost,
5889 fc_get_event_number(),
5890 sizeof(struct lpfc_els_event_header),
5901 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
5902 * @phba: pointer to lpfc hba data structure.
5903 * @pring: pointer to a SLI ring.
5904 * @vport: pointer to a host virtual N_Port data structure.
5905 * @elsiocb: pointer to lpfc els command iocb data structure.
5907 * This routine is used for processing the IOCB associated with a unsolicited
5908 * event. It first determines whether there is an existing ndlp that matches
5909 * the DID from the unsolicited IOCB. If not, it will create a new one with
5910 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5911 * IOCB is then used to invoke the proper routine and to set up proper state
5912 * of the discovery state machine.
5915 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5916 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
5918 struct Scsi_Host *shost;
5919 struct lpfc_nodelist *ndlp;
5922 uint32_t cmd, did, newnode, rjt_err = 0;
5923 IOCB_t *icmd = &elsiocb->iocb;
5925 if (!vport || !(elsiocb->context2))
5929 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5931 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
5932 lpfc_post_buffer(phba, pring, 1);
5934 did = icmd->un.rcvels.remoteID;
5935 if (icmd->ulpStatus) {
5936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5937 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5938 icmd->ulpStatus, icmd->un.ulpWord[4], did);
5942 /* Check to see if link went down during discovery */
5943 if (lpfc_els_chk_latt(vport))
5946 /* Ignore traffic received during vport shutdown. */
5947 if (vport->load_flag & FC_UNLOADING)
5950 ndlp = lpfc_findnode_did(vport, did);
5952 /* Cannot find existing Fabric ndlp, so allocate a new one */
5953 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5957 lpfc_nlp_init(vport, ndlp, did);
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 (!NLP_CHK_NODE_ACT(ndlp)) {
5963 ndlp = lpfc_enable_node(vport, ndlp,
5964 NLP_STE_UNUSED_NODE);
5967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5969 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5970 ndlp->nlp_type |= NLP_FABRIC;
5971 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5972 /* This is similar to the new node path */
5973 ndlp = lpfc_nlp_get(ndlp);
5976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5980 phba->fc_stat.elsRcvFrame++;
5982 elsiocb->context1 = lpfc_nlp_get(ndlp);
5983 elsiocb->vport = vport;
5985 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5986 cmd &= ELS_CMD_MASK;
5988 /* ELS command <elsCmd> received from NPORT <did> */
5989 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5990 "0112 ELS command x%x received from NPORT x%x "
5991 "Data: x%x\n", cmd, did, vport->port_state);
5994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5995 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5996 did, vport->port_state, ndlp->nlp_flag);
5998 phba->fc_stat.elsRcvPLOGI++;
5999 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6001 lpfc_send_els_event(vport, ndlp, payload);
6002 if (vport->port_state < LPFC_DISC_AUTH) {
6003 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6004 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6005 rjt_err = LSRJT_UNABLE_TPC;
6008 /* We get here, and drop thru, if we are PT2PT with
6009 * another NPort and the other side has initiated
6010 * the PLOGI before responding to our FLOGI.
6014 shost = lpfc_shost_from_vport(vport);
6015 spin_lock_irq(shost->host_lock);
6016 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6017 spin_unlock_irq(shost->host_lock);
6019 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6025 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6026 did, vport->port_state, ndlp->nlp_flag);
6028 phba->fc_stat.elsRcvFLOGI++;
6029 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
6034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6035 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6036 did, vport->port_state, ndlp->nlp_flag);
6038 phba->fc_stat.elsRcvLOGO++;
6039 lpfc_send_els_event(vport, ndlp, payload);
6040 if (vport->port_state < LPFC_DISC_AUTH) {
6041 rjt_err = LSRJT_UNABLE_TPC;
6044 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
6047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6048 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6049 did, vport->port_state, ndlp->nlp_flag);
6051 phba->fc_stat.elsRcvPRLO++;
6052 lpfc_send_els_event(vport, ndlp, payload);
6053 if (vport->port_state < LPFC_DISC_AUTH) {
6054 rjt_err = LSRJT_UNABLE_TPC;
6057 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
6060 phba->fc_stat.elsRcvRSCN++;
6061 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
6066 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6067 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6068 did, vport->port_state, ndlp->nlp_flag);
6070 lpfc_send_els_event(vport, ndlp, payload);
6071 phba->fc_stat.elsRcvADISC++;
6072 if (vport->port_state < LPFC_DISC_AUTH) {
6073 rjt_err = LSRJT_UNABLE_TPC;
6076 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6080 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6081 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6082 did, vport->port_state, ndlp->nlp_flag);
6084 phba->fc_stat.elsRcvPDISC++;
6085 if (vport->port_state < LPFC_DISC_AUTH) {
6086 rjt_err = LSRJT_UNABLE_TPC;
6089 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6093 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6094 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6095 did, vport->port_state, ndlp->nlp_flag);
6097 phba->fc_stat.elsRcvFARPR++;
6098 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
6101 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6102 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6103 did, vport->port_state, ndlp->nlp_flag);
6105 phba->fc_stat.elsRcvFARP++;
6106 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
6109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6110 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6111 did, vport->port_state, ndlp->nlp_flag);
6113 phba->fc_stat.elsRcvFAN++;
6114 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
6117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6118 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6119 did, vport->port_state, ndlp->nlp_flag);
6121 phba->fc_stat.elsRcvPRLI++;
6122 if (vport->port_state < LPFC_DISC_AUTH) {
6123 rjt_err = LSRJT_UNABLE_TPC;
6126 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
6129 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6130 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6131 did, vport->port_state, ndlp->nlp_flag);
6133 phba->fc_stat.elsRcvLIRR++;
6134 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
6139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6140 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6141 did, vport->port_state, ndlp->nlp_flag);
6143 phba->fc_stat.elsRcvRLS++;
6144 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6149 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6150 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6151 did, vport->port_state, ndlp->nlp_flag);
6153 phba->fc_stat.elsRcvRPS++;
6154 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
6159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6160 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6161 did, vport->port_state, ndlp->nlp_flag);
6163 phba->fc_stat.elsRcvRPL++;
6164 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
6169 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6170 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6171 did, vport->port_state, ndlp->nlp_flag);
6173 phba->fc_stat.elsRcvRNID++;
6174 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
6179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6180 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6181 did, vport->port_state, ndlp->nlp_flag);
6182 phba->fc_stat.elsRcvRTV++;
6183 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6189 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6190 did, vport->port_state, ndlp->nlp_flag);
6192 phba->fc_stat.elsRcvRRQ++;
6193 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6198 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6199 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6200 did, vport->port_state, ndlp->nlp_flag);
6202 phba->fc_stat.elsRcvECHO++;
6203 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6208 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6209 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6210 cmd, did, vport->port_state);
6212 /* Unsupported ELS command, reject */
6213 rjt_err = LSRJT_CMD_UNSUPPORTED;
6215 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6216 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6217 "0115 Unknown ELS command x%x "
6218 "received from NPORT x%x\n", cmd, did);
6224 /* check if need to LS_RJT received ELS cmd */
6226 memset(&stat, 0, sizeof(stat));
6227 stat.un.b.lsRjtRsnCode = rjt_err;
6228 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
6229 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6233 lpfc_nlp_put(elsiocb->context1);
6234 elsiocb->context1 = NULL;
6238 if (vport && !(vport->load_flag & FC_UNLOADING))
6239 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6240 "0111 Dropping received ELS cmd "
6241 "Data: x%x x%x x%x\n",
6242 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
6243 phba->fc_stat.elsRcvDrop++;
6247 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6248 * @phba: pointer to lpfc hba data structure.
6249 * @vpi: host virtual N_Port identifier.
6251 * This routine finds a vport on a HBA (referred by @phba) through a
6252 * @vpi. The function walks the HBA's vport list and returns the address
6253 * of the vport with the matching @vpi.
6256 * NULL - No vport with the matching @vpi found
6257 * Otherwise - Address to the vport with the matching @vpi.
6260 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6262 struct lpfc_vport *vport;
6263 unsigned long flags;
6265 spin_lock_irqsave(&phba->hbalock, flags);
6266 list_for_each_entry(vport, &phba->port_list, listentry) {
6267 if (vport->vpi == vpi) {
6268 spin_unlock_irqrestore(&phba->hbalock, flags);
6272 spin_unlock_irqrestore(&phba->hbalock, flags);
6277 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6278 * @phba: pointer to lpfc hba data structure.
6279 * @pring: pointer to a SLI ring.
6280 * @elsiocb: pointer to lpfc els iocb data structure.
6282 * This routine is used to process an unsolicited event received from a SLI
6283 * (Service Level Interface) ring. The actual processing of the data buffer
6284 * associated with the unsolicited event is done by invoking the routine
6285 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6286 * SLI ring on which the unsolicited event was received.
6289 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6290 struct lpfc_iocbq *elsiocb)
6292 struct lpfc_vport *vport = phba->pport;
6293 IOCB_t *icmd = &elsiocb->iocb;
6295 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6296 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
6298 elsiocb->context1 = NULL;
6299 elsiocb->context2 = NULL;
6300 elsiocb->context3 = NULL;
6302 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6303 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6304 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6305 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
6306 phba->fc_stat.NoRcvBuf++;
6307 /* Not enough posted buffers; Try posting more buffers */
6308 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
6309 lpfc_post_buffer(phba, pring, 0);
6313 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6314 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6315 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6316 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6317 vport = phba->pport;
6319 vport = lpfc_find_vport_by_vpid(phba,
6320 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
6322 /* If there are no BDEs associated
6323 * with this IOCB, there is nothing to do.
6325 if (icmd->ulpBdeCount == 0)
6328 /* type of ELS cmd is first 32bit word
6331 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
6332 elsiocb->context2 = bdeBuf1;
6334 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6335 icmd->un.cont64[0].addrLow);
6336 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6340 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6342 * The different unsolicited event handlers would tell us
6343 * if they are done with "mp" by setting context2 to NULL.
6345 if (elsiocb->context2) {
6346 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6347 elsiocb->context2 = NULL;
6350 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6351 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
6352 icmd->ulpBdeCount == 2) {
6353 elsiocb->context2 = bdeBuf2;
6354 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6355 /* free mp if we are done with it */
6356 if (elsiocb->context2) {
6357 lpfc_in_buf_free(phba, elsiocb->context2);
6358 elsiocb->context2 = NULL;
6364 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6365 * @phba: pointer to lpfc hba data structure.
6366 * @vport: pointer to a virtual N_Port data structure.
6368 * This routine issues a Port Login (PLOGI) to the Name Server with
6369 * State Change Request (SCR) for a @vport. This routine will create an
6370 * ndlp for the Name Server associated to the @vport if such node does
6371 * not already exist. The PLOGI to Name Server is issued by invoking the
6372 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6373 * (FDMI) is configured to the @vport, a FDMI node will be created and
6374 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6377 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6379 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6381 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6383 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6385 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6386 lpfc_disc_start(vport);
6389 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6390 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6391 "0251 NameServer login: no memory\n");
6394 lpfc_nlp_init(vport, ndlp, NameServer_DID);
6395 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6396 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6398 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6399 lpfc_disc_start(vport);
6402 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6403 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6404 "0348 NameServer login: node freed\n");
6408 ndlp->nlp_type |= NLP_FABRIC;
6410 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6412 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6413 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6414 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6415 "0252 Cannot issue NameServer login\n");
6419 if (vport->cfg_fdmi_on) {
6420 /* If this is the first time, allocate an ndlp and initialize
6421 * it. Otherwise, make sure the node is enabled and then do the
6424 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6426 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6429 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6430 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6434 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6435 ndlp_fdmi = lpfc_enable_node(vport,
6440 lpfc_nlp_set_state(vport, ndlp_fdmi,
6441 NLP_STE_PLOGI_ISSUE);
6442 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
6448 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6449 * @phba: pointer to lpfc hba data structure.
6450 * @pmb: pointer to the driver internal queue element for mailbox command.
6452 * This routine is the completion callback function to register new vport
6453 * mailbox command. If the new vport mailbox command completes successfully,
6454 * the fabric registration login shall be performed on physical port (the
6455 * new vport created is actually a physical port, with VPI 0) or the port
6456 * login to Name Server for State Change Request (SCR) will be performed
6457 * on virtual port (real virtual port, with VPI greater than 0).
6460 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6462 struct lpfc_vport *vport = pmb->vport;
6463 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6464 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
6465 MAILBOX_t *mb = &pmb->u.mb;
6468 spin_lock_irq(shost->host_lock);
6469 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6470 spin_unlock_irq(shost->host_lock);
6472 if (mb->mbxStatus) {
6473 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6474 "0915 Register VPI failed : Status: x%x"
6475 " upd bit: x%x \n", mb->mbxStatus,
6476 mb->un.varRegVpi.upd);
6477 if (phba->sli_rev == LPFC_SLI_REV4 &&
6478 mb->un.varRegVpi.upd)
6479 goto mbox_err_exit ;
6481 switch (mb->mbxStatus) {
6482 case 0x11: /* unsupported feature */
6483 case 0x9603: /* max_vpi exceeded */
6484 case 0x9602: /* Link event since CLEAR_LA */
6485 /* giving up on vport registration */
6486 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6487 spin_lock_irq(shost->host_lock);
6488 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6489 spin_unlock_irq(shost->host_lock);
6490 lpfc_can_disctmo(vport);
6492 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6494 spin_lock_irq(shost->host_lock);
6495 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6496 spin_unlock_irq(shost->host_lock);
6497 lpfc_init_vpi(phba, pmb, vport->vpi);
6499 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6500 rc = lpfc_sli_issue_mbox(phba, pmb,
6502 if (rc == MBX_NOT_FINISHED) {
6503 lpfc_printf_vlog(vport,
6505 "2732 Failed to issue INIT_VPI"
6506 " mailbox command\n");
6513 /* Try to recover from this error */
6514 if (phba->sli_rev == LPFC_SLI_REV4)
6515 lpfc_sli4_unreg_all_rpis(vport);
6516 lpfc_mbx_unreg_vpi(vport);
6517 spin_lock_irq(shost->host_lock);
6518 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6519 spin_unlock_irq(shost->host_lock);
6520 if (vport->port_type == LPFC_PHYSICAL_PORT
6521 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
6522 lpfc_issue_init_vfi(vport);
6524 lpfc_initial_fdisc(vport);
6528 spin_lock_irq(shost->host_lock);
6529 vport->vpi_state |= LPFC_VPI_REGISTERED;
6530 spin_unlock_irq(shost->host_lock);
6531 if (vport == phba->pport) {
6532 if (phba->sli_rev < LPFC_SLI_REV4)
6533 lpfc_issue_fabric_reglogin(vport);
6536 * If the physical port is instantiated using
6537 * FDISC, do not start vport discovery.
6539 if (vport->port_state != LPFC_FDISC)
6540 lpfc_start_fdiscs(phba);
6541 lpfc_do_scr_ns_plogi(phba, vport);
6544 lpfc_do_scr_ns_plogi(phba, vport);
6547 /* Now, we decrement the ndlp reference count held for this
6552 mempool_free(pmb, phba->mbox_mem_pool);
6557 * lpfc_register_new_vport - Register a new vport with a HBA
6558 * @phba: pointer to lpfc hba data structure.
6559 * @vport: pointer to a host virtual N_Port data structure.
6560 * @ndlp: pointer to a node-list data structure.
6562 * This routine registers the @vport as a new virtual port with a HBA.
6563 * It is done through a registering vpi mailbox command.
6566 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6567 struct lpfc_nodelist *ndlp)
6569 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6572 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6574 lpfc_reg_vpi(vport, mbox);
6575 mbox->vport = vport;
6576 mbox->context2 = lpfc_nlp_get(ndlp);
6577 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
6578 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6579 == MBX_NOT_FINISHED) {
6580 /* mailbox command not success, decrement ndlp
6581 * reference count for this command
6584 mempool_free(mbox, phba->mbox_mem_pool);
6586 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6587 "0253 Register VPI: Can't send mbox\n");
6591 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6592 "0254 Register VPI: no memory\n");
6598 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6599 spin_lock_irq(shost->host_lock);
6600 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6601 spin_unlock_irq(shost->host_lock);
6606 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6607 * @phba: pointer to lpfc hba data structure.
6609 * This routine cancels the retry delay timers to all the vports.
6612 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
6614 struct lpfc_vport **vports;
6615 struct lpfc_nodelist *ndlp;
6616 uint32_t link_state;
6619 /* Treat this failure as linkdown for all vports */
6620 link_state = phba->link_state;
6621 lpfc_linkdown(phba);
6622 phba->link_state = link_state;
6624 vports = lpfc_create_vport_work_array(phba);
6627 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6628 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6630 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6631 lpfc_els_flush_cmd(vports[i]);
6633 lpfc_destroy_vport_work_array(phba, vports);
6638 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6639 * @phba: pointer to lpfc hba data structure.
6641 * This routine abort all pending discovery commands and
6642 * start a timer to retry FLOGI for the physical port
6646 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6648 struct lpfc_nodelist *ndlp;
6649 struct Scsi_Host *shost;
6651 /* Cancel the all vports retry delay retry timers */
6652 lpfc_cancel_all_vport_retry_delay_timer(phba);
6654 /* If fabric require FLOGI, then re-instantiate physical login */
6655 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6659 shost = lpfc_shost_from_vport(phba->pport);
6660 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6661 spin_lock_irq(shost->host_lock);
6662 ndlp->nlp_flag |= NLP_DELAY_TMO;
6663 spin_unlock_irq(shost->host_lock);
6664 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6665 phba->pport->port_state = LPFC_FLOGI;
6670 * lpfc_fabric_login_reqd - Check if FLOGI required.
6671 * @phba: pointer to lpfc hba data structure.
6672 * @cmdiocb: pointer to FDISC command iocb.
6673 * @rspiocb: pointer to FDISC response iocb.
6675 * This routine checks if a FLOGI is reguired for FDISC
6679 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6680 struct lpfc_iocbq *cmdiocb,
6681 struct lpfc_iocbq *rspiocb)
6684 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6685 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6692 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6693 * @phba: pointer to lpfc hba data structure.
6694 * @cmdiocb: pointer to lpfc command iocb data structure.
6695 * @rspiocb: pointer to lpfc response iocb data structure.
6697 * This routine is the completion callback function to a Fabric Discover
6698 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6699 * single threaded, each FDISC completion callback function will reset
6700 * the discovery timer for all vports such that the timers will not get
6701 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6702 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6703 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6704 * assigned to the vport has been changed with the completion of the FDISC
6705 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6706 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6707 * routine is invoked to register new vport with the HBA. Otherwise, the
6708 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6709 * Server for State Change Request (SCR).
6712 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6713 struct lpfc_iocbq *rspiocb)
6715 struct lpfc_vport *vport = cmdiocb->vport;
6716 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6717 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6718 struct lpfc_nodelist *np;
6719 struct lpfc_nodelist *next_np;
6720 IOCB_t *irsp = &rspiocb->iocb;
6721 struct lpfc_iocbq *piocb;
6723 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6724 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6725 irsp->ulpStatus, irsp->un.ulpWord[4],
6727 /* Since all FDISCs are being single threaded, we
6728 * must reset the discovery timer for ALL vports
6729 * waiting to send FDISC when one completes.
6731 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6732 lpfc_set_disctmo(piocb->vport);
6735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6736 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6737 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6739 if (irsp->ulpStatus) {
6741 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6742 lpfc_retry_pport_discovery(phba);
6746 /* Check for retry */
6747 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6750 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6751 "0126 FDISC failed. (%d/%d)\n",
6752 irsp->ulpStatus, irsp->un.ulpWord[4]);
6755 spin_lock_irq(shost->host_lock);
6756 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
6757 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
6758 vport->fc_flag |= FC_FABRIC;
6759 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
6760 vport->fc_flag |= FC_PUBLIC_LOOP;
6761 spin_unlock_irq(shost->host_lock);
6763 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6764 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6765 if ((vport->fc_prevDID != vport->fc_myDID) &&
6766 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6767 /* If our NportID changed, we need to ensure all
6768 * remaining NPORTs get unreg_login'ed so we can
6771 list_for_each_entry_safe(np, next_np,
6772 &vport->fc_nodes, nlp_listp) {
6773 if (!NLP_CHK_NODE_ACT(ndlp) ||
6774 (np->nlp_state != NLP_STE_NPR_NODE) ||
6775 !(np->nlp_flag & NLP_NPR_ADISC))
6777 spin_lock_irq(shost->host_lock);
6778 np->nlp_flag &= ~NLP_NPR_ADISC;
6779 spin_unlock_irq(shost->host_lock);
6780 lpfc_unreg_rpi(vport, np);
6782 lpfc_cleanup_pending_mbox(vport);
6784 if (phba->sli_rev == LPFC_SLI_REV4)
6785 lpfc_sli4_unreg_all_rpis(vport);
6787 lpfc_mbx_unreg_vpi(vport);
6788 spin_lock_irq(shost->host_lock);
6789 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6790 if (phba->sli_rev == LPFC_SLI_REV4)
6791 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6793 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
6794 spin_unlock_irq(shost->host_lock);
6795 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6796 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6798 * Driver needs to re-reg VPI in order for f/w
6799 * to update the MAC address.
6801 lpfc_register_new_vport(phba, vport, ndlp);
6805 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6806 lpfc_issue_init_vpi(vport);
6807 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
6808 lpfc_register_new_vport(phba, vport, ndlp);
6810 lpfc_do_scr_ns_plogi(phba, vport);
6813 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6814 /* Cancel discovery timer */
6815 lpfc_can_disctmo(vport);
6818 lpfc_els_free_iocb(phba, cmdiocb);
6822 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
6823 * @vport: pointer to a virtual N_Port data structure.
6824 * @ndlp: pointer to a node-list data structure.
6825 * @retry: number of retries to the command IOCB.
6827 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6828 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6829 * routine to issue the IOCB, which makes sure only one outstanding fabric
6830 * IOCB will be sent off HBA at any given time.
6832 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6833 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6834 * will be stored into the context1 field of the IOCB for the completion
6835 * callback function to the FDISC ELS command.
6838 * 0 - Successfully issued fdisc iocb command
6839 * 1 - Failed to issue fdisc iocb command
6842 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6845 struct lpfc_hba *phba = vport->phba;
6847 struct lpfc_iocbq *elsiocb;
6848 struct serv_parm *sp;
6851 int did = ndlp->nlp_DID;
6854 vport->port_state = LPFC_FDISC;
6855 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6856 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6859 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6860 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6861 "0255 Issue FDISC: no IOCB\n");
6865 icmd = &elsiocb->iocb;
6866 icmd->un.elsreq64.myID = 0;
6867 icmd->un.elsreq64.fl = 1;
6869 if (phba->sli_rev == LPFC_SLI_REV4) {
6870 /* FDISC needs to be 1 for WQE VPI */
6871 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6872 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6873 /* Set the ulpContext to the vpi */
6874 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6876 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6881 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6882 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6883 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6884 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6885 sp = (struct serv_parm *) pcmd;
6886 /* Setup CSPs accordingly for Fabric */
6887 sp->cmn.e_d_tov = 0;
6888 sp->cmn.w2.r_a_tov = 0;
6889 sp->cls1.classValid = 0;
6890 sp->cls2.seqDelivery = 1;
6891 sp->cls3.seqDelivery = 1;
6893 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6894 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6895 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6896 pcmd += sizeof(uint32_t); /* Port Name */
6897 memcpy(pcmd, &vport->fc_portname, 8);
6898 pcmd += sizeof(uint32_t); /* Node Name */
6899 pcmd += sizeof(uint32_t); /* Node Name */
6900 memcpy(pcmd, &vport->fc_nodename, 8);
6902 lpfc_set_disctmo(vport);
6904 phba->fc_stat.elsXmitFDISC++;
6905 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6907 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6908 "Issue FDISC: did:x%x",
6911 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6912 if (rc == IOCB_ERROR) {
6913 lpfc_els_free_iocb(phba, elsiocb);
6914 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6915 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6916 "0256 Issue FDISC: Cannot send IOCB\n");
6919 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6924 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
6925 * @phba: pointer to lpfc hba data structure.
6926 * @cmdiocb: pointer to lpfc command iocb data structure.
6927 * @rspiocb: pointer to lpfc response iocb data structure.
6929 * This routine is the completion callback function to the issuing of a LOGO
6930 * ELS command off a vport. It frees the command IOCB and then decrement the
6931 * reference count held on ndlp for this completion function, indicating that
6932 * the reference to the ndlp is no long needed. Note that the
6933 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6934 * callback function and an additional explicit ndlp reference decrementation
6935 * will trigger the actual release of the ndlp.
6938 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6939 struct lpfc_iocbq *rspiocb)
6941 struct lpfc_vport *vport = cmdiocb->vport;
6943 struct lpfc_nodelist *ndlp;
6944 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
6946 irsp = &rspiocb->iocb;
6947 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6948 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6949 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
6951 lpfc_els_free_iocb(phba, cmdiocb);
6952 vport->unreg_vpi_cmpl = VPORT_ERROR;
6954 /* Trigger the release of the ndlp after logo */
6959 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
6960 * @vport: pointer to a virtual N_Port data structure.
6961 * @ndlp: pointer to a node-list data structure.
6963 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6965 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6966 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6967 * will be stored into the context1 field of the IOCB for the completion
6968 * callback function to the LOGO ELS command.
6971 * 0 - Successfully issued logo off the @vport
6972 * 1 - Failed to issue logo off the @vport
6975 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6977 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6978 struct lpfc_hba *phba = vport->phba;
6980 struct lpfc_iocbq *elsiocb;
6984 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6985 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6990 icmd = &elsiocb->iocb;
6991 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6992 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6993 pcmd += sizeof(uint32_t);
6995 /* Fill in LOGO payload */
6996 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6997 pcmd += sizeof(uint32_t);
6998 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7000 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7001 "Issue LOGO npiv did:x%x flg:x%x",
7002 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7004 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7005 spin_lock_irq(shost->host_lock);
7006 ndlp->nlp_flag |= NLP_LOGO_SND;
7007 spin_unlock_irq(shost->host_lock);
7008 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7010 spin_lock_irq(shost->host_lock);
7011 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7012 spin_unlock_irq(shost->host_lock);
7013 lpfc_els_free_iocb(phba, elsiocb);
7020 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7021 * @ptr: holder for the timer function associated data.
7023 * This routine is invoked by the fabric iocb block timer after
7024 * timeout. It posts the fabric iocb block timeout event by setting the
7025 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7026 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7027 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7028 * posted event WORKER_FABRIC_BLOCK_TMO.
7031 lpfc_fabric_block_timeout(unsigned long ptr)
7033 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7034 unsigned long iflags;
7035 uint32_t tmo_posted;
7037 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7038 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7040 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7041 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7044 lpfc_worker_wake_up(phba);
7049 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7050 * @phba: pointer to lpfc hba data structure.
7052 * This routine issues one fabric iocb from the driver internal list to
7053 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7054 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7055 * remove one pending fabric iocb from the driver internal list and invokes
7056 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7059 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7061 struct lpfc_iocbq *iocb;
7062 unsigned long iflags;
7068 spin_lock_irqsave(&phba->hbalock, iflags);
7069 /* Post any pending iocb to the SLI layer */
7070 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7071 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7074 /* Increment fabric iocb count to hold the position */
7075 atomic_inc(&phba->fabric_iocb_count);
7077 spin_unlock_irqrestore(&phba->hbalock, iflags);
7079 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7080 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7081 iocb->iocb_flag |= LPFC_IO_FABRIC;
7083 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7084 "Fabric sched1: ste:x%x",
7085 iocb->vport->port_state, 0, 0);
7087 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7089 if (ret == IOCB_ERROR) {
7090 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7091 iocb->fabric_iocb_cmpl = NULL;
7092 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7094 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7095 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7096 iocb->iocb_cmpl(phba, iocb, iocb);
7098 atomic_dec(&phba->fabric_iocb_count);
7107 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7108 * @phba: pointer to lpfc hba data structure.
7110 * This routine unblocks the issuing fabric iocb command. The function
7111 * will clear the fabric iocb block bit and then invoke the routine
7112 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7113 * from the driver internal fabric iocb list.
7116 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7118 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7120 lpfc_resume_fabric_iocbs(phba);
7125 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7126 * @phba: pointer to lpfc hba data structure.
7128 * This routine blocks the issuing fabric iocb for a specified amount of
7129 * time (currently 100 ms). This is done by set the fabric iocb block bit
7130 * and set up a timeout timer for 100ms. When the block bit is set, no more
7131 * fabric iocb will be issued out of the HBA.
7134 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7138 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7139 /* Start a timer to unblock fabric iocbs after 100ms */
7141 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7147 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7148 * @phba: pointer to lpfc hba data structure.
7149 * @cmdiocb: pointer to lpfc command iocb data structure.
7150 * @rspiocb: pointer to lpfc response iocb data structure.
7152 * This routine is the callback function that is put to the fabric iocb's
7153 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7154 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7155 * function first restores and invokes the original iocb's callback function
7156 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7157 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7160 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7161 struct lpfc_iocbq *rspiocb)
7165 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7168 switch (rspiocb->iocb.ulpStatus) {
7169 case IOSTAT_NPORT_RJT:
7170 case IOSTAT_FABRIC_RJT:
7171 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7172 lpfc_block_fabric_iocbs(phba);
7176 case IOSTAT_NPORT_BSY:
7177 case IOSTAT_FABRIC_BSY:
7178 lpfc_block_fabric_iocbs(phba);
7182 stat.un.lsRjtError =
7183 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7184 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7185 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7186 lpfc_block_fabric_iocbs(phba);
7190 if (atomic_read(&phba->fabric_iocb_count) == 0)
7193 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7194 cmdiocb->fabric_iocb_cmpl = NULL;
7195 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7196 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7198 atomic_dec(&phba->fabric_iocb_count);
7199 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
7200 /* Post any pending iocbs to HBA */
7201 lpfc_resume_fabric_iocbs(phba);
7206 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7207 * @phba: pointer to lpfc hba data structure.
7208 * @iocb: pointer to lpfc command iocb data structure.
7210 * This routine is used as the top-level API for issuing a fabric iocb command
7211 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7212 * function makes sure that only one fabric bound iocb will be outstanding at
7213 * any given time. As such, this function will first check to see whether there
7214 * is already an outstanding fabric iocb on the wire. If so, it will put the
7215 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7216 * issued later. Otherwise, it will issue the iocb on the wire and update the
7217 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7219 * Note, this implementation has a potential sending out fabric IOCBs out of
7220 * order. The problem is caused by the construction of the "ready" boolen does
7221 * not include the condition that the internal fabric IOCB list is empty. As
7222 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7223 * ahead of the fabric IOCBs in the internal list.
7226 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7227 * IOCB_ERROR - failed to issue fabric iocb
7230 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7232 unsigned long iflags;
7236 if (atomic_read(&phba->fabric_iocb_count) > 1)
7239 spin_lock_irqsave(&phba->hbalock, iflags);
7240 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7241 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7244 /* Increment fabric iocb count to hold the position */
7245 atomic_inc(&phba->fabric_iocb_count);
7246 spin_unlock_irqrestore(&phba->hbalock, iflags);
7248 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7249 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7250 iocb->iocb_flag |= LPFC_IO_FABRIC;
7252 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7253 "Fabric sched2: ste:x%x",
7254 iocb->vport->port_state, 0, 0);
7256 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7258 if (ret == IOCB_ERROR) {
7259 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7260 iocb->fabric_iocb_cmpl = NULL;
7261 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7262 atomic_dec(&phba->fabric_iocb_count);
7265 spin_lock_irqsave(&phba->hbalock, iflags);
7266 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7267 spin_unlock_irqrestore(&phba->hbalock, iflags);
7274 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7275 * @vport: pointer to a virtual N_Port data structure.
7277 * This routine aborts all the IOCBs associated with a @vport from the
7278 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7279 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7280 * list, removes each IOCB associated with the @vport off the list, set the
7281 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7282 * associated with the IOCB.
7284 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
7286 LIST_HEAD(completions);
7287 struct lpfc_hba *phba = vport->phba;
7288 struct lpfc_iocbq *tmp_iocb, *piocb;
7290 spin_lock_irq(&phba->hbalock);
7291 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7294 if (piocb->vport != vport)
7297 list_move_tail(&piocb->list, &completions);
7299 spin_unlock_irq(&phba->hbalock);
7301 /* Cancel all the IOCBs from the completions list */
7302 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7307 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7308 * @ndlp: pointer to a node-list data structure.
7310 * This routine aborts all the IOCBs associated with an @ndlp from the
7311 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7312 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7313 * list, removes each IOCB associated with the @ndlp off the list, set the
7314 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7315 * associated with the IOCB.
7317 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7319 LIST_HEAD(completions);
7320 struct lpfc_hba *phba = ndlp->phba;
7321 struct lpfc_iocbq *tmp_iocb, *piocb;
7322 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7324 spin_lock_irq(&phba->hbalock);
7325 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7327 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7329 list_move_tail(&piocb->list, &completions);
7332 spin_unlock_irq(&phba->hbalock);
7334 /* Cancel all the IOCBs from the completions list */
7335 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7340 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7341 * @phba: pointer to lpfc hba data structure.
7343 * This routine aborts all the IOCBs currently on the driver internal
7344 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7345 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7346 * list, removes IOCBs off the list, set the status feild to
7347 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7350 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7352 LIST_HEAD(completions);
7354 spin_lock_irq(&phba->hbalock);
7355 list_splice_init(&phba->fabric_iocb_list, &completions);
7356 spin_unlock_irq(&phba->hbalock);
7358 /* Cancel all the IOCBs from the completions list */
7359 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7364 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7365 * @phba: pointer to lpfc hba data structure.
7366 * @axri: pointer to the els xri abort wcqe structure.
7368 * This routine is invoked by the worker thread to process a SLI4 slow-path
7372 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7373 struct sli4_wcqe_xri_aborted *axri)
7375 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7376 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7377 unsigned long iflag = 0;
7378 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7380 spin_lock_irqsave(&phba->hbalock, iflag);
7381 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7382 list_for_each_entry_safe(sglq_entry, sglq_next,
7383 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7384 if (sglq_entry->sli4_xritag == xri) {
7385 list_del(&sglq_entry->list);
7386 list_add_tail(&sglq_entry->list,
7387 &phba->sli4_hba.lpfc_sgl_list);
7388 sglq_entry->state = SGL_FREED;
7389 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7390 spin_unlock_irqrestore(&phba->hbalock, iflag);
7392 /* Check if TXQ queue needs to be serviced */
7394 lpfc_worker_wake_up(phba);
7398 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7399 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7400 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7401 spin_unlock_irqrestore(&phba->hbalock, iflag);
7404 sglq_entry->state = SGL_XRI_ABORTED;
7405 spin_unlock_irqrestore(&phba->hbalock, iflag);