1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
49 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
52 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp, uint8_t retry);
54 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
55 struct lpfc_iocbq *iocb);
57 static int lpfc_max_els_tries = 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport *vport)
84 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
88 if (vport->port_state >= LPFC_VPORT_READY ||
89 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
93 /* Read the HBA Host Attention Register */
94 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 if (!(ha_copy & HA_LATT))
100 /* Pending Link Event during Discovery */
101 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba->pport->port_state);
106 /* CLEAR_LA should re-enable link attention events and
107 * we should then immediately take a LATT event. The
108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
112 spin_lock_irq(shost->host_lock);
113 vport->fc_flag |= FC_ABORT_DISCOVERY;
114 spin_unlock_irq(shost->host_lock);
116 if (phba->link_state != LPFC_CLEAR_LA)
117 lpfc_issue_clear_la(phba, vport);
123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
151 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
156 struct lpfc_hba *phba = vport->phba;
157 struct lpfc_iocbq *elsiocb;
158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
163 if (!lpfc_is_link_up(phba))
166 /* Allocate buffer for command iocb */
167 elsiocb = lpfc_sli_get_iocbq(phba);
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
176 if ((did == Fabric_DID) &&
177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
190 & LPFC_FIP_ELS_ID_MASK);
193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
195 & LPFC_FIP_ELS_ID_MASK);
199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
201 icmd = &elsiocb->iocb;
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
211 INIT_LIST_HEAD(&pcmd->list);
213 /* Allocate buffer for response payload */
215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
221 INIT_LIST_HEAD(&prsp->list);
225 /* Allocate buffer for Buffer ptr list */
226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
233 INIT_LIST_HEAD(&pbuflist->list);
236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
241 icmd->un.elsreq64.remoteID = did; /* DID */
242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
246 icmd->ulpTimeout = phba->fc_ratov * 2;
248 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
249 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
250 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
251 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
252 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
253 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
255 icmd->ulpBdeCount = 1;
257 icmd->ulpClass = CLASS3;
260 * If we have NPIV enabled, we want to send ELS traffic by VPI.
261 * For SLI4, since the driver controls VPIs we also want to include
262 * all ELS pt2pt protocol traffic as well.
264 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
265 ((phba->sli_rev == LPFC_SLI_REV4) &&
266 (vport->fc_flag & FC_PT2PT))) {
269 icmd->un.elsreq64.myID = vport->fc_myDID;
271 /* For ELS_REQUEST64_CR, use the VPI by default */
272 icmd->ulpContext = phba->vpi_ids[vport->vpi];
276 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
277 if (elscmd == ELS_CMD_ECHO)
278 icmd->ulpCt_l = 0; /* context = invalid RPI */
280 icmd->ulpCt_l = 1; /* context = VPI */
283 bpl = (struct ulp_bde64 *) pbuflist->virt;
284 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
285 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
286 bpl->tus.f.bdeSize = cmdSize;
287 bpl->tus.f.bdeFlags = 0;
288 bpl->tus.w = le32_to_cpu(bpl->tus.w);
292 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
293 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
294 bpl->tus.f.bdeSize = FCELSSIZE;
295 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
296 bpl->tus.w = le32_to_cpu(bpl->tus.w);
299 /* prevent preparing iocb with NULL ndlp reference */
300 elsiocb->context1 = lpfc_nlp_get(ndlp);
301 if (!elsiocb->context1)
302 goto els_iocb_free_pbuf_exit;
303 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
305 elsiocb->retry = retry;
306 elsiocb->vport = vport;
307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
310 list_add(&prsp->list, &pcmd->list);
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
316 "NPORT x%x I/O tag: x%x, port state:x%x"
318 elscmd, did, elsiocb->iotag,
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
325 "NPORT x%x I/O tag: x%x, size: x%x "
326 "port_state x%x fc_flag x%x\n",
327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
328 cmdSize, vport->port_state,
333 els_iocb_free_pbuf_exit:
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
338 els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
342 els_iocb_free_pcmb_exit:
344 lpfc_sli_release_iocbq(phba, elsiocb);
349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
350 * @vport: pointer to a host virtual N_Port data structure.
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
365 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
367 struct lpfc_hba *phba = vport->phba;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
377 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
394 if (rc == MBX_NOT_FINISHED) {
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
416 mbox->context2 = lpfc_nlp_get(ndlp);
418 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
419 if (rc == MBX_NOT_FINISHED) {
421 goto fail_issue_reg_login;
426 fail_issue_reg_login:
427 /* decrement the reference count on ndlp just incremented
428 * for the failed mbox command.
431 mp = (struct lpfc_dmabuf *) mbox->context1;
432 lpfc_mbuf_free(phba, mp->virt, mp->phys);
435 mempool_free(mbox, phba->mbox_mem_pool);
438 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
440 "0249 Cannot issue Register Fabric login: Err %d\n", err);
445 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
446 * @vport: pointer to a host virtual N_Port data structure.
448 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
449 * the @vport. This mailbox command is necessary for SLI4 port only.
452 * 0 - successfully issued REG_VFI for @vport
453 * A failure code otherwise.
456 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
458 struct lpfc_hba *phba = vport->phba;
459 LPFC_MBOXQ_t *mboxq = NULL;
460 struct lpfc_nodelist *ndlp;
461 struct lpfc_dmabuf *dmabuf = NULL;
464 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
465 if ((phba->sli_rev == LPFC_SLI_REV4) &&
466 !(phba->link_flag & LS_LOOPBACK_MODE) &&
467 !(vport->fc_flag & FC_PT2PT)) {
468 ndlp = lpfc_findnode_did(vport, Fabric_DID);
469 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
475 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
481 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
482 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
483 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
488 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
493 memcpy(dmabuf->virt, &phba->fc_fabparam,
494 sizeof(struct serv_parm));
497 vport->port_state = LPFC_FABRIC_CFG_LINK;
499 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
501 lpfc_reg_vfi(mboxq, vport, 0);
503 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
504 mboxq->vport = vport;
505 mboxq->context1 = dmabuf;
506 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
507 if (rc == MBX_NOT_FINISHED) {
515 mempool_free(mboxq, phba->mbox_mem_pool);
518 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
522 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
523 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
524 "0289 Issue Register VFI failed: Err %d\n", rc);
529 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
530 * @vport: pointer to a host virtual N_Port data structure.
532 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
533 * the @vport. This mailbox command is necessary for SLI4 port only.
536 * 0 - successfully issued REG_VFI for @vport
537 * A failure code otherwise.
540 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
542 struct lpfc_hba *phba = vport->phba;
543 struct Scsi_Host *shost;
547 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
549 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
550 "2556 UNREG_VFI mbox allocation failed"
551 "HBA state x%x\n", phba->pport->port_state);
555 lpfc_unreg_vfi(mboxq, vport);
556 mboxq->vport = vport;
557 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
559 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
560 if (rc == MBX_NOT_FINISHED) {
561 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
562 "2557 UNREG_VFI issue mbox failed rc x%x "
564 rc, phba->pport->port_state);
565 mempool_free(mboxq, phba->mbox_mem_pool);
569 shost = lpfc_shost_from_vport(vport);
570 spin_lock_irq(shost->host_lock);
571 vport->fc_flag &= ~FC_VFI_REGISTERED;
572 spin_unlock_irq(shost->host_lock);
577 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
578 * @vport: pointer to a host virtual N_Port data structure.
579 * @sp: pointer to service parameter data structure.
581 * This routine is called from FLOGI/FDISC completion handler functions.
582 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
583 * node nodename is changed in the completion service parameter else return
584 * 0. This function also set flag in the vport data structure to delay
585 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
586 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
587 * node nodename is changed in the completion service parameter.
590 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
591 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
595 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
596 struct serv_parm *sp)
598 struct lpfc_hba *phba = vport->phba;
599 uint8_t fabric_param_changed = 0;
600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
602 if ((vport->fc_prevDID != vport->fc_myDID) ||
603 memcmp(&vport->fabric_portname, &sp->portName,
604 sizeof(struct lpfc_name)) ||
605 memcmp(&vport->fabric_nodename, &sp->nodeName,
606 sizeof(struct lpfc_name)))
607 fabric_param_changed = 1;
610 * Word 1 Bit 31 in common service parameter is overloaded.
611 * Word 1 Bit 31 in FLOGI request is multiple NPort request
612 * Word 1 Bit 31 in FLOGI response is clean address bit
614 * If fabric parameter is changed and clean address bit is
615 * cleared delay nport discovery if
616 * - vport->fc_prevDID != 0 (not initial discovery) OR
617 * - lpfc_delay_discovery module parameter is set.
619 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
620 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
621 spin_lock_irq(shost->host_lock);
622 vport->fc_flag |= FC_DISC_DELAYED;
623 spin_unlock_irq(shost->host_lock);
626 return fabric_param_changed;
631 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
632 * @vport: pointer to a host virtual N_Port data structure.
633 * @ndlp: pointer to a node-list data structure.
634 * @sp: pointer to service parameter data structure.
635 * @irsp: pointer to the IOCB within the lpfc response IOCB.
637 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
638 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
639 * port in a fabric topology. It properly sets up the parameters to the @ndlp
640 * from the IOCB response. It also check the newly assigned N_Port ID to the
641 * @vport against the previously assigned N_Port ID. If it is different from
642 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
643 * is invoked on all the remaining nodes with the @vport to unregister the
644 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
645 * is invoked to register login to the fabric.
648 * 0 - Success (currently, always return 0)
651 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
652 struct serv_parm *sp, IOCB_t *irsp)
654 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
655 struct lpfc_hba *phba = vport->phba;
656 struct lpfc_nodelist *np;
657 struct lpfc_nodelist *next_np;
658 uint8_t fabric_param_changed;
660 spin_lock_irq(shost->host_lock);
661 vport->fc_flag |= FC_FABRIC;
662 spin_unlock_irq(shost->host_lock);
664 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
665 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
666 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
668 phba->fc_edtovResol = sp->cmn.edtovResolution;
669 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
671 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
672 spin_lock_irq(shost->host_lock);
673 vport->fc_flag |= FC_PUBLIC_LOOP;
674 spin_unlock_irq(shost->host_lock);
677 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
678 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
679 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
680 ndlp->nlp_class_sup = 0;
681 if (sp->cls1.classValid)
682 ndlp->nlp_class_sup |= FC_COS_CLASS1;
683 if (sp->cls2.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS2;
685 if (sp->cls3.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS3;
687 if (sp->cls4.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS4;
689 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
690 sp->cmn.bbRcvSizeLsb;
692 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
693 if (fabric_param_changed) {
694 /* Reset FDMI attribute masks based on config parameter */
695 if (phba->cfg_enable_SmartSAN ||
696 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
697 /* Setup appropriate attribute masks */
698 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
699 if (phba->cfg_enable_SmartSAN)
700 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
702 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
704 vport->fdmi_hba_mask = 0;
705 vport->fdmi_port_mask = 0;
709 memcpy(&vport->fabric_portname, &sp->portName,
710 sizeof(struct lpfc_name));
711 memcpy(&vport->fabric_nodename, &sp->nodeName,
712 sizeof(struct lpfc_name));
713 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
715 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
716 if (sp->cmn.response_multiple_NPort) {
717 lpfc_printf_vlog(vport, KERN_WARNING,
719 "1816 FLOGI NPIV supported, "
720 "response data 0x%x\n",
721 sp->cmn.response_multiple_NPort);
722 spin_lock_irq(&phba->hbalock);
723 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
724 spin_unlock_irq(&phba->hbalock);
726 /* Because we asked f/w for NPIV it still expects us
727 to call reg_vnpid atleast for the physcial host */
728 lpfc_printf_vlog(vport, KERN_WARNING,
730 "1817 Fabric does not support NPIV "
731 "- configuring single port mode.\n");
732 spin_lock_irq(&phba->hbalock);
733 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
734 spin_unlock_irq(&phba->hbalock);
739 * For FC we need to do some special processing because of the SLI
740 * Port's default settings of the Common Service Parameters.
742 if ((phba->sli_rev == LPFC_SLI_REV4) &&
743 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
744 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
745 if (fabric_param_changed)
746 lpfc_unregister_fcf_prep(phba);
748 /* This should just update the VFI CSPs*/
749 if (vport->fc_flag & FC_VFI_REGISTERED)
750 lpfc_issue_reg_vfi(vport);
753 if (fabric_param_changed &&
754 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
756 /* If our NportID changed, we need to ensure all
757 * remaining NPORTs get unreg_login'ed.
759 list_for_each_entry_safe(np, next_np,
760 &vport->fc_nodes, nlp_listp) {
761 if (!NLP_CHK_NODE_ACT(np))
763 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
764 !(np->nlp_flag & NLP_NPR_ADISC))
766 spin_lock_irq(shost->host_lock);
767 np->nlp_flag &= ~NLP_NPR_ADISC;
768 spin_unlock_irq(shost->host_lock);
769 lpfc_unreg_rpi(vport, np);
771 lpfc_cleanup_pending_mbox(vport);
773 if (phba->sli_rev == LPFC_SLI_REV4) {
774 lpfc_sli4_unreg_all_rpis(vport);
775 lpfc_mbx_unreg_vpi(vport);
776 spin_lock_irq(shost->host_lock);
777 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
778 spin_unlock_irq(shost->host_lock);
782 * For SLI3 and SLI4, the VPI needs to be reregistered in
783 * response to this fabric parameter change event.
785 spin_lock_irq(shost->host_lock);
786 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
787 spin_unlock_irq(shost->host_lock);
788 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
789 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
791 * Driver needs to re-reg VPI in order for f/w
792 * to update the MAC address.
794 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
795 lpfc_register_new_vport(phba, vport, ndlp);
799 if (phba->sli_rev < LPFC_SLI_REV4) {
800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
801 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
802 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
803 lpfc_register_new_vport(phba, vport, ndlp);
805 lpfc_issue_fabric_reglogin(vport);
807 ndlp->nlp_type |= NLP_FABRIC;
808 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
809 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
810 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
811 lpfc_start_fdiscs(phba);
812 lpfc_do_scr_ns_plogi(phba, vport);
813 } else if (vport->fc_flag & FC_VFI_REGISTERED)
814 lpfc_issue_init_vpi(vport);
816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
817 "3135 Need register VFI: (x%x/%x)\n",
818 vport->fc_prevDID, vport->fc_myDID);
819 lpfc_issue_reg_vfi(vport);
826 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
827 * @vport: pointer to a host virtual N_Port data structure.
828 * @ndlp: pointer to a node-list data structure.
829 * @sp: pointer to service parameter data structure.
831 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
832 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
833 * in a point-to-point topology. First, the @vport's N_Port Name is compared
834 * with the received N_Port Name: if the @vport's N_Port Name is greater than
835 * the received N_Port Name lexicographically, this node shall assign local
836 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
837 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
838 * this node shall just wait for the remote node to issue PLOGI and assign
846 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
847 struct serv_parm *sp)
849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
850 struct lpfc_hba *phba = vport->phba;
854 spin_lock_irq(shost->host_lock);
855 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
856 vport->fc_flag |= FC_PT2PT;
857 spin_unlock_irq(shost->host_lock);
859 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
860 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
861 lpfc_unregister_fcf_prep(phba);
863 spin_lock_irq(shost->host_lock);
864 vport->fc_flag &= ~FC_VFI_REGISTERED;
865 spin_unlock_irq(shost->host_lock);
866 phba->fc_topology_changed = 0;
869 rc = memcmp(&vport->fc_portname, &sp->portName,
870 sizeof(vport->fc_portname));
873 /* This side will initiate the PLOGI */
874 spin_lock_irq(shost->host_lock);
875 vport->fc_flag |= FC_PT2PT_PLOGI;
876 spin_unlock_irq(shost->host_lock);
879 * N_Port ID cannot be 0, set our Id to LocalID
880 * the other side will be RemoteID.
885 vport->fc_myDID = PT2PT_LocalID;
887 /* Decrement ndlp reference count indicating that ndlp can be
888 * safely released when other references to it are done.
892 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
895 * Cannot find existing Fabric ndlp, so allocate a
898 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
901 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
902 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
903 ndlp = lpfc_enable_node(vport, ndlp,
904 NLP_STE_UNUSED_NODE);
909 memcpy(&ndlp->nlp_portname, &sp->portName,
910 sizeof(struct lpfc_name));
911 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
912 sizeof(struct lpfc_name));
913 /* Set state will put ndlp onto node list if not already done */
914 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
915 spin_lock_irq(shost->host_lock);
916 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
917 spin_unlock_irq(shost->host_lock);
919 /* This side will wait for the PLOGI, decrement ndlp reference
920 * count indicating that ndlp can be released when other
921 * references to it are done.
925 /* If we are pt2pt with another NPort, force NPIV off! */
926 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
928 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
932 lpfc_config_link(phba, mbox);
934 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
936 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
937 if (rc == MBX_NOT_FINISHED) {
938 mempool_free(mbox, phba->mbox_mem_pool);
948 * lpfc_cmpl_els_flogi - Completion callback function for flogi
949 * @phba: pointer to lpfc hba data structure.
950 * @cmdiocb: pointer to lpfc command iocb data structure.
951 * @rspiocb: pointer to lpfc response iocb data structure.
953 * This routine is the top-level completion callback function for issuing
954 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
955 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
956 * retry has been made (either immediately or delayed with lpfc_els_retry()
957 * returning 1), the command IOCB will be released and function returned.
958 * If the retry attempt has been given up (possibly reach the maximum
959 * number of retries), one additional decrement of ndlp reference shall be
960 * invoked before going out after releasing the command IOCB. This will
961 * actually release the remote node (Note, lpfc_els_free_iocb() will also
962 * invoke one decrement of ndlp reference count). If no error reported in
963 * the IOCB status, the command Port ID field is used to determine whether
964 * this is a point-to-point topology or a fabric topology: if the Port ID
965 * field is assigned, it is a fabric topology; otherwise, it is a
966 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
967 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
968 * specific topology completion conditions.
971 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
972 struct lpfc_iocbq *rspiocb)
974 struct lpfc_vport *vport = cmdiocb->vport;
975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
976 IOCB_t *irsp = &rspiocb->iocb;
977 struct lpfc_nodelist *ndlp = cmdiocb->context1;
978 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
979 struct serv_parm *sp;
983 /* Check to see if link went down during discovery */
984 if (lpfc_els_chk_latt(vport)) {
985 /* One additional decrement on node reference count to
986 * trigger the release of the node
992 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
993 "FLOGI cmpl: status:x%x/x%x state:x%x",
994 irsp->ulpStatus, irsp->un.ulpWord[4],
997 if (irsp->ulpStatus) {
999 * In case of FIP mode, perform roundrobin FCF failover
1000 * due to new FCF discovery
1002 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1003 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1004 if (phba->link_state < LPFC_LINK_UP)
1005 goto stop_rr_fcf_flogi;
1006 if ((phba->fcoe_cvl_eventtag_attn ==
1007 phba->fcoe_cvl_eventtag) &&
1008 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1009 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1011 goto stop_rr_fcf_flogi;
1013 phba->fcoe_cvl_eventtag_attn =
1014 phba->fcoe_cvl_eventtag;
1015 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1016 "2611 FLOGI failed on FCF (x%x), "
1017 "status:x%x/x%x, tmo:x%x, perform "
1018 "roundrobin FCF failover\n",
1019 phba->fcf.current_rec.fcf_indx,
1020 irsp->ulpStatus, irsp->un.ulpWord[4],
1022 lpfc_sli4_set_fcf_flogi_fail(phba,
1023 phba->fcf.current_rec.fcf_indx);
1024 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1025 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1032 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1033 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1035 irsp->ulpStatus, irsp->un.ulpWord[4],
1036 irsp->ulpTimeout, phba->hba_flag,
1037 phba->fcf.fcf_flag);
1039 /* Check for retry */
1040 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1044 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1045 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1046 irsp->ulpStatus, irsp->un.ulpWord[4],
1049 /* FLOGI failed, so there is no fabric */
1050 spin_lock_irq(shost->host_lock);
1051 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1052 spin_unlock_irq(shost->host_lock);
1054 /* If private loop, then allow max outstanding els to be
1055 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1056 * alpa map would take too long otherwise.
1058 if (phba->alpa_map[0] == 0)
1059 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1060 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1061 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1062 (vport->fc_prevDID != vport->fc_myDID) ||
1063 phba->fc_topology_changed)) {
1064 if (vport->fc_flag & FC_VFI_REGISTERED) {
1065 if (phba->fc_topology_changed) {
1066 lpfc_unregister_fcf_prep(phba);
1067 spin_lock_irq(shost->host_lock);
1068 vport->fc_flag &= ~FC_VFI_REGISTERED;
1069 spin_unlock_irq(shost->host_lock);
1070 phba->fc_topology_changed = 0;
1072 lpfc_sli4_unreg_all_rpis(vport);
1076 /* Do not register VFI if the driver aborted FLOGI */
1077 if (!lpfc_error_lost_link(irsp))
1078 lpfc_issue_reg_vfi(vport);
1084 spin_lock_irq(shost->host_lock);
1085 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1086 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1087 spin_unlock_irq(shost->host_lock);
1090 * The FLogI succeeded. Sync the data for the CPU before
1093 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1096 sp = prsp->virt + sizeof(uint32_t);
1098 /* FLOGI completes successfully */
1099 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1100 "0101 FLOGI completes successfully, I/O tag:x%x, "
1101 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
1102 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1103 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1104 vport->port_state, vport->fc_flag);
1106 if (vport->port_state == LPFC_FLOGI) {
1108 * If Common Service Parameters indicate Nport
1109 * we are point to point, if Fport we are Fabric.
1112 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1113 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1114 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1116 lpfc_printf_vlog(vport, KERN_ERR,
1118 "2831 FLOGI response with cleared Fabric "
1119 "bit fcf_index 0x%x "
1120 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1122 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1123 phba->fcf.current_rec.fcf_indx,
1124 phba->fcf.current_rec.switch_name[0],
1125 phba->fcf.current_rec.switch_name[1],
1126 phba->fcf.current_rec.switch_name[2],
1127 phba->fcf.current_rec.switch_name[3],
1128 phba->fcf.current_rec.switch_name[4],
1129 phba->fcf.current_rec.switch_name[5],
1130 phba->fcf.current_rec.switch_name[6],
1131 phba->fcf.current_rec.switch_name[7],
1132 phba->fcf.current_rec.fabric_name[0],
1133 phba->fcf.current_rec.fabric_name[1],
1134 phba->fcf.current_rec.fabric_name[2],
1135 phba->fcf.current_rec.fabric_name[3],
1136 phba->fcf.current_rec.fabric_name[4],
1137 phba->fcf.current_rec.fabric_name[5],
1138 phba->fcf.current_rec.fabric_name[6],
1139 phba->fcf.current_rec.fabric_name[7]);
1141 spin_lock_irq(&phba->hbalock);
1142 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1143 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1144 spin_unlock_irq(&phba->hbalock);
1148 /* Mark the FCF discovery process done */
1149 if (phba->hba_flag & HBA_FIP_SUPPORT)
1150 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1152 "2769 FLOGI to FCF (x%x) "
1153 "completed successfully\n",
1154 phba->fcf.current_rec.fcf_indx);
1155 spin_lock_irq(&phba->hbalock);
1156 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1157 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1158 spin_unlock_irq(&phba->hbalock);
1164 spin_lock_irq(&phba->hbalock);
1165 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1166 spin_unlock_irq(&phba->hbalock);
1170 if (!lpfc_error_lost_link(irsp)) {
1171 /* FLOGI failed, so just use loop map to make discovery list */
1172 lpfc_disc_list_loopmap(vport);
1174 /* Start discovery */
1175 lpfc_disc_start(vport);
1176 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1177 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1178 IOERR_SLI_ABORTED) &&
1179 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1180 IOERR_SLI_DOWN))) &&
1181 (phba->link_state != LPFC_CLEAR_LA)) {
1182 /* If FLOGI failed enable link interrupt. */
1183 lpfc_issue_clear_la(phba, vport);
1186 lpfc_els_free_iocb(phba, cmdiocb);
1190 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1191 * @vport: pointer to a host virtual N_Port data structure.
1192 * @ndlp: pointer to a node-list data structure.
1193 * @retry: number of retries to the command IOCB.
1195 * This routine issues a Fabric Login (FLOGI) Request ELS command
1196 * for a @vport. The initiator service parameters are put into the payload
1197 * of the FLOGI Request IOCB and the top-level callback function pointer
1198 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1199 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1200 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1202 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1203 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1204 * will be stored into the context1 field of the IOCB for the completion
1205 * callback function to the FLOGI ELS command.
1208 * 0 - successfully issued flogi iocb for @vport
1209 * 1 - failed to issue flogi iocb for @vport
1212 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1215 struct lpfc_hba *phba = vport->phba;
1216 struct serv_parm *sp;
1218 struct lpfc_iocbq *elsiocb;
1224 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1225 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1226 ndlp->nlp_DID, ELS_CMD_FLOGI);
1231 icmd = &elsiocb->iocb;
1232 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1234 /* For FLOGI request, remainder of payload is service parameters */
1235 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1236 pcmd += sizeof(uint32_t);
1237 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1238 sp = (struct serv_parm *) pcmd;
1240 /* Setup CSPs accordingly for Fabric */
1241 sp->cmn.e_d_tov = 0;
1242 sp->cmn.w2.r_a_tov = 0;
1243 sp->cmn.virtual_fabric_support = 0;
1244 sp->cls1.classValid = 0;
1245 if (sp->cmn.fcphLow < FC_PH3)
1246 sp->cmn.fcphLow = FC_PH3;
1247 if (sp->cmn.fcphHigh < FC_PH3)
1248 sp->cmn.fcphHigh = FC_PH3;
1250 if (phba->sli_rev == LPFC_SLI_REV4) {
1251 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1252 LPFC_SLI_INTF_IF_TYPE_0) {
1253 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1254 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1255 /* FLOGI needs to be 3 for WQE FCFI */
1256 /* Set the fcfi to the fcfi we registered with */
1257 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1259 /* Can't do SLI4 class2 without support sequence coalescing */
1260 sp->cls2.classValid = 0;
1261 sp->cls2.seqDelivery = 0;
1263 /* Historical, setting sequential-delivery bit for SLI3 */
1264 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1265 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1266 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1267 sp->cmn.request_multiple_Nport = 1;
1268 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1272 sp->cmn.request_multiple_Nport = 0;
1275 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1276 icmd->un.elsreq64.myID = 0;
1277 icmd->un.elsreq64.fl = 1;
1280 tmo = phba->fc_ratov;
1281 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1282 lpfc_set_disctmo(vport);
1283 phba->fc_ratov = tmo;
1285 phba->fc_stat.elsXmitFLOGI++;
1286 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1288 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1289 "Issue FLOGI: opt:x%x",
1290 phba->sli3_options, 0, 0);
1292 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1293 if (rc == IOCB_ERROR) {
1294 lpfc_els_free_iocb(phba, elsiocb);
1301 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1302 * @phba: pointer to lpfc hba data structure.
1304 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1305 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1306 * list and issues an abort IOCB commond on each outstanding IOCB that
1307 * contains a active Fabric_DID ndlp. Note that this function is to issue
1308 * the abort IOCB command on all the outstanding IOCBs, thus when this
1309 * function returns, it does not guarantee all the IOCBs are actually aborted.
1312 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1315 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1317 struct lpfc_sli_ring *pring;
1318 struct lpfc_iocbq *iocb, *next_iocb;
1319 struct lpfc_nodelist *ndlp;
1322 /* Abort outstanding I/O on NPort <nlp_DID> */
1323 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1324 "0201 Abort outstanding I/O on NPort x%x\n",
1327 pring = lpfc_phba_elsring(phba);
1330 * Check the txcmplq for an iocb that matches the nport the driver is
1333 spin_lock_irq(&phba->hbalock);
1334 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1336 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1337 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1338 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1339 (ndlp->nlp_DID == Fabric_DID))
1340 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1343 spin_unlock_irq(&phba->hbalock);
1349 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1350 * @vport: pointer to a host virtual N_Port data structure.
1352 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1353 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1354 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1355 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1356 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1357 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1361 * 0 - failed to issue initial flogi for @vport
1362 * 1 - successfully issued initial flogi for @vport
1365 lpfc_initial_flogi(struct lpfc_vport *vport)
1367 struct lpfc_hba *phba = vport->phba;
1368 struct lpfc_nodelist *ndlp;
1370 vport->port_state = LPFC_FLOGI;
1371 lpfc_set_disctmo(vport);
1373 /* First look for the Fabric ndlp */
1374 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1376 /* Cannot find existing Fabric ndlp, so allocate a new one */
1377 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1380 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1381 /* Set the node type */
1382 ndlp->nlp_type |= NLP_FABRIC;
1383 /* Put ndlp onto node list */
1384 lpfc_enqueue_node(vport, ndlp);
1385 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1386 /* re-setup ndlp without removing from node list */
1387 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1392 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1393 /* This decrement of reference count to node shall kick off
1394 * the release of the node.
1403 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1404 * @vport: pointer to a host virtual N_Port data structure.
1406 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1407 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1408 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1409 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1410 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1411 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1415 * 0 - failed to issue initial fdisc for @vport
1416 * 1 - successfully issued initial fdisc for @vport
1419 lpfc_initial_fdisc(struct lpfc_vport *vport)
1421 struct lpfc_hba *phba = vport->phba;
1422 struct lpfc_nodelist *ndlp;
1424 /* First look for the Fabric ndlp */
1425 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1427 /* Cannot find existing Fabric ndlp, so allocate a new one */
1428 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1431 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1432 /* Put ndlp onto node list */
1433 lpfc_enqueue_node(vport, ndlp);
1434 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1435 /* re-setup ndlp without removing from node list */
1436 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1441 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1442 /* decrement node reference count to trigger the release of
1452 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1453 * @vport: pointer to a host virtual N_Port data structure.
1455 * This routine checks whether there are more remaining Port Logins
1456 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1457 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1458 * to issue ELS PLOGIs up to the configured discover threads with the
1459 * @vport (@vport->cfg_discovery_threads). The function also decrement
1460 * the @vport's num_disc_node by 1 if it is not already 0.
1463 lpfc_more_plogi(struct lpfc_vport *vport)
1465 if (vport->num_disc_nodes)
1466 vport->num_disc_nodes--;
1468 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1469 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1470 "0232 Continue discovery with %d PLOGIs to go "
1471 "Data: x%x x%x x%x\n",
1472 vport->num_disc_nodes, vport->fc_plogi_cnt,
1473 vport->fc_flag, vport->port_state);
1474 /* Check to see if there are more PLOGIs to be sent */
1475 if (vport->fc_flag & FC_NLP_MORE)
1476 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1477 lpfc_els_disc_plogi(vport);
1483 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1484 * @phba: pointer to lpfc hba data structure.
1485 * @prsp: pointer to response IOCB payload.
1486 * @ndlp: pointer to a node-list data structure.
1488 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1489 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1490 * The following cases are considered N_Port confirmed:
1491 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1492 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1493 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1494 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1495 * 1) if there is a node on vport list other than the @ndlp with the same
1496 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1497 * on that node to release the RPI associated with the node; 2) if there is
1498 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1499 * into, a new node shall be allocated (or activated). In either case, the
1500 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1501 * be released and the new_ndlp shall be put on to the vport node list and
1502 * its pointer returned as the confirmed node.
1504 * Note that before the @ndlp got "released", the keepDID from not-matching
1505 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1506 * of the @ndlp. This is because the release of @ndlp is actually to put it
1507 * into an inactive state on the vport node list and the vport node list
1508 * management algorithm does not allow two node with a same DID.
1511 * pointer to the PLOGI N_Port @ndlp
1513 static struct lpfc_nodelist *
1514 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1515 struct lpfc_nodelist *ndlp)
1517 struct lpfc_vport *vport = ndlp->vport;
1518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1519 struct lpfc_nodelist *new_ndlp;
1520 struct lpfc_rport_data *rdata;
1521 struct fc_rport *rport;
1522 struct serv_parm *sp;
1523 uint8_t name[sizeof(struct lpfc_name)];
1524 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1525 uint16_t keep_nlp_state;
1528 unsigned long *active_rrqs_xri_bitmap = NULL;
1530 /* Fabric nodes can have the same WWPN so we don't bother searching
1531 * by WWPN. Just return the ndlp that was given to us.
1533 if (ndlp->nlp_type & NLP_FABRIC)
1536 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1537 memset(name, 0, sizeof(struct lpfc_name));
1539 /* Now we find out if the NPort we are logging into, matches the WWPN
1540 * we have for that ndlp. If not, we have some work to do.
1542 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1544 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1546 if (phba->sli_rev == LPFC_SLI_REV4) {
1547 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1549 if (active_rrqs_xri_bitmap)
1550 memset(active_rrqs_xri_bitmap, 0,
1551 phba->cfg_rrq_xri_bitmap_sz);
1554 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1555 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1556 ndlp, ndlp->nlp_DID, new_ndlp);
1559 rc = memcmp(&ndlp->nlp_portname, name,
1560 sizeof(struct lpfc_name));
1562 if (active_rrqs_xri_bitmap)
1563 mempool_free(active_rrqs_xri_bitmap,
1564 phba->active_rrq_pool);
1567 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1569 if (active_rrqs_xri_bitmap)
1570 mempool_free(active_rrqs_xri_bitmap,
1571 phba->active_rrq_pool);
1574 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1575 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1576 rc = memcmp(&ndlp->nlp_portname, name,
1577 sizeof(struct lpfc_name));
1579 if (active_rrqs_xri_bitmap)
1580 mempool_free(active_rrqs_xri_bitmap,
1581 phba->active_rrq_pool);
1584 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1585 NLP_STE_UNUSED_NODE);
1587 if (active_rrqs_xri_bitmap)
1588 mempool_free(active_rrqs_xri_bitmap,
1589 phba->active_rrq_pool);
1592 keepDID = new_ndlp->nlp_DID;
1593 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1594 memcpy(active_rrqs_xri_bitmap,
1595 new_ndlp->active_rrqs_xri_bitmap,
1596 phba->cfg_rrq_xri_bitmap_sz);
1598 keepDID = new_ndlp->nlp_DID;
1599 if (phba->sli_rev == LPFC_SLI_REV4 &&
1600 active_rrqs_xri_bitmap)
1601 memcpy(active_rrqs_xri_bitmap,
1602 new_ndlp->active_rrqs_xri_bitmap,
1603 phba->cfg_rrq_xri_bitmap_sz);
1606 lpfc_unreg_rpi(vport, new_ndlp);
1607 new_ndlp->nlp_DID = ndlp->nlp_DID;
1608 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1609 if (phba->sli_rev == LPFC_SLI_REV4)
1610 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1611 ndlp->active_rrqs_xri_bitmap,
1612 phba->cfg_rrq_xri_bitmap_sz);
1614 spin_lock_irq(shost->host_lock);
1615 keep_nlp_flag = new_ndlp->nlp_flag;
1616 new_ndlp->nlp_flag = ndlp->nlp_flag;
1617 ndlp->nlp_flag = keep_nlp_flag;
1618 spin_unlock_irq(shost->host_lock);
1620 /* Set nlp_states accordingly */
1621 keep_nlp_state = new_ndlp->nlp_state;
1622 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1624 /* Move this back to NPR state */
1625 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1626 /* The new_ndlp is replacing ndlp totally, so we need
1627 * to put ndlp on UNUSED list and try to free it.
1629 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1630 "3179 PLOGI confirm NEW: %x %x\n",
1631 new_ndlp->nlp_DID, keepDID);
1633 /* Fix up the rport accordingly */
1634 rport = ndlp->rport;
1636 rdata = rport->dd_data;
1637 if (rdata->pnode == ndlp) {
1638 /* break the link before dropping the ref */
1641 rdata->pnode = lpfc_nlp_get(new_ndlp);
1642 new_ndlp->rport = rport;
1644 new_ndlp->nlp_type = ndlp->nlp_type;
1646 /* We shall actually free the ndlp with both nlp_DID and
1647 * nlp_portname fields equals 0 to avoid any ndlp on the
1648 * nodelist never to be used.
1650 if (ndlp->nlp_DID == 0) {
1651 spin_lock_irq(&phba->ndlp_lock);
1652 NLP_SET_FREE_REQ(ndlp);
1653 spin_unlock_irq(&phba->ndlp_lock);
1656 /* Two ndlps cannot have the same did on the nodelist */
1657 ndlp->nlp_DID = keepDID;
1658 if (phba->sli_rev == LPFC_SLI_REV4 &&
1659 active_rrqs_xri_bitmap)
1660 memcpy(ndlp->active_rrqs_xri_bitmap,
1661 active_rrqs_xri_bitmap,
1662 phba->cfg_rrq_xri_bitmap_sz);
1664 if (!NLP_CHK_NODE_ACT(ndlp))
1665 lpfc_drop_node(vport, ndlp);
1668 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1669 "3180 PLOGI confirm SWAP: %x %x\n",
1670 new_ndlp->nlp_DID, keepDID);
1672 lpfc_unreg_rpi(vport, ndlp);
1674 /* Two ndlps cannot have the same did */
1675 ndlp->nlp_DID = keepDID;
1676 if (phba->sli_rev == LPFC_SLI_REV4 &&
1677 active_rrqs_xri_bitmap)
1678 memcpy(ndlp->active_rrqs_xri_bitmap,
1679 active_rrqs_xri_bitmap,
1680 phba->cfg_rrq_xri_bitmap_sz);
1682 /* Since we are switching over to the new_ndlp,
1683 * reset the old ndlp state
1685 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1686 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1687 keep_nlp_state = NLP_STE_NPR_NODE;
1688 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1690 /* Fix up the rport accordingly */
1691 rport = ndlp->rport;
1693 rdata = rport->dd_data;
1694 put_node = rdata->pnode != NULL;
1695 put_rport = ndlp->rport != NULL;
1696 rdata->pnode = NULL;
1701 put_device(&rport->dev);
1704 if (phba->sli_rev == LPFC_SLI_REV4 &&
1705 active_rrqs_xri_bitmap)
1706 mempool_free(active_rrqs_xri_bitmap,
1707 phba->active_rrq_pool);
1712 * lpfc_end_rscn - Check and handle more rscn for a vport
1713 * @vport: pointer to a host virtual N_Port data structure.
1715 * This routine checks whether more Registration State Change
1716 * Notifications (RSCNs) came in while the discovery state machine was in
1717 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1718 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1719 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1720 * handling the RSCNs.
1723 lpfc_end_rscn(struct lpfc_vport *vport)
1725 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1727 if (vport->fc_flag & FC_RSCN_MODE) {
1729 * Check to see if more RSCNs came in while we were
1730 * processing this one.
1732 if (vport->fc_rscn_id_cnt ||
1733 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1734 lpfc_els_handle_rscn(vport);
1736 spin_lock_irq(shost->host_lock);
1737 vport->fc_flag &= ~FC_RSCN_MODE;
1738 spin_unlock_irq(shost->host_lock);
1744 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1745 * @phba: pointer to lpfc hba data structure.
1746 * @cmdiocb: pointer to lpfc command iocb data structure.
1747 * @rspiocb: pointer to lpfc response iocb data structure.
1749 * This routine will call the clear rrq function to free the rrq and
1750 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1751 * exist then the clear_rrq is still called because the rrq needs to
1756 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1757 struct lpfc_iocbq *rspiocb)
1759 struct lpfc_vport *vport = cmdiocb->vport;
1761 struct lpfc_nodelist *ndlp;
1762 struct lpfc_node_rrq *rrq;
1764 /* we pass cmdiocb to state machine which needs rspiocb as well */
1765 rrq = cmdiocb->context_un.rrq;
1766 cmdiocb->context_un.rsp_iocb = rspiocb;
1768 irsp = &rspiocb->iocb;
1769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1770 "RRQ cmpl: status:x%x/x%x did:x%x",
1771 irsp->ulpStatus, irsp->un.ulpWord[4],
1772 irsp->un.elsreq64.remoteID);
1774 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1775 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1776 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1777 "2882 RRQ completes to NPort x%x "
1778 "with no ndlp. Data: x%x x%x x%x\n",
1779 irsp->un.elsreq64.remoteID,
1780 irsp->ulpStatus, irsp->un.ulpWord[4],
1785 /* rrq completes to NPort <nlp_DID> */
1786 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1787 "2880 RRQ completes to NPort x%x "
1788 "Data: x%x x%x x%x x%x x%x\n",
1789 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1790 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1792 if (irsp->ulpStatus) {
1793 /* Check for retry */
1794 /* RRQ failed Don't print the vport to vport rjts */
1795 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1796 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1797 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1798 (phba)->pport->cfg_log_verbose & LOG_ELS)
1799 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1800 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1801 ndlp->nlp_DID, irsp->ulpStatus,
1802 irsp->un.ulpWord[4]);
1806 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1807 lpfc_els_free_iocb(phba, cmdiocb);
1811 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1812 * @phba: pointer to lpfc hba data structure.
1813 * @cmdiocb: pointer to lpfc command iocb data structure.
1814 * @rspiocb: pointer to lpfc response iocb data structure.
1816 * This routine is the completion callback function for issuing the Port
1817 * Login (PLOGI) command. For PLOGI completion, there must be an active
1818 * ndlp on the vport node list that matches the remote node ID from the
1819 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1820 * ignored and command IOCB released. The PLOGI response IOCB status is
1821 * checked for error conditons. If there is error status reported, PLOGI
1822 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1823 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1824 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1825 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1826 * there are additional N_Port nodes with the vport that need to perform
1827 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1831 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1832 struct lpfc_iocbq *rspiocb)
1834 struct lpfc_vport *vport = cmdiocb->vport;
1835 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1837 struct lpfc_nodelist *ndlp;
1838 struct lpfc_dmabuf *prsp;
1841 /* we pass cmdiocb to state machine which needs rspiocb as well */
1842 cmdiocb->context_un.rsp_iocb = rspiocb;
1844 irsp = &rspiocb->iocb;
1845 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1846 "PLOGI cmpl: status:x%x/x%x did:x%x",
1847 irsp->ulpStatus, irsp->un.ulpWord[4],
1848 irsp->un.elsreq64.remoteID);
1850 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1851 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1852 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1853 "0136 PLOGI completes to NPort x%x "
1854 "with no ndlp. Data: x%x x%x x%x\n",
1855 irsp->un.elsreq64.remoteID,
1856 irsp->ulpStatus, irsp->un.ulpWord[4],
1861 /* Since ndlp can be freed in the disc state machine, note if this node
1862 * is being used during discovery.
1864 spin_lock_irq(shost->host_lock);
1865 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1866 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1867 spin_unlock_irq(shost->host_lock);
1870 /* PLOGI completes to NPort <nlp_DID> */
1871 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1872 "0102 PLOGI completes to NPort x%06x "
1873 "Data: x%x x%x x%x x%x x%x\n",
1874 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1875 irsp->ulpStatus, irsp->un.ulpWord[4],
1876 disc, vport->num_disc_nodes);
1878 /* Check to see if link went down during discovery */
1879 if (lpfc_els_chk_latt(vport)) {
1880 spin_lock_irq(shost->host_lock);
1881 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1882 spin_unlock_irq(shost->host_lock);
1886 if (irsp->ulpStatus) {
1887 /* Check for retry */
1888 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1889 /* ELS command is being retried */
1891 spin_lock_irq(shost->host_lock);
1892 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1893 spin_unlock_irq(shost->host_lock);
1897 /* PLOGI failed Don't print the vport to vport rjts */
1898 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1899 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1900 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1901 (phba)->pport->cfg_log_verbose & LOG_ELS)
1902 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1903 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1904 ndlp->nlp_DID, irsp->ulpStatus,
1905 irsp->un.ulpWord[4]);
1906 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1907 if (lpfc_error_lost_link(irsp))
1908 rc = NLP_STE_FREED_NODE;
1910 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1911 NLP_EVT_CMPL_PLOGI);
1913 /* Good status, call state machine */
1914 prsp = list_entry(((struct lpfc_dmabuf *)
1915 cmdiocb->context2)->list.next,
1916 struct lpfc_dmabuf, list);
1917 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1918 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1919 NLP_EVT_CMPL_PLOGI);
1922 if (disc && vport->num_disc_nodes) {
1923 /* Check to see if there are more PLOGIs to be sent */
1924 lpfc_more_plogi(vport);
1926 if (vport->num_disc_nodes == 0) {
1927 spin_lock_irq(shost->host_lock);
1928 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1929 spin_unlock_irq(shost->host_lock);
1931 lpfc_can_disctmo(vport);
1932 lpfc_end_rscn(vport);
1937 lpfc_els_free_iocb(phba, cmdiocb);
1942 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1943 * @vport: pointer to a host virtual N_Port data structure.
1944 * @did: destination port identifier.
1945 * @retry: number of retries to the command IOCB.
1947 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1948 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1949 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1950 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1951 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1953 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1954 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1955 * will be stored into the context1 field of the IOCB for the completion
1956 * callback function to the PLOGI ELS command.
1959 * 0 - Successfully issued a plogi for @vport
1960 * 1 - failed to issue a plogi for @vport
1963 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1965 struct lpfc_hba *phba = vport->phba;
1966 struct serv_parm *sp;
1967 struct lpfc_nodelist *ndlp;
1968 struct lpfc_iocbq *elsiocb;
1973 ndlp = lpfc_findnode_did(vport, did);
1974 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1977 /* If ndlp is not NULL, we will bump the reference count on it */
1978 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1979 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1984 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1986 /* For PLOGI request, remainder of payload is service parameters */
1987 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1988 pcmd += sizeof(uint32_t);
1989 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1990 sp = (struct serv_parm *) pcmd;
1993 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1994 * to device on remote loops work.
1996 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1997 sp->cmn.altBbCredit = 1;
1999 if (sp->cmn.fcphLow < FC_PH_4_3)
2000 sp->cmn.fcphLow = FC_PH_4_3;
2002 if (sp->cmn.fcphHigh < FC_PH3)
2003 sp->cmn.fcphHigh = FC_PH3;
2005 sp->cmn.valid_vendor_ver_level = 0;
2006 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2009 "Issue PLOGI: did:x%x",
2012 /* If our firmware supports this feature, convey that
2013 * information to the target using the vendor specific field.
2015 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2016 sp->cmn.valid_vendor_ver_level = 1;
2017 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2018 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2021 phba->fc_stat.elsXmitPLOGI++;
2022 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2023 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2025 if (ret == IOCB_ERROR) {
2026 lpfc_els_free_iocb(phba, elsiocb);
2033 * lpfc_cmpl_els_prli - Completion callback function for prli
2034 * @phba: pointer to lpfc hba data structure.
2035 * @cmdiocb: pointer to lpfc command iocb data structure.
2036 * @rspiocb: pointer to lpfc response iocb data structure.
2038 * This routine is the completion callback function for a Process Login
2039 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2040 * status. If there is error status reported, PRLI retry shall be attempted
2041 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2042 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2043 * ndlp to mark the PRLI completion.
2046 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2047 struct lpfc_iocbq *rspiocb)
2049 struct lpfc_vport *vport = cmdiocb->vport;
2050 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2052 struct lpfc_nodelist *ndlp;
2054 /* we pass cmdiocb to state machine which needs rspiocb as well */
2055 cmdiocb->context_un.rsp_iocb = rspiocb;
2057 irsp = &(rspiocb->iocb);
2058 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2059 spin_lock_irq(shost->host_lock);
2060 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2061 spin_unlock_irq(shost->host_lock);
2063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2064 "PRLI cmpl: status:x%x/x%x did:x%x",
2065 irsp->ulpStatus, irsp->un.ulpWord[4],
2068 /* Ddriver supports multiple FC4 types. Counters matter. */
2069 vport->fc_prli_sent--;
2071 /* PRLI completes to NPort <nlp_DID> */
2072 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2073 "0103 PRLI completes to NPort x%06x "
2074 "Data: x%x x%x x%x x%x\n",
2075 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2076 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2078 /* Check to see if link went down during discovery */
2079 if (lpfc_els_chk_latt(vport))
2082 if (irsp->ulpStatus) {
2083 /* Check for retry */
2084 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2085 /* ELS command is being retried */
2086 ndlp->fc4_prli_sent--;
2090 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2091 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2092 ndlp->nlp_DID, irsp->ulpStatus,
2093 irsp->un.ulpWord[4]);
2094 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2095 if (lpfc_error_lost_link(irsp))
2098 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2101 /* Good status, call state machine. However, if another
2102 * PRLI is outstanding, don't call the state machine
2103 * because final disposition to Mapped or Unmapped is
2106 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2110 lpfc_els_free_iocb(phba, cmdiocb);
2115 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2116 * @vport: pointer to a host virtual N_Port data structure.
2117 * @ndlp: pointer to a node-list data structure.
2118 * @retry: number of retries to the command IOCB.
2120 * This routine issues a Process Login (PRLI) ELS command for the
2121 * @vport. The PRLI service parameters are set up in the payload of the
2122 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2123 * is put to the IOCB completion callback func field before invoking the
2124 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2126 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2127 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2128 * will be stored into the context1 field of the IOCB for the completion
2129 * callback function to the PRLI ELS command.
2132 * 0 - successfully issued prli iocb command for @vport
2133 * 1 - failed to issue prli iocb command for @vport
2136 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2140 struct lpfc_hba *phba = vport->phba;
2142 struct lpfc_nvme_prli *npr_nvme;
2143 struct lpfc_iocbq *elsiocb;
2146 u32 local_nlp_type, elscmd;
2148 local_nlp_type = ndlp->nlp_fc4_type;
2151 if (local_nlp_type & NLP_FC4_FCP) {
2152 /* Payload is 4 + 16 = 20 x14 bytes. */
2153 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2154 elscmd = ELS_CMD_PRLI;
2155 } else if (local_nlp_type & NLP_FC4_NVME) {
2156 /* Payload is 4 + 20 = 24 x18 bytes. */
2157 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2158 elscmd = ELS_CMD_NVMEPRLI;
2160 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2161 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2162 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2165 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2166 ndlp->nlp_DID, elscmd);
2170 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2172 /* For PRLI request, remainder of payload is service parameters */
2173 memset(pcmd, 0, cmdsize);
2175 if (local_nlp_type & NLP_FC4_FCP) {
2176 /* Remainder of payload is FCP PRLI parameter page.
2177 * Note: this data structure is defined as
2178 * BE/LE in the structure definition so no
2179 * byte swap call is made.
2181 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2182 pcmd += sizeof(uint32_t);
2186 * If our firmware version is 3.20 or later,
2187 * set the following bits for FC-TAPE support.
2189 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2190 npr->ConfmComplAllowed = 1;
2192 npr->TaskRetryIdReq = 1;
2194 npr->estabImagePair = 1;
2195 npr->readXferRdyDis = 1;
2196 if (vport->cfg_first_burst_size)
2197 npr->writeXferRdyDis = 1;
2199 /* For FCP support */
2200 npr->prliType = PRLI_FCP_TYPE;
2201 npr->initiatorFunc = 1;
2202 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2204 /* Remove FCP type - processed. */
2205 local_nlp_type &= ~NLP_FC4_FCP;
2206 } else if (local_nlp_type & NLP_FC4_NVME) {
2207 /* Remainder of payload is NVME PRLI parameter page.
2208 * This data structure is the newer definition that
2209 * uses bf macros so a byte swap is required.
2211 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2212 pcmd += sizeof(uint32_t);
2213 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2214 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2215 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2217 /* Only initiators request first burst. */
2218 if ((phba->cfg_nvme_enable_fb) &&
2219 !phba->nvmet_support)
2220 bf_set(prli_fba, npr_nvme, 1);
2222 if (phba->nvmet_support) {
2223 bf_set(prli_tgt, npr_nvme, 1);
2224 bf_set(prli_disc, npr_nvme, 1);
2227 bf_set(prli_init, npr_nvme, 1);
2229 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2230 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2231 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2233 /* Remove NVME type - processed. */
2234 local_nlp_type &= ~NLP_FC4_NVME;
2237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2238 "Issue PRLI: did:x%x",
2239 ndlp->nlp_DID, 0, 0);
2241 phba->fc_stat.elsXmitPRLI++;
2242 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2243 spin_lock_irq(shost->host_lock);
2244 ndlp->nlp_flag |= NLP_PRLI_SND;
2245 spin_unlock_irq(shost->host_lock);
2246 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2248 spin_lock_irq(shost->host_lock);
2249 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2250 spin_unlock_irq(shost->host_lock);
2251 lpfc_els_free_iocb(phba, elsiocb);
2255 /* The vport counters are used for lpfc_scan_finished, but
2256 * the ndlp is used to track outstanding PRLIs for different
2259 vport->fc_prli_sent++;
2260 ndlp->fc4_prli_sent++;
2262 /* The driver supports 2 FC4 types. Make sure
2263 * a PRLI is issued for all types before exiting.
2265 if (local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2266 goto send_next_prli;
2272 * lpfc_rscn_disc - Perform rscn discovery for a vport
2273 * @vport: pointer to a host virtual N_Port data structure.
2275 * This routine performs Registration State Change Notification (RSCN)
2276 * discovery for a @vport. If the @vport's node port recovery count is not
2277 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2278 * the nodes that need recovery. If none of the PLOGI were needed through
2279 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2280 * invoked to check and handle possible more RSCN came in during the period
2281 * of processing the current ones.
2284 lpfc_rscn_disc(struct lpfc_vport *vport)
2286 lpfc_can_disctmo(vport);
2288 /* RSCN discovery */
2289 /* go thru NPR nodes and issue ELS PLOGIs */
2290 if (vport->fc_npr_cnt)
2291 if (lpfc_els_disc_plogi(vport))
2294 lpfc_end_rscn(vport);
2298 * lpfc_adisc_done - Complete the adisc phase of discovery
2299 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2301 * This function is called when the final ADISC is completed during discovery.
2302 * This function handles clearing link attention or issuing reg_vpi depending
2303 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2305 * This function is called with no locks held.
2308 lpfc_adisc_done(struct lpfc_vport *vport)
2310 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2311 struct lpfc_hba *phba = vport->phba;
2314 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2315 * and continue discovery.
2317 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2318 !(vport->fc_flag & FC_RSCN_MODE) &&
2319 (phba->sli_rev < LPFC_SLI_REV4)) {
2320 /* The ADISCs are complete. Doesn't matter if they
2321 * succeeded or failed because the ADISC completion
2322 * routine guarantees to call the state machine and
2323 * the RPI is either unregistered (failed ADISC response)
2324 * or the RPI is still valid and the node is marked
2325 * mapped for a target. The exchanges should be in the
2326 * correct state. This code is specific to SLI3.
2328 lpfc_issue_clear_la(phba, vport);
2329 lpfc_issue_reg_vpi(phba, vport);
2333 * For SLI2, we need to set port_state to READY
2334 * and continue discovery.
2336 if (vport->port_state < LPFC_VPORT_READY) {
2337 /* If we get here, there is nothing to ADISC */
2338 lpfc_issue_clear_la(phba, vport);
2339 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2340 vport->num_disc_nodes = 0;
2341 /* go thru NPR list, issue ELS PLOGIs */
2342 if (vport->fc_npr_cnt)
2343 lpfc_els_disc_plogi(vport);
2344 if (!vport->num_disc_nodes) {
2345 spin_lock_irq(shost->host_lock);
2346 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2347 spin_unlock_irq(shost->host_lock);
2348 lpfc_can_disctmo(vport);
2349 lpfc_end_rscn(vport);
2352 vport->port_state = LPFC_VPORT_READY;
2354 lpfc_rscn_disc(vport);
2358 * lpfc_more_adisc - Issue more adisc as needed
2359 * @vport: pointer to a host virtual N_Port data structure.
2361 * This routine determines whether there are more ndlps on a @vport
2362 * node list need to have Address Discover (ADISC) issued. If so, it will
2363 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2364 * remaining nodes which need to have ADISC sent.
2367 lpfc_more_adisc(struct lpfc_vport *vport)
2369 if (vport->num_disc_nodes)
2370 vport->num_disc_nodes--;
2371 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2372 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2373 "0210 Continue discovery with %d ADISCs to go "
2374 "Data: x%x x%x x%x\n",
2375 vport->num_disc_nodes, vport->fc_adisc_cnt,
2376 vport->fc_flag, vport->port_state);
2377 /* Check to see if there are more ADISCs to be sent */
2378 if (vport->fc_flag & FC_NLP_MORE) {
2379 lpfc_set_disctmo(vport);
2380 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2381 lpfc_els_disc_adisc(vport);
2383 if (!vport->num_disc_nodes)
2384 lpfc_adisc_done(vport);
2389 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2390 * @phba: pointer to lpfc hba data structure.
2391 * @cmdiocb: pointer to lpfc command iocb data structure.
2392 * @rspiocb: pointer to lpfc response iocb data structure.
2394 * This routine is the completion function for issuing the Address Discover
2395 * (ADISC) command. It first checks to see whether link went down during
2396 * the discovery process. If so, the node will be marked as node port
2397 * recovery for issuing discover IOCB by the link attention handler and
2398 * exit. Otherwise, the response status is checked. If error was reported
2399 * in the response status, the ADISC command shall be retried by invoking
2400 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2401 * the response status, the state machine is invoked to set transition
2402 * with respect to NLP_EVT_CMPL_ADISC event.
2405 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2406 struct lpfc_iocbq *rspiocb)
2408 struct lpfc_vport *vport = cmdiocb->vport;
2409 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2411 struct lpfc_nodelist *ndlp;
2414 /* we pass cmdiocb to state machine which needs rspiocb as well */
2415 cmdiocb->context_un.rsp_iocb = rspiocb;
2417 irsp = &(rspiocb->iocb);
2418 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2420 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2421 "ADISC cmpl: status:x%x/x%x did:x%x",
2422 irsp->ulpStatus, irsp->un.ulpWord[4],
2425 /* Since ndlp can be freed in the disc state machine, note if this node
2426 * is being used during discovery.
2428 spin_lock_irq(shost->host_lock);
2429 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2430 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2431 spin_unlock_irq(shost->host_lock);
2432 /* ADISC completes to NPort <nlp_DID> */
2433 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2434 "0104 ADISC completes to NPort x%x "
2435 "Data: x%x x%x x%x x%x x%x\n",
2436 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2437 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2438 /* Check to see if link went down during discovery */
2439 if (lpfc_els_chk_latt(vport)) {
2440 spin_lock_irq(shost->host_lock);
2441 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2442 spin_unlock_irq(shost->host_lock);
2446 if (irsp->ulpStatus) {
2447 /* Check for retry */
2448 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2449 /* ELS command is being retried */
2451 spin_lock_irq(shost->host_lock);
2452 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2453 spin_unlock_irq(shost->host_lock);
2454 lpfc_set_disctmo(vport);
2459 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2460 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2461 ndlp->nlp_DID, irsp->ulpStatus,
2462 irsp->un.ulpWord[4]);
2463 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2464 if (!lpfc_error_lost_link(irsp))
2465 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2466 NLP_EVT_CMPL_ADISC);
2468 /* Good status, call state machine */
2469 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2470 NLP_EVT_CMPL_ADISC);
2472 /* Check to see if there are more ADISCs to be sent */
2473 if (disc && vport->num_disc_nodes)
2474 lpfc_more_adisc(vport);
2476 lpfc_els_free_iocb(phba, cmdiocb);
2481 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2482 * @vport: pointer to a virtual N_Port data structure.
2483 * @ndlp: pointer to a node-list data structure.
2484 * @retry: number of retries to the command IOCB.
2486 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2487 * @vport. It prepares the payload of the ADISC ELS command, updates the
2488 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2489 * to issue the ADISC ELS command.
2491 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2492 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2493 * will be stored into the context1 field of the IOCB for the completion
2494 * callback function to the ADISC ELS command.
2497 * 0 - successfully issued adisc
2498 * 1 - failed to issue adisc
2501 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2505 struct lpfc_hba *phba = vport->phba;
2507 struct lpfc_iocbq *elsiocb;
2511 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2512 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2513 ndlp->nlp_DID, ELS_CMD_ADISC);
2517 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2519 /* For ADISC request, remainder of payload is service parameters */
2520 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2521 pcmd += sizeof(uint32_t);
2523 /* Fill in ADISC payload */
2524 ap = (ADISC *) pcmd;
2525 ap->hardAL_PA = phba->fc_pref_ALPA;
2526 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2527 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2528 ap->DID = be32_to_cpu(vport->fc_myDID);
2530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2531 "Issue ADISC: did:x%x",
2532 ndlp->nlp_DID, 0, 0);
2534 phba->fc_stat.elsXmitADISC++;
2535 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2536 spin_lock_irq(shost->host_lock);
2537 ndlp->nlp_flag |= NLP_ADISC_SND;
2538 spin_unlock_irq(shost->host_lock);
2539 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2541 spin_lock_irq(shost->host_lock);
2542 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2543 spin_unlock_irq(shost->host_lock);
2544 lpfc_els_free_iocb(phba, elsiocb);
2551 * lpfc_cmpl_els_logo - Completion callback function for logo
2552 * @phba: pointer to lpfc hba data structure.
2553 * @cmdiocb: pointer to lpfc command iocb data structure.
2554 * @rspiocb: pointer to lpfc response iocb data structure.
2556 * This routine is the completion function for issuing the ELS Logout (LOGO)
2557 * command. If no error status was reported from the LOGO response, the
2558 * state machine of the associated ndlp shall be invoked for transition with
2559 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2560 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2563 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2564 struct lpfc_iocbq *rspiocb)
2566 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2567 struct lpfc_vport *vport = ndlp->vport;
2568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2570 struct lpfcMboxq *mbox;
2571 unsigned long flags;
2572 uint32_t skip_recovery = 0;
2574 /* we pass cmdiocb to state machine which needs rspiocb as well */
2575 cmdiocb->context_un.rsp_iocb = rspiocb;
2577 irsp = &(rspiocb->iocb);
2578 spin_lock_irq(shost->host_lock);
2579 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2580 spin_unlock_irq(shost->host_lock);
2582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2583 "LOGO cmpl: status:x%x/x%x did:x%x",
2584 irsp->ulpStatus, irsp->un.ulpWord[4],
2587 /* LOGO completes to NPort <nlp_DID> */
2588 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2589 "0105 LOGO completes to NPort x%x "
2590 "Data: x%x x%x x%x x%x\n",
2591 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2592 irsp->ulpTimeout, vport->num_disc_nodes);
2594 if (lpfc_els_chk_latt(vport)) {
2599 /* Check to see if link went down during discovery */
2600 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2601 /* NLP_EVT_DEVICE_RM should unregister the RPI
2602 * which should abort all outstanding IOs.
2604 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2610 if (irsp->ulpStatus) {
2611 /* Check for retry */
2612 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2613 /* ELS command is being retried */
2618 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2619 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2620 ndlp->nlp_DID, irsp->ulpStatus,
2621 irsp->un.ulpWord[4]);
2622 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2623 if (lpfc_error_lost_link(irsp)) {
2629 /* Call state machine. This will unregister the rpi if needed. */
2630 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2633 lpfc_els_free_iocb(phba, cmdiocb);
2634 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2635 if ((vport->fc_flag & FC_PT2PT) &&
2636 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2637 phba->pport->fc_myDID = 0;
2639 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2640 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2641 if (phba->nvmet_support)
2642 lpfc_nvmet_update_targetport(phba);
2644 lpfc_nvme_update_localport(phba->pport);
2647 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2649 lpfc_config_link(phba, mbox);
2650 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2651 mbox->vport = vport;
2652 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2654 mempool_free(mbox, phba->mbox_mem_pool);
2661 * If the node is a target, the handling attempts to recover the port.
2662 * For any other port type, the rpi is unregistered as an implicit
2665 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2666 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2667 spin_lock_irqsave(shost->host_lock, flags);
2668 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2669 spin_unlock_irqrestore(shost->host_lock, flags);
2671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2672 "3187 LOGO completes to NPort x%x: Start "
2673 "Recovery Data: x%x x%x x%x x%x\n",
2674 ndlp->nlp_DID, irsp->ulpStatus,
2675 irsp->un.ulpWord[4], irsp->ulpTimeout,
2676 vport->num_disc_nodes);
2677 lpfc_disc_start(vport);
2683 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2684 * @vport: pointer to a virtual N_Port data structure.
2685 * @ndlp: pointer to a node-list data structure.
2686 * @retry: number of retries to the command IOCB.
2688 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2689 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2690 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2691 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2693 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2694 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2695 * will be stored into the context1 field of the IOCB for the completion
2696 * callback function to the LOGO ELS command.
2699 * 0 - successfully issued logo
2700 * 1 - failed to issue logo
2703 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2706 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2707 struct lpfc_hba *phba = vport->phba;
2708 struct lpfc_iocbq *elsiocb;
2713 spin_lock_irq(shost->host_lock);
2714 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2715 spin_unlock_irq(shost->host_lock);
2718 spin_unlock_irq(shost->host_lock);
2720 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2721 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2722 ndlp->nlp_DID, ELS_CMD_LOGO);
2726 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2727 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2728 pcmd += sizeof(uint32_t);
2730 /* Fill in LOGO payload */
2731 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2732 pcmd += sizeof(uint32_t);
2733 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2736 "Issue LOGO: did:x%x",
2737 ndlp->nlp_DID, 0, 0);
2740 * If we are issuing a LOGO, we may try to recover the remote NPort
2741 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2742 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2743 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2744 * for that ELS cmd. To avoid this situation, lets get rid of the
2745 * RPI right now, before any ELS cmds are sent.
2747 spin_lock_irq(shost->host_lock);
2748 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2749 spin_unlock_irq(shost->host_lock);
2750 if (lpfc_unreg_rpi(vport, ndlp)) {
2751 lpfc_els_free_iocb(phba, elsiocb);
2755 phba->fc_stat.elsXmitLOGO++;
2756 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2757 spin_lock_irq(shost->host_lock);
2758 ndlp->nlp_flag |= NLP_LOGO_SND;
2759 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2760 spin_unlock_irq(shost->host_lock);
2761 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2763 if (rc == IOCB_ERROR) {
2764 spin_lock_irq(shost->host_lock);
2765 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2766 spin_unlock_irq(shost->host_lock);
2767 lpfc_els_free_iocb(phba, elsiocb);
2774 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2775 * @phba: pointer to lpfc hba data structure.
2776 * @cmdiocb: pointer to lpfc command iocb data structure.
2777 * @rspiocb: pointer to lpfc response iocb data structure.
2779 * This routine is a generic completion callback function for ELS commands.
2780 * Specifically, it is the callback function which does not need to perform
2781 * any command specific operations. It is currently used by the ELS command
2782 * issuing routines for the ELS State Change Request (SCR),
2783 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2784 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2785 * certain debug loggings, this callback function simply invokes the
2786 * lpfc_els_chk_latt() routine to check whether link went down during the
2787 * discovery process.
2790 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2791 struct lpfc_iocbq *rspiocb)
2793 struct lpfc_vport *vport = cmdiocb->vport;
2796 irsp = &rspiocb->iocb;
2798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2799 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2800 irsp->ulpStatus, irsp->un.ulpWord[4],
2801 irsp->un.elsreq64.remoteID);
2802 /* ELS cmd tag <ulpIoTag> completes */
2803 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2804 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2805 irsp->ulpIoTag, irsp->ulpStatus,
2806 irsp->un.ulpWord[4], irsp->ulpTimeout);
2807 /* Check to see if link went down during discovery */
2808 lpfc_els_chk_latt(vport);
2809 lpfc_els_free_iocb(phba, cmdiocb);
2814 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2815 * @vport: pointer to a host virtual N_Port data structure.
2816 * @nportid: N_Port identifier to the remote node.
2817 * @retry: number of retries to the command IOCB.
2819 * This routine issues a State Change Request (SCR) to a fabric node
2820 * on a @vport. The remote node @nportid is passed into the function. It
2821 * first search the @vport node list to find the matching ndlp. If no such
2822 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2823 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2824 * routine is invoked to send the SCR IOCB.
2826 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2827 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2828 * will be stored into the context1 field of the IOCB for the completion
2829 * callback function to the SCR ELS command.
2832 * 0 - Successfully issued scr command
2833 * 1 - Failed to issue scr command
2836 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2838 struct lpfc_hba *phba = vport->phba;
2839 struct lpfc_iocbq *elsiocb;
2842 struct lpfc_nodelist *ndlp;
2844 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2846 ndlp = lpfc_findnode_did(vport, nportid);
2848 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2851 lpfc_nlp_init(vport, ndlp, nportid);
2852 lpfc_enqueue_node(vport, ndlp);
2853 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2854 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2859 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2860 ndlp->nlp_DID, ELS_CMD_SCR);
2863 /* This will trigger the release of the node just
2870 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2872 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2873 pcmd += sizeof(uint32_t);
2875 /* For SCR, remainder of payload is SCR parameter page */
2876 memset(pcmd, 0, sizeof(SCR));
2877 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2879 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2880 "Issue SCR: did:x%x",
2881 ndlp->nlp_DID, 0, 0);
2883 phba->fc_stat.elsXmitSCR++;
2884 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2885 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2887 /* The additional lpfc_nlp_put will cause the following
2888 * lpfc_els_free_iocb routine to trigger the rlease of
2892 lpfc_els_free_iocb(phba, elsiocb);
2895 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2896 * trigger the release of node.
2904 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2905 * @vport: pointer to a host virtual N_Port data structure.
2906 * @nportid: N_Port identifier to the remote node.
2907 * @retry: number of retries to the command IOCB.
2909 * This routine issues a Fibre Channel Address Resolution Response
2910 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2911 * is passed into the function. It first search the @vport node list to find
2912 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2913 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2914 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2916 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2917 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2918 * will be stored into the context1 field of the IOCB for the completion
2919 * callback function to the PARPR ELS command.
2922 * 0 - Successfully issued farpr command
2923 * 1 - Failed to issue farpr command
2926 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2928 struct lpfc_hba *phba = vport->phba;
2929 struct lpfc_iocbq *elsiocb;
2934 struct lpfc_nodelist *ondlp;
2935 struct lpfc_nodelist *ndlp;
2937 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2939 ndlp = lpfc_findnode_did(vport, nportid);
2941 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2944 lpfc_nlp_init(vport, ndlp, nportid);
2945 lpfc_enqueue_node(vport, ndlp);
2946 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2947 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2952 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2953 ndlp->nlp_DID, ELS_CMD_RNID);
2955 /* This will trigger the release of the node just
2962 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2964 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2965 pcmd += sizeof(uint32_t);
2967 /* Fill in FARPR payload */
2968 fp = (FARP *) (pcmd);
2969 memset(fp, 0, sizeof(FARP));
2970 lp = (uint32_t *) pcmd;
2971 *lp++ = be32_to_cpu(nportid);
2972 *lp++ = be32_to_cpu(vport->fc_myDID);
2974 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2976 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2977 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2978 ondlp = lpfc_findnode_did(vport, nportid);
2979 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2980 memcpy(&fp->OportName, &ondlp->nlp_portname,
2981 sizeof(struct lpfc_name));
2982 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2983 sizeof(struct lpfc_name));
2986 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2987 "Issue FARPR: did:x%x",
2988 ndlp->nlp_DID, 0, 0);
2990 phba->fc_stat.elsXmitFARPR++;
2991 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2992 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2994 /* The additional lpfc_nlp_put will cause the following
2995 * lpfc_els_free_iocb routine to trigger the release of
2999 lpfc_els_free_iocb(phba, elsiocb);
3002 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3003 * trigger the release of the node.
3010 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3011 * @vport: pointer to a host virtual N_Port data structure.
3012 * @nlp: pointer to a node-list data structure.
3014 * This routine cancels the timer with a delayed IOCB-command retry for
3015 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3016 * removes the ELS retry event if it presents. In addition, if the
3017 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3018 * commands are sent for the @vport's nodes that require issuing discovery
3022 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3025 struct lpfc_work_evt *evtp;
3027 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3029 spin_lock_irq(shost->host_lock);
3030 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3031 spin_unlock_irq(shost->host_lock);
3032 del_timer_sync(&nlp->nlp_delayfunc);
3033 nlp->nlp_last_elscmd = 0;
3034 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3035 list_del_init(&nlp->els_retry_evt.evt_listp);
3036 /* Decrement nlp reference count held for the delayed retry */
3037 evtp = &nlp->els_retry_evt;
3038 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3040 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3041 spin_lock_irq(shost->host_lock);
3042 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3043 spin_unlock_irq(shost->host_lock);
3044 if (vport->num_disc_nodes) {
3045 if (vport->port_state < LPFC_VPORT_READY) {
3046 /* Check if there are more ADISCs to be sent */
3047 lpfc_more_adisc(vport);
3049 /* Check if there are more PLOGIs to be sent */
3050 lpfc_more_plogi(vport);
3051 if (vport->num_disc_nodes == 0) {
3052 spin_lock_irq(shost->host_lock);
3053 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3054 spin_unlock_irq(shost->host_lock);
3055 lpfc_can_disctmo(vport);
3056 lpfc_end_rscn(vport);
3065 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3066 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3068 * This routine is invoked by the ndlp delayed-function timer to check
3069 * whether there is any pending ELS retry event(s) with the node. If not, it
3070 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3071 * adds the delayed events to the HBA work list and invokes the
3072 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3073 * event. Note that lpfc_nlp_get() is called before posting the event to
3074 * the work list to hold reference count of ndlp so that it guarantees the
3075 * reference to ndlp will still be available when the worker thread gets
3076 * to the event associated with the ndlp.
3079 lpfc_els_retry_delay(unsigned long ptr)
3081 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
3082 struct lpfc_vport *vport = ndlp->vport;
3083 struct lpfc_hba *phba = vport->phba;
3084 unsigned long flags;
3085 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3087 spin_lock_irqsave(&phba->hbalock, flags);
3088 if (!list_empty(&evtp->evt_listp)) {
3089 spin_unlock_irqrestore(&phba->hbalock, flags);
3093 /* We need to hold the node by incrementing the reference
3094 * count until the queued work is done
3096 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3097 if (evtp->evt_arg1) {
3098 evtp->evt = LPFC_EVT_ELS_RETRY;
3099 list_add_tail(&evtp->evt_listp, &phba->work_list);
3100 lpfc_worker_wake_up(phba);
3102 spin_unlock_irqrestore(&phba->hbalock, flags);
3107 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3108 * @ndlp: pointer to a node-list data structure.
3110 * This routine is the worker-thread handler for processing the @ndlp delayed
3111 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3112 * the last ELS command from the associated ndlp and invokes the proper ELS
3113 * function according to the delayed ELS command to retry the command.
3116 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3118 struct lpfc_vport *vport = ndlp->vport;
3119 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3120 uint32_t cmd, retry;
3122 spin_lock_irq(shost->host_lock);
3123 cmd = ndlp->nlp_last_elscmd;
3124 ndlp->nlp_last_elscmd = 0;
3126 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3127 spin_unlock_irq(shost->host_lock);
3131 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3132 spin_unlock_irq(shost->host_lock);
3134 * If a discovery event readded nlp_delayfunc after timer
3135 * firing and before processing the timer, cancel the
3138 del_timer_sync(&ndlp->nlp_delayfunc);
3139 retry = ndlp->nlp_retry;
3140 ndlp->nlp_retry = 0;
3144 lpfc_issue_els_flogi(vport, ndlp, retry);
3147 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3148 ndlp->nlp_prev_state = ndlp->nlp_state;
3149 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3153 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3154 ndlp->nlp_prev_state = ndlp->nlp_state;
3155 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3159 case ELS_CMD_NVMEPRLI:
3160 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3161 ndlp->nlp_prev_state = ndlp->nlp_state;
3162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3166 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3167 ndlp->nlp_prev_state = ndlp->nlp_state;
3168 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3172 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3173 lpfc_issue_els_fdisc(vport, ndlp, retry);
3180 * lpfc_els_retry - Make retry decision on an els command iocb
3181 * @phba: pointer to lpfc hba data structure.
3182 * @cmdiocb: pointer to lpfc command iocb data structure.
3183 * @rspiocb: pointer to lpfc response iocb data structure.
3185 * This routine makes a retry decision on an ELS command IOCB, which has
3186 * failed. The following ELS IOCBs use this function for retrying the command
3187 * when previously issued command responsed with error status: FLOGI, PLOGI,
3188 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3189 * returned error status, it makes the decision whether a retry shall be
3190 * issued for the command, and whether a retry shall be made immediately or
3191 * delayed. In the former case, the corresponding ELS command issuing-function
3192 * is called to retry the command. In the later case, the ELS command shall
3193 * be posted to the ndlp delayed event and delayed function timer set to the
3194 * ndlp for the delayed command issusing.
3197 * 0 - No retry of els command is made
3198 * 1 - Immediate or delayed retry of els command is made
3201 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3202 struct lpfc_iocbq *rspiocb)
3204 struct lpfc_vport *vport = cmdiocb->vport;
3205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3206 IOCB_t *irsp = &rspiocb->iocb;
3207 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3208 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3211 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3217 /* Note: context2 may be 0 for internal driver abort
3218 * of delays ELS command.
3221 if (pcmd && pcmd->virt) {
3222 elscmd = (uint32_t *) (pcmd->virt);
3226 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3227 did = ndlp->nlp_DID;
3229 /* We should only hit this case for retrying PLOGI */
3230 did = irsp->un.elsreq64.remoteID;
3231 ndlp = lpfc_findnode_did(vport, did);
3232 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3233 && (cmd != ELS_CMD_PLOGI))
3237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3238 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3239 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3241 switch (irsp->ulpStatus) {
3242 case IOSTAT_FCP_RSP_ERROR:
3244 case IOSTAT_REMOTE_STOP:
3245 if (phba->sli_rev == LPFC_SLI_REV4) {
3246 /* This IO was aborted by the target, we don't
3247 * know the rxid and because we did not send the
3248 * ABTS we cannot generate and RRQ.
3250 lpfc_set_rrq_active(phba, ndlp,
3251 cmdiocb->sli4_lxritag, 0, 0);
3254 case IOSTAT_LOCAL_REJECT:
3255 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3256 case IOERR_LOOP_OPEN_FAILURE:
3257 if (cmd == ELS_CMD_FLOGI) {
3258 if (PCI_DEVICE_ID_HORNET ==
3259 phba->pcidev->device) {
3260 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3261 phba->pport->fc_myDID = 0;
3262 phba->alpa_map[0] = 0;
3263 phba->alpa_map[1] = 0;
3266 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3271 case IOERR_ILLEGAL_COMMAND:
3272 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3273 "0124 Retry illegal cmd x%x "
3274 "retry:x%x delay:x%x\n",
3275 cmd, cmdiocb->retry, delay);
3277 /* All command's retry policy */
3279 if (cmdiocb->retry > 2)
3283 case IOERR_NO_RESOURCES:
3284 logerr = 1; /* HBA out of resources */
3286 if (cmdiocb->retry > 100)
3291 case IOERR_ILLEGAL_FRAME:
3296 case IOERR_SEQUENCE_TIMEOUT:
3297 case IOERR_INVALID_RPI:
3298 if (cmd == ELS_CMD_PLOGI &&
3299 did == NameServer_DID) {
3300 /* Continue forever if plogi to */
3301 /* the nameserver fails */
3310 case IOSTAT_NPORT_RJT:
3311 case IOSTAT_FABRIC_RJT:
3312 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3318 case IOSTAT_NPORT_BSY:
3319 case IOSTAT_FABRIC_BSY:
3320 logerr = 1; /* Fabric / Remote NPort out of resources */
3325 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3326 /* Added for Vendor specifc support
3327 * Just keep retrying for these Rsn / Exp codes
3329 switch (stat.un.b.lsRjtRsnCode) {
3330 case LSRJT_UNABLE_TPC:
3331 if (stat.un.b.lsRjtRsnCodeExp ==
3332 LSEXP_CMD_IN_PROGRESS) {
3333 if (cmd == ELS_CMD_PLOGI) {
3340 if (stat.un.b.lsRjtRsnCodeExp ==
3341 LSEXP_CANT_GIVE_DATA) {
3342 if (cmd == ELS_CMD_PLOGI) {
3349 if ((cmd == ELS_CMD_PLOGI) ||
3350 (cmd == ELS_CMD_PRLI) ||
3351 (cmd == ELS_CMD_NVMEPRLI)) {
3353 maxretry = lpfc_max_els_tries + 1;
3357 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3358 (cmd == ELS_CMD_FDISC) &&
3359 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3360 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3361 "0125 FDISC Failed (x%x). "
3362 "Fabric out of resources\n",
3363 stat.un.lsRjtError);
3364 lpfc_vport_set_state(vport,
3365 FC_VPORT_NO_FABRIC_RSCS);
3369 case LSRJT_LOGICAL_BSY:
3370 if ((cmd == ELS_CMD_PLOGI) ||
3371 (cmd == ELS_CMD_PRLI) ||
3372 (cmd == ELS_CMD_NVMEPRLI)) {
3375 } else if (cmd == ELS_CMD_FDISC) {
3376 /* FDISC retry policy */
3378 if (cmdiocb->retry >= 32)
3384 case LSRJT_LOGICAL_ERR:
3385 /* There are some cases where switches return this
3386 * error when they are not ready and should be returning
3387 * Logical Busy. We should delay every time.
3389 if (cmd == ELS_CMD_FDISC &&
3390 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3396 case LSRJT_PROTOCOL_ERR:
3397 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3398 (cmd == ELS_CMD_FDISC) &&
3399 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3400 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3402 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3403 "0122 FDISC Failed (x%x). "
3404 "Fabric Detected Bad WWN\n",
3405 stat.un.lsRjtError);
3406 lpfc_vport_set_state(vport,
3407 FC_VPORT_FABRIC_REJ_WWN);
3410 case LSRJT_VENDOR_UNIQUE:
3411 if ((stat.un.b.vendorUnique == 0x45) &&
3412 (cmd == ELS_CMD_FLOGI)) {
3419 case IOSTAT_INTERMED_RSP:
3427 if (did == FDMI_DID)
3430 if ((cmd == ELS_CMD_FLOGI) &&
3431 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3432 !lpfc_error_lost_link(irsp)) {
3433 /* FLOGI retry policy */
3435 /* retry FLOGI forever */
3436 if (phba->link_flag != LS_LOOPBACK_MODE)
3441 if (cmdiocb->retry >= 100)
3443 else if (cmdiocb->retry >= 32)
3445 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3446 /* retry FDISCs every second up to devloss */
3448 maxretry = vport->cfg_devloss_tmo;
3453 if (maxretry && (cmdiocb->retry >= maxretry)) {
3454 phba->fc_stat.elsRetryExceeded++;
3458 if ((vport->load_flag & FC_UNLOADING) != 0)
3463 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3464 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3465 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3466 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3467 "2849 Stop retry ELS command "
3468 "x%x to remote NPORT x%x, "
3469 "Data: x%x x%x\n", cmd, did,
3470 cmdiocb->retry, delay);
3475 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3476 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3477 "0107 Retry ELS command x%x to remote "
3478 "NPORT x%x Data: x%x x%x\n",
3479 cmd, did, cmdiocb->retry, delay);
3481 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3482 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3483 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3484 IOERR_NO_RESOURCES))) {
3485 /* Don't reset timer for no resources */
3487 /* If discovery / RSCN timer is running, reset it */
3488 if (timer_pending(&vport->fc_disctmo) ||
3489 (vport->fc_flag & FC_RSCN_MODE))
3490 lpfc_set_disctmo(vport);
3493 phba->fc_stat.elsXmitRetry++;
3494 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3495 phba->fc_stat.elsDelayRetry++;
3496 ndlp->nlp_retry = cmdiocb->retry;
3498 /* delay is specified in milliseconds */
3499 mod_timer(&ndlp->nlp_delayfunc,
3500 jiffies + msecs_to_jiffies(delay));
3501 spin_lock_irq(shost->host_lock);
3502 ndlp->nlp_flag |= NLP_DELAY_TMO;
3503 spin_unlock_irq(shost->host_lock);
3505 ndlp->nlp_prev_state = ndlp->nlp_state;
3506 if ((cmd == ELS_CMD_PRLI) ||
3507 (cmd == ELS_CMD_NVMEPRLI))
3508 lpfc_nlp_set_state(vport, ndlp,
3509 NLP_STE_PRLI_ISSUE);
3511 lpfc_nlp_set_state(vport, ndlp,
3513 ndlp->nlp_last_elscmd = cmd;
3519 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3522 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3525 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3526 ndlp->nlp_prev_state = ndlp->nlp_state;
3527 lpfc_nlp_set_state(vport, ndlp,
3528 NLP_STE_PLOGI_ISSUE);
3530 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3533 ndlp->nlp_prev_state = ndlp->nlp_state;
3534 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3535 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3538 case ELS_CMD_NVMEPRLI:
3539 ndlp->nlp_prev_state = ndlp->nlp_state;
3540 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3541 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3544 ndlp->nlp_prev_state = ndlp->nlp_state;
3545 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3546 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3550 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3552 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3553 "0137 No retry ELS command x%x to remote "
3554 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3555 cmd, did, irsp->ulpStatus,
3556 irsp->un.ulpWord[4]);
3559 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3560 "0108 No retry ELS command x%x to remote "
3561 "NPORT x%x Retried:%d Error:x%x/%x\n",
3562 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3563 irsp->un.ulpWord[4]);
3569 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3570 * @phba: pointer to lpfc hba data structure.
3571 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3573 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3574 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3575 * checks to see whether there is a lpfc DMA buffer associated with the
3576 * response of the command IOCB. If so, it will be released before releasing
3577 * the lpfc DMA buffer associated with the IOCB itself.
3580 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3583 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3585 struct lpfc_dmabuf *buf_ptr;
3587 /* Free the response before processing the command. */
3588 if (!list_empty(&buf_ptr1->list)) {
3589 list_remove_head(&buf_ptr1->list, buf_ptr,
3592 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3595 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3601 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3602 * @phba: pointer to lpfc hba data structure.
3603 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3605 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3606 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3610 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3613 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3615 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3621 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3622 * @phba: pointer to lpfc hba data structure.
3623 * @elsiocb: pointer to lpfc els command iocb data structure.
3625 * This routine frees a command IOCB and its associated resources. The
3626 * command IOCB data structure contains the reference to various associated
3627 * resources, these fields must be set to NULL if the associated reference
3629 * context1 - reference to ndlp
3630 * context2 - reference to cmd
3631 * context2->next - reference to rsp
3632 * context3 - reference to bpl
3634 * It first properly decrements the reference count held on ndlp for the
3635 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3636 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3637 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3638 * adds the DMA buffer the @phba data structure for the delayed release.
3639 * If reference to the Buffer Pointer List (BPL) is present, the
3640 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3641 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3642 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3645 * 0 - Success (currently, always return 0)
3648 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3650 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3651 struct lpfc_nodelist *ndlp;
3653 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3655 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3658 /* If the ndlp is not being used by another discovery
3661 if (!lpfc_nlp_not_used(ndlp)) {
3662 /* If ndlp is being used by another discovery
3663 * thread, just clear NLP_DEFER_RM
3665 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3670 elsiocb->context1 = NULL;
3672 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3673 if (elsiocb->context2) {
3674 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3675 /* Firmware could still be in progress of DMAing
3676 * payload, so don't free data buffer till after
3679 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3680 buf_ptr = elsiocb->context2;
3681 elsiocb->context2 = NULL;
3684 spin_lock_irq(&phba->hbalock);
3685 if (!list_empty(&buf_ptr->list)) {
3686 list_remove_head(&buf_ptr->list,
3687 buf_ptr1, struct lpfc_dmabuf,
3689 INIT_LIST_HEAD(&buf_ptr1->list);
3690 list_add_tail(&buf_ptr1->list,
3694 INIT_LIST_HEAD(&buf_ptr->list);
3695 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3697 spin_unlock_irq(&phba->hbalock);
3700 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3701 lpfc_els_free_data(phba, buf_ptr1);
3702 elsiocb->context2 = NULL;
3706 if (elsiocb->context3) {
3707 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3708 lpfc_els_free_bpl(phba, buf_ptr);
3709 elsiocb->context3 = NULL;
3711 lpfc_sli_release_iocbq(phba, elsiocb);
3716 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3717 * @phba: pointer to lpfc hba data structure.
3718 * @cmdiocb: pointer to lpfc command iocb data structure.
3719 * @rspiocb: pointer to lpfc response iocb data structure.
3721 * This routine is the completion callback function to the Logout (LOGO)
3722 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3723 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3724 * release the ndlp if it has the last reference remaining (reference count
3725 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3726 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3727 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3728 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3729 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3730 * IOCB data structure.
3733 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3734 struct lpfc_iocbq *rspiocb)
3736 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3737 struct lpfc_vport *vport = cmdiocb->vport;
3740 irsp = &rspiocb->iocb;
3741 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3742 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3743 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3744 /* ACC to LOGO completes to NPort <nlp_DID> */
3745 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3746 "0109 ACC to LOGO completes to NPort x%x "
3747 "Data: x%x x%x x%x\n",
3748 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3751 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3752 /* NPort Recovery mode or node is just allocated */
3753 if (!lpfc_nlp_not_used(ndlp)) {
3754 /* If the ndlp is being used by another discovery
3755 * thread, just unregister the RPI.
3757 lpfc_unreg_rpi(vport, ndlp);
3759 /* Indicate the node has already released, should
3760 * not reference to it from within lpfc_els_free_iocb.
3762 cmdiocb->context1 = NULL;
3767 * The driver received a LOGO from the rport and has ACK'd it.
3768 * At this point, the driver is done so release the IOCB
3770 lpfc_els_free_iocb(phba, cmdiocb);
3774 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3775 * @phba: pointer to lpfc hba data structure.
3776 * @pmb: pointer to the driver internal queue element for mailbox command.
3778 * This routine is the completion callback function for unregister default
3779 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3780 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3781 * decrements the ndlp reference count held for this completion callback
3782 * function. After that, it invokes the lpfc_nlp_not_used() to check
3783 * whether there is only one reference left on the ndlp. If so, it will
3784 * perform one more decrement and trigger the release of the ndlp.
3787 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3789 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3790 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3792 pmb->context1 = NULL;
3793 pmb->context2 = NULL;
3795 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3797 mempool_free(pmb, phba->mbox_mem_pool);
3799 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3800 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3801 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3802 kref_read(&ndlp->kref),
3803 ndlp->nlp_usg_map, ndlp);
3804 if (NLP_CHK_NODE_ACT(ndlp)) {
3806 /* This is the end of the default RPI cleanup logic for
3807 * this ndlp. If no other discovery threads are using
3808 * this ndlp, free all resources associated with it.
3810 lpfc_nlp_not_used(ndlp);
3812 lpfc_drop_node(ndlp->vport, ndlp);
3820 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3821 * @phba: pointer to lpfc hba data structure.
3822 * @cmdiocb: pointer to lpfc command iocb data structure.
3823 * @rspiocb: pointer to lpfc response iocb data structure.
3825 * This routine is the completion callback function for ELS Response IOCB
3826 * command. In normal case, this callback function just properly sets the
3827 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3828 * field in the command IOCB is not NULL, the referred mailbox command will
3829 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3830 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3831 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3832 * routine shall be invoked trying to release the ndlp if no other threads
3833 * are currently referring it.
3836 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3837 struct lpfc_iocbq *rspiocb)
3839 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3840 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3841 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3844 LPFC_MBOXQ_t *mbox = NULL;
3845 struct lpfc_dmabuf *mp = NULL;
3846 uint32_t ls_rjt = 0;
3848 irsp = &rspiocb->iocb;
3850 if (cmdiocb->context_un.mbox)
3851 mbox = cmdiocb->context_un.mbox;
3853 /* First determine if this is a LS_RJT cmpl. Note, this callback
3854 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3856 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3857 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3858 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3859 /* A LS_RJT associated with Default RPI cleanup has its own
3860 * separate code path.
3862 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3866 /* Check to see if link went down during discovery */
3867 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3869 mp = (struct lpfc_dmabuf *) mbox->context1;
3871 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3874 mempool_free(mbox, phba->mbox_mem_pool);
3876 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3877 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3878 if (lpfc_nlp_not_used(ndlp)) {
3880 /* Indicate the node has already released,
3881 * should not reference to it from within
3882 * the routine lpfc_els_free_iocb.
3884 cmdiocb->context1 = NULL;
3889 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3890 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3891 irsp->ulpStatus, irsp->un.ulpWord[4],
3892 cmdiocb->iocb.un.elsreq64.remoteID);
3893 /* ELS response tag <ulpIoTag> completes */
3894 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3895 "0110 ELS response tag x%x completes "
3896 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3897 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3898 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3899 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3902 if ((rspiocb->iocb.ulpStatus == 0)
3903 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3904 lpfc_unreg_rpi(vport, ndlp);
3905 /* Increment reference count to ndlp to hold the
3906 * reference to ndlp for the callback function.
3908 mbox->context2 = lpfc_nlp_get(ndlp);
3909 mbox->vport = vport;
3910 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3911 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3912 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3915 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3916 ndlp->nlp_prev_state = ndlp->nlp_state;
3917 lpfc_nlp_set_state(vport, ndlp,
3918 NLP_STE_REG_LOGIN_ISSUE);
3921 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3922 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3923 != MBX_NOT_FINISHED)
3926 /* Decrement the ndlp reference count we
3927 * set for this failed mailbox command.
3930 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3932 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3933 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3934 "0138 ELS rsp: Cannot issue reg_login for x%x "
3935 "Data: x%x x%x x%x\n",
3936 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3939 if (lpfc_nlp_not_used(ndlp)) {
3941 /* Indicate node has already been released,
3942 * should not reference to it from within
3943 * the routine lpfc_els_free_iocb.
3945 cmdiocb->context1 = NULL;
3948 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3949 if (!lpfc_error_lost_link(irsp) &&
3950 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3951 if (lpfc_nlp_not_used(ndlp)) {
3953 /* Indicate node has already been
3954 * released, should not reference
3955 * to it from within the routine
3956 * lpfc_els_free_iocb.
3958 cmdiocb->context1 = NULL;
3962 mp = (struct lpfc_dmabuf *) mbox->context1;
3964 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3967 mempool_free(mbox, phba->mbox_mem_pool);
3970 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3971 spin_lock_irq(shost->host_lock);
3972 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3973 spin_unlock_irq(shost->host_lock);
3975 /* If the node is not being used by another discovery thread,
3976 * and we are sending a reject, we are done with it.
3977 * Release driver reference count here and free associated
3981 if (lpfc_nlp_not_used(ndlp))
3982 /* Indicate node has already been released,
3983 * should not reference to it from within
3984 * the routine lpfc_els_free_iocb.
3986 cmdiocb->context1 = NULL;
3990 lpfc_els_free_iocb(phba, cmdiocb);
3995 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3996 * @vport: pointer to a host virtual N_Port data structure.
3997 * @flag: the els command code to be accepted.
3998 * @oldiocb: pointer to the original lpfc command iocb data structure.
3999 * @ndlp: pointer to a node-list data structure.
4000 * @mbox: pointer to the driver internal queue element for mailbox command.
4002 * This routine prepares and issues an Accept (ACC) response IOCB
4003 * command. It uses the @flag to properly set up the IOCB field for the
4004 * specific ACC response command to be issued and invokes the
4005 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4006 * @mbox pointer is passed in, it will be put into the context_un.mbox
4007 * field of the IOCB for the completion callback function to issue the
4008 * mailbox command to the HBA later when callback is invoked.
4010 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4011 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4012 * will be stored into the context1 field of the IOCB for the completion
4013 * callback function to the corresponding response ELS IOCB command.
4016 * 0 - Successfully issued acc response
4017 * 1 - Failed to issue acc response
4020 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4021 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4025 struct lpfc_hba *phba = vport->phba;
4028 struct lpfc_iocbq *elsiocb;
4030 struct serv_parm *sp;
4033 ELS_PKT *els_pkt_ptr;
4035 oldcmd = &oldiocb->iocb;
4039 cmdsize = sizeof(uint32_t);
4040 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4041 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4043 spin_lock_irq(shost->host_lock);
4044 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4045 spin_unlock_irq(shost->host_lock);
4049 icmd = &elsiocb->iocb;
4050 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4051 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4052 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4053 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4054 pcmd += sizeof(uint32_t);
4056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4057 "Issue ACC: did:x%x flg:x%x",
4058 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4062 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4063 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4064 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4068 icmd = &elsiocb->iocb;
4069 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4070 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4071 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4074 elsiocb->context_un.mbox = mbox;
4076 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4077 pcmd += sizeof(uint32_t);
4078 sp = (struct serv_parm *)pcmd;
4080 if (flag == ELS_CMD_FLOGI) {
4081 /* Copy the received service parameters back */
4082 memcpy(sp, &phba->fc_fabparam,
4083 sizeof(struct serv_parm));
4085 /* Clear the F_Port bit */
4088 /* Mark all class service parameters as invalid */
4089 sp->cls1.classValid = 0;
4090 sp->cls2.classValid = 0;
4091 sp->cls3.classValid = 0;
4092 sp->cls4.classValid = 0;
4094 /* Copy our worldwide names */
4095 memcpy(&sp->portName, &vport->fc_sparam.portName,
4096 sizeof(struct lpfc_name));
4097 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4098 sizeof(struct lpfc_name));
4100 memcpy(pcmd, &vport->fc_sparam,
4101 sizeof(struct serv_parm));
4103 sp->cmn.valid_vendor_ver_level = 0;
4104 memset(sp->un.vendorVersion, 0,
4105 sizeof(sp->un.vendorVersion));
4107 /* If our firmware supports this feature, convey that
4108 * info to the target using the vendor specific field.
4110 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4111 sp->cmn.valid_vendor_ver_level = 1;
4112 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4114 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4119 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4120 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4123 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4124 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4125 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4129 icmd = &elsiocb->iocb;
4130 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4131 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4132 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4134 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4135 sizeof(uint32_t) + sizeof(PRLO));
4136 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4137 els_pkt_ptr = (ELS_PKT *) pcmd;
4138 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4141 "Issue ACC PRLO: did:x%x flg:x%x",
4142 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4147 /* Xmit ELS ACC response tag <ulpIoTag> */
4148 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4149 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4150 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4152 elsiocb->iotag, elsiocb->iocb.ulpContext,
4153 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4154 ndlp->nlp_rpi, vport->fc_flag);
4155 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4156 spin_lock_irq(shost->host_lock);
4157 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4158 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4159 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4160 spin_unlock_irq(shost->host_lock);
4161 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4163 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4166 phba->fc_stat.elsXmitACC++;
4167 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4168 if (rc == IOCB_ERROR) {
4169 lpfc_els_free_iocb(phba, elsiocb);
4176 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4177 * @vport: pointer to a virtual N_Port data structure.
4179 * @oldiocb: pointer to the original lpfc command iocb data structure.
4180 * @ndlp: pointer to a node-list data structure.
4181 * @mbox: pointer to the driver internal queue element for mailbox command.
4183 * This routine prepares and issue an Reject (RJT) response IOCB
4184 * command. If a @mbox pointer is passed in, it will be put into the
4185 * context_un.mbox field of the IOCB for the completion callback function
4186 * to issue to the HBA later.
4188 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4189 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4190 * will be stored into the context1 field of the IOCB for the completion
4191 * callback function to the reject response ELS IOCB command.
4194 * 0 - Successfully issued reject response
4195 * 1 - Failed to issue reject response
4198 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4199 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4202 struct lpfc_hba *phba = vport->phba;
4205 struct lpfc_iocbq *elsiocb;
4210 cmdsize = 2 * sizeof(uint32_t);
4211 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4212 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4216 icmd = &elsiocb->iocb;
4217 oldcmd = &oldiocb->iocb;
4218 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4219 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4220 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4222 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4223 pcmd += sizeof(uint32_t);
4224 *((uint32_t *) (pcmd)) = rejectError;
4227 elsiocb->context_un.mbox = mbox;
4229 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4230 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4231 "0129 Xmit ELS RJT x%x response tag x%x "
4232 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4234 rejectError, elsiocb->iotag,
4235 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4236 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4238 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4239 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4241 phba->fc_stat.elsXmitLSRJT++;
4242 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4243 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_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4254 * @vport: pointer to a virtual N_Port data structure.
4255 * @oldiocb: pointer to the original lpfc command iocb data structure.
4256 * @ndlp: pointer to a node-list data structure.
4258 * This routine prepares and issues an Accept (ACC) response to Address
4259 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4260 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4262 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4263 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4264 * will be stored into the context1 field of the IOCB for the completion
4265 * callback function to the ADISC Accept response ELS IOCB command.
4268 * 0 - Successfully issued acc adisc response
4269 * 1 - Failed to issue adisc acc response
4272 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4273 struct lpfc_nodelist *ndlp)
4275 struct lpfc_hba *phba = vport->phba;
4277 IOCB_t *icmd, *oldcmd;
4278 struct lpfc_iocbq *elsiocb;
4283 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4284 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4285 ndlp->nlp_DID, ELS_CMD_ACC);
4289 icmd = &elsiocb->iocb;
4290 oldcmd = &oldiocb->iocb;
4291 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4292 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4294 /* Xmit ADISC ACC response tag <ulpIoTag> */
4295 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4296 "0130 Xmit ADISC ACC response iotag x%x xri: "
4297 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4298 elsiocb->iotag, elsiocb->iocb.ulpContext,
4299 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4301 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4303 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4304 pcmd += sizeof(uint32_t);
4306 ap = (ADISC *) (pcmd);
4307 ap->hardAL_PA = phba->fc_pref_ALPA;
4308 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4309 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4310 ap->DID = be32_to_cpu(vport->fc_myDID);
4312 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4313 "Issue ACC ADISC: did:x%x flg:x%x",
4314 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4316 phba->fc_stat.elsXmitACC++;
4317 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4318 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4319 if (rc == IOCB_ERROR) {
4320 lpfc_els_free_iocb(phba, elsiocb);
4327 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4328 * @vport: pointer to a virtual N_Port data structure.
4329 * @oldiocb: pointer to the original lpfc command iocb data structure.
4330 * @ndlp: pointer to a node-list data structure.
4332 * This routine prepares and issues an Accept (ACC) response to Process
4333 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4334 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4336 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4337 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4338 * will be stored into the context1 field of the IOCB for the completion
4339 * callback function to the PRLI Accept response ELS IOCB command.
4342 * 0 - Successfully issued acc prli response
4343 * 1 - Failed to issue acc prli response
4346 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4347 struct lpfc_nodelist *ndlp)
4349 struct lpfc_hba *phba = vport->phba;
4351 struct lpfc_nvme_prli *npr_nvme;
4355 struct lpfc_iocbq *elsiocb;
4358 uint32_t prli_fc4_req, *req_payload;
4359 struct lpfc_dmabuf *req_buf;
4363 /* Need the incoming PRLI payload to determine if the ACC is for an
4364 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4366 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4367 req_payload = (((uint32_t *)req_buf->virt) + 1);
4369 /* PRLI type payload is at byte 3 for FCP or NVME. */
4370 prli_fc4_req = be32_to_cpu(*req_payload);
4371 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4373 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4374 prli_fc4_req, *((uint32_t *)req_payload));
4376 if (prli_fc4_req == PRLI_FCP_TYPE) {
4377 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4378 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4379 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4380 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4381 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4386 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4387 ndlp->nlp_DID, elsrspcmd);
4391 icmd = &elsiocb->iocb;
4392 oldcmd = &oldiocb->iocb;
4393 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4394 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4396 /* Xmit PRLI ACC response tag <ulpIoTag> */
4397 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4398 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4399 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4400 elsiocb->iotag, elsiocb->iocb.ulpContext,
4401 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4403 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4404 memset(pcmd, 0, cmdsize);
4406 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4407 pcmd += sizeof(uint32_t);
4409 /* For PRLI, remainder of payload is PRLI parameter page */
4412 if (prli_fc4_req == PRLI_FCP_TYPE) {
4414 * If the remote port is a target and our firmware version
4415 * is 3.20 or later, set the following bits for FC-TAPE
4418 npr = (PRLI *) pcmd;
4419 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4420 (vpd->rev.feaLevelHigh >= 0x02)) {
4421 npr->ConfmComplAllowed = 1;
4423 npr->TaskRetryIdReq = 1;
4425 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4426 npr->estabImagePair = 1;
4427 npr->readXferRdyDis = 1;
4428 npr->ConfmComplAllowed = 1;
4429 npr->prliType = PRLI_FCP_TYPE;
4430 npr->initiatorFunc = 1;
4431 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4432 /* Respond with an NVME PRLI Type */
4433 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4434 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4435 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4436 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4437 if (phba->nvmet_support) {
4438 bf_set(prli_tgt, npr_nvme, 1);
4439 bf_set(prli_disc, npr_nvme, 1);
4440 if (phba->cfg_nvme_enable_fb) {
4441 bf_set(prli_fba, npr_nvme, 1);
4443 /* TBD. Target mode needs to post buffers
4444 * that support the configured first burst
4447 bf_set(prli_fb_sz, npr_nvme,
4448 phba->cfg_nvmet_fb_size);
4451 bf_set(prli_init, npr_nvme, 1);
4454 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4455 "6015 NVME issue PRLI ACC word1 x%08x "
4456 "word4 x%08x word5 x%08x flag x%x, "
4457 "fcp_info x%x nlp_type x%x\n",
4458 npr_nvme->word1, npr_nvme->word4,
4459 npr_nvme->word5, ndlp->nlp_flag,
4460 ndlp->nlp_fcp_info, ndlp->nlp_type);
4461 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4462 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4463 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4465 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4466 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4467 prli_fc4_req, ndlp->nlp_fc4_type,
4470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4471 "Issue ACC PRLI: did:x%x flg:x%x",
4472 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4474 phba->fc_stat.elsXmitACC++;
4475 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4477 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4478 if (rc == IOCB_ERROR) {
4479 lpfc_els_free_iocb(phba, elsiocb);
4486 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4487 * @vport: pointer to a virtual N_Port data structure.
4488 * @format: rnid command format.
4489 * @oldiocb: pointer to the original lpfc command iocb data structure.
4490 * @ndlp: pointer to a node-list data structure.
4492 * This routine issues a Request Node Identification Data (RNID) Accept
4493 * (ACC) response. It constructs the RNID ACC response command according to
4494 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4495 * issue the response. Note that this command does not need to hold the ndlp
4496 * reference count for the callback. So, the ndlp reference count taken by
4497 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4498 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4499 * there is no ndlp reference available.
4501 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4502 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4503 * will be stored into the context1 field of the IOCB for the completion
4504 * callback function. However, for the RNID Accept Response ELS command,
4505 * this is undone later by this routine after the IOCB is allocated.
4508 * 0 - Successfully issued acc rnid response
4509 * 1 - Failed to issue acc rnid response
4512 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4513 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4515 struct lpfc_hba *phba = vport->phba;
4517 IOCB_t *icmd, *oldcmd;
4518 struct lpfc_iocbq *elsiocb;
4523 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4524 + (2 * sizeof(struct lpfc_name));
4526 cmdsize += sizeof(RNID_TOP_DISC);
4528 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4529 ndlp->nlp_DID, ELS_CMD_ACC);
4533 icmd = &elsiocb->iocb;
4534 oldcmd = &oldiocb->iocb;
4535 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4536 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4538 /* Xmit RNID ACC response tag <ulpIoTag> */
4539 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4540 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4541 elsiocb->iotag, elsiocb->iocb.ulpContext);
4542 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4543 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4544 pcmd += sizeof(uint32_t);
4546 memset(pcmd, 0, sizeof(RNID));
4547 rn = (RNID *) (pcmd);
4548 rn->Format = format;
4549 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4550 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4551 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4554 rn->SpecificLen = 0;
4556 case RNID_TOPOLOGY_DISC:
4557 rn->SpecificLen = sizeof(RNID_TOP_DISC);
4558 memcpy(&rn->un.topologyDisc.portName,
4559 &vport->fc_portname, sizeof(struct lpfc_name));
4560 rn->un.topologyDisc.unitType = RNID_HBA;
4561 rn->un.topologyDisc.physPort = 0;
4562 rn->un.topologyDisc.attachedNodes = 0;
4566 rn->SpecificLen = 0;
4570 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4571 "Issue ACC RNID: did:x%x flg:x%x",
4572 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4574 phba->fc_stat.elsXmitACC++;
4575 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4577 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4578 if (rc == IOCB_ERROR) {
4579 lpfc_els_free_iocb(phba, elsiocb);
4586 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4587 * @vport: pointer to a virtual N_Port data structure.
4588 * @iocb: pointer to the lpfc command iocb data structure.
4589 * @ndlp: pointer to a node-list data structure.
4594 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4595 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4597 struct lpfc_hba *phba = vport->phba;
4602 struct lpfc_node_rrq *prrq;
4605 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4606 pcmd += sizeof(uint32_t);
4607 rrq = (struct RRQ *)pcmd;
4608 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4609 rxid = bf_get(rrq_rxid, rrq);
4611 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4612 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4614 be32_to_cpu(bf_get(rrq_did, rrq)),
4615 bf_get(rrq_oxid, rrq),
4617 iocb->iotag, iocb->iocb.ulpContext);
4619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4620 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4621 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4622 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4623 xri = bf_get(rrq_oxid, rrq);
4626 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4628 lpfc_clr_rrq_active(phba, xri, prrq);
4633 * lpfc_els_rsp_echo_acc - Issue echo acc response
4634 * @vport: pointer to a virtual N_Port data structure.
4635 * @data: pointer to echo data to return in the accept.
4636 * @oldiocb: pointer to the original lpfc command iocb data structure.
4637 * @ndlp: pointer to a node-list data structure.
4640 * 0 - Successfully issued acc echo response
4641 * 1 - Failed to issue acc echo response
4644 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4645 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4647 struct lpfc_hba *phba = vport->phba;
4648 struct lpfc_iocbq *elsiocb;
4653 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4655 /* The accumulated length can exceed the BPL_SIZE. For
4656 * now, use this as the limit
4658 if (cmdsize > LPFC_BPL_SIZE)
4659 cmdsize = LPFC_BPL_SIZE;
4660 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4661 ndlp->nlp_DID, ELS_CMD_ACC);
4665 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4666 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4668 /* Xmit ECHO ACC response tag <ulpIoTag> */
4669 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4670 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4671 elsiocb->iotag, elsiocb->iocb.ulpContext);
4672 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4673 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4674 pcmd += sizeof(uint32_t);
4675 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4677 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4678 "Issue ACC ECHO: did:x%x flg:x%x",
4679 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4681 phba->fc_stat.elsXmitACC++;
4682 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4684 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4685 if (rc == IOCB_ERROR) {
4686 lpfc_els_free_iocb(phba, elsiocb);
4693 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4694 * @vport: pointer to a host virtual N_Port data structure.
4696 * This routine issues Address Discover (ADISC) ELS commands to those
4697 * N_Ports which are in node port recovery state and ADISC has not been issued
4698 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4699 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4700 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4701 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4702 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4703 * IOCBs quit for later pick up. On the other hand, after walking through
4704 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4705 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4706 * no more ADISC need to be sent.
4709 * The number of N_Ports with adisc issued.
4712 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4714 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4715 struct lpfc_nodelist *ndlp, *next_ndlp;
4718 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4719 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4720 if (!NLP_CHK_NODE_ACT(ndlp))
4722 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4723 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4724 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4725 spin_lock_irq(shost->host_lock);
4726 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4727 spin_unlock_irq(shost->host_lock);
4728 ndlp->nlp_prev_state = ndlp->nlp_state;
4729 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4730 lpfc_issue_els_adisc(vport, ndlp, 0);
4732 vport->num_disc_nodes++;
4733 if (vport->num_disc_nodes >=
4734 vport->cfg_discovery_threads) {
4735 spin_lock_irq(shost->host_lock);
4736 vport->fc_flag |= FC_NLP_MORE;
4737 spin_unlock_irq(shost->host_lock);
4742 if (sentadisc == 0) {
4743 spin_lock_irq(shost->host_lock);
4744 vport->fc_flag &= ~FC_NLP_MORE;
4745 spin_unlock_irq(shost->host_lock);
4751 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4752 * @vport: pointer to a host virtual N_Port data structure.
4754 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4755 * which are in node port recovery state, with a @vport. Each time an ELS
4756 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4757 * the per @vport number of discover count (num_disc_nodes) shall be
4758 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4759 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4760 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4761 * later pick up. On the other hand, after walking through all the ndlps with
4762 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4763 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4764 * PLOGI need to be sent.
4767 * The number of N_Ports with plogi issued.
4770 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4773 struct lpfc_nodelist *ndlp, *next_ndlp;
4776 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4777 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4778 if (!NLP_CHK_NODE_ACT(ndlp))
4780 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4781 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4782 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4783 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4784 ndlp->nlp_prev_state = ndlp->nlp_state;
4785 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4786 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4788 vport->num_disc_nodes++;
4789 if (vport->num_disc_nodes >=
4790 vport->cfg_discovery_threads) {
4791 spin_lock_irq(shost->host_lock);
4792 vport->fc_flag |= FC_NLP_MORE;
4793 spin_unlock_irq(shost->host_lock);
4799 lpfc_set_disctmo(vport);
4802 spin_lock_irq(shost->host_lock);
4803 vport->fc_flag &= ~FC_NLP_MORE;
4804 spin_unlock_irq(shost->host_lock);
4810 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4814 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4815 desc->payload.els_req = word0;
4816 desc->length = cpu_to_be32(sizeof(desc->payload));
4818 return sizeof(struct fc_rdp_link_service_desc);
4822 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4823 uint8_t *page_a0, uint8_t *page_a2)
4825 uint16_t wavelength;
4826 uint16_t temperature;
4832 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4833 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4835 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4837 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4838 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4839 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4840 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4842 if ((trasn_code_byte4->fc_sw_laser) ||
4843 (trasn_code_byte5->fc_sw_laser_sl) ||
4844 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4845 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4846 } else if (trasn_code_byte4->fc_lw_laser) {
4847 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4848 page_a0[SSF_WAVELENGTH_B0];
4849 if (wavelength == SFP_WAVELENGTH_LC1310)
4850 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4851 if (wavelength == SFP_WAVELENGTH_LL1550)
4852 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4854 /* check if its SFP+ */
4855 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4856 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4857 << SFP_FLAG_CT_SHIFT;
4859 /* check if its OPTICAL */
4860 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4861 SFP_FLAG_IS_OPTICAL_PORT : 0)
4862 << SFP_FLAG_IS_OPTICAL_SHIFT;
4864 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4865 page_a2[SFF_TEMPERATURE_B0]);
4866 vcc = (page_a2[SFF_VCC_B1] << 8 |
4867 page_a2[SFF_VCC_B0]);
4868 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4869 page_a2[SFF_TXPOWER_B0]);
4870 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4871 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4872 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4873 page_a2[SFF_RXPOWER_B0]);
4874 desc->sfp_info.temperature = cpu_to_be16(temperature);
4875 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4876 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4877 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4878 desc->sfp_info.vcc = cpu_to_be16(vcc);
4880 desc->sfp_info.flags = cpu_to_be16(flag);
4881 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4883 return sizeof(struct fc_rdp_sfp_desc);
4887 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4892 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4894 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4896 desc->info.port_type = cpu_to_be32(type);
4898 desc->info.link_status.link_failure_cnt =
4899 cpu_to_be32(stat->linkFailureCnt);
4900 desc->info.link_status.loss_of_synch_cnt =
4901 cpu_to_be32(stat->lossSyncCnt);
4902 desc->info.link_status.loss_of_signal_cnt =
4903 cpu_to_be32(stat->lossSignalCnt);
4904 desc->info.link_status.primitive_seq_proto_err =
4905 cpu_to_be32(stat->primSeqErrCnt);
4906 desc->info.link_status.invalid_trans_word =
4907 cpu_to_be32(stat->invalidXmitWord);
4908 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4910 desc->length = cpu_to_be32(sizeof(desc->info));
4912 return sizeof(struct fc_rdp_link_error_status_desc);
4916 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
4917 struct lpfc_vport *vport)
4921 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
4923 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
4924 (vport->fc_sparam.cmn.bbCreditMsb << 8);
4925 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
4926 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
4927 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
4928 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
4929 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
4931 desc->bbc_info.attached_port_bbc = 0;
4934 desc->bbc_info.rtt = 0;
4935 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
4937 return sizeof(struct fc_rdp_bbc_desc);
4941 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
4942 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
4946 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4948 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
4949 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
4950 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
4951 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
4953 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4954 flags |= RDP_OET_HIGH_ALARM;
4955 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4956 flags |= RDP_OET_LOW_ALARM;
4957 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4958 flags |= RDP_OET_HIGH_WARNING;
4959 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4960 flags |= RDP_OET_LOW_WARNING;
4962 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
4963 desc->oed_info.function_flags = cpu_to_be32(flags);
4964 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4965 return sizeof(struct fc_rdp_oed_sfp_desc);
4969 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
4970 struct fc_rdp_oed_sfp_desc *desc,
4975 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4977 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
4978 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
4979 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
4980 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
4982 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4983 flags |= RDP_OET_HIGH_ALARM;
4984 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4985 flags |= RDP_OET_LOW_ALARM;
4986 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4987 flags |= RDP_OET_HIGH_WARNING;
4988 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4989 flags |= RDP_OET_LOW_WARNING;
4991 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
4992 desc->oed_info.function_flags = cpu_to_be32(flags);
4993 desc->length = cpu_to_be32(sizeof(desc->oed_info));
4994 return sizeof(struct fc_rdp_oed_sfp_desc);
4998 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
4999 struct fc_rdp_oed_sfp_desc *desc,
5004 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5006 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5007 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5008 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5009 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5011 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5012 flags |= RDP_OET_HIGH_ALARM;
5013 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5014 flags |= RDP_OET_LOW_ALARM;
5015 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5016 flags |= RDP_OET_HIGH_WARNING;
5017 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5018 flags |= RDP_OET_LOW_WARNING;
5020 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5021 desc->oed_info.function_flags = cpu_to_be32(flags);
5022 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5023 return sizeof(struct fc_rdp_oed_sfp_desc);
5027 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5028 struct fc_rdp_oed_sfp_desc *desc,
5033 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5035 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5036 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5037 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5038 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5040 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5041 flags |= RDP_OET_HIGH_ALARM;
5042 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5043 flags |= RDP_OET_LOW_ALARM;
5044 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5045 flags |= RDP_OET_HIGH_WARNING;
5046 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5047 flags |= RDP_OET_LOW_WARNING;
5049 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5050 desc->oed_info.function_flags = cpu_to_be32(flags);
5051 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5052 return sizeof(struct fc_rdp_oed_sfp_desc);
5057 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5058 struct fc_rdp_oed_sfp_desc *desc,
5063 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5065 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5066 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5067 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5068 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5070 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5071 flags |= RDP_OET_HIGH_ALARM;
5072 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5073 flags |= RDP_OET_LOW_ALARM;
5074 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5075 flags |= RDP_OET_HIGH_WARNING;
5076 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5077 flags |= RDP_OET_LOW_WARNING;
5079 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5080 desc->oed_info.function_flags = cpu_to_be32(flags);
5081 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5082 return sizeof(struct fc_rdp_oed_sfp_desc);
5086 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5087 uint8_t *page_a0, struct lpfc_vport *vport)
5089 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5090 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5091 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5092 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5093 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5094 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5095 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5096 return sizeof(struct fc_rdp_opd_sfp_desc);
5100 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5102 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5104 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5106 desc->info.CorrectedBlocks =
5107 cpu_to_be32(stat->fecCorrBlkCount);
5108 desc->info.UncorrectableBlocks =
5109 cpu_to_be32(stat->fecUncorrBlkCount);
5111 desc->length = cpu_to_be32(sizeof(desc->info));
5113 return sizeof(struct fc_fec_rdp_desc);
5117 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5119 uint16_t rdp_cap = 0;
5122 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5124 switch (phba->fc_linkspeed) {
5125 case LPFC_LINK_SPEED_1GHZ:
5126 rdp_speed = RDP_PS_1GB;
5128 case LPFC_LINK_SPEED_2GHZ:
5129 rdp_speed = RDP_PS_2GB;
5131 case LPFC_LINK_SPEED_4GHZ:
5132 rdp_speed = RDP_PS_4GB;
5134 case LPFC_LINK_SPEED_8GHZ:
5135 rdp_speed = RDP_PS_8GB;
5137 case LPFC_LINK_SPEED_10GHZ:
5138 rdp_speed = RDP_PS_10GB;
5140 case LPFC_LINK_SPEED_16GHZ:
5141 rdp_speed = RDP_PS_16GB;
5143 case LPFC_LINK_SPEED_32GHZ:
5144 rdp_speed = RDP_PS_32GB;
5147 rdp_speed = RDP_PS_UNKNOWN;
5151 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5153 if (phba->lmt & LMT_32Gb)
5154 rdp_cap |= RDP_PS_32GB;
5155 if (phba->lmt & LMT_16Gb)
5156 rdp_cap |= RDP_PS_16GB;
5157 if (phba->lmt & LMT_10Gb)
5158 rdp_cap |= RDP_PS_10GB;
5159 if (phba->lmt & LMT_8Gb)
5160 rdp_cap |= RDP_PS_8GB;
5161 if (phba->lmt & LMT_4Gb)
5162 rdp_cap |= RDP_PS_4GB;
5163 if (phba->lmt & LMT_2Gb)
5164 rdp_cap |= RDP_PS_2GB;
5165 if (phba->lmt & LMT_1Gb)
5166 rdp_cap |= RDP_PS_1GB;
5169 rdp_cap = RDP_CAP_UNKNOWN;
5170 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5171 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5173 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5174 desc->length = cpu_to_be32(sizeof(desc->info));
5175 return sizeof(struct fc_rdp_port_speed_desc);
5179 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5180 struct lpfc_vport *vport)
5183 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5185 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5186 sizeof(desc->port_names.wwnn));
5188 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5189 sizeof(desc->port_names.wwpn));
5191 desc->length = cpu_to_be32(sizeof(desc->port_names));
5192 return sizeof(struct fc_rdp_port_name_desc);
5196 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5197 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5200 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5201 if (vport->fc_flag & FC_FABRIC) {
5202 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5203 sizeof(desc->port_names.wwnn));
5205 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5206 sizeof(desc->port_names.wwpn));
5207 } else { /* Point to Point */
5208 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5209 sizeof(desc->port_names.wwnn));
5211 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5212 sizeof(desc->port_names.wwpn));
5215 desc->length = cpu_to_be32(sizeof(desc->port_names));
5216 return sizeof(struct fc_rdp_port_name_desc);
5220 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5223 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5224 struct lpfc_vport *vport = ndlp->vport;
5225 struct lpfc_iocbq *elsiocb;
5226 struct ulp_bde64 *bpl;
5229 struct ls_rjt *stat;
5230 struct fc_rdp_res_frame *rdp_res;
5231 uint32_t cmdsize, len;
5235 if (status != SUCCESS)
5238 /* This will change once we know the true size of the RDP payload */
5239 cmdsize = sizeof(struct fc_rdp_res_frame);
5241 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5242 lpfc_max_els_tries, rdp_context->ndlp,
5243 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5246 goto free_rdp_context;
5248 icmd = &elsiocb->iocb;
5249 icmd->ulpContext = rdp_context->rx_id;
5250 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5252 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5253 "2171 Xmit RDP response tag x%x xri x%x, "
5254 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5255 elsiocb->iotag, elsiocb->iocb.ulpContext,
5256 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5258 rdp_res = (struct fc_rdp_res_frame *)
5259 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5260 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5261 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5262 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5264 /* Update Alarm and Warning */
5265 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5266 phba->sfp_alarm |= *flag_ptr;
5267 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5268 phba->sfp_warning |= *flag_ptr;
5270 /* For RDP payload */
5272 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5273 (len + pcmd), ELS_CMD_RDP);
5275 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5276 rdp_context->page_a0, rdp_context->page_a2);
5277 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5279 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5280 (len + pcmd), &rdp_context->link_stat);
5281 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5282 (len + pcmd), vport);
5283 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5284 (len + pcmd), vport, ndlp);
5285 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5286 &rdp_context->link_stat);
5287 /* Check if nport is logged, BZ190632 */
5288 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5289 goto lpfc_skip_descriptor;
5291 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5292 &rdp_context->link_stat, vport);
5293 len += lpfc_rdp_res_oed_temp_desc(phba,
5294 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5295 rdp_context->page_a2);
5296 len += lpfc_rdp_res_oed_voltage_desc(phba,
5297 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5298 rdp_context->page_a2);
5299 len += lpfc_rdp_res_oed_txbias_desc(phba,
5300 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5301 rdp_context->page_a2);
5302 len += lpfc_rdp_res_oed_txpower_desc(phba,
5303 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5304 rdp_context->page_a2);
5305 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5306 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5307 rdp_context->page_a2);
5308 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5309 rdp_context->page_a0, vport);
5311 lpfc_skip_descriptor:
5312 rdp_res->length = cpu_to_be32(len - 8);
5313 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5315 /* Now that we know the true size of the payload, update the BPL */
5316 bpl = (struct ulp_bde64 *)
5317 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5318 bpl->tus.f.bdeSize = len;
5319 bpl->tus.f.bdeFlags = 0;
5320 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5322 phba->fc_stat.elsXmitACC++;
5323 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5324 if (rc == IOCB_ERROR)
5325 lpfc_els_free_iocb(phba, elsiocb);
5331 cmdsize = 2 * sizeof(uint32_t);
5332 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5333 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5336 goto free_rdp_context;
5338 icmd = &elsiocb->iocb;
5339 icmd->ulpContext = rdp_context->rx_id;
5340 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5341 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5343 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5344 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5345 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5347 phba->fc_stat.elsXmitLSRJT++;
5348 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5349 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5351 if (rc == IOCB_ERROR)
5352 lpfc_els_free_iocb(phba, elsiocb);
5358 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5360 LPFC_MBOXQ_t *mbox = NULL;
5363 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5365 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5366 "7105 failed to allocate mailbox memory");
5370 if (lpfc_sli4_dump_page_a0(phba, mbox))
5371 goto prep_mbox_fail;
5372 mbox->vport = rdp_context->ndlp->vport;
5373 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5374 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5375 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5376 if (rc == MBX_NOT_FINISHED)
5377 goto issue_mbox_fail;
5383 mempool_free(mbox, phba->mbox_mem_pool);
5388 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5389 * @vport: pointer to a host virtual N_Port data structure.
5390 * @cmdiocb: pointer to lpfc command iocb data structure.
5391 * @ndlp: pointer to a node-list data structure.
5393 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5394 * IOCB. First, the payload of the unsolicited RDP is checked.
5395 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5396 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5397 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5398 * gather all data and send RDP response.
5401 * 0 - Sent the acc response
5402 * 1 - Sent the reject response.
5405 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5406 struct lpfc_nodelist *ndlp)
5408 struct lpfc_hba *phba = vport->phba;
5409 struct lpfc_dmabuf *pcmd;
5410 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5411 struct fc_rdp_req_frame *rdp_req;
5412 struct lpfc_rdp_context *rdp_context;
5416 if (phba->sli_rev < LPFC_SLI_REV4 ||
5417 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5418 LPFC_SLI_INTF_IF_TYPE_2) {
5419 rjt_err = LSRJT_UNABLE_TPC;
5420 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5424 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5425 rjt_err = LSRJT_UNABLE_TPC;
5426 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5430 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5431 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5434 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5435 "2422 ELS RDP Request "
5436 "dec len %d tag x%x port_id %d len %d\n",
5437 be32_to_cpu(rdp_req->rdp_des_length),
5438 be32_to_cpu(rdp_req->nport_id_desc.tag),
5439 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5440 be32_to_cpu(rdp_req->nport_id_desc.length));
5442 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5443 !phba->cfg_enable_SmartSAN) {
5444 rjt_err = LSRJT_UNABLE_TPC;
5445 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5448 if (sizeof(struct fc_rdp_nport_desc) !=
5449 be32_to_cpu(rdp_req->rdp_des_length))
5451 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5453 if (RDP_NPORT_ID_SIZE !=
5454 be32_to_cpu(rdp_req->nport_id_desc.length))
5456 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5458 rjt_err = LSRJT_UNABLE_TPC;
5462 cmd = &cmdiocb->iocb;
5463 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5464 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5465 rdp_context->rx_id = cmd->ulpContext;
5466 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5467 if (lpfc_get_rdp_info(phba, rdp_context)) {
5468 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5469 "2423 Unable to send mailbox");
5471 rjt_err = LSRJT_UNABLE_TPC;
5479 rjt_err = LSRJT_LOGICAL_ERR;
5482 memset(&stat, 0, sizeof(stat));
5483 stat.un.b.lsRjtRsnCode = rjt_err;
5484 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5485 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5491 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5496 struct lpfc_iocbq *elsiocb;
5497 struct lpfc_nodelist *ndlp;
5498 struct ls_rjt *stat;
5499 union lpfc_sli4_cfg_shdr *shdr;
5500 struct lpfc_lcb_context *lcb_context;
5501 struct fc_lcb_res_frame *lcb_res;
5502 uint32_t cmdsize, shdr_status, shdr_add_status;
5506 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5507 ndlp = lcb_context->ndlp;
5508 pmb->context1 = NULL;
5509 pmb->context2 = NULL;
5511 shdr = (union lpfc_sli4_cfg_shdr *)
5512 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5513 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5514 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5516 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5517 "0194 SET_BEACON_CONFIG mailbox "
5518 "completed with status x%x add_status x%x,"
5519 " mbx status x%x\n",
5520 shdr_status, shdr_add_status, mb->mbxStatus);
5522 if (mb->mbxStatus && !(shdr_status &&
5523 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
5524 mempool_free(pmb, phba->mbox_mem_pool);
5528 mempool_free(pmb, phba->mbox_mem_pool);
5529 cmdsize = sizeof(struct fc_lcb_res_frame);
5530 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5531 lpfc_max_els_tries, ndlp,
5532 ndlp->nlp_DID, ELS_CMD_ACC);
5534 /* Decrement the ndlp reference count from previous mbox command */
5538 goto free_lcb_context;
5540 lcb_res = (struct fc_lcb_res_frame *)
5541 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5543 icmd = &elsiocb->iocb;
5544 icmd->ulpContext = lcb_context->rx_id;
5545 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5547 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5548 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5549 lcb_res->lcb_sub_command = lcb_context->sub_command;
5550 lcb_res->lcb_type = lcb_context->type;
5551 lcb_res->lcb_frequency = lcb_context->frequency;
5552 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5553 phba->fc_stat.elsXmitACC++;
5554 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5555 if (rc == IOCB_ERROR)
5556 lpfc_els_free_iocb(phba, elsiocb);
5562 cmdsize = sizeof(struct fc_lcb_res_frame);
5563 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5564 lpfc_max_els_tries, ndlp,
5565 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5568 goto free_lcb_context;
5570 icmd = &elsiocb->iocb;
5571 icmd->ulpContext = lcb_context->rx_id;
5572 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5573 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5575 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5576 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5577 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5579 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5580 phba->fc_stat.elsXmitLSRJT++;
5581 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5582 if (rc == IOCB_ERROR)
5583 lpfc_els_free_iocb(phba, elsiocb);
5589 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5590 struct lpfc_lcb_context *lcb_context,
5591 uint32_t beacon_state)
5593 struct lpfc_hba *phba = vport->phba;
5594 LPFC_MBOXQ_t *mbox = NULL;
5598 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5602 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5603 sizeof(struct lpfc_sli4_cfg_mhdr);
5604 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5605 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5606 LPFC_SLI4_MBX_EMBED);
5607 mbox->context1 = (void *)lcb_context;
5608 mbox->vport = phba->pport;
5609 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5610 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5611 phba->sli4_hba.physical_port);
5612 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5614 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5615 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5616 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5617 if (rc == MBX_NOT_FINISHED) {
5618 mempool_free(mbox, phba->mbox_mem_pool);
5627 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5628 * @vport: pointer to a host virtual N_Port data structure.
5629 * @cmdiocb: pointer to lpfc command iocb data structure.
5630 * @ndlp: pointer to a node-list data structure.
5632 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5633 * First, the payload of the unsolicited LCB is checked.
5634 * Then based on Subcommand beacon will either turn on or off.
5637 * 0 - Sent the acc response
5638 * 1 - Sent the reject response.
5641 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5642 struct lpfc_nodelist *ndlp)
5644 struct lpfc_hba *phba = vport->phba;
5645 struct lpfc_dmabuf *pcmd;
5647 struct fc_lcb_request_frame *beacon;
5648 struct lpfc_lcb_context *lcb_context;
5649 uint8_t state, rjt_err;
5652 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5653 lp = (uint8_t *)pcmd->virt;
5654 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5656 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5657 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5658 "type x%x frequency %x duration x%x\n",
5659 lp[0], lp[1], lp[2],
5660 beacon->lcb_command,
5661 beacon->lcb_sub_command,
5663 beacon->lcb_frequency,
5664 be16_to_cpu(beacon->lcb_duration));
5666 if (phba->sli_rev < LPFC_SLI_REV4 ||
5667 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5668 LPFC_SLI_INTF_IF_TYPE_2)) {
5669 rjt_err = LSRJT_CMD_UNSUPPORTED;
5673 if (phba->hba_flag & HBA_FCOE_MODE) {
5674 rjt_err = LSRJT_CMD_UNSUPPORTED;
5677 if (beacon->lcb_frequency == 0) {
5678 rjt_err = LSRJT_CMD_UNSUPPORTED;
5681 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5682 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5683 rjt_err = LSRJT_CMD_UNSUPPORTED;
5686 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5687 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5688 rjt_err = LSRJT_CMD_UNSUPPORTED;
5691 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5692 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5693 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5694 rjt_err = LSRJT_CMD_UNSUPPORTED;
5697 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5698 rjt_err = LSRJT_CMD_UNSUPPORTED;
5702 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5704 rjt_err = LSRJT_UNABLE_TPC;
5708 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5709 lcb_context->sub_command = beacon->lcb_sub_command;
5710 lcb_context->type = beacon->lcb_type;
5711 lcb_context->frequency = beacon->lcb_frequency;
5712 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5713 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5714 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5715 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5716 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5717 LOG_ELS, "0193 failed to send mail box");
5720 rjt_err = LSRJT_UNABLE_TPC;
5725 memset(&stat, 0, sizeof(stat));
5726 stat.un.b.lsRjtRsnCode = rjt_err;
5727 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5733 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5734 * @vport: pointer to a host virtual N_Port data structure.
5736 * This routine cleans up any Registration State Change Notification
5737 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5738 * @vport together with the host_lock is used to prevent multiple thread
5739 * trying to access the RSCN array on a same @vport at the same time.
5742 lpfc_els_flush_rscn(struct lpfc_vport *vport)
5744 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5745 struct lpfc_hba *phba = vport->phba;
5748 spin_lock_irq(shost->host_lock);
5749 if (vport->fc_rscn_flush) {
5750 /* Another thread is walking fc_rscn_id_list on this vport */
5751 spin_unlock_irq(shost->host_lock);
5754 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5755 vport->fc_rscn_flush = 1;
5756 spin_unlock_irq(shost->host_lock);
5758 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5759 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
5760 vport->fc_rscn_id_list[i] = NULL;
5762 spin_lock_irq(shost->host_lock);
5763 vport->fc_rscn_id_cnt = 0;
5764 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5765 spin_unlock_irq(shost->host_lock);
5766 lpfc_can_disctmo(vport);
5767 /* Indicate we are done walking this fc_rscn_id_list */
5768 vport->fc_rscn_flush = 0;
5772 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5773 * @vport: pointer to a host virtual N_Port data structure.
5774 * @did: remote destination port identifier.
5776 * This routine checks whether there is any pending Registration State
5777 * Configuration Notification (RSCN) to a @did on @vport.
5780 * None zero - The @did matched with a pending rscn
5781 * 0 - not able to match @did with a pending rscn
5784 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
5789 uint32_t payload_len, i;
5790 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5792 ns_did.un.word = did;
5794 /* Never match fabric nodes for RSCNs */
5795 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5798 /* If we are doing a FULL RSCN rediscovery, match everything */
5799 if (vport->fc_flag & FC_RSCN_DISCOVERY)
5802 spin_lock_irq(shost->host_lock);
5803 if (vport->fc_rscn_flush) {
5804 /* Another thread is walking fc_rscn_id_list on this vport */
5805 spin_unlock_irq(shost->host_lock);
5808 /* Indicate we are walking fc_rscn_id_list on this vport */
5809 vport->fc_rscn_flush = 1;
5810 spin_unlock_irq(shost->host_lock);
5811 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
5812 lp = vport->fc_rscn_id_list[i]->virt;
5813 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5814 payload_len -= sizeof(uint32_t); /* take off word 0 */
5815 while (payload_len) {
5816 rscn_did.un.word = be32_to_cpu(*lp++);
5817 payload_len -= sizeof(uint32_t);
5818 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5819 case RSCN_ADDRESS_FORMAT_PORT:
5820 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5821 && (ns_did.un.b.area == rscn_did.un.b.area)
5822 && (ns_did.un.b.id == rscn_did.un.b.id))
5823 goto return_did_out;
5825 case RSCN_ADDRESS_FORMAT_AREA:
5826 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5827 && (ns_did.un.b.area == rscn_did.un.b.area))
5828 goto return_did_out;
5830 case RSCN_ADDRESS_FORMAT_DOMAIN:
5831 if (ns_did.un.b.domain == rscn_did.un.b.domain)
5832 goto return_did_out;
5834 case RSCN_ADDRESS_FORMAT_FABRIC:
5835 goto return_did_out;
5839 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5840 vport->fc_rscn_flush = 0;
5843 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5844 vport->fc_rscn_flush = 0;
5849 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5850 * @vport: pointer to a host virtual N_Port data structure.
5852 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5853 * state machine for a @vport's nodes that are with pending RSCN (Registration
5854 * State Change Notification).
5857 * 0 - Successful (currently alway return 0)
5860 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
5862 struct lpfc_nodelist *ndlp = NULL;
5864 /* Move all affected nodes by pending RSCNs to NPR state. */
5865 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5866 if (!NLP_CHK_NODE_ACT(ndlp) ||
5867 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5868 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
5870 if (vport->phba->nvmet_support)
5872 lpfc_disc_state_machine(vport, ndlp, NULL,
5873 NLP_EVT_DEVICE_RECOVERY);
5874 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5880 * lpfc_send_rscn_event - Send an RSCN event to management application
5881 * @vport: pointer to a host virtual N_Port data structure.
5882 * @cmdiocb: pointer to lpfc command iocb data structure.
5884 * lpfc_send_rscn_event sends an RSCN netlink event to management
5888 lpfc_send_rscn_event(struct lpfc_vport *vport,
5889 struct lpfc_iocbq *cmdiocb)
5891 struct lpfc_dmabuf *pcmd;
5892 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5893 uint32_t *payload_ptr;
5894 uint32_t payload_len;
5895 struct lpfc_rscn_event_header *rscn_event_data;
5897 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5898 payload_ptr = (uint32_t *) pcmd->virt;
5899 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5901 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5902 payload_len, GFP_KERNEL);
5903 if (!rscn_event_data) {
5904 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5905 "0147 Failed to allocate memory for RSCN event\n");
5908 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5909 rscn_event_data->payload_length = payload_len;
5910 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5913 fc_host_post_vendor_event(shost,
5914 fc_get_event_number(),
5915 sizeof(struct lpfc_rscn_event_header) + payload_len,
5916 (char *)rscn_event_data,
5919 kfree(rscn_event_data);
5923 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
5924 * @vport: pointer to a host virtual N_Port data structure.
5925 * @cmdiocb: pointer to lpfc command iocb data structure.
5926 * @ndlp: pointer to a node-list data structure.
5928 * This routine processes an unsolicited RSCN (Registration State Change
5929 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5930 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5931 * discover state machine is about to begin discovery, it just accepts the
5932 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5933 * contains N_Port IDs for other vports on this HBA, it just accepts the
5934 * RSCN and ignore processing it. If the state machine is in the recovery
5935 * state, the fc_rscn_id_list of this @vport is walked and the
5936 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5937 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5938 * routine is invoked to handle the RSCN event.
5941 * 0 - Just sent the acc response
5942 * 1 - Sent the acc response and waited for name server completion
5945 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5946 struct lpfc_nodelist *ndlp)
5948 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5949 struct lpfc_hba *phba = vport->phba;
5950 struct lpfc_dmabuf *pcmd;
5951 uint32_t *lp, *datap;
5952 uint32_t payload_len, length, nportid, *cmd;
5954 int rscn_id = 0, hba_id = 0;
5957 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5958 lp = (uint32_t *) pcmd->virt;
5960 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5961 payload_len -= sizeof(uint32_t); /* take off word 0 */
5963 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5964 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5965 vport->fc_flag, payload_len, *lp,
5966 vport->fc_rscn_id_cnt);
5968 /* Send an RSCN event to the management application */
5969 lpfc_send_rscn_event(vport, cmdiocb);
5971 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
5972 fc_host_post_event(shost, fc_get_event_number(),
5973 FCH_EVT_RSCN, lp[i]);
5975 /* If we are about to begin discovery, just ACC the RSCN.
5976 * Discovery processing will satisfy it.
5978 if (vport->port_state <= LPFC_NS_QRY) {
5979 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5980 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5981 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5983 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5987 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5988 * just ACC and ignore it.
5990 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5991 !(vport->cfg_peer_port_login)) {
5996 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5997 i -= sizeof(uint32_t);
5999 if (lpfc_find_vport_by_did(phba, nportid))
6002 if (rscn_id == hba_id) {
6003 /* ALL NPortIDs in RSCN are on HBA */
6004 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6006 "Data: x%x x%x x%x x%x\n",
6007 vport->fc_flag, payload_len,
6008 *lp, vport->fc_rscn_id_cnt);
6009 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6010 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6011 ndlp->nlp_DID, vport->port_state,
6014 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6020 spin_lock_irq(shost->host_lock);
6021 if (vport->fc_rscn_flush) {
6022 /* Another thread is walking fc_rscn_id_list on this vport */
6023 vport->fc_flag |= FC_RSCN_DISCOVERY;
6024 spin_unlock_irq(shost->host_lock);
6026 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6029 /* Indicate we are walking fc_rscn_id_list on this vport */
6030 vport->fc_rscn_flush = 1;
6031 spin_unlock_irq(shost->host_lock);
6032 /* Get the array count after successfully have the token */
6033 rscn_cnt = vport->fc_rscn_id_cnt;
6034 /* If we are already processing an RSCN, save the received
6035 * RSCN payload buffer, cmdiocb->context2 to process later.
6037 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6038 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6039 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6040 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6042 spin_lock_irq(shost->host_lock);
6043 vport->fc_flag |= FC_RSCN_DEFERRED;
6044 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6045 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6046 vport->fc_flag |= FC_RSCN_MODE;
6047 spin_unlock_irq(shost->host_lock);
6049 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6050 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6053 (payload_len + length <= LPFC_BPL_SIZE)) {
6054 *cmd &= ELS_CMD_MASK;
6055 *cmd |= cpu_to_be32(payload_len + length);
6056 memcpy(((uint8_t *)cmd) + length, lp,
6059 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6060 vport->fc_rscn_id_cnt++;
6061 /* If we zero, cmdiocb->context2, the calling
6062 * routine will not try to free it.
6064 cmdiocb->context2 = NULL;
6067 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6068 "0235 Deferred RSCN "
6069 "Data: x%x x%x x%x\n",
6070 vport->fc_rscn_id_cnt, vport->fc_flag,
6073 vport->fc_flag |= FC_RSCN_DISCOVERY;
6074 spin_unlock_irq(shost->host_lock);
6075 /* ReDiscovery RSCN */
6076 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6077 "0234 ReDiscovery RSCN "
6078 "Data: x%x x%x x%x\n",
6079 vport->fc_rscn_id_cnt, vport->fc_flag,
6082 /* Indicate we are done walking fc_rscn_id_list on this vport */
6083 vport->fc_rscn_flush = 0;
6085 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6086 /* send RECOVERY event for ALL nodes that match RSCN payload */
6087 lpfc_rscn_recovery_check(vport);
6088 spin_lock_irq(shost->host_lock);
6089 vport->fc_flag &= ~FC_RSCN_DEFERRED;
6090 spin_unlock_irq(shost->host_lock);
6093 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6094 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6095 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6097 spin_lock_irq(shost->host_lock);
6098 vport->fc_flag |= FC_RSCN_MODE;
6099 spin_unlock_irq(shost->host_lock);
6100 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6101 /* Indicate we are done walking fc_rscn_id_list on this vport */
6102 vport->fc_rscn_flush = 0;
6104 * If we zero, cmdiocb->context2, the calling routine will
6105 * not try to free it.
6107 cmdiocb->context2 = NULL;
6108 lpfc_set_disctmo(vport);
6110 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6111 /* send RECOVERY event for ALL nodes that match RSCN payload */
6112 lpfc_rscn_recovery_check(vport);
6113 return lpfc_els_handle_rscn(vport);
6117 * lpfc_els_handle_rscn - Handle rscn for a vport
6118 * @vport: pointer to a host virtual N_Port data structure.
6120 * This routine handles the Registration State Configuration Notification
6121 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6122 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6123 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6124 * NameServer shall be issued. If CT command to the NameServer fails to be
6125 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6126 * RSCN activities with the @vport.
6129 * 0 - Cleaned up rscn on the @vport
6130 * 1 - Wait for plogi to name server before proceed
6133 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6135 struct lpfc_nodelist *ndlp;
6136 struct lpfc_hba *phba = vport->phba;
6138 /* Ignore RSCN if the port is being torn down. */
6139 if (vport->load_flag & FC_UNLOADING) {
6140 lpfc_els_flush_rscn(vport);
6144 /* Start timer for RSCN processing */
6145 lpfc_set_disctmo(vport);
6147 /* RSCN processed */
6148 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6149 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6150 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6153 /* To process RSCN, first compare RSCN data with NameServer */
6154 vport->fc_ns_retry = 0;
6155 vport->num_disc_nodes = 0;
6157 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6158 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6159 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6160 /* Good ndlp, issue CT Request to NameServer */
6161 vport->gidft_inp = 0;
6162 if (lpfc_issue_gidft(vport) == 0)
6163 /* Wait for NameServer query cmpl before we can
6168 /* If login to NameServer does not exist, issue one */
6169 /* Good status, issue PLOGI to NameServer */
6170 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6171 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
6172 /* Wait for NameServer login cmpl before we can
6177 ndlp = lpfc_enable_node(vport, ndlp,
6178 NLP_STE_PLOGI_ISSUE);
6180 lpfc_els_flush_rscn(vport);
6183 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6185 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6187 lpfc_els_flush_rscn(vport);
6190 lpfc_nlp_init(vport, ndlp, NameServer_DID);
6191 ndlp->nlp_prev_state = ndlp->nlp_state;
6192 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6194 ndlp->nlp_type |= NLP_FABRIC;
6195 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6196 /* Wait for NameServer login cmpl before we can
6202 lpfc_els_flush_rscn(vport);
6207 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6208 * @vport: pointer to a host virtual N_Port data structure.
6209 * @cmdiocb: pointer to lpfc command iocb data structure.
6210 * @ndlp: pointer to a node-list data structure.
6212 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6213 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6214 * point topology. As an unsolicited FLOGI should not be received in a loop
6215 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6216 * lpfc_check_sparm() routine is invoked to check the parameters in the
6217 * unsolicited FLOGI. If parameters validation failed, the routine
6218 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6219 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6220 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6221 * will initiate PLOGI. The higher lexicographical value party shall has
6222 * higher priority (as the winning port) and will initiate PLOGI and
6223 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6224 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6225 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6228 * 0 - Successfully processed the unsolicited flogi
6229 * 1 - Failed to process the unsolicited flogi
6232 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6233 struct lpfc_nodelist *ndlp)
6235 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6236 struct lpfc_hba *phba = vport->phba;
6237 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6238 uint32_t *lp = (uint32_t *) pcmd->virt;
6239 IOCB_t *icmd = &cmdiocb->iocb;
6240 struct serv_parm *sp;
6244 uint32_t fc_flag = 0;
6245 uint32_t port_state = 0;
6248 sp = (struct serv_parm *) lp;
6250 /* FLOGI received */
6252 lpfc_set_disctmo(vport);
6254 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6255 /* We should never receive a FLOGI in loop mode, ignore it */
6256 did = icmd->un.elsreq64.remoteID;
6258 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6260 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6261 "0113 An FLOGI ELS command x%x was "
6262 "received from DID x%x in Loop Mode\n",
6267 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6270 * If our portname is greater than the remote portname,
6271 * then we initiate Nport login.
6274 rc = memcmp(&vport->fc_portname, &sp->portName,
6275 sizeof(struct lpfc_name));
6278 if (phba->sli_rev < LPFC_SLI_REV4) {
6279 mbox = mempool_alloc(phba->mbox_mem_pool,
6283 lpfc_linkdown(phba);
6284 lpfc_init_link(phba, mbox,
6286 phba->cfg_link_speed);
6287 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6288 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6289 mbox->vport = vport;
6290 rc = lpfc_sli_issue_mbox(phba, mbox,
6292 lpfc_set_loopback_flag(phba);
6293 if (rc == MBX_NOT_FINISHED)
6294 mempool_free(mbox, phba->mbox_mem_pool);
6298 /* abort the flogi coming back to ourselves
6299 * due to external loopback on the port.
6301 lpfc_els_abort_flogi(phba);
6304 } else if (rc > 0) { /* greater than */
6305 spin_lock_irq(shost->host_lock);
6306 vport->fc_flag |= FC_PT2PT_PLOGI;
6307 spin_unlock_irq(shost->host_lock);
6309 /* If we have the high WWPN we can assign our own
6310 * myDID; otherwise, we have to WAIT for a PLOGI
6311 * from the remote NPort to find out what it
6314 vport->fc_myDID = PT2PT_LocalID;
6316 vport->fc_myDID = PT2PT_RemoteID;
6320 * The vport state should go to LPFC_FLOGI only
6321 * AFTER we issue a FLOGI, not receive one.
6323 spin_lock_irq(shost->host_lock);
6324 fc_flag = vport->fc_flag;
6325 port_state = vport->port_state;
6326 vport->fc_flag |= FC_PT2PT;
6327 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6328 spin_unlock_irq(shost->host_lock);
6329 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6330 "3311 Rcv Flogi PS x%x new PS x%x "
6331 "fc_flag x%x new fc_flag x%x\n",
6332 port_state, vport->port_state,
6333 fc_flag, vport->fc_flag);
6336 * We temporarily set fc_myDID to make it look like we are
6337 * a Fabric. This is done just so we end up with the right
6338 * did / sid on the FLOGI ACC rsp.
6340 did = vport->fc_myDID;
6341 vport->fc_myDID = Fabric_DID;
6343 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6346 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6348 /* Now lets put fc_myDID back to what its supposed to be */
6349 vport->fc_myDID = did;
6355 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6356 * @vport: pointer to a host virtual N_Port data structure.
6357 * @cmdiocb: pointer to lpfc command iocb data structure.
6358 * @ndlp: pointer to a node-list data structure.
6360 * This routine processes Request Node Identification Data (RNID) IOCB
6361 * received as an ELS unsolicited event. Only when the RNID specified format
6362 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6363 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6364 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6365 * rejected by invoking the lpfc_els_rsp_reject() routine.
6368 * 0 - Successfully processed rnid iocb (currently always return 0)
6371 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6372 struct lpfc_nodelist *ndlp)
6374 struct lpfc_dmabuf *pcmd;
6380 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6381 lp = (uint32_t *) pcmd->virt;
6388 switch (rn->Format) {
6390 case RNID_TOPOLOGY_DISC:
6392 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6395 /* Reject this request because format not supported */
6396 stat.un.b.lsRjtRsvd0 = 0;
6397 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6398 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6399 stat.un.b.vendorUnique = 0;
6400 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6407 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6408 * @vport: pointer to a host virtual N_Port data structure.
6409 * @cmdiocb: pointer to lpfc command iocb data structure.
6410 * @ndlp: pointer to a node-list data structure.
6413 * 0 - Successfully processed echo iocb (currently always return 0)
6416 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6417 struct lpfc_nodelist *ndlp)
6421 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6423 /* skip over first word of echo command to find echo data */
6424 pcmd += sizeof(uint32_t);
6426 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6431 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6432 * @vport: pointer to a host virtual N_Port data structure.
6433 * @cmdiocb: pointer to lpfc command iocb data structure.
6434 * @ndlp: pointer to a node-list data structure.
6436 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6437 * received as an ELS unsolicited event. Currently, this function just invokes
6438 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6441 * 0 - Successfully processed lirr iocb (currently always return 0)
6444 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6445 struct lpfc_nodelist *ndlp)
6449 /* For now, unconditionally reject this command */
6450 stat.un.b.lsRjtRsvd0 = 0;
6451 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6452 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6453 stat.un.b.vendorUnique = 0;
6454 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6459 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6460 * @vport: pointer to a host virtual N_Port data structure.
6461 * @cmdiocb: pointer to lpfc command iocb data structure.
6462 * @ndlp: pointer to a node-list data structure.
6464 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6465 * received as an ELS unsolicited event. A request to RRQ shall only
6466 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6467 * Nx_Port N_Port_ID of the target Exchange is the same as the
6468 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6469 * not accepted, an LS_RJT with reason code "Unable to perform
6470 * command request" and reason code explanation "Invalid Originator
6471 * S_ID" shall be returned. For now, we just unconditionally accept
6472 * RRQ from the target.
6475 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6476 struct lpfc_nodelist *ndlp)
6478 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6479 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6480 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
6484 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6485 * @phba: pointer to lpfc hba data structure.
6486 * @pmb: pointer to the driver internal queue element for mailbox command.
6488 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6489 * mailbox command. This callback function is to actually send the Accept
6490 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6491 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6492 * mailbox command, constructs the RPS response with the link statistics
6493 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6494 * response to the RPS.
6496 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6497 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6498 * will be stored into the context1 field of the IOCB for the completion
6499 * callback function to the RPS Accept Response ELS IOCB command.
6503 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6507 struct RLS_RSP *rls_rsp;
6509 struct lpfc_iocbq *elsiocb;
6510 struct lpfc_nodelist *ndlp;
6517 ndlp = (struct lpfc_nodelist *) pmb->context2;
6518 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6519 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6520 pmb->context1 = NULL;
6521 pmb->context2 = NULL;
6523 if (mb->mbxStatus) {
6524 mempool_free(pmb, phba->mbox_mem_pool);
6528 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
6529 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6530 lpfc_max_els_tries, ndlp,
6531 ndlp->nlp_DID, ELS_CMD_ACC);
6533 /* Decrement the ndlp reference count from previous mbox command */
6537 mempool_free(pmb, phba->mbox_mem_pool);
6541 icmd = &elsiocb->iocb;
6542 icmd->ulpContext = rxid;
6543 icmd->unsli3.rcvsli3.ox_id = oxid;
6545 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6546 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6547 pcmd += sizeof(uint32_t); /* Skip past command */
6548 rls_rsp = (struct RLS_RSP *)pcmd;
6550 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6551 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6552 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6553 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6554 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6555 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6556 mempool_free(pmb, phba->mbox_mem_pool);
6557 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6558 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6559 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6560 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6561 elsiocb->iotag, elsiocb->iocb.ulpContext,
6562 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6564 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6565 phba->fc_stat.elsXmitACC++;
6566 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6567 lpfc_els_free_iocb(phba, elsiocb);
6571 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6572 * @phba: pointer to lpfc hba data structure.
6573 * @pmb: pointer to the driver internal queue element for mailbox command.
6575 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6576 * mailbox command. This callback function is to actually send the Accept
6577 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6578 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6579 * mailbox command, constructs the RPS response with the link statistics
6580 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6581 * response to the RPS.
6583 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6584 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6585 * will be stored into the context1 field of the IOCB for the completion
6586 * callback function to the RPS Accept Response ELS IOCB command.
6590 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6596 struct lpfc_iocbq *elsiocb;
6597 struct lpfc_nodelist *ndlp;
6605 ndlp = (struct lpfc_nodelist *) pmb->context2;
6606 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6607 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
6608 pmb->context1 = NULL;
6609 pmb->context2 = NULL;
6611 if (mb->mbxStatus) {
6612 mempool_free(pmb, phba->mbox_mem_pool);
6616 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
6617 mempool_free(pmb, phba->mbox_mem_pool);
6618 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6619 lpfc_max_els_tries, ndlp,
6620 ndlp->nlp_DID, ELS_CMD_ACC);
6622 /* Decrement the ndlp reference count from previous mbox command */
6628 icmd = &elsiocb->iocb;
6629 icmd->ulpContext = rxid;
6630 icmd->unsli3.rcvsli3.ox_id = oxid;
6632 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6633 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6634 pcmd += sizeof(uint32_t); /* Skip past command */
6635 rps_rsp = (RPS_RSP *)pcmd;
6637 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
6641 if (phba->pport->fc_flag & FC_FABRIC)
6645 rps_rsp->portStatus = cpu_to_be16(status);
6646 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6647 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6648 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6649 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6650 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6651 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
6652 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6653 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6654 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6655 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6656 elsiocb->iotag, elsiocb->iocb.ulpContext,
6657 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6659 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6660 phba->fc_stat.elsXmitACC++;
6661 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6662 lpfc_els_free_iocb(phba, elsiocb);
6667 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6668 * @vport: pointer to a host virtual N_Port data structure.
6669 * @cmdiocb: pointer to lpfc command iocb data structure.
6670 * @ndlp: pointer to a node-list data structure.
6672 * This routine processes Read Port Status (RPL) IOCB received as an
6673 * ELS unsolicited event. It first checks the remote port state. If the
6674 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6675 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6676 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6677 * for reading the HBA link statistics. It is for the callback function,
6678 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6679 * to actually sending out RPL Accept (ACC) response.
6682 * 0 - Successfully processed rls iocb (currently always return 0)
6685 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6686 struct lpfc_nodelist *ndlp)
6688 struct lpfc_hba *phba = vport->phba;
6692 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6693 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6694 /* reject the unsolicited RPS request and done with it */
6697 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6699 lpfc_read_lnk_stat(phba, mbox);
6700 mbox->context1 = (void *)((unsigned long)
6701 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6702 cmdiocb->iocb.ulpContext)); /* rx_id */
6703 mbox->context2 = lpfc_nlp_get(ndlp);
6704 mbox->vport = vport;
6705 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6706 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6707 != MBX_NOT_FINISHED)
6708 /* Mbox completion will send ELS Response */
6710 /* Decrement reference count used for the failed mbox
6714 mempool_free(mbox, phba->mbox_mem_pool);
6717 /* issue rejection response */
6718 stat.un.b.lsRjtRsvd0 = 0;
6719 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6720 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6721 stat.un.b.vendorUnique = 0;
6722 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6727 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6728 * @vport: pointer to a host virtual N_Port data structure.
6729 * @cmdiocb: pointer to lpfc command iocb data structure.
6730 * @ndlp: pointer to a node-list data structure.
6732 * This routine processes Read Timout Value (RTV) IOCB received as an
6733 * ELS unsolicited event. It first checks the remote port state. If the
6734 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6735 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6736 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6737 * Value (RTV) unsolicited IOCB event.
6739 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6740 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6741 * will be stored into the context1 field of the IOCB for the completion
6742 * callback function to the RPS Accept Response ELS IOCB command.
6745 * 0 - Successfully processed rtv iocb (currently always return 0)
6748 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6749 struct lpfc_nodelist *ndlp)
6751 struct lpfc_hba *phba = vport->phba;
6753 struct RTV_RSP *rtv_rsp;
6755 struct lpfc_iocbq *elsiocb;
6759 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6760 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6761 /* reject the unsolicited RPS request and done with it */
6764 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6765 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6766 lpfc_max_els_tries, ndlp,
6767 ndlp->nlp_DID, ELS_CMD_ACC);
6772 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6773 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6774 pcmd += sizeof(uint32_t); /* Skip past command */
6776 /* use the command's xri in the response */
6777 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6778 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6780 rtv_rsp = (struct RTV_RSP *)pcmd;
6782 /* populate RTV payload */
6783 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6784 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6785 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6786 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6787 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6789 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6790 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6791 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6792 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6793 "Data: x%x x%x x%x\n",
6794 elsiocb->iotag, elsiocb->iocb.ulpContext,
6795 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6797 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6798 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6799 phba->fc_stat.elsXmitACC++;
6800 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6801 lpfc_els_free_iocb(phba, elsiocb);
6805 /* issue rejection response */
6806 stat.un.b.lsRjtRsvd0 = 0;
6807 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6808 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6809 stat.un.b.vendorUnique = 0;
6810 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6814 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6815 * @vport: pointer to a host virtual N_Port data structure.
6816 * @cmdiocb: pointer to lpfc command iocb data structure.
6817 * @ndlp: pointer to a node-list data structure.
6819 * This routine processes Read Port Status (RPS) IOCB received as an
6820 * ELS unsolicited event. It first checks the remote port state. If the
6821 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6822 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6823 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6824 * for reading the HBA link statistics. It is for the callback function,
6825 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6826 * to actually sending out RPS Accept (ACC) response.
6829 * 0 - Successfully processed rps iocb (currently always return 0)
6832 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6833 struct lpfc_nodelist *ndlp)
6835 struct lpfc_hba *phba = vport->phba;
6839 struct lpfc_dmabuf *pcmd;
6843 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6844 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6845 /* reject the unsolicited RPS request and done with it */
6848 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6849 lp = (uint32_t *) pcmd->virt;
6850 flag = (be32_to_cpu(*lp++) & 0xf);
6854 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
6855 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
6856 sizeof(struct lpfc_name)) == 0))) {
6858 printk("Fix me....\n");
6860 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6862 lpfc_read_lnk_stat(phba, mbox);
6863 mbox->context1 = (void *)((unsigned long)
6864 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6865 cmdiocb->iocb.ulpContext)); /* rx_id */
6866 mbox->context2 = lpfc_nlp_get(ndlp);
6867 mbox->vport = vport;
6868 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
6869 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6870 != MBX_NOT_FINISHED)
6871 /* Mbox completion will send ELS Response */
6873 /* Decrement reference count used for the failed mbox
6877 mempool_free(mbox, phba->mbox_mem_pool);
6882 /* issue rejection response */
6883 stat.un.b.lsRjtRsvd0 = 0;
6884 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6885 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6886 stat.un.b.vendorUnique = 0;
6887 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6891 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6892 * @vport: pointer to a host virtual N_Port data structure.
6893 * @ndlp: pointer to a node-list data structure.
6894 * @did: DID of the target.
6895 * @rrq: Pointer to the rrq struct.
6897 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6898 * Successful the the completion handler will clear the RRQ.
6901 * 0 - Successfully sent rrq els iocb.
6902 * 1 - Failed to send rrq els iocb.
6905 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6906 uint32_t did, struct lpfc_node_rrq *rrq)
6908 struct lpfc_hba *phba = vport->phba;
6909 struct RRQ *els_rrq;
6910 struct lpfc_iocbq *elsiocb;
6916 if (ndlp != rrq->ndlp)
6918 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6921 /* If ndlp is not NULL, we will bump the reference count on it */
6922 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6923 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6928 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6930 /* For RRQ request, remainder of payload is Exchange IDs */
6931 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6932 pcmd += sizeof(uint32_t);
6933 els_rrq = (struct RRQ *) pcmd;
6935 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
6936 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6937 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6938 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6939 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6943 "Issue RRQ: did:x%x",
6944 did, rrq->xritag, rrq->rxid);
6945 elsiocb->context_un.rrq = rrq;
6946 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6947 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6949 if (ret == IOCB_ERROR) {
6950 lpfc_els_free_iocb(phba, elsiocb);
6957 * lpfc_send_rrq - Sends ELS RRQ if needed.
6958 * @phba: pointer to lpfc hba data structure.
6959 * @rrq: pointer to the active rrq.
6961 * This routine will call the lpfc_issue_els_rrq if the rrq is
6962 * still active for the xri. If this function returns a failure then
6963 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6965 * Returns 0 Success.
6969 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6971 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6973 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6974 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6981 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6982 * @vport: pointer to a host virtual N_Port data structure.
6983 * @cmdsize: size of the ELS command.
6984 * @oldiocb: pointer to the original lpfc command iocb data structure.
6985 * @ndlp: pointer to a node-list data structure.
6987 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6988 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6990 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6991 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6992 * will be stored into the context1 field of the IOCB for the completion
6993 * callback function to the RPL Accept Response ELS command.
6996 * 0 - Successfully issued ACC RPL ELS command
6997 * 1 - Failed to issue ACC RPL ELS command
7000 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7001 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7003 struct lpfc_hba *phba = vport->phba;
7004 IOCB_t *icmd, *oldcmd;
7006 struct lpfc_iocbq *elsiocb;
7009 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7010 ndlp->nlp_DID, ELS_CMD_ACC);
7015 icmd = &elsiocb->iocb;
7016 oldcmd = &oldiocb->iocb;
7017 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7018 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7020 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7021 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7022 pcmd += sizeof(uint16_t);
7023 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7024 pcmd += sizeof(uint16_t);
7026 /* Setup the RPL ACC payload */
7027 rpl_rsp.listLen = be32_to_cpu(1);
7029 rpl_rsp.port_num_blk.portNum = 0;
7030 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7031 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7032 sizeof(struct lpfc_name));
7033 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7034 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7035 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7036 "0120 Xmit ELS RPL ACC response tag x%x "
7037 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7039 elsiocb->iotag, elsiocb->iocb.ulpContext,
7040 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7042 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7043 phba->fc_stat.elsXmitACC++;
7044 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7046 lpfc_els_free_iocb(phba, elsiocb);
7053 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7054 * @vport: pointer to a host virtual N_Port data structure.
7055 * @cmdiocb: pointer to lpfc command iocb data structure.
7056 * @ndlp: pointer to a node-list data structure.
7058 * This routine processes Read Port List (RPL) IOCB received as an ELS
7059 * unsolicited event. It first checks the remote port state. If the remote
7060 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7061 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7062 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7063 * to accept the RPL.
7066 * 0 - Successfully processed rpl iocb (currently always return 0)
7069 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7070 struct lpfc_nodelist *ndlp)
7072 struct lpfc_dmabuf *pcmd;
7079 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7080 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7081 /* issue rejection response */
7082 stat.un.b.lsRjtRsvd0 = 0;
7083 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7084 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7085 stat.un.b.vendorUnique = 0;
7086 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7088 /* rejected the unsolicited RPL request and done with it */
7092 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7093 lp = (uint32_t *) pcmd->virt;
7094 rpl = (RPL *) (lp + 1);
7095 maxsize = be32_to_cpu(rpl->maxsize);
7097 /* We support only one port */
7098 if ((rpl->index == 0) &&
7100 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7101 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7103 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7105 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7111 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7112 * @vport: pointer to a virtual N_Port data structure.
7113 * @cmdiocb: pointer to lpfc command iocb data structure.
7114 * @ndlp: pointer to a node-list data structure.
7116 * This routine processes Fibre Channel Address Resolution Protocol
7117 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7118 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7119 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7120 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7121 * remote PortName is compared against the FC PortName stored in the @vport
7122 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7123 * compared against the FC NodeName stored in the @vport data structure.
7124 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7125 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7126 * invoked to send out FARP Response to the remote node. Before sending the
7127 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7128 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7129 * routine is invoked to log into the remote port first.
7132 * 0 - Either the FARP Match Mode not supported or successfully processed
7135 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7136 struct lpfc_nodelist *ndlp)
7138 struct lpfc_dmabuf *pcmd;
7142 uint32_t cmd, cnt, did;
7144 icmd = &cmdiocb->iocb;
7145 did = icmd->un.elsreq64.remoteID;
7146 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7147 lp = (uint32_t *) pcmd->virt;
7151 /* FARP-REQ received from DID <did> */
7152 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7153 "0601 FARP-REQ received from DID x%x\n", did);
7154 /* We will only support match on WWPN or WWNN */
7155 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7160 /* If this FARP command is searching for my portname */
7161 if (fp->Mflags & FARP_MATCH_PORT) {
7162 if (memcmp(&fp->RportName, &vport->fc_portname,
7163 sizeof(struct lpfc_name)) == 0)
7167 /* If this FARP command is searching for my nodename */
7168 if (fp->Mflags & FARP_MATCH_NODE) {
7169 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7170 sizeof(struct lpfc_name)) == 0)
7175 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7176 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7177 /* Log back into the node before sending the FARP. */
7178 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7179 ndlp->nlp_prev_state = ndlp->nlp_state;
7180 lpfc_nlp_set_state(vport, ndlp,
7181 NLP_STE_PLOGI_ISSUE);
7182 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7185 /* Send a FARP response to that node */
7186 if (fp->Rflags & FARP_REQUEST_FARPR)
7187 lpfc_issue_els_farpr(vport, did, 0);
7194 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7195 * @vport: pointer to a host virtual N_Port data structure.
7196 * @cmdiocb: pointer to lpfc command iocb data structure.
7197 * @ndlp: pointer to a node-list data structure.
7199 * This routine processes Fibre Channel Address Resolution Protocol
7200 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7201 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7202 * the FARP response request.
7205 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7208 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7209 struct lpfc_nodelist *ndlp)
7211 struct lpfc_dmabuf *pcmd;
7216 icmd = &cmdiocb->iocb;
7217 did = icmd->un.elsreq64.remoteID;
7218 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7219 lp = (uint32_t *) pcmd->virt;
7222 /* FARP-RSP received from DID <did> */
7223 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7224 "0600 FARP-RSP received from DID x%x\n", did);
7225 /* ACCEPT the Farp resp request */
7226 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7232 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7233 * @vport: pointer to a host virtual N_Port data structure.
7234 * @cmdiocb: pointer to lpfc command iocb data structure.
7235 * @fan_ndlp: pointer to a node-list data structure.
7237 * This routine processes a Fabric Address Notification (FAN) IOCB
7238 * command received as an ELS unsolicited event. The FAN ELS command will
7239 * only be processed on a physical port (i.e., the @vport represents the
7240 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7241 * compared against those in the phba data structure. If any of those is
7242 * different, the lpfc_initial_flogi() routine is invoked to initialize
7243 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7244 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7245 * is invoked to register login to the fabric.
7248 * 0 - Successfully processed fan iocb (currently always return 0).
7251 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7252 struct lpfc_nodelist *fan_ndlp)
7254 struct lpfc_hba *phba = vport->phba;
7258 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7259 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7261 /* FAN received; Fan does not have a reply sequence */
7262 if ((vport == phba->pport) &&
7263 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7264 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7265 sizeof(struct lpfc_name))) ||
7266 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7267 sizeof(struct lpfc_name)))) {
7268 /* This port has switched fabrics. FLOGI is required */
7269 lpfc_issue_init_vfi(vport);
7271 /* FAN verified - skip FLOGI */
7272 vport->fc_myDID = vport->fc_prevDID;
7273 if (phba->sli_rev < LPFC_SLI_REV4)
7274 lpfc_issue_fabric_reglogin(vport);
7276 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7277 "3138 Need register VFI: (x%x/%x)\n",
7278 vport->fc_prevDID, vport->fc_myDID);
7279 lpfc_issue_reg_vfi(vport);
7287 * lpfc_els_timeout - Handler funciton to the els timer
7288 * @ptr: holder for the timer function associated data.
7290 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7291 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7292 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7293 * up the worker thread. It is for the worker thread to invoke the routine
7294 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7297 lpfc_els_timeout(unsigned long ptr)
7299 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7300 struct lpfc_hba *phba = vport->phba;
7301 uint32_t tmo_posted;
7302 unsigned long iflag;
7304 spin_lock_irqsave(&vport->work_port_lock, iflag);
7305 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7306 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7307 vport->work_port_events |= WORKER_ELS_TMO;
7308 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7310 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7311 lpfc_worker_wake_up(phba);
7317 * lpfc_els_timeout_handler - Process an els timeout event
7318 * @vport: pointer to a virtual N_Port data structure.
7320 * This routine is the actual handler function that processes an ELS timeout
7321 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7322 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7323 * invoking the lpfc_sli_issue_abort_iotag() routine.
7326 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7328 struct lpfc_hba *phba = vport->phba;
7329 struct lpfc_sli_ring *pring;
7330 struct lpfc_iocbq *tmp_iocb, *piocb;
7332 struct lpfc_dmabuf *pcmd;
7333 uint32_t els_command = 0;
7335 uint32_t remote_ID = 0xffffffff;
7336 LIST_HEAD(abort_list);
7339 timeout = (uint32_t)(phba->fc_ratov << 1);
7341 pring = lpfc_phba_elsring(phba);
7343 if ((phba->pport->load_flag & FC_UNLOADING))
7345 spin_lock_irq(&phba->hbalock);
7346 if (phba->sli_rev == LPFC_SLI_REV4)
7347 spin_lock(&pring->ring_lock);
7349 if ((phba->pport->load_flag & FC_UNLOADING)) {
7350 if (phba->sli_rev == LPFC_SLI_REV4)
7351 spin_unlock(&pring->ring_lock);
7352 spin_unlock_irq(&phba->hbalock);
7356 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7359 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7360 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7361 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7364 if (piocb->vport != vport)
7367 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7369 els_command = *(uint32_t *) (pcmd->virt);
7371 if (els_command == ELS_CMD_FARP ||
7372 els_command == ELS_CMD_FARPR ||
7373 els_command == ELS_CMD_FDISC)
7376 if (piocb->drvrTimeout > 0) {
7377 if (piocb->drvrTimeout >= timeout)
7378 piocb->drvrTimeout -= timeout;
7380 piocb->drvrTimeout = 0;
7384 remote_ID = 0xffffffff;
7385 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7386 remote_ID = cmd->un.elsreq64.remoteID;
7388 struct lpfc_nodelist *ndlp;
7389 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7390 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7391 remote_ID = ndlp->nlp_DID;
7393 list_add_tail(&piocb->dlist, &abort_list);
7395 if (phba->sli_rev == LPFC_SLI_REV4)
7396 spin_unlock(&pring->ring_lock);
7397 spin_unlock_irq(&phba->hbalock);
7399 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7401 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7402 "0127 ELS timeout Data: x%x x%x x%x "
7403 "x%x\n", els_command,
7404 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7405 spin_lock_irq(&phba->hbalock);
7406 list_del_init(&piocb->dlist);
7407 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7408 spin_unlock_irq(&phba->hbalock);
7411 if (!list_empty(&pring->txcmplq))
7412 if (!(phba->pport->load_flag & FC_UNLOADING))
7413 mod_timer(&vport->els_tmofunc,
7414 jiffies + msecs_to_jiffies(1000 * timeout));
7418 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7419 * @vport: pointer to a host virtual N_Port data structure.
7421 * This routine is used to clean up all the outstanding ELS commands on a
7422 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7423 * routine. After that, it walks the ELS transmit queue to remove all the
7424 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7425 * the IOCBs with a non-NULL completion callback function, the callback
7426 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7427 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7428 * callback function, the IOCB will simply be released. Finally, it walks
7429 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7430 * completion queue IOCB that is associated with the @vport and is not
7431 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7432 * part of the discovery state machine) out to HBA by invoking the
7433 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7434 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7435 * the IOCBs are aborted when this function returns.
7438 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7440 LIST_HEAD(abort_list);
7441 struct lpfc_hba *phba = vport->phba;
7442 struct lpfc_sli_ring *pring;
7443 struct lpfc_iocbq *tmp_iocb, *piocb;
7446 lpfc_fabric_abort_vport(vport);
7448 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7449 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7450 * ultimately grabs the ring_lock, the driver must splice the list into
7451 * a working list and release the locks before calling the abort.
7453 spin_lock_irq(&phba->hbalock);
7454 pring = lpfc_phba_elsring(phba);
7455 if (phba->sli_rev == LPFC_SLI_REV4)
7456 spin_lock(&pring->ring_lock);
7458 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7459 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7462 if (piocb->vport != vport)
7464 list_add_tail(&piocb->dlist, &abort_list);
7466 if (phba->sli_rev == LPFC_SLI_REV4)
7467 spin_unlock(&pring->ring_lock);
7468 spin_unlock_irq(&phba->hbalock);
7469 /* Abort each iocb on the aborted list and remove the dlist links. */
7470 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7471 spin_lock_irq(&phba->hbalock);
7472 list_del_init(&piocb->dlist);
7473 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7474 spin_unlock_irq(&phba->hbalock);
7476 if (!list_empty(&abort_list))
7477 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7478 "3387 abort list for txq not empty\n");
7479 INIT_LIST_HEAD(&abort_list);
7481 spin_lock_irq(&phba->hbalock);
7482 if (phba->sli_rev == LPFC_SLI_REV4)
7483 spin_lock(&pring->ring_lock);
7485 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7488 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7492 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7493 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7494 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7495 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7496 cmd->ulpCommand == CMD_ABORT_XRI_CN)
7499 if (piocb->vport != vport)
7502 list_del_init(&piocb->list);
7503 list_add_tail(&piocb->list, &abort_list);
7505 if (phba->sli_rev == LPFC_SLI_REV4)
7506 spin_unlock(&pring->ring_lock);
7507 spin_unlock_irq(&phba->hbalock);
7509 /* Cancell all the IOCBs from the completions list */
7510 lpfc_sli_cancel_iocbs(phba, &abort_list,
7511 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
7517 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7518 * @phba: pointer to lpfc hba data structure.
7520 * This routine is used to clean up all the outstanding ELS commands on a
7521 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7522 * routine. After that, it walks the ELS transmit queue to remove all the
7523 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7524 * the IOCBs with the completion callback function associated, the callback
7525 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7526 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7527 * callback function associated, the IOCB will simply be released. Finally,
7528 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7529 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7530 * management plane IOCBs that are not part of the discovery state machine)
7531 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7534 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7536 struct lpfc_vport *vport;
7537 list_for_each_entry(vport, &phba->port_list, listentry)
7538 lpfc_els_flush_cmd(vport);
7544 * lpfc_send_els_failure_event - Posts an ELS command failure event
7545 * @phba: Pointer to hba context object.
7546 * @cmdiocbp: Pointer to command iocb which reported error.
7547 * @rspiocbp: Pointer to response iocb which reported error.
7549 * This function sends an event when there is an ELS command
7553 lpfc_send_els_failure_event(struct lpfc_hba *phba,
7554 struct lpfc_iocbq *cmdiocbp,
7555 struct lpfc_iocbq *rspiocbp)
7557 struct lpfc_vport *vport = cmdiocbp->vport;
7558 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7559 struct lpfc_lsrjt_event lsrjt_event;
7560 struct lpfc_fabric_event_header fabric_event;
7562 struct lpfc_nodelist *ndlp;
7565 ndlp = cmdiocbp->context1;
7566 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7569 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7570 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7571 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7572 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7573 sizeof(struct lpfc_name));
7574 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7575 sizeof(struct lpfc_name));
7576 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7577 cmdiocbp->context2)->virt);
7578 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
7579 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7580 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7581 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7582 fc_host_post_vendor_event(shost,
7583 fc_get_event_number(),
7584 sizeof(lsrjt_event),
7585 (char *)&lsrjt_event,
7589 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7590 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7591 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7592 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7593 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7595 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7596 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7597 sizeof(struct lpfc_name));
7598 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7599 sizeof(struct lpfc_name));
7600 fc_host_post_vendor_event(shost,
7601 fc_get_event_number(),
7602 sizeof(fabric_event),
7603 (char *)&fabric_event,
7611 * lpfc_send_els_event - Posts unsolicited els event
7612 * @vport: Pointer to vport object.
7613 * @ndlp: Pointer FC node object.
7614 * @cmd: ELS command code.
7616 * This function posts an event when there is an incoming
7617 * unsolicited ELS command.
7620 lpfc_send_els_event(struct lpfc_vport *vport,
7621 struct lpfc_nodelist *ndlp,
7624 struct lpfc_els_event_header *els_data = NULL;
7625 struct lpfc_logo_event *logo_data = NULL;
7626 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7628 if (*payload == ELS_CMD_LOGO) {
7629 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7631 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7632 "0148 Failed to allocate memory "
7633 "for LOGO event\n");
7636 els_data = &logo_data->header;
7638 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7641 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7642 "0149 Failed to allocate memory "
7647 els_data->event_type = FC_REG_ELS_EVENT;
7650 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
7653 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
7656 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7659 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7660 /* Copy the WWPN in the LOGO payload */
7661 memcpy(logo_data->logo_wwpn, &payload[2],
7662 sizeof(struct lpfc_name));
7668 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7669 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7670 if (*payload == ELS_CMD_LOGO) {
7671 fc_host_post_vendor_event(shost,
7672 fc_get_event_number(),
7673 sizeof(struct lpfc_logo_event),
7678 fc_host_post_vendor_event(shost,
7679 fc_get_event_number(),
7680 sizeof(struct lpfc_els_event_header),
7691 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7692 * @phba: pointer to lpfc hba data structure.
7693 * @pring: pointer to a SLI ring.
7694 * @vport: pointer to a host virtual N_Port data structure.
7695 * @elsiocb: pointer to lpfc els command iocb data structure.
7697 * This routine is used for processing the IOCB associated with a unsolicited
7698 * event. It first determines whether there is an existing ndlp that matches
7699 * the DID from the unsolicited IOCB. If not, it will create a new one with
7700 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7701 * IOCB is then used to invoke the proper routine and to set up proper state
7702 * of the discovery state machine.
7705 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7706 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
7708 struct Scsi_Host *shost;
7709 struct lpfc_nodelist *ndlp;
7712 uint32_t cmd, did, newnode;
7713 uint8_t rjt_exp, rjt_err = 0;
7714 IOCB_t *icmd = &elsiocb->iocb;
7716 if (!vport || !(elsiocb->context2))
7720 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7722 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
7723 lpfc_post_buffer(phba, pring, 1);
7725 did = icmd->un.rcvels.remoteID;
7726 if (icmd->ulpStatus) {
7727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7728 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7729 icmd->ulpStatus, icmd->un.ulpWord[4], did);
7733 /* Check to see if link went down during discovery */
7734 if (lpfc_els_chk_latt(vport))
7737 /* Ignore traffic received during vport shutdown. */
7738 if (vport->load_flag & FC_UNLOADING)
7741 /* If NPort discovery is delayed drop incoming ELS */
7742 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7743 (cmd != ELS_CMD_PLOGI))
7746 ndlp = lpfc_findnode_did(vport, did);
7748 /* Cannot find existing Fabric ndlp, so allocate a new one */
7749 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7753 lpfc_nlp_init(vport, ndlp, did);
7754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7756 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7757 ndlp->nlp_type |= NLP_FABRIC;
7758 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7759 ndlp = lpfc_enable_node(vport, ndlp,
7760 NLP_STE_UNUSED_NODE);
7763 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7765 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7766 ndlp->nlp_type |= NLP_FABRIC;
7767 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7768 /* This is similar to the new node path */
7769 ndlp = lpfc_nlp_get(ndlp);
7772 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7776 phba->fc_stat.elsRcvFrame++;
7779 * Do not process any unsolicited ELS commands
7780 * if the ndlp is in DEV_LOSS
7782 shost = lpfc_shost_from_vport(vport);
7783 spin_lock_irq(shost->host_lock);
7784 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7785 spin_unlock_irq(shost->host_lock);
7788 spin_unlock_irq(shost->host_lock);
7790 elsiocb->context1 = lpfc_nlp_get(ndlp);
7791 elsiocb->vport = vport;
7793 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7794 cmd &= ELS_CMD_MASK;
7796 /* ELS command <elsCmd> received from NPORT <did> */
7797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7798 "0112 ELS command x%x received from NPORT x%x "
7799 "Data: x%x x%x x%x x%x\n",
7800 cmd, did, vport->port_state, vport->fc_flag,
7801 vport->fc_myDID, vport->fc_prevDID);
7803 /* reject till our FLOGI completes */
7804 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
7805 (cmd != ELS_CMD_FLOGI)) {
7806 rjt_err = LSRJT_LOGICAL_BSY;
7807 rjt_exp = LSEXP_NOTHING_MORE;
7813 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7814 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7815 did, vport->port_state, ndlp->nlp_flag);
7817 phba->fc_stat.elsRcvPLOGI++;
7818 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
7819 if (phba->sli_rev == LPFC_SLI_REV4 &&
7820 (phba->pport->fc_flag & FC_PT2PT)) {
7821 vport->fc_prevDID = vport->fc_myDID;
7822 /* Our DID needs to be updated before registering
7823 * the vfi. This is done in lpfc_rcv_plogi but
7824 * that is called after the reg_vfi.
7826 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7827 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7828 "3312 Remote port assigned DID x%x "
7829 "%x\n", vport->fc_myDID,
7833 lpfc_send_els_event(vport, ndlp, payload);
7835 /* If Nport discovery is delayed, reject PLOGIs */
7836 if (vport->fc_flag & FC_DISC_DELAYED) {
7837 rjt_err = LSRJT_UNABLE_TPC;
7838 rjt_exp = LSEXP_NOTHING_MORE;
7842 if (vport->port_state < LPFC_DISC_AUTH) {
7843 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7844 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7845 rjt_err = LSRJT_UNABLE_TPC;
7846 rjt_exp = LSEXP_NOTHING_MORE;
7851 spin_lock_irq(shost->host_lock);
7852 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7853 spin_unlock_irq(shost->host_lock);
7855 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7861 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7862 did, vport->port_state, ndlp->nlp_flag);
7864 phba->fc_stat.elsRcvFLOGI++;
7865 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
7870 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7871 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7872 did, vport->port_state, ndlp->nlp_flag);
7874 phba->fc_stat.elsRcvLOGO++;
7875 lpfc_send_els_event(vport, ndlp, payload);
7876 if (vport->port_state < LPFC_DISC_AUTH) {
7877 rjt_err = LSRJT_UNABLE_TPC;
7878 rjt_exp = LSEXP_NOTHING_MORE;
7881 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
7884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7885 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7886 did, vport->port_state, ndlp->nlp_flag);
7888 phba->fc_stat.elsRcvPRLO++;
7889 lpfc_send_els_event(vport, ndlp, payload);
7890 if (vport->port_state < LPFC_DISC_AUTH) {
7891 rjt_err = LSRJT_UNABLE_TPC;
7892 rjt_exp = LSEXP_NOTHING_MORE;
7895 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
7898 phba->fc_stat.elsRcvLCB++;
7899 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7902 phba->fc_stat.elsRcvRDP++;
7903 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7906 phba->fc_stat.elsRcvRSCN++;
7907 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
7912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7913 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7914 did, vport->port_state, ndlp->nlp_flag);
7916 lpfc_send_els_event(vport, ndlp, payload);
7917 phba->fc_stat.elsRcvADISC++;
7918 if (vport->port_state < LPFC_DISC_AUTH) {
7919 rjt_err = LSRJT_UNABLE_TPC;
7920 rjt_exp = LSEXP_NOTHING_MORE;
7923 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7928 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7929 did, vport->port_state, ndlp->nlp_flag);
7931 phba->fc_stat.elsRcvPDISC++;
7932 if (vport->port_state < LPFC_DISC_AUTH) {
7933 rjt_err = LSRJT_UNABLE_TPC;
7934 rjt_exp = LSEXP_NOTHING_MORE;
7937 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7941 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7942 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7943 did, vport->port_state, ndlp->nlp_flag);
7945 phba->fc_stat.elsRcvFARPR++;
7946 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
7949 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7950 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7951 did, vport->port_state, ndlp->nlp_flag);
7953 phba->fc_stat.elsRcvFARP++;
7954 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
7957 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7958 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7959 did, vport->port_state, ndlp->nlp_flag);
7961 phba->fc_stat.elsRcvFAN++;
7962 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
7965 case ELS_CMD_NVMEPRLI:
7966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7967 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7968 did, vport->port_state, ndlp->nlp_flag);
7970 phba->fc_stat.elsRcvPRLI++;
7971 if (vport->port_state < LPFC_DISC_AUTH) {
7972 rjt_err = LSRJT_UNABLE_TPC;
7973 rjt_exp = LSEXP_NOTHING_MORE;
7976 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
7979 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7980 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7981 did, vport->port_state, ndlp->nlp_flag);
7983 phba->fc_stat.elsRcvLIRR++;
7984 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
7989 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7990 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7991 did, vport->port_state, ndlp->nlp_flag);
7993 phba->fc_stat.elsRcvRLS++;
7994 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8000 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8001 did, vport->port_state, ndlp->nlp_flag);
8003 phba->fc_stat.elsRcvRPS++;
8004 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8009 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8010 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8011 did, vport->port_state, ndlp->nlp_flag);
8013 phba->fc_stat.elsRcvRPL++;
8014 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8019 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8020 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8021 did, vport->port_state, ndlp->nlp_flag);
8023 phba->fc_stat.elsRcvRNID++;
8024 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8029 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8030 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8031 did, vport->port_state, ndlp->nlp_flag);
8032 phba->fc_stat.elsRcvRTV++;
8033 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8038 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8039 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8040 did, vport->port_state, ndlp->nlp_flag);
8042 phba->fc_stat.elsRcvRRQ++;
8043 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8048 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8049 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8050 did, vport->port_state, ndlp->nlp_flag);
8052 phba->fc_stat.elsRcvECHO++;
8053 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8058 /* receive this due to exchange closed */
8059 rjt_err = LSRJT_UNABLE_TPC;
8060 rjt_exp = LSEXP_INVALID_OX_RX;
8063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8064 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8065 cmd, did, vport->port_state);
8067 /* Unsupported ELS command, reject */
8068 rjt_err = LSRJT_CMD_UNSUPPORTED;
8069 rjt_exp = LSEXP_NOTHING_MORE;
8071 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8072 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8073 "0115 Unknown ELS command x%x "
8074 "received from NPORT x%x\n", cmd, did);
8081 /* check if need to LS_RJT received ELS cmd */
8083 memset(&stat, 0, sizeof(stat));
8084 stat.un.b.lsRjtRsnCode = rjt_err;
8085 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8086 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8090 lpfc_nlp_put(elsiocb->context1);
8091 elsiocb->context1 = NULL;
8095 if (vport && !(vport->load_flag & FC_UNLOADING))
8096 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8097 "0111 Dropping received ELS cmd "
8098 "Data: x%x x%x x%x\n",
8099 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8100 phba->fc_stat.elsRcvDrop++;
8104 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8105 * @phba: pointer to lpfc hba data structure.
8106 * @pring: pointer to a SLI ring.
8107 * @elsiocb: pointer to lpfc els iocb data structure.
8109 * This routine is used to process an unsolicited event received from a SLI
8110 * (Service Level Interface) ring. The actual processing of the data buffer
8111 * associated with the unsolicited event is done by invoking the routine
8112 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8113 * SLI ring on which the unsolicited event was received.
8116 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8117 struct lpfc_iocbq *elsiocb)
8119 struct lpfc_vport *vport = phba->pport;
8120 IOCB_t *icmd = &elsiocb->iocb;
8122 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8123 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8125 elsiocb->context1 = NULL;
8126 elsiocb->context2 = NULL;
8127 elsiocb->context3 = NULL;
8129 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8130 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8131 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8132 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8133 IOERR_RCV_BUFFER_WAITING) {
8134 phba->fc_stat.NoRcvBuf++;
8135 /* Not enough posted buffers; Try posting more buffers */
8136 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8137 lpfc_post_buffer(phba, pring, 0);
8141 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8142 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8143 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8144 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8145 vport = phba->pport;
8147 vport = lpfc_find_vport_by_vpid(phba,
8148 icmd->unsli3.rcvsli3.vpi);
8151 /* If there are no BDEs associated
8152 * with this IOCB, there is nothing to do.
8154 if (icmd->ulpBdeCount == 0)
8157 /* type of ELS cmd is first 32bit word
8160 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8161 elsiocb->context2 = bdeBuf1;
8163 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8164 icmd->un.cont64[0].addrLow);
8165 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8169 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8171 * The different unsolicited event handlers would tell us
8172 * if they are done with "mp" by setting context2 to NULL.
8174 if (elsiocb->context2) {
8175 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8176 elsiocb->context2 = NULL;
8179 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8180 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8181 icmd->ulpBdeCount == 2) {
8182 elsiocb->context2 = bdeBuf2;
8183 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8184 /* free mp if we are done with it */
8185 if (elsiocb->context2) {
8186 lpfc_in_buf_free(phba, elsiocb->context2);
8187 elsiocb->context2 = NULL;
8193 lpfc_start_fdmi(struct lpfc_vport *vport)
8195 struct lpfc_hba *phba = vport->phba;
8196 struct lpfc_nodelist *ndlp;
8198 /* If this is the first time, allocate an ndlp and initialize
8199 * it. Otherwise, make sure the node is enabled and then do the
8202 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8204 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
8206 lpfc_nlp_init(vport, ndlp, FDMI_DID);
8207 ndlp->nlp_type |= NLP_FABRIC;
8212 if (!NLP_CHK_NODE_ACT(ndlp))
8213 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8216 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8217 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8222 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8223 * @phba: pointer to lpfc hba data structure.
8224 * @vport: pointer to a virtual N_Port data structure.
8226 * This routine issues a Port Login (PLOGI) to the Name Server with
8227 * State Change Request (SCR) for a @vport. This routine will create an
8228 * ndlp for the Name Server associated to the @vport if such node does
8229 * not already exist. The PLOGI to Name Server is issued by invoking the
8230 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8231 * (FDMI) is configured to the @vport, a FDMI node will be created and
8232 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8235 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8237 struct lpfc_nodelist *ndlp;
8238 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8241 * If lpfc_delay_discovery parameter is set and the clean address
8242 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8245 spin_lock_irq(shost->host_lock);
8246 if (vport->fc_flag & FC_DISC_DELAYED) {
8247 spin_unlock_irq(shost->host_lock);
8248 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8249 "3334 Delay fc port discovery for %d seconds\n",
8251 mod_timer(&vport->delayed_disc_tmo,
8252 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8255 spin_unlock_irq(shost->host_lock);
8257 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8259 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
8261 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8262 lpfc_disc_start(vport);
8265 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8266 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8267 "0251 NameServer login: no memory\n");
8270 lpfc_nlp_init(vport, ndlp, NameServer_DID);
8271 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8272 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8274 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8275 lpfc_disc_start(vport);
8278 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8279 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8280 "0348 NameServer login: node freed\n");
8284 ndlp->nlp_type |= NLP_FABRIC;
8286 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8288 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8289 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8290 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8291 "0252 Cannot issue NameServer login\n");
8295 if ((phba->cfg_enable_SmartSAN ||
8296 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8297 (vport->load_flag & FC_ALLOW_FDMI))
8298 lpfc_start_fdmi(vport);
8302 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8303 * @phba: pointer to lpfc hba data structure.
8304 * @pmb: pointer to the driver internal queue element for mailbox command.
8306 * This routine is the completion callback function to register new vport
8307 * mailbox command. If the new vport mailbox command completes successfully,
8308 * the fabric registration login shall be performed on physical port (the
8309 * new vport created is actually a physical port, with VPI 0) or the port
8310 * login to Name Server for State Change Request (SCR) will be performed
8311 * on virtual port (real virtual port, with VPI greater than 0).
8314 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8316 struct lpfc_vport *vport = pmb->vport;
8317 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8318 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
8319 MAILBOX_t *mb = &pmb->u.mb;
8322 spin_lock_irq(shost->host_lock);
8323 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8324 spin_unlock_irq(shost->host_lock);
8326 if (mb->mbxStatus) {
8327 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8328 "0915 Register VPI failed : Status: x%x"
8329 " upd bit: x%x \n", mb->mbxStatus,
8330 mb->un.varRegVpi.upd);
8331 if (phba->sli_rev == LPFC_SLI_REV4 &&
8332 mb->un.varRegVpi.upd)
8333 goto mbox_err_exit ;
8335 switch (mb->mbxStatus) {
8336 case 0x11: /* unsupported feature */
8337 case 0x9603: /* max_vpi exceeded */
8338 case 0x9602: /* Link event since CLEAR_LA */
8339 /* giving up on vport registration */
8340 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8341 spin_lock_irq(shost->host_lock);
8342 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8343 spin_unlock_irq(shost->host_lock);
8344 lpfc_can_disctmo(vport);
8346 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8348 spin_lock_irq(shost->host_lock);
8349 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8350 spin_unlock_irq(shost->host_lock);
8351 lpfc_init_vpi(phba, pmb, vport->vpi);
8353 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8354 rc = lpfc_sli_issue_mbox(phba, pmb,
8356 if (rc == MBX_NOT_FINISHED) {
8357 lpfc_printf_vlog(vport,
8359 "2732 Failed to issue INIT_VPI"
8360 " mailbox command\n");
8367 /* Try to recover from this error */
8368 if (phba->sli_rev == LPFC_SLI_REV4)
8369 lpfc_sli4_unreg_all_rpis(vport);
8370 lpfc_mbx_unreg_vpi(vport);
8371 spin_lock_irq(shost->host_lock);
8372 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8373 spin_unlock_irq(shost->host_lock);
8374 if (mb->mbxStatus == MBX_NOT_FINISHED)
8376 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8377 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8378 if (phba->sli_rev == LPFC_SLI_REV4)
8379 lpfc_issue_init_vfi(vport);
8381 lpfc_initial_flogi(vport);
8383 lpfc_initial_fdisc(vport);
8388 spin_lock_irq(shost->host_lock);
8389 vport->vpi_state |= LPFC_VPI_REGISTERED;
8390 spin_unlock_irq(shost->host_lock);
8391 if (vport == phba->pport) {
8392 if (phba->sli_rev < LPFC_SLI_REV4)
8393 lpfc_issue_fabric_reglogin(vport);
8396 * If the physical port is instantiated using
8397 * FDISC, do not start vport discovery.
8399 if (vport->port_state != LPFC_FDISC)
8400 lpfc_start_fdiscs(phba);
8401 lpfc_do_scr_ns_plogi(phba, vport);
8404 lpfc_do_scr_ns_plogi(phba, vport);
8407 /* Now, we decrement the ndlp reference count held for this
8412 mempool_free(pmb, phba->mbox_mem_pool);
8417 * lpfc_register_new_vport - Register a new vport with a HBA
8418 * @phba: pointer to lpfc hba data structure.
8419 * @vport: pointer to a host virtual N_Port data structure.
8420 * @ndlp: pointer to a node-list data structure.
8422 * This routine registers the @vport as a new virtual port with a HBA.
8423 * It is done through a registering vpi mailbox command.
8426 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8427 struct lpfc_nodelist *ndlp)
8429 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8432 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8434 lpfc_reg_vpi(vport, mbox);
8435 mbox->vport = vport;
8436 mbox->context2 = lpfc_nlp_get(ndlp);
8437 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
8438 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8439 == MBX_NOT_FINISHED) {
8440 /* mailbox command not success, decrement ndlp
8441 * reference count for this command
8444 mempool_free(mbox, phba->mbox_mem_pool);
8446 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8447 "0253 Register VPI: Can't send mbox\n");
8451 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8452 "0254 Register VPI: no memory\n");
8458 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8459 spin_lock_irq(shost->host_lock);
8460 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8461 spin_unlock_irq(shost->host_lock);
8466 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8467 * @phba: pointer to lpfc hba data structure.
8469 * This routine cancels the retry delay timers to all the vports.
8472 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
8474 struct lpfc_vport **vports;
8475 struct lpfc_nodelist *ndlp;
8476 uint32_t link_state;
8479 /* Treat this failure as linkdown for all vports */
8480 link_state = phba->link_state;
8481 lpfc_linkdown(phba);
8482 phba->link_state = link_state;
8484 vports = lpfc_create_vport_work_array(phba);
8487 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8488 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8490 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8491 lpfc_els_flush_cmd(vports[i]);
8493 lpfc_destroy_vport_work_array(phba, vports);
8498 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8499 * @phba: pointer to lpfc hba data structure.
8501 * This routine abort all pending discovery commands and
8502 * start a timer to retry FLOGI for the physical port
8506 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8508 struct lpfc_nodelist *ndlp;
8509 struct Scsi_Host *shost;
8511 /* Cancel the all vports retry delay retry timers */
8512 lpfc_cancel_all_vport_retry_delay_timer(phba);
8514 /* If fabric require FLOGI, then re-instantiate physical login */
8515 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8519 shost = lpfc_shost_from_vport(phba->pport);
8520 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
8521 spin_lock_irq(shost->host_lock);
8522 ndlp->nlp_flag |= NLP_DELAY_TMO;
8523 spin_unlock_irq(shost->host_lock);
8524 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8525 phba->pport->port_state = LPFC_FLOGI;
8530 * lpfc_fabric_login_reqd - Check if FLOGI required.
8531 * @phba: pointer to lpfc hba data structure.
8532 * @cmdiocb: pointer to FDISC command iocb.
8533 * @rspiocb: pointer to FDISC response iocb.
8535 * This routine checks if a FLOGI is reguired for FDISC
8539 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8540 struct lpfc_iocbq *cmdiocb,
8541 struct lpfc_iocbq *rspiocb)
8544 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8545 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8552 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8553 * @phba: pointer to lpfc hba data structure.
8554 * @cmdiocb: pointer to lpfc command iocb data structure.
8555 * @rspiocb: pointer to lpfc response iocb data structure.
8557 * This routine is the completion callback function to a Fabric Discover
8558 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8559 * single threaded, each FDISC completion callback function will reset
8560 * the discovery timer for all vports such that the timers will not get
8561 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8562 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8563 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8564 * assigned to the vport has been changed with the completion of the FDISC
8565 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8566 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8567 * routine is invoked to register new vport with the HBA. Otherwise, the
8568 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8569 * Server for State Change Request (SCR).
8572 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8573 struct lpfc_iocbq *rspiocb)
8575 struct lpfc_vport *vport = cmdiocb->vport;
8576 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8577 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8578 struct lpfc_nodelist *np;
8579 struct lpfc_nodelist *next_np;
8580 IOCB_t *irsp = &rspiocb->iocb;
8581 struct lpfc_iocbq *piocb;
8582 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8583 struct serv_parm *sp;
8584 uint8_t fabric_param_changed;
8586 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8587 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8588 irsp->ulpStatus, irsp->un.ulpWord[4],
8590 /* Since all FDISCs are being single threaded, we
8591 * must reset the discovery timer for ALL vports
8592 * waiting to send FDISC when one completes.
8594 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8595 lpfc_set_disctmo(piocb->vport);
8598 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8599 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8600 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8602 if (irsp->ulpStatus) {
8604 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8605 lpfc_retry_pport_discovery(phba);
8609 /* Check for retry */
8610 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8613 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8614 "0126 FDISC failed. (x%x/x%x)\n",
8615 irsp->ulpStatus, irsp->un.ulpWord[4]);
8618 spin_lock_irq(shost->host_lock);
8619 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
8620 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
8621 vport->fc_flag |= FC_FABRIC;
8622 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
8623 vport->fc_flag |= FC_PUBLIC_LOOP;
8624 spin_unlock_irq(shost->host_lock);
8626 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8627 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
8628 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
8631 sp = prsp->virt + sizeof(uint32_t);
8632 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8633 memcpy(&vport->fabric_portname, &sp->portName,
8634 sizeof(struct lpfc_name));
8635 memcpy(&vport->fabric_nodename, &sp->nodeName,
8636 sizeof(struct lpfc_name));
8637 if (fabric_param_changed &&
8638 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8639 /* If our NportID changed, we need to ensure all
8640 * remaining NPORTs get unreg_login'ed so we can
8643 list_for_each_entry_safe(np, next_np,
8644 &vport->fc_nodes, nlp_listp) {
8645 if (!NLP_CHK_NODE_ACT(ndlp) ||
8646 (np->nlp_state != NLP_STE_NPR_NODE) ||
8647 !(np->nlp_flag & NLP_NPR_ADISC))
8649 spin_lock_irq(shost->host_lock);
8650 np->nlp_flag &= ~NLP_NPR_ADISC;
8651 spin_unlock_irq(shost->host_lock);
8652 lpfc_unreg_rpi(vport, np);
8654 lpfc_cleanup_pending_mbox(vport);
8656 if (phba->sli_rev == LPFC_SLI_REV4)
8657 lpfc_sli4_unreg_all_rpis(vport);
8659 lpfc_mbx_unreg_vpi(vport);
8660 spin_lock_irq(shost->host_lock);
8661 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8662 if (phba->sli_rev == LPFC_SLI_REV4)
8663 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
8665 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
8666 spin_unlock_irq(shost->host_lock);
8667 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8668 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8670 * Driver needs to re-reg VPI in order for f/w
8671 * to update the MAC address.
8673 lpfc_register_new_vport(phba, vport, ndlp);
8677 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8678 lpfc_issue_init_vpi(vport);
8679 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
8680 lpfc_register_new_vport(phba, vport, ndlp);
8682 lpfc_do_scr_ns_plogi(phba, vport);
8685 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8686 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8687 /* Cancel discovery timer */
8688 lpfc_can_disctmo(vport);
8691 lpfc_els_free_iocb(phba, cmdiocb);
8695 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8696 * @vport: pointer to a virtual N_Port data structure.
8697 * @ndlp: pointer to a node-list data structure.
8698 * @retry: number of retries to the command IOCB.
8700 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8701 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8702 * routine to issue the IOCB, which makes sure only one outstanding fabric
8703 * IOCB will be sent off HBA at any given time.
8705 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8706 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8707 * will be stored into the context1 field of the IOCB for the completion
8708 * callback function to the FDISC ELS command.
8711 * 0 - Successfully issued fdisc iocb command
8712 * 1 - Failed to issue fdisc iocb command
8715 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8718 struct lpfc_hba *phba = vport->phba;
8720 struct lpfc_iocbq *elsiocb;
8721 struct serv_parm *sp;
8724 int did = ndlp->nlp_DID;
8727 vport->port_state = LPFC_FDISC;
8728 vport->fc_myDID = 0;
8729 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8730 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8733 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8734 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8735 "0255 Issue FDISC: no IOCB\n");
8739 icmd = &elsiocb->iocb;
8740 icmd->un.elsreq64.myID = 0;
8741 icmd->un.elsreq64.fl = 1;
8744 * SLI3 ports require a different context type value than SLI4.
8745 * Catch SLI3 ports here and override the prep.
8747 if (phba->sli_rev == LPFC_SLI_REV3) {
8752 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8753 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8754 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8755 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8756 sp = (struct serv_parm *) pcmd;
8757 /* Setup CSPs accordingly for Fabric */
8758 sp->cmn.e_d_tov = 0;
8759 sp->cmn.w2.r_a_tov = 0;
8760 sp->cmn.virtual_fabric_support = 0;
8761 sp->cls1.classValid = 0;
8762 sp->cls2.seqDelivery = 1;
8763 sp->cls3.seqDelivery = 1;
8765 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8766 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8767 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8768 pcmd += sizeof(uint32_t); /* Port Name */
8769 memcpy(pcmd, &vport->fc_portname, 8);
8770 pcmd += sizeof(uint32_t); /* Node Name */
8771 pcmd += sizeof(uint32_t); /* Node Name */
8772 memcpy(pcmd, &vport->fc_nodename, 8);
8774 lpfc_set_disctmo(vport);
8776 phba->fc_stat.elsXmitFDISC++;
8777 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8779 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8780 "Issue FDISC: did:x%x",
8783 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8784 if (rc == IOCB_ERROR) {
8785 lpfc_els_free_iocb(phba, elsiocb);
8786 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8787 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8788 "0256 Issue FDISC: Cannot send IOCB\n");
8791 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
8796 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8797 * @phba: pointer to lpfc hba data structure.
8798 * @cmdiocb: pointer to lpfc command iocb data structure.
8799 * @rspiocb: pointer to lpfc response iocb data structure.
8801 * This routine is the completion callback function to the issuing of a LOGO
8802 * ELS command off a vport. It frees the command IOCB and then decrement the
8803 * reference count held on ndlp for this completion function, indicating that
8804 * the reference to the ndlp is no long needed. Note that the
8805 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8806 * callback function and an additional explicit ndlp reference decrementation
8807 * will trigger the actual release of the ndlp.
8810 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8811 struct lpfc_iocbq *rspiocb)
8813 struct lpfc_vport *vport = cmdiocb->vport;
8815 struct lpfc_nodelist *ndlp;
8816 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8818 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
8819 irsp = &rspiocb->iocb;
8820 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8821 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8822 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
8824 lpfc_els_free_iocb(phba, cmdiocb);
8825 vport->unreg_vpi_cmpl = VPORT_ERROR;
8827 /* Trigger the release of the ndlp after logo */
8830 /* NPIV LOGO completes to NPort <nlp_DID> */
8831 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8832 "2928 NPIV LOGO completes to NPort x%x "
8833 "Data: x%x x%x x%x x%x\n",
8834 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8835 irsp->ulpTimeout, vport->num_disc_nodes);
8837 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8838 spin_lock_irq(shost->host_lock);
8839 vport->fc_flag &= ~FC_NDISC_ACTIVE;
8840 vport->fc_flag &= ~FC_FABRIC;
8841 spin_unlock_irq(shost->host_lock);
8842 lpfc_can_disctmo(vport);
8847 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8848 * @vport: pointer to a virtual N_Port data structure.
8849 * @ndlp: pointer to a node-list data structure.
8851 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8853 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8854 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8855 * will be stored into the context1 field of the IOCB for the completion
8856 * callback function to the LOGO ELS command.
8859 * 0 - Successfully issued logo off the @vport
8860 * 1 - Failed to issue logo off the @vport
8863 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8865 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8866 struct lpfc_hba *phba = vport->phba;
8867 struct lpfc_iocbq *elsiocb;
8871 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8872 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8877 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8878 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8879 pcmd += sizeof(uint32_t);
8881 /* Fill in LOGO payload */
8882 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8883 pcmd += sizeof(uint32_t);
8884 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8887 "Issue LOGO npiv did:x%x flg:x%x",
8888 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8890 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8891 spin_lock_irq(shost->host_lock);
8892 ndlp->nlp_flag |= NLP_LOGO_SND;
8893 spin_unlock_irq(shost->host_lock);
8894 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8896 spin_lock_irq(shost->host_lock);
8897 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8898 spin_unlock_irq(shost->host_lock);
8899 lpfc_els_free_iocb(phba, elsiocb);
8906 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
8907 * @ptr: holder for the timer function associated data.
8909 * This routine is invoked by the fabric iocb block timer after
8910 * timeout. It posts the fabric iocb block timeout event by setting the
8911 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8912 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8913 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8914 * posted event WORKER_FABRIC_BLOCK_TMO.
8917 lpfc_fabric_block_timeout(unsigned long ptr)
8919 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8920 unsigned long iflags;
8921 uint32_t tmo_posted;
8923 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8924 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8926 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8927 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8930 lpfc_worker_wake_up(phba);
8935 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
8936 * @phba: pointer to lpfc hba data structure.
8938 * This routine issues one fabric iocb from the driver internal list to
8939 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8940 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8941 * remove one pending fabric iocb from the driver internal list and invokes
8942 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8945 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8947 struct lpfc_iocbq *iocb;
8948 unsigned long iflags;
8954 spin_lock_irqsave(&phba->hbalock, iflags);
8955 /* Post any pending iocb to the SLI layer */
8956 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8957 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8960 /* Increment fabric iocb count to hold the position */
8961 atomic_inc(&phba->fabric_iocb_count);
8963 spin_unlock_irqrestore(&phba->hbalock, iflags);
8965 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8966 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8967 iocb->iocb_flag |= LPFC_IO_FABRIC;
8969 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8970 "Fabric sched1: ste:x%x",
8971 iocb->vport->port_state, 0, 0);
8973 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
8975 if (ret == IOCB_ERROR) {
8976 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8977 iocb->fabric_iocb_cmpl = NULL;
8978 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8980 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8981 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8982 iocb->iocb_cmpl(phba, iocb, iocb);
8984 atomic_dec(&phba->fabric_iocb_count);
8993 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
8994 * @phba: pointer to lpfc hba data structure.
8996 * This routine unblocks the issuing fabric iocb command. The function
8997 * will clear the fabric iocb block bit and then invoke the routine
8998 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8999 * from the driver internal fabric iocb list.
9002 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9004 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9006 lpfc_resume_fabric_iocbs(phba);
9011 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9012 * @phba: pointer to lpfc hba data structure.
9014 * This routine blocks the issuing fabric iocb for a specified amount of
9015 * time (currently 100 ms). This is done by set the fabric iocb block bit
9016 * and set up a timeout timer for 100ms. When the block bit is set, no more
9017 * fabric iocb will be issued out of the HBA.
9020 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9024 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9025 /* Start a timer to unblock fabric iocbs after 100ms */
9027 mod_timer(&phba->fabric_block_timer,
9028 jiffies + msecs_to_jiffies(100));
9034 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9035 * @phba: pointer to lpfc hba data structure.
9036 * @cmdiocb: pointer to lpfc command iocb data structure.
9037 * @rspiocb: pointer to lpfc response iocb data structure.
9039 * This routine is the callback function that is put to the fabric iocb's
9040 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9041 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9042 * function first restores and invokes the original iocb's callback function
9043 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9044 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9047 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9048 struct lpfc_iocbq *rspiocb)
9052 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9054 switch (rspiocb->iocb.ulpStatus) {
9055 case IOSTAT_NPORT_RJT:
9056 case IOSTAT_FABRIC_RJT:
9057 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9058 lpfc_block_fabric_iocbs(phba);
9062 case IOSTAT_NPORT_BSY:
9063 case IOSTAT_FABRIC_BSY:
9064 lpfc_block_fabric_iocbs(phba);
9068 stat.un.lsRjtError =
9069 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9070 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9071 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9072 lpfc_block_fabric_iocbs(phba);
9076 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9078 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9079 cmdiocb->fabric_iocb_cmpl = NULL;
9080 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9081 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9083 atomic_dec(&phba->fabric_iocb_count);
9084 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9085 /* Post any pending iocbs to HBA */
9086 lpfc_resume_fabric_iocbs(phba);
9091 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9092 * @phba: pointer to lpfc hba data structure.
9093 * @iocb: pointer to lpfc command iocb data structure.
9095 * This routine is used as the top-level API for issuing a fabric iocb command
9096 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9097 * function makes sure that only one fabric bound iocb will be outstanding at
9098 * any given time. As such, this function will first check to see whether there
9099 * is already an outstanding fabric iocb on the wire. If so, it will put the
9100 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9101 * issued later. Otherwise, it will issue the iocb on the wire and update the
9102 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9104 * Note, this implementation has a potential sending out fabric IOCBs out of
9105 * order. The problem is caused by the construction of the "ready" boolen does
9106 * not include the condition that the internal fabric IOCB list is empty. As
9107 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9108 * ahead of the fabric IOCBs in the internal list.
9111 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9112 * IOCB_ERROR - failed to issue fabric iocb
9115 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9117 unsigned long iflags;
9121 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9123 spin_lock_irqsave(&phba->hbalock, iflags);
9124 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9125 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9128 /* Increment fabric iocb count to hold the position */
9129 atomic_inc(&phba->fabric_iocb_count);
9130 spin_unlock_irqrestore(&phba->hbalock, iflags);
9132 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9133 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9134 iocb->iocb_flag |= LPFC_IO_FABRIC;
9136 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9137 "Fabric sched2: ste:x%x",
9138 iocb->vport->port_state, 0, 0);
9140 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9142 if (ret == IOCB_ERROR) {
9143 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9144 iocb->fabric_iocb_cmpl = NULL;
9145 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9146 atomic_dec(&phba->fabric_iocb_count);
9149 spin_lock_irqsave(&phba->hbalock, iflags);
9150 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9151 spin_unlock_irqrestore(&phba->hbalock, iflags);
9158 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9159 * @vport: pointer to a virtual N_Port data structure.
9161 * This routine aborts all the IOCBs associated with a @vport from the
9162 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9163 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9164 * list, removes each IOCB associated with the @vport off the list, set the
9165 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9166 * associated with the IOCB.
9168 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9170 LIST_HEAD(completions);
9171 struct lpfc_hba *phba = vport->phba;
9172 struct lpfc_iocbq *tmp_iocb, *piocb;
9174 spin_lock_irq(&phba->hbalock);
9175 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9178 if (piocb->vport != vport)
9181 list_move_tail(&piocb->list, &completions);
9183 spin_unlock_irq(&phba->hbalock);
9185 /* Cancel all the IOCBs from the completions list */
9186 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9191 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9192 * @ndlp: pointer to a node-list data structure.
9194 * This routine aborts all the IOCBs associated with an @ndlp from the
9195 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9196 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9197 * list, removes each IOCB associated with the @ndlp off the list, set the
9198 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9199 * associated with the IOCB.
9201 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9203 LIST_HEAD(completions);
9204 struct lpfc_hba *phba = ndlp->phba;
9205 struct lpfc_iocbq *tmp_iocb, *piocb;
9206 struct lpfc_sli_ring *pring;
9208 pring = lpfc_phba_elsring(phba);
9210 spin_lock_irq(&phba->hbalock);
9211 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9213 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9215 list_move_tail(&piocb->list, &completions);
9218 spin_unlock_irq(&phba->hbalock);
9220 /* Cancel all the IOCBs from the completions list */
9221 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9226 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9227 * @phba: pointer to lpfc hba data structure.
9229 * This routine aborts all the IOCBs currently on the driver internal
9230 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9231 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9232 * list, removes IOCBs off the list, set the status feild to
9233 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9236 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9238 LIST_HEAD(completions);
9240 spin_lock_irq(&phba->hbalock);
9241 list_splice_init(&phba->fabric_iocb_list, &completions);
9242 spin_unlock_irq(&phba->hbalock);
9244 /* Cancel all the IOCBs from the completions list */
9245 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9250 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9251 * @vport: pointer to lpfc vport data structure.
9253 * This routine is invoked by the vport cleanup for deletions and the cleanup
9254 * for an ndlp on removal.
9257 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9259 struct lpfc_hba *phba = vport->phba;
9260 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9261 unsigned long iflag = 0;
9263 spin_lock_irqsave(&phba->hbalock, iflag);
9264 spin_lock(&phba->sli4_hba.sgl_list_lock);
9265 list_for_each_entry_safe(sglq_entry, sglq_next,
9266 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9267 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9268 sglq_entry->ndlp = NULL;
9270 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9271 spin_unlock_irqrestore(&phba->hbalock, iflag);
9276 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9277 * @phba: pointer to lpfc hba data structure.
9278 * @axri: pointer to the els xri abort wcqe structure.
9280 * This routine is invoked by the worker thread to process a SLI4 slow-path
9284 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9285 struct sli4_wcqe_xri_aborted *axri)
9287 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9288 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9291 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9292 unsigned long iflag = 0;
9293 struct lpfc_nodelist *ndlp;
9294 struct lpfc_sli_ring *pring;
9296 pring = lpfc_phba_elsring(phba);
9298 spin_lock_irqsave(&phba->hbalock, iflag);
9299 spin_lock(&phba->sli4_hba.sgl_list_lock);
9300 list_for_each_entry_safe(sglq_entry, sglq_next,
9301 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9302 if (sglq_entry->sli4_xritag == xri) {
9303 list_del(&sglq_entry->list);
9304 ndlp = sglq_entry->ndlp;
9305 sglq_entry->ndlp = NULL;
9306 list_add_tail(&sglq_entry->list,
9307 &phba->sli4_hba.lpfc_els_sgl_list);
9308 sglq_entry->state = SGL_FREED;
9309 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9310 spin_unlock_irqrestore(&phba->hbalock, iflag);
9311 lpfc_set_rrq_active(phba, ndlp,
9312 sglq_entry->sli4_lxritag,
9315 /* Check if TXQ queue needs to be serviced */
9316 if (!(list_empty(&pring->txq)))
9317 lpfc_worker_wake_up(phba);
9321 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9322 lxri = lpfc_sli4_xri_inrange(phba, xri);
9323 if (lxri == NO_XRI) {
9324 spin_unlock_irqrestore(&phba->hbalock, iflag);
9327 spin_lock(&phba->sli4_hba.sgl_list_lock);
9328 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9329 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9330 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9331 spin_unlock_irqrestore(&phba->hbalock, iflag);
9334 sglq_entry->state = SGL_XRI_ABORTED;
9335 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9336 spin_unlock_irqrestore(&phba->hbalock, iflag);
9340 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9341 * @vport: pointer to virtual port object.
9342 * @ndlp: nodelist pointer for the impacted node.
9344 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9345 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9346 * the driver is required to send a LOGO to the remote node before it
9347 * attempts to recover its login to the remote node.
9350 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9351 struct lpfc_nodelist *ndlp)
9353 struct Scsi_Host *shost;
9354 struct lpfc_hba *phba;
9355 unsigned long flags = 0;
9357 shost = lpfc_shost_from_vport(vport);
9359 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9360 lpfc_printf_log(phba, KERN_INFO,
9361 LOG_SLI, "3093 No rport recovery needed. "
9362 "rport in state 0x%x\n", ndlp->nlp_state);
9365 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9366 "3094 Start rport recovery on shost id 0x%x "
9367 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9369 shost->host_no, ndlp->nlp_DID,
9370 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9373 * The rport is not responding. Remove the FCP-2 flag to prevent
9374 * an ADISC in the follow-up recovery code.
9376 spin_lock_irqsave(shost->host_lock, flags);
9377 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9378 spin_unlock_irqrestore(shost->host_lock, flags);
9379 lpfc_issue_els_logo(vport, ndlp, 0);
9380 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);