1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 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>
36 #include "lpfc_sli4.h"
38 #include "lpfc_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_vport.h"
44 #include "lpfc_debugfs.h"
46 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
48 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
50 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
51 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp, uint8_t retry);
53 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
54 struct lpfc_iocbq *iocb);
56 static int lpfc_max_els_tries = 3;
59 * lpfc_els_chk_latt - Check host link attention event for a vport
60 * @vport: pointer to a host virtual N_Port data structure.
62 * This routine checks whether there is an outstanding host link
63 * attention event during the discovery process with the @vport. It is done
64 * by reading the HBA's Host Attention (HA) register. If there is any host
65 * link attention events during this @vport's discovery process, the @vport
66 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
67 * be issued if the link state is not already in host link cleared state,
68 * and a return code shall indicate whether the host link attention event
71 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
72 * state in LPFC_VPORT_READY, the request for checking host link attention
73 * event will be ignored and a return code shall indicate no host link
74 * attention event had happened.
77 * 0 - no host link attention event happened
78 * 1 - host link attention event happened
81 lpfc_els_chk_latt(struct lpfc_vport *vport)
83 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
84 struct lpfc_hba *phba = vport->phba;
87 if (vport->port_state >= LPFC_VPORT_READY ||
88 phba->link_state == LPFC_LINK_DOWN ||
89 phba->sli_rev > LPFC_SLI_REV3)
92 /* Read the HBA Host Attention Register */
93 if (lpfc_readl(phba->HAregaddr, &ha_copy))
96 if (!(ha_copy & HA_LATT))
99 /* Pending Link Event during Discovery */
100 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba->pport->port_state);
105 /* CLEAR_LA should re-enable link attention events and
106 * we should then immediately take a LATT event. The
107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
111 spin_lock_irq(shost->host_lock);
112 vport->fc_flag |= FC_ABORT_DISCOVERY;
113 spin_unlock_irq(shost->host_lock);
115 if (phba->link_state != LPFC_CLEAR_LA)
116 lpfc_issue_clear_la(phba, vport);
122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
150 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
151 uint16_t cmdSize, uint8_t retry,
152 struct lpfc_nodelist *ndlp, uint32_t did,
155 struct lpfc_hba *phba = vport->phba;
156 struct lpfc_iocbq *elsiocb;
157 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
158 struct ulp_bde64 *bpl;
162 if (!lpfc_is_link_up(phba))
165 /* Allocate buffer for command iocb */
166 elsiocb = lpfc_sli_get_iocbq(phba);
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
175 if ((did == Fabric_DID) &&
176 (phba->hba_flag & HBA_FIP_SUPPORT) &&
177 ((elscmd == ELS_CMD_FLOGI) ||
178 (elscmd == ELS_CMD_FDISC) ||
179 (elscmd == ELS_CMD_LOGO)))
182 elsiocb->iocb_flag |=
183 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
184 & LPFC_FIP_ELS_ID_MASK);
187 elsiocb->iocb_flag |=
188 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
192 elsiocb->iocb_flag |=
193 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
194 & LPFC_FIP_ELS_ID_MASK);
198 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
200 icmd = &elsiocb->iocb;
202 /* fill in BDEs for command */
203 /* Allocate buffer for command payload */
204 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
206 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
207 if (!pcmd || !pcmd->virt)
208 goto els_iocb_free_pcmb_exit;
210 INIT_LIST_HEAD(&pcmd->list);
212 /* Allocate buffer for response payload */
214 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
216 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
218 if (!prsp || !prsp->virt)
219 goto els_iocb_free_prsp_exit;
220 INIT_LIST_HEAD(&prsp->list);
224 /* Allocate buffer for Buffer ptr list */
225 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
227 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
229 if (!pbuflist || !pbuflist->virt)
230 goto els_iocb_free_pbuf_exit;
232 INIT_LIST_HEAD(&pbuflist->list);
235 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
236 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
237 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
240 icmd->un.elsreq64.remoteID = did; /* DID */
241 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
242 if (elscmd == ELS_CMD_FLOGI)
243 icmd->ulpTimeout = FF_DEF_RATOV * 2;
245 icmd->ulpTimeout = phba->fc_ratov * 2;
247 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
248 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
249 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
250 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
251 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
252 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
254 icmd->ulpBdeCount = 1;
256 icmd->ulpClass = CLASS3;
259 * If we have NPIV enabled, we want to send ELS traffic by VPI.
260 * For SLI4, since the driver controls VPIs we also want to include
261 * all ELS pt2pt protocol traffic as well.
263 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
264 ((phba->sli_rev == LPFC_SLI_REV4) &&
265 (vport->fc_flag & FC_PT2PT))) {
268 icmd->un.elsreq64.myID = vport->fc_myDID;
270 /* For ELS_REQUEST64_CR, use the VPI by default */
271 icmd->ulpContext = phba->vpi_ids[vport->vpi];
275 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
276 if (elscmd == ELS_CMD_ECHO)
277 icmd->ulpCt_l = 0; /* context = invalid RPI */
279 icmd->ulpCt_l = 1; /* context = VPI */
282 bpl = (struct ulp_bde64 *) pbuflist->virt;
283 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
284 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
285 bpl->tus.f.bdeSize = cmdSize;
286 bpl->tus.f.bdeFlags = 0;
287 bpl->tus.w = le32_to_cpu(bpl->tus.w);
291 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
292 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
293 bpl->tus.f.bdeSize = FCELSSIZE;
294 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
295 bpl->tus.w = le32_to_cpu(bpl->tus.w);
298 /* prevent preparing iocb with NULL ndlp reference */
299 elsiocb->context1 = lpfc_nlp_get(ndlp);
300 if (!elsiocb->context1)
301 goto els_iocb_free_pbuf_exit;
302 elsiocb->context2 = pcmd;
303 elsiocb->context3 = pbuflist;
304 elsiocb->retry = retry;
305 elsiocb->vport = vport;
306 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
309 list_add(&prsp->list, &pcmd->list);
312 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
313 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
314 "0116 Xmit ELS command x%x to remote "
315 "NPORT x%x I/O tag: x%x, port state:x%x"
317 elscmd, did, elsiocb->iotag,
321 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
323 "0117 Xmit ELS response x%x to remote "
324 "NPORT x%x I/O tag: x%x, size: x%x "
325 "port_state x%x fc_flag x%x\n",
326 elscmd, ndlp->nlp_DID, elsiocb->iotag,
327 cmdSize, vport->port_state,
332 els_iocb_free_pbuf_exit:
334 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
337 els_iocb_free_prsp_exit:
338 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
341 els_iocb_free_pcmb_exit:
343 lpfc_sli_release_iocbq(phba, elsiocb);
348 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
349 * @vport: pointer to a host virtual N_Port data structure.
351 * This routine issues a fabric registration login for a @vport. An
352 * active ndlp node with Fabric_DID must already exist for this @vport.
353 * The routine invokes two mailbox commands to carry out fabric registration
354 * login through the HBA firmware: the first mailbox command requests the
355 * HBA to perform link configuration for the @vport; and the second mailbox
356 * command requests the HBA to perform the actual fabric registration login
360 * 0 - successfully issued fabric registration login for @vport
361 * -ENXIO -- failed to issue fabric registration login for @vport
364 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
366 struct lpfc_hba *phba = vport->phba;
368 struct lpfc_dmabuf *mp;
369 struct lpfc_nodelist *ndlp;
370 struct serv_parm *sp;
374 sp = &phba->fc_fabparam;
375 ndlp = lpfc_findnode_did(vport, Fabric_DID);
376 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
381 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
387 vport->port_state = LPFC_FABRIC_CFG_LINK;
388 lpfc_config_link(phba, mbox);
389 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
392 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
393 if (rc == MBX_NOT_FINISHED) {
398 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
403 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
410 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
412 /* increment the reference count on ndlp to hold reference
413 * for the callback routine.
415 mbox->context2 = lpfc_nlp_get(ndlp);
417 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
418 if (rc == MBX_NOT_FINISHED) {
420 goto fail_issue_reg_login;
425 fail_issue_reg_login:
426 /* decrement the reference count on ndlp just incremented
427 * for the failed mbox command.
430 mp = (struct lpfc_dmabuf *) mbox->context1;
431 lpfc_mbuf_free(phba, mp->virt, mp->phys);
434 mempool_free(mbox, phba->mbox_mem_pool);
437 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
438 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
439 "0249 Cannot issue Register Fabric login: Err %d\n", err);
444 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
445 * @vport: pointer to a host virtual N_Port data structure.
447 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
448 * the @vport. This mailbox command is necessary for SLI4 port only.
451 * 0 - successfully issued REG_VFI for @vport
452 * A failure code otherwise.
455 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
457 struct lpfc_hba *phba = vport->phba;
459 struct lpfc_nodelist *ndlp;
460 struct lpfc_dmabuf *dmabuf;
463 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
464 if ((phba->sli_rev == LPFC_SLI_REV4) &&
465 !(phba->link_flag & LS_LOOPBACK_MODE) &&
466 !(vport->fc_flag & FC_PT2PT)) {
467 ndlp = lpfc_findnode_did(vport, Fabric_DID);
468 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
474 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
479 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
482 goto fail_free_dmabuf;
485 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
488 goto fail_free_coherent;
490 vport->port_state = LPFC_FABRIC_CFG_LINK;
491 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
492 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
494 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
495 mboxq->vport = vport;
496 mboxq->context1 = dmabuf;
497 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
498 if (rc == MBX_NOT_FINISHED) {
505 mempool_free(mboxq, phba->mbox_mem_pool);
507 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
511 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
512 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
513 "0289 Issue Register VFI failed: Err %d\n", rc);
518 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
519 * @vport: pointer to a host virtual N_Port data structure.
521 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
522 * the @vport. This mailbox command is necessary for SLI4 port only.
525 * 0 - successfully issued REG_VFI for @vport
526 * A failure code otherwise.
529 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
531 struct lpfc_hba *phba = vport->phba;
532 struct Scsi_Host *shost;
536 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
538 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
539 "2556 UNREG_VFI mbox allocation failed"
540 "HBA state x%x\n", phba->pport->port_state);
544 lpfc_unreg_vfi(mboxq, vport);
545 mboxq->vport = vport;
546 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
548 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
549 if (rc == MBX_NOT_FINISHED) {
550 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
551 "2557 UNREG_VFI issue mbox failed rc x%x "
553 rc, phba->pport->port_state);
554 mempool_free(mboxq, phba->mbox_mem_pool);
558 shost = lpfc_shost_from_vport(vport);
559 spin_lock_irq(shost->host_lock);
560 vport->fc_flag &= ~FC_VFI_REGISTERED;
561 spin_unlock_irq(shost->host_lock);
566 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
567 * @vport: pointer to a host virtual N_Port data structure.
568 * @sp: pointer to service parameter data structure.
570 * This routine is called from FLOGI/FDISC completion handler functions.
571 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
572 * node nodename is changed in the completion service parameter else return
573 * 0. This function also set flag in the vport data structure to delay
574 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
575 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
576 * node nodename is changed in the completion service parameter.
579 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
580 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
584 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
585 struct serv_parm *sp)
587 uint8_t fabric_param_changed = 0;
588 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
590 if ((vport->fc_prevDID != vport->fc_myDID) ||
591 memcmp(&vport->fabric_portname, &sp->portName,
592 sizeof(struct lpfc_name)) ||
593 memcmp(&vport->fabric_nodename, &sp->nodeName,
594 sizeof(struct lpfc_name)))
595 fabric_param_changed = 1;
598 * Word 1 Bit 31 in common service parameter is overloaded.
599 * Word 1 Bit 31 in FLOGI request is multiple NPort request
600 * Word 1 Bit 31 in FLOGI response is clean address bit
602 * If fabric parameter is changed and clean address bit is
603 * cleared delay nport discovery if
604 * - vport->fc_prevDID != 0 (not initial discovery) OR
605 * - lpfc_delay_discovery module parameter is set.
607 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
608 (vport->fc_prevDID || lpfc_delay_discovery)) {
609 spin_lock_irq(shost->host_lock);
610 vport->fc_flag |= FC_DISC_DELAYED;
611 spin_unlock_irq(shost->host_lock);
614 return fabric_param_changed;
619 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
620 * @vport: pointer to a host virtual N_Port data structure.
621 * @ndlp: pointer to a node-list data structure.
622 * @sp: pointer to service parameter data structure.
623 * @irsp: pointer to the IOCB within the lpfc response IOCB.
625 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
626 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
627 * port in a fabric topology. It properly sets up the parameters to the @ndlp
628 * from the IOCB response. It also check the newly assigned N_Port ID to the
629 * @vport against the previously assigned N_Port ID. If it is different from
630 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
631 * is invoked on all the remaining nodes with the @vport to unregister the
632 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
633 * is invoked to register login to the fabric.
636 * 0 - Success (currently, always return 0)
639 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
640 struct serv_parm *sp, IOCB_t *irsp)
642 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
643 struct lpfc_hba *phba = vport->phba;
644 struct lpfc_nodelist *np;
645 struct lpfc_nodelist *next_np;
646 uint8_t fabric_param_changed;
648 spin_lock_irq(shost->host_lock);
649 vport->fc_flag |= FC_FABRIC;
650 spin_unlock_irq(shost->host_lock);
652 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
653 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
654 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
656 phba->fc_edtovResol = sp->cmn.edtovResolution;
657 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
659 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
660 spin_lock_irq(shost->host_lock);
661 vport->fc_flag |= FC_PUBLIC_LOOP;
662 spin_unlock_irq(shost->host_lock);
665 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
666 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
667 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
668 ndlp->nlp_class_sup = 0;
669 if (sp->cls1.classValid)
670 ndlp->nlp_class_sup |= FC_COS_CLASS1;
671 if (sp->cls2.classValid)
672 ndlp->nlp_class_sup |= FC_COS_CLASS2;
673 if (sp->cls3.classValid)
674 ndlp->nlp_class_sup |= FC_COS_CLASS3;
675 if (sp->cls4.classValid)
676 ndlp->nlp_class_sup |= FC_COS_CLASS4;
677 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
678 sp->cmn.bbRcvSizeLsb;
680 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
681 memcpy(&vport->fabric_portname, &sp->portName,
682 sizeof(struct lpfc_name));
683 memcpy(&vport->fabric_nodename, &sp->nodeName,
684 sizeof(struct lpfc_name));
685 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
687 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
688 if (sp->cmn.response_multiple_NPort) {
689 lpfc_printf_vlog(vport, KERN_WARNING,
691 "1816 FLOGI NPIV supported, "
692 "response data 0x%x\n",
693 sp->cmn.response_multiple_NPort);
694 spin_lock_irq(&phba->hbalock);
695 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
696 spin_unlock_irq(&phba->hbalock);
698 /* Because we asked f/w for NPIV it still expects us
699 to call reg_vnpid atleast for the physcial host */
700 lpfc_printf_vlog(vport, KERN_WARNING,
702 "1817 Fabric does not support NPIV "
703 "- configuring single port mode.\n");
704 spin_lock_irq(&phba->hbalock);
705 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
706 spin_unlock_irq(&phba->hbalock);
711 * For FC we need to do some special processing because of the SLI
712 * Port's default settings of the Common Service Parameters.
714 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) {
715 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
716 if ((phba->sli_rev == LPFC_SLI_REV4) && fabric_param_changed)
717 lpfc_unregister_fcf_prep(phba);
719 /* This should just update the VFI CSPs*/
720 if (vport->fc_flag & FC_VFI_REGISTERED)
721 lpfc_issue_reg_vfi(vport);
724 if (fabric_param_changed &&
725 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
727 /* If our NportID changed, we need to ensure all
728 * remaining NPORTs get unreg_login'ed.
730 list_for_each_entry_safe(np, next_np,
731 &vport->fc_nodes, nlp_listp) {
732 if (!NLP_CHK_NODE_ACT(np))
734 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
735 !(np->nlp_flag & NLP_NPR_ADISC))
737 spin_lock_irq(shost->host_lock);
738 np->nlp_flag &= ~NLP_NPR_ADISC;
739 spin_unlock_irq(shost->host_lock);
740 lpfc_unreg_rpi(vport, np);
742 lpfc_cleanup_pending_mbox(vport);
744 if (phba->sli_rev == LPFC_SLI_REV4) {
745 lpfc_sli4_unreg_all_rpis(vport);
746 lpfc_mbx_unreg_vpi(vport);
747 spin_lock_irq(shost->host_lock);
748 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
749 spin_unlock_irq(shost->host_lock);
753 * For SLI3 and SLI4, the VPI needs to be reregistered in
754 * response to this fabric parameter change event.
756 spin_lock_irq(shost->host_lock);
757 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
758 spin_unlock_irq(shost->host_lock);
759 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
760 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
762 * Driver needs to re-reg VPI in order for f/w
763 * to update the MAC address.
765 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
766 lpfc_register_new_vport(phba, vport, ndlp);
770 if (phba->sli_rev < LPFC_SLI_REV4) {
771 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
772 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
773 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
774 lpfc_register_new_vport(phba, vport, ndlp);
776 lpfc_issue_fabric_reglogin(vport);
778 ndlp->nlp_type |= NLP_FABRIC;
779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
780 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
781 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
782 lpfc_start_fdiscs(phba);
783 lpfc_do_scr_ns_plogi(phba, vport);
784 } else if (vport->fc_flag & FC_VFI_REGISTERED)
785 lpfc_issue_init_vpi(vport);
787 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
788 "3135 Need register VFI: (x%x/%x)\n",
789 vport->fc_prevDID, vport->fc_myDID);
790 lpfc_issue_reg_vfi(vport);
797 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
798 * @vport: pointer to a host virtual N_Port data structure.
799 * @ndlp: pointer to a node-list data structure.
800 * @sp: pointer to service parameter data structure.
802 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
803 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
804 * in a point-to-point topology. First, the @vport's N_Port Name is compared
805 * with the received N_Port Name: if the @vport's N_Port Name is greater than
806 * the received N_Port Name lexicographically, this node shall assign local
807 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
808 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
809 * this node shall just wait for the remote node to issue PLOGI and assign
817 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
818 struct serv_parm *sp)
820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
821 struct lpfc_hba *phba = vport->phba;
825 spin_lock_irq(shost->host_lock);
826 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
827 spin_unlock_irq(shost->host_lock);
829 phba->fc_edtov = FF_DEF_EDTOV;
830 phba->fc_ratov = FF_DEF_RATOV;
831 rc = memcmp(&vport->fc_portname, &sp->portName,
832 sizeof(vport->fc_portname));
833 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
836 /* This side will initiate the PLOGI */
837 spin_lock_irq(shost->host_lock);
838 vport->fc_flag |= FC_PT2PT_PLOGI;
839 spin_unlock_irq(shost->host_lock);
842 * N_Port ID cannot be 0, set our to LocalID the other
843 * side will be RemoteID.
848 vport->fc_myDID = PT2PT_LocalID;
850 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
854 lpfc_config_link(phba, mbox);
856 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
858 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
859 if (rc == MBX_NOT_FINISHED) {
860 mempool_free(mbox, phba->mbox_mem_pool);
865 * For SLI4, the VFI/VPI are registered AFTER the
866 * Nport with the higher WWPN sends the PLOGI with
867 * an assigned NPortId.
871 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
872 lpfc_issue_reg_vfi(vport);
874 /* Decrement ndlp reference count indicating that ndlp can be
875 * safely released when other references to it are done.
879 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
882 * Cannot find existing Fabric ndlp, so allocate a
885 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
888 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
889 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
890 ndlp = lpfc_enable_node(vport, ndlp,
891 NLP_STE_UNUSED_NODE);
896 memcpy(&ndlp->nlp_portname, &sp->portName,
897 sizeof(struct lpfc_name));
898 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
899 sizeof(struct lpfc_name));
900 /* Set state will put ndlp onto node list if not already done */
901 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
902 spin_lock_irq(shost->host_lock);
903 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
904 spin_unlock_irq(shost->host_lock);
906 /* This side will wait for the PLOGI, decrement ndlp reference
907 * count indicating that ndlp can be released when other
908 * references to it are done.
912 /* If we are pt2pt with another NPort, force NPIV off! */
913 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
915 spin_lock_irq(shost->host_lock);
916 vport->fc_flag |= FC_PT2PT;
917 spin_unlock_irq(shost->host_lock);
918 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
919 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
920 lpfc_unregister_fcf_prep(phba);
922 /* The FC_VFI_REGISTERED flag will get clear in the cmpl
923 * handler for unreg_vfi, but if we don't force the
924 * FC_VFI_REGISTERED flag then the reg_vfi mailbox could be
925 * built with the update bit set instead of just the vp bit to
926 * change the Nport ID. We need to have the vp set and the
927 * Upd cleared on topology changes.
929 spin_lock_irq(shost->host_lock);
930 vport->fc_flag &= ~FC_VFI_REGISTERED;
931 spin_unlock_irq(shost->host_lock);
932 phba->fc_topology_changed = 0;
933 lpfc_issue_reg_vfi(vport);
936 /* Start discovery - this should just do CLEAR_LA */
937 lpfc_disc_start(vport);
944 * lpfc_cmpl_els_flogi - Completion callback function for flogi
945 * @phba: pointer to lpfc hba data structure.
946 * @cmdiocb: pointer to lpfc command iocb data structure.
947 * @rspiocb: pointer to lpfc response iocb data structure.
949 * This routine is the top-level completion callback function for issuing
950 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
951 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
952 * retry has been made (either immediately or delayed with lpfc_els_retry()
953 * returning 1), the command IOCB will be released and function returned.
954 * If the retry attempt has been given up (possibly reach the maximum
955 * number of retries), one additional decrement of ndlp reference shall be
956 * invoked before going out after releasing the command IOCB. This will
957 * actually release the remote node (Note, lpfc_els_free_iocb() will also
958 * invoke one decrement of ndlp reference count). If no error reported in
959 * the IOCB status, the command Port ID field is used to determine whether
960 * this is a point-to-point topology or a fabric topology: if the Port ID
961 * field is assigned, it is a fabric topology; otherwise, it is a
962 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
963 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
964 * specific topology completion conditions.
967 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
968 struct lpfc_iocbq *rspiocb)
970 struct lpfc_vport *vport = cmdiocb->vport;
971 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
972 IOCB_t *irsp = &rspiocb->iocb;
973 struct lpfc_nodelist *ndlp = cmdiocb->context1;
974 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
975 struct serv_parm *sp;
979 /* Check to see if link went down during discovery */
980 if (lpfc_els_chk_latt(vport)) {
981 /* One additional decrement on node reference count to
982 * trigger the release of the node
988 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
989 "FLOGI cmpl: status:x%x/x%x state:x%x",
990 irsp->ulpStatus, irsp->un.ulpWord[4],
993 if (irsp->ulpStatus) {
995 * In case of FIP mode, perform roundrobin FCF failover
996 * due to new FCF discovery
998 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
999 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1000 if (phba->link_state < LPFC_LINK_UP)
1001 goto stop_rr_fcf_flogi;
1002 if ((phba->fcoe_cvl_eventtag_attn ==
1003 phba->fcoe_cvl_eventtag) &&
1004 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1005 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1007 goto stop_rr_fcf_flogi;
1009 phba->fcoe_cvl_eventtag_attn =
1010 phba->fcoe_cvl_eventtag;
1011 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1012 "2611 FLOGI failed on FCF (x%x), "
1013 "status:x%x/x%x, tmo:x%x, perform "
1014 "roundrobin FCF failover\n",
1015 phba->fcf.current_rec.fcf_indx,
1016 irsp->ulpStatus, irsp->un.ulpWord[4],
1018 lpfc_sli4_set_fcf_flogi_fail(phba,
1019 phba->fcf.current_rec.fcf_indx);
1020 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1021 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1028 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1029 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1031 irsp->ulpStatus, irsp->un.ulpWord[4],
1032 irsp->ulpTimeout, phba->hba_flag,
1033 phba->fcf.fcf_flag);
1035 /* Check for retry */
1036 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1040 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1041 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1042 irsp->ulpStatus, irsp->un.ulpWord[4],
1045 /* FLOGI failed, so there is no fabric */
1046 spin_lock_irq(shost->host_lock);
1047 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1048 spin_unlock_irq(shost->host_lock);
1050 /* If private loop, then allow max outstanding els to be
1051 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1052 * alpa map would take too long otherwise.
1054 if (phba->alpa_map[0] == 0)
1055 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1056 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1057 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1058 (vport->fc_prevDID != vport->fc_myDID) ||
1059 phba->fc_topology_changed)) {
1060 if (vport->fc_flag & FC_VFI_REGISTERED) {
1061 if (phba->fc_topology_changed) {
1062 lpfc_unregister_fcf_prep(phba);
1063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~FC_VFI_REGISTERED;
1065 spin_unlock_irq(shost->host_lock);
1066 phba->fc_topology_changed = 0;
1068 lpfc_sli4_unreg_all_rpis(vport);
1071 lpfc_issue_reg_vfi(vport);
1077 spin_lock_irq(shost->host_lock);
1078 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1079 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1080 spin_unlock_irq(shost->host_lock);
1083 * The FLogI succeeded. Sync the data for the CPU before
1086 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1089 sp = prsp->virt + sizeof(uint32_t);
1091 /* FLOGI completes successfully */
1092 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1093 "0101 FLOGI completes successfully, I/O tag:x%x, "
1094 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1095 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1096 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1097 vport->port_state, vport->fc_flag);
1099 if (vport->port_state == LPFC_FLOGI) {
1101 * If Common Service Parameters indicate Nport
1102 * we are point to point, if Fport we are Fabric.
1105 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1106 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1107 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1109 lpfc_printf_vlog(vport, KERN_ERR,
1111 "2831 FLOGI response with cleared Fabric "
1112 "bit fcf_index 0x%x "
1113 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1115 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1116 phba->fcf.current_rec.fcf_indx,
1117 phba->fcf.current_rec.switch_name[0],
1118 phba->fcf.current_rec.switch_name[1],
1119 phba->fcf.current_rec.switch_name[2],
1120 phba->fcf.current_rec.switch_name[3],
1121 phba->fcf.current_rec.switch_name[4],
1122 phba->fcf.current_rec.switch_name[5],
1123 phba->fcf.current_rec.switch_name[6],
1124 phba->fcf.current_rec.switch_name[7],
1125 phba->fcf.current_rec.fabric_name[0],
1126 phba->fcf.current_rec.fabric_name[1],
1127 phba->fcf.current_rec.fabric_name[2],
1128 phba->fcf.current_rec.fabric_name[3],
1129 phba->fcf.current_rec.fabric_name[4],
1130 phba->fcf.current_rec.fabric_name[5],
1131 phba->fcf.current_rec.fabric_name[6],
1132 phba->fcf.current_rec.fabric_name[7]);
1134 spin_lock_irq(&phba->hbalock);
1135 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1136 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1137 spin_unlock_irq(&phba->hbalock);
1141 /* Mark the FCF discovery process done */
1142 if (phba->hba_flag & HBA_FIP_SUPPORT)
1143 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1145 "2769 FLOGI to FCF (x%x) "
1146 "completed successfully\n",
1147 phba->fcf.current_rec.fcf_indx);
1148 spin_lock_irq(&phba->hbalock);
1149 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1150 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1151 spin_unlock_irq(&phba->hbalock);
1157 spin_lock_irq(&phba->hbalock);
1158 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1159 spin_unlock_irq(&phba->hbalock);
1162 if (!lpfc_error_lost_link(irsp)) {
1163 /* FLOGI failed, so just use loop map to make discovery list */
1164 lpfc_disc_list_loopmap(vport);
1166 /* Start discovery */
1167 lpfc_disc_start(vport);
1168 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1169 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1170 IOERR_SLI_ABORTED) &&
1171 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1172 IOERR_SLI_DOWN))) &&
1173 (phba->link_state != LPFC_CLEAR_LA)) {
1174 /* If FLOGI failed enable link interrupt. */
1175 lpfc_issue_clear_la(phba, vport);
1178 lpfc_els_free_iocb(phba, cmdiocb);
1182 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1183 * @vport: pointer to a host virtual N_Port data structure.
1184 * @ndlp: pointer to a node-list data structure.
1185 * @retry: number of retries to the command IOCB.
1187 * This routine issues a Fabric Login (FLOGI) Request ELS command
1188 * for a @vport. The initiator service parameters are put into the payload
1189 * of the FLOGI Request IOCB and the top-level callback function pointer
1190 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1191 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1192 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1194 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1195 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1196 * will be stored into the context1 field of the IOCB for the completion
1197 * callback function to the FLOGI ELS command.
1200 * 0 - successfully issued flogi iocb for @vport
1201 * 1 - failed to issue flogi iocb for @vport
1204 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1207 struct lpfc_hba *phba = vport->phba;
1208 struct serv_parm *sp;
1210 struct lpfc_iocbq *elsiocb;
1216 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1217 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1218 ndlp->nlp_DID, ELS_CMD_FLOGI);
1223 icmd = &elsiocb->iocb;
1224 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1226 /* For FLOGI request, remainder of payload is service parameters */
1227 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1228 pcmd += sizeof(uint32_t);
1229 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1230 sp = (struct serv_parm *) pcmd;
1232 /* Setup CSPs accordingly for Fabric */
1233 sp->cmn.e_d_tov = 0;
1234 sp->cmn.w2.r_a_tov = 0;
1235 sp->cmn.virtual_fabric_support = 0;
1236 sp->cls1.classValid = 0;
1237 if (sp->cmn.fcphLow < FC_PH3)
1238 sp->cmn.fcphLow = FC_PH3;
1239 if (sp->cmn.fcphHigh < FC_PH3)
1240 sp->cmn.fcphHigh = FC_PH3;
1242 if (phba->sli_rev == LPFC_SLI_REV4) {
1243 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1244 LPFC_SLI_INTF_IF_TYPE_0) {
1245 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1246 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1247 /* FLOGI needs to be 3 for WQE FCFI */
1248 /* Set the fcfi to the fcfi we registered with */
1249 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1251 /* Can't do SLI4 class2 without support sequence coalescing */
1252 sp->cls2.classValid = 0;
1253 sp->cls2.seqDelivery = 0;
1255 /* Historical, setting sequential-delivery bit for SLI3 */
1256 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1257 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1258 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1259 sp->cmn.request_multiple_Nport = 1;
1260 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1264 sp->cmn.request_multiple_Nport = 0;
1267 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1268 icmd->un.elsreq64.myID = 0;
1269 icmd->un.elsreq64.fl = 1;
1272 tmo = phba->fc_ratov;
1273 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1274 lpfc_set_disctmo(vport);
1275 phba->fc_ratov = tmo;
1277 phba->fc_stat.elsXmitFLOGI++;
1278 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1281 "Issue FLOGI: opt:x%x",
1282 phba->sli3_options, 0, 0);
1284 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1285 if (rc == IOCB_ERROR) {
1286 lpfc_els_free_iocb(phba, elsiocb);
1293 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1294 * @phba: pointer to lpfc hba data structure.
1296 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1297 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1298 * list and issues an abort IOCB commond on each outstanding IOCB that
1299 * contains a active Fabric_DID ndlp. Note that this function is to issue
1300 * the abort IOCB command on all the outstanding IOCBs, thus when this
1301 * function returns, it does not guarantee all the IOCBs are actually aborted.
1304 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1307 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1309 struct lpfc_sli_ring *pring;
1310 struct lpfc_iocbq *iocb, *next_iocb;
1311 struct lpfc_nodelist *ndlp;
1314 /* Abort outstanding I/O on NPort <nlp_DID> */
1315 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1316 "0201 Abort outstanding I/O on NPort x%x\n",
1319 pring = &phba->sli.ring[LPFC_ELS_RING];
1322 * Check the txcmplq for an iocb that matches the nport the driver is
1325 spin_lock_irq(&phba->hbalock);
1326 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1328 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1329 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1330 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1331 (ndlp->nlp_DID == Fabric_DID))
1332 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1335 spin_unlock_irq(&phba->hbalock);
1341 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1342 * @vport: pointer to a host virtual N_Port data structure.
1344 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1345 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1346 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1347 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1348 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1349 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1353 * 0 - failed to issue initial flogi for @vport
1354 * 1 - successfully issued initial flogi for @vport
1357 lpfc_initial_flogi(struct lpfc_vport *vport)
1359 struct lpfc_hba *phba = vport->phba;
1360 struct lpfc_nodelist *ndlp;
1362 vport->port_state = LPFC_FLOGI;
1363 lpfc_set_disctmo(vport);
1365 /* First look for the Fabric ndlp */
1366 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1368 /* Cannot find existing Fabric ndlp, so allocate a new one */
1369 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1372 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1373 /* Set the node type */
1374 ndlp->nlp_type |= NLP_FABRIC;
1375 /* Put ndlp onto node list */
1376 lpfc_enqueue_node(vport, ndlp);
1377 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1378 /* re-setup ndlp without removing from node list */
1379 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1384 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1385 /* This decrement of reference count to node shall kick off
1386 * the release of the node.
1395 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1396 * @vport: pointer to a host virtual N_Port data structure.
1398 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1399 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1400 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1401 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1402 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1403 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1407 * 0 - failed to issue initial fdisc for @vport
1408 * 1 - successfully issued initial fdisc for @vport
1411 lpfc_initial_fdisc(struct lpfc_vport *vport)
1413 struct lpfc_hba *phba = vport->phba;
1414 struct lpfc_nodelist *ndlp;
1416 /* First look for the Fabric ndlp */
1417 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1419 /* Cannot find existing Fabric ndlp, so allocate a new one */
1420 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1423 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1424 /* Put ndlp onto node list */
1425 lpfc_enqueue_node(vport, ndlp);
1426 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1427 /* re-setup ndlp without removing from node list */
1428 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1433 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1434 /* decrement node reference count to trigger the release of
1444 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1445 * @vport: pointer to a host virtual N_Port data structure.
1447 * This routine checks whether there are more remaining Port Logins
1448 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1449 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1450 * to issue ELS PLOGIs up to the configured discover threads with the
1451 * @vport (@vport->cfg_discovery_threads). The function also decrement
1452 * the @vport's num_disc_node by 1 if it is not already 0.
1455 lpfc_more_plogi(struct lpfc_vport *vport)
1457 if (vport->num_disc_nodes)
1458 vport->num_disc_nodes--;
1460 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1461 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1462 "0232 Continue discovery with %d PLOGIs to go "
1463 "Data: x%x x%x x%x\n",
1464 vport->num_disc_nodes, vport->fc_plogi_cnt,
1465 vport->fc_flag, vport->port_state);
1466 /* Check to see if there are more PLOGIs to be sent */
1467 if (vport->fc_flag & FC_NLP_MORE)
1468 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1469 lpfc_els_disc_plogi(vport);
1475 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1476 * @phba: pointer to lpfc hba data structure.
1477 * @prsp: pointer to response IOCB payload.
1478 * @ndlp: pointer to a node-list data structure.
1480 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1481 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1482 * The following cases are considered N_Port confirmed:
1483 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1484 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1485 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1486 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1487 * 1) if there is a node on vport list other than the @ndlp with the same
1488 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1489 * on that node to release the RPI associated with the node; 2) if there is
1490 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1491 * into, a new node shall be allocated (or activated). In either case, the
1492 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1493 * be released and the new_ndlp shall be put on to the vport node list and
1494 * its pointer returned as the confirmed node.
1496 * Note that before the @ndlp got "released", the keepDID from not-matching
1497 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1498 * of the @ndlp. This is because the release of @ndlp is actually to put it
1499 * into an inactive state on the vport node list and the vport node list
1500 * management algorithm does not allow two node with a same DID.
1503 * pointer to the PLOGI N_Port @ndlp
1505 static struct lpfc_nodelist *
1506 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1507 struct lpfc_nodelist *ndlp)
1509 struct lpfc_vport *vport = ndlp->vport;
1510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1511 struct lpfc_nodelist *new_ndlp;
1512 struct lpfc_rport_data *rdata;
1513 struct fc_rport *rport;
1514 struct serv_parm *sp;
1515 uint8_t name[sizeof(struct lpfc_name)];
1516 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1517 uint16_t keep_nlp_state;
1520 unsigned long *active_rrqs_xri_bitmap = NULL;
1522 /* Fabric nodes can have the same WWPN so we don't bother searching
1523 * by WWPN. Just return the ndlp that was given to us.
1525 if (ndlp->nlp_type & NLP_FABRIC)
1528 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1529 memset(name, 0, sizeof(struct lpfc_name));
1531 /* Now we find out if the NPort we are logging into, matches the WWPN
1532 * we have for that ndlp. If not, we have some work to do.
1534 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1536 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1538 if (phba->sli_rev == LPFC_SLI_REV4) {
1539 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1541 if (active_rrqs_xri_bitmap)
1542 memset(active_rrqs_xri_bitmap, 0,
1543 phba->cfg_rrq_xri_bitmap_sz);
1546 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1547 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1548 ndlp, ndlp->nlp_DID, new_ndlp);
1551 rc = memcmp(&ndlp->nlp_portname, name,
1552 sizeof(struct lpfc_name));
1554 if (active_rrqs_xri_bitmap)
1555 mempool_free(active_rrqs_xri_bitmap,
1556 phba->active_rrq_pool);
1559 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1561 if (active_rrqs_xri_bitmap)
1562 mempool_free(active_rrqs_xri_bitmap,
1563 phba->active_rrq_pool);
1566 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1567 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1568 rc = memcmp(&ndlp->nlp_portname, name,
1569 sizeof(struct lpfc_name));
1571 if (active_rrqs_xri_bitmap)
1572 mempool_free(active_rrqs_xri_bitmap,
1573 phba->active_rrq_pool);
1576 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1577 NLP_STE_UNUSED_NODE);
1579 if (active_rrqs_xri_bitmap)
1580 mempool_free(active_rrqs_xri_bitmap,
1581 phba->active_rrq_pool);
1584 keepDID = new_ndlp->nlp_DID;
1585 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1586 memcpy(active_rrqs_xri_bitmap,
1587 new_ndlp->active_rrqs_xri_bitmap,
1588 phba->cfg_rrq_xri_bitmap_sz);
1590 keepDID = new_ndlp->nlp_DID;
1591 if (phba->sli_rev == LPFC_SLI_REV4 &&
1592 active_rrqs_xri_bitmap)
1593 memcpy(active_rrqs_xri_bitmap,
1594 new_ndlp->active_rrqs_xri_bitmap,
1595 phba->cfg_rrq_xri_bitmap_sz);
1598 lpfc_unreg_rpi(vport, new_ndlp);
1599 new_ndlp->nlp_DID = ndlp->nlp_DID;
1600 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1601 if (phba->sli_rev == LPFC_SLI_REV4)
1602 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1603 ndlp->active_rrqs_xri_bitmap,
1604 phba->cfg_rrq_xri_bitmap_sz);
1606 spin_lock_irq(shost->host_lock);
1607 keep_nlp_flag = new_ndlp->nlp_flag;
1608 new_ndlp->nlp_flag = ndlp->nlp_flag;
1609 ndlp->nlp_flag = keep_nlp_flag;
1610 spin_unlock_irq(shost->host_lock);
1612 /* Set nlp_states accordingly */
1613 keep_nlp_state = new_ndlp->nlp_state;
1614 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1616 /* Move this back to NPR state */
1617 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1618 /* The new_ndlp is replacing ndlp totally, so we need
1619 * to put ndlp on UNUSED list and try to free it.
1621 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1622 "3179 PLOGI confirm NEW: %x %x\n",
1623 new_ndlp->nlp_DID, keepDID);
1625 /* Fix up the rport accordingly */
1626 rport = ndlp->rport;
1628 rdata = rport->dd_data;
1629 if (rdata->pnode == ndlp) {
1630 /* break the link before dropping the ref */
1633 rdata->pnode = lpfc_nlp_get(new_ndlp);
1634 new_ndlp->rport = rport;
1636 new_ndlp->nlp_type = ndlp->nlp_type;
1638 /* We shall actually free the ndlp with both nlp_DID and
1639 * nlp_portname fields equals 0 to avoid any ndlp on the
1640 * nodelist never to be used.
1642 if (ndlp->nlp_DID == 0) {
1643 spin_lock_irq(&phba->ndlp_lock);
1644 NLP_SET_FREE_REQ(ndlp);
1645 spin_unlock_irq(&phba->ndlp_lock);
1648 /* Two ndlps cannot have the same did on the nodelist */
1649 ndlp->nlp_DID = keepDID;
1650 if (phba->sli_rev == LPFC_SLI_REV4 &&
1651 active_rrqs_xri_bitmap)
1652 memcpy(ndlp->active_rrqs_xri_bitmap,
1653 active_rrqs_xri_bitmap,
1654 phba->cfg_rrq_xri_bitmap_sz);
1656 if (!NLP_CHK_NODE_ACT(ndlp))
1657 lpfc_drop_node(vport, ndlp);
1660 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1661 "3180 PLOGI confirm SWAP: %x %x\n",
1662 new_ndlp->nlp_DID, keepDID);
1664 lpfc_unreg_rpi(vport, ndlp);
1666 /* Two ndlps cannot have the same did */
1667 ndlp->nlp_DID = keepDID;
1668 if (phba->sli_rev == LPFC_SLI_REV4 &&
1669 active_rrqs_xri_bitmap)
1670 memcpy(ndlp->active_rrqs_xri_bitmap,
1671 active_rrqs_xri_bitmap,
1672 phba->cfg_rrq_xri_bitmap_sz);
1674 /* Since we are switching over to the new_ndlp,
1675 * reset the old ndlp state
1677 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1678 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1679 keep_nlp_state = NLP_STE_NPR_NODE;
1680 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1682 /* Fix up the rport accordingly */
1683 rport = ndlp->rport;
1685 rdata = rport->dd_data;
1686 put_node = rdata->pnode != NULL;
1687 put_rport = ndlp->rport != NULL;
1688 rdata->pnode = NULL;
1693 put_device(&rport->dev);
1696 if (phba->sli_rev == LPFC_SLI_REV4 &&
1697 active_rrqs_xri_bitmap)
1698 mempool_free(active_rrqs_xri_bitmap,
1699 phba->active_rrq_pool);
1704 * lpfc_end_rscn - Check and handle more rscn for a vport
1705 * @vport: pointer to a host virtual N_Port data structure.
1707 * This routine checks whether more Registration State Change
1708 * Notifications (RSCNs) came in while the discovery state machine was in
1709 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1710 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1711 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1712 * handling the RSCNs.
1715 lpfc_end_rscn(struct lpfc_vport *vport)
1717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1719 if (vport->fc_flag & FC_RSCN_MODE) {
1721 * Check to see if more RSCNs came in while we were
1722 * processing this one.
1724 if (vport->fc_rscn_id_cnt ||
1725 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1726 lpfc_els_handle_rscn(vport);
1728 spin_lock_irq(shost->host_lock);
1729 vport->fc_flag &= ~FC_RSCN_MODE;
1730 spin_unlock_irq(shost->host_lock);
1736 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1737 * @phba: pointer to lpfc hba data structure.
1738 * @cmdiocb: pointer to lpfc command iocb data structure.
1739 * @rspiocb: pointer to lpfc response iocb data structure.
1741 * This routine will call the clear rrq function to free the rrq and
1742 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1743 * exist then the clear_rrq is still called because the rrq needs to
1748 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1749 struct lpfc_iocbq *rspiocb)
1751 struct lpfc_vport *vport = cmdiocb->vport;
1753 struct lpfc_nodelist *ndlp;
1754 struct lpfc_node_rrq *rrq;
1756 /* we pass cmdiocb to state machine which needs rspiocb as well */
1757 rrq = cmdiocb->context_un.rrq;
1758 cmdiocb->context_un.rsp_iocb = rspiocb;
1760 irsp = &rspiocb->iocb;
1761 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1762 "RRQ cmpl: status:x%x/x%x did:x%x",
1763 irsp->ulpStatus, irsp->un.ulpWord[4],
1764 irsp->un.elsreq64.remoteID);
1766 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1767 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1768 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1769 "2882 RRQ completes to NPort x%x "
1770 "with no ndlp. Data: x%x x%x x%x\n",
1771 irsp->un.elsreq64.remoteID,
1772 irsp->ulpStatus, irsp->un.ulpWord[4],
1777 /* rrq completes to NPort <nlp_DID> */
1778 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1779 "2880 RRQ completes to NPort x%x "
1780 "Data: x%x x%x x%x x%x x%x\n",
1781 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1782 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1784 if (irsp->ulpStatus) {
1785 /* Check for retry */
1786 /* RRQ failed Don't print the vport to vport rjts */
1787 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1788 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1789 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1790 (phba)->pport->cfg_log_verbose & LOG_ELS)
1791 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1792 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1793 ndlp->nlp_DID, irsp->ulpStatus,
1794 irsp->un.ulpWord[4]);
1798 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1799 lpfc_els_free_iocb(phba, cmdiocb);
1803 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1804 * @phba: pointer to lpfc hba data structure.
1805 * @cmdiocb: pointer to lpfc command iocb data structure.
1806 * @rspiocb: pointer to lpfc response iocb data structure.
1808 * This routine is the completion callback function for issuing the Port
1809 * Login (PLOGI) command. For PLOGI completion, there must be an active
1810 * ndlp on the vport node list that matches the remote node ID from the
1811 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1812 * ignored and command IOCB released. The PLOGI response IOCB status is
1813 * checked for error conditons. If there is error status reported, PLOGI
1814 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1815 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1816 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1817 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1818 * there are additional N_Port nodes with the vport that need to perform
1819 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1823 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1824 struct lpfc_iocbq *rspiocb)
1826 struct lpfc_vport *vport = cmdiocb->vport;
1827 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1829 struct lpfc_nodelist *ndlp;
1830 struct lpfc_dmabuf *prsp;
1833 /* we pass cmdiocb to state machine which needs rspiocb as well */
1834 cmdiocb->context_un.rsp_iocb = rspiocb;
1836 irsp = &rspiocb->iocb;
1837 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1838 "PLOGI cmpl: status:x%x/x%x did:x%x",
1839 irsp->ulpStatus, irsp->un.ulpWord[4],
1840 irsp->un.elsreq64.remoteID);
1842 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1843 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1844 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1845 "0136 PLOGI completes to NPort x%x "
1846 "with no ndlp. Data: x%x x%x x%x\n",
1847 irsp->un.elsreq64.remoteID,
1848 irsp->ulpStatus, irsp->un.ulpWord[4],
1853 /* Since ndlp can be freed in the disc state machine, note if this node
1854 * is being used during discovery.
1856 spin_lock_irq(shost->host_lock);
1857 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1858 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1859 spin_unlock_irq(shost->host_lock);
1862 /* PLOGI completes to NPort <nlp_DID> */
1863 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1864 "0102 PLOGI completes to NPort x%x "
1865 "Data: x%x x%x x%x x%x x%x\n",
1866 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1867 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1868 /* Check to see if link went down during discovery */
1869 if (lpfc_els_chk_latt(vport)) {
1870 spin_lock_irq(shost->host_lock);
1871 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1872 spin_unlock_irq(shost->host_lock);
1876 if (irsp->ulpStatus) {
1877 /* Check for retry */
1878 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1879 /* ELS command is being retried */
1881 spin_lock_irq(shost->host_lock);
1882 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1883 spin_unlock_irq(shost->host_lock);
1887 /* PLOGI failed Don't print the vport to vport rjts */
1888 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1889 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1890 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1891 (phba)->pport->cfg_log_verbose & LOG_ELS)
1892 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1893 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1894 ndlp->nlp_DID, irsp->ulpStatus,
1895 irsp->un.ulpWord[4]);
1896 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1897 if (lpfc_error_lost_link(irsp))
1898 rc = NLP_STE_FREED_NODE;
1900 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1901 NLP_EVT_CMPL_PLOGI);
1903 /* Good status, call state machine */
1904 prsp = list_entry(((struct lpfc_dmabuf *)
1905 cmdiocb->context2)->list.next,
1906 struct lpfc_dmabuf, list);
1907 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1908 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1909 NLP_EVT_CMPL_PLOGI);
1912 if (disc && vport->num_disc_nodes) {
1913 /* Check to see if there are more PLOGIs to be sent */
1914 lpfc_more_plogi(vport);
1916 if (vport->num_disc_nodes == 0) {
1917 spin_lock_irq(shost->host_lock);
1918 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1919 spin_unlock_irq(shost->host_lock);
1921 lpfc_can_disctmo(vport);
1922 lpfc_end_rscn(vport);
1927 lpfc_els_free_iocb(phba, cmdiocb);
1932 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1933 * @vport: pointer to a host virtual N_Port data structure.
1934 * @did: destination port identifier.
1935 * @retry: number of retries to the command IOCB.
1937 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1938 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1939 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1940 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1941 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1943 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1944 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1945 * will be stored into the context1 field of the IOCB for the completion
1946 * callback function to the PLOGI ELS command.
1949 * 0 - Successfully issued a plogi for @vport
1950 * 1 - failed to issue a plogi for @vport
1953 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1955 struct lpfc_hba *phba = vport->phba;
1956 struct serv_parm *sp;
1957 struct lpfc_nodelist *ndlp;
1958 struct lpfc_iocbq *elsiocb;
1963 ndlp = lpfc_findnode_did(vport, did);
1964 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1967 /* If ndlp is not NULL, we will bump the reference count on it */
1968 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1969 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1974 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1976 /* For PLOGI request, remainder of payload is service parameters */
1977 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1978 pcmd += sizeof(uint32_t);
1979 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1980 sp = (struct serv_parm *) pcmd;
1983 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1984 * to device on remote loops work.
1986 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1987 sp->cmn.altBbCredit = 1;
1989 if (sp->cmn.fcphLow < FC_PH_4_3)
1990 sp->cmn.fcphLow = FC_PH_4_3;
1992 if (sp->cmn.fcphHigh < FC_PH3)
1993 sp->cmn.fcphHigh = FC_PH3;
1995 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1996 "Issue PLOGI: did:x%x",
1999 phba->fc_stat.elsXmitPLOGI++;
2000 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2001 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2003 if (ret == IOCB_ERROR) {
2004 lpfc_els_free_iocb(phba, elsiocb);
2011 * lpfc_cmpl_els_prli - Completion callback function for prli
2012 * @phba: pointer to lpfc hba data structure.
2013 * @cmdiocb: pointer to lpfc command iocb data structure.
2014 * @rspiocb: pointer to lpfc response iocb data structure.
2016 * This routine is the completion callback function for a Process Login
2017 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2018 * status. If there is error status reported, PRLI retry shall be attempted
2019 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2020 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2021 * ndlp to mark the PRLI completion.
2024 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2025 struct lpfc_iocbq *rspiocb)
2027 struct lpfc_vport *vport = cmdiocb->vport;
2028 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2030 struct lpfc_nodelist *ndlp;
2032 /* we pass cmdiocb to state machine which needs rspiocb as well */
2033 cmdiocb->context_un.rsp_iocb = rspiocb;
2035 irsp = &(rspiocb->iocb);
2036 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2037 spin_lock_irq(shost->host_lock);
2038 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2039 spin_unlock_irq(shost->host_lock);
2041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2042 "PRLI cmpl: status:x%x/x%x did:x%x",
2043 irsp->ulpStatus, irsp->un.ulpWord[4],
2045 /* PRLI completes to NPort <nlp_DID> */
2046 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2047 "0103 PRLI completes to NPort x%x "
2048 "Data: x%x x%x x%x x%x\n",
2049 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2050 irsp->ulpTimeout, vport->num_disc_nodes);
2052 vport->fc_prli_sent--;
2053 /* Check to see if link went down during discovery */
2054 if (lpfc_els_chk_latt(vport))
2057 if (irsp->ulpStatus) {
2058 /* Check for retry */
2059 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2060 /* ELS command is being retried */
2064 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2065 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2066 ndlp->nlp_DID, irsp->ulpStatus,
2067 irsp->un.ulpWord[4]);
2068 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2069 if (lpfc_error_lost_link(irsp))
2072 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2075 /* Good status, call state machine */
2076 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2079 lpfc_els_free_iocb(phba, cmdiocb);
2084 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2085 * @vport: pointer to a host virtual N_Port data structure.
2086 * @ndlp: pointer to a node-list data structure.
2087 * @retry: number of retries to the command IOCB.
2089 * This routine issues a Process Login (PRLI) ELS command for the
2090 * @vport. The PRLI service parameters are set up in the payload of the
2091 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2092 * is put to the IOCB completion callback func field before invoking the
2093 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2095 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2096 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2097 * will be stored into the context1 field of the IOCB for the completion
2098 * callback function to the PRLI ELS command.
2101 * 0 - successfully issued prli iocb command for @vport
2102 * 1 - failed to issue prli iocb command for @vport
2105 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2108 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2109 struct lpfc_hba *phba = vport->phba;
2111 struct lpfc_iocbq *elsiocb;
2115 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2116 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2117 ndlp->nlp_DID, ELS_CMD_PRLI);
2121 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2123 /* For PRLI request, remainder of payload is service parameters */
2124 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
2125 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
2126 pcmd += sizeof(uint32_t);
2128 /* For PRLI, remainder of payload is PRLI parameter page */
2129 npr = (PRLI *) pcmd;
2131 * If our firmware version is 3.20 or later,
2132 * set the following bits for FC-TAPE support.
2134 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2135 npr->ConfmComplAllowed = 1;
2137 npr->TaskRetryIdReq = 1;
2139 npr->estabImagePair = 1;
2140 npr->readXferRdyDis = 1;
2141 if (vport->cfg_first_burst_size)
2142 npr->writeXferRdyDis = 1;
2144 /* For FCP support */
2145 npr->prliType = PRLI_FCP_TYPE;
2146 npr->initiatorFunc = 1;
2148 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2149 "Issue PRLI: did:x%x",
2150 ndlp->nlp_DID, 0, 0);
2152 phba->fc_stat.elsXmitPRLI++;
2153 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2154 spin_lock_irq(shost->host_lock);
2155 ndlp->nlp_flag |= NLP_PRLI_SND;
2156 spin_unlock_irq(shost->host_lock);
2157 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2159 spin_lock_irq(shost->host_lock);
2160 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2161 spin_unlock_irq(shost->host_lock);
2162 lpfc_els_free_iocb(phba, elsiocb);
2165 vport->fc_prli_sent++;
2170 * lpfc_rscn_disc - Perform rscn discovery for a vport
2171 * @vport: pointer to a host virtual N_Port data structure.
2173 * This routine performs Registration State Change Notification (RSCN)
2174 * discovery for a @vport. If the @vport's node port recovery count is not
2175 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2176 * the nodes that need recovery. If none of the PLOGI were needed through
2177 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2178 * invoked to check and handle possible more RSCN came in during the period
2179 * of processing the current ones.
2182 lpfc_rscn_disc(struct lpfc_vport *vport)
2184 lpfc_can_disctmo(vport);
2186 /* RSCN discovery */
2187 /* go thru NPR nodes and issue ELS PLOGIs */
2188 if (vport->fc_npr_cnt)
2189 if (lpfc_els_disc_plogi(vport))
2192 lpfc_end_rscn(vport);
2196 * lpfc_adisc_done - Complete the adisc phase of discovery
2197 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2199 * This function is called when the final ADISC is completed during discovery.
2200 * This function handles clearing link attention or issuing reg_vpi depending
2201 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2203 * This function is called with no locks held.
2206 lpfc_adisc_done(struct lpfc_vport *vport)
2208 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2209 struct lpfc_hba *phba = vport->phba;
2212 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2213 * and continue discovery.
2215 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2216 !(vport->fc_flag & FC_RSCN_MODE) &&
2217 (phba->sli_rev < LPFC_SLI_REV4)) {
2218 /* The ADISCs are complete. Doesn't matter if they
2219 * succeeded or failed because the ADISC completion
2220 * routine guarantees to call the state machine and
2221 * the RPI is either unregistered (failed ADISC response)
2222 * or the RPI is still valid and the node is marked
2223 * mapped for a target. The exchanges should be in the
2224 * correct state. This code is specific to SLI3.
2226 lpfc_issue_clear_la(phba, vport);
2227 lpfc_issue_reg_vpi(phba, vport);
2231 * For SLI2, we need to set port_state to READY
2232 * and continue discovery.
2234 if (vport->port_state < LPFC_VPORT_READY) {
2235 /* If we get here, there is nothing to ADISC */
2236 lpfc_issue_clear_la(phba, vport);
2237 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2238 vport->num_disc_nodes = 0;
2239 /* go thru NPR list, issue ELS PLOGIs */
2240 if (vport->fc_npr_cnt)
2241 lpfc_els_disc_plogi(vport);
2242 if (!vport->num_disc_nodes) {
2243 spin_lock_irq(shost->host_lock);
2244 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2245 spin_unlock_irq(shost->host_lock);
2246 lpfc_can_disctmo(vport);
2247 lpfc_end_rscn(vport);
2250 vport->port_state = LPFC_VPORT_READY;
2252 lpfc_rscn_disc(vport);
2256 * lpfc_more_adisc - Issue more adisc as needed
2257 * @vport: pointer to a host virtual N_Port data structure.
2259 * This routine determines whether there are more ndlps on a @vport
2260 * node list need to have Address Discover (ADISC) issued. If so, it will
2261 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2262 * remaining nodes which need to have ADISC sent.
2265 lpfc_more_adisc(struct lpfc_vport *vport)
2267 if (vport->num_disc_nodes)
2268 vport->num_disc_nodes--;
2269 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2270 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2271 "0210 Continue discovery with %d ADISCs to go "
2272 "Data: x%x x%x x%x\n",
2273 vport->num_disc_nodes, vport->fc_adisc_cnt,
2274 vport->fc_flag, vport->port_state);
2275 /* Check to see if there are more ADISCs to be sent */
2276 if (vport->fc_flag & FC_NLP_MORE) {
2277 lpfc_set_disctmo(vport);
2278 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2279 lpfc_els_disc_adisc(vport);
2281 if (!vport->num_disc_nodes)
2282 lpfc_adisc_done(vport);
2287 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2288 * @phba: pointer to lpfc hba data structure.
2289 * @cmdiocb: pointer to lpfc command iocb data structure.
2290 * @rspiocb: pointer to lpfc response iocb data structure.
2292 * This routine is the completion function for issuing the Address Discover
2293 * (ADISC) command. It first checks to see whether link went down during
2294 * the discovery process. If so, the node will be marked as node port
2295 * recovery for issuing discover IOCB by the link attention handler and
2296 * exit. Otherwise, the response status is checked. If error was reported
2297 * in the response status, the ADISC command shall be retried by invoking
2298 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2299 * the response status, the state machine is invoked to set transition
2300 * with respect to NLP_EVT_CMPL_ADISC event.
2303 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2304 struct lpfc_iocbq *rspiocb)
2306 struct lpfc_vport *vport = cmdiocb->vport;
2307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2309 struct lpfc_nodelist *ndlp;
2312 /* we pass cmdiocb to state machine which needs rspiocb as well */
2313 cmdiocb->context_un.rsp_iocb = rspiocb;
2315 irsp = &(rspiocb->iocb);
2316 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2319 "ADISC cmpl: status:x%x/x%x did:x%x",
2320 irsp->ulpStatus, irsp->un.ulpWord[4],
2323 /* Since ndlp can be freed in the disc state machine, note if this node
2324 * is being used during discovery.
2326 spin_lock_irq(shost->host_lock);
2327 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2328 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2329 spin_unlock_irq(shost->host_lock);
2330 /* ADISC completes to NPort <nlp_DID> */
2331 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2332 "0104 ADISC completes to NPort x%x "
2333 "Data: x%x x%x x%x x%x x%x\n",
2334 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2335 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2336 /* Check to see if link went down during discovery */
2337 if (lpfc_els_chk_latt(vport)) {
2338 spin_lock_irq(shost->host_lock);
2339 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2340 spin_unlock_irq(shost->host_lock);
2344 if (irsp->ulpStatus) {
2345 /* Check for retry */
2346 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2347 /* ELS command is being retried */
2349 spin_lock_irq(shost->host_lock);
2350 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2351 spin_unlock_irq(shost->host_lock);
2352 lpfc_set_disctmo(vport);
2357 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2358 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2359 ndlp->nlp_DID, irsp->ulpStatus,
2360 irsp->un.ulpWord[4]);
2361 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2362 if (!lpfc_error_lost_link(irsp))
2363 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2364 NLP_EVT_CMPL_ADISC);
2366 /* Good status, call state machine */
2367 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2368 NLP_EVT_CMPL_ADISC);
2370 /* Check to see if there are more ADISCs to be sent */
2371 if (disc && vport->num_disc_nodes)
2372 lpfc_more_adisc(vport);
2374 lpfc_els_free_iocb(phba, cmdiocb);
2379 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2380 * @vport: pointer to a virtual N_Port data structure.
2381 * @ndlp: pointer to a node-list data structure.
2382 * @retry: number of retries to the command IOCB.
2384 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2385 * @vport. It prepares the payload of the ADISC ELS command, updates the
2386 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2387 * to issue the ADISC ELS command.
2389 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2390 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2391 * will be stored into the context1 field of the IOCB for the completion
2392 * callback function to the ADISC ELS command.
2395 * 0 - successfully issued adisc
2396 * 1 - failed to issue adisc
2399 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2403 struct lpfc_hba *phba = vport->phba;
2405 struct lpfc_iocbq *elsiocb;
2409 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2410 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2411 ndlp->nlp_DID, ELS_CMD_ADISC);
2415 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2417 /* For ADISC request, remainder of payload is service parameters */
2418 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2419 pcmd += sizeof(uint32_t);
2421 /* Fill in ADISC payload */
2422 ap = (ADISC *) pcmd;
2423 ap->hardAL_PA = phba->fc_pref_ALPA;
2424 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2425 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2426 ap->DID = be32_to_cpu(vport->fc_myDID);
2428 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2429 "Issue ADISC: did:x%x",
2430 ndlp->nlp_DID, 0, 0);
2432 phba->fc_stat.elsXmitADISC++;
2433 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2434 spin_lock_irq(shost->host_lock);
2435 ndlp->nlp_flag |= NLP_ADISC_SND;
2436 spin_unlock_irq(shost->host_lock);
2437 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2439 spin_lock_irq(shost->host_lock);
2440 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2441 spin_unlock_irq(shost->host_lock);
2442 lpfc_els_free_iocb(phba, elsiocb);
2449 * lpfc_cmpl_els_logo - Completion callback function for logo
2450 * @phba: pointer to lpfc hba data structure.
2451 * @cmdiocb: pointer to lpfc command iocb data structure.
2452 * @rspiocb: pointer to lpfc response iocb data structure.
2454 * This routine is the completion function for issuing the ELS Logout (LOGO)
2455 * command. If no error status was reported from the LOGO response, the
2456 * state machine of the associated ndlp shall be invoked for transition with
2457 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2458 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2461 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2462 struct lpfc_iocbq *rspiocb)
2464 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2465 struct lpfc_vport *vport = ndlp->vport;
2466 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2468 struct lpfcMboxq *mbox;
2469 unsigned long flags;
2470 uint32_t skip_recovery = 0;
2472 /* we pass cmdiocb to state machine which needs rspiocb as well */
2473 cmdiocb->context_un.rsp_iocb = rspiocb;
2475 irsp = &(rspiocb->iocb);
2476 spin_lock_irq(shost->host_lock);
2477 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2478 spin_unlock_irq(shost->host_lock);
2480 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2481 "LOGO cmpl: status:x%x/x%x did:x%x",
2482 irsp->ulpStatus, irsp->un.ulpWord[4],
2485 /* LOGO completes to NPort <nlp_DID> */
2486 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2487 "0105 LOGO completes to NPort x%x "
2488 "Data: x%x x%x x%x x%x\n",
2489 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2490 irsp->ulpTimeout, vport->num_disc_nodes);
2492 if (lpfc_els_chk_latt(vport)) {
2497 /* Check to see if link went down during discovery */
2498 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2499 /* NLP_EVT_DEVICE_RM should unregister the RPI
2500 * which should abort all outstanding IOs.
2502 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2508 if (irsp->ulpStatus) {
2509 /* Check for retry */
2510 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2511 /* ELS command is being retried */
2516 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2517 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2518 ndlp->nlp_DID, irsp->ulpStatus,
2519 irsp->un.ulpWord[4]);
2520 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2521 if (lpfc_error_lost_link(irsp)) {
2527 /* Call state machine. This will unregister the rpi if needed. */
2528 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2531 lpfc_els_free_iocb(phba, cmdiocb);
2532 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2533 if ((vport->fc_flag & FC_PT2PT) &&
2534 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2535 phba->pport->fc_myDID = 0;
2536 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2538 lpfc_config_link(phba, mbox);
2539 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2540 mbox->vport = vport;
2541 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2543 mempool_free(mbox, phba->mbox_mem_pool);
2550 * If the node is a target, the handling attempts to recover the port.
2551 * For any other port type, the rpi is unregistered as an implicit
2554 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2555 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2556 spin_lock_irqsave(shost->host_lock, flags);
2557 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2558 spin_unlock_irqrestore(shost->host_lock, flags);
2560 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2561 "3187 LOGO completes to NPort x%x: Start "
2562 "Recovery Data: x%x x%x x%x x%x\n",
2563 ndlp->nlp_DID, irsp->ulpStatus,
2564 irsp->un.ulpWord[4], irsp->ulpTimeout,
2565 vport->num_disc_nodes);
2566 lpfc_disc_start(vport);
2572 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2573 * @vport: pointer to a virtual N_Port data structure.
2574 * @ndlp: pointer to a node-list data structure.
2575 * @retry: number of retries to the command IOCB.
2577 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2578 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2579 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2580 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2582 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2583 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2584 * will be stored into the context1 field of the IOCB for the completion
2585 * callback function to the LOGO ELS command.
2588 * 0 - successfully issued logo
2589 * 1 - failed to issue logo
2592 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2595 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2596 struct lpfc_hba *phba = vport->phba;
2597 struct lpfc_iocbq *elsiocb;
2602 spin_lock_irq(shost->host_lock);
2603 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2604 spin_unlock_irq(shost->host_lock);
2607 spin_unlock_irq(shost->host_lock);
2609 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2610 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2611 ndlp->nlp_DID, ELS_CMD_LOGO);
2615 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2616 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2617 pcmd += sizeof(uint32_t);
2619 /* Fill in LOGO payload */
2620 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2621 pcmd += sizeof(uint32_t);
2622 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2624 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2625 "Issue LOGO: did:x%x",
2626 ndlp->nlp_DID, 0, 0);
2629 * If we are issuing a LOGO, we may try to recover the remote NPort
2630 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2631 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2632 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2633 * for that ELS cmd. To avoid this situation, lets get rid of the
2634 * RPI right now, before any ELS cmds are sent.
2636 spin_lock_irq(shost->host_lock);
2637 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2638 spin_unlock_irq(shost->host_lock);
2639 if (lpfc_unreg_rpi(vport, ndlp)) {
2640 lpfc_els_free_iocb(phba, elsiocb);
2644 phba->fc_stat.elsXmitLOGO++;
2645 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2646 spin_lock_irq(shost->host_lock);
2647 ndlp->nlp_flag |= NLP_LOGO_SND;
2648 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2649 spin_unlock_irq(shost->host_lock);
2650 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2652 if (rc == IOCB_ERROR) {
2653 spin_lock_irq(shost->host_lock);
2654 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2655 spin_unlock_irq(shost->host_lock);
2656 lpfc_els_free_iocb(phba, elsiocb);
2663 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2664 * @phba: pointer to lpfc hba data structure.
2665 * @cmdiocb: pointer to lpfc command iocb data structure.
2666 * @rspiocb: pointer to lpfc response iocb data structure.
2668 * This routine is a generic completion callback function for ELS commands.
2669 * Specifically, it is the callback function which does not need to perform
2670 * any command specific operations. It is currently used by the ELS command
2671 * issuing routines for the ELS State Change Request (SCR),
2672 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2673 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2674 * certain debug loggings, this callback function simply invokes the
2675 * lpfc_els_chk_latt() routine to check whether link went down during the
2676 * discovery process.
2679 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2680 struct lpfc_iocbq *rspiocb)
2682 struct lpfc_vport *vport = cmdiocb->vport;
2685 irsp = &rspiocb->iocb;
2687 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2688 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2689 irsp->ulpStatus, irsp->un.ulpWord[4],
2690 irsp->un.elsreq64.remoteID);
2691 /* ELS cmd tag <ulpIoTag> completes */
2692 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2693 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2694 irsp->ulpIoTag, irsp->ulpStatus,
2695 irsp->un.ulpWord[4], irsp->ulpTimeout);
2696 /* Check to see if link went down during discovery */
2697 lpfc_els_chk_latt(vport);
2698 lpfc_els_free_iocb(phba, cmdiocb);
2703 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2704 * @vport: pointer to a host virtual N_Port data structure.
2705 * @nportid: N_Port identifier to the remote node.
2706 * @retry: number of retries to the command IOCB.
2708 * This routine issues a State Change Request (SCR) to a fabric node
2709 * on a @vport. The remote node @nportid is passed into the function. It
2710 * first search the @vport node list to find the matching ndlp. If no such
2711 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2712 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2713 * routine is invoked to send the SCR IOCB.
2715 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2716 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2717 * will be stored into the context1 field of the IOCB for the completion
2718 * callback function to the SCR ELS command.
2721 * 0 - Successfully issued scr command
2722 * 1 - Failed to issue scr command
2725 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2727 struct lpfc_hba *phba = vport->phba;
2728 struct lpfc_iocbq *elsiocb;
2731 struct lpfc_nodelist *ndlp;
2733 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2735 ndlp = lpfc_findnode_did(vport, nportid);
2737 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2740 lpfc_nlp_init(vport, ndlp, nportid);
2741 lpfc_enqueue_node(vport, ndlp);
2742 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2743 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2748 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2749 ndlp->nlp_DID, ELS_CMD_SCR);
2752 /* This will trigger the release of the node just
2759 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2761 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2762 pcmd += sizeof(uint32_t);
2764 /* For SCR, remainder of payload is SCR parameter page */
2765 memset(pcmd, 0, sizeof(SCR));
2766 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2769 "Issue SCR: did:x%x",
2770 ndlp->nlp_DID, 0, 0);
2772 phba->fc_stat.elsXmitSCR++;
2773 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2774 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2776 /* The additional lpfc_nlp_put will cause the following
2777 * lpfc_els_free_iocb routine to trigger the rlease of
2781 lpfc_els_free_iocb(phba, elsiocb);
2784 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2785 * trigger the release of node.
2793 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2794 * @vport: pointer to a host virtual N_Port data structure.
2795 * @nportid: N_Port identifier to the remote node.
2796 * @retry: number of retries to the command IOCB.
2798 * This routine issues a Fibre Channel Address Resolution Response
2799 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2800 * is passed into the function. It first search the @vport node list to find
2801 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2802 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2803 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2805 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2806 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2807 * will be stored into the context1 field of the IOCB for the completion
2808 * callback function to the PARPR ELS command.
2811 * 0 - Successfully issued farpr command
2812 * 1 - Failed to issue farpr command
2815 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2817 struct lpfc_hba *phba = vport->phba;
2818 struct lpfc_iocbq *elsiocb;
2823 struct lpfc_nodelist *ondlp;
2824 struct lpfc_nodelist *ndlp;
2826 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2828 ndlp = lpfc_findnode_did(vport, nportid);
2830 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2833 lpfc_nlp_init(vport, ndlp, nportid);
2834 lpfc_enqueue_node(vport, ndlp);
2835 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2836 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2841 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2842 ndlp->nlp_DID, ELS_CMD_RNID);
2844 /* This will trigger the release of the node just
2851 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2853 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2854 pcmd += sizeof(uint32_t);
2856 /* Fill in FARPR payload */
2857 fp = (FARP *) (pcmd);
2858 memset(fp, 0, sizeof(FARP));
2859 lp = (uint32_t *) pcmd;
2860 *lp++ = be32_to_cpu(nportid);
2861 *lp++ = be32_to_cpu(vport->fc_myDID);
2863 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2865 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2866 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2867 ondlp = lpfc_findnode_did(vport, nportid);
2868 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2869 memcpy(&fp->OportName, &ondlp->nlp_portname,
2870 sizeof(struct lpfc_name));
2871 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2872 sizeof(struct lpfc_name));
2875 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2876 "Issue FARPR: did:x%x",
2877 ndlp->nlp_DID, 0, 0);
2879 phba->fc_stat.elsXmitFARPR++;
2880 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2881 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2883 /* The additional lpfc_nlp_put will cause the following
2884 * lpfc_els_free_iocb routine to trigger the release of
2888 lpfc_els_free_iocb(phba, elsiocb);
2891 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2892 * trigger the release of the node.
2899 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2900 * @vport: pointer to a host virtual N_Port data structure.
2901 * @nlp: pointer to a node-list data structure.
2903 * This routine cancels the timer with a delayed IOCB-command retry for
2904 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2905 * removes the ELS retry event if it presents. In addition, if the
2906 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2907 * commands are sent for the @vport's nodes that require issuing discovery
2911 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2913 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2914 struct lpfc_work_evt *evtp;
2916 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2918 spin_lock_irq(shost->host_lock);
2919 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2920 spin_unlock_irq(shost->host_lock);
2921 del_timer_sync(&nlp->nlp_delayfunc);
2922 nlp->nlp_last_elscmd = 0;
2923 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2924 list_del_init(&nlp->els_retry_evt.evt_listp);
2925 /* Decrement nlp reference count held for the delayed retry */
2926 evtp = &nlp->els_retry_evt;
2927 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2929 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2930 spin_lock_irq(shost->host_lock);
2931 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2932 spin_unlock_irq(shost->host_lock);
2933 if (vport->num_disc_nodes) {
2934 if (vport->port_state < LPFC_VPORT_READY) {
2935 /* Check if there are more ADISCs to be sent */
2936 lpfc_more_adisc(vport);
2938 /* Check if there are more PLOGIs to be sent */
2939 lpfc_more_plogi(vport);
2940 if (vport->num_disc_nodes == 0) {
2941 spin_lock_irq(shost->host_lock);
2942 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2943 spin_unlock_irq(shost->host_lock);
2944 lpfc_can_disctmo(vport);
2945 lpfc_end_rscn(vport);
2954 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2955 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2957 * This routine is invoked by the ndlp delayed-function timer to check
2958 * whether there is any pending ELS retry event(s) with the node. If not, it
2959 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2960 * adds the delayed events to the HBA work list and invokes the
2961 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2962 * event. Note that lpfc_nlp_get() is called before posting the event to
2963 * the work list to hold reference count of ndlp so that it guarantees the
2964 * reference to ndlp will still be available when the worker thread gets
2965 * to the event associated with the ndlp.
2968 lpfc_els_retry_delay(unsigned long ptr)
2970 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2971 struct lpfc_vport *vport = ndlp->vport;
2972 struct lpfc_hba *phba = vport->phba;
2973 unsigned long flags;
2974 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2976 spin_lock_irqsave(&phba->hbalock, flags);
2977 if (!list_empty(&evtp->evt_listp)) {
2978 spin_unlock_irqrestore(&phba->hbalock, flags);
2982 /* We need to hold the node by incrementing the reference
2983 * count until the queued work is done
2985 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2986 if (evtp->evt_arg1) {
2987 evtp->evt = LPFC_EVT_ELS_RETRY;
2988 list_add_tail(&evtp->evt_listp, &phba->work_list);
2989 lpfc_worker_wake_up(phba);
2991 spin_unlock_irqrestore(&phba->hbalock, flags);
2996 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2997 * @ndlp: pointer to a node-list data structure.
2999 * This routine is the worker-thread handler for processing the @ndlp delayed
3000 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3001 * the last ELS command from the associated ndlp and invokes the proper ELS
3002 * function according to the delayed ELS command to retry the command.
3005 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3007 struct lpfc_vport *vport = ndlp->vport;
3008 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3009 uint32_t cmd, retry;
3011 spin_lock_irq(shost->host_lock);
3012 cmd = ndlp->nlp_last_elscmd;
3013 ndlp->nlp_last_elscmd = 0;
3015 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3016 spin_unlock_irq(shost->host_lock);
3020 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3021 spin_unlock_irq(shost->host_lock);
3023 * If a discovery event readded nlp_delayfunc after timer
3024 * firing and before processing the timer, cancel the
3027 del_timer_sync(&ndlp->nlp_delayfunc);
3028 retry = ndlp->nlp_retry;
3029 ndlp->nlp_retry = 0;
3033 lpfc_issue_els_flogi(vport, ndlp, retry);
3036 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3037 ndlp->nlp_prev_state = ndlp->nlp_state;
3038 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3042 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3043 ndlp->nlp_prev_state = ndlp->nlp_state;
3044 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3048 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3049 ndlp->nlp_prev_state = ndlp->nlp_state;
3050 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3054 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3055 ndlp->nlp_prev_state = ndlp->nlp_state;
3056 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3060 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3061 lpfc_issue_els_fdisc(vport, ndlp, retry);
3068 * lpfc_els_retry - Make retry decision on an els command iocb
3069 * @phba: pointer to lpfc hba data structure.
3070 * @cmdiocb: pointer to lpfc command iocb data structure.
3071 * @rspiocb: pointer to lpfc response iocb data structure.
3073 * This routine makes a retry decision on an ELS command IOCB, which has
3074 * failed. The following ELS IOCBs use this function for retrying the command
3075 * when previously issued command responsed with error status: FLOGI, PLOGI,
3076 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3077 * returned error status, it makes the decision whether a retry shall be
3078 * issued for the command, and whether a retry shall be made immediately or
3079 * delayed. In the former case, the corresponding ELS command issuing-function
3080 * is called to retry the command. In the later case, the ELS command shall
3081 * be posted to the ndlp delayed event and delayed function timer set to the
3082 * ndlp for the delayed command issusing.
3085 * 0 - No retry of els command is made
3086 * 1 - Immediate or delayed retry of els command is made
3089 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3090 struct lpfc_iocbq *rspiocb)
3092 struct lpfc_vport *vport = cmdiocb->vport;
3093 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3094 IOCB_t *irsp = &rspiocb->iocb;
3095 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3096 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3099 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3105 /* Note: context2 may be 0 for internal driver abort
3106 * of delays ELS command.
3109 if (pcmd && pcmd->virt) {
3110 elscmd = (uint32_t *) (pcmd->virt);
3114 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3115 did = ndlp->nlp_DID;
3117 /* We should only hit this case for retrying PLOGI */
3118 did = irsp->un.elsreq64.remoteID;
3119 ndlp = lpfc_findnode_did(vport, did);
3120 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3121 && (cmd != ELS_CMD_PLOGI))
3125 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3126 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3127 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3129 switch (irsp->ulpStatus) {
3130 case IOSTAT_FCP_RSP_ERROR:
3132 case IOSTAT_REMOTE_STOP:
3133 if (phba->sli_rev == LPFC_SLI_REV4) {
3134 /* This IO was aborted by the target, we don't
3135 * know the rxid and because we did not send the
3136 * ABTS we cannot generate and RRQ.
3138 lpfc_set_rrq_active(phba, ndlp,
3139 cmdiocb->sli4_lxritag, 0, 0);
3142 case IOSTAT_LOCAL_REJECT:
3143 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3144 case IOERR_LOOP_OPEN_FAILURE:
3145 if (cmd == ELS_CMD_FLOGI) {
3146 if (PCI_DEVICE_ID_HORNET ==
3147 phba->pcidev->device) {
3148 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3149 phba->pport->fc_myDID = 0;
3150 phba->alpa_map[0] = 0;
3151 phba->alpa_map[1] = 0;
3154 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3159 case IOERR_ILLEGAL_COMMAND:
3160 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3161 "0124 Retry illegal cmd x%x "
3162 "retry:x%x delay:x%x\n",
3163 cmd, cmdiocb->retry, delay);
3165 /* All command's retry policy */
3167 if (cmdiocb->retry > 2)
3171 case IOERR_NO_RESOURCES:
3172 logerr = 1; /* HBA out of resources */
3174 if (cmdiocb->retry > 100)
3179 case IOERR_ILLEGAL_FRAME:
3184 case IOERR_SEQUENCE_TIMEOUT:
3185 case IOERR_INVALID_RPI:
3186 if (cmd == ELS_CMD_PLOGI &&
3187 did == NameServer_DID) {
3188 /* Continue forever if plogi to */
3189 /* the nameserver fails */
3198 case IOSTAT_NPORT_RJT:
3199 case IOSTAT_FABRIC_RJT:
3200 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3206 case IOSTAT_NPORT_BSY:
3207 case IOSTAT_FABRIC_BSY:
3208 logerr = 1; /* Fabric / Remote NPort out of resources */
3213 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3214 /* Added for Vendor specifc support
3215 * Just keep retrying for these Rsn / Exp codes
3217 switch (stat.un.b.lsRjtRsnCode) {
3218 case LSRJT_UNABLE_TPC:
3219 if (stat.un.b.lsRjtRsnCodeExp ==
3220 LSEXP_CMD_IN_PROGRESS) {
3221 if (cmd == ELS_CMD_PLOGI) {
3228 if (stat.un.b.lsRjtRsnCodeExp ==
3229 LSEXP_CANT_GIVE_DATA) {
3230 if (cmd == ELS_CMD_PLOGI) {
3237 if ((cmd == ELS_CMD_PLOGI) ||
3238 (cmd == ELS_CMD_PRLI)) {
3240 maxretry = lpfc_max_els_tries + 1;
3244 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3245 (cmd == ELS_CMD_FDISC) &&
3246 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3247 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3248 "0125 FDISC Failed (x%x). "
3249 "Fabric out of resources\n",
3250 stat.un.lsRjtError);
3251 lpfc_vport_set_state(vport,
3252 FC_VPORT_NO_FABRIC_RSCS);
3256 case LSRJT_LOGICAL_BSY:
3257 if ((cmd == ELS_CMD_PLOGI) ||
3258 (cmd == ELS_CMD_PRLI)) {
3261 } else if (cmd == ELS_CMD_FDISC) {
3262 /* FDISC retry policy */
3264 if (cmdiocb->retry >= 32)
3270 case LSRJT_LOGICAL_ERR:
3271 /* There are some cases where switches return this
3272 * error when they are not ready and should be returning
3273 * Logical Busy. We should delay every time.
3275 if (cmd == ELS_CMD_FDISC &&
3276 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3282 case LSRJT_PROTOCOL_ERR:
3283 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3284 (cmd == ELS_CMD_FDISC) &&
3285 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3286 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3289 "0122 FDISC Failed (x%x). "
3290 "Fabric Detected Bad WWN\n",
3291 stat.un.lsRjtError);
3292 lpfc_vport_set_state(vport,
3293 FC_VPORT_FABRIC_REJ_WWN);
3299 case IOSTAT_INTERMED_RSP:
3307 if (did == FDMI_DID)
3310 if ((cmd == ELS_CMD_FLOGI) &&
3311 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3312 !lpfc_error_lost_link(irsp)) {
3313 /* FLOGI retry policy */
3315 /* retry FLOGI forever */
3316 if (phba->link_flag != LS_LOOPBACK_MODE)
3321 if (cmdiocb->retry >= 100)
3323 else if (cmdiocb->retry >= 32)
3325 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3326 /* retry FDISCs every second up to devloss */
3328 maxretry = vport->cfg_devloss_tmo;
3333 if (maxretry && (cmdiocb->retry >= maxretry)) {
3334 phba->fc_stat.elsRetryExceeded++;
3338 if ((vport->load_flag & FC_UNLOADING) != 0)
3342 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3343 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3344 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3345 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3346 "2849 Stop retry ELS command "
3347 "x%x to remote NPORT x%x, "
3348 "Data: x%x x%x\n", cmd, did,
3349 cmdiocb->retry, delay);
3354 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3355 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3356 "0107 Retry ELS command x%x to remote "
3357 "NPORT x%x Data: x%x x%x\n",
3358 cmd, did, cmdiocb->retry, delay);
3360 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3361 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3362 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3363 IOERR_NO_RESOURCES))) {
3364 /* Don't reset timer for no resources */
3366 /* If discovery / RSCN timer is running, reset it */
3367 if (timer_pending(&vport->fc_disctmo) ||
3368 (vport->fc_flag & FC_RSCN_MODE))
3369 lpfc_set_disctmo(vport);
3372 phba->fc_stat.elsXmitRetry++;
3373 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3374 phba->fc_stat.elsDelayRetry++;
3375 ndlp->nlp_retry = cmdiocb->retry;
3377 /* delay is specified in milliseconds */
3378 mod_timer(&ndlp->nlp_delayfunc,
3379 jiffies + msecs_to_jiffies(delay));
3380 spin_lock_irq(shost->host_lock);
3381 ndlp->nlp_flag |= NLP_DELAY_TMO;
3382 spin_unlock_irq(shost->host_lock);
3384 ndlp->nlp_prev_state = ndlp->nlp_state;
3385 if (cmd == ELS_CMD_PRLI)
3386 lpfc_nlp_set_state(vport, ndlp,
3387 NLP_STE_PRLI_ISSUE);
3389 lpfc_nlp_set_state(vport, ndlp,
3391 ndlp->nlp_last_elscmd = cmd;
3397 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3400 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3403 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3404 ndlp->nlp_prev_state = ndlp->nlp_state;
3405 lpfc_nlp_set_state(vport, ndlp,
3406 NLP_STE_PLOGI_ISSUE);
3408 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3411 ndlp->nlp_prev_state = ndlp->nlp_state;
3412 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3413 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3416 ndlp->nlp_prev_state = ndlp->nlp_state;
3417 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3418 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3421 ndlp->nlp_prev_state = ndlp->nlp_state;
3422 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3423 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3427 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3429 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3430 "0137 No retry ELS command x%x to remote "
3431 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3432 cmd, did, irsp->ulpStatus,
3433 irsp->un.ulpWord[4]);
3436 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3437 "0108 No retry ELS command x%x to remote "
3438 "NPORT x%x Retried:%d Error:x%x/%x\n",
3439 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3440 irsp->un.ulpWord[4]);
3446 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3447 * @phba: pointer to lpfc hba data structure.
3448 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3450 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3451 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3452 * checks to see whether there is a lpfc DMA buffer associated with the
3453 * response of the command IOCB. If so, it will be released before releasing
3454 * the lpfc DMA buffer associated with the IOCB itself.
3457 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3460 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3462 struct lpfc_dmabuf *buf_ptr;
3464 /* Free the response before processing the command. */
3465 if (!list_empty(&buf_ptr1->list)) {
3466 list_remove_head(&buf_ptr1->list, buf_ptr,
3469 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3472 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3478 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3479 * @phba: pointer to lpfc hba data structure.
3480 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3482 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3483 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3487 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3490 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3492 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3498 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3499 * @phba: pointer to lpfc hba data structure.
3500 * @elsiocb: pointer to lpfc els command iocb data structure.
3502 * This routine frees a command IOCB and its associated resources. The
3503 * command IOCB data structure contains the reference to various associated
3504 * resources, these fields must be set to NULL if the associated reference
3506 * context1 - reference to ndlp
3507 * context2 - reference to cmd
3508 * context2->next - reference to rsp
3509 * context3 - reference to bpl
3511 * It first properly decrements the reference count held on ndlp for the
3512 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3513 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3514 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3515 * adds the DMA buffer the @phba data structure for the delayed release.
3516 * If reference to the Buffer Pointer List (BPL) is present, the
3517 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3518 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3519 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3522 * 0 - Success (currently, always return 0)
3525 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3527 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3528 struct lpfc_nodelist *ndlp;
3530 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3532 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3535 /* If the ndlp is not being used by another discovery
3538 if (!lpfc_nlp_not_used(ndlp)) {
3539 /* If ndlp is being used by another discovery
3540 * thread, just clear NLP_DEFER_RM
3542 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3547 elsiocb->context1 = NULL;
3549 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3550 if (elsiocb->context2) {
3551 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3552 /* Firmware could still be in progress of DMAing
3553 * payload, so don't free data buffer till after
3556 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3557 buf_ptr = elsiocb->context2;
3558 elsiocb->context2 = NULL;
3561 spin_lock_irq(&phba->hbalock);
3562 if (!list_empty(&buf_ptr->list)) {
3563 list_remove_head(&buf_ptr->list,
3564 buf_ptr1, struct lpfc_dmabuf,
3566 INIT_LIST_HEAD(&buf_ptr1->list);
3567 list_add_tail(&buf_ptr1->list,
3571 INIT_LIST_HEAD(&buf_ptr->list);
3572 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3574 spin_unlock_irq(&phba->hbalock);
3577 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3578 lpfc_els_free_data(phba, buf_ptr1);
3582 if (elsiocb->context3) {
3583 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3584 lpfc_els_free_bpl(phba, buf_ptr);
3586 lpfc_sli_release_iocbq(phba, elsiocb);
3591 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3592 * @phba: pointer to lpfc hba data structure.
3593 * @cmdiocb: pointer to lpfc command iocb data structure.
3594 * @rspiocb: pointer to lpfc response iocb data structure.
3596 * This routine is the completion callback function to the Logout (LOGO)
3597 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3598 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3599 * release the ndlp if it has the last reference remaining (reference count
3600 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3601 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3602 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3603 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3604 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3605 * IOCB data structure.
3608 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3609 struct lpfc_iocbq *rspiocb)
3611 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3612 struct lpfc_vport *vport = cmdiocb->vport;
3615 irsp = &rspiocb->iocb;
3616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3617 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3618 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3619 /* ACC to LOGO completes to NPort <nlp_DID> */
3620 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3621 "0109 ACC to LOGO completes to NPort x%x "
3622 "Data: x%x x%x x%x\n",
3623 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3626 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3627 /* NPort Recovery mode or node is just allocated */
3628 if (!lpfc_nlp_not_used(ndlp)) {
3629 /* If the ndlp is being used by another discovery
3630 * thread, just unregister the RPI.
3632 lpfc_unreg_rpi(vport, ndlp);
3634 /* Indicate the node has already released, should
3635 * not reference to it from within lpfc_els_free_iocb.
3637 cmdiocb->context1 = NULL;
3642 * The driver received a LOGO from the rport and has ACK'd it.
3643 * At this point, the driver is done so release the IOCB
3645 lpfc_els_free_iocb(phba, cmdiocb);
3649 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3650 * @phba: pointer to lpfc hba data structure.
3651 * @pmb: pointer to the driver internal queue element for mailbox command.
3653 * This routine is the completion callback function for unregister default
3654 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3655 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3656 * decrements the ndlp reference count held for this completion callback
3657 * function. After that, it invokes the lpfc_nlp_not_used() to check
3658 * whether there is only one reference left on the ndlp. If so, it will
3659 * perform one more decrement and trigger the release of the ndlp.
3662 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3664 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3665 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3667 pmb->context1 = NULL;
3668 pmb->context2 = NULL;
3670 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3672 mempool_free(pmb, phba->mbox_mem_pool);
3674 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3675 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3676 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3677 atomic_read(&ndlp->kref.refcount),
3678 ndlp->nlp_usg_map, ndlp);
3679 if (NLP_CHK_NODE_ACT(ndlp)) {
3681 /* This is the end of the default RPI cleanup logic for
3682 * this ndlp. If no other discovery threads are using
3683 * this ndlp, free all resources associated with it.
3685 lpfc_nlp_not_used(ndlp);
3687 lpfc_drop_node(ndlp->vport, ndlp);
3695 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3696 * @phba: pointer to lpfc hba data structure.
3697 * @cmdiocb: pointer to lpfc command iocb data structure.
3698 * @rspiocb: pointer to lpfc response iocb data structure.
3700 * This routine is the completion callback function for ELS Response IOCB
3701 * command. In normal case, this callback function just properly sets the
3702 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3703 * field in the command IOCB is not NULL, the referred mailbox command will
3704 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3705 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3706 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3707 * routine shall be invoked trying to release the ndlp if no other threads
3708 * are currently referring it.
3711 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3712 struct lpfc_iocbq *rspiocb)
3714 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3715 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3716 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3719 LPFC_MBOXQ_t *mbox = NULL;
3720 struct lpfc_dmabuf *mp = NULL;
3721 uint32_t ls_rjt = 0;
3723 irsp = &rspiocb->iocb;
3725 if (cmdiocb->context_un.mbox)
3726 mbox = cmdiocb->context_un.mbox;
3728 /* First determine if this is a LS_RJT cmpl. Note, this callback
3729 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3731 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3732 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3733 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3734 /* A LS_RJT associated with Default RPI cleanup has its own
3735 * separate code path.
3737 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3741 /* Check to see if link went down during discovery */
3742 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3744 mp = (struct lpfc_dmabuf *) mbox->context1;
3746 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3749 mempool_free(mbox, phba->mbox_mem_pool);
3751 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3752 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3753 if (lpfc_nlp_not_used(ndlp)) {
3755 /* Indicate the node has already released,
3756 * should not reference to it from within
3757 * the routine lpfc_els_free_iocb.
3759 cmdiocb->context1 = NULL;
3764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3765 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3766 irsp->ulpStatus, irsp->un.ulpWord[4],
3767 cmdiocb->iocb.un.elsreq64.remoteID);
3768 /* ELS response tag <ulpIoTag> completes */
3769 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3770 "0110 ELS response tag x%x completes "
3771 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3772 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3773 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3774 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3777 if ((rspiocb->iocb.ulpStatus == 0)
3778 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3779 lpfc_unreg_rpi(vport, ndlp);
3780 /* Increment reference count to ndlp to hold the
3781 * reference to ndlp for the callback function.
3783 mbox->context2 = lpfc_nlp_get(ndlp);
3784 mbox->vport = vport;
3785 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3786 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3787 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3790 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3791 ndlp->nlp_prev_state = ndlp->nlp_state;
3792 lpfc_nlp_set_state(vport, ndlp,
3793 NLP_STE_REG_LOGIN_ISSUE);
3795 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3796 != MBX_NOT_FINISHED)
3799 /* Decrement the ndlp reference count we
3800 * set for this failed mailbox command.
3804 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3805 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3806 "0138 ELS rsp: Cannot issue reg_login for x%x "
3807 "Data: x%x x%x x%x\n",
3808 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3811 if (lpfc_nlp_not_used(ndlp)) {
3813 /* Indicate node has already been released,
3814 * should not reference to it from within
3815 * the routine lpfc_els_free_iocb.
3817 cmdiocb->context1 = NULL;
3820 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3821 if (!lpfc_error_lost_link(irsp) &&
3822 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3823 if (lpfc_nlp_not_used(ndlp)) {
3825 /* Indicate node has already been
3826 * released, should not reference
3827 * to it from within the routine
3828 * lpfc_els_free_iocb.
3830 cmdiocb->context1 = NULL;
3834 mp = (struct lpfc_dmabuf *) mbox->context1;
3836 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3839 mempool_free(mbox, phba->mbox_mem_pool);
3842 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3843 spin_lock_irq(shost->host_lock);
3844 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3845 spin_unlock_irq(shost->host_lock);
3847 /* If the node is not being used by another discovery thread,
3848 * and we are sending a reject, we are done with it.
3849 * Release driver reference count here and free associated
3853 if (lpfc_nlp_not_used(ndlp))
3854 /* Indicate node has already been released,
3855 * should not reference to it from within
3856 * the routine lpfc_els_free_iocb.
3858 cmdiocb->context1 = NULL;
3861 lpfc_els_free_iocb(phba, cmdiocb);
3866 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3867 * @vport: pointer to a host virtual N_Port data structure.
3868 * @flag: the els command code to be accepted.
3869 * @oldiocb: pointer to the original lpfc command iocb data structure.
3870 * @ndlp: pointer to a node-list data structure.
3871 * @mbox: pointer to the driver internal queue element for mailbox command.
3873 * This routine prepares and issues an Accept (ACC) response IOCB
3874 * command. It uses the @flag to properly set up the IOCB field for the
3875 * specific ACC response command to be issued and invokes the
3876 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3877 * @mbox pointer is passed in, it will be put into the context_un.mbox
3878 * field of the IOCB for the completion callback function to issue the
3879 * mailbox command to the HBA later when callback is invoked.
3881 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3882 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3883 * will be stored into the context1 field of the IOCB for the completion
3884 * callback function to the corresponding response ELS IOCB command.
3887 * 0 - Successfully issued acc response
3888 * 1 - Failed to issue acc response
3891 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3892 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3895 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3896 struct lpfc_hba *phba = vport->phba;
3899 struct lpfc_iocbq *elsiocb;
3903 ELS_PKT *els_pkt_ptr;
3905 oldcmd = &oldiocb->iocb;
3909 cmdsize = sizeof(uint32_t);
3910 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3911 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3913 spin_lock_irq(shost->host_lock);
3914 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3915 spin_unlock_irq(shost->host_lock);
3919 icmd = &elsiocb->iocb;
3920 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3921 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3922 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3923 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3924 pcmd += sizeof(uint32_t);
3926 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3927 "Issue ACC: did:x%x flg:x%x",
3928 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3931 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3932 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3933 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3937 icmd = &elsiocb->iocb;
3938 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3939 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3940 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3943 elsiocb->context_un.mbox = mbox;
3945 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3946 pcmd += sizeof(uint32_t);
3947 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3949 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3950 "Issue ACC PLOGI: did:x%x flg:x%x",
3951 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3954 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3955 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3956 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3960 icmd = &elsiocb->iocb;
3961 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3962 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3963 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3965 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3966 sizeof(uint32_t) + sizeof(PRLO));
3967 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3968 els_pkt_ptr = (ELS_PKT *) pcmd;
3969 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3971 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3972 "Issue ACC PRLO: did:x%x flg:x%x",
3973 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3978 /* Xmit ELS ACC response tag <ulpIoTag> */
3979 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3980 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3981 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3983 elsiocb->iotag, elsiocb->iocb.ulpContext,
3984 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3985 ndlp->nlp_rpi, vport->fc_flag);
3986 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3987 spin_lock_irq(shost->host_lock);
3988 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
3989 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
3990 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3991 spin_unlock_irq(shost->host_lock);
3992 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3994 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3997 phba->fc_stat.elsXmitACC++;
3998 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3999 if (rc == IOCB_ERROR) {
4000 lpfc_els_free_iocb(phba, elsiocb);
4007 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4008 * @vport: pointer to a virtual N_Port data structure.
4010 * @oldiocb: pointer to the original lpfc command iocb data structure.
4011 * @ndlp: pointer to a node-list data structure.
4012 * @mbox: pointer to the driver internal queue element for mailbox command.
4014 * This routine prepares and issue an Reject (RJT) response IOCB
4015 * command. If a @mbox pointer is passed in, it will be put into the
4016 * context_un.mbox field of the IOCB for the completion callback function
4017 * to issue to the HBA later.
4019 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4020 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4021 * will be stored into the context1 field of the IOCB for the completion
4022 * callback function to the reject response ELS IOCB command.
4025 * 0 - Successfully issued reject response
4026 * 1 - Failed to issue reject response
4029 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4030 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4033 struct lpfc_hba *phba = vport->phba;
4036 struct lpfc_iocbq *elsiocb;
4041 cmdsize = 2 * sizeof(uint32_t);
4042 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4043 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4047 icmd = &elsiocb->iocb;
4048 oldcmd = &oldiocb->iocb;
4049 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4050 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4051 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4053 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4054 pcmd += sizeof(uint32_t);
4055 *((uint32_t *) (pcmd)) = rejectError;
4058 elsiocb->context_un.mbox = mbox;
4060 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4061 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4062 "0129 Xmit ELS RJT x%x response tag x%x "
4063 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4065 rejectError, elsiocb->iotag,
4066 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4067 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4069 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4070 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4072 phba->fc_stat.elsXmitLSRJT++;
4073 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4074 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4076 if (rc == IOCB_ERROR) {
4077 lpfc_els_free_iocb(phba, elsiocb);
4084 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4085 * @vport: pointer to a virtual N_Port data structure.
4086 * @oldiocb: pointer to the original lpfc command iocb data structure.
4087 * @ndlp: pointer to a node-list data structure.
4089 * This routine prepares and issues an Accept (ACC) response to Address
4090 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4091 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4093 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4094 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4095 * will be stored into the context1 field of the IOCB for the completion
4096 * callback function to the ADISC Accept response ELS IOCB command.
4099 * 0 - Successfully issued acc adisc response
4100 * 1 - Failed to issue adisc acc response
4103 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4104 struct lpfc_nodelist *ndlp)
4106 struct lpfc_hba *phba = vport->phba;
4108 IOCB_t *icmd, *oldcmd;
4109 struct lpfc_iocbq *elsiocb;
4114 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4115 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4116 ndlp->nlp_DID, ELS_CMD_ACC);
4120 icmd = &elsiocb->iocb;
4121 oldcmd = &oldiocb->iocb;
4122 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4123 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4125 /* Xmit ADISC ACC response tag <ulpIoTag> */
4126 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4127 "0130 Xmit ADISC ACC response iotag x%x xri: "
4128 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4129 elsiocb->iotag, elsiocb->iocb.ulpContext,
4130 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4132 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4134 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4135 pcmd += sizeof(uint32_t);
4137 ap = (ADISC *) (pcmd);
4138 ap->hardAL_PA = phba->fc_pref_ALPA;
4139 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4140 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4141 ap->DID = be32_to_cpu(vport->fc_myDID);
4143 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4144 "Issue ACC ADISC: did:x%x flg:x%x",
4145 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4147 phba->fc_stat.elsXmitACC++;
4148 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4149 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4150 if (rc == IOCB_ERROR) {
4151 lpfc_els_free_iocb(phba, elsiocb);
4158 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4159 * @vport: pointer to a virtual N_Port data structure.
4160 * @oldiocb: pointer to the original lpfc command iocb data structure.
4161 * @ndlp: pointer to a node-list data structure.
4163 * This routine prepares and issues an Accept (ACC) response to Process
4164 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4165 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4167 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4168 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4169 * will be stored into the context1 field of the IOCB for the completion
4170 * callback function to the PRLI Accept response ELS IOCB command.
4173 * 0 - Successfully issued acc prli response
4174 * 1 - Failed to issue acc prli response
4177 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4178 struct lpfc_nodelist *ndlp)
4180 struct lpfc_hba *phba = vport->phba;
4185 struct lpfc_iocbq *elsiocb;
4190 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4191 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4192 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
4196 icmd = &elsiocb->iocb;
4197 oldcmd = &oldiocb->iocb;
4198 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4199 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4201 /* Xmit PRLI ACC response tag <ulpIoTag> */
4202 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4203 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4204 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4205 elsiocb->iotag, elsiocb->iocb.ulpContext,
4206 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4208 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4210 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4211 pcmd += sizeof(uint32_t);
4213 /* For PRLI, remainder of payload is PRLI parameter page */
4214 memset(pcmd, 0, sizeof(PRLI));
4216 npr = (PRLI *) pcmd;
4219 * If the remote port is a target and our firmware version is 3.20 or
4220 * later, set the following bits for FC-TAPE support.
4222 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4223 (vpd->rev.feaLevelHigh >= 0x02)) {
4224 npr->ConfmComplAllowed = 1;
4226 npr->TaskRetryIdReq = 1;
4229 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4230 npr->estabImagePair = 1;
4231 npr->readXferRdyDis = 1;
4232 npr->ConfmComplAllowed = 1;
4234 npr->prliType = PRLI_FCP_TYPE;
4235 npr->initiatorFunc = 1;
4237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4238 "Issue ACC PRLI: did:x%x flg:x%x",
4239 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4241 phba->fc_stat.elsXmitACC++;
4242 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4244 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4245 if (rc == IOCB_ERROR) {
4246 lpfc_els_free_iocb(phba, elsiocb);
4253 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4254 * @vport: pointer to a virtual N_Port data structure.
4255 * @format: rnid command format.
4256 * @oldiocb: pointer to the original lpfc command iocb data structure.
4257 * @ndlp: pointer to a node-list data structure.
4259 * This routine issues a Request Node Identification Data (RNID) Accept
4260 * (ACC) response. It constructs the RNID ACC response command according to
4261 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4262 * issue the response. Note that this command does not need to hold the ndlp
4263 * reference count for the callback. So, the ndlp reference count taken by
4264 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4265 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4266 * there is no ndlp reference available.
4268 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4269 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4270 * will be stored into the context1 field of the IOCB for the completion
4271 * callback function. However, for the RNID Accept Response ELS command,
4272 * this is undone later by this routine after the IOCB is allocated.
4275 * 0 - Successfully issued acc rnid response
4276 * 1 - Failed to issue acc rnid response
4279 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4280 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4282 struct lpfc_hba *phba = vport->phba;
4284 IOCB_t *icmd, *oldcmd;
4285 struct lpfc_iocbq *elsiocb;
4290 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4291 + (2 * sizeof(struct lpfc_name));
4293 cmdsize += sizeof(RNID_TOP_DISC);
4295 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4296 ndlp->nlp_DID, ELS_CMD_ACC);
4300 icmd = &elsiocb->iocb;
4301 oldcmd = &oldiocb->iocb;
4302 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4303 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4305 /* Xmit RNID ACC response tag <ulpIoTag> */
4306 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4307 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4308 elsiocb->iotag, elsiocb->iocb.ulpContext);
4309 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4310 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4311 pcmd += sizeof(uint32_t);
4313 memset(pcmd, 0, sizeof(RNID));
4314 rn = (RNID *) (pcmd);
4315 rn->Format = format;
4316 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4317 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4318 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4321 rn->SpecificLen = 0;
4323 case RNID_TOPOLOGY_DISC:
4324 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4325 memcpy(&rn->un.topologyDisc.portName,
4326 &vport->fc_portname, sizeof(struct lpfc_name));
4327 rn->un.topologyDisc.unitType = RNID_HBA;
4328 rn->un.topologyDisc.physPort = 0;
4329 rn->un.topologyDisc.attachedNodes = 0;
4333 rn->SpecificLen = 0;
4337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4338 "Issue ACC RNID: did:x%x flg:x%x",
4339 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4341 phba->fc_stat.elsXmitACC++;
4342 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4344 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4345 if (rc == IOCB_ERROR) {
4346 lpfc_els_free_iocb(phba, elsiocb);
4353 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4354 * @vport: pointer to a virtual N_Port data structure.
4355 * @iocb: pointer to the lpfc command iocb data structure.
4356 * @ndlp: pointer to a node-list data structure.
4361 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4362 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4364 struct lpfc_hba *phba = vport->phba;
4369 struct lpfc_node_rrq *prrq;
4372 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4373 pcmd += sizeof(uint32_t);
4374 rrq = (struct RRQ *)pcmd;
4375 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4376 rxid = bf_get(rrq_rxid, rrq);
4378 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4379 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4381 be32_to_cpu(bf_get(rrq_did, rrq)),
4382 bf_get(rrq_oxid, rrq),
4384 iocb->iotag, iocb->iocb.ulpContext);
4386 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4387 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4388 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4389 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4390 xri = bf_get(rrq_oxid, rrq);
4393 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4395 lpfc_clr_rrq_active(phba, xri, prrq);
4400 * lpfc_els_rsp_echo_acc - Issue echo acc response
4401 * @vport: pointer to a virtual N_Port data structure.
4402 * @data: pointer to echo data to return in the accept.
4403 * @oldiocb: pointer to the original lpfc command iocb data structure.
4404 * @ndlp: pointer to a node-list data structure.
4407 * 0 - Successfully issued acc echo response
4408 * 1 - Failed to issue acc echo response
4411 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4412 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4414 struct lpfc_hba *phba = vport->phba;
4415 struct lpfc_iocbq *elsiocb;
4420 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4422 /* The accumulated length can exceed the BPL_SIZE. For
4423 * now, use this as the limit
4425 if (cmdsize > LPFC_BPL_SIZE)
4426 cmdsize = LPFC_BPL_SIZE;
4427 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4428 ndlp->nlp_DID, ELS_CMD_ACC);
4432 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4433 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4435 /* Xmit ECHO ACC response tag <ulpIoTag> */
4436 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4437 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4438 elsiocb->iotag, elsiocb->iocb.ulpContext);
4439 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4440 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4441 pcmd += sizeof(uint32_t);
4442 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4444 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4445 "Issue ACC ECHO: did:x%x flg:x%x",
4446 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4448 phba->fc_stat.elsXmitACC++;
4449 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4451 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4452 if (rc == IOCB_ERROR) {
4453 lpfc_els_free_iocb(phba, elsiocb);
4460 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4461 * @vport: pointer to a host virtual N_Port data structure.
4463 * This routine issues Address Discover (ADISC) ELS commands to those
4464 * N_Ports which are in node port recovery state and ADISC has not been issued
4465 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4466 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4467 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4468 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4469 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4470 * IOCBs quit for later pick up. On the other hand, after walking through
4471 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4472 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4473 * no more ADISC need to be sent.
4476 * The number of N_Ports with adisc issued.
4479 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4481 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4482 struct lpfc_nodelist *ndlp, *next_ndlp;
4485 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4486 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4487 if (!NLP_CHK_NODE_ACT(ndlp))
4489 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4490 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4491 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4492 spin_lock_irq(shost->host_lock);
4493 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4494 spin_unlock_irq(shost->host_lock);
4495 ndlp->nlp_prev_state = ndlp->nlp_state;
4496 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4497 lpfc_issue_els_adisc(vport, ndlp, 0);
4499 vport->num_disc_nodes++;
4500 if (vport->num_disc_nodes >=
4501 vport->cfg_discovery_threads) {
4502 spin_lock_irq(shost->host_lock);
4503 vport->fc_flag |= FC_NLP_MORE;
4504 spin_unlock_irq(shost->host_lock);
4509 if (sentadisc == 0) {
4510 spin_lock_irq(shost->host_lock);
4511 vport->fc_flag &= ~FC_NLP_MORE;
4512 spin_unlock_irq(shost->host_lock);
4518 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4519 * @vport: pointer to a host virtual N_Port data structure.
4521 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4522 * which are in node port recovery state, with a @vport. Each time an ELS
4523 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4524 * the per @vport number of discover count (num_disc_nodes) shall be
4525 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4526 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4527 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4528 * later pick up. On the other hand, after walking through all the ndlps with
4529 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4530 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4531 * PLOGI need to be sent.
4534 * The number of N_Ports with plogi issued.
4537 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4539 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4540 struct lpfc_nodelist *ndlp, *next_ndlp;
4543 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4544 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4545 if (!NLP_CHK_NODE_ACT(ndlp))
4547 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4548 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4549 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4550 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4551 ndlp->nlp_prev_state = ndlp->nlp_state;
4552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4553 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4555 vport->num_disc_nodes++;
4556 if (vport->num_disc_nodes >=
4557 vport->cfg_discovery_threads) {
4558 spin_lock_irq(shost->host_lock);
4559 vport->fc_flag |= FC_NLP_MORE;
4560 spin_unlock_irq(shost->host_lock);
4566 lpfc_set_disctmo(vport);
4569 spin_lock_irq(shost->host_lock);
4570 vport->fc_flag &= ~FC_NLP_MORE;
4571 spin_unlock_irq(shost->host_lock);
4577 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4581 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4582 desc->payload.els_req = word0;
4583 desc->length = cpu_to_be32(sizeof(desc->payload));
4587 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4588 uint8_t *page_a0, uint8_t *page_a2)
4590 uint16_t wavelength;
4591 uint16_t temperature;
4597 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4598 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4600 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4602 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4603 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4604 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4605 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4607 if ((trasn_code_byte4->fc_sw_laser) ||
4608 (trasn_code_byte5->fc_sw_laser_sl) ||
4609 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4610 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4611 } else if (trasn_code_byte4->fc_lw_laser) {
4612 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4613 page_a0[SSF_WAVELENGTH_B0];
4614 if (wavelength == SFP_WAVELENGTH_LC1310)
4615 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4616 if (wavelength == SFP_WAVELENGTH_LL1550)
4617 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4619 /* check if its SFP+ */
4620 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4621 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4622 << SFP_FLAG_CT_SHIFT;
4624 /* check if its OPTICAL */
4625 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4626 SFP_FLAG_IS_OPTICAL_PORT : 0)
4627 << SFP_FLAG_IS_OPTICAL_SHIFT;
4629 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4630 page_a2[SFF_TEMPERATURE_B0]);
4631 vcc = (page_a2[SFF_VCC_B1] << 8 |
4632 page_a2[SFF_VCC_B0]);
4633 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4634 page_a2[SFF_TXPOWER_B0]);
4635 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4636 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4637 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4638 page_a2[SFF_RXPOWER_B0]);
4639 desc->sfp_info.temperature = cpu_to_be16(temperature);
4640 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4641 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4642 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4643 desc->sfp_info.vcc = cpu_to_be16(vcc);
4645 desc->sfp_info.flags = cpu_to_be16(flag);
4646 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4650 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4655 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4657 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4659 desc->info.port_type = cpu_to_be32(type);
4661 desc->info.link_status.link_failure_cnt =
4662 cpu_to_be32(stat->linkFailureCnt);
4663 desc->info.link_status.loss_of_synch_cnt =
4664 cpu_to_be32(stat->lossSyncCnt);
4665 desc->info.link_status.loss_of_signal_cnt =
4666 cpu_to_be32(stat->lossSignalCnt);
4667 desc->info.link_status.primitive_seq_proto_err =
4668 cpu_to_be32(stat->primSeqErrCnt);
4669 desc->info.link_status.invalid_trans_word =
4670 cpu_to_be32(stat->invalidXmitWord);
4671 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4673 desc->length = cpu_to_be32(sizeof(desc->info));
4677 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
4679 uint16_t rdp_cap = 0;
4682 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
4684 switch (phba->sli4_hba.link_state.speed) {
4685 case LPFC_FC_LA_SPEED_1G:
4686 rdp_speed = RDP_PS_1GB;
4688 case LPFC_FC_LA_SPEED_2G:
4689 rdp_speed = RDP_PS_2GB;
4691 case LPFC_FC_LA_SPEED_4G:
4692 rdp_speed = RDP_PS_4GB;
4694 case LPFC_FC_LA_SPEED_8G:
4695 rdp_speed = RDP_PS_8GB;
4697 case LPFC_FC_LA_SPEED_10G:
4698 rdp_speed = RDP_PS_10GB;
4700 case LPFC_FC_LA_SPEED_16G:
4701 rdp_speed = RDP_PS_16GB;
4703 case LPFC_FC_LA_SPEED_32G:
4704 rdp_speed = RDP_PS_32GB;
4707 rdp_speed = RDP_PS_UNKNOWN;
4711 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
4713 if (phba->lmt & LMT_32Gb)
4714 rdp_cap |= RDP_PS_32GB;
4715 if (phba->lmt & LMT_16Gb)
4716 rdp_cap |= RDP_PS_16GB;
4717 if (phba->lmt & LMT_10Gb)
4718 rdp_cap |= RDP_PS_10GB;
4719 if (phba->lmt & LMT_8Gb)
4720 rdp_cap |= RDP_PS_8GB;
4721 if (phba->lmt & LMT_4Gb)
4722 rdp_cap |= RDP_PS_4GB;
4723 if (phba->lmt & LMT_2Gb)
4724 rdp_cap |= RDP_PS_2GB;
4725 if (phba->lmt & LMT_1Gb)
4726 rdp_cap |= RDP_PS_1GB;
4729 rdp_cap = RDP_CAP_UNKNOWN;
4731 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
4732 desc->length = cpu_to_be32(sizeof(desc->info));
4736 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
4737 struct lpfc_hba *phba)
4740 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4742 memcpy(desc->port_names.wwnn, phba->wwnn,
4743 sizeof(desc->port_names.wwnn));
4745 memcpy(desc->port_names.wwpn, &phba->wwpn,
4746 sizeof(desc->port_names.wwpn));
4748 desc->length = cpu_to_be32(sizeof(desc->port_names));
4752 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
4753 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4756 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4757 if (vport->fc_flag & FC_FABRIC) {
4758 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
4759 sizeof(desc->port_names.wwnn));
4761 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
4762 sizeof(desc->port_names.wwpn));
4763 } else { /* Point to Point */
4764 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
4765 sizeof(desc->port_names.wwnn));
4767 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
4768 sizeof(desc->port_names.wwpn));
4771 desc->length = cpu_to_be32(sizeof(desc->port_names));
4775 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
4778 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
4779 struct lpfc_vport *vport = ndlp->vport;
4780 struct lpfc_iocbq *elsiocb;
4783 struct ls_rjt *stat;
4784 struct fc_rdp_res_frame *rdp_res;
4788 if (status != SUCCESS)
4790 cmdsize = sizeof(struct fc_rdp_res_frame);
4792 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
4793 lpfc_max_els_tries, rdp_context->ndlp,
4794 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
4797 goto free_rdp_context;
4799 icmd = &elsiocb->iocb;
4800 icmd->ulpContext = rdp_context->rx_id;
4801 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4803 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4804 "2171 Xmit RDP response tag x%x xri x%x, "
4805 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
4806 elsiocb->iotag, elsiocb->iocb.ulpContext,
4807 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4809 rdp_res = (struct fc_rdp_res_frame *)
4810 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4811 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4812 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
4813 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4815 /* For RDP payload */
4816 lpfc_rdp_res_link_service(&rdp_res->link_service_desc, ELS_CMD_RDP);
4818 lpfc_rdp_res_sfp_desc(&rdp_res->sfp_desc,
4819 rdp_context->page_a0, rdp_context->page_a2);
4820 lpfc_rdp_res_speed(&rdp_res->portspeed_desc, phba);
4821 lpfc_rdp_res_link_error(&rdp_res->link_error_desc,
4822 &rdp_context->link_stat);
4823 lpfc_rdp_res_diag_port_names(&rdp_res->diag_port_names_desc, phba);
4824 lpfc_rdp_res_attach_port_names(&rdp_res->attached_port_names_desc,
4826 rdp_res->length = cpu_to_be32(RDP_DESC_PAYLOAD_SIZE);
4828 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4830 phba->fc_stat.elsXmitACC++;
4831 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4832 if (rc == IOCB_ERROR)
4833 lpfc_els_free_iocb(phba, elsiocb);
4839 cmdsize = 2 * sizeof(uint32_t);
4840 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
4841 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
4844 goto free_rdp_context;
4846 icmd = &elsiocb->iocb;
4847 icmd->ulpContext = rdp_context->rx_id;
4848 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4849 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4851 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4852 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
4853 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4855 phba->fc_stat.elsXmitLSRJT++;
4856 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4857 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4859 if (rc == IOCB_ERROR)
4860 lpfc_els_free_iocb(phba, elsiocb);
4866 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
4868 LPFC_MBOXQ_t *mbox = NULL;
4871 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4873 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
4874 "7105 failed to allocate mailbox memory");
4878 if (lpfc_sli4_dump_page_a0(phba, mbox))
4879 goto prep_mbox_fail;
4880 mbox->vport = rdp_context->ndlp->vport;
4881 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
4882 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
4883 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4884 if (rc == MBX_NOT_FINISHED)
4885 goto issue_mbox_fail;
4891 mempool_free(mbox, phba->mbox_mem_pool);
4896 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
4897 * @vport: pointer to a host virtual N_Port data structure.
4898 * @cmdiocb: pointer to lpfc command iocb data structure.
4899 * @ndlp: pointer to a node-list data structure.
4901 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
4902 * IOCB. First, the payload of the unsolicited RDP is checked.
4903 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
4904 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
4905 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
4906 * gather all data and send RDP response.
4909 * 0 - Sent the acc response
4910 * 1 - Sent the reject response.
4913 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4914 struct lpfc_nodelist *ndlp)
4916 struct lpfc_hba *phba = vport->phba;
4917 struct lpfc_dmabuf *pcmd;
4918 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
4919 struct fc_rdp_req_frame *rdp_req;
4920 struct lpfc_rdp_context *rdp_context;
4924 if (phba->sli_rev < LPFC_SLI_REV4 ||
4925 (bf_get(lpfc_sli_intf_if_type,
4926 &phba->sli4_hba.sli_intf) !=
4927 LPFC_SLI_INTF_IF_TYPE_2)) {
4928 rjt_err = LSRJT_UNABLE_TPC;
4929 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4933 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
4934 rjt_err = LSRJT_UNABLE_TPC;
4935 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4939 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4940 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
4943 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4944 "2422 ELS RDP Request "
4945 "dec len %d tag x%x port_id %d len %d\n",
4946 be32_to_cpu(rdp_req->rdp_des_length),
4947 be32_to_cpu(rdp_req->nport_id_desc.tag),
4948 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
4949 be32_to_cpu(rdp_req->nport_id_desc.length));
4951 if (sizeof(struct fc_rdp_nport_desc) !=
4952 be32_to_cpu(rdp_req->rdp_des_length))
4954 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
4956 if (RDP_NPORT_ID_SIZE !=
4957 be32_to_cpu(rdp_req->nport_id_desc.length))
4959 rdp_context = kmalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
4961 rjt_err = LSRJT_UNABLE_TPC;
4965 memset(rdp_context, 0, sizeof(struct lpfc_rdp_context));
4966 cmd = &cmdiocb->iocb;
4967 rdp_context->ndlp = lpfc_nlp_get(ndlp);
4968 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
4969 rdp_context->rx_id = cmd->ulpContext;
4970 rdp_context->cmpl = lpfc_els_rdp_cmpl;
4971 if (lpfc_get_rdp_info(phba, rdp_context)) {
4972 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
4973 "2423 Unable to send mailbox");
4975 rjt_err = LSRJT_UNABLE_TPC;
4983 rjt_err = LSRJT_LOGICAL_ERR;
4986 memset(&stat, 0, sizeof(stat));
4987 stat.un.b.lsRjtRsnCode = rjt_err;
4988 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
4989 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4995 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5000 struct lpfc_iocbq *elsiocb;
5001 struct lpfc_nodelist *ndlp;
5002 struct ls_rjt *stat;
5003 union lpfc_sli4_cfg_shdr *shdr;
5004 struct lpfc_lcb_context *lcb_context;
5005 struct fc_lcb_res_frame *lcb_res;
5006 uint32_t cmdsize, shdr_status, shdr_add_status;
5010 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5011 ndlp = lcb_context->ndlp;
5012 pmb->context1 = NULL;
5013 pmb->context2 = NULL;
5015 shdr = (union lpfc_sli4_cfg_shdr *)
5016 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5017 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5018 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5020 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5021 "0194 SET_BEACON_CONFIG mailbox "
5022 "completed with status x%x add_status x%x,"
5023 " mbx status x%x\n",
5024 shdr_status, shdr_add_status, mb->mbxStatus);
5026 if (mb->mbxStatus && !(shdr_status &&
5027 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
5028 mempool_free(pmb, phba->mbox_mem_pool);
5032 mempool_free(pmb, phba->mbox_mem_pool);
5033 cmdsize = sizeof(struct fc_lcb_res_frame);
5034 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5035 lpfc_max_els_tries, ndlp,
5036 ndlp->nlp_DID, ELS_CMD_ACC);
5038 /* Decrement the ndlp reference count from previous mbox command */
5042 goto free_lcb_context;
5044 lcb_res = (struct fc_lcb_res_frame *)
5045 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5047 icmd = &elsiocb->iocb;
5048 icmd->ulpContext = lcb_context->rx_id;
5049 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5051 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5052 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5053 lcb_res->lcb_sub_command = lcb_context->sub_command;
5054 lcb_res->lcb_type = lcb_context->type;
5055 lcb_res->lcb_frequency = lcb_context->frequency;
5056 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5057 phba->fc_stat.elsXmitACC++;
5058 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5059 if (rc == IOCB_ERROR)
5060 lpfc_els_free_iocb(phba, elsiocb);
5066 cmdsize = sizeof(struct fc_lcb_res_frame);
5067 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5068 lpfc_max_els_tries, ndlp,
5069 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5072 goto free_lcb_context;
5074 icmd = &elsiocb->iocb;
5075 icmd->ulpContext = lcb_context->rx_id;
5076 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5077 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5079 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5080 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5081 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5083 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5084 phba->fc_stat.elsXmitLSRJT++;
5085 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5086 if (rc == IOCB_ERROR)
5087 lpfc_els_free_iocb(phba, elsiocb);
5093 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5094 struct lpfc_lcb_context *lcb_context,
5095 uint32_t beacon_state)
5097 struct lpfc_hba *phba = vport->phba;
5098 LPFC_MBOXQ_t *mbox = NULL;
5102 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5106 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5107 sizeof(struct lpfc_sli4_cfg_mhdr);
5108 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5109 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5110 LPFC_SLI4_MBX_EMBED);
5111 mbox->context1 = (void *)lcb_context;
5112 mbox->vport = phba->pport;
5113 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5114 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5115 phba->sli4_hba.physical_port);
5116 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5118 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5119 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5120 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5121 if (rc == MBX_NOT_FINISHED) {
5122 mempool_free(mbox, phba->mbox_mem_pool);
5131 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5132 * @vport: pointer to a host virtual N_Port data structure.
5133 * @cmdiocb: pointer to lpfc command iocb data structure.
5134 * @ndlp: pointer to a node-list data structure.
5136 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5137 * First, the payload of the unsolicited LCB is checked.
5138 * Then based on Subcommand beacon will either turn on or off.
5141 * 0 - Sent the acc response
5142 * 1 - Sent the reject response.
5145 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5146 struct lpfc_nodelist *ndlp)
5148 struct lpfc_hba *phba = vport->phba;
5149 struct lpfc_dmabuf *pcmd;
5151 struct fc_lcb_request_frame *beacon;
5152 struct lpfc_lcb_context *lcb_context;
5153 uint8_t state, rjt_err;
5156 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5157 lp = (uint8_t *)pcmd->virt;
5158 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5160 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5161 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5162 "type x%x frequency %x duration x%x\n",
5163 lp[0], lp[1], lp[2],
5164 beacon->lcb_command,
5165 beacon->lcb_sub_command,
5167 beacon->lcb_frequency,
5168 be16_to_cpu(beacon->lcb_duration));
5170 if (phba->sli_rev < LPFC_SLI_REV4 ||
5171 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5172 LPFC_SLI_INTF_IF_TYPE_2)) {
5173 rjt_err = LSRJT_CMD_UNSUPPORTED;
5176 lcb_context = kmalloc(sizeof(struct lpfc_lcb_context), GFP_KERNEL);
5178 if (phba->hba_flag & HBA_FCOE_MODE) {
5179 rjt_err = LSRJT_CMD_UNSUPPORTED;
5182 if (beacon->lcb_frequency == 0) {
5183 rjt_err = LSRJT_CMD_UNSUPPORTED;
5186 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5187 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5188 rjt_err = LSRJT_CMD_UNSUPPORTED;
5191 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5192 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5193 rjt_err = LSRJT_CMD_UNSUPPORTED;
5196 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5197 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5198 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5199 rjt_err = LSRJT_CMD_UNSUPPORTED;
5202 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5203 rjt_err = LSRJT_CMD_UNSUPPORTED;
5207 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5208 lcb_context->sub_command = beacon->lcb_sub_command;
5209 lcb_context->type = beacon->lcb_type;
5210 lcb_context->frequency = beacon->lcb_frequency;
5211 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5212 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5213 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5214 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5215 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5216 LOG_ELS, "0193 failed to send mail box");
5218 rjt_err = LSRJT_UNABLE_TPC;
5223 memset(&stat, 0, sizeof(stat));
5224 stat.un.b.lsRjtRsnCode = rjt_err;
5225 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5231 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5232 * @vport: pointer to a host virtual N_Port data structure.
5234 * This routine cleans up any Registration State Change Notification
5235 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5236 * @vport together with the host_lock is used to prevent multiple thread
5237 * trying to access the RSCN array on a same @vport at the same time.
5240 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5242 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5243 struct lpfc_hba *phba = vport->phba;
5246 spin_lock_irq(shost->host_lock);
5247 if (vport->fc_rscn_flush) {
5248 /* Another thread is walking fc_rscn_id_list on this vport */
5249 spin_unlock_irq(shost->host_lock);
5252 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5253 vport->fc_rscn_flush = 1;
5254 spin_unlock_irq(shost->host_lock);
5256 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5257 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5258 vport->fc_rscn_id_list[i] = NULL;
5260 spin_lock_irq(shost->host_lock);
5261 vport->fc_rscn_id_cnt = 0;
5262 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5263 spin_unlock_irq(shost->host_lock);
5264 lpfc_can_disctmo(vport);
5265 /* Indicate we are done walking this fc_rscn_id_list */
5266 vport->fc_rscn_flush = 0;
5270 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5271 * @vport: pointer to a host virtual N_Port data structure.
5272 * @did: remote destination port identifier.
5274 * This routine checks whether there is any pending Registration State
5275 * Configuration Notification (RSCN) to a @did on @vport.
5278 * None zero - The @did matched with a pending rscn
5279 * 0 - not able to match @did with a pending rscn
5282 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5287 uint32_t payload_len, i;
5288 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5290 ns_did.un.word = did;
5292 /* Never match fabric nodes for RSCNs */
5293 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5296 /* If we are doing a FULL RSCN rediscovery, match everything */
5297 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5300 spin_lock_irq(shost->host_lock);
5301 if (vport->fc_rscn_flush) {
5302 /* Another thread is walking fc_rscn_id_list on this vport */
5303 spin_unlock_irq(shost->host_lock);
5306 /* Indicate we are walking fc_rscn_id_list on this vport */
5307 vport->fc_rscn_flush = 1;
5308 spin_unlock_irq(shost->host_lock);
5309 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5310 lp = vport->fc_rscn_id_list[i]->virt;
5311 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5312 payload_len -= sizeof(uint32_t); /* take off word 0 */
5313 while (payload_len) {
5314 rscn_did.un.word = be32_to_cpu(*lp++);
5315 payload_len -= sizeof(uint32_t);
5316 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5317 case RSCN_ADDRESS_FORMAT_PORT:
5318 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5319 && (ns_did.un.b.area == rscn_did.un.b.area)
5320 && (ns_did.un.b.id == rscn_did.un.b.id))
5321 goto return_did_out;
5323 case RSCN_ADDRESS_FORMAT_AREA:
5324 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5325 && (ns_did.un.b.area == rscn_did.un.b.area))
5326 goto return_did_out;
5328 case RSCN_ADDRESS_FORMAT_DOMAIN:
5329 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5330 goto return_did_out;
5332 case RSCN_ADDRESS_FORMAT_FABRIC:
5333 goto return_did_out;
5337 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5338 vport->fc_rscn_flush = 0;
5341 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5342 vport->fc_rscn_flush = 0;
5347 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5348 * @vport: pointer to a host virtual N_Port data structure.
5350 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5351 * state machine for a @vport's nodes that are with pending RSCN (Registration
5352 * State Change Notification).
5355 * 0 - Successful (currently alway return 0)
5358 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
5360 struct lpfc_nodelist *ndlp = NULL;
5362 /* Move all affected nodes by pending RSCNs to NPR state. */
5363 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5364 if (!NLP_CHK_NODE_ACT(ndlp) ||
5365 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5366 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
5368 lpfc_disc_state_machine(vport, ndlp, NULL,
5369 NLP_EVT_DEVICE_RECOVERY);
5370 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5376 * lpfc_send_rscn_event - Send an RSCN event to management application
5377 * @vport: pointer to a host virtual N_Port data structure.
5378 * @cmdiocb: pointer to lpfc command iocb data structure.
5380 * lpfc_send_rscn_event sends an RSCN netlink event to management
5384 lpfc_send_rscn_event(struct lpfc_vport *vport,
5385 struct lpfc_iocbq *cmdiocb)
5387 struct lpfc_dmabuf *pcmd;
5388 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5389 uint32_t *payload_ptr;
5390 uint32_t payload_len;
5391 struct lpfc_rscn_event_header *rscn_event_data;
5393 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5394 payload_ptr = (uint32_t *) pcmd->virt;
5395 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5397 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5398 payload_len, GFP_KERNEL);
5399 if (!rscn_event_data) {
5400 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5401 "0147 Failed to allocate memory for RSCN event\n");
5404 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5405 rscn_event_data->payload_length = payload_len;
5406 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5409 fc_host_post_vendor_event(shost,
5410 fc_get_event_number(),
5411 sizeof(struct lpfc_rscn_event_header) + payload_len,
5412 (char *)rscn_event_data,
5415 kfree(rscn_event_data);
5419 * lpfc_els_rcv_rscn - Process an unsolicited rscn 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 an unsolicited RSCN (Registration State Change
5425 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5426 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5427 * discover state machine is about to begin discovery, it just accepts the
5428 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5429 * contains N_Port IDs for other vports on this HBA, it just accepts the
5430 * RSCN and ignore processing it. If the state machine is in the recovery
5431 * state, the fc_rscn_id_list of this @vport is walked and the
5432 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5433 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5434 * routine is invoked to handle the RSCN event.
5437 * 0 - Just sent the acc response
5438 * 1 - Sent the acc response and waited for name server completion
5441 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5442 struct lpfc_nodelist *ndlp)
5444 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5445 struct lpfc_hba *phba = vport->phba;
5446 struct lpfc_dmabuf *pcmd;
5447 uint32_t *lp, *datap;
5448 uint32_t payload_len, length, nportid, *cmd;
5450 int rscn_id = 0, hba_id = 0;
5453 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5454 lp = (uint32_t *) pcmd->virt;
5456 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5457 payload_len -= sizeof(uint32_t); /* take off word 0 */
5459 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5460 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5461 vport->fc_flag, payload_len, *lp,
5462 vport->fc_rscn_id_cnt);
5464 /* Send an RSCN event to the management application */
5465 lpfc_send_rscn_event(vport, cmdiocb);
5467 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
5468 fc_host_post_event(shost, fc_get_event_number(),
5469 FCH_EVT_RSCN, lp[i]);
5471 /* If we are about to begin discovery, just ACC the RSCN.
5472 * Discovery processing will satisfy it.
5474 if (vport->port_state <= LPFC_NS_QRY) {
5475 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5476 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5477 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5479 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5483 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5484 * just ACC and ignore it.
5486 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5487 !(vport->cfg_peer_port_login)) {
5492 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5493 i -= sizeof(uint32_t);
5495 if (lpfc_find_vport_by_did(phba, nportid))
5498 if (rscn_id == hba_id) {
5499 /* ALL NPortIDs in RSCN are on HBA */
5500 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5502 "Data: x%x x%x x%x x%x\n",
5503 vport->fc_flag, payload_len,
5504 *lp, vport->fc_rscn_id_cnt);
5505 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5506 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5507 ndlp->nlp_DID, vport->port_state,
5510 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
5516 spin_lock_irq(shost->host_lock);
5517 if (vport->fc_rscn_flush) {
5518 /* Another thread is walking fc_rscn_id_list on this vport */
5519 vport->fc_flag |= FC_RSCN_DISCOVERY;
5520 spin_unlock_irq(shost->host_lock);
5522 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5525 /* Indicate we are walking fc_rscn_id_list on this vport */
5526 vport->fc_rscn_flush = 1;
5527 spin_unlock_irq(shost->host_lock);
5528 /* Get the array count after successfully have the token */
5529 rscn_cnt = vport->fc_rscn_id_cnt;
5530 /* If we are already processing an RSCN, save the received
5531 * RSCN payload buffer, cmdiocb->context2 to process later.
5533 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
5534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5535 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5536 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5538 spin_lock_irq(shost->host_lock);
5539 vport->fc_flag |= FC_RSCN_DEFERRED;
5540 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
5541 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
5542 vport->fc_flag |= FC_RSCN_MODE;
5543 spin_unlock_irq(shost->host_lock);
5545 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
5546 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
5549 (payload_len + length <= LPFC_BPL_SIZE)) {
5550 *cmd &= ELS_CMD_MASK;
5551 *cmd |= cpu_to_be32(payload_len + length);
5552 memcpy(((uint8_t *)cmd) + length, lp,
5555 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
5556 vport->fc_rscn_id_cnt++;
5557 /* If we zero, cmdiocb->context2, the calling
5558 * routine will not try to free it.
5560 cmdiocb->context2 = NULL;
5563 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5564 "0235 Deferred RSCN "
5565 "Data: x%x x%x x%x\n",
5566 vport->fc_rscn_id_cnt, vport->fc_flag,
5569 vport->fc_flag |= FC_RSCN_DISCOVERY;
5570 spin_unlock_irq(shost->host_lock);
5571 /* ReDiscovery RSCN */
5572 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5573 "0234 ReDiscovery RSCN "
5574 "Data: x%x x%x x%x\n",
5575 vport->fc_rscn_id_cnt, vport->fc_flag,
5578 /* Indicate we are done walking fc_rscn_id_list on this vport */
5579 vport->fc_rscn_flush = 0;
5581 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5582 /* send RECOVERY event for ALL nodes that match RSCN payload */
5583 lpfc_rscn_recovery_check(vport);
5584 spin_lock_irq(shost->host_lock);
5585 vport->fc_flag &= ~FC_RSCN_DEFERRED;
5586 spin_unlock_irq(shost->host_lock);
5589 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5590 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5591 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5593 spin_lock_irq(shost->host_lock);
5594 vport->fc_flag |= FC_RSCN_MODE;
5595 spin_unlock_irq(shost->host_lock);
5596 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
5597 /* Indicate we are done walking fc_rscn_id_list on this vport */
5598 vport->fc_rscn_flush = 0;
5600 * If we zero, cmdiocb->context2, the calling routine will
5601 * not try to free it.
5603 cmdiocb->context2 = NULL;
5604 lpfc_set_disctmo(vport);
5606 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5607 /* send RECOVERY event for ALL nodes that match RSCN payload */
5608 lpfc_rscn_recovery_check(vport);
5609 return lpfc_els_handle_rscn(vport);
5613 * lpfc_els_handle_rscn - Handle rscn for a vport
5614 * @vport: pointer to a host virtual N_Port data structure.
5616 * This routine handles the Registration State Configuration Notification
5617 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5618 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5619 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5620 * NameServer shall be issued. If CT command to the NameServer fails to be
5621 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5622 * RSCN activities with the @vport.
5625 * 0 - Cleaned up rscn on the @vport
5626 * 1 - Wait for plogi to name server before proceed
5629 lpfc_els_handle_rscn(struct lpfc_vport *vport)
5631 struct lpfc_nodelist *ndlp;
5632 struct lpfc_hba *phba = vport->phba;
5634 /* Ignore RSCN if the port is being torn down. */
5635 if (vport->load_flag & FC_UNLOADING) {
5636 lpfc_els_flush_rscn(vport);
5640 /* Start timer for RSCN processing */
5641 lpfc_set_disctmo(vport);
5643 /* RSCN processed */
5644 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5645 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5646 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
5649 /* To process RSCN, first compare RSCN data with NameServer */
5650 vport->fc_ns_retry = 0;
5651 vport->num_disc_nodes = 0;
5653 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5654 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
5655 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
5656 /* Good ndlp, issue CT Request to NameServer */
5657 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
5658 /* Wait for NameServer query cmpl before we can
5662 /* If login to NameServer does not exist, issue one */
5663 /* Good status, issue PLOGI to NameServer */
5664 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5665 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5666 /* Wait for NameServer login cmpl before we can
5671 ndlp = lpfc_enable_node(vport, ndlp,
5672 NLP_STE_PLOGI_ISSUE);
5674 lpfc_els_flush_rscn(vport);
5677 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
5679 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5681 lpfc_els_flush_rscn(vport);
5684 lpfc_nlp_init(vport, ndlp, NameServer_DID);
5685 ndlp->nlp_prev_state = ndlp->nlp_state;
5686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5688 ndlp->nlp_type |= NLP_FABRIC;
5689 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
5690 /* Wait for NameServer login cmpl before we can
5696 lpfc_els_flush_rscn(vport);
5701 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
5702 * @vport: pointer to a host virtual N_Port data structure.
5703 * @cmdiocb: pointer to lpfc command iocb data structure.
5704 * @ndlp: pointer to a node-list data structure.
5706 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5707 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5708 * point topology. As an unsolicited FLOGI should not be received in a loop
5709 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5710 * lpfc_check_sparm() routine is invoked to check the parameters in the
5711 * unsolicited FLOGI. If parameters validation failed, the routine
5712 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5713 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5714 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5715 * will initiate PLOGI. The higher lexicographical value party shall has
5716 * higher priority (as the winning port) and will initiate PLOGI and
5717 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5718 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5719 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5722 * 0 - Successfully processed the unsolicited flogi
5723 * 1 - Failed to process the unsolicited flogi
5726 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5727 struct lpfc_nodelist *ndlp)
5729 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5730 struct lpfc_hba *phba = vport->phba;
5731 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5732 uint32_t *lp = (uint32_t *) pcmd->virt;
5733 IOCB_t *icmd = &cmdiocb->iocb;
5734 struct serv_parm *sp;
5739 uint32_t fc_flag = 0;
5740 uint32_t port_state = 0;
5743 sp = (struct serv_parm *) lp;
5745 /* FLOGI received */
5747 lpfc_set_disctmo(vport);
5749 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5750 /* We should never receive a FLOGI in loop mode, ignore it */
5751 did = icmd->un.elsreq64.remoteID;
5753 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5755 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5756 "0113 An FLOGI ELS command x%x was "
5757 "received from DID x%x in Loop Mode\n",
5762 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
5763 /* For a FLOGI we accept, then if our portname is greater
5764 * then the remote portname we initiate Nport login.
5767 rc = memcmp(&vport->fc_portname, &sp->portName,
5768 sizeof(struct lpfc_name));
5771 if (phba->sli_rev < LPFC_SLI_REV4) {
5772 mbox = mempool_alloc(phba->mbox_mem_pool,
5776 lpfc_linkdown(phba);
5777 lpfc_init_link(phba, mbox,
5779 phba->cfg_link_speed);
5780 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5781 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5782 mbox->vport = vport;
5783 rc = lpfc_sli_issue_mbox(phba, mbox,
5785 lpfc_set_loopback_flag(phba);
5786 if (rc == MBX_NOT_FINISHED)
5787 mempool_free(mbox, phba->mbox_mem_pool);
5790 /* abort the flogi coming back to ourselves
5791 * due to external loopback on the port.
5793 lpfc_els_abort_flogi(phba);
5796 } else if (rc > 0) { /* greater than */
5797 spin_lock_irq(shost->host_lock);
5798 vport->fc_flag |= FC_PT2PT_PLOGI;
5799 spin_unlock_irq(shost->host_lock);
5801 /* If we have the high WWPN we can assign our own
5802 * myDID; otherwise, we have to WAIT for a PLOGI
5803 * from the remote NPort to find out what it
5806 vport->fc_myDID = PT2PT_LocalID;
5808 vport->fc_myDID = PT2PT_RemoteID;
5811 * The vport state should go to LPFC_FLOGI only
5812 * AFTER we issue a FLOGI, not receive one.
5814 spin_lock_irq(shost->host_lock);
5815 fc_flag = vport->fc_flag;
5816 port_state = vport->port_state;
5817 vport->fc_flag |= FC_PT2PT;
5818 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5819 spin_unlock_irq(shost->host_lock);
5820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5821 "3311 Rcv Flogi PS x%x new PS x%x "
5822 "fc_flag x%x new fc_flag x%x\n",
5823 port_state, vport->port_state,
5824 fc_flag, vport->fc_flag);
5827 * We temporarily set fc_myDID to make it look like we are
5828 * a Fabric. This is done just so we end up with the right
5829 * did / sid on the FLOGI ACC rsp.
5831 did = vport->fc_myDID;
5832 vport->fc_myDID = Fabric_DID;
5835 /* Reject this request because invalid parameters */
5836 stat.un.b.lsRjtRsvd0 = 0;
5837 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5838 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5839 stat.un.b.vendorUnique = 0;
5842 * We temporarily set fc_myDID to make it look like we are
5843 * a Fabric. This is done just so we end up with the right
5844 * did / sid on the FLOGI LS_RJT rsp.
5846 did = vport->fc_myDID;
5847 vport->fc_myDID = Fabric_DID;
5849 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5852 /* Now lets put fc_myDID back to what its supposed to be */
5853 vport->fc_myDID = did;
5858 /* send our FLOGI first */
5859 if (vport->port_state < LPFC_FLOGI) {
5860 vport->fc_myDID = 0;
5861 lpfc_initial_flogi(vport);
5862 vport->fc_myDID = Fabric_DID;
5866 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
5868 /* Now lets put fc_myDID back to what its supposed to be */
5869 vport->fc_myDID = did;
5871 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
5873 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5877 lpfc_config_link(phba, mbox);
5879 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5880 mbox->vport = vport;
5881 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5882 if (rc == MBX_NOT_FINISHED) {
5883 mempool_free(mbox, phba->mbox_mem_pool);
5894 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
5895 * @vport: pointer to a host virtual N_Port data structure.
5896 * @cmdiocb: pointer to lpfc command iocb data structure.
5897 * @ndlp: pointer to a node-list data structure.
5899 * This routine processes Request Node Identification Data (RNID) IOCB
5900 * received as an ELS unsolicited event. Only when the RNID specified format
5901 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5902 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5903 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5904 * rejected by invoking the lpfc_els_rsp_reject() routine.
5907 * 0 - Successfully processed rnid iocb (currently always return 0)
5910 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5911 struct lpfc_nodelist *ndlp)
5913 struct lpfc_dmabuf *pcmd;
5919 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5920 lp = (uint32_t *) pcmd->virt;
5927 switch (rn->Format) {
5929 case RNID_TOPOLOGY_DISC:
5931 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
5934 /* Reject this request because format not supported */
5935 stat.un.b.lsRjtRsvd0 = 0;
5936 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5937 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5938 stat.un.b.vendorUnique = 0;
5939 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5946 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5947 * @vport: pointer to a host virtual N_Port data structure.
5948 * @cmdiocb: pointer to lpfc command iocb data structure.
5949 * @ndlp: pointer to a node-list data structure.
5952 * 0 - Successfully processed echo iocb (currently always return 0)
5955 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5956 struct lpfc_nodelist *ndlp)
5960 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5962 /* skip over first word of echo command to find echo data */
5963 pcmd += sizeof(uint32_t);
5965 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5970 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
5971 * @vport: pointer to a host virtual N_Port data structure.
5972 * @cmdiocb: pointer to lpfc command iocb data structure.
5973 * @ndlp: pointer to a node-list data structure.
5975 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5976 * received as an ELS unsolicited event. Currently, this function just invokes
5977 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5980 * 0 - Successfully processed lirr iocb (currently always return 0)
5983 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5984 struct lpfc_nodelist *ndlp)
5988 /* For now, unconditionally reject this command */
5989 stat.un.b.lsRjtRsvd0 = 0;
5990 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5991 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5992 stat.un.b.vendorUnique = 0;
5993 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5998 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5999 * @vport: pointer to a host virtual N_Port data structure.
6000 * @cmdiocb: pointer to lpfc command iocb data structure.
6001 * @ndlp: pointer to a node-list data structure.
6003 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6004 * received as an ELS unsolicited event. A request to RRQ shall only
6005 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6006 * Nx_Port N_Port_ID of the target Exchange is the same as the
6007 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6008 * not accepted, an LS_RJT with reason code "Unable to perform
6009 * command request" and reason code explanation "Invalid Originator
6010 * S_ID" shall be returned. For now, we just unconditionally accept
6011 * RRQ from the target.
6014 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6015 struct lpfc_nodelist *ndlp)
6017 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6018 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6019 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6023 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6024 * @phba: pointer to lpfc hba data structure.
6025 * @pmb: pointer to the driver internal queue element for mailbox command.
6027 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6028 * mailbox command. This callback function is to actually send the Accept
6029 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6030 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6031 * mailbox command, constructs the RPS response with the link statistics
6032 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6033 * response to the RPS.
6035 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6036 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6037 * will be stored into the context1 field of the IOCB for the completion
6038 * callback function to the RPS Accept Response ELS IOCB command.
6042 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6046 struct RLS_RSP *rls_rsp;
6048 struct lpfc_iocbq *elsiocb;
6049 struct lpfc_nodelist *ndlp;
6056 ndlp = (struct lpfc_nodelist *) pmb->context2;
6057 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6058 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6059 pmb->context1 = NULL;
6060 pmb->context2 = NULL;
6062 if (mb->mbxStatus) {
6063 mempool_free(pmb, phba->mbox_mem_pool);
6067 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6068 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6069 lpfc_max_els_tries, ndlp,
6070 ndlp->nlp_DID, ELS_CMD_ACC);
6072 /* Decrement the ndlp reference count from previous mbox command */
6076 mempool_free(pmb, phba->mbox_mem_pool);
6080 icmd = &elsiocb->iocb;
6081 icmd->ulpContext = rxid;
6082 icmd->unsli3.rcvsli3.ox_id = oxid;
6084 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6085 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6086 pcmd += sizeof(uint32_t); /* Skip past command */
6087 rls_rsp = (struct RLS_RSP *)pcmd;
6089 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6090 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6091 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6092 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6093 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6094 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6095 mempool_free(pmb, phba->mbox_mem_pool);
6096 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6097 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6098 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6099 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6100 elsiocb->iotag, elsiocb->iocb.ulpContext,
6101 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6103 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6104 phba->fc_stat.elsXmitACC++;
6105 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6106 lpfc_els_free_iocb(phba, elsiocb);
6110 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6111 * @phba: pointer to lpfc hba data structure.
6112 * @pmb: pointer to the driver internal queue element for mailbox command.
6114 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6115 * mailbox command. This callback function is to actually send the Accept
6116 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6117 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6118 * mailbox command, constructs the RPS response with the link statistics
6119 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6120 * response to the RPS.
6122 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6123 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6124 * will be stored into the context1 field of the IOCB for the completion
6125 * callback function to the RPS Accept Response ELS IOCB command.
6129 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6135 struct lpfc_iocbq *elsiocb;
6136 struct lpfc_nodelist *ndlp;
6144 ndlp = (struct lpfc_nodelist *) pmb->context2;
6145 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6146 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6147 pmb->context1 = NULL;
6148 pmb->context2 = NULL;
6150 if (mb->mbxStatus) {
6151 mempool_free(pmb, phba->mbox_mem_pool);
6155 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6156 mempool_free(pmb, phba->mbox_mem_pool);
6157 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6158 lpfc_max_els_tries, ndlp,
6159 ndlp->nlp_DID, ELS_CMD_ACC);
6161 /* Decrement the ndlp reference count from previous mbox command */
6167 icmd = &elsiocb->iocb;
6168 icmd->ulpContext = rxid;
6169 icmd->unsli3.rcvsli3.ox_id = oxid;
6171 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6172 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6173 pcmd += sizeof(uint32_t); /* Skip past command */
6174 rps_rsp = (RPS_RSP *)pcmd;
6176 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6180 if (phba->pport->fc_flag & FC_FABRIC)
6184 rps_rsp->portStatus = cpu_to_be16(status);
6185 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6186 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6187 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6188 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6189 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6190 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6191 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6192 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6193 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6194 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6195 elsiocb->iotag, elsiocb->iocb.ulpContext,
6196 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6198 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6199 phba->fc_stat.elsXmitACC++;
6200 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6201 lpfc_els_free_iocb(phba, elsiocb);
6206 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6207 * @vport: pointer to a host virtual N_Port data structure.
6208 * @cmdiocb: pointer to lpfc command iocb data structure.
6209 * @ndlp: pointer to a node-list data structure.
6211 * This routine processes Read Port Status (RPL) IOCB received as an
6212 * ELS unsolicited event. It first checks the remote port state. If the
6213 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6214 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6215 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6216 * for reading the HBA link statistics. It is for the callback function,
6217 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6218 * to actually sending out RPL Accept (ACC) response.
6221 * 0 - Successfully processed rls iocb (currently always return 0)
6224 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6225 struct lpfc_nodelist *ndlp)
6227 struct lpfc_hba *phba = vport->phba;
6231 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6232 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6233 /* reject the unsolicited RPS request and done with it */
6236 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6238 lpfc_read_lnk_stat(phba, mbox);
6239 mbox->context1 = (void *)((unsigned long)
6240 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6241 cmdiocb->iocb.ulpContext)); /* rx_id */
6242 mbox->context2 = lpfc_nlp_get(ndlp);
6243 mbox->vport = vport;
6244 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6245 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6246 != MBX_NOT_FINISHED)
6247 /* Mbox completion will send ELS Response */
6249 /* Decrement reference count used for the failed mbox
6253 mempool_free(mbox, phba->mbox_mem_pool);
6256 /* issue rejection response */
6257 stat.un.b.lsRjtRsvd0 = 0;
6258 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6259 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6260 stat.un.b.vendorUnique = 0;
6261 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6266 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6267 * @vport: pointer to a host virtual N_Port data structure.
6268 * @cmdiocb: pointer to lpfc command iocb data structure.
6269 * @ndlp: pointer to a node-list data structure.
6271 * This routine processes Read Timout Value (RTV) IOCB received as an
6272 * ELS unsolicited event. It first checks the remote port state. If the
6273 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6274 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6275 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6276 * Value (RTV) unsolicited IOCB event.
6278 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6279 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6280 * will be stored into the context1 field of the IOCB for the completion
6281 * callback function to the RPS Accept Response ELS IOCB command.
6284 * 0 - Successfully processed rtv iocb (currently always return 0)
6287 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6288 struct lpfc_nodelist *ndlp)
6290 struct lpfc_hba *phba = vport->phba;
6292 struct RTV_RSP *rtv_rsp;
6294 struct lpfc_iocbq *elsiocb;
6298 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6299 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6300 /* reject the unsolicited RPS request and done with it */
6303 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6304 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6305 lpfc_max_els_tries, ndlp,
6306 ndlp->nlp_DID, ELS_CMD_ACC);
6311 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6312 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6313 pcmd += sizeof(uint32_t); /* Skip past command */
6315 /* use the command's xri in the response */
6316 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6317 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6319 rtv_rsp = (struct RTV_RSP *)pcmd;
6321 /* populate RTV payload */
6322 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6323 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6324 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6325 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6326 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6328 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6329 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6330 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6331 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6332 "Data: x%x x%x x%x\n",
6333 elsiocb->iotag, elsiocb->iocb.ulpContext,
6334 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6336 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6337 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6338 phba->fc_stat.elsXmitACC++;
6339 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6340 lpfc_els_free_iocb(phba, elsiocb);
6344 /* issue rejection response */
6345 stat.un.b.lsRjtRsvd0 = 0;
6346 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6347 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6348 stat.un.b.vendorUnique = 0;
6349 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6353 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6354 * @vport: pointer to a host virtual N_Port data structure.
6355 * @cmdiocb: pointer to lpfc command iocb data structure.
6356 * @ndlp: pointer to a node-list data structure.
6358 * This routine processes Read Port Status (RPS) IOCB received as an
6359 * ELS unsolicited event. It first checks the remote port state. If the
6360 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6361 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6362 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6363 * for reading the HBA link statistics. It is for the callback function,
6364 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6365 * to actually sending out RPS Accept (ACC) response.
6368 * 0 - Successfully processed rps iocb (currently always return 0)
6371 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6372 struct lpfc_nodelist *ndlp)
6374 struct lpfc_hba *phba = vport->phba;
6378 struct lpfc_dmabuf *pcmd;
6382 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6383 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6384 /* reject the unsolicited RPS request and done with it */
6387 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6388 lp = (uint32_t *) pcmd->virt;
6389 flag = (be32_to_cpu(*lp++) & 0xf);
6393 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
6394 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
6395 sizeof(struct lpfc_name)) == 0))) {
6397 printk("Fix me....\n");
6399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6401 lpfc_read_lnk_stat(phba, mbox);
6402 mbox->context1 = (void *)((unsigned long)
6403 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6404 cmdiocb->iocb.ulpContext)); /* rx_id */
6405 mbox->context2 = lpfc_nlp_get(ndlp);
6406 mbox->vport = vport;
6407 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
6408 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6409 != MBX_NOT_FINISHED)
6410 /* Mbox completion will send ELS Response */
6412 /* Decrement reference count used for the failed mbox
6416 mempool_free(mbox, phba->mbox_mem_pool);
6421 /* issue rejection response */
6422 stat.un.b.lsRjtRsvd0 = 0;
6423 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6424 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6425 stat.un.b.vendorUnique = 0;
6426 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6430 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6431 * @vport: pointer to a host virtual N_Port data structure.
6432 * @ndlp: pointer to a node-list data structure.
6433 * @did: DID of the target.
6434 * @rrq: Pointer to the rrq struct.
6436 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6437 * Successful the the completion handler will clear the RRQ.
6440 * 0 - Successfully sent rrq els iocb.
6441 * 1 - Failed to send rrq els iocb.
6444 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6445 uint32_t did, struct lpfc_node_rrq *rrq)
6447 struct lpfc_hba *phba = vport->phba;
6448 struct RRQ *els_rrq;
6449 struct lpfc_iocbq *elsiocb;
6455 if (ndlp != rrq->ndlp)
6457 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6460 /* If ndlp is not NULL, we will bump the reference count on it */
6461 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6462 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6467 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6469 /* For RRQ request, remainder of payload is Exchange IDs */
6470 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6471 pcmd += sizeof(uint32_t);
6472 els_rrq = (struct RRQ *) pcmd;
6474 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
6475 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6476 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6477 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6478 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6481 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6482 "Issue RRQ: did:x%x",
6483 did, rrq->xritag, rrq->rxid);
6484 elsiocb->context_un.rrq = rrq;
6485 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6486 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6488 if (ret == IOCB_ERROR) {
6489 lpfc_els_free_iocb(phba, elsiocb);
6496 * lpfc_send_rrq - Sends ELS RRQ if needed.
6497 * @phba: pointer to lpfc hba data structure.
6498 * @rrq: pointer to the active rrq.
6500 * This routine will call the lpfc_issue_els_rrq if the rrq is
6501 * still active for the xri. If this function returns a failure then
6502 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6504 * Returns 0 Success.
6508 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6510 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6512 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6513 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6520 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6521 * @vport: pointer to a host virtual N_Port data structure.
6522 * @cmdsize: size of the ELS command.
6523 * @oldiocb: pointer to the original lpfc command iocb data structure.
6524 * @ndlp: pointer to a node-list data structure.
6526 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6527 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6529 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6530 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6531 * will be stored into the context1 field of the IOCB for the completion
6532 * callback function to the RPL Accept Response ELS command.
6535 * 0 - Successfully issued ACC RPL ELS command
6536 * 1 - Failed to issue ACC RPL ELS command
6539 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6540 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6542 struct lpfc_hba *phba = vport->phba;
6543 IOCB_t *icmd, *oldcmd;
6545 struct lpfc_iocbq *elsiocb;
6548 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6549 ndlp->nlp_DID, ELS_CMD_ACC);
6554 icmd = &elsiocb->iocb;
6555 oldcmd = &oldiocb->iocb;
6556 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6557 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
6559 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6560 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6561 pcmd += sizeof(uint16_t);
6562 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
6563 pcmd += sizeof(uint16_t);
6565 /* Setup the RPL ACC payload */
6566 rpl_rsp.listLen = be32_to_cpu(1);
6568 rpl_rsp.port_num_blk.portNum = 0;
6569 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
6570 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
6571 sizeof(struct lpfc_name));
6572 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
6573 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
6574 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6575 "0120 Xmit ELS RPL ACC response tag x%x "
6576 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6578 elsiocb->iotag, elsiocb->iocb.ulpContext,
6579 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6581 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6582 phba->fc_stat.elsXmitACC++;
6583 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6585 lpfc_els_free_iocb(phba, elsiocb);
6592 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
6593 * @vport: pointer to a host virtual N_Port data structure.
6594 * @cmdiocb: pointer to lpfc command iocb data structure.
6595 * @ndlp: pointer to a node-list data structure.
6597 * This routine processes Read Port List (RPL) IOCB received as an ELS
6598 * unsolicited event. It first checks the remote port state. If the remote
6599 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6600 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6601 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6602 * to accept the RPL.
6605 * 0 - Successfully processed rpl iocb (currently always return 0)
6608 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6609 struct lpfc_nodelist *ndlp)
6611 struct lpfc_dmabuf *pcmd;
6618 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6619 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
6620 /* issue rejection response */
6621 stat.un.b.lsRjtRsvd0 = 0;
6622 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6623 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6624 stat.un.b.vendorUnique = 0;
6625 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6627 /* rejected the unsolicited RPL request and done with it */
6631 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6632 lp = (uint32_t *) pcmd->virt;
6633 rpl = (RPL *) (lp + 1);
6634 maxsize = be32_to_cpu(rpl->maxsize);
6636 /* We support only one port */
6637 if ((rpl->index == 0) &&
6639 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
6640 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
6642 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
6644 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
6650 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
6651 * @vport: pointer to a virtual N_Port data structure.
6652 * @cmdiocb: pointer to lpfc command iocb data structure.
6653 * @ndlp: pointer to a node-list data structure.
6655 * This routine processes Fibre Channel Address Resolution Protocol
6656 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6657 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6658 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6659 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6660 * remote PortName is compared against the FC PortName stored in the @vport
6661 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6662 * compared against the FC NodeName stored in the @vport data structure.
6663 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6664 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6665 * invoked to send out FARP Response to the remote node. Before sending the
6666 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6667 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6668 * routine is invoked to log into the remote port first.
6671 * 0 - Either the FARP Match Mode not supported or successfully processed
6674 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6675 struct lpfc_nodelist *ndlp)
6677 struct lpfc_dmabuf *pcmd;
6681 uint32_t cmd, cnt, did;
6683 icmd = &cmdiocb->iocb;
6684 did = icmd->un.elsreq64.remoteID;
6685 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6686 lp = (uint32_t *) pcmd->virt;
6690 /* FARP-REQ received from DID <did> */
6691 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6692 "0601 FARP-REQ received from DID x%x\n", did);
6693 /* We will only support match on WWPN or WWNN */
6694 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
6699 /* If this FARP command is searching for my portname */
6700 if (fp->Mflags & FARP_MATCH_PORT) {
6701 if (memcmp(&fp->RportName, &vport->fc_portname,
6702 sizeof(struct lpfc_name)) == 0)
6706 /* If this FARP command is searching for my nodename */
6707 if (fp->Mflags & FARP_MATCH_NODE) {
6708 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
6709 sizeof(struct lpfc_name)) == 0)
6714 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6715 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6716 /* Log back into the node before sending the FARP. */
6717 if (fp->Rflags & FARP_REQUEST_PLOGI) {
6718 ndlp->nlp_prev_state = ndlp->nlp_state;
6719 lpfc_nlp_set_state(vport, ndlp,
6720 NLP_STE_PLOGI_ISSUE);
6721 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6724 /* Send a FARP response to that node */
6725 if (fp->Rflags & FARP_REQUEST_FARPR)
6726 lpfc_issue_els_farpr(vport, did, 0);
6733 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
6734 * @vport: pointer to a host virtual N_Port data structure.
6735 * @cmdiocb: pointer to lpfc command iocb data structure.
6736 * @ndlp: pointer to a node-list data structure.
6738 * This routine processes Fibre Channel Address Resolution Protocol
6739 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6740 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6741 * the FARP response request.
6744 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6747 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6748 struct lpfc_nodelist *ndlp)
6750 struct lpfc_dmabuf *pcmd;
6755 icmd = &cmdiocb->iocb;
6756 did = icmd->un.elsreq64.remoteID;
6757 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6758 lp = (uint32_t *) pcmd->virt;
6761 /* FARP-RSP received from DID <did> */
6762 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6763 "0600 FARP-RSP received from DID x%x\n", did);
6764 /* ACCEPT the Farp resp request */
6765 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6771 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
6772 * @vport: pointer to a host virtual N_Port data structure.
6773 * @cmdiocb: pointer to lpfc command iocb data structure.
6774 * @fan_ndlp: pointer to a node-list data structure.
6776 * This routine processes a Fabric Address Notification (FAN) IOCB
6777 * command received as an ELS unsolicited event. The FAN ELS command will
6778 * only be processed on a physical port (i.e., the @vport represents the
6779 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6780 * compared against those in the phba data structure. If any of those is
6781 * different, the lpfc_initial_flogi() routine is invoked to initialize
6782 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6783 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6784 * is invoked to register login to the fabric.
6787 * 0 - Successfully processed fan iocb (currently always return 0).
6790 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6791 struct lpfc_nodelist *fan_ndlp)
6793 struct lpfc_hba *phba = vport->phba;
6797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6798 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6800 /* FAN received; Fan does not have a reply sequence */
6801 if ((vport == phba->pport) &&
6802 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
6803 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
6804 sizeof(struct lpfc_name))) ||
6805 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
6806 sizeof(struct lpfc_name)))) {
6807 /* This port has switched fabrics. FLOGI is required */
6808 lpfc_issue_init_vfi(vport);
6810 /* FAN verified - skip FLOGI */
6811 vport->fc_myDID = vport->fc_prevDID;
6812 if (phba->sli_rev < LPFC_SLI_REV4)
6813 lpfc_issue_fabric_reglogin(vport);
6815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6816 "3138 Need register VFI: (x%x/%x)\n",
6817 vport->fc_prevDID, vport->fc_myDID);
6818 lpfc_issue_reg_vfi(vport);
6826 * lpfc_els_timeout - Handler funciton to the els timer
6827 * @ptr: holder for the timer function associated data.
6829 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6830 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6831 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6832 * up the worker thread. It is for the worker thread to invoke the routine
6833 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6836 lpfc_els_timeout(unsigned long ptr)
6838 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6839 struct lpfc_hba *phba = vport->phba;
6840 uint32_t tmo_posted;
6841 unsigned long iflag;
6843 spin_lock_irqsave(&vport->work_port_lock, iflag);
6844 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6845 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
6846 vport->work_port_events |= WORKER_ELS_TMO;
6847 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
6849 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
6850 lpfc_worker_wake_up(phba);
6856 * lpfc_els_timeout_handler - Process an els timeout event
6857 * @vport: pointer to a virtual N_Port data structure.
6859 * This routine is the actual handler function that processes an ELS timeout
6860 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6861 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6862 * invoking the lpfc_sli_issue_abort_iotag() routine.
6865 lpfc_els_timeout_handler(struct lpfc_vport *vport)
6867 struct lpfc_hba *phba = vport->phba;
6868 struct lpfc_sli_ring *pring;
6869 struct lpfc_iocbq *tmp_iocb, *piocb;
6871 struct lpfc_dmabuf *pcmd;
6872 uint32_t els_command = 0;
6874 uint32_t remote_ID = 0xffffffff;
6875 LIST_HEAD(abort_list);
6878 timeout = (uint32_t)(phba->fc_ratov << 1);
6880 pring = &phba->sli.ring[LPFC_ELS_RING];
6881 if ((phba->pport->load_flag & FC_UNLOADING))
6883 spin_lock_irq(&phba->hbalock);
6884 if (phba->sli_rev == LPFC_SLI_REV4)
6885 spin_lock(&pring->ring_lock);
6887 if ((phba->pport->load_flag & FC_UNLOADING)) {
6888 if (phba->sli_rev == LPFC_SLI_REV4)
6889 spin_unlock(&pring->ring_lock);
6890 spin_unlock_irq(&phba->hbalock);
6894 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6897 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6898 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6899 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
6902 if (piocb->vport != vport)
6905 pcmd = (struct lpfc_dmabuf *) piocb->context2;
6907 els_command = *(uint32_t *) (pcmd->virt);
6909 if (els_command == ELS_CMD_FARP ||
6910 els_command == ELS_CMD_FARPR ||
6911 els_command == ELS_CMD_FDISC)
6914 if (piocb->drvrTimeout > 0) {
6915 if (piocb->drvrTimeout >= timeout)
6916 piocb->drvrTimeout -= timeout;
6918 piocb->drvrTimeout = 0;
6922 remote_ID = 0xffffffff;
6923 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
6924 remote_ID = cmd->un.elsreq64.remoteID;
6926 struct lpfc_nodelist *ndlp;
6927 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
6928 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
6929 remote_ID = ndlp->nlp_DID;
6931 list_add_tail(&piocb->dlist, &abort_list);
6933 if (phba->sli_rev == LPFC_SLI_REV4)
6934 spin_unlock(&pring->ring_lock);
6935 spin_unlock_irq(&phba->hbalock);
6937 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6939 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6940 "0127 ELS timeout Data: x%x x%x x%x "
6941 "x%x\n", els_command,
6942 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6943 spin_lock_irq(&phba->hbalock);
6944 list_del_init(&piocb->dlist);
6945 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6946 spin_unlock_irq(&phba->hbalock);
6949 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
6950 if (!(phba->pport->load_flag & FC_UNLOADING))
6951 mod_timer(&vport->els_tmofunc,
6952 jiffies + msecs_to_jiffies(1000 * timeout));
6956 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
6957 * @vport: pointer to a host virtual N_Port data structure.
6959 * This routine is used to clean up all the outstanding ELS commands on a
6960 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6961 * routine. After that, it walks the ELS transmit queue to remove all the
6962 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6963 * the IOCBs with a non-NULL completion callback function, the callback
6964 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6965 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6966 * callback function, the IOCB will simply be released. Finally, it walks
6967 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6968 * completion queue IOCB that is associated with the @vport and is not
6969 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6970 * part of the discovery state machine) out to HBA by invoking the
6971 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6972 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6973 * the IOCBs are aborted when this function returns.
6976 lpfc_els_flush_cmd(struct lpfc_vport *vport)
6978 LIST_HEAD(abort_list);
6979 struct lpfc_hba *phba = vport->phba;
6980 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6981 struct lpfc_iocbq *tmp_iocb, *piocb;
6984 lpfc_fabric_abort_vport(vport);
6986 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
6987 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
6988 * ultimately grabs the ring_lock, the driver must splice the list into
6989 * a working list and release the locks before calling the abort.
6991 spin_lock_irq(&phba->hbalock);
6992 if (phba->sli_rev == LPFC_SLI_REV4)
6993 spin_lock(&pring->ring_lock);
6995 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6996 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6999 if (piocb->vport != vport)
7001 list_add_tail(&piocb->dlist, &abort_list);
7003 if (phba->sli_rev == LPFC_SLI_REV4)
7004 spin_unlock(&pring->ring_lock);
7005 spin_unlock_irq(&phba->hbalock);
7006 /* Abort each iocb on the aborted list and remove the dlist links. */
7007 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7008 spin_lock_irq(&phba->hbalock);
7009 list_del_init(&piocb->dlist);
7010 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7011 spin_unlock_irq(&phba->hbalock);
7013 if (!list_empty(&abort_list))
7014 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7015 "3387 abort list for txq not empty\n");
7016 INIT_LIST_HEAD(&abort_list);
7018 spin_lock_irq(&phba->hbalock);
7019 if (phba->sli_rev == LPFC_SLI_REV4)
7020 spin_lock(&pring->ring_lock);
7022 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7025 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7029 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7030 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7031 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7032 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7033 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7036 if (piocb->vport != vport)
7039 list_del_init(&piocb->list);
7040 list_add_tail(&piocb->list, &abort_list);
7042 if (phba->sli_rev == LPFC_SLI_REV4)
7043 spin_unlock(&pring->ring_lock);
7044 spin_unlock_irq(&phba->hbalock);
7046 /* Cancell all the IOCBs from the completions list */
7047 lpfc_sli_cancel_iocbs(phba, &abort_list,
7048 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7054 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7055 * @phba: pointer to lpfc hba data structure.
7057 * This routine is used to clean up all the outstanding ELS commands on a
7058 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7059 * routine. After that, it walks the ELS transmit queue to remove all the
7060 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7061 * the IOCBs with the completion callback function associated, the callback
7062 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7063 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7064 * callback function associated, the IOCB will simply be released. Finally,
7065 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7066 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7067 * management plane IOCBs that are not part of the discovery state machine)
7068 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7071 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7073 struct lpfc_vport *vport;
7074 list_for_each_entry(vport, &phba->port_list, listentry)
7075 lpfc_els_flush_cmd(vport);
7081 * lpfc_send_els_failure_event - Posts an ELS command failure event
7082 * @phba: Pointer to hba context object.
7083 * @cmdiocbp: Pointer to command iocb which reported error.
7084 * @rspiocbp: Pointer to response iocb which reported error.
7086 * This function sends an event when there is an ELS command
7090 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7091 struct lpfc_iocbq *cmdiocbp,
7092 struct lpfc_iocbq *rspiocbp)
7094 struct lpfc_vport *vport = cmdiocbp->vport;
7095 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7096 struct lpfc_lsrjt_event lsrjt_event;
7097 struct lpfc_fabric_event_header fabric_event;
7099 struct lpfc_nodelist *ndlp;
7102 ndlp = cmdiocbp->context1;
7103 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7106 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7107 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7108 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7109 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7110 sizeof(struct lpfc_name));
7111 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7112 sizeof(struct lpfc_name));
7113 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7114 cmdiocbp->context2)->virt);
7115 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7116 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7117 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7118 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7119 fc_host_post_vendor_event(shost,
7120 fc_get_event_number(),
7121 sizeof(lsrjt_event),
7122 (char *)&lsrjt_event,
7126 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7127 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7128 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7129 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7130 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7132 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7133 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7134 sizeof(struct lpfc_name));
7135 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7136 sizeof(struct lpfc_name));
7137 fc_host_post_vendor_event(shost,
7138 fc_get_event_number(),
7139 sizeof(fabric_event),
7140 (char *)&fabric_event,
7148 * lpfc_send_els_event - Posts unsolicited els event
7149 * @vport: Pointer to vport object.
7150 * @ndlp: Pointer FC node object.
7151 * @cmd: ELS command code.
7153 * This function posts an event when there is an incoming
7154 * unsolicited ELS command.
7157 lpfc_send_els_event(struct lpfc_vport *vport,
7158 struct lpfc_nodelist *ndlp,
7161 struct lpfc_els_event_header *els_data = NULL;
7162 struct lpfc_logo_event *logo_data = NULL;
7163 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7165 if (*payload == ELS_CMD_LOGO) {
7166 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7168 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7169 "0148 Failed to allocate memory "
7170 "for LOGO event\n");
7173 els_data = &logo_data->header;
7175 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7178 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7179 "0149 Failed to allocate memory "
7184 els_data->event_type = FC_REG_ELS_EVENT;
7187 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7190 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7193 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7196 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7197 /* Copy the WWPN in the LOGO payload */
7198 memcpy(logo_data->logo_wwpn, &payload[2],
7199 sizeof(struct lpfc_name));
7205 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7206 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7207 if (*payload == ELS_CMD_LOGO) {
7208 fc_host_post_vendor_event(shost,
7209 fc_get_event_number(),
7210 sizeof(struct lpfc_logo_event),
7215 fc_host_post_vendor_event(shost,
7216 fc_get_event_number(),
7217 sizeof(struct lpfc_els_event_header),
7228 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7229 * @phba: pointer to lpfc hba data structure.
7230 * @pring: pointer to a SLI ring.
7231 * @vport: pointer to a host virtual N_Port data structure.
7232 * @elsiocb: pointer to lpfc els command iocb data structure.
7234 * This routine is used for processing the IOCB associated with a unsolicited
7235 * event. It first determines whether there is an existing ndlp that matches
7236 * the DID from the unsolicited IOCB. If not, it will create a new one with
7237 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7238 * IOCB is then used to invoke the proper routine and to set up proper state
7239 * of the discovery state machine.
7242 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7243 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7245 struct Scsi_Host *shost;
7246 struct lpfc_nodelist *ndlp;
7249 uint32_t cmd, did, newnode;
7250 uint8_t rjt_exp, rjt_err = 0;
7251 IOCB_t *icmd = &elsiocb->iocb;
7253 if (!vport || !(elsiocb->context2))
7257 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7259 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7260 lpfc_post_buffer(phba, pring, 1);
7262 did = icmd->un.rcvels.remoteID;
7263 if (icmd->ulpStatus) {
7264 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7265 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7266 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7270 /* Check to see if link went down during discovery */
7271 if (lpfc_els_chk_latt(vport))
7274 /* Ignore traffic received during vport shutdown. */
7275 if (vport->load_flag & FC_UNLOADING)
7278 /* If NPort discovery is delayed drop incoming ELS */
7279 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7280 (cmd != ELS_CMD_PLOGI))
7283 ndlp = lpfc_findnode_did(vport, did);
7285 /* Cannot find existing Fabric ndlp, so allocate a new one */
7286 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7290 lpfc_nlp_init(vport, ndlp, did);
7291 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7293 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7294 ndlp->nlp_type |= NLP_FABRIC;
7295 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7296 ndlp = lpfc_enable_node(vport, ndlp,
7297 NLP_STE_UNUSED_NODE);
7300 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7302 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7303 ndlp->nlp_type |= NLP_FABRIC;
7304 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7305 /* This is similar to the new node path */
7306 ndlp = lpfc_nlp_get(ndlp);
7309 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7313 phba->fc_stat.elsRcvFrame++;
7316 * Do not process any unsolicited ELS commands
7317 * if the ndlp is in DEV_LOSS
7319 shost = lpfc_shost_from_vport(vport);
7320 spin_lock_irq(shost->host_lock);
7321 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7322 spin_unlock_irq(shost->host_lock);
7325 spin_unlock_irq(shost->host_lock);
7327 elsiocb->context1 = lpfc_nlp_get(ndlp);
7328 elsiocb->vport = vport;
7330 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7331 cmd &= ELS_CMD_MASK;
7333 /* ELS command <elsCmd> received from NPORT <did> */
7334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7335 "0112 ELS command x%x received from NPORT x%x "
7336 "Data: x%x x%x x%x x%x\n",
7337 cmd, did, vport->port_state, vport->fc_flag,
7338 vport->fc_myDID, vport->fc_prevDID);
7340 /* reject till our FLOGI completes */
7341 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7342 (cmd != ELS_CMD_FLOGI)) {
7343 rjt_err = LSRJT_UNABLE_TPC;
7344 rjt_exp = LSEXP_NOTHING_MORE;
7350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7351 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7352 did, vport->port_state, ndlp->nlp_flag);
7354 phba->fc_stat.elsRcvPLOGI++;
7355 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7356 if (phba->sli_rev == LPFC_SLI_REV4 &&
7357 (phba->pport->fc_flag & FC_PT2PT)) {
7358 vport->fc_prevDID = vport->fc_myDID;
7359 /* Our DID needs to be updated before registering
7360 * the vfi. This is done in lpfc_rcv_plogi but
7361 * that is called after the reg_vfi.
7363 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7364 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7365 "3312 Remote port assigned DID x%x "
7366 "%x\n", vport->fc_myDID,
7370 lpfc_send_els_event(vport, ndlp, payload);
7372 /* If Nport discovery is delayed, reject PLOGIs */
7373 if (vport->fc_flag & FC_DISC_DELAYED) {
7374 rjt_err = LSRJT_UNABLE_TPC;
7375 rjt_exp = LSEXP_NOTHING_MORE;
7378 if (vport->port_state < LPFC_DISC_AUTH) {
7379 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7380 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7381 rjt_err = LSRJT_UNABLE_TPC;
7382 rjt_exp = LSEXP_NOTHING_MORE;
7387 spin_lock_irq(shost->host_lock);
7388 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7389 spin_unlock_irq(shost->host_lock);
7391 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7396 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7397 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7398 did, vport->port_state, ndlp->nlp_flag);
7400 phba->fc_stat.elsRcvFLOGI++;
7401 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
7406 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7407 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7408 did, vport->port_state, ndlp->nlp_flag);
7410 phba->fc_stat.elsRcvLOGO++;
7411 lpfc_send_els_event(vport, ndlp, payload);
7412 if (vport->port_state < LPFC_DISC_AUTH) {
7413 rjt_err = LSRJT_UNABLE_TPC;
7414 rjt_exp = LSEXP_NOTHING_MORE;
7417 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
7420 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7421 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7422 did, vport->port_state, ndlp->nlp_flag);
7424 phba->fc_stat.elsRcvPRLO++;
7425 lpfc_send_els_event(vport, ndlp, payload);
7426 if (vport->port_state < LPFC_DISC_AUTH) {
7427 rjt_err = LSRJT_UNABLE_TPC;
7428 rjt_exp = LSEXP_NOTHING_MORE;
7431 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
7434 phba->fc_stat.elsRcvLCB++;
7435 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7438 phba->fc_stat.elsRcvRDP++;
7439 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7442 phba->fc_stat.elsRcvRSCN++;
7443 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
7448 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7449 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7450 did, vport->port_state, ndlp->nlp_flag);
7452 lpfc_send_els_event(vport, ndlp, payload);
7453 phba->fc_stat.elsRcvADISC++;
7454 if (vport->port_state < LPFC_DISC_AUTH) {
7455 rjt_err = LSRJT_UNABLE_TPC;
7456 rjt_exp = LSEXP_NOTHING_MORE;
7459 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7463 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7464 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7465 did, vport->port_state, ndlp->nlp_flag);
7467 phba->fc_stat.elsRcvPDISC++;
7468 if (vport->port_state < LPFC_DISC_AUTH) {
7469 rjt_err = LSRJT_UNABLE_TPC;
7470 rjt_exp = LSEXP_NOTHING_MORE;
7473 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7477 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7478 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7479 did, vport->port_state, ndlp->nlp_flag);
7481 phba->fc_stat.elsRcvFARPR++;
7482 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
7485 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7486 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7487 did, vport->port_state, ndlp->nlp_flag);
7489 phba->fc_stat.elsRcvFARP++;
7490 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
7493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7494 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7495 did, vport->port_state, ndlp->nlp_flag);
7497 phba->fc_stat.elsRcvFAN++;
7498 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
7501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7502 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7503 did, vport->port_state, ndlp->nlp_flag);
7505 phba->fc_stat.elsRcvPRLI++;
7506 if (vport->port_state < LPFC_DISC_AUTH) {
7507 rjt_err = LSRJT_UNABLE_TPC;
7508 rjt_exp = LSEXP_NOTHING_MORE;
7511 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
7514 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7515 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7516 did, vport->port_state, ndlp->nlp_flag);
7518 phba->fc_stat.elsRcvLIRR++;
7519 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
7524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7525 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7526 did, vport->port_state, ndlp->nlp_flag);
7528 phba->fc_stat.elsRcvRLS++;
7529 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7535 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7536 did, vport->port_state, ndlp->nlp_flag);
7538 phba->fc_stat.elsRcvRPS++;
7539 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
7544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7545 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7546 did, vport->port_state, ndlp->nlp_flag);
7548 phba->fc_stat.elsRcvRPL++;
7549 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
7554 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7555 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7556 did, vport->port_state, ndlp->nlp_flag);
7558 phba->fc_stat.elsRcvRNID++;
7559 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
7564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7565 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7566 did, vport->port_state, ndlp->nlp_flag);
7567 phba->fc_stat.elsRcvRTV++;
7568 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
7573 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7574 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7575 did, vport->port_state, ndlp->nlp_flag);
7577 phba->fc_stat.elsRcvRRQ++;
7578 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
7583 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7584 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7585 did, vport->port_state, ndlp->nlp_flag);
7587 phba->fc_stat.elsRcvECHO++;
7588 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
7593 /* receive this due to exchange closed */
7594 rjt_err = LSRJT_UNABLE_TPC;
7595 rjt_exp = LSEXP_INVALID_OX_RX;
7598 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7599 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7600 cmd, did, vport->port_state);
7602 /* Unsupported ELS command, reject */
7603 rjt_err = LSRJT_CMD_UNSUPPORTED;
7604 rjt_exp = LSEXP_NOTHING_MORE;
7606 /* Unknown ELS command <elsCmd> received from NPORT <did> */
7607 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7608 "0115 Unknown ELS command x%x "
7609 "received from NPORT x%x\n", cmd, did);
7616 /* check if need to LS_RJT received ELS cmd */
7618 memset(&stat, 0, sizeof(stat));
7619 stat.un.b.lsRjtRsnCode = rjt_err;
7620 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
7621 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
7625 lpfc_nlp_put(elsiocb->context1);
7626 elsiocb->context1 = NULL;
7630 if (vport && !(vport->load_flag & FC_UNLOADING))
7631 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7632 "0111 Dropping received ELS cmd "
7633 "Data: x%x x%x x%x\n",
7634 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
7635 phba->fc_stat.elsRcvDrop++;
7639 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
7640 * @phba: pointer to lpfc hba data structure.
7641 * @pring: pointer to a SLI ring.
7642 * @elsiocb: pointer to lpfc els iocb data structure.
7644 * This routine is used to process an unsolicited event received from a SLI
7645 * (Service Level Interface) ring. The actual processing of the data buffer
7646 * associated with the unsolicited event is done by invoking the routine
7647 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7648 * SLI ring on which the unsolicited event was received.
7651 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7652 struct lpfc_iocbq *elsiocb)
7654 struct lpfc_vport *vport = phba->pport;
7655 IOCB_t *icmd = &elsiocb->iocb;
7657 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
7658 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
7660 elsiocb->context1 = NULL;
7661 elsiocb->context2 = NULL;
7662 elsiocb->context3 = NULL;
7664 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
7665 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
7666 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
7667 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
7668 IOERR_RCV_BUFFER_WAITING) {
7669 phba->fc_stat.NoRcvBuf++;
7670 /* Not enough posted buffers; Try posting more buffers */
7671 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
7672 lpfc_post_buffer(phba, pring, 0);
7676 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7677 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
7678 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
7679 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
7680 vport = phba->pport;
7682 vport = lpfc_find_vport_by_vpid(phba,
7683 icmd->unsli3.rcvsli3.vpi);
7686 /* If there are no BDEs associated
7687 * with this IOCB, there is nothing to do.
7689 if (icmd->ulpBdeCount == 0)
7692 /* type of ELS cmd is first 32bit word
7695 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
7696 elsiocb->context2 = bdeBuf1;
7698 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
7699 icmd->un.cont64[0].addrLow);
7700 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
7704 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7706 * The different unsolicited event handlers would tell us
7707 * if they are done with "mp" by setting context2 to NULL.
7709 if (elsiocb->context2) {
7710 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
7711 elsiocb->context2 = NULL;
7714 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
7715 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
7716 icmd->ulpBdeCount == 2) {
7717 elsiocb->context2 = bdeBuf2;
7718 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7719 /* free mp if we are done with it */
7720 if (elsiocb->context2) {
7721 lpfc_in_buf_free(phba, elsiocb->context2);
7722 elsiocb->context2 = NULL;
7728 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
7729 * @phba: pointer to lpfc hba data structure.
7730 * @vport: pointer to a virtual N_Port data structure.
7732 * This routine issues a Port Login (PLOGI) to the Name Server with
7733 * State Change Request (SCR) for a @vport. This routine will create an
7734 * ndlp for the Name Server associated to the @vport if such node does
7735 * not already exist. The PLOGI to Name Server is issued by invoking the
7736 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
7737 * (FDMI) is configured to the @vport, a FDMI node will be created and
7738 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
7741 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
7743 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
7744 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7747 * If lpfc_delay_discovery parameter is set and the clean address
7748 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7751 spin_lock_irq(shost->host_lock);
7752 if (vport->fc_flag & FC_DISC_DELAYED) {
7753 spin_unlock_irq(shost->host_lock);
7754 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
7755 "3334 Delay fc port discovery for %d seconds\n",
7757 mod_timer(&vport->delayed_disc_tmo,
7758 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
7761 spin_unlock_irq(shost->host_lock);
7763 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7765 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7767 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7768 lpfc_disc_start(vport);
7771 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7773 "0251 NameServer login: no memory\n");
7776 lpfc_nlp_init(vport, ndlp, NameServer_DID);
7777 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7778 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
7780 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7781 lpfc_disc_start(vport);
7784 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7785 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7786 "0348 NameServer login: node freed\n");
7790 ndlp->nlp_type |= NLP_FABRIC;
7792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7794 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7795 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7796 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7797 "0252 Cannot issue NameServer login\n");
7801 if (vport->cfg_fdmi_on & LPFC_FDMI_SUPPORT) {
7802 /* If this is the first time, allocate an ndlp and initialize
7803 * it. Otherwise, make sure the node is enabled and then do the
7806 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7808 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7811 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7812 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7816 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7817 ndlp_fdmi = lpfc_enable_node(vport,
7822 lpfc_nlp_set_state(vport, ndlp_fdmi,
7823 NLP_STE_PLOGI_ISSUE);
7824 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
7830 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
7831 * @phba: pointer to lpfc hba data structure.
7832 * @pmb: pointer to the driver internal queue element for mailbox command.
7834 * This routine is the completion callback function to register new vport
7835 * mailbox command. If the new vport mailbox command completes successfully,
7836 * the fabric registration login shall be performed on physical port (the
7837 * new vport created is actually a physical port, with VPI 0) or the port
7838 * login to Name Server for State Change Request (SCR) will be performed
7839 * on virtual port (real virtual port, with VPI greater than 0).
7842 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7844 struct lpfc_vport *vport = pmb->vport;
7845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7846 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
7847 MAILBOX_t *mb = &pmb->u.mb;
7850 spin_lock_irq(shost->host_lock);
7851 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7852 spin_unlock_irq(shost->host_lock);
7854 if (mb->mbxStatus) {
7855 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7856 "0915 Register VPI failed : Status: x%x"
7857 " upd bit: x%x \n", mb->mbxStatus,
7858 mb->un.varRegVpi.upd);
7859 if (phba->sli_rev == LPFC_SLI_REV4 &&
7860 mb->un.varRegVpi.upd)
7861 goto mbox_err_exit ;
7863 switch (mb->mbxStatus) {
7864 case 0x11: /* unsupported feature */
7865 case 0x9603: /* max_vpi exceeded */
7866 case 0x9602: /* Link event since CLEAR_LA */
7867 /* giving up on vport registration */
7868 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7869 spin_lock_irq(shost->host_lock);
7870 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7871 spin_unlock_irq(shost->host_lock);
7872 lpfc_can_disctmo(vport);
7874 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7876 spin_lock_irq(shost->host_lock);
7877 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7878 spin_unlock_irq(shost->host_lock);
7879 lpfc_init_vpi(phba, pmb, vport->vpi);
7881 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7882 rc = lpfc_sli_issue_mbox(phba, pmb,
7884 if (rc == MBX_NOT_FINISHED) {
7885 lpfc_printf_vlog(vport,
7887 "2732 Failed to issue INIT_VPI"
7888 " mailbox command\n");
7895 /* Try to recover from this error */
7896 if (phba->sli_rev == LPFC_SLI_REV4)
7897 lpfc_sli4_unreg_all_rpis(vport);
7898 lpfc_mbx_unreg_vpi(vport);
7899 spin_lock_irq(shost->host_lock);
7900 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7901 spin_unlock_irq(shost->host_lock);
7902 if (vport->port_type == LPFC_PHYSICAL_PORT
7903 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
7904 lpfc_issue_init_vfi(vport);
7906 lpfc_initial_fdisc(vport);
7910 spin_lock_irq(shost->host_lock);
7911 vport->vpi_state |= LPFC_VPI_REGISTERED;
7912 spin_unlock_irq(shost->host_lock);
7913 if (vport == phba->pport) {
7914 if (phba->sli_rev < LPFC_SLI_REV4)
7915 lpfc_issue_fabric_reglogin(vport);
7918 * If the physical port is instantiated using
7919 * FDISC, do not start vport discovery.
7921 if (vport->port_state != LPFC_FDISC)
7922 lpfc_start_fdiscs(phba);
7923 lpfc_do_scr_ns_plogi(phba, vport);
7926 lpfc_do_scr_ns_plogi(phba, vport);
7929 /* Now, we decrement the ndlp reference count held for this
7934 mempool_free(pmb, phba->mbox_mem_pool);
7939 * lpfc_register_new_vport - Register a new vport with a HBA
7940 * @phba: pointer to lpfc hba data structure.
7941 * @vport: pointer to a host virtual N_Port data structure.
7942 * @ndlp: pointer to a node-list data structure.
7944 * This routine registers the @vport as a new virtual port with a HBA.
7945 * It is done through a registering vpi mailbox command.
7948 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7949 struct lpfc_nodelist *ndlp)
7951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7954 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7956 lpfc_reg_vpi(vport, mbox);
7957 mbox->vport = vport;
7958 mbox->context2 = lpfc_nlp_get(ndlp);
7959 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
7960 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7961 == MBX_NOT_FINISHED) {
7962 /* mailbox command not success, decrement ndlp
7963 * reference count for this command
7966 mempool_free(mbox, phba->mbox_mem_pool);
7968 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7969 "0253 Register VPI: Can't send mbox\n");
7973 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7974 "0254 Register VPI: no memory\n");
7980 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7981 spin_lock_irq(shost->host_lock);
7982 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7983 spin_unlock_irq(shost->host_lock);
7988 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
7989 * @phba: pointer to lpfc hba data structure.
7991 * This routine cancels the retry delay timers to all the vports.
7994 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
7996 struct lpfc_vport **vports;
7997 struct lpfc_nodelist *ndlp;
7998 uint32_t link_state;
8001 /* Treat this failure as linkdown for all vports */
8002 link_state = phba->link_state;
8003 lpfc_linkdown(phba);
8004 phba->link_state = link_state;
8006 vports = lpfc_create_vport_work_array(phba);
8009 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8010 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8012 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8013 lpfc_els_flush_cmd(vports[i]);
8015 lpfc_destroy_vport_work_array(phba, vports);
8020 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8021 * @phba: pointer to lpfc hba data structure.
8023 * This routine abort all pending discovery commands and
8024 * start a timer to retry FLOGI for the physical port
8028 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8030 struct lpfc_nodelist *ndlp;
8031 struct Scsi_Host *shost;
8033 /* Cancel the all vports retry delay retry timers */
8034 lpfc_cancel_all_vport_retry_delay_timer(phba);
8036 /* If fabric require FLOGI, then re-instantiate physical login */
8037 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8041 shost = lpfc_shost_from_vport(phba->pport);
8042 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8043 spin_lock_irq(shost->host_lock);
8044 ndlp->nlp_flag |= NLP_DELAY_TMO;
8045 spin_unlock_irq(shost->host_lock);
8046 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8047 phba->pport->port_state = LPFC_FLOGI;
8052 * lpfc_fabric_login_reqd - Check if FLOGI required.
8053 * @phba: pointer to lpfc hba data structure.
8054 * @cmdiocb: pointer to FDISC command iocb.
8055 * @rspiocb: pointer to FDISC response iocb.
8057 * This routine checks if a FLOGI is reguired for FDISC
8061 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8062 struct lpfc_iocbq *cmdiocb,
8063 struct lpfc_iocbq *rspiocb)
8066 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8067 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8074 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8075 * @phba: pointer to lpfc hba data structure.
8076 * @cmdiocb: pointer to lpfc command iocb data structure.
8077 * @rspiocb: pointer to lpfc response iocb data structure.
8079 * This routine is the completion callback function to a Fabric Discover
8080 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8081 * single threaded, each FDISC completion callback function will reset
8082 * the discovery timer for all vports such that the timers will not get
8083 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8084 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8085 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8086 * assigned to the vport has been changed with the completion of the FDISC
8087 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8088 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8089 * routine is invoked to register new vport with the HBA. Otherwise, the
8090 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8091 * Server for State Change Request (SCR).
8094 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8095 struct lpfc_iocbq *rspiocb)
8097 struct lpfc_vport *vport = cmdiocb->vport;
8098 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8099 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8100 struct lpfc_nodelist *np;
8101 struct lpfc_nodelist *next_np;
8102 IOCB_t *irsp = &rspiocb->iocb;
8103 struct lpfc_iocbq *piocb;
8104 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8105 struct serv_parm *sp;
8106 uint8_t fabric_param_changed;
8108 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8109 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8110 irsp->ulpStatus, irsp->un.ulpWord[4],
8112 /* Since all FDISCs are being single threaded, we
8113 * must reset the discovery timer for ALL vports
8114 * waiting to send FDISC when one completes.
8116 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8117 lpfc_set_disctmo(piocb->vport);
8120 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8121 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8122 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8124 if (irsp->ulpStatus) {
8126 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8127 lpfc_retry_pport_discovery(phba);
8131 /* Check for retry */
8132 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8135 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8136 "0126 FDISC failed. (x%x/x%x)\n",
8137 irsp->ulpStatus, irsp->un.ulpWord[4]);
8140 spin_lock_irq(shost->host_lock);
8141 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8142 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8143 vport->fc_flag |= FC_FABRIC;
8144 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8145 vport->fc_flag |= FC_PUBLIC_LOOP;
8146 spin_unlock_irq(shost->host_lock);
8148 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8149 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8150 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8153 sp = prsp->virt + sizeof(uint32_t);
8154 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8155 memcpy(&vport->fabric_portname, &sp->portName,
8156 sizeof(struct lpfc_name));
8157 memcpy(&vport->fabric_nodename, &sp->nodeName,
8158 sizeof(struct lpfc_name));
8159 if (fabric_param_changed &&
8160 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8161 /* If our NportID changed, we need to ensure all
8162 * remaining NPORTs get unreg_login'ed so we can
8165 list_for_each_entry_safe(np, next_np,
8166 &vport->fc_nodes, nlp_listp) {
8167 if (!NLP_CHK_NODE_ACT(ndlp) ||
8168 (np->nlp_state != NLP_STE_NPR_NODE) ||
8169 !(np->nlp_flag & NLP_NPR_ADISC))
8171 spin_lock_irq(shost->host_lock);
8172 np->nlp_flag &= ~NLP_NPR_ADISC;
8173 spin_unlock_irq(shost->host_lock);
8174 lpfc_unreg_rpi(vport, np);
8176 lpfc_cleanup_pending_mbox(vport);
8178 if (phba->sli_rev == LPFC_SLI_REV4)
8179 lpfc_sli4_unreg_all_rpis(vport);
8181 lpfc_mbx_unreg_vpi(vport);
8182 spin_lock_irq(shost->host_lock);
8183 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8184 if (phba->sli_rev == LPFC_SLI_REV4)
8185 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8187 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8188 spin_unlock_irq(shost->host_lock);
8189 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8190 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8192 * Driver needs to re-reg VPI in order for f/w
8193 * to update the MAC address.
8195 lpfc_register_new_vport(phba, vport, ndlp);
8199 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8200 lpfc_issue_init_vpi(vport);
8201 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8202 lpfc_register_new_vport(phba, vport, ndlp);
8204 lpfc_do_scr_ns_plogi(phba, vport);
8207 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8208 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8209 /* Cancel discovery timer */
8210 lpfc_can_disctmo(vport);
8213 lpfc_els_free_iocb(phba, cmdiocb);
8217 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8218 * @vport: pointer to a virtual N_Port data structure.
8219 * @ndlp: pointer to a node-list data structure.
8220 * @retry: number of retries to the command IOCB.
8222 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8223 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8224 * routine to issue the IOCB, which makes sure only one outstanding fabric
8225 * IOCB will be sent off HBA at any given time.
8227 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8228 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8229 * will be stored into the context1 field of the IOCB for the completion
8230 * callback function to the FDISC ELS command.
8233 * 0 - Successfully issued fdisc iocb command
8234 * 1 - Failed to issue fdisc iocb command
8237 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8240 struct lpfc_hba *phba = vport->phba;
8242 struct lpfc_iocbq *elsiocb;
8243 struct serv_parm *sp;
8246 int did = ndlp->nlp_DID;
8249 vport->port_state = LPFC_FDISC;
8250 vport->fc_myDID = 0;
8251 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8252 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8255 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8256 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8257 "0255 Issue FDISC: no IOCB\n");
8261 icmd = &elsiocb->iocb;
8262 icmd->un.elsreq64.myID = 0;
8263 icmd->un.elsreq64.fl = 1;
8266 * SLI3 ports require a different context type value than SLI4.
8267 * Catch SLI3 ports here and override the prep.
8269 if (phba->sli_rev == LPFC_SLI_REV3) {
8274 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8275 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8276 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8277 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8278 sp = (struct serv_parm *) pcmd;
8279 /* Setup CSPs accordingly for Fabric */
8280 sp->cmn.e_d_tov = 0;
8281 sp->cmn.w2.r_a_tov = 0;
8282 sp->cmn.virtual_fabric_support = 0;
8283 sp->cls1.classValid = 0;
8284 sp->cls2.seqDelivery = 1;
8285 sp->cls3.seqDelivery = 1;
8287 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8288 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8289 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8290 pcmd += sizeof(uint32_t); /* Port Name */
8291 memcpy(pcmd, &vport->fc_portname, 8);
8292 pcmd += sizeof(uint32_t); /* Node Name */
8293 pcmd += sizeof(uint32_t); /* Node Name */
8294 memcpy(pcmd, &vport->fc_nodename, 8);
8296 lpfc_set_disctmo(vport);
8298 phba->fc_stat.elsXmitFDISC++;
8299 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8301 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8302 "Issue FDISC: did:x%x",
8305 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8306 if (rc == IOCB_ERROR) {
8307 lpfc_els_free_iocb(phba, elsiocb);
8308 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8309 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8310 "0256 Issue FDISC: Cannot send IOCB\n");
8313 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
8318 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8319 * @phba: pointer to lpfc hba data structure.
8320 * @cmdiocb: pointer to lpfc command iocb data structure.
8321 * @rspiocb: pointer to lpfc response iocb data structure.
8323 * This routine is the completion callback function to the issuing of a LOGO
8324 * ELS command off a vport. It frees the command IOCB and then decrement the
8325 * reference count held on ndlp for this completion function, indicating that
8326 * the reference to the ndlp is no long needed. Note that the
8327 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8328 * callback function and an additional explicit ndlp reference decrementation
8329 * will trigger the actual release of the ndlp.
8332 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8333 struct lpfc_iocbq *rspiocb)
8335 struct lpfc_vport *vport = cmdiocb->vport;
8337 struct lpfc_nodelist *ndlp;
8338 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8340 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
8341 irsp = &rspiocb->iocb;
8342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8343 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8344 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
8346 lpfc_els_free_iocb(phba, cmdiocb);
8347 vport->unreg_vpi_cmpl = VPORT_ERROR;
8349 /* Trigger the release of the ndlp after logo */
8352 /* NPIV LOGO completes to NPort <nlp_DID> */
8353 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8354 "2928 NPIV LOGO completes to NPort x%x "
8355 "Data: x%x x%x x%x x%x\n",
8356 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8357 irsp->ulpTimeout, vport->num_disc_nodes);
8359 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8360 spin_lock_irq(shost->host_lock);
8361 vport->fc_flag &= ~FC_NDISC_ACTIVE;
8362 vport->fc_flag &= ~FC_FABRIC;
8363 spin_unlock_irq(shost->host_lock);
8364 lpfc_can_disctmo(vport);
8369 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8370 * @vport: pointer to a virtual N_Port data structure.
8371 * @ndlp: pointer to a node-list data structure.
8373 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8375 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8376 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8377 * will be stored into the context1 field of the IOCB for the completion
8378 * callback function to the LOGO ELS command.
8381 * 0 - Successfully issued logo off the @vport
8382 * 1 - Failed to issue logo off the @vport
8385 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8388 struct lpfc_hba *phba = vport->phba;
8389 struct lpfc_iocbq *elsiocb;
8393 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8394 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8399 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8400 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8401 pcmd += sizeof(uint32_t);
8403 /* Fill in LOGO payload */
8404 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8405 pcmd += sizeof(uint32_t);
8406 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8408 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8409 "Issue LOGO npiv did:x%x flg:x%x",
8410 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8412 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8413 spin_lock_irq(shost->host_lock);
8414 ndlp->nlp_flag |= NLP_LOGO_SND;
8415 spin_unlock_irq(shost->host_lock);
8416 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8418 spin_lock_irq(shost->host_lock);
8419 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8420 spin_unlock_irq(shost->host_lock);
8421 lpfc_els_free_iocb(phba, elsiocb);
8428 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
8429 * @ptr: holder for the timer function associated data.
8431 * This routine is invoked by the fabric iocb block timer after
8432 * timeout. It posts the fabric iocb block timeout event by setting the
8433 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8434 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8435 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8436 * posted event WORKER_FABRIC_BLOCK_TMO.
8439 lpfc_fabric_block_timeout(unsigned long ptr)
8441 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8442 unsigned long iflags;
8443 uint32_t tmo_posted;
8445 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8446 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8448 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8449 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8452 lpfc_worker_wake_up(phba);
8457 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
8458 * @phba: pointer to lpfc hba data structure.
8460 * This routine issues one fabric iocb from the driver internal list to
8461 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8462 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8463 * remove one pending fabric iocb from the driver internal list and invokes
8464 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8467 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8469 struct lpfc_iocbq *iocb;
8470 unsigned long iflags;
8476 spin_lock_irqsave(&phba->hbalock, iflags);
8477 /* Post any pending iocb to the SLI layer */
8478 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8479 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8482 /* Increment fabric iocb count to hold the position */
8483 atomic_inc(&phba->fabric_iocb_count);
8485 spin_unlock_irqrestore(&phba->hbalock, iflags);
8487 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8488 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8489 iocb->iocb_flag |= LPFC_IO_FABRIC;
8491 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8492 "Fabric sched1: ste:x%x",
8493 iocb->vport->port_state, 0, 0);
8495 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
8497 if (ret == IOCB_ERROR) {
8498 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8499 iocb->fabric_iocb_cmpl = NULL;
8500 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8502 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8503 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8504 iocb->iocb_cmpl(phba, iocb, iocb);
8506 atomic_dec(&phba->fabric_iocb_count);
8515 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
8516 * @phba: pointer to lpfc hba data structure.
8518 * This routine unblocks the issuing fabric iocb command. The function
8519 * will clear the fabric iocb block bit and then invoke the routine
8520 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8521 * from the driver internal fabric iocb list.
8524 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8526 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8528 lpfc_resume_fabric_iocbs(phba);
8533 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
8534 * @phba: pointer to lpfc hba data structure.
8536 * This routine blocks the issuing fabric iocb for a specified amount of
8537 * time (currently 100 ms). This is done by set the fabric iocb block bit
8538 * and set up a timeout timer for 100ms. When the block bit is set, no more
8539 * fabric iocb will be issued out of the HBA.
8542 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
8546 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8547 /* Start a timer to unblock fabric iocbs after 100ms */
8549 mod_timer(&phba->fabric_block_timer,
8550 jiffies + msecs_to_jiffies(100));
8556 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
8557 * @phba: pointer to lpfc hba data structure.
8558 * @cmdiocb: pointer to lpfc command iocb data structure.
8559 * @rspiocb: pointer to lpfc response iocb data structure.
8561 * This routine is the callback function that is put to the fabric iocb's
8562 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8563 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8564 * function first restores and invokes the original iocb's callback function
8565 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8566 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8569 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8570 struct lpfc_iocbq *rspiocb)
8574 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
8577 switch (rspiocb->iocb.ulpStatus) {
8578 case IOSTAT_NPORT_RJT:
8579 case IOSTAT_FABRIC_RJT:
8580 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
8581 lpfc_block_fabric_iocbs(phba);
8585 case IOSTAT_NPORT_BSY:
8586 case IOSTAT_FABRIC_BSY:
8587 lpfc_block_fabric_iocbs(phba);
8591 stat.un.lsRjtError =
8592 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
8593 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
8594 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
8595 lpfc_block_fabric_iocbs(phba);
8599 if (atomic_read(&phba->fabric_iocb_count) == 0)
8602 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
8603 cmdiocb->fabric_iocb_cmpl = NULL;
8604 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
8605 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
8607 atomic_dec(&phba->fabric_iocb_count);
8608 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
8609 /* Post any pending iocbs to HBA */
8610 lpfc_resume_fabric_iocbs(phba);
8615 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
8616 * @phba: pointer to lpfc hba data structure.
8617 * @iocb: pointer to lpfc command iocb data structure.
8619 * This routine is used as the top-level API for issuing a fabric iocb command
8620 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8621 * function makes sure that only one fabric bound iocb will be outstanding at
8622 * any given time. As such, this function will first check to see whether there
8623 * is already an outstanding fabric iocb on the wire. If so, it will put the
8624 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8625 * issued later. Otherwise, it will issue the iocb on the wire and update the
8626 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8628 * Note, this implementation has a potential sending out fabric IOCBs out of
8629 * order. The problem is caused by the construction of the "ready" boolen does
8630 * not include the condition that the internal fabric IOCB list is empty. As
8631 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8632 * ahead of the fabric IOCBs in the internal list.
8635 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8636 * IOCB_ERROR - failed to issue fabric iocb
8639 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
8641 unsigned long iflags;
8645 if (atomic_read(&phba->fabric_iocb_count) > 1)
8648 spin_lock_irqsave(&phba->hbalock, iflags);
8649 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
8650 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8653 /* Increment fabric iocb count to hold the position */
8654 atomic_inc(&phba->fabric_iocb_count);
8655 spin_unlock_irqrestore(&phba->hbalock, iflags);
8657 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8658 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8659 iocb->iocb_flag |= LPFC_IO_FABRIC;
8661 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8662 "Fabric sched2: ste:x%x",
8663 iocb->vport->port_state, 0, 0);
8665 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
8667 if (ret == IOCB_ERROR) {
8668 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8669 iocb->fabric_iocb_cmpl = NULL;
8670 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8671 atomic_dec(&phba->fabric_iocb_count);
8674 spin_lock_irqsave(&phba->hbalock, iflags);
8675 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
8676 spin_unlock_irqrestore(&phba->hbalock, iflags);
8683 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
8684 * @vport: pointer to a virtual N_Port data structure.
8686 * This routine aborts all the IOCBs associated with a @vport from the
8687 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8688 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8689 * list, removes each IOCB associated with the @vport off the list, set the
8690 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8691 * associated with the IOCB.
8693 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
8695 LIST_HEAD(completions);
8696 struct lpfc_hba *phba = vport->phba;
8697 struct lpfc_iocbq *tmp_iocb, *piocb;
8699 spin_lock_irq(&phba->hbalock);
8700 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8703 if (piocb->vport != vport)
8706 list_move_tail(&piocb->list, &completions);
8708 spin_unlock_irq(&phba->hbalock);
8710 /* Cancel all the IOCBs from the completions list */
8711 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8716 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
8717 * @ndlp: pointer to a node-list data structure.
8719 * This routine aborts all the IOCBs associated with an @ndlp from the
8720 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8721 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8722 * list, removes each IOCB associated with the @ndlp off the list, set the
8723 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8724 * associated with the IOCB.
8726 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
8728 LIST_HEAD(completions);
8729 struct lpfc_hba *phba = ndlp->phba;
8730 struct lpfc_iocbq *tmp_iocb, *piocb;
8731 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8733 spin_lock_irq(&phba->hbalock);
8734 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8736 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
8738 list_move_tail(&piocb->list, &completions);
8741 spin_unlock_irq(&phba->hbalock);
8743 /* Cancel all the IOCBs from the completions list */
8744 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8749 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
8750 * @phba: pointer to lpfc hba data structure.
8752 * This routine aborts all the IOCBs currently on the driver internal
8753 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
8754 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
8755 * list, removes IOCBs off the list, set the status feild to
8756 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8759 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
8761 LIST_HEAD(completions);
8763 spin_lock_irq(&phba->hbalock);
8764 list_splice_init(&phba->fabric_iocb_list, &completions);
8765 spin_unlock_irq(&phba->hbalock);
8767 /* Cancel all the IOCBs from the completions list */
8768 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8773 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8774 * @vport: pointer to lpfc vport data structure.
8776 * This routine is invoked by the vport cleanup for deletions and the cleanup
8777 * for an ndlp on removal.
8780 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8782 struct lpfc_hba *phba = vport->phba;
8783 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8784 unsigned long iflag = 0;
8786 spin_lock_irqsave(&phba->hbalock, iflag);
8787 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8788 list_for_each_entry_safe(sglq_entry, sglq_next,
8789 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8790 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8791 sglq_entry->ndlp = NULL;
8793 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8794 spin_unlock_irqrestore(&phba->hbalock, iflag);
8799 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8800 * @phba: pointer to lpfc hba data structure.
8801 * @axri: pointer to the els xri abort wcqe structure.
8803 * This routine is invoked by the worker thread to process a SLI4 slow-path
8807 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8808 struct sli4_wcqe_xri_aborted *axri)
8810 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
8811 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
8814 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8815 unsigned long iflag = 0;
8816 struct lpfc_nodelist *ndlp;
8817 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
8819 spin_lock_irqsave(&phba->hbalock, iflag);
8820 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8821 list_for_each_entry_safe(sglq_entry, sglq_next,
8822 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8823 if (sglq_entry->sli4_xritag == xri) {
8824 list_del(&sglq_entry->list);
8825 ndlp = sglq_entry->ndlp;
8826 sglq_entry->ndlp = NULL;
8827 spin_lock(&pring->ring_lock);
8828 list_add_tail(&sglq_entry->list,
8829 &phba->sli4_hba.lpfc_sgl_list);
8830 sglq_entry->state = SGL_FREED;
8831 spin_unlock(&pring->ring_lock);
8832 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8833 spin_unlock_irqrestore(&phba->hbalock, iflag);
8834 lpfc_set_rrq_active(phba, ndlp,
8835 sglq_entry->sli4_lxritag,
8838 /* Check if TXQ queue needs to be serviced */
8839 if (!(list_empty(&pring->txq)))
8840 lpfc_worker_wake_up(phba);
8844 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8845 lxri = lpfc_sli4_xri_inrange(phba, xri);
8846 if (lxri == NO_XRI) {
8847 spin_unlock_irqrestore(&phba->hbalock, iflag);
8850 spin_lock(&pring->ring_lock);
8851 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
8852 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8853 spin_unlock(&pring->ring_lock);
8854 spin_unlock_irqrestore(&phba->hbalock, iflag);
8857 sglq_entry->state = SGL_XRI_ABORTED;
8858 spin_unlock(&pring->ring_lock);
8859 spin_unlock_irqrestore(&phba->hbalock, iflag);
8863 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8864 * @vport: pointer to virtual port object.
8865 * @ndlp: nodelist pointer for the impacted node.
8867 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8868 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8869 * the driver is required to send a LOGO to the remote node before it
8870 * attempts to recover its login to the remote node.
8873 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8874 struct lpfc_nodelist *ndlp)
8876 struct Scsi_Host *shost;
8877 struct lpfc_hba *phba;
8878 unsigned long flags = 0;
8880 shost = lpfc_shost_from_vport(vport);
8882 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8883 lpfc_printf_log(phba, KERN_INFO,
8884 LOG_SLI, "3093 No rport recovery needed. "
8885 "rport in state 0x%x\n", ndlp->nlp_state);
8888 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8889 "3094 Start rport recovery on shost id 0x%x "
8890 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8892 shost->host_no, ndlp->nlp_DID,
8893 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8896 * The rport is not responding. Remove the FCP-2 flag to prevent
8897 * an ADISC in the follow-up recovery code.
8899 spin_lock_irqsave(shost->host_lock, flags);
8900 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8901 spin_unlock_irqrestore(shost->host_lock, flags);
8902 lpfc_issue_els_logo(vport, ndlp, 0);
8903 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);