1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. 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>
28 #include <linux/delay.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <uapi/scsi/fc/fc_fs.h>
35 #include <uapi/scsi/fc/fc_els.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_debugfs.h"
50 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
52 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
54 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
55 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
56 struct lpfc_nodelist *ndlp, uint8_t retry);
57 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
58 struct lpfc_iocbq *iocb);
59 static void lpfc_cmpl_els_edc(struct lpfc_hba *phba,
60 struct lpfc_iocbq *cmdiocb,
61 struct lpfc_iocbq *rspiocb);
62 static void lpfc_cmpl_els_uvem(struct lpfc_hba *, struct lpfc_iocbq *,
65 static int lpfc_max_els_tries = 3;
67 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport);
68 static void lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max);
69 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid);
72 * lpfc_els_chk_latt - Check host link attention event for a vport
73 * @vport: pointer to a host virtual N_Port data structure.
75 * This routine checks whether there is an outstanding host link
76 * attention event during the discovery process with the @vport. It is done
77 * by reading the HBA's Host Attention (HA) register. If there is any host
78 * link attention events during this @vport's discovery process, the @vport
79 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
80 * be issued if the link state is not already in host link cleared state,
81 * and a return code shall indicate whether the host link attention event
84 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
85 * state in LPFC_VPORT_READY, the request for checking host link attention
86 * event will be ignored and a return code shall indicate no host link
87 * attention event had happened.
90 * 0 - no host link attention event happened
91 * 1 - host link attention event happened
94 lpfc_els_chk_latt(struct lpfc_vport *vport)
96 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
97 struct lpfc_hba *phba = vport->phba;
100 if (vport->port_state >= LPFC_VPORT_READY ||
101 phba->link_state == LPFC_LINK_DOWN ||
102 phba->sli_rev > LPFC_SLI_REV3)
105 /* Read the HBA Host Attention Register */
106 if (lpfc_readl(phba->HAregaddr, &ha_copy))
109 if (!(ha_copy & HA_LATT))
112 /* Pending Link Event during Discovery */
113 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
114 "0237 Pending Link Event during "
115 "Discovery: State x%x\n",
116 phba->pport->port_state);
118 /* CLEAR_LA should re-enable link attention events and
119 * we should then immediately take a LATT event. The
120 * LATT processing should call lpfc_linkdown() which
121 * will cleanup any left over in-progress discovery
124 spin_lock_irq(shost->host_lock);
125 vport->fc_flag |= FC_ABORT_DISCOVERY;
126 spin_unlock_irq(shost->host_lock);
128 if (phba->link_state != LPFC_CLEAR_LA)
129 lpfc_issue_clear_la(phba, vport);
135 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
136 * @vport: pointer to a host virtual N_Port data structure.
137 * @expect_rsp: flag indicating whether response is expected.
138 * @cmd_size: size of the ELS command.
139 * @retry: number of retries to the command when it fails.
140 * @ndlp: pointer to a node-list data structure.
141 * @did: destination identifier.
142 * @elscmd: the ELS command code.
144 * This routine is used for allocating a lpfc-IOCB data structure from
145 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
146 * passed into the routine for discovery state machine to issue an Extended
147 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
148 * and preparation routine that is used by all the discovery state machine
149 * routines and the ELS command-specific fields will be later set up by
150 * the individual discovery machine routines after calling this routine
151 * allocating and preparing a generic IOCB data structure. It fills in the
152 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
153 * payload and response payload (if expected). The reference count on the
154 * ndlp is incremented by 1 and the reference to the ndlp is put into
155 * context1 of the IOCB data structure for this IOCB to hold the ndlp
156 * reference for the command's callback function to access later.
159 * Pointer to the newly allocated/prepared els iocb data structure
160 * NULL - when els iocb data structure allocation/preparation failed
163 lpfc_prep_els_iocb(struct lpfc_vport *vport, u8 expect_rsp,
164 u16 cmd_size, u8 retry,
165 struct lpfc_nodelist *ndlp, u32 did,
168 struct lpfc_hba *phba = vport->phba;
169 struct lpfc_iocbq *elsiocb;
170 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist, *bmp;
171 struct ulp_bde64_le *bpl;
174 if (!lpfc_is_link_up(phba))
177 /* Allocate buffer for command iocb */
178 elsiocb = lpfc_sli_get_iocbq(phba);
183 * If this command is for fabric controller and HBA running
184 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
186 if ((did == Fabric_DID) &&
187 (phba->hba_flag & HBA_FIP_SUPPORT) &&
188 ((elscmd == ELS_CMD_FLOGI) ||
189 (elscmd == ELS_CMD_FDISC) ||
190 (elscmd == ELS_CMD_LOGO)))
194 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
195 & LPFC_FIP_ELS_ID_MASK);
199 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
200 & LPFC_FIP_ELS_ID_MASK);
204 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
205 & LPFC_FIP_ELS_ID_MASK);
209 elsiocb->cmd_flag &= ~LPFC_FIP_ELS_ID_MASK;
211 /* fill in BDEs for command */
212 /* Allocate buffer for command payload */
213 pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL);
215 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
216 if (!pcmd || !pcmd->virt)
217 goto els_iocb_free_pcmb_exit;
219 INIT_LIST_HEAD(&pcmd->list);
221 /* Allocate buffer for response payload */
223 prsp = kmalloc(sizeof(*prsp), GFP_KERNEL);
225 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 if (!prsp || !prsp->virt)
228 goto els_iocb_free_prsp_exit;
229 INIT_LIST_HEAD(&prsp->list);
234 /* Allocate buffer for Buffer ptr list */
235 pbuflist = kmalloc(sizeof(*pbuflist), GFP_KERNEL);
237 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
239 if (!pbuflist || !pbuflist->virt)
240 goto els_iocb_free_pbuf_exit;
242 INIT_LIST_HEAD(&pbuflist->list);
247 timeout = FF_DEF_RATOV * 2;
250 timeout = phba->fc_ratov;
253 timeout = phba->fc_ratov * 2;
256 /* Fill SGE for the num bde count */
257 elsiocb->num_bdes = 2;
260 if (phba->sli_rev == LPFC_SLI_REV4)
265 lpfc_sli_prep_els_req_rsp(phba, elsiocb, vport, bmp, cmd_size, did,
266 elscmd, timeout, expect_rsp);
268 bpl = (struct ulp_bde64_le *)pbuflist->virt;
269 bpl->addr_low = cpu_to_le32(putPaddrLow(pcmd->phys));
270 bpl->addr_high = cpu_to_le32(putPaddrHigh(pcmd->phys));
271 bpl->type_size = cpu_to_le32(cmd_size);
272 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
276 bpl->addr_low = cpu_to_le32(putPaddrLow(prsp->phys));
277 bpl->addr_high = cpu_to_le32(putPaddrHigh(prsp->phys));
278 bpl->type_size = cpu_to_le32(FCELSSIZE);
279 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
282 elsiocb->context2 = pcmd;
283 elsiocb->context3 = pbuflist;
284 elsiocb->retry = retry;
285 elsiocb->vport = vport;
286 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
289 list_add(&prsp->list, &pcmd->list);
291 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
293 "0116 Xmit ELS command x%x to remote "
294 "NPORT x%x I/O tag: x%x, port state:x%x "
295 "rpi x%x fc_flag:x%x\n",
296 elscmd, did, elsiocb->iotag,
297 vport->port_state, ndlp->nlp_rpi,
300 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
301 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
302 "0117 Xmit ELS response x%x to remote "
303 "NPORT x%x I/O tag: x%x, size: x%x "
304 "port_state x%x rpi x%x fc_flag x%x\n",
305 elscmd, ndlp->nlp_DID, elsiocb->iotag,
306 cmd_size, vport->port_state,
307 ndlp->nlp_rpi, vport->fc_flag);
312 els_iocb_free_pbuf_exit:
314 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
317 els_iocb_free_prsp_exit:
318 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
321 els_iocb_free_pcmb_exit:
323 lpfc_sli_release_iocbq(phba, elsiocb);
328 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
329 * @vport: pointer to a host virtual N_Port data structure.
331 * This routine issues a fabric registration login for a @vport. An
332 * active ndlp node with Fabric_DID must already exist for this @vport.
333 * The routine invokes two mailbox commands to carry out fabric registration
334 * login through the HBA firmware: the first mailbox command requests the
335 * HBA to perform link configuration for the @vport; and the second mailbox
336 * command requests the HBA to perform the actual fabric registration login
340 * 0 - successfully issued fabric registration login for @vport
341 * -ENXIO -- failed to issue fabric registration login for @vport
344 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
346 struct lpfc_hba *phba = vport->phba;
348 struct lpfc_dmabuf *mp;
349 struct lpfc_nodelist *ndlp;
350 struct serv_parm *sp;
354 sp = &phba->fc_fabparam;
355 ndlp = lpfc_findnode_did(vport, Fabric_DID);
361 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
367 vport->port_state = LPFC_FABRIC_CFG_LINK;
368 lpfc_config_link(phba, mbox);
369 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
372 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
373 if (rc == MBX_NOT_FINISHED) {
378 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
383 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
390 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
392 /* increment the reference count on ndlp to hold reference
393 * for the callback routine.
395 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
396 if (!mbox->ctx_ndlp) {
401 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
402 if (rc == MBX_NOT_FINISHED) {
404 goto fail_issue_reg_login;
409 fail_issue_reg_login:
410 /* decrement the reference count on ndlp just incremented
411 * for the failed mbox command.
415 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
416 lpfc_mbuf_free(phba, mp->virt, mp->phys);
419 mempool_free(mbox, phba->mbox_mem_pool);
422 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
423 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
424 "0249 Cannot issue Register Fabric login: Err %d\n",
430 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
431 * @vport: pointer to a host virtual N_Port data structure.
433 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
434 * the @vport. This mailbox command is necessary for SLI4 port only.
437 * 0 - successfully issued REG_VFI for @vport
438 * A failure code otherwise.
441 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
443 struct lpfc_hba *phba = vport->phba;
444 LPFC_MBOXQ_t *mboxq = NULL;
445 struct lpfc_nodelist *ndlp;
446 struct lpfc_dmabuf *dmabuf = NULL;
449 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
450 if ((phba->sli_rev == LPFC_SLI_REV4) &&
451 !(phba->link_flag & LS_LOOPBACK_MODE) &&
452 !(vport->fc_flag & FC_PT2PT)) {
453 ndlp = lpfc_findnode_did(vport, Fabric_DID);
460 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
466 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
467 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
468 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
473 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
478 memcpy(dmabuf->virt, &phba->fc_fabparam,
479 sizeof(struct serv_parm));
482 vport->port_state = LPFC_FABRIC_CFG_LINK;
484 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
486 lpfc_reg_vfi(mboxq, vport, 0);
488 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
489 mboxq->vport = vport;
490 mboxq->ctx_buf = dmabuf;
491 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
492 if (rc == MBX_NOT_FINISHED) {
500 mempool_free(mboxq, phba->mbox_mem_pool);
503 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
507 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
508 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
509 "0289 Issue Register VFI failed: Err %d\n", rc);
514 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
515 * @vport: pointer to a host virtual N_Port data structure.
517 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
518 * the @vport. This mailbox command is necessary for SLI4 port only.
521 * 0 - successfully issued REG_VFI for @vport
522 * A failure code otherwise.
525 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
527 struct lpfc_hba *phba = vport->phba;
528 struct Scsi_Host *shost;
532 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
534 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
535 "2556 UNREG_VFI mbox allocation failed"
536 "HBA state x%x\n", phba->pport->port_state);
540 lpfc_unreg_vfi(mboxq, vport);
541 mboxq->vport = vport;
542 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
544 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
545 if (rc == MBX_NOT_FINISHED) {
546 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
547 "2557 UNREG_VFI issue mbox failed rc x%x "
549 rc, phba->pport->port_state);
550 mempool_free(mboxq, phba->mbox_mem_pool);
554 shost = lpfc_shost_from_vport(vport);
555 spin_lock_irq(shost->host_lock);
556 vport->fc_flag &= ~FC_VFI_REGISTERED;
557 spin_unlock_irq(shost->host_lock);
562 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
563 * @vport: pointer to a host virtual N_Port data structure.
564 * @sp: pointer to service parameter data structure.
566 * This routine is called from FLOGI/FDISC completion handler functions.
567 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
568 * node nodename is changed in the completion service parameter else return
569 * 0. This function also set flag in the vport data structure to delay
570 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
571 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
572 * node nodename is changed in the completion service parameter.
575 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
576 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
580 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
581 struct serv_parm *sp)
583 struct lpfc_hba *phba = vport->phba;
584 uint8_t fabric_param_changed = 0;
585 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
587 if ((vport->fc_prevDID != vport->fc_myDID) ||
588 memcmp(&vport->fabric_portname, &sp->portName,
589 sizeof(struct lpfc_name)) ||
590 memcmp(&vport->fabric_nodename, &sp->nodeName,
591 sizeof(struct lpfc_name)) ||
592 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
593 fabric_param_changed = 1;
594 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
597 * Word 1 Bit 31 in common service parameter is overloaded.
598 * Word 1 Bit 31 in FLOGI request is multiple NPort request
599 * Word 1 Bit 31 in FLOGI response is clean address bit
601 * If fabric parameter is changed and clean address bit is
602 * cleared delay nport discovery if
603 * - vport->fc_prevDID != 0 (not initial discovery) OR
604 * - lpfc_delay_discovery module parameter is set.
606 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
607 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
608 spin_lock_irq(shost->host_lock);
609 vport->fc_flag |= FC_DISC_DELAYED;
610 spin_unlock_irq(shost->host_lock);
613 return fabric_param_changed;
618 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
619 * @vport: pointer to a host virtual N_Port data structure.
620 * @ndlp: pointer to a node-list data structure.
621 * @sp: pointer to service parameter data structure.
622 * @ulp_word4: command response value
624 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
625 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
626 * port in a fabric topology. It properly sets up the parameters to the @ndlp
627 * from the IOCB response. It also check the newly assigned N_Port ID to the
628 * @vport against the previously assigned N_Port ID. If it is different from
629 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
630 * is invoked on all the remaining nodes with the @vport to unregister the
631 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
632 * is invoked to register login to the fabric.
635 * 0 - Success (currently, always return 0)
638 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
639 struct serv_parm *sp, uint32_t ulp_word4)
641 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
642 struct lpfc_hba *phba = vport->phba;
643 struct lpfc_nodelist *np;
644 struct lpfc_nodelist *next_np;
645 uint8_t fabric_param_changed;
647 spin_lock_irq(shost->host_lock);
648 vport->fc_flag |= FC_FABRIC;
649 spin_unlock_irq(shost->host_lock);
651 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
652 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
653 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
655 phba->fc_edtovResol = sp->cmn.edtovResolution;
656 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
658 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
659 spin_lock_irq(shost->host_lock);
660 vport->fc_flag |= FC_PUBLIC_LOOP;
661 spin_unlock_irq(shost->host_lock);
664 vport->fc_myDID = ulp_word4 & Mask_DID;
665 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
666 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
667 ndlp->nlp_class_sup = 0;
668 if (sp->cls1.classValid)
669 ndlp->nlp_class_sup |= FC_COS_CLASS1;
670 if (sp->cls2.classValid)
671 ndlp->nlp_class_sup |= FC_COS_CLASS2;
672 if (sp->cls3.classValid)
673 ndlp->nlp_class_sup |= FC_COS_CLASS3;
674 if (sp->cls4.classValid)
675 ndlp->nlp_class_sup |= FC_COS_CLASS4;
676 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
677 sp->cmn.bbRcvSizeLsb;
679 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
680 if (fabric_param_changed) {
681 /* Reset FDMI attribute masks based on config parameter */
682 if (phba->cfg_enable_SmartSAN ||
683 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
684 /* Setup appropriate attribute masks */
685 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
686 if (phba->cfg_enable_SmartSAN)
687 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
689 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
691 vport->fdmi_hba_mask = 0;
692 vport->fdmi_port_mask = 0;
696 memcpy(&vport->fabric_portname, &sp->portName,
697 sizeof(struct lpfc_name));
698 memcpy(&vport->fabric_nodename, &sp->nodeName,
699 sizeof(struct lpfc_name));
700 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
702 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
703 if (sp->cmn.response_multiple_NPort) {
704 lpfc_printf_vlog(vport, KERN_WARNING,
706 "1816 FLOGI NPIV supported, "
707 "response data 0x%x\n",
708 sp->cmn.response_multiple_NPort);
709 spin_lock_irq(&phba->hbalock);
710 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
711 spin_unlock_irq(&phba->hbalock);
713 /* Because we asked f/w for NPIV it still expects us
714 to call reg_vnpid at least for the physical host */
715 lpfc_printf_vlog(vport, KERN_WARNING,
717 "1817 Fabric does not support NPIV "
718 "- configuring single port mode.\n");
719 spin_lock_irq(&phba->hbalock);
720 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
721 spin_unlock_irq(&phba->hbalock);
726 * For FC we need to do some special processing because of the SLI
727 * Port's default settings of the Common Service Parameters.
729 if ((phba->sli_rev == LPFC_SLI_REV4) &&
730 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
731 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
732 if (fabric_param_changed)
733 lpfc_unregister_fcf_prep(phba);
735 /* This should just update the VFI CSPs*/
736 if (vport->fc_flag & FC_VFI_REGISTERED)
737 lpfc_issue_reg_vfi(vport);
740 if (fabric_param_changed &&
741 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
743 /* If our NportID changed, we need to ensure all
744 * remaining NPORTs get unreg_login'ed.
746 list_for_each_entry_safe(np, next_np,
747 &vport->fc_nodes, nlp_listp) {
748 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
749 !(np->nlp_flag & NLP_NPR_ADISC))
751 spin_lock_irq(&np->lock);
752 np->nlp_flag &= ~NLP_NPR_ADISC;
753 spin_unlock_irq(&np->lock);
754 lpfc_unreg_rpi(vport, np);
756 lpfc_cleanup_pending_mbox(vport);
758 if (phba->sli_rev == LPFC_SLI_REV4) {
759 lpfc_sli4_unreg_all_rpis(vport);
760 lpfc_mbx_unreg_vpi(vport);
761 spin_lock_irq(shost->host_lock);
762 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
763 spin_unlock_irq(shost->host_lock);
767 * For SLI3 and SLI4, the VPI needs to be reregistered in
768 * response to this fabric parameter change event.
770 spin_lock_irq(shost->host_lock);
771 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
772 spin_unlock_irq(shost->host_lock);
773 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
774 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
776 * Driver needs to re-reg VPI in order for f/w
777 * to update the MAC address.
779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
780 lpfc_register_new_vport(phba, vport, ndlp);
784 if (phba->sli_rev < LPFC_SLI_REV4) {
785 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
786 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
787 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
788 lpfc_register_new_vport(phba, vport, ndlp);
790 lpfc_issue_fabric_reglogin(vport);
792 ndlp->nlp_type |= NLP_FABRIC;
793 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
794 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
795 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
796 lpfc_start_fdiscs(phba);
797 lpfc_do_scr_ns_plogi(phba, vport);
798 } else if (vport->fc_flag & FC_VFI_REGISTERED)
799 lpfc_issue_init_vpi(vport);
801 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
802 "3135 Need register VFI: (x%x/%x)\n",
803 vport->fc_prevDID, vport->fc_myDID);
804 lpfc_issue_reg_vfi(vport);
811 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
812 * @vport: pointer to a host virtual N_Port data structure.
813 * @ndlp: pointer to a node-list data structure.
814 * @sp: pointer to service parameter data structure.
816 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
817 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
818 * in a point-to-point topology. First, the @vport's N_Port Name is compared
819 * with the received N_Port Name: if the @vport's N_Port Name is greater than
820 * the received N_Port Name lexicographically, this node shall assign local
821 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
822 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
823 * this node shall just wait for the remote node to issue PLOGI and assign
831 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
832 struct serv_parm *sp)
834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
835 struct lpfc_hba *phba = vport->phba;
839 spin_lock_irq(shost->host_lock);
840 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
841 vport->fc_flag |= FC_PT2PT;
842 spin_unlock_irq(shost->host_lock);
844 /* If we are pt2pt with another NPort, force NPIV off! */
845 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
847 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
848 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
849 lpfc_unregister_fcf_prep(phba);
851 spin_lock_irq(shost->host_lock);
852 vport->fc_flag &= ~FC_VFI_REGISTERED;
853 spin_unlock_irq(shost->host_lock);
854 phba->fc_topology_changed = 0;
857 rc = memcmp(&vport->fc_portname, &sp->portName,
858 sizeof(vport->fc_portname));
861 /* This side will initiate the PLOGI */
862 spin_lock_irq(shost->host_lock);
863 vport->fc_flag |= FC_PT2PT_PLOGI;
864 spin_unlock_irq(shost->host_lock);
867 * N_Port ID cannot be 0, set our Id to LocalID
868 * the other side will be RemoteID.
873 vport->fc_myDID = PT2PT_LocalID;
875 /* If not registered with a transport, decrement ndlp reference
876 * count indicating that ndlp can be safely released when other
877 * references are removed.
879 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
882 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
885 * Cannot find existing Fabric ndlp, so allocate a
888 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
893 memcpy(&ndlp->nlp_portname, &sp->portName,
894 sizeof(struct lpfc_name));
895 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
896 sizeof(struct lpfc_name));
897 /* Set state will put ndlp onto node list if not already done */
898 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
899 spin_lock_irq(&ndlp->lock);
900 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
901 spin_unlock_irq(&ndlp->lock);
903 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
907 lpfc_config_link(phba, mbox);
909 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
911 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
912 if (rc == MBX_NOT_FINISHED) {
913 mempool_free(mbox, phba->mbox_mem_pool);
917 /* This side will wait for the PLOGI. If not registered with
918 * a transport, decrement node reference count indicating that
919 * ndlp can be released when other references are removed.
921 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
924 /* Start discovery - this should just do CLEAR_LA */
925 lpfc_disc_start(vport);
934 * lpfc_cmpl_els_flogi - Completion callback function for flogi
935 * @phba: pointer to lpfc hba data structure.
936 * @cmdiocb: pointer to lpfc command iocb data structure.
937 * @rspiocb: pointer to lpfc response iocb data structure.
939 * This routine is the top-level completion callback function for issuing
940 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
941 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
942 * retry has been made (either immediately or delayed with lpfc_els_retry()
943 * returning 1), the command IOCB will be released and function returned.
944 * If the retry attempt has been given up (possibly reach the maximum
945 * number of retries), one additional decrement of ndlp reference shall be
946 * invoked before going out after releasing the command IOCB. This will
947 * actually release the remote node (Note, lpfc_els_free_iocb() will also
948 * invoke one decrement of ndlp reference count). If no error reported in
949 * the IOCB status, the command Port ID field is used to determine whether
950 * this is a point-to-point topology or a fabric topology: if the Port ID
951 * field is assigned, it is a fabric topology; otherwise, it is a
952 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
953 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
954 * specific topology completion conditions.
957 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
958 struct lpfc_iocbq *rspiocb)
960 struct lpfc_vport *vport = cmdiocb->vport;
961 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
962 struct lpfc_nodelist *ndlp = cmdiocb->context1;
964 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
965 struct serv_parm *sp;
968 u32 ulp_status, ulp_word4, tmo;
970 /* Check to see if link went down during discovery */
971 if (lpfc_els_chk_latt(vport)) {
972 /* One additional decrement on node reference count to
973 * trigger the release of the node
975 if (!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD))
980 ulp_status = get_job_ulpstatus(phba, rspiocb);
981 ulp_word4 = get_job_word4(phba, rspiocb);
983 if (phba->sli_rev == LPFC_SLI_REV4) {
984 tmo = get_wqe_tmo(cmdiocb);
986 irsp = &rspiocb->iocb;
987 tmo = irsp->ulpTimeout;
990 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
991 "FLOGI cmpl: status:x%x/x%x state:x%x",
992 ulp_status, ulp_word4,
997 * In case of FIP mode, perform roundrobin FCF failover
998 * due to new FCF discovery
1000 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1001 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1002 if (phba->link_state < LPFC_LINK_UP)
1003 goto stop_rr_fcf_flogi;
1004 if ((phba->fcoe_cvl_eventtag_attn ==
1005 phba->fcoe_cvl_eventtag) &&
1006 (ulp_status == IOSTAT_LOCAL_REJECT) &&
1007 ((ulp_word4 & IOERR_PARAM_MASK) ==
1009 goto stop_rr_fcf_flogi;
1011 phba->fcoe_cvl_eventtag_attn =
1012 phba->fcoe_cvl_eventtag;
1013 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1014 "2611 FLOGI failed on FCF (x%x), "
1015 "status:x%x/x%x, tmo:x%x, perform "
1016 "roundrobin FCF failover\n",
1017 phba->fcf.current_rec.fcf_indx,
1018 ulp_status, ulp_word4, tmo);
1019 lpfc_sli4_set_fcf_flogi_fail(phba,
1020 phba->fcf.current_rec.fcf_indx);
1021 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1022 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1029 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
1030 ((ulp_word4 & IOERR_PARAM_MASK) ==
1031 IOERR_LOOP_OPEN_FAILURE)))
1032 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1033 "2858 FLOGI failure Status:x%x/x%x TMO"
1034 ":x%x Data x%x x%x\n",
1035 ulp_status, ulp_word4, tmo,
1036 phba->hba_flag, phba->fcf.fcf_flag);
1038 /* Check for retry */
1039 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1042 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1043 "0150 FLOGI failure Status:x%x/x%x "
1044 "xri x%x TMO:x%x refcnt %d\n",
1045 ulp_status, ulp_word4, cmdiocb->sli4_xritag,
1046 tmo, kref_read(&ndlp->kref));
1048 /* If this is not a loop open failure, bail out */
1049 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
1050 ((ulp_word4 & IOERR_PARAM_MASK) ==
1051 IOERR_LOOP_OPEN_FAILURE))) {
1053 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1054 "0100 FLOGI failure Status:x%x/x%x "
1056 ulp_status, ulp_word4, tmo);
1060 /* FLOGI failed, so there is no fabric */
1061 spin_lock_irq(shost->host_lock);
1062 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP |
1064 spin_unlock_irq(shost->host_lock);
1066 /* If private loop, then allow max outstanding els to be
1067 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1068 * alpa map would take too long otherwise.
1070 if (phba->alpa_map[0] == 0)
1071 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1072 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1073 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1074 (vport->fc_prevDID != vport->fc_myDID) ||
1075 phba->fc_topology_changed)) {
1076 if (vport->fc_flag & FC_VFI_REGISTERED) {
1077 if (phba->fc_topology_changed) {
1078 lpfc_unregister_fcf_prep(phba);
1079 spin_lock_irq(shost->host_lock);
1080 vport->fc_flag &= ~FC_VFI_REGISTERED;
1081 spin_unlock_irq(shost->host_lock);
1082 phba->fc_topology_changed = 0;
1084 lpfc_sli4_unreg_all_rpis(vport);
1088 /* Do not register VFI if the driver aborted FLOGI */
1089 if (!lpfc_error_lost_link(ulp_status, ulp_word4))
1090 lpfc_issue_reg_vfi(vport);
1097 spin_lock_irq(shost->host_lock);
1098 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1099 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1100 spin_unlock_irq(shost->host_lock);
1103 * The FLogI succeeded. Sync the data for the CPU before
1106 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1109 sp = prsp->virt + sizeof(uint32_t);
1111 /* FLOGI completes successfully */
1112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1113 "0101 FLOGI completes successfully, I/O tag:x%x "
1114 "xri x%x Data: x%x x%x x%x x%x x%x x%x x%x %d\n",
1115 cmdiocb->iotag, cmdiocb->sli4_xritag,
1116 ulp_word4, sp->cmn.e_d_tov,
1117 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1118 vport->port_state, vport->fc_flag,
1119 sp->cmn.priority_tagging, kref_read(&ndlp->kref));
1121 if (sp->cmn.priority_tagging)
1122 vport->vmid_flag |= LPFC_VMID_ISSUE_QFPA;
1124 if (vport->port_state == LPFC_FLOGI) {
1126 * If Common Service Parameters indicate Nport
1127 * we are point to point, if Fport we are Fabric.
1130 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp,
1132 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1133 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1135 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1136 "2831 FLOGI response with cleared Fabric "
1137 "bit fcf_index 0x%x "
1138 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1140 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1141 phba->fcf.current_rec.fcf_indx,
1142 phba->fcf.current_rec.switch_name[0],
1143 phba->fcf.current_rec.switch_name[1],
1144 phba->fcf.current_rec.switch_name[2],
1145 phba->fcf.current_rec.switch_name[3],
1146 phba->fcf.current_rec.switch_name[4],
1147 phba->fcf.current_rec.switch_name[5],
1148 phba->fcf.current_rec.switch_name[6],
1149 phba->fcf.current_rec.switch_name[7],
1150 phba->fcf.current_rec.fabric_name[0],
1151 phba->fcf.current_rec.fabric_name[1],
1152 phba->fcf.current_rec.fabric_name[2],
1153 phba->fcf.current_rec.fabric_name[3],
1154 phba->fcf.current_rec.fabric_name[4],
1155 phba->fcf.current_rec.fabric_name[5],
1156 phba->fcf.current_rec.fabric_name[6],
1157 phba->fcf.current_rec.fabric_name[7]);
1160 spin_lock_irq(&phba->hbalock);
1161 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1162 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1163 spin_unlock_irq(&phba->hbalock);
1164 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1168 /* Mark the FCF discovery process done */
1169 if (phba->hba_flag & HBA_FIP_SUPPORT)
1170 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1172 "2769 FLOGI to FCF (x%x) "
1173 "completed successfully\n",
1174 phba->fcf.current_rec.fcf_indx);
1175 spin_lock_irq(&phba->hbalock);
1176 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1177 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1178 spin_unlock_irq(&phba->hbalock);
1179 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1182 } else if (vport->port_state > LPFC_FLOGI &&
1183 vport->fc_flag & FC_PT2PT) {
1185 * In a p2p topology, it is possible that discovery has
1186 * already progressed, and this completion can be ignored.
1187 * Recheck the indicated topology.
1194 spin_lock_irq(&phba->hbalock);
1195 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1196 spin_unlock_irq(&phba->hbalock);
1198 if (!lpfc_error_lost_link(ulp_status, ulp_word4)) {
1199 /* FLOGI failed, so just use loop map to make discovery list */
1200 lpfc_disc_list_loopmap(vport);
1202 /* Start discovery */
1203 lpfc_disc_start(vport);
1204 } else if (((ulp_status != IOSTAT_LOCAL_REJECT) ||
1205 (((ulp_word4 & IOERR_PARAM_MASK) !=
1206 IOERR_SLI_ABORTED) &&
1207 ((ulp_word4 & IOERR_PARAM_MASK) !=
1208 IOERR_SLI_DOWN))) &&
1209 (phba->link_state != LPFC_CLEAR_LA)) {
1210 /* If FLOGI failed enable link interrupt. */
1211 lpfc_issue_clear_la(phba, vport);
1214 phba->hba_flag &= ~HBA_FLOGI_OUTSTANDING;
1215 lpfc_els_free_iocb(phba, cmdiocb);
1220 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1221 * aborted during a link down
1222 * @phba: pointer to lpfc hba data structure.
1223 * @cmdiocb: pointer to lpfc command iocb data structure.
1224 * @rspiocb: pointer to lpfc response iocb data structure.
1228 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1229 struct lpfc_iocbq *rspiocb)
1233 u32 ulp_status, ulp_word4;
1235 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1238 ulp_status = get_job_ulpstatus(phba, rspiocb);
1239 ulp_word4 = get_job_word4(phba, rspiocb);
1241 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1242 "6445 ELS completes after LINK_DOWN: "
1243 " Status %x/%x cmd x%x flg x%x\n",
1244 ulp_status, ulp_word4, cmd,
1247 if (cmdiocb->cmd_flag & LPFC_IO_FABRIC) {
1248 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
1249 atomic_dec(&phba->fabric_iocb_count);
1251 lpfc_els_free_iocb(phba, cmdiocb);
1255 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1256 * @vport: pointer to a host virtual N_Port data structure.
1257 * @ndlp: pointer to a node-list data structure.
1258 * @retry: number of retries to the command IOCB.
1260 * This routine issues a Fabric Login (FLOGI) Request ELS command
1261 * for a @vport. The initiator service parameters are put into the payload
1262 * of the FLOGI Request IOCB and the top-level callback function pointer
1263 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1264 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1265 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1267 * Note that the ndlp reference count will be incremented by 1 for holding the
1268 * ndlp and the reference to ndlp will be stored into the context1 field of
1269 * the IOCB for the completion callback function to the FLOGI ELS command.
1272 * 0 - successfully issued flogi iocb for @vport
1273 * 1 - failed to issue flogi iocb for @vport
1276 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1279 struct lpfc_hba *phba = vport->phba;
1280 struct serv_parm *sp;
1281 union lpfc_wqe128 *wqe = NULL;
1282 IOCB_t *icmd = NULL;
1283 struct lpfc_iocbq *elsiocb;
1284 struct lpfc_iocbq defer_flogi_acc;
1290 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1291 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1292 ndlp->nlp_DID, ELS_CMD_FLOGI);
1297 wqe = &elsiocb->wqe;
1298 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1299 icmd = &elsiocb->iocb;
1301 /* For FLOGI request, remainder of payload is service parameters */
1302 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1303 pcmd += sizeof(uint32_t);
1304 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1305 sp = (struct serv_parm *) pcmd;
1307 /* Setup CSPs accordingly for Fabric */
1308 sp->cmn.e_d_tov = 0;
1309 sp->cmn.w2.r_a_tov = 0;
1310 sp->cmn.virtual_fabric_support = 0;
1311 sp->cls1.classValid = 0;
1312 if (sp->cmn.fcphLow < FC_PH3)
1313 sp->cmn.fcphLow = FC_PH3;
1314 if (sp->cmn.fcphHigh < FC_PH3)
1315 sp->cmn.fcphHigh = FC_PH3;
1317 /* Determine if switch supports priority tagging */
1318 if (phba->cfg_vmid_priority_tagging) {
1319 sp->cmn.priority_tagging = 1;
1320 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
1321 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid)) {
1322 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn,
1323 sizeof(phba->wwpn));
1324 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn,
1325 sizeof(phba->wwnn));
1329 if (phba->sli_rev == LPFC_SLI_REV4) {
1330 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1331 LPFC_SLI_INTF_IF_TYPE_0) {
1332 /* FLOGI needs to be 3 for WQE FCFI */
1333 ct = ((SLI4_CT_FCFI >> 1) & 1) | (SLI4_CT_FCFI & 1);
1334 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
1336 /* Set the fcfi to the fcfi we registered with */
1337 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
1341 /* Can't do SLI4 class2 without support sequence coalescing */
1342 sp->cls2.classValid = 0;
1343 sp->cls2.seqDelivery = 0;
1345 /* Historical, setting sequential-delivery bit for SLI3 */
1346 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1347 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1348 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1349 sp->cmn.request_multiple_Nport = 1;
1350 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1354 sp->cmn.request_multiple_Nport = 0;
1357 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1358 icmd->un.elsreq64.myID = 0;
1359 icmd->un.elsreq64.fl = 1;
1363 tmo = phba->fc_ratov;
1364 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1365 lpfc_set_disctmo(vport);
1366 phba->fc_ratov = tmo;
1368 phba->fc_stat.elsXmitFLOGI++;
1369 elsiocb->cmd_cmpl = lpfc_cmpl_els_flogi;
1371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1372 "Issue FLOGI: opt:x%x",
1373 phba->sli3_options, 0, 0);
1375 elsiocb->context1 = lpfc_nlp_get(ndlp);
1376 if (!elsiocb->context1) {
1377 lpfc_els_free_iocb(phba, elsiocb);
1381 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1382 if (rc == IOCB_ERROR) {
1383 lpfc_els_free_iocb(phba, elsiocb);
1388 phba->hba_flag |= (HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
1390 /* Check for a deferred FLOGI ACC condition */
1391 if (phba->defer_flogi_acc_flag) {
1392 /* lookup ndlp for received FLOGI */
1393 ndlp = lpfc_findnode_did(vport, 0);
1397 did = vport->fc_myDID;
1398 vport->fc_myDID = Fabric_DID;
1400 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1402 if (phba->sli_rev == LPFC_SLI_REV4) {
1403 bf_set(wqe_ctxt_tag,
1404 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1405 phba->defer_flogi_acc_rx_id);
1407 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1408 phba->defer_flogi_acc_ox_id);
1410 icmd = &defer_flogi_acc.iocb;
1411 icmd->ulpContext = phba->defer_flogi_acc_rx_id;
1412 icmd->unsli3.rcvsli3.ox_id =
1413 phba->defer_flogi_acc_ox_id;
1416 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1417 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1418 " ox_id: x%x, hba_flag x%x\n",
1419 phba->defer_flogi_acc_rx_id,
1420 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1422 /* Send deferred FLOGI ACC */
1423 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1426 phba->defer_flogi_acc_flag = false;
1427 vport->fc_myDID = did;
1429 /* Decrement ndlp reference count to indicate the node can be
1430 * released when other references are removed.
1439 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1440 * @phba: pointer to lpfc hba data structure.
1442 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1443 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1444 * list and issues an abort IOCB commond on each outstanding IOCB that
1445 * contains a active Fabric_DID ndlp. Note that this function is to issue
1446 * the abort IOCB command on all the outstanding IOCBs, thus when this
1447 * function returns, it does not guarantee all the IOCBs are actually aborted.
1450 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1453 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1455 struct lpfc_sli_ring *pring;
1456 struct lpfc_iocbq *iocb, *next_iocb;
1457 struct lpfc_nodelist *ndlp;
1460 /* Abort outstanding I/O on NPort <nlp_DID> */
1461 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1462 "0201 Abort outstanding I/O on NPort x%x\n",
1465 pring = lpfc_phba_elsring(phba);
1466 if (unlikely(!pring))
1470 * Check the txcmplq for an iocb that matches the nport the driver is
1473 spin_lock_irq(&phba->hbalock);
1474 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1475 ulp_command = get_job_cmnd(phba, iocb);
1476 if (ulp_command == CMD_ELS_REQUEST64_CR) {
1477 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1478 if (ndlp && ndlp->nlp_DID == Fabric_DID) {
1479 if ((phba->pport->fc_flag & FC_PT2PT) &&
1480 !(phba->pport->fc_flag & FC_PT2PT_PLOGI))
1481 iocb->fabric_cmd_cmpl =
1482 lpfc_ignore_els_cmpl;
1483 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1488 /* Make sure HBA is alive */
1489 lpfc_issue_hb_tmo(phba);
1491 spin_unlock_irq(&phba->hbalock);
1497 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1498 * @vport: pointer to a host virtual N_Port data structure.
1500 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1501 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1502 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1503 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1504 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1505 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1509 * 0 - failed to issue initial flogi for @vport
1510 * 1 - successfully issued initial flogi for @vport
1513 lpfc_initial_flogi(struct lpfc_vport *vport)
1515 struct lpfc_nodelist *ndlp;
1517 vport->port_state = LPFC_FLOGI;
1518 lpfc_set_disctmo(vport);
1520 /* First look for the Fabric ndlp */
1521 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1523 /* Cannot find existing Fabric ndlp, so allocate a new one */
1524 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1527 /* Set the node type */
1528 ndlp->nlp_type |= NLP_FABRIC;
1530 /* Put ndlp onto node list */
1531 lpfc_enqueue_node(vport, ndlp);
1534 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1535 /* This decrement of reference count to node shall kick off
1536 * the release of the node.
1545 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1546 * @vport: pointer to a host virtual N_Port data structure.
1548 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1549 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1550 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1551 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1552 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1553 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1557 * 0 - failed to issue initial fdisc for @vport
1558 * 1 - successfully issued initial fdisc for @vport
1561 lpfc_initial_fdisc(struct lpfc_vport *vport)
1563 struct lpfc_nodelist *ndlp;
1565 /* First look for the Fabric ndlp */
1566 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1568 /* Cannot find existing Fabric ndlp, so allocate a new one */
1569 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1573 /* NPIV is only supported in Fabrics. */
1574 ndlp->nlp_type |= NLP_FABRIC;
1576 /* Put ndlp onto node list */
1577 lpfc_enqueue_node(vport, ndlp);
1580 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1581 /* decrement node reference count to trigger the release of
1591 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1592 * @vport: pointer to a host virtual N_Port data structure.
1594 * This routine checks whether there are more remaining Port Logins
1595 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1596 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1597 * to issue ELS PLOGIs up to the configured discover threads with the
1598 * @vport (@vport->cfg_discovery_threads). The function also decrement
1599 * the @vport's num_disc_node by 1 if it is not already 0.
1602 lpfc_more_plogi(struct lpfc_vport *vport)
1604 if (vport->num_disc_nodes)
1605 vport->num_disc_nodes--;
1607 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1608 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1609 "0232 Continue discovery with %d PLOGIs to go "
1610 "Data: x%x x%x x%x\n",
1611 vport->num_disc_nodes, vport->fc_plogi_cnt,
1612 vport->fc_flag, vport->port_state);
1613 /* Check to see if there are more PLOGIs to be sent */
1614 if (vport->fc_flag & FC_NLP_MORE)
1615 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1616 lpfc_els_disc_plogi(vport);
1622 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1623 * @phba: pointer to lpfc hba data structure.
1624 * @prsp: pointer to response IOCB payload.
1625 * @ndlp: pointer to a node-list data structure.
1627 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1628 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1629 * The following cases are considered N_Port confirmed:
1630 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1631 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1632 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1633 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1634 * 1) if there is a node on vport list other than the @ndlp with the same
1635 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1636 * on that node to release the RPI associated with the node; 2) if there is
1637 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1638 * into, a new node shall be allocated (or activated). In either case, the
1639 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1640 * be released and the new_ndlp shall be put on to the vport node list and
1641 * its pointer returned as the confirmed node.
1643 * Note that before the @ndlp got "released", the keepDID from not-matching
1644 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1645 * of the @ndlp. This is because the release of @ndlp is actually to put it
1646 * into an inactive state on the vport node list and the vport node list
1647 * management algorithm does not allow two node with a same DID.
1650 * pointer to the PLOGI N_Port @ndlp
1652 static struct lpfc_nodelist *
1653 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1654 struct lpfc_nodelist *ndlp)
1656 struct lpfc_vport *vport = ndlp->vport;
1657 struct lpfc_nodelist *new_ndlp;
1658 struct serv_parm *sp;
1659 uint8_t name[sizeof(struct lpfc_name)];
1660 uint32_t keepDID = 0, keep_nlp_flag = 0;
1661 uint32_t keep_new_nlp_flag = 0;
1662 uint16_t keep_nlp_state;
1663 u32 keep_nlp_fc4_type = 0;
1664 struct lpfc_nvme_rport *keep_nrport = NULL;
1665 unsigned long *active_rrqs_xri_bitmap = NULL;
1667 /* Fabric nodes can have the same WWPN so we don't bother searching
1668 * by WWPN. Just return the ndlp that was given to us.
1670 if (ndlp->nlp_type & NLP_FABRIC)
1673 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1674 memset(name, 0, sizeof(struct lpfc_name));
1676 /* Now we find out if the NPort we are logging into, matches the WWPN
1677 * we have for that ndlp. If not, we have some work to do.
1679 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1681 /* return immediately if the WWPN matches ndlp */
1682 if (!new_ndlp || (new_ndlp == ndlp))
1686 * Unregister from backend if not done yet. Could have been skipped
1689 lpfc_nlp_unreg_node(vport, new_ndlp);
1691 if (phba->sli_rev == LPFC_SLI_REV4) {
1692 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1694 if (active_rrqs_xri_bitmap)
1695 memset(active_rrqs_xri_bitmap, 0,
1696 phba->cfg_rrq_xri_bitmap_sz);
1699 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1700 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1701 "new_ndlp x%x x%x x%x\n",
1702 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1703 (new_ndlp ? new_ndlp->nlp_DID : 0),
1704 (new_ndlp ? new_ndlp->nlp_flag : 0),
1705 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1707 keepDID = new_ndlp->nlp_DID;
1709 if (phba->sli_rev == LPFC_SLI_REV4 && active_rrqs_xri_bitmap)
1710 memcpy(active_rrqs_xri_bitmap, new_ndlp->active_rrqs_xri_bitmap,
1711 phba->cfg_rrq_xri_bitmap_sz);
1713 /* At this point in this routine, we know new_ndlp will be
1714 * returned. however, any previous GID_FTs that were done
1715 * would have updated nlp_fc4_type in ndlp, so we must ensure
1716 * new_ndlp has the right value.
1718 if (vport->fc_flag & FC_FABRIC) {
1719 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1720 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1723 lpfc_unreg_rpi(vport, new_ndlp);
1724 new_ndlp->nlp_DID = ndlp->nlp_DID;
1725 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1726 if (phba->sli_rev == LPFC_SLI_REV4)
1727 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1728 ndlp->active_rrqs_xri_bitmap,
1729 phba->cfg_rrq_xri_bitmap_sz);
1731 /* Lock both ndlps */
1732 spin_lock_irq(&ndlp->lock);
1733 spin_lock_irq(&new_ndlp->lock);
1734 keep_new_nlp_flag = new_ndlp->nlp_flag;
1735 keep_nlp_flag = ndlp->nlp_flag;
1736 new_ndlp->nlp_flag = ndlp->nlp_flag;
1738 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1739 if (keep_new_nlp_flag & NLP_UNREG_INP)
1740 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1742 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1744 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1745 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1746 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1748 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1751 * Retain the DROPPED flag. This will take care of the init
1752 * refcount when affecting the state change
1754 if (keep_new_nlp_flag & NLP_DROPPED)
1755 new_ndlp->nlp_flag |= NLP_DROPPED;
1757 new_ndlp->nlp_flag &= ~NLP_DROPPED;
1759 ndlp->nlp_flag = keep_new_nlp_flag;
1761 /* if ndlp had NLP_UNREG_INP set, keep it */
1762 if (keep_nlp_flag & NLP_UNREG_INP)
1763 ndlp->nlp_flag |= NLP_UNREG_INP;
1765 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1767 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1768 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1769 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1771 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1774 * Retain the DROPPED flag. This will take care of the init
1775 * refcount when affecting the state change
1777 if (keep_nlp_flag & NLP_DROPPED)
1778 ndlp->nlp_flag |= NLP_DROPPED;
1780 ndlp->nlp_flag &= ~NLP_DROPPED;
1782 spin_unlock_irq(&new_ndlp->lock);
1783 spin_unlock_irq(&ndlp->lock);
1785 /* Set nlp_states accordingly */
1786 keep_nlp_state = new_ndlp->nlp_state;
1787 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1789 /* interchange the nvme remoteport structs */
1790 keep_nrport = new_ndlp->nrport;
1791 new_ndlp->nrport = ndlp->nrport;
1793 /* Move this back to NPR state */
1794 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1795 /* The new_ndlp is replacing ndlp totally, so we need
1796 * to put ndlp on UNUSED list and try to free it.
1798 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1799 "3179 PLOGI confirm NEW: %x %x\n",
1800 new_ndlp->nlp_DID, keepDID);
1802 /* Two ndlps cannot have the same did on the nodelist.
1803 * Note: for this case, ndlp has a NULL WWPN so setting
1804 * the nlp_fc4_type isn't required.
1806 ndlp->nlp_DID = keepDID;
1807 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1808 if (phba->sli_rev == LPFC_SLI_REV4 &&
1809 active_rrqs_xri_bitmap)
1810 memcpy(ndlp->active_rrqs_xri_bitmap,
1811 active_rrqs_xri_bitmap,
1812 phba->cfg_rrq_xri_bitmap_sz);
1815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1816 "3180 PLOGI confirm SWAP: %x %x\n",
1817 new_ndlp->nlp_DID, keepDID);
1819 lpfc_unreg_rpi(vport, ndlp);
1821 /* Two ndlps cannot have the same did and the fc4
1822 * type must be transferred because the ndlp is in
1825 ndlp->nlp_DID = keepDID;
1826 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1828 if (phba->sli_rev == LPFC_SLI_REV4 &&
1829 active_rrqs_xri_bitmap)
1830 memcpy(ndlp->active_rrqs_xri_bitmap,
1831 active_rrqs_xri_bitmap,
1832 phba->cfg_rrq_xri_bitmap_sz);
1834 /* Since we are switching over to the new_ndlp,
1835 * reset the old ndlp state
1837 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1838 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1839 keep_nlp_state = NLP_STE_NPR_NODE;
1840 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1841 ndlp->nrport = keep_nrport;
1845 * If ndlp is not associated with any rport we can drop it here else
1846 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1848 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1849 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1851 if (phba->sli_rev == LPFC_SLI_REV4 &&
1852 active_rrqs_xri_bitmap)
1853 mempool_free(active_rrqs_xri_bitmap,
1854 phba->active_rrq_pool);
1856 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1857 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1858 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1859 new_ndlp->nlp_fc4_type);
1865 * lpfc_end_rscn - Check and handle more rscn for a vport
1866 * @vport: pointer to a host virtual N_Port data structure.
1868 * This routine checks whether more Registration State Change
1869 * Notifications (RSCNs) came in while the discovery state machine was in
1870 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1871 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1872 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1873 * handling the RSCNs.
1876 lpfc_end_rscn(struct lpfc_vport *vport)
1878 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1880 if (vport->fc_flag & FC_RSCN_MODE) {
1882 * Check to see if more RSCNs came in while we were
1883 * processing this one.
1885 if (vport->fc_rscn_id_cnt ||
1886 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1887 lpfc_els_handle_rscn(vport);
1889 spin_lock_irq(shost->host_lock);
1890 vport->fc_flag &= ~FC_RSCN_MODE;
1891 spin_unlock_irq(shost->host_lock);
1897 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1898 * @phba: pointer to lpfc hba data structure.
1899 * @cmdiocb: pointer to lpfc command iocb data structure.
1900 * @rspiocb: pointer to lpfc response iocb data structure.
1902 * This routine will call the clear rrq function to free the rrq and
1903 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1904 * exist then the clear_rrq is still called because the rrq needs to
1909 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1910 struct lpfc_iocbq *rspiocb)
1912 struct lpfc_vport *vport = cmdiocb->vport;
1913 struct lpfc_nodelist *ndlp = cmdiocb->context1;
1914 struct lpfc_node_rrq *rrq;
1915 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
1916 u32 ulp_word4 = get_job_word4(phba, rspiocb);
1918 /* we pass cmdiocb to state machine which needs rspiocb as well */
1919 rrq = cmdiocb->context_un.rrq;
1920 cmdiocb->context_un.rsp_iocb = rspiocb;
1922 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1923 "RRQ cmpl: status:x%x/x%x did:x%x",
1924 ulp_status, ulp_word4,
1925 get_job_els_rsp64_did(phba, cmdiocb));
1928 /* rrq completes to NPort <nlp_DID> */
1929 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1930 "2880 RRQ completes to DID x%x "
1931 "Data: x%x x%x x%x x%x x%x\n",
1932 ndlp->nlp_DID, ulp_status, ulp_word4,
1933 get_wqe_tmo(cmdiocb), rrq->xritag, rrq->rxid);
1936 /* Check for retry */
1937 /* RRQ failed Don't print the vport to vport rjts */
1938 if (ulp_status != IOSTAT_LS_RJT ||
1939 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
1940 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
1941 (phba)->pport->cfg_log_verbose & LOG_ELS)
1942 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1943 "2881 RRQ failure DID:%06X Status:"
1945 ndlp->nlp_DID, ulp_status,
1949 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1950 lpfc_els_free_iocb(phba, cmdiocb);
1955 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1956 * @phba: pointer to lpfc hba data structure.
1957 * @cmdiocb: pointer to lpfc command iocb data structure.
1958 * @rspiocb: pointer to lpfc response iocb data structure.
1960 * This routine is the completion callback function for issuing the Port
1961 * Login (PLOGI) command. For PLOGI completion, there must be an active
1962 * ndlp on the vport node list that matches the remote node ID from the
1963 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1964 * ignored and command IOCB released. The PLOGI response IOCB status is
1965 * checked for error conditions. If there is error status reported, PLOGI
1966 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1967 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1968 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1969 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1970 * there are additional N_Port nodes with the vport that need to perform
1971 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1975 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1976 struct lpfc_iocbq *rspiocb)
1978 struct lpfc_vport *vport = cmdiocb->vport;
1979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1981 struct lpfc_nodelist *ndlp, *free_ndlp;
1982 struct lpfc_dmabuf *prsp;
1984 struct serv_parm *sp = NULL;
1985 u32 ulp_status, ulp_word4, did, iotag;
1987 /* we pass cmdiocb to state machine which needs rspiocb as well */
1988 cmdiocb->context_un.rsp_iocb = rspiocb;
1990 ulp_status = get_job_ulpstatus(phba, rspiocb);
1991 ulp_word4 = get_job_word4(phba, rspiocb);
1992 did = get_job_els_rsp64_did(phba, cmdiocb);
1994 if (phba->sli_rev == LPFC_SLI_REV4) {
1995 iotag = get_wqe_reqtag(cmdiocb);
1997 irsp = &rspiocb->iocb;
1998 iotag = irsp->ulpIoTag;
2001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2002 "PLOGI cmpl: status:x%x/x%x did:x%x",
2003 ulp_status, ulp_word4, did);
2005 ndlp = lpfc_findnode_did(vport, did);
2007 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2008 "0136 PLOGI completes to NPort x%x "
2009 "with no ndlp. Data: x%x x%x x%x\n",
2010 did, ulp_status, ulp_word4, iotag);
2014 /* Since ndlp can be freed in the disc state machine, note if this node
2015 * is being used during discovery.
2017 spin_lock_irq(&ndlp->lock);
2018 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2019 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2020 spin_unlock_irq(&ndlp->lock);
2022 /* PLOGI completes to NPort <nlp_DID> */
2023 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2024 "0102 PLOGI completes to NPort x%06x "
2025 "Data: x%x x%x x%x x%x x%x\n",
2026 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2027 ulp_status, ulp_word4,
2028 disc, vport->num_disc_nodes);
2030 /* Check to see if link went down during discovery */
2031 if (lpfc_els_chk_latt(vport)) {
2032 spin_lock_irq(&ndlp->lock);
2033 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2034 spin_unlock_irq(&ndlp->lock);
2039 /* Check for retry */
2040 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2041 /* ELS command is being retried */
2043 spin_lock_irq(&ndlp->lock);
2044 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2045 spin_unlock_irq(&ndlp->lock);
2049 /* PLOGI failed Don't print the vport to vport rjts */
2050 if (ulp_status != IOSTAT_LS_RJT ||
2051 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
2052 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
2053 (phba)->pport->cfg_log_verbose & LOG_ELS)
2054 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2055 "2753 PLOGI failure DID:%06X "
2057 ndlp->nlp_DID, ulp_status,
2060 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2061 if (!lpfc_error_lost_link(ulp_status, ulp_word4))
2062 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2063 NLP_EVT_CMPL_PLOGI);
2065 /* If a PLOGI collision occurred, the node needs to continue
2066 * with the reglogin process.
2068 spin_lock_irq(&ndlp->lock);
2069 if ((ndlp->nlp_flag & (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI)) &&
2070 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
2071 spin_unlock_irq(&ndlp->lock);
2074 spin_unlock_irq(&ndlp->lock);
2076 /* No PLOGI collision and the node is not registered with the
2077 * scsi or nvme transport. It is no longer an active node. Just
2078 * start the device remove process.
2080 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2081 spin_lock_irq(&ndlp->lock);
2082 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2083 spin_unlock_irq(&ndlp->lock);
2084 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2088 /* Good status, call state machine */
2089 prsp = list_entry(((struct lpfc_dmabuf *)
2090 cmdiocb->context2)->list.next,
2091 struct lpfc_dmabuf, list);
2092 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2094 sp = (struct serv_parm *)((u8 *)prsp->virt +
2097 ndlp->vmid_support = 0;
2098 if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) ||
2099 (phba->cfg_vmid_priority_tagging &&
2100 sp->cmn.priority_tagging)) {
2101 lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS,
2102 "4018 app_hdr_support %d tagging %d DID x%x\n",
2103 sp->cmn.app_hdr_support,
2104 sp->cmn.priority_tagging,
2106 /* if the dest port supports VMID, mark it in ndlp */
2107 ndlp->vmid_support = 1;
2110 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2111 NLP_EVT_CMPL_PLOGI);
2114 if (disc && vport->num_disc_nodes) {
2115 /* Check to see if there are more PLOGIs to be sent */
2116 lpfc_more_plogi(vport);
2118 if (vport->num_disc_nodes == 0) {
2119 spin_lock_irq(shost->host_lock);
2120 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2121 spin_unlock_irq(shost->host_lock);
2123 lpfc_can_disctmo(vport);
2124 lpfc_end_rscn(vport);
2129 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2130 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2131 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2134 /* Release the reference on the original I/O request. */
2135 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2137 lpfc_els_free_iocb(phba, cmdiocb);
2138 lpfc_nlp_put(free_ndlp);
2143 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2144 * @vport: pointer to a host virtual N_Port data structure.
2145 * @did: destination port identifier.
2146 * @retry: number of retries to the command IOCB.
2148 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2149 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2150 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2151 * This routine constructs the proper fields of the PLOGI IOCB and invokes
2152 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2154 * Note that the ndlp reference count will be incremented by 1 for holding
2155 * the ndlp and the reference to ndlp will be stored into the context1 field
2156 * of the IOCB for the completion callback function to the PLOGI ELS command.
2159 * 0 - Successfully issued a plogi for @vport
2160 * 1 - failed to issue a plogi for @vport
2163 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2165 struct lpfc_hba *phba = vport->phba;
2166 struct serv_parm *sp;
2167 struct lpfc_nodelist *ndlp;
2168 struct lpfc_iocbq *elsiocb;
2173 ndlp = lpfc_findnode_did(vport, did);
2177 /* Defer the processing of the issue PLOGI until after the
2178 * outstanding UNREG_RPI mbox command completes, unless we
2179 * are going offline. This logic does not apply for Fabric DIDs
2181 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2182 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2183 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2184 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2185 "4110 Issue PLOGI x%x deferred "
2186 "on NPort x%x rpi x%x Data: x%px\n",
2187 ndlp->nlp_defer_did, ndlp->nlp_DID,
2188 ndlp->nlp_rpi, ndlp);
2190 /* We can only defer 1st PLOGI */
2191 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2192 ndlp->nlp_defer_did = did;
2196 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2197 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2202 spin_lock_irq(&ndlp->lock);
2203 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2204 spin_unlock_irq(&ndlp->lock);
2206 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2208 /* For PLOGI request, remainder of payload is service parameters */
2209 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2210 pcmd += sizeof(uint32_t);
2211 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2212 sp = (struct serv_parm *) pcmd;
2215 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2216 * to device on remote loops work.
2218 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2219 sp->cmn.altBbCredit = 1;
2221 if (sp->cmn.fcphLow < FC_PH_4_3)
2222 sp->cmn.fcphLow = FC_PH_4_3;
2224 if (sp->cmn.fcphHigh < FC_PH3)
2225 sp->cmn.fcphHigh = FC_PH3;
2227 sp->cmn.valid_vendor_ver_level = 0;
2228 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2229 sp->cmn.bbRcvSizeMsb &= 0xF;
2231 /* Check if the destination port supports VMID */
2232 ndlp->vmid_support = 0;
2233 if (vport->vmid_priority_tagging)
2234 sp->cmn.priority_tagging = 1;
2235 else if (phba->cfg_vmid_app_header &&
2236 bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags))
2237 sp->cmn.app_hdr_support = 1;
2239 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2240 "Issue PLOGI: did:x%x",
2243 /* If our firmware supports this feature, convey that
2244 * information to the target using the vendor specific field.
2246 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2247 sp->cmn.valid_vendor_ver_level = 1;
2248 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2249 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2252 phba->fc_stat.elsXmitPLOGI++;
2253 elsiocb->cmd_cmpl = lpfc_cmpl_els_plogi;
2255 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2256 "Issue PLOGI: did:x%x refcnt %d",
2257 did, kref_read(&ndlp->kref), 0);
2258 elsiocb->context1 = lpfc_nlp_get(ndlp);
2259 if (!elsiocb->context1) {
2260 lpfc_els_free_iocb(phba, elsiocb);
2264 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2266 lpfc_els_free_iocb(phba, elsiocb);
2275 * lpfc_cmpl_els_prli - Completion callback function for prli
2276 * @phba: pointer to lpfc hba data structure.
2277 * @cmdiocb: pointer to lpfc command iocb data structure.
2278 * @rspiocb: pointer to lpfc response iocb data structure.
2280 * This routine is the completion callback function for a Process Login
2281 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2282 * status. If there is error status reported, PRLI retry shall be attempted
2283 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2284 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2285 * ndlp to mark the PRLI completion.
2288 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2289 struct lpfc_iocbq *rspiocb)
2291 struct lpfc_vport *vport = cmdiocb->vport;
2292 struct lpfc_nodelist *ndlp;
2298 /* we pass cmdiocb to state machine which needs rspiocb as well */
2299 cmdiocb->context_un.rsp_iocb = rspiocb;
2301 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2303 ulp_status = get_job_ulpstatus(phba, rspiocb);
2304 ulp_word4 = get_job_word4(phba, rspiocb);
2306 spin_lock_irq(&ndlp->lock);
2307 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2309 /* Driver supports multiple FC4 types. Counters matter. */
2310 vport->fc_prli_sent--;
2311 ndlp->fc4_prli_sent--;
2312 spin_unlock_irq(&ndlp->lock);
2314 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2315 "PRLI cmpl: status:x%x/x%x did:x%x",
2316 ulp_status, ulp_word4,
2319 /* PRLI completes to NPort <nlp_DID> */
2320 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2321 "0103 PRLI completes to NPort x%06x "
2322 "Data: x%x x%x x%x x%x\n",
2323 ndlp->nlp_DID, ulp_status, ulp_word4,
2324 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2326 /* Check to see if link went down during discovery */
2327 if (lpfc_els_chk_latt(vport))
2331 /* Check for retry */
2332 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2333 /* ELS command is being retried */
2337 /* If we don't send GFT_ID to Fabric, a PRLI error
2338 * could be expected.
2340 if ((vport->fc_flag & FC_FABRIC) ||
2341 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2343 loglevel = LOG_TRACE_EVENT;
2350 lpfc_printf_vlog(vport, mode, loglevel,
2351 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2353 ndlp->nlp_DID, ulp_status,
2354 ulp_word4, ndlp->fc4_prli_sent);
2356 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2357 if (!lpfc_error_lost_link(ulp_status, ulp_word4))
2358 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2362 * For P2P topology, retain the node so that PLOGI can be
2363 * attempted on it again.
2365 if (vport->fc_flag & FC_PT2PT)
2368 /* As long as this node is not registered with the SCSI
2369 * or NVMe transport and no other PRLIs are outstanding,
2370 * it is no longer an active node. Otherwise devloss
2371 * handles the final cleanup.
2373 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2374 !ndlp->fc4_prli_sent) {
2375 spin_lock_irq(&ndlp->lock);
2376 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2377 spin_unlock_irq(&ndlp->lock);
2378 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2382 /* Good status, call state machine. However, if another
2383 * PRLI is outstanding, don't call the state machine
2384 * because final disposition to Mapped or Unmapped is
2387 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2392 lpfc_els_free_iocb(phba, cmdiocb);
2398 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2399 * @vport: pointer to a host virtual N_Port data structure.
2400 * @ndlp: pointer to a node-list data structure.
2401 * @retry: number of retries to the command IOCB.
2403 * This routine issues a Process Login (PRLI) ELS command for the
2404 * @vport. The PRLI service parameters are set up in the payload of the
2405 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2406 * is put to the IOCB completion callback func field before invoking the
2407 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2409 * Note that the ndlp reference count will be incremented by 1 for holding the
2410 * ndlp and the reference to ndlp will be stored into the context1 field of
2411 * the IOCB for the completion callback function to the PRLI ELS command.
2414 * 0 - successfully issued prli iocb command for @vport
2415 * 1 - failed to issue prli iocb command for @vport
2418 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2422 struct lpfc_hba *phba = vport->phba;
2424 struct lpfc_nvme_prli *npr_nvme;
2425 struct lpfc_iocbq *elsiocb;
2428 u32 local_nlp_type, elscmd;
2431 * If we are in RSCN mode, the FC4 types supported from a
2432 * previous GFT_ID command may not be accurate. So, if we
2433 * are a NVME Initiator, always look for the possibility of
2434 * the remote NPort beng a NVME Target.
2436 if (phba->sli_rev == LPFC_SLI_REV4 &&
2437 vport->fc_flag & FC_RSCN_MODE &&
2438 vport->nvmei_support)
2439 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2440 local_nlp_type = ndlp->nlp_fc4_type;
2442 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2443 * fields here before any of them can complete.
2445 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2446 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2447 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2448 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2449 ndlp->nvme_fb_size = 0;
2452 if (local_nlp_type & NLP_FC4_FCP) {
2453 /* Payload is 4 + 16 = 20 x14 bytes. */
2454 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2455 elscmd = ELS_CMD_PRLI;
2456 } else if (local_nlp_type & NLP_FC4_NVME) {
2457 /* Payload is 4 + 20 = 24 x18 bytes. */
2458 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2459 elscmd = ELS_CMD_NVMEPRLI;
2461 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2462 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2463 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2467 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2468 * FC4 type, implicitly LOGO.
2470 if (phba->sli_rev == LPFC_SLI_REV3 &&
2471 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2472 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2473 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2475 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2479 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2480 ndlp->nlp_DID, elscmd);
2484 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2486 /* For PRLI request, remainder of payload is service parameters */
2487 memset(pcmd, 0, cmdsize);
2489 if (local_nlp_type & NLP_FC4_FCP) {
2490 /* Remainder of payload is FCP PRLI parameter page.
2491 * Note: this data structure is defined as
2492 * BE/LE in the structure definition so no
2493 * byte swap call is made.
2495 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2496 pcmd += sizeof(uint32_t);
2500 * If our firmware version is 3.20 or later,
2501 * set the following bits for FC-TAPE support.
2503 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2504 npr->ConfmComplAllowed = 1;
2506 npr->TaskRetryIdReq = 1;
2508 npr->estabImagePair = 1;
2509 npr->readXferRdyDis = 1;
2510 if (vport->cfg_first_burst_size)
2511 npr->writeXferRdyDis = 1;
2513 /* For FCP support */
2514 npr->prliType = PRLI_FCP_TYPE;
2515 npr->initiatorFunc = 1;
2516 elsiocb->cmd_flag |= LPFC_PRLI_FCP_REQ;
2518 /* Remove FCP type - processed. */
2519 local_nlp_type &= ~NLP_FC4_FCP;
2520 } else if (local_nlp_type & NLP_FC4_NVME) {
2521 /* Remainder of payload is NVME PRLI parameter page.
2522 * This data structure is the newer definition that
2523 * uses bf macros so a byte swap is required.
2525 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2526 pcmd += sizeof(uint32_t);
2527 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2528 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2529 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2531 bf_set(prli_nsler, npr_nvme, 1);
2532 bf_set(prli_conf, npr_nvme, 1);
2535 /* Only initiators request first burst. */
2536 if ((phba->cfg_nvme_enable_fb) &&
2537 !phba->nvmet_support)
2538 bf_set(prli_fba, npr_nvme, 1);
2540 if (phba->nvmet_support) {
2541 bf_set(prli_tgt, npr_nvme, 1);
2542 bf_set(prli_disc, npr_nvme, 1);
2544 bf_set(prli_init, npr_nvme, 1);
2545 bf_set(prli_conf, npr_nvme, 1);
2548 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2549 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2550 elsiocb->cmd_flag |= LPFC_PRLI_NVME_REQ;
2552 /* Remove NVME type - processed. */
2553 local_nlp_type &= ~NLP_FC4_NVME;
2556 phba->fc_stat.elsXmitPRLI++;
2557 elsiocb->cmd_cmpl = lpfc_cmpl_els_prli;
2558 spin_lock_irq(&ndlp->lock);
2559 ndlp->nlp_flag |= NLP_PRLI_SND;
2561 /* The vport counters are used for lpfc_scan_finished, but
2562 * the ndlp is used to track outstanding PRLIs for different
2565 vport->fc_prli_sent++;
2566 ndlp->fc4_prli_sent++;
2567 spin_unlock_irq(&ndlp->lock);
2569 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2570 "Issue PRLI: did:x%x refcnt %d",
2571 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2572 elsiocb->context1 = lpfc_nlp_get(ndlp);
2573 if (!elsiocb->context1) {
2574 lpfc_els_free_iocb(phba, elsiocb);
2578 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2579 if (rc == IOCB_ERROR) {
2580 lpfc_els_free_iocb(phba, elsiocb);
2586 /* The driver supports 2 FC4 types. Make sure
2587 * a PRLI is issued for all types before exiting.
2589 if (phba->sli_rev == LPFC_SLI_REV4 &&
2590 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2591 goto send_next_prli;
2596 spin_lock_irq(&ndlp->lock);
2597 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2598 spin_unlock_irq(&ndlp->lock);
2603 * lpfc_rscn_disc - Perform rscn discovery for a vport
2604 * @vport: pointer to a host virtual N_Port data structure.
2606 * This routine performs Registration State Change Notification (RSCN)
2607 * discovery for a @vport. If the @vport's node port recovery count is not
2608 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2609 * the nodes that need recovery. If none of the PLOGI were needed through
2610 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2611 * invoked to check and handle possible more RSCN came in during the period
2612 * of processing the current ones.
2615 lpfc_rscn_disc(struct lpfc_vport *vport)
2617 lpfc_can_disctmo(vport);
2619 /* RSCN discovery */
2620 /* go thru NPR nodes and issue ELS PLOGIs */
2621 if (vport->fc_npr_cnt)
2622 if (lpfc_els_disc_plogi(vport))
2625 lpfc_end_rscn(vport);
2629 * lpfc_adisc_done - Complete the adisc phase of discovery
2630 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2632 * This function is called when the final ADISC is completed during discovery.
2633 * This function handles clearing link attention or issuing reg_vpi depending
2634 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2636 * This function is called with no locks held.
2639 lpfc_adisc_done(struct lpfc_vport *vport)
2641 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2642 struct lpfc_hba *phba = vport->phba;
2645 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2646 * and continue discovery.
2648 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2649 !(vport->fc_flag & FC_RSCN_MODE) &&
2650 (phba->sli_rev < LPFC_SLI_REV4)) {
2653 * If link is down, clear_la and reg_vpi will be done after
2654 * flogi following a link up event
2656 if (!lpfc_is_link_up(phba))
2659 /* The ADISCs are complete. Doesn't matter if they
2660 * succeeded or failed because the ADISC completion
2661 * routine guarantees to call the state machine and
2662 * the RPI is either unregistered (failed ADISC response)
2663 * or the RPI is still valid and the node is marked
2664 * mapped for a target. The exchanges should be in the
2665 * correct state. This code is specific to SLI3.
2667 lpfc_issue_clear_la(phba, vport);
2668 lpfc_issue_reg_vpi(phba, vport);
2672 * For SLI2, we need to set port_state to READY
2673 * and continue discovery.
2675 if (vport->port_state < LPFC_VPORT_READY) {
2676 /* If we get here, there is nothing to ADISC */
2677 lpfc_issue_clear_la(phba, vport);
2678 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2679 vport->num_disc_nodes = 0;
2680 /* go thru NPR list, issue ELS PLOGIs */
2681 if (vport->fc_npr_cnt)
2682 lpfc_els_disc_plogi(vport);
2683 if (!vport->num_disc_nodes) {
2684 spin_lock_irq(shost->host_lock);
2685 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2686 spin_unlock_irq(shost->host_lock);
2687 lpfc_can_disctmo(vport);
2688 lpfc_end_rscn(vport);
2691 vport->port_state = LPFC_VPORT_READY;
2693 lpfc_rscn_disc(vport);
2697 * lpfc_more_adisc - Issue more adisc as needed
2698 * @vport: pointer to a host virtual N_Port data structure.
2700 * This routine determines whether there are more ndlps on a @vport
2701 * node list need to have Address Discover (ADISC) issued. If so, it will
2702 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2703 * remaining nodes which need to have ADISC sent.
2706 lpfc_more_adisc(struct lpfc_vport *vport)
2708 if (vport->num_disc_nodes)
2709 vport->num_disc_nodes--;
2710 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2711 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2712 "0210 Continue discovery with %d ADISCs to go "
2713 "Data: x%x x%x x%x\n",
2714 vport->num_disc_nodes, vport->fc_adisc_cnt,
2715 vport->fc_flag, vport->port_state);
2716 /* Check to see if there are more ADISCs to be sent */
2717 if (vport->fc_flag & FC_NLP_MORE) {
2718 lpfc_set_disctmo(vport);
2719 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2720 lpfc_els_disc_adisc(vport);
2722 if (!vport->num_disc_nodes)
2723 lpfc_adisc_done(vport);
2728 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2729 * @phba: pointer to lpfc hba data structure.
2730 * @cmdiocb: pointer to lpfc command iocb data structure.
2731 * @rspiocb: pointer to lpfc response iocb data structure.
2733 * This routine is the completion function for issuing the Address Discover
2734 * (ADISC) command. It first checks to see whether link went down during
2735 * the discovery process. If so, the node will be marked as node port
2736 * recovery for issuing discover IOCB by the link attention handler and
2737 * exit. Otherwise, the response status is checked. If error was reported
2738 * in the response status, the ADISC command shall be retried by invoking
2739 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2740 * the response status, the state machine is invoked to set transition
2741 * with respect to NLP_EVT_CMPL_ADISC event.
2744 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2745 struct lpfc_iocbq *rspiocb)
2747 struct lpfc_vport *vport = cmdiocb->vport;
2749 struct lpfc_nodelist *ndlp;
2751 u32 ulp_status, ulp_word4, tmo;
2753 /* we pass cmdiocb to state machine which needs rspiocb as well */
2754 cmdiocb->context_un.rsp_iocb = rspiocb;
2756 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2758 ulp_status = get_job_ulpstatus(phba, rspiocb);
2759 ulp_word4 = get_job_word4(phba, rspiocb);
2761 if (phba->sli_rev == LPFC_SLI_REV4) {
2762 tmo = get_wqe_tmo(cmdiocb);
2764 irsp = &rspiocb->iocb;
2765 tmo = irsp->ulpTimeout;
2768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2769 "ADISC cmpl: status:x%x/x%x did:x%x",
2770 ulp_status, ulp_word4,
2773 /* Since ndlp can be freed in the disc state machine, note if this node
2774 * is being used during discovery.
2776 spin_lock_irq(&ndlp->lock);
2777 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2778 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2779 spin_unlock_irq(&ndlp->lock);
2780 /* ADISC completes to NPort <nlp_DID> */
2781 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2782 "0104 ADISC completes to NPort x%x "
2783 "Data: x%x x%x x%x x%x x%x\n",
2784 ndlp->nlp_DID, ulp_status, ulp_word4,
2785 tmo, disc, vport->num_disc_nodes);
2786 /* Check to see if link went down during discovery */
2787 if (lpfc_els_chk_latt(vport)) {
2788 spin_lock_irq(&ndlp->lock);
2789 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2790 spin_unlock_irq(&ndlp->lock);
2795 /* Check for retry */
2796 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2797 /* ELS command is being retried */
2799 spin_lock_irq(&ndlp->lock);
2800 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2801 spin_unlock_irq(&ndlp->lock);
2802 lpfc_set_disctmo(vport);
2807 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2808 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2809 ndlp->nlp_DID, ulp_status,
2811 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2812 NLP_EVT_CMPL_ADISC);
2814 /* As long as this node is not registered with the SCSI or NVMe
2815 * transport, it is no longer an active node. Otherwise
2816 * devloss handles the final cleanup.
2818 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2819 spin_lock_irq(&ndlp->lock);
2820 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2821 spin_unlock_irq(&ndlp->lock);
2822 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2826 /* Good status, call state machine */
2827 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2828 NLP_EVT_CMPL_ADISC);
2830 /* Check to see if there are more ADISCs to be sent */
2831 if (disc && vport->num_disc_nodes)
2832 lpfc_more_adisc(vport);
2834 lpfc_els_free_iocb(phba, cmdiocb);
2840 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2841 * @vport: pointer to a virtual N_Port data structure.
2842 * @ndlp: pointer to a node-list data structure.
2843 * @retry: number of retries to the command IOCB.
2845 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2846 * @vport. It prepares the payload of the ADISC ELS command, updates the
2847 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2848 * to issue the ADISC ELS command.
2850 * Note that the ndlp reference count will be incremented by 1 for holding the
2851 * ndlp and the reference to ndlp will be stored into the context1 field of
2852 * the IOCB for the completion callback function to the ADISC ELS command.
2855 * 0 - successfully issued adisc
2856 * 1 - failed to issue adisc
2859 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2863 struct lpfc_hba *phba = vport->phba;
2865 struct lpfc_iocbq *elsiocb;
2869 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2870 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2871 ndlp->nlp_DID, ELS_CMD_ADISC);
2875 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2877 /* For ADISC request, remainder of payload is service parameters */
2878 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2879 pcmd += sizeof(uint32_t);
2881 /* Fill in ADISC payload */
2882 ap = (ADISC *) pcmd;
2883 ap->hardAL_PA = phba->fc_pref_ALPA;
2884 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2885 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2886 ap->DID = be32_to_cpu(vport->fc_myDID);
2888 phba->fc_stat.elsXmitADISC++;
2889 elsiocb->cmd_cmpl = lpfc_cmpl_els_adisc;
2890 spin_lock_irq(&ndlp->lock);
2891 ndlp->nlp_flag |= NLP_ADISC_SND;
2892 spin_unlock_irq(&ndlp->lock);
2893 elsiocb->context1 = lpfc_nlp_get(ndlp);
2894 if (!elsiocb->context1) {
2895 lpfc_els_free_iocb(phba, elsiocb);
2899 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2900 "Issue ADISC: did:x%x refcnt %d",
2901 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2903 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2904 if (rc == IOCB_ERROR) {
2905 lpfc_els_free_iocb(phba, elsiocb);
2913 spin_lock_irq(&ndlp->lock);
2914 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2915 spin_unlock_irq(&ndlp->lock);
2920 * lpfc_cmpl_els_logo - Completion callback function for logo
2921 * @phba: pointer to lpfc hba data structure.
2922 * @cmdiocb: pointer to lpfc command iocb data structure.
2923 * @rspiocb: pointer to lpfc response iocb data structure.
2925 * This routine is the completion function for issuing the ELS Logout (LOGO)
2926 * command. If no error status was reported from the LOGO response, the
2927 * state machine of the associated ndlp shall be invoked for transition with
2928 * respect to NLP_EVT_CMPL_LOGO event.
2931 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2932 struct lpfc_iocbq *rspiocb)
2934 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2935 struct lpfc_vport *vport = ndlp->vport;
2937 unsigned long flags;
2938 uint32_t skip_recovery = 0;
2939 int wake_up_waiter = 0;
2944 /* we pass cmdiocb to state machine which needs rspiocb as well */
2945 cmdiocb->context_un.rsp_iocb = rspiocb;
2947 ulp_status = get_job_ulpstatus(phba, rspiocb);
2948 ulp_word4 = get_job_word4(phba, rspiocb);
2950 if (phba->sli_rev == LPFC_SLI_REV4) {
2951 tmo = get_wqe_tmo(cmdiocb);
2953 irsp = &rspiocb->iocb;
2954 tmo = irsp->ulpTimeout;
2957 spin_lock_irq(&ndlp->lock);
2958 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2959 if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
2961 ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
2963 spin_unlock_irq(&ndlp->lock);
2965 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2966 "LOGO cmpl: status:x%x/x%x did:x%x",
2967 ulp_status, ulp_word4,
2970 /* LOGO completes to NPort <nlp_DID> */
2971 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2972 "0105 LOGO completes to NPort x%x "
2973 "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
2974 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
2975 ulp_status, ulp_word4,
2976 tmo, vport->num_disc_nodes);
2978 if (lpfc_els_chk_latt(vport)) {
2983 /* The LOGO will not be retried on failure. A LOGO was
2984 * issued to the remote rport and a ACC or RJT or no Answer are
2985 * all acceptable. Note the failure and move forward with
2986 * discovery. The PLOGI will retry.
2990 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2991 "2756 LOGO failure, No Retry DID:%06X "
2993 ndlp->nlp_DID, ulp_status,
2996 if (lpfc_error_lost_link(ulp_status, ulp_word4)) {
3002 /* Call state machine. This will unregister the rpi if needed. */
3003 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
3005 /* The driver sets this flag for an NPIV instance that doesn't want to
3006 * log into the remote port.
3008 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
3009 spin_lock_irq(&ndlp->lock);
3010 if (phba->sli_rev == LPFC_SLI_REV4)
3011 ndlp->nlp_flag |= NLP_RELEASE_RPI;
3012 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3013 spin_unlock_irq(&ndlp->lock);
3014 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3016 lpfc_els_free_iocb(phba, cmdiocb);
3019 /* Presume the node was released. */
3024 /* Driver is done with the IO. */
3025 lpfc_els_free_iocb(phba, cmdiocb);
3028 /* At this point, the LOGO processing is complete. NOTE: For a
3029 * pt2pt topology, we are assuming the NPortID will only change
3030 * on link up processing. For a LOGO / PLOGI initiated by the
3031 * Initiator, we are assuming the NPortID is not going to change.
3034 if (wake_up_waiter && ndlp->logo_waitq)
3035 wake_up(ndlp->logo_waitq);
3037 * If the node is a target, the handling attempts to recover the port.
3038 * For any other port type, the rpi is unregistered as an implicit
3041 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
3042 skip_recovery == 0) {
3043 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3044 spin_lock_irqsave(&ndlp->lock, flags);
3045 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
3046 spin_unlock_irqrestore(&ndlp->lock, flags);
3048 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3049 "3187 LOGO completes to NPort x%x: Start "
3050 "Recovery Data: x%x x%x x%x x%x\n",
3051 ndlp->nlp_DID, ulp_status,
3053 vport->num_disc_nodes);
3054 lpfc_disc_start(vport);
3058 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
3059 * driver sends a LOGO to the rport to cleanup. For fabric and
3060 * initiator ports cleanup the node as long as it the node is not
3061 * register with the transport.
3063 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
3064 spin_lock_irq(&ndlp->lock);
3065 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3066 spin_unlock_irq(&ndlp->lock);
3067 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3073 * lpfc_issue_els_logo - Issue a logo to an node on a vport
3074 * @vport: pointer to a virtual N_Port data structure.
3075 * @ndlp: pointer to a node-list data structure.
3076 * @retry: number of retries to the command IOCB.
3078 * This routine constructs and issues an ELS Logout (LOGO) iocb command
3079 * to a remote node, referred by an @ndlp on a @vport. It constructs the
3080 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
3081 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
3083 * Note that the ndlp reference count will be incremented by 1 for holding the
3084 * ndlp and the reference to ndlp will be stored into the context1 field of
3085 * the IOCB for the completion callback function to the LOGO ELS command.
3087 * Callers of this routine are expected to unregister the RPI first
3090 * 0 - successfully issued logo
3091 * 1 - failed to issue logo
3094 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3097 struct lpfc_hba *phba = vport->phba;
3098 struct lpfc_iocbq *elsiocb;
3103 spin_lock_irq(&ndlp->lock);
3104 if (ndlp->nlp_flag & NLP_LOGO_SND) {
3105 spin_unlock_irq(&ndlp->lock);
3108 spin_unlock_irq(&ndlp->lock);
3110 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
3111 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3112 ndlp->nlp_DID, ELS_CMD_LOGO);
3116 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3117 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
3118 pcmd += sizeof(uint32_t);
3120 /* Fill in LOGO payload */
3121 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
3122 pcmd += sizeof(uint32_t);
3123 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
3125 phba->fc_stat.elsXmitLOGO++;
3126 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo;
3127 spin_lock_irq(&ndlp->lock);
3128 ndlp->nlp_flag |= NLP_LOGO_SND;
3129 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
3130 spin_unlock_irq(&ndlp->lock);
3131 elsiocb->context1 = lpfc_nlp_get(ndlp);
3132 if (!elsiocb->context1) {
3133 lpfc_els_free_iocb(phba, elsiocb);
3137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3138 "Issue LOGO: did:x%x refcnt %d",
3139 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3141 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3142 if (rc == IOCB_ERROR) {
3143 lpfc_els_free_iocb(phba, elsiocb);
3148 spin_lock_irq(&ndlp->lock);
3149 ndlp->nlp_prev_state = ndlp->nlp_state;
3150 spin_unlock_irq(&ndlp->lock);
3151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3155 spin_lock_irq(&ndlp->lock);
3156 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3157 spin_unlock_irq(&ndlp->lock);
3162 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3163 * @phba: pointer to lpfc hba data structure.
3164 * @cmdiocb: pointer to lpfc command iocb data structure.
3165 * @rspiocb: pointer to lpfc response iocb data structure.
3167 * This routine is a generic completion callback function for ELS commands.
3168 * Specifically, it is the callback function which does not need to perform
3169 * any command specific operations. It is currently used by the ELS command
3170 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3171 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3172 * Other than certain debug loggings, this callback function simply invokes the
3173 * lpfc_els_chk_latt() routine to check whether link went down during the
3174 * discovery process.
3177 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3178 struct lpfc_iocbq *rspiocb)
3180 struct lpfc_vport *vport = cmdiocb->vport;
3181 struct lpfc_nodelist *free_ndlp;
3183 u32 ulp_status, ulp_word4, tmo, did, iotag;
3185 ulp_status = get_job_ulpstatus(phba, rspiocb);
3186 ulp_word4 = get_job_word4(phba, rspiocb);
3187 did = get_job_els_rsp64_did(phba, cmdiocb);
3189 if (phba->sli_rev == LPFC_SLI_REV4) {
3190 tmo = get_wqe_tmo(cmdiocb);
3191 iotag = get_wqe_reqtag(cmdiocb);
3193 irsp = &rspiocb->iocb;
3194 tmo = irsp->ulpTimeout;
3195 iotag = irsp->ulpIoTag;
3198 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3199 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3200 ulp_status, ulp_word4, did);
3202 /* ELS cmd tag <ulpIoTag> completes */
3203 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3204 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3205 iotag, ulp_status, ulp_word4, tmo);
3207 /* Check to see if link went down during discovery */
3208 lpfc_els_chk_latt(vport);
3210 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3212 lpfc_els_free_iocb(phba, cmdiocb);
3213 lpfc_nlp_put(free_ndlp);
3217 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
3218 * @vport: pointer to lpfc_vport data structure.
3219 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
3221 * This routine registers the rpi assigned to the fabric controller
3222 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
3223 * state triggering a registration with the SCSI transport.
3225 * This routine is single out because the fabric controller node
3226 * does not receive a PLOGI. This routine is consumed by the
3227 * SCR and RDF ELS commands. Callers are expected to qualify
3231 lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp)
3234 struct lpfc_hba *phba = vport->phba;
3235 struct lpfc_nodelist *ns_ndlp;
3237 struct lpfc_dmabuf *mp;
3239 if (fc_ndlp->nlp_flag & NLP_RPI_REGISTERED)
3242 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
3246 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3247 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
3248 __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID,
3249 ns_ndlp->nlp_state);
3250 if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3253 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3255 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3256 "0936 %s: no memory for reg_login "
3257 "Data: x%x x%x x%x x%x\n", __func__,
3258 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3259 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3262 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID,
3263 (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi);
3269 fc_ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3270 mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login;
3271 mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp);
3272 if (!mbox->ctx_ndlp) {
3277 mbox->vport = vport;
3278 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3279 if (rc == MBX_NOT_FINISHED) {
3281 lpfc_nlp_put(fc_ndlp);
3284 /* Success path. Exit. */
3285 lpfc_nlp_set_state(vport, fc_ndlp,
3286 NLP_STE_REG_LOGIN_ISSUE);
3290 fc_ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3291 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
3292 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3296 mempool_free(mbox, phba->mbox_mem_pool);
3297 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3298 "0938 %s: failed to format reg_login "
3299 "Data: x%x x%x x%x x%x\n", __func__,
3300 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3301 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3306 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3307 * @phba: pointer to lpfc hba data structure.
3308 * @cmdiocb: pointer to lpfc command iocb data structure.
3309 * @rspiocb: pointer to lpfc response iocb data structure.
3311 * This routine is a generic completion callback function for Discovery ELS cmd.
3312 * Currently used by the ELS command issuing routines for the ELS State Change
3313 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3314 * These commands will be retried once only for ELS timeout errors.
3317 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3318 struct lpfc_iocbq *rspiocb)
3320 struct lpfc_vport *vport = cmdiocb->vport;
3322 struct lpfc_els_rdf_rsp *prdf;
3323 struct lpfc_dmabuf *pcmd, *prsp;
3326 struct lpfc_nodelist *ndlp = cmdiocb->context1;
3327 u32 ulp_status, ulp_word4, tmo, did, iotag;
3329 ulp_status = get_job_ulpstatus(phba, rspiocb);
3330 ulp_word4 = get_job_word4(phba, rspiocb);
3331 did = get_job_els_rsp64_did(phba, cmdiocb);
3333 if (phba->sli_rev == LPFC_SLI_REV4) {
3334 tmo = get_wqe_tmo(cmdiocb);
3335 iotag = get_wqe_reqtag(cmdiocb);
3337 irsp = &rspiocb->iocb;
3338 tmo = irsp->ulpTimeout;
3339 iotag = irsp->ulpIoTag;
3342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3343 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3344 ulp_status, ulp_word4, did);
3346 /* ELS cmd tag <ulpIoTag> completes */
3347 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3348 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x x%x\n",
3349 iotag, ulp_status, ulp_word4, tmo, cmdiocb->retry);
3351 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3355 pdata = (u32 *)pcmd->virt;
3360 /* Only 1 retry for ELS Timeout only */
3361 if (ulp_status == IOSTAT_LOCAL_REJECT &&
3362 ((ulp_word4 & IOERR_PARAM_MASK) ==
3363 IOERR_SEQUENCE_TIMEOUT)) {
3365 if (cmdiocb->retry <= 1) {
3368 lpfc_issue_els_scr(vport, cmdiocb->retry);
3371 lpfc_issue_els_edc(vport, cmdiocb->retry);
3374 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3375 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3380 phba->fc_stat.elsRetryExceeded++;
3382 if (cmd == ELS_CMD_EDC) {
3383 /* must be called before checking uplStatus and returning */
3384 lpfc_cmpl_els_edc(phba, cmdiocb, rspiocb);
3388 /* ELS discovery cmd completes with error */
3389 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
3390 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3391 ulp_status, ulp_word4);
3395 /* The RDF response doesn't have any impact on the running driver
3396 * but the notification descriptors are dumped here for support.
3398 if (cmd == ELS_CMD_RDF) {
3401 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3405 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3409 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3410 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3411 lpfc_printf_vlog(vport, KERN_INFO,
3412 LOG_ELS | LOG_CGN_MGMT,
3413 "4677 Fabric RDF Notification Grant "
3414 "Data: 0x%08x Reg: %x %x\n",
3416 prdf->reg_d1.desc_tags[i]),
3417 phba->cgn_reg_signal,
3418 phba->cgn_reg_fpin);
3422 /* Check to see if link went down during discovery */
3423 lpfc_els_chk_latt(vport);
3424 lpfc_els_free_iocb(phba, cmdiocb);
3430 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3431 * @vport: pointer to a host virtual N_Port data structure.
3432 * @retry: retry counter for the command IOCB.
3434 * This routine issues a State Change Request (SCR) to a fabric node
3435 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3436 * first search the @vport node list to find the matching ndlp. If no such
3437 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3438 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3439 * routine is invoked to send the SCR IOCB.
3441 * Note that the ndlp reference count will be incremented by 1 for holding the
3442 * ndlp and the reference to ndlp will be stored into the context1 field of
3443 * the IOCB for the completion callback function to the SCR ELS command.
3446 * 0 - Successfully issued scr command
3447 * 1 - Failed to issue scr command
3450 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3453 struct lpfc_hba *phba = vport->phba;
3454 struct lpfc_iocbq *elsiocb;
3457 struct lpfc_nodelist *ndlp;
3459 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3461 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3463 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3466 lpfc_enqueue_node(vport, ndlp);
3469 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3470 ndlp->nlp_DID, ELS_CMD_SCR);
3474 if (phba->sli_rev == LPFC_SLI_REV4) {
3475 rc = lpfc_reg_fab_ctrl_node(vport, ndlp);
3477 lpfc_els_free_iocb(phba, elsiocb);
3478 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3479 "0937 %s: Failed to reg fc node, rc %d\n",
3484 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3486 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3487 pcmd += sizeof(uint32_t);
3489 /* For SCR, remainder of payload is SCR parameter page */
3490 memset(pcmd, 0, sizeof(SCR));
3491 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3494 "Issue SCR: did:x%x",
3495 ndlp->nlp_DID, 0, 0);
3497 phba->fc_stat.elsXmitSCR++;
3498 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
3499 elsiocb->context1 = lpfc_nlp_get(ndlp);
3500 if (!elsiocb->context1) {
3501 lpfc_els_free_iocb(phba, elsiocb);
3505 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3506 "Issue SCR: did:x%x refcnt %d",
3507 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3509 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3510 if (rc == IOCB_ERROR) {
3511 lpfc_els_free_iocb(phba, elsiocb);
3520 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3521 * or the other nport (pt2pt).
3522 * @vport: pointer to a host virtual N_Port data structure.
3523 * @retry: number of retries to the command IOCB.
3525 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3526 * when connected to a fabric, or to the remote port when connected
3527 * in point-to-point mode. When sent to the Fabric Controller, it will
3528 * replay the RSCN to registered recipients.
3530 * Note that the ndlp reference count will be incremented by 1 for holding the
3531 * ndlp and the reference to ndlp will be stored into the context1 field of
3532 * the IOCB for the completion callback function to the RSCN ELS command.
3535 * 0 - Successfully issued RSCN command
3536 * 1 - Failed to issue RSCN command
3539 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3542 struct lpfc_hba *phba = vport->phba;
3543 struct lpfc_iocbq *elsiocb;
3544 struct lpfc_nodelist *ndlp;
3546 struct fc_els_rscn rscn;
3547 struct fc_els_rscn_page portid;
3550 uint16_t cmdsize = sizeof(*event);
3552 /* Not supported for private loop */
3553 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3554 !(vport->fc_flag & FC_PUBLIC_LOOP))
3557 if (vport->fc_flag & FC_PT2PT) {
3558 /* find any mapped nport - that would be the other nport */
3559 ndlp = lpfc_findnode_mapped(vport);
3563 nportid = FC_FID_FCTRL;
3564 /* find the fabric controller node */
3565 ndlp = lpfc_findnode_did(vport, nportid);
3567 /* if one didn't exist, make one */
3568 ndlp = lpfc_nlp_init(vport, nportid);
3571 lpfc_enqueue_node(vport, ndlp);
3575 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3576 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3581 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3583 event->rscn.rscn_cmd = ELS_RSCN;
3584 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3585 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3587 nportid = vport->fc_myDID;
3588 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3589 event->portid.rscn_page_flags = 0;
3590 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3591 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3592 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3594 phba->fc_stat.elsXmitRSCN++;
3595 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
3596 elsiocb->context1 = lpfc_nlp_get(ndlp);
3597 if (!elsiocb->context1) {
3598 lpfc_els_free_iocb(phba, elsiocb);
3602 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3603 "Issue RSCN: did:x%x",
3604 ndlp->nlp_DID, 0, 0);
3606 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3607 if (rc == IOCB_ERROR) {
3608 lpfc_els_free_iocb(phba, elsiocb);
3617 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3618 * @vport: pointer to a host virtual N_Port data structure.
3619 * @nportid: N_Port identifier to the remote node.
3620 * @retry: number of retries to the command IOCB.
3622 * This routine issues a Fibre Channel Address Resolution Response
3623 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3624 * is passed into the function. It first search the @vport node list to find
3625 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3626 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3627 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3629 * Note that the ndlp reference count will be incremented by 1 for holding the
3630 * ndlp and the reference to ndlp will be stored into the context1 field of
3631 * the IOCB for the completion callback function to the FARPR ELS command.
3634 * 0 - Successfully issued farpr command
3635 * 1 - Failed to issue farpr command
3638 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3641 struct lpfc_hba *phba = vport->phba;
3642 struct lpfc_iocbq *elsiocb;
3647 struct lpfc_nodelist *ondlp;
3648 struct lpfc_nodelist *ndlp;
3650 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3652 ndlp = lpfc_findnode_did(vport, nportid);
3654 ndlp = lpfc_nlp_init(vport, nportid);
3657 lpfc_enqueue_node(vport, ndlp);
3660 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3661 ndlp->nlp_DID, ELS_CMD_FARPR);
3665 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3667 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3668 pcmd += sizeof(uint32_t);
3670 /* Fill in FARPR payload */
3671 fp = (FARP *) (pcmd);
3672 memset(fp, 0, sizeof(FARP));
3673 lp = (uint32_t *) pcmd;
3674 *lp++ = be32_to_cpu(nportid);
3675 *lp++ = be32_to_cpu(vport->fc_myDID);
3677 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3679 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3680 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3681 ondlp = lpfc_findnode_did(vport, nportid);
3683 memcpy(&fp->OportName, &ondlp->nlp_portname,
3684 sizeof(struct lpfc_name));
3685 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3686 sizeof(struct lpfc_name));
3689 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3690 "Issue FARPR: did:x%x",
3691 ndlp->nlp_DID, 0, 0);
3693 phba->fc_stat.elsXmitFARPR++;
3694 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
3695 elsiocb->context1 = lpfc_nlp_get(ndlp);
3696 if (!elsiocb->context1) {
3697 lpfc_els_free_iocb(phba, elsiocb);
3701 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3702 if (rc == IOCB_ERROR) {
3703 /* The additional lpfc_nlp_put will cause the following
3704 * lpfc_els_free_iocb routine to trigger the release of
3707 lpfc_els_free_iocb(phba, elsiocb);
3711 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3712 * trigger the release of the node.
3714 /* Don't release reference count as RDF is likely outstanding */
3719 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3720 * @vport: pointer to a host virtual N_Port data structure.
3721 * @retry: retry counter for the command IOCB.
3723 * This routine issues an ELS RDF to the Fabric Controller to register
3724 * for diagnostic functions.
3726 * Note that the ndlp reference count will be incremented by 1 for holding the
3727 * ndlp and the reference to ndlp will be stored into the context1 field of
3728 * the IOCB for the completion callback function to the RDF ELS command.
3731 * 0 - Successfully issued rdf command
3732 * 1 - Failed to issue rdf command
3735 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3737 struct lpfc_hba *phba = vport->phba;
3738 struct lpfc_iocbq *elsiocb;
3739 struct lpfc_els_rdf_req *prdf;
3740 struct lpfc_nodelist *ndlp;
3744 cmdsize = sizeof(*prdf);
3746 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3748 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3751 lpfc_enqueue_node(vport, ndlp);
3754 /* RDF ELS is not required on an NPIV VN_Port. */
3755 if (vport->port_type == LPFC_NPIV_PORT)
3758 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3759 ndlp->nlp_DID, ELS_CMD_RDF);
3763 /* Configure the payload for the supported FPIN events. */
3764 prdf = (struct lpfc_els_rdf_req *)
3765 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3766 memset(prdf, 0, cmdsize);
3767 prdf->rdf.fpin_cmd = ELS_RDF;
3768 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3769 sizeof(struct fc_els_rdf));
3770 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3771 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3772 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3773 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3774 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3775 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3776 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3777 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3779 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3780 "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n",
3781 ndlp->nlp_DID, phba->cgn_reg_signal,
3782 phba->cgn_reg_fpin);
3784 phba->cgn_fpin_frequency = LPFC_FPIN_INIT_FREQ;
3785 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
3786 elsiocb->context1 = lpfc_nlp_get(ndlp);
3787 if (!elsiocb->context1) {
3788 lpfc_els_free_iocb(phba, elsiocb);
3792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3793 "Issue RDF: did:x%x refcnt %d",
3794 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3796 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3797 if (rc == IOCB_ERROR) {
3798 lpfc_els_free_iocb(phba, elsiocb);
3806 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
3807 * @vport: pointer to a host virtual N_Port data structure.
3808 * @cmdiocb: pointer to lpfc command iocb data structure.
3809 * @ndlp: pointer to a node-list data structure.
3811 * A received RDF implies a possible change to fabric supported diagnostic
3812 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
3813 * RDF request to reregister for supported diagnostic functions.
3817 * -EIO - Failed to process received RDF
3820 lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3821 struct lpfc_nodelist *ndlp)
3824 if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) {
3825 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3826 "1623 Failed to RDF_ACC from x%x for x%x\n",
3827 ndlp->nlp_DID, vport->fc_myDID);
3831 /* Issue new RDF for reregistering */
3832 if (lpfc_issue_els_rdf(vport, 0)) {
3833 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3834 "2623 Failed to re register RDF for x%x\n",
3843 * lpfc_least_capable_settings - helper function for EDC rsp processing
3844 * @phba: pointer to lpfc hba data structure.
3845 * @pcgd: pointer to congestion detection descriptor in EDC rsp.
3847 * This helper routine determines the least capable setting for
3848 * congestion signals, signal freq, including scale, from the
3849 * congestion detection descriptor in the EDC rsp. The routine
3850 * sets @phba values in preparation for a set_featues mailbox.
3853 lpfc_least_capable_settings(struct lpfc_hba *phba,
3854 struct fc_diag_cg_sig_desc *pcgd)
3856 u32 rsp_sig_cap = 0, drv_sig_cap = 0;
3857 u32 rsp_sig_freq_cyc = 0, rsp_sig_freq_scale = 0;
3858 struct lpfc_cgn_info *cp;
3862 /* Get rsp signal and frequency capabilities. */
3863 rsp_sig_cap = be32_to_cpu(pcgd->xmt_signal_capability);
3864 rsp_sig_freq_cyc = be16_to_cpu(pcgd->xmt_signal_frequency.count);
3865 rsp_sig_freq_scale = be16_to_cpu(pcgd->xmt_signal_frequency.units);
3867 /* If the Fport does not support signals. Set FPIN only */
3868 if (rsp_sig_cap == EDC_CG_SIG_NOTSUPPORTED)
3869 goto out_no_support;
3871 /* Apply the xmt scale to the xmt cycle to get the correct frequency.
3872 * Adapter default is 100 millisSeconds. Convert all xmt cycle values
3875 switch (rsp_sig_freq_scale) {
3876 case EDC_CG_SIGFREQ_SEC:
3877 rsp_sig_freq_cyc *= MSEC_PER_SEC;
3879 case EDC_CG_SIGFREQ_MSEC:
3880 rsp_sig_freq_cyc = 1;
3883 goto out_no_support;
3886 /* Convenient shorthand. */
3887 drv_sig_cap = phba->cgn_reg_signal;
3889 /* Choose the least capable frequency. */
3890 if (rsp_sig_freq_cyc > phba->cgn_sig_freq)
3891 phba->cgn_sig_freq = rsp_sig_freq_cyc;
3893 /* Should be some common signals support. Settle on least capable
3894 * signal and adjust FPIN values. Initialize defaults to ease the
3897 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
3898 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3899 if (rsp_sig_cap == EDC_CG_SIG_WARN_ONLY &&
3900 (drv_sig_cap == EDC_CG_SIG_WARN_ONLY ||
3901 drv_sig_cap == EDC_CG_SIG_WARN_ALARM)) {
3902 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3903 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3905 if (rsp_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3906 if (drv_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3907 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ALARM;
3908 phba->cgn_reg_fpin = LPFC_CGN_FPIN_NONE;
3910 if (drv_sig_cap == EDC_CG_SIG_WARN_ONLY) {
3911 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3912 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3919 /* Update signal frequency in congestion info buffer */
3920 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
3922 /* Frequency (in ms) Signal Warning/Signal Congestion Notifications
3923 * are received by the HBA
3925 sig_freq = phba->cgn_sig_freq;
3927 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY)
3928 cp->cgn_warn_freq = cpu_to_le16(sig_freq);
3929 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
3930 cp->cgn_alarm_freq = cpu_to_le16(sig_freq);
3931 cp->cgn_warn_freq = cpu_to_le16(sig_freq);
3933 crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
3934 cp->cgn_info_crc = cpu_to_le32(crc);
3938 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3939 phba->cgn_sig_freq = 0;
3940 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
3943 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
3944 FC_LS_TLV_DTAG_INIT);
3947 * lpfc_cmpl_els_edc - Completion callback function for EDC
3948 * @phba: pointer to lpfc hba data structure.
3949 * @cmdiocb: pointer to lpfc command iocb data structure.
3950 * @rspiocb: pointer to lpfc response iocb data structure.
3952 * This routine is the completion callback function for issuing the Exchange
3953 * Diagnostic Capabilities (EDC) command. The driver issues an EDC to
3954 * notify the FPort of its Congestion and Link Fault capabilities. This
3955 * routine parses the FPort's response and decides on the least common
3956 * values applicable to both FPort and NPort for Warnings and Alarms that
3957 * are communicated via hardware signals.
3960 lpfc_cmpl_els_edc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3961 struct lpfc_iocbq *rspiocb)
3964 struct fc_els_edc_resp *edc_rsp;
3965 struct fc_tlv_desc *tlv;
3966 struct fc_diag_cg_sig_desc *pcgd;
3967 struct fc_diag_lnkflt_desc *plnkflt;
3968 struct lpfc_dmabuf *pcmd, *prsp;
3969 const char *dtag_nm;
3971 int desc_cnt = 0, bytes_remain;
3972 bool rcv_cap_desc = false;
3973 struct lpfc_nodelist *ndlp;
3974 u32 ulp_status, ulp_word4, tmo, did, iotag;
3976 ndlp = cmdiocb->context1;
3978 ulp_status = get_job_ulpstatus(phba, rspiocb);
3979 ulp_word4 = get_job_word4(phba, rspiocb);
3980 did = get_job_els_rsp64_did(phba, rspiocb);
3982 if (phba->sli_rev == LPFC_SLI_REV4) {
3983 tmo = get_wqe_tmo(rspiocb);
3984 iotag = get_wqe_reqtag(rspiocb);
3986 irsp_iocb = &rspiocb->iocb;
3987 tmo = irsp_iocb->ulpTimeout;
3988 iotag = irsp_iocb->ulpIoTag;
3991 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
3992 "EDC cmpl: status:x%x/x%x did:x%x",
3993 ulp_status, ulp_word4, did);
3995 /* ELS cmd tag <ulpIoTag> completes */
3996 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3997 "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n",
3998 iotag, ulp_status, ulp_word4, tmo);
4000 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
4004 pdata = (u32 *)pcmd->virt;
4008 /* Need to clear signal values, send features MB and RDF with FPIN. */
4012 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
4016 edc_rsp = prsp->virt;
4020 /* ELS cmd tag <ulpIoTag> completes */
4021 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4022 "4676 Fabric EDC Rsp: "
4024 edc_rsp->acc_hdr.la_cmd,
4025 be32_to_cpu(edc_rsp->desc_list_len));
4028 * Payload length in bytes is the response descriptor list
4029 * length minus the 12 bytes of Link Service Request
4030 * Information descriptor in the reply.
4032 bytes_remain = be32_to_cpu(edc_rsp->desc_list_len) -
4033 sizeof(struct fc_els_lsri_desc);
4034 if (bytes_remain <= 0)
4037 tlv = edc_rsp->desc;
4040 * cycle through EDC diagnostic descriptors to find the
4041 * congestion signaling capability descriptor
4043 while (bytes_remain) {
4044 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
4045 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4046 "6461 Truncated TLV hdr on "
4047 "Diagnostic descriptor[%d]\n",
4052 dtag = be32_to_cpu(tlv->desc_tag);
4054 case ELS_DTAG_LNK_FAULT_CAP:
4055 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4056 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4057 sizeof(struct fc_diag_lnkflt_desc)) {
4059 phba, KERN_WARNING, LOG_CGN_MGMT,
4060 "6462 Truncated Link Fault Diagnostic "
4061 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4062 desc_cnt, bytes_remain,
4063 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4064 sizeof(struct fc_diag_cg_sig_desc));
4067 plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
4069 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4070 "4617 Link Fault Desc Data: 0x%08x 0x%08x "
4071 "0x%08x 0x%08x 0x%08x\n",
4072 be32_to_cpu(plnkflt->desc_tag),
4073 be32_to_cpu(plnkflt->desc_len),
4075 plnkflt->degrade_activate_threshold),
4077 plnkflt->degrade_deactivate_threshold),
4078 be32_to_cpu(plnkflt->fec_degrade_interval));
4080 case ELS_DTAG_CG_SIGNAL_CAP:
4081 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4082 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4083 sizeof(struct fc_diag_cg_sig_desc)) {
4085 phba, KERN_WARNING, LOG_CGN_MGMT,
4086 "6463 Truncated Cgn Signal Diagnostic "
4087 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4088 desc_cnt, bytes_remain,
4089 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4090 sizeof(struct fc_diag_cg_sig_desc));
4094 pcgd = (struct fc_diag_cg_sig_desc *)tlv;
4096 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4097 "4616 CGN Desc Data: 0x%08x 0x%08x "
4098 "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n",
4099 be32_to_cpu(pcgd->desc_tag),
4100 be32_to_cpu(pcgd->desc_len),
4101 be32_to_cpu(pcgd->xmt_signal_capability),
4102 be16_to_cpu(pcgd->xmt_signal_frequency.count),
4103 be16_to_cpu(pcgd->xmt_signal_frequency.units),
4104 be32_to_cpu(pcgd->rcv_signal_capability),
4105 be16_to_cpu(pcgd->rcv_signal_frequency.count),
4106 be16_to_cpu(pcgd->rcv_signal_frequency.units));
4108 /* Compare driver and Fport capabilities and choose
4111 lpfc_least_capable_settings(phba, pcgd);
4112 rcv_cap_desc = true;
4115 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
4116 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4117 "4919 unknown Diagnostic "
4118 "Descriptor[%d]: tag x%x (%s)\n",
4119 desc_cnt, dtag, dtag_nm);
4122 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
4123 tlv = fc_tlv_next_desc(tlv);
4128 if (!rcv_cap_desc) {
4129 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
4130 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4131 phba->cgn_sig_freq = 0;
4132 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
4133 "4202 EDC rsp error - sending RDF "
4134 "for FPIN only.\n");
4137 lpfc_config_cgn_signal(phba);
4139 /* Check to see if link went down during discovery */
4140 lpfc_els_chk_latt(phba->pport);
4141 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
4142 "EDC Cmpl: did:x%x refcnt %d",
4143 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4144 lpfc_els_free_iocb(phba, cmdiocb);
4149 lpfc_format_edc_cgn_desc(struct lpfc_hba *phba, struct fc_diag_cg_sig_desc *cgd)
4151 /* We are assuming cgd was zero'ed before calling this routine */
4153 /* Configure the congestion detection capability */
4154 cgd->desc_tag = cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP);
4156 /* Descriptor len doesn't include the tag or len fields. */
4157 cgd->desc_len = cpu_to_be32(
4158 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc));
4160 /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4161 * xmt_signal_frequency.count already set to 0.
4162 * xmt_signal_frequency.units already set to 0.
4165 if (phba->cmf_active_mode == LPFC_CFG_OFF) {
4166 /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4167 * rcv_signal_frequency.count already set to 0.
4168 * rcv_signal_frequency.units already set to 0.
4170 phba->cgn_sig_freq = 0;
4173 switch (phba->cgn_reg_signal) {
4174 case EDC_CG_SIG_WARN_ONLY:
4175 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ONLY);
4177 case EDC_CG_SIG_WARN_ALARM:
4178 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ALARM);
4181 /* rcv_signal_capability left 0 thus no support */
4185 /* We start negotiation with lpfc_fabric_cgn_frequency, after
4186 * the completion we settle on the higher frequency.
4188 cgd->rcv_signal_frequency.count =
4189 cpu_to_be16(lpfc_fabric_cgn_frequency);
4190 cgd->rcv_signal_frequency.units =
4191 cpu_to_be16(EDC_CG_SIGFREQ_MSEC);
4195 * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric.
4196 * @vport: pointer to a host virtual N_Port data structure.
4197 * @retry: retry counter for the command iocb.
4199 * This routine issues an ELS EDC to the F-Port Controller to communicate
4200 * this N_Port's support of hardware signals in its Congestion
4201 * Capabilities Descriptor.
4203 * Note: This routine does not check if one or more signals are
4204 * set in the cgn_reg_signal parameter. The caller makes the
4205 * decision to enforce cgn_reg_signal as nonzero or zero depending
4206 * on the conditions. During Fabric requests, the driver
4207 * requires cgn_reg_signals to be nonzero. But a dynamic request
4208 * to set the congestion mode to OFF from Monitor or Manage
4209 * would correctly issue an EDC with no signals enabled to
4210 * turn off switch functionality and then update the FW.
4213 * 0 - Successfully issued edc command
4214 * 1 - Failed to issue edc command
4217 lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry)
4219 struct lpfc_hba *phba = vport->phba;
4220 struct lpfc_iocbq *elsiocb;
4221 struct lpfc_els_edc_req *edc_req;
4222 struct fc_diag_cg_sig_desc *cgn_desc;
4224 struct lpfc_nodelist *ndlp;
4226 u32 edc_req_size, cgn_desc_size;
4229 if (vport->port_type == LPFC_NPIV_PORT)
4232 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4233 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
4236 /* If HBA doesn't support signals, drop into RDF */
4237 if (!phba->cgn_init_reg_signal)
4240 edc_req_size = sizeof(struct fc_els_edc);
4241 cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc);
4242 cmdsize = edc_req_size + cgn_desc_size;
4243 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
4244 ndlp->nlp_DID, ELS_CMD_EDC);
4248 /* Configure the payload for the supported Diagnostics capabilities. */
4249 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
4250 memset(pcmd, 0, cmdsize);
4251 edc_req = (struct lpfc_els_edc_req *)pcmd;
4252 edc_req->edc.desc_len = cpu_to_be32(cgn_desc_size);
4253 edc_req->edc.edc_cmd = ELS_EDC;
4255 cgn_desc = &edc_req->cgn_desc;
4257 lpfc_format_edc_cgn_desc(phba, cgn_desc);
4259 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
4261 lpfc_printf_vlog(vport, KERN_INFO, LOG_CGN_MGMT,
4262 "4623 Xmit EDC to remote "
4263 "NPORT x%x reg_sig x%x reg_fpin:x%x\n",
4264 ndlp->nlp_DID, phba->cgn_reg_signal,
4265 phba->cgn_reg_fpin);
4267 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
4268 elsiocb->context1 = lpfc_nlp_get(ndlp);
4269 if (!elsiocb->context1) {
4270 lpfc_els_free_iocb(phba, elsiocb);
4274 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4275 "Issue EDC: did:x%x refcnt %d",
4276 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4277 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4278 if (rc == IOCB_ERROR) {
4279 /* The additional lpfc_nlp_put will cause the following
4280 * lpfc_els_free_iocb routine to trigger the rlease of
4283 lpfc_els_free_iocb(phba, elsiocb);
4289 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
4290 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4291 rc = lpfc_issue_els_rdf(vport, 0);
4296 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
4297 * @vport: pointer to a host virtual N_Port data structure.
4298 * @nlp: pointer to a node-list data structure.
4300 * This routine cancels the timer with a delayed IOCB-command retry for
4301 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
4302 * removes the ELS retry event if it presents. In addition, if the
4303 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
4304 * commands are sent for the @vport's nodes that require issuing discovery
4308 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
4310 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4311 struct lpfc_work_evt *evtp;
4313 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
4315 spin_lock_irq(&nlp->lock);
4316 nlp->nlp_flag &= ~NLP_DELAY_TMO;
4317 spin_unlock_irq(&nlp->lock);
4318 del_timer_sync(&nlp->nlp_delayfunc);
4319 nlp->nlp_last_elscmd = 0;
4320 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
4321 list_del_init(&nlp->els_retry_evt.evt_listp);
4322 /* Decrement nlp reference count held for the delayed retry */
4323 evtp = &nlp->els_retry_evt;
4324 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
4326 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
4327 spin_lock_irq(&nlp->lock);
4328 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4329 spin_unlock_irq(&nlp->lock);
4330 if (vport->num_disc_nodes) {
4331 if (vport->port_state < LPFC_VPORT_READY) {
4332 /* Check if there are more ADISCs to be sent */
4333 lpfc_more_adisc(vport);
4335 /* Check if there are more PLOGIs to be sent */
4336 lpfc_more_plogi(vport);
4337 if (vport->num_disc_nodes == 0) {
4338 spin_lock_irq(shost->host_lock);
4339 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4340 spin_unlock_irq(shost->host_lock);
4341 lpfc_can_disctmo(vport);
4342 lpfc_end_rscn(vport);
4351 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
4352 * @t: pointer to the timer function associated data (ndlp).
4354 * This routine is invoked by the ndlp delayed-function timer to check
4355 * whether there is any pending ELS retry event(s) with the node. If not, it
4356 * simply returns. Otherwise, if there is at least one ELS delayed event, it
4357 * adds the delayed events to the HBA work list and invokes the
4358 * lpfc_worker_wake_up() routine to wake up worker thread to process the
4359 * event. Note that lpfc_nlp_get() is called before posting the event to
4360 * the work list to hold reference count of ndlp so that it guarantees the
4361 * reference to ndlp will still be available when the worker thread gets
4362 * to the event associated with the ndlp.
4365 lpfc_els_retry_delay(struct timer_list *t)
4367 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
4368 struct lpfc_vport *vport = ndlp->vport;
4369 struct lpfc_hba *phba = vport->phba;
4370 unsigned long flags;
4371 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
4373 spin_lock_irqsave(&phba->hbalock, flags);
4374 if (!list_empty(&evtp->evt_listp)) {
4375 spin_unlock_irqrestore(&phba->hbalock, flags);
4379 /* We need to hold the node by incrementing the reference
4380 * count until the queued work is done
4382 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
4383 if (evtp->evt_arg1) {
4384 evtp->evt = LPFC_EVT_ELS_RETRY;
4385 list_add_tail(&evtp->evt_listp, &phba->work_list);
4386 lpfc_worker_wake_up(phba);
4388 spin_unlock_irqrestore(&phba->hbalock, flags);
4393 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
4394 * @ndlp: pointer to a node-list data structure.
4396 * This routine is the worker-thread handler for processing the @ndlp delayed
4397 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
4398 * the last ELS command from the associated ndlp and invokes the proper ELS
4399 * function according to the delayed ELS command to retry the command.
4402 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
4404 struct lpfc_vport *vport = ndlp->vport;
4405 uint32_t cmd, retry;
4407 spin_lock_irq(&ndlp->lock);
4408 cmd = ndlp->nlp_last_elscmd;
4409 ndlp->nlp_last_elscmd = 0;
4411 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
4412 spin_unlock_irq(&ndlp->lock);
4416 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4417 spin_unlock_irq(&ndlp->lock);
4419 * If a discovery event readded nlp_delayfunc after timer
4420 * firing and before processing the timer, cancel the
4423 del_timer_sync(&ndlp->nlp_delayfunc);
4424 retry = ndlp->nlp_retry;
4425 ndlp->nlp_retry = 0;
4429 lpfc_issue_els_flogi(vport, ndlp, retry);
4432 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
4433 ndlp->nlp_prev_state = ndlp->nlp_state;
4434 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4438 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
4439 ndlp->nlp_prev_state = ndlp->nlp_state;
4440 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4444 case ELS_CMD_NVMEPRLI:
4445 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
4446 ndlp->nlp_prev_state = ndlp->nlp_state;
4447 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4451 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
4452 ndlp->nlp_prev_state = ndlp->nlp_state;
4453 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4457 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
4458 lpfc_issue_els_fdisc(vport, ndlp, retry);
4465 * lpfc_link_reset - Issue link reset
4466 * @vport: pointer to a virtual N_Port data structure.
4468 * This routine performs link reset by sending INIT_LINK mailbox command.
4469 * For SLI-3 adapter, link attention interrupt is enabled before issuing
4470 * INIT_LINK mailbox command.
4473 * 0 - Link reset initiated successfully
4474 * 1 - Failed to initiate link reset
4477 lpfc_link_reset(struct lpfc_vport *vport)
4479 struct lpfc_hba *phba = vport->phba;
4484 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4485 "2851 Attempt link reset\n");
4486 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4488 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4489 "2852 Failed to allocate mbox memory");
4493 /* Enable Link attention interrupts */
4494 if (phba->sli_rev <= LPFC_SLI_REV3) {
4495 spin_lock_irq(&phba->hbalock);
4496 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4497 control = readl(phba->HCregaddr);
4498 control |= HC_LAINT_ENA;
4499 writel(control, phba->HCregaddr);
4500 readl(phba->HCregaddr); /* flush */
4501 spin_unlock_irq(&phba->hbalock);
4504 lpfc_init_link(phba, mbox, phba->cfg_topology,
4505 phba->cfg_link_speed);
4506 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4507 mbox->vport = vport;
4508 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4509 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
4510 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4511 "2853 Failed to issue INIT_LINK "
4512 "mbox command, rc:x%x\n", rc);
4513 mempool_free(mbox, phba->mbox_mem_pool);
4521 * lpfc_els_retry - Make retry decision on an els command iocb
4522 * @phba: pointer to lpfc hba data structure.
4523 * @cmdiocb: pointer to lpfc command iocb data structure.
4524 * @rspiocb: pointer to lpfc response iocb data structure.
4526 * This routine makes a retry decision on an ELS command IOCB, which has
4527 * failed. The following ELS IOCBs use this function for retrying the command
4528 * when previously issued command responsed with error status: FLOGI, PLOGI,
4529 * PRLI, ADISC and FDISC. Based on the ELS command type and the
4530 * returned error status, it makes the decision whether a retry shall be
4531 * issued for the command, and whether a retry shall be made immediately or
4532 * delayed. In the former case, the corresponding ELS command issuing-function
4533 * is called to retry the command. In the later case, the ELS command shall
4534 * be posted to the ndlp delayed event and delayed function timer set to the
4535 * ndlp for the delayed command issusing.
4538 * 0 - No retry of els command is made
4539 * 1 - Immediate or delayed retry of els command is made
4542 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4543 struct lpfc_iocbq *rspiocb)
4545 struct lpfc_vport *vport = cmdiocb->vport;
4546 union lpfc_wqe128 *irsp = &rspiocb->wqe;
4547 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4548 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4551 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
4555 int link_reset = 0, rc;
4556 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
4557 u32 ulp_word4 = get_job_word4(phba, rspiocb);
4560 /* Note: context2 may be 0 for internal driver abort
4561 * of delays ELS command.
4564 if (pcmd && pcmd->virt) {
4565 elscmd = (uint32_t *) (pcmd->virt);
4570 did = ndlp->nlp_DID;
4572 /* We should only hit this case for retrying PLOGI */
4573 did = get_job_els_rsp64_did(phba, rspiocb);
4574 ndlp = lpfc_findnode_did(vport, did);
4575 if (!ndlp && (cmd != ELS_CMD_PLOGI))
4579 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4580 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
4581 *(((uint32_t *)irsp) + 7), ulp_word4, did);
4583 switch (ulp_status) {
4584 case IOSTAT_FCP_RSP_ERROR:
4586 case IOSTAT_REMOTE_STOP:
4587 if (phba->sli_rev == LPFC_SLI_REV4) {
4588 /* This IO was aborted by the target, we don't
4589 * know the rxid and because we did not send the
4590 * ABTS we cannot generate and RRQ.
4592 lpfc_set_rrq_active(phba, ndlp,
4593 cmdiocb->sli4_lxritag, 0, 0);
4596 case IOSTAT_LOCAL_REJECT:
4597 switch ((ulp_word4 & IOERR_PARAM_MASK)) {
4598 case IOERR_LOOP_OPEN_FAILURE:
4599 if (cmd == ELS_CMD_FLOGI) {
4600 if (PCI_DEVICE_ID_HORNET ==
4601 phba->pcidev->device) {
4602 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
4603 phba->pport->fc_myDID = 0;
4604 phba->alpa_map[0] = 0;
4605 phba->alpa_map[1] = 0;
4608 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
4613 case IOERR_ILLEGAL_COMMAND:
4614 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4615 "0124 Retry illegal cmd x%x "
4616 "retry:x%x delay:x%x\n",
4617 cmd, cmdiocb->retry, delay);
4619 /* All command's retry policy */
4621 if (cmdiocb->retry > 2)
4625 case IOERR_NO_RESOURCES:
4626 logerr = 1; /* HBA out of resources */
4628 if (cmdiocb->retry > 100)
4633 case IOERR_ILLEGAL_FRAME:
4638 case IOERR_INVALID_RPI:
4639 if (cmd == ELS_CMD_PLOGI &&
4640 did == NameServer_DID) {
4641 /* Continue forever if plogi to */
4642 /* the nameserver fails */
4649 case IOERR_SEQUENCE_TIMEOUT:
4650 if (cmd == ELS_CMD_PLOGI &&
4651 did == NameServer_DID &&
4652 (cmdiocb->retry + 1) == maxretry) {
4653 /* Reset the Link */
4660 case IOERR_SLI_ABORTED:
4661 /* Retry ELS PLOGI command?
4662 * Possibly the rport just wasn't ready.
4664 if (cmd == ELS_CMD_PLOGI) {
4665 /* No retry if state change */
4667 ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
4676 case IOSTAT_NPORT_RJT:
4677 case IOSTAT_FABRIC_RJT:
4678 if (ulp_word4 & RJT_UNAVAIL_TEMP) {
4684 case IOSTAT_NPORT_BSY:
4685 case IOSTAT_FABRIC_BSY:
4686 logerr = 1; /* Fabric / Remote NPort out of resources */
4691 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
4692 /* Added for Vendor specifc support
4693 * Just keep retrying for these Rsn / Exp codes
4695 if ((vport->fc_flag & FC_PT2PT) &&
4696 cmd == ELS_CMD_NVMEPRLI) {
4697 switch (stat.un.b.lsRjtRsnCode) {
4698 case LSRJT_UNABLE_TPC:
4699 case LSRJT_INVALID_CMD:
4700 case LSRJT_LOGICAL_ERR:
4701 case LSRJT_CMD_UNSUPPORTED:
4702 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
4703 "0168 NVME PRLI LS_RJT "
4704 "reason %x port doesn't "
4705 "support NVME, disabling NVME\n",
4706 stat.un.b.lsRjtRsnCode);
4708 vport->fc_flag |= FC_PT2PT_NO_NVME;
4712 switch (stat.un.b.lsRjtRsnCode) {
4713 case LSRJT_UNABLE_TPC:
4714 /* The driver has a VALID PLOGI but the rport has
4715 * rejected the PRLI - can't do it now. Delay
4716 * for 1 second and try again.
4718 * However, if explanation is REQ_UNSUPPORTED there's
4719 * no point to retry PRLI.
4721 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
4722 stat.un.b.lsRjtRsnCodeExp !=
4723 LSEXP_REQ_UNSUPPORTED) {
4725 maxretry = lpfc_max_els_tries + 1;
4730 /* Legacy bug fix code for targets with PLOGI delays. */
4731 if (stat.un.b.lsRjtRsnCodeExp ==
4732 LSEXP_CMD_IN_PROGRESS) {
4733 if (cmd == ELS_CMD_PLOGI) {
4740 if (stat.un.b.lsRjtRsnCodeExp ==
4741 LSEXP_CANT_GIVE_DATA) {
4742 if (cmd == ELS_CMD_PLOGI) {
4749 if (cmd == ELS_CMD_PLOGI) {
4751 maxretry = lpfc_max_els_tries + 1;
4755 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4756 (cmd == ELS_CMD_FDISC) &&
4757 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
4758 lpfc_printf_vlog(vport, KERN_ERR,
4760 "0125 FDISC Failed (x%x). "
4761 "Fabric out of resources\n",
4762 stat.un.lsRjtError);
4763 lpfc_vport_set_state(vport,
4764 FC_VPORT_NO_FABRIC_RSCS);
4768 case LSRJT_LOGICAL_BSY:
4769 if ((cmd == ELS_CMD_PLOGI) ||
4770 (cmd == ELS_CMD_PRLI) ||
4771 (cmd == ELS_CMD_NVMEPRLI)) {
4774 } else if (cmd == ELS_CMD_FDISC) {
4775 /* FDISC retry policy */
4777 if (cmdiocb->retry >= 32)
4783 case LSRJT_LOGICAL_ERR:
4784 /* There are some cases where switches return this
4785 * error when they are not ready and should be returning
4786 * Logical Busy. We should delay every time.
4788 if (cmd == ELS_CMD_FDISC &&
4789 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4793 } else if (cmd == ELS_CMD_FLOGI &&
4794 stat.un.b.lsRjtRsnCodeExp ==
4795 LSEXP_NOTHING_MORE) {
4796 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4798 lpfc_printf_vlog(vport, KERN_ERR,
4800 "0820 FLOGI Failed (x%x). "
4801 "BBCredit Not Supported\n",
4802 stat.un.lsRjtError);
4806 case LSRJT_PROTOCOL_ERR:
4807 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4808 (cmd == ELS_CMD_FDISC) &&
4809 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4810 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4812 lpfc_printf_vlog(vport, KERN_ERR,
4814 "0122 FDISC Failed (x%x). "
4815 "Fabric Detected Bad WWN\n",
4816 stat.un.lsRjtError);
4817 lpfc_vport_set_state(vport,
4818 FC_VPORT_FABRIC_REJ_WWN);
4821 case LSRJT_VENDOR_UNIQUE:
4822 if ((stat.un.b.vendorUnique == 0x45) &&
4823 (cmd == ELS_CMD_FLOGI)) {
4827 case LSRJT_CMD_UNSUPPORTED:
4828 /* lpfc nvmet returns this type of LS_RJT when it
4829 * receives an FCP PRLI because lpfc nvmet only
4830 * support NVME. ELS request is terminated for FCP4
4833 if (stat.un.b.lsRjtRsnCodeExp ==
4834 LSEXP_REQ_UNSUPPORTED) {
4835 if (cmd == ELS_CMD_PRLI) {
4836 spin_lock_irq(&ndlp->lock);
4837 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4838 spin_unlock_irq(&ndlp->lock);
4847 case IOSTAT_INTERMED_RSP:
4856 rc = lpfc_link_reset(vport);
4858 /* Do not give up. Retry PLOGI one more time and attempt
4859 * link reset if PLOGI fails again.
4868 if (did == FDMI_DID)
4871 if ((cmd == ELS_CMD_FLOGI) &&
4872 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4873 !lpfc_error_lost_link(ulp_status, ulp_word4)) {
4874 /* FLOGI retry policy */
4876 /* retry FLOGI forever */
4877 if (phba->link_flag != LS_LOOPBACK_MODE)
4882 if (cmdiocb->retry >= 100)
4884 else if (cmdiocb->retry >= 32)
4886 } else if ((cmd == ELS_CMD_FDISC) &&
4887 !lpfc_error_lost_link(ulp_status, ulp_word4)) {
4888 /* retry FDISCs every second up to devloss */
4890 maxretry = vport->cfg_devloss_tmo;
4895 if (maxretry && (cmdiocb->retry >= maxretry)) {
4896 phba->fc_stat.elsRetryExceeded++;
4900 if ((vport->load_flag & FC_UNLOADING) != 0)
4905 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4906 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4907 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4908 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4909 "2849 Stop retry ELS command "
4910 "x%x to remote NPORT x%x, "
4911 "Data: x%x x%x\n", cmd, did,
4912 cmdiocb->retry, delay);
4917 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4918 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4919 "0107 Retry ELS command x%x to remote "
4920 "NPORT x%x Data: x%x x%x\n",
4921 cmd, did, cmdiocb->retry, delay);
4923 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4924 ((ulp_status != IOSTAT_LOCAL_REJECT) ||
4925 ((ulp_word4 & IOERR_PARAM_MASK) !=
4926 IOERR_NO_RESOURCES))) {
4927 /* Don't reset timer for no resources */
4929 /* If discovery / RSCN timer is running, reset it */
4930 if (timer_pending(&vport->fc_disctmo) ||
4931 (vport->fc_flag & FC_RSCN_MODE))
4932 lpfc_set_disctmo(vport);
4935 phba->fc_stat.elsXmitRetry++;
4936 if (ndlp && delay) {
4937 phba->fc_stat.elsDelayRetry++;
4938 ndlp->nlp_retry = cmdiocb->retry;
4940 /* delay is specified in milliseconds */
4941 mod_timer(&ndlp->nlp_delayfunc,
4942 jiffies + msecs_to_jiffies(delay));
4943 spin_lock_irq(&ndlp->lock);
4944 ndlp->nlp_flag |= NLP_DELAY_TMO;
4945 spin_unlock_irq(&ndlp->lock);
4947 ndlp->nlp_prev_state = ndlp->nlp_state;
4948 if ((cmd == ELS_CMD_PRLI) ||
4949 (cmd == ELS_CMD_NVMEPRLI))
4950 lpfc_nlp_set_state(vport, ndlp,
4951 NLP_STE_PRLI_ISSUE);
4952 else if (cmd != ELS_CMD_ADISC)
4953 lpfc_nlp_set_state(vport, ndlp,
4955 ndlp->nlp_last_elscmd = cmd;
4961 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4964 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4968 ndlp->nlp_prev_state = ndlp->nlp_state;
4969 lpfc_nlp_set_state(vport, ndlp,
4970 NLP_STE_PLOGI_ISSUE);
4972 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4975 ndlp->nlp_prev_state = ndlp->nlp_state;
4976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4977 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4980 case ELS_CMD_NVMEPRLI:
4981 ndlp->nlp_prev_state = ndlp->nlp_state;
4982 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4983 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4986 ndlp->nlp_prev_state = ndlp->nlp_state;
4987 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4988 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4992 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4994 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4995 "0137 No retry ELS command x%x to remote "
4996 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4997 cmd, did, ulp_status,
5001 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5002 "0108 No retry ELS command x%x to remote "
5003 "NPORT x%x Retried:%d Error:x%x/%x\n",
5004 cmd, did, cmdiocb->retry, ulp_status,
5011 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
5012 * @phba: pointer to lpfc hba data structure.
5013 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
5015 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
5016 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
5017 * checks to see whether there is a lpfc DMA buffer associated with the
5018 * response of the command IOCB. If so, it will be released before releasing
5019 * the lpfc DMA buffer associated with the IOCB itself.
5022 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5025 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
5027 struct lpfc_dmabuf *buf_ptr;
5029 /* Free the response before processing the command. */
5030 if (!list_empty(&buf_ptr1->list)) {
5031 list_remove_head(&buf_ptr1->list, buf_ptr,
5034 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5037 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
5043 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
5044 * @phba: pointer to lpfc hba data structure.
5045 * @buf_ptr: pointer to the lpfc dma buffer data structure.
5047 * This routine releases the lpfc Direct Memory Access (DMA) buffer
5048 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
5052 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5055 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
5057 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5063 * lpfc_els_free_iocb - Free a command iocb and its associated resources
5064 * @phba: pointer to lpfc hba data structure.
5065 * @elsiocb: pointer to lpfc els command iocb data structure.
5067 * This routine frees a command IOCB and its associated resources. The
5068 * command IOCB data structure contains the reference to various associated
5069 * resources, these fields must be set to NULL if the associated reference
5071 * context1 - reference to ndlp
5072 * context2 - reference to cmd
5073 * context2->next - reference to rsp
5074 * context3 - reference to bpl
5076 * It first properly decrements the reference count held on ndlp for the
5077 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
5078 * set, it invokes the lpfc_els_free_data() routine to release the Direct
5079 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
5080 * adds the DMA buffer the @phba data structure for the delayed release.
5081 * If reference to the Buffer Pointer List (BPL) is present, the
5082 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
5083 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
5084 * invoked to release the IOCB data structure back to @phba IOCBQ list.
5087 * 0 - Success (currently, always return 0)
5090 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
5092 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
5094 /* The I/O iocb is complete. Clear the context1 data. */
5095 elsiocb->context1 = NULL;
5097 /* context2 = cmd, context2->next = rsp, context3 = bpl */
5098 if (elsiocb->context2) {
5099 if (elsiocb->cmd_flag & LPFC_DELAY_MEM_FREE) {
5100 /* Firmware could still be in progress of DMAing
5101 * payload, so don't free data buffer till after
5104 elsiocb->cmd_flag &= ~LPFC_DELAY_MEM_FREE;
5105 buf_ptr = elsiocb->context2;
5106 elsiocb->context2 = NULL;
5109 spin_lock_irq(&phba->hbalock);
5110 if (!list_empty(&buf_ptr->list)) {
5111 list_remove_head(&buf_ptr->list,
5112 buf_ptr1, struct lpfc_dmabuf,
5114 INIT_LIST_HEAD(&buf_ptr1->list);
5115 list_add_tail(&buf_ptr1->list,
5119 INIT_LIST_HEAD(&buf_ptr->list);
5120 list_add_tail(&buf_ptr->list, &phba->elsbuf);
5122 spin_unlock_irq(&phba->hbalock);
5125 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
5126 lpfc_els_free_data(phba, buf_ptr1);
5127 elsiocb->context2 = NULL;
5131 if (elsiocb->context3) {
5132 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
5133 lpfc_els_free_bpl(phba, buf_ptr);
5134 elsiocb->context3 = NULL;
5136 lpfc_sli_release_iocbq(phba, elsiocb);
5141 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
5142 * @phba: pointer to lpfc hba data structure.
5143 * @cmdiocb: pointer to lpfc command iocb data structure.
5144 * @rspiocb: pointer to lpfc response iocb data structure.
5146 * This routine is the completion callback function to the Logout (LOGO)
5147 * Accept (ACC) Response ELS command. This routine is invoked to indicate
5148 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
5149 * release the ndlp if it has the last reference remaining (reference count
5150 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
5151 * field to NULL to inform the following lpfc_els_free_iocb() routine no
5152 * ndlp reference count needs to be decremented. Otherwise, the ndlp
5153 * reference use-count shall be decremented by the lpfc_els_free_iocb()
5154 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
5155 * IOCB data structure.
5158 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5159 struct lpfc_iocbq *rspiocb)
5161 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5162 struct lpfc_vport *vport = cmdiocb->vport;
5163 u32 ulp_status, ulp_word4;
5165 ulp_status = get_job_ulpstatus(phba, rspiocb);
5166 ulp_word4 = get_job_word4(phba, rspiocb);
5168 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5169 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
5170 ulp_status, ulp_word4, ndlp->nlp_DID);
5171 /* ACC to LOGO completes to NPort <nlp_DID> */
5172 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5173 "0109 ACC to LOGO completes to NPort x%x refcnt %d "
5174 "Data: x%x x%x x%x\n",
5175 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
5176 ndlp->nlp_state, ndlp->nlp_rpi);
5178 /* This clause allows the LOGO ACC to complete and free resources
5179 * for the Fabric Domain Controller. It does deliberately skip
5180 * the unreg_rpi and release rpi because some fabrics send RDP
5181 * requests after logging out from the initiator.
5183 if (ndlp->nlp_type & NLP_FABRIC &&
5184 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
5187 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
5188 /* If PLOGI is being retried, PLOGI completion will cleanup the
5189 * node. The NLP_NPR_2B_DISC flag needs to be retained to make
5190 * progress on nodes discovered from last RSCN.
5192 if ((ndlp->nlp_flag & NLP_DELAY_TMO) &&
5193 (ndlp->nlp_last_elscmd == ELS_CMD_PLOGI))
5196 /* NPort Recovery mode or node is just allocated */
5197 if (!lpfc_nlp_not_used(ndlp)) {
5198 /* A LOGO is completing and the node is in NPR state.
5199 * Just unregister the RPI because the node is still
5202 lpfc_unreg_rpi(vport, ndlp);
5204 /* Indicate the node has already released, should
5205 * not reference to it from within lpfc_els_free_iocb.
5207 cmdiocb->context1 = NULL;
5212 * The driver received a LOGO from the rport and has ACK'd it.
5213 * At this point, the driver is done so release the IOCB
5215 lpfc_els_free_iocb(phba, cmdiocb);
5220 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
5221 * @phba: pointer to lpfc hba data structure.
5222 * @pmb: pointer to the driver internal queue element for mailbox command.
5224 * This routine is the completion callback function for unregister default
5225 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
5226 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
5227 * decrements the ndlp reference count held for this completion callback
5228 * function. After that, it invokes the lpfc_nlp_not_used() to check
5229 * whether there is only one reference left on the ndlp. If so, it will
5230 * perform one more decrement and trigger the release of the ndlp.
5233 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5235 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
5236 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
5237 u32 mbx_flag = pmb->mbox_flag;
5238 u32 mbx_cmd = pmb->u.mb.mbxCommand;
5240 pmb->ctx_buf = NULL;
5241 pmb->ctx_ndlp = NULL;
5244 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5245 "0006 rpi x%x DID:%x flg:%x %d x%px "
5246 "mbx_cmd x%x mbx_flag x%x x%px\n",
5247 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5248 kref_read(&ndlp->kref), ndlp, mbx_cmd,
5251 /* This ends the default/temporary RPI cleanup logic for this
5252 * ndlp and the node and rpi needs to be released. Free the rpi
5253 * first on an UNREG_LOGIN and then release the final
5256 spin_lock_irq(&ndlp->lock);
5257 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
5258 if (mbx_cmd == MBX_UNREG_LOGIN)
5259 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5260 spin_unlock_irq(&ndlp->lock);
5262 lpfc_drop_node(ndlp->vport, ndlp);
5265 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5267 mempool_free(pmb, phba->mbox_mem_pool);
5272 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
5273 * @phba: pointer to lpfc hba data structure.
5274 * @cmdiocb: pointer to lpfc command iocb data structure.
5275 * @rspiocb: pointer to lpfc response iocb data structure.
5277 * This routine is the completion callback function for ELS Response IOCB
5278 * command. In normal case, this callback function just properly sets the
5279 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
5280 * field in the command IOCB is not NULL, the referred mailbox command will
5281 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
5285 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5286 struct lpfc_iocbq *rspiocb)
5288 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5289 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
5290 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
5292 LPFC_MBOXQ_t *mbox = NULL;
5293 struct lpfc_dmabuf *mp = NULL;
5294 u32 ulp_status, ulp_word4, tmo, did, iotag;
5297 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5298 "3177 ELS response failed\n");
5301 if (cmdiocb->context_un.mbox)
5302 mbox = cmdiocb->context_un.mbox;
5304 ulp_status = get_job_ulpstatus(phba, rspiocb);
5305 ulp_word4 = get_job_word4(phba, rspiocb);
5306 did = get_job_els_rsp64_did(phba, cmdiocb);
5308 if (phba->sli_rev == LPFC_SLI_REV4) {
5309 tmo = get_wqe_tmo(cmdiocb);
5310 iotag = get_wqe_reqtag(cmdiocb);
5312 irsp = &rspiocb->iocb;
5313 tmo = irsp->ulpTimeout;
5314 iotag = irsp->ulpIoTag;
5317 /* Check to see if link went down during discovery */
5318 if (!ndlp || lpfc_els_chk_latt(vport)) {
5320 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
5322 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5325 mempool_free(mbox, phba->mbox_mem_pool);
5330 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5331 "ELS rsp cmpl: status:x%x/x%x did:x%x",
5332 ulp_status, ulp_word4, did);
5333 /* ELS response tag <ulpIoTag> completes */
5334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5335 "0110 ELS response tag x%x completes "
5336 "Data: x%x x%x x%x x%x x%x x%x x%x x%x %p %p\n",
5337 iotag, ulp_status, ulp_word4, tmo,
5338 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5339 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox, ndlp);
5342 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
5343 if (!lpfc_unreg_rpi(vport, ndlp) &&
5344 (!(vport->fc_flag & FC_PT2PT))) {
5345 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5347 NLP_STE_REG_LOGIN_ISSUE) {
5348 lpfc_printf_vlog(vport, KERN_INFO,
5352 "Data: x%x x%x x%x\n",
5359 lpfc_mbuf_free(phba, mp->virt,
5363 mempool_free(mbox, phba->mbox_mem_pool);
5368 /* Increment reference count to ndlp to hold the
5369 * reference to ndlp for the callback function.
5371 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5372 if (!mbox->ctx_ndlp)
5375 mbox->vport = vport;
5376 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
5377 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5378 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5381 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
5382 ndlp->nlp_prev_state = ndlp->nlp_state;
5383 lpfc_nlp_set_state(vport, ndlp,
5384 NLP_STE_REG_LOGIN_ISSUE);
5387 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
5388 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5389 != MBX_NOT_FINISHED)
5392 /* Decrement the ndlp reference count we
5393 * set for this failed mailbox command.
5396 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
5398 /* ELS rsp: Cannot issue reg_login for <NPortid> */
5399 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5400 "0138 ELS rsp: Cannot issue reg_login for x%x "
5401 "Data: x%x x%x x%x\n",
5402 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5405 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
5407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5410 mempool_free(mbox, phba->mbox_mem_pool);
5413 if (ndlp && shost) {
5414 spin_lock_irq(&ndlp->lock);
5416 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
5417 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
5418 spin_unlock_irq(&ndlp->lock);
5421 /* An SLI4 NPIV instance wants to drop the node at this point under
5422 * these conditions and release the RPI.
5424 if (phba->sli_rev == LPFC_SLI_REV4 &&
5425 (vport && vport->port_type == LPFC_NPIV_PORT) &&
5426 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD) &&
5427 ndlp->nlp_flag & NLP_RELEASE_RPI) {
5428 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE &&
5429 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
5430 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
5431 spin_lock_irq(&ndlp->lock);
5432 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5433 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5434 spin_unlock_irq(&ndlp->lock);
5435 lpfc_drop_node(vport, ndlp);
5439 /* Release the originating I/O reference. */
5440 lpfc_els_free_iocb(phba, cmdiocb);
5446 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
5447 * @vport: pointer to a host virtual N_Port data structure.
5448 * @flag: the els command code to be accepted.
5449 * @oldiocb: pointer to the original lpfc command iocb data structure.
5450 * @ndlp: pointer to a node-list data structure.
5451 * @mbox: pointer to the driver internal queue element for mailbox command.
5453 * This routine prepares and issues an Accept (ACC) response IOCB
5454 * command. It uses the @flag to properly set up the IOCB field for the
5455 * specific ACC response command to be issued and invokes the
5456 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
5457 * @mbox pointer is passed in, it will be put into the context_un.mbox
5458 * field of the IOCB for the completion callback function to issue the
5459 * mailbox command to the HBA later when callback is invoked.
5461 * Note that the ndlp reference count will be incremented by 1 for holding the
5462 * ndlp and the reference to ndlp will be stored into the context1 field of
5463 * the IOCB for the completion callback function to the corresponding
5464 * response ELS IOCB command.
5467 * 0 - Successfully issued acc response
5468 * 1 - Failed to issue acc response
5471 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
5472 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5475 struct lpfc_hba *phba = vport->phba;
5478 union lpfc_wqe128 *wqe;
5479 union lpfc_wqe128 *oldwqe = &oldiocb->wqe;
5480 struct lpfc_iocbq *elsiocb;
5482 struct serv_parm *sp;
5485 ELS_PKT *els_pkt_ptr;
5486 struct fc_els_rdf_resp *rdf_resp;
5490 cmdsize = sizeof(uint32_t);
5491 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5492 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5494 spin_lock_irq(&ndlp->lock);
5495 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5496 spin_unlock_irq(&ndlp->lock);
5500 if (phba->sli_rev == LPFC_SLI_REV4) {
5501 wqe = &elsiocb->wqe;
5503 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5504 bf_get(wqe_ctxt_tag,
5505 &oldwqe->xmit_els_rsp.wqe_com));
5508 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5510 &oldwqe->xmit_els_rsp.wqe_com));
5512 icmd = &elsiocb->iocb;
5513 oldcmd = &oldiocb->iocb;
5514 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5515 icmd->unsli3.rcvsli3.ox_id =
5516 oldcmd->unsli3.rcvsli3.ox_id;
5519 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5520 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5521 pcmd += sizeof(uint32_t);
5523 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5524 "Issue ACC: did:x%x flg:x%x",
5525 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5529 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
5530 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5531 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5535 if (phba->sli_rev == LPFC_SLI_REV4) {
5536 wqe = &elsiocb->wqe;
5538 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5539 bf_get(wqe_ctxt_tag,
5540 &oldwqe->xmit_els_rsp.wqe_com));
5543 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5545 &oldwqe->xmit_els_rsp.wqe_com));
5547 icmd = &elsiocb->iocb;
5548 oldcmd = &oldiocb->iocb;
5549 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5550 icmd->unsli3.rcvsli3.ox_id =
5551 oldcmd->unsli3.rcvsli3.ox_id;
5554 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5557 elsiocb->context_un.mbox = mbox;
5559 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5560 pcmd += sizeof(uint32_t);
5561 sp = (struct serv_parm *)pcmd;
5563 if (flag == ELS_CMD_FLOGI) {
5564 /* Copy the received service parameters back */
5565 memcpy(sp, &phba->fc_fabparam,
5566 sizeof(struct serv_parm));
5568 /* Clear the F_Port bit */
5571 /* Mark all class service parameters as invalid */
5572 sp->cls1.classValid = 0;
5573 sp->cls2.classValid = 0;
5574 sp->cls3.classValid = 0;
5575 sp->cls4.classValid = 0;
5577 /* Copy our worldwide names */
5578 memcpy(&sp->portName, &vport->fc_sparam.portName,
5579 sizeof(struct lpfc_name));
5580 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
5581 sizeof(struct lpfc_name));
5583 memcpy(pcmd, &vport->fc_sparam,
5584 sizeof(struct serv_parm));
5586 sp->cmn.valid_vendor_ver_level = 0;
5587 memset(sp->un.vendorVersion, 0,
5588 sizeof(sp->un.vendorVersion));
5589 sp->cmn.bbRcvSizeMsb &= 0xF;
5591 /* If our firmware supports this feature, convey that
5592 * info to the target using the vendor specific field.
5594 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
5595 sp->cmn.valid_vendor_ver_level = 1;
5596 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
5598 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
5602 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5603 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
5604 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5607 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
5608 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5609 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
5613 if (phba->sli_rev == LPFC_SLI_REV4) {
5614 wqe = &elsiocb->wqe;
5616 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5617 bf_get(wqe_ctxt_tag,
5618 &oldwqe->xmit_els_rsp.wqe_com));
5621 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5623 &oldwqe->xmit_els_rsp.wqe_com));
5625 icmd = &elsiocb->iocb;
5626 oldcmd = &oldiocb->iocb;
5627 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5628 icmd->unsli3.rcvsli3.ox_id =
5629 oldcmd->unsli3.rcvsli3.ox_id;
5632 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5634 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
5635 sizeof(uint32_t) + sizeof(PRLO));
5636 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
5637 els_pkt_ptr = (ELS_PKT *) pcmd;
5638 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
5640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5641 "Issue ACC PRLO: did:x%x flg:x%x",
5642 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5645 cmdsize = sizeof(*rdf_resp);
5646 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5647 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5651 if (phba->sli_rev == LPFC_SLI_REV4) {
5652 wqe = &elsiocb->wqe;
5654 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5655 bf_get(wqe_ctxt_tag,
5656 &oldwqe->xmit_els_rsp.wqe_com));
5659 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5661 &oldwqe->xmit_els_rsp.wqe_com));
5663 icmd = &elsiocb->iocb;
5664 oldcmd = &oldiocb->iocb;
5665 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5666 icmd->unsli3.rcvsli3.ox_id =
5667 oldcmd->unsli3.rcvsli3.ox_id;
5670 pcmd = (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5671 rdf_resp = (struct fc_els_rdf_resp *)pcmd;
5672 memset(rdf_resp, 0, sizeof(*rdf_resp));
5673 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC;
5675 /* FC-LS-5 specifies desc_list_len shall be set to 12 */
5676 rdf_resp->desc_list_len = cpu_to_be32(12);
5678 /* FC-LS-5 specifies LS REQ Information descriptor */
5679 rdf_resp->lsri.desc_tag = cpu_to_be32(1);
5680 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32));
5681 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF;
5686 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
5687 spin_lock_irq(&ndlp->lock);
5688 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5689 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
5690 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5691 spin_unlock_irq(&ndlp->lock);
5692 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo_acc;
5694 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5697 phba->fc_stat.elsXmitACC++;
5698 elsiocb->context1 = lpfc_nlp_get(ndlp);
5699 if (!elsiocb->context1) {
5700 lpfc_els_free_iocb(phba, elsiocb);
5704 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5705 if (rc == IOCB_ERROR) {
5706 lpfc_els_free_iocb(phba, elsiocb);
5711 /* Xmit ELS ACC response tag <ulpIoTag> */
5712 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5713 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5714 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5715 "RPI: x%x, fc_flag x%x refcnt %d\n",
5716 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5717 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5718 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref));
5723 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
5724 * @vport: pointer to a virtual N_Port data structure.
5725 * @rejectError: reject response to issue
5726 * @oldiocb: pointer to the original lpfc command iocb data structure.
5727 * @ndlp: pointer to a node-list data structure.
5728 * @mbox: pointer to the driver internal queue element for mailbox command.
5730 * This routine prepares and issue an Reject (RJT) response IOCB
5731 * command. If a @mbox pointer is passed in, it will be put into the
5732 * context_un.mbox field of the IOCB for the completion callback function
5733 * to issue to the HBA later.
5735 * Note that the ndlp reference count will be incremented by 1 for holding the
5736 * ndlp and the reference to ndlp will be stored into the context1 field of
5737 * the IOCB for the completion callback function to the reject response
5741 * 0 - Successfully issued reject response
5742 * 1 - Failed to issue reject response
5745 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
5746 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5750 struct lpfc_hba *phba = vport->phba;
5753 union lpfc_wqe128 *wqe;
5754 struct lpfc_iocbq *elsiocb;
5758 cmdsize = 2 * sizeof(uint32_t);
5759 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5760 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5764 if (phba->sli_rev == LPFC_SLI_REV4) {
5765 wqe = &elsiocb->wqe;
5766 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5767 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
5768 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5769 get_job_rcvoxid(phba, oldiocb));
5771 icmd = &elsiocb->iocb;
5772 oldcmd = &oldiocb->iocb;
5773 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5774 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5777 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5779 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5780 pcmd += sizeof(uint32_t);
5781 *((uint32_t *) (pcmd)) = rejectError;
5784 elsiocb->context_un.mbox = mbox;
5786 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
5787 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5788 "0129 Xmit ELS RJT x%x response tag x%x "
5789 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5791 rejectError, elsiocb->iotag,
5792 get_job_ulpcontext(phba, elsiocb), ndlp->nlp_DID,
5793 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
5794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5795 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
5796 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
5798 phba->fc_stat.elsXmitLSRJT++;
5799 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5800 elsiocb->context1 = lpfc_nlp_get(ndlp);
5801 if (!elsiocb->context1) {
5802 lpfc_els_free_iocb(phba, elsiocb);
5806 /* The NPIV instance is rejecting this unsolicited ELS. Make sure the
5807 * node's assigned RPI gets released provided this node is not already
5808 * registered with the transport.
5810 if (phba->sli_rev == LPFC_SLI_REV4 &&
5811 vport->port_type == LPFC_NPIV_PORT &&
5812 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
5813 spin_lock_irq(&ndlp->lock);
5814 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5815 spin_unlock_irq(&ndlp->lock);
5818 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5819 if (rc == IOCB_ERROR) {
5820 lpfc_els_free_iocb(phba, elsiocb);
5829 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric.
5830 * @vport: pointer to a host virtual N_Port data structure.
5831 * @cmdiocb: pointer to the original lpfc command iocb data structure.
5832 * @ndlp: NPort to where rsp is directed
5834 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate
5835 * this N_Port's support of hardware signals in its Congestion
5836 * Capabilities Descriptor.
5839 * 0 - Successfully issued edc rsp command
5840 * 1 - Failed to issue edc rsp command
5843 lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5844 struct lpfc_nodelist *ndlp)
5846 struct lpfc_hba *phba = vport->phba;
5847 struct lpfc_els_edc_rsp *edc_rsp;
5848 struct lpfc_iocbq *elsiocb;
5850 union lpfc_wqe128 *wqe;
5854 cmdsize = sizeof(struct lpfc_els_edc_rsp);
5855 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry,
5856 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5860 if (phba->sli_rev == LPFC_SLI_REV4) {
5861 wqe = &elsiocb->wqe;
5862 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5863 get_job_ulpcontext(phba, cmdiocb)); /* Xri / rx_id */
5864 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5865 get_job_rcvoxid(phba, cmdiocb));
5867 icmd = &elsiocb->iocb;
5868 cmd = &cmdiocb->iocb;
5869 icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */
5870 icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id;
5873 pcmd = (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5875 memset(pcmd, 0, cmdsize);
5877 edc_rsp = (struct lpfc_els_edc_rsp *)pcmd;
5878 edc_rsp->edc_rsp.acc_hdr.la_cmd = ELS_LS_ACC;
5879 edc_rsp->edc_rsp.desc_list_len = cpu_to_be32(
5880 FC_TLV_DESC_LENGTH_FROM_SZ(struct lpfc_els_edc_rsp));
5881 edc_rsp->edc_rsp.lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO);
5882 edc_rsp->edc_rsp.lsri.desc_len = cpu_to_be32(
5883 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc));
5884 edc_rsp->edc_rsp.lsri.rqst_w0.cmd = ELS_EDC;
5885 lpfc_format_edc_cgn_desc(phba, &edc_rsp->cgn_desc);
5887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5888 "Issue EDC ACC: did:x%x flg:x%x refcnt %d",
5889 ndlp->nlp_DID, ndlp->nlp_flag,
5890 kref_read(&ndlp->kref));
5891 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5893 phba->fc_stat.elsXmitACC++;
5894 elsiocb->context1 = lpfc_nlp_get(ndlp);
5895 if (!elsiocb->context1) {
5896 lpfc_els_free_iocb(phba, elsiocb);
5900 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5901 if (rc == IOCB_ERROR) {
5902 lpfc_els_free_iocb(phba, elsiocb);
5907 /* Xmit ELS ACC response tag <ulpIoTag> */
5908 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5909 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, "
5910 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5911 "RPI: x%x, fc_flag x%x\n",
5912 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5913 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5914 ndlp->nlp_rpi, vport->fc_flag);
5920 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
5921 * @vport: pointer to a virtual N_Port data structure.
5922 * @oldiocb: pointer to the original lpfc command iocb data structure.
5923 * @ndlp: pointer to a node-list data structure.
5925 * This routine prepares and issues an Accept (ACC) response to Address
5926 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
5927 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5929 * Note that the ndlp reference count will be incremented by 1 for holding the
5930 * ndlp and the reference to ndlp will be stored into the context1 field of
5931 * the IOCB for the completion callback function to the ADISC Accept response
5935 * 0 - Successfully issued acc adisc response
5936 * 1 - Failed to issue adisc acc response
5939 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5940 struct lpfc_nodelist *ndlp)
5942 struct lpfc_hba *phba = vport->phba;
5944 IOCB_t *icmd, *oldcmd;
5945 union lpfc_wqe128 *wqe;
5946 struct lpfc_iocbq *elsiocb;
5952 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
5953 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5954 ndlp->nlp_DID, ELS_CMD_ACC);
5958 if (phba->sli_rev == LPFC_SLI_REV4) {
5959 wqe = &elsiocb->wqe;
5961 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5962 get_job_ulpcontext(phba, oldiocb));
5963 ulp_context = get_job_ulpcontext(phba, elsiocb);
5965 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5966 get_job_rcvoxid(phba, oldiocb));
5968 icmd = &elsiocb->iocb;
5969 oldcmd = &oldiocb->iocb;
5970 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5971 ulp_context = elsiocb->iocb.ulpContext;
5972 icmd->unsli3.rcvsli3.ox_id =
5973 oldcmd->unsli3.rcvsli3.ox_id;
5976 /* Xmit ADISC ACC response tag <ulpIoTag> */
5977 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5978 "0130 Xmit ADISC ACC response iotag x%x xri: "
5979 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
5980 elsiocb->iotag, ulp_context,
5981 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5983 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5985 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5986 pcmd += sizeof(uint32_t);
5988 ap = (ADISC *) (pcmd);
5989 ap->hardAL_PA = phba->fc_pref_ALPA;
5990 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5991 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5992 ap->DID = be32_to_cpu(vport->fc_myDID);
5994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5995 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5996 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5998 phba->fc_stat.elsXmitACC++;
5999 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6000 elsiocb->context1 = lpfc_nlp_get(ndlp);
6001 if (!elsiocb->context1) {
6002 lpfc_els_free_iocb(phba, elsiocb);
6006 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6007 if (rc == IOCB_ERROR) {
6008 lpfc_els_free_iocb(phba, elsiocb);
6017 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
6018 * @vport: pointer to a virtual N_Port data structure.
6019 * @oldiocb: pointer to the original lpfc command iocb data structure.
6020 * @ndlp: pointer to a node-list data structure.
6022 * This routine prepares and issues an Accept (ACC) response to Process
6023 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
6024 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
6026 * Note that the ndlp reference count will be incremented by 1 for holding the
6027 * ndlp and the reference to ndlp will be stored into the context1 field of
6028 * the IOCB for the completion callback function to the PRLI Accept response
6032 * 0 - Successfully issued acc prli response
6033 * 1 - Failed to issue acc prli response
6036 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
6037 struct lpfc_nodelist *ndlp)
6039 struct lpfc_hba *phba = vport->phba;
6041 struct lpfc_nvme_prli *npr_nvme;
6045 union lpfc_wqe128 *wqe;
6046 struct lpfc_iocbq *elsiocb;
6049 uint32_t prli_fc4_req, *req_payload;
6050 struct lpfc_dmabuf *req_buf;
6052 u32 elsrspcmd, ulp_context;
6054 /* Need the incoming PRLI payload to determine if the ACC is for an
6055 * FC4 or NVME PRLI type. The PRLI type is at word 1.
6057 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
6058 req_payload = (((uint32_t *)req_buf->virt) + 1);
6060 /* PRLI type payload is at byte 3 for FCP or NVME. */
6061 prli_fc4_req = be32_to_cpu(*req_payload);
6062 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
6063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6064 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
6065 prli_fc4_req, *((uint32_t *)req_payload));
6067 if (prli_fc4_req == PRLI_FCP_TYPE) {
6068 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
6069 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
6070 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
6071 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
6072 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
6077 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6078 ndlp->nlp_DID, elsrspcmd);
6082 if (phba->sli_rev == LPFC_SLI_REV4) {
6083 wqe = &elsiocb->wqe;
6084 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6085 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6086 ulp_context = get_job_ulpcontext(phba, elsiocb);
6087 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6088 get_job_rcvoxid(phba, oldiocb));
6090 icmd = &elsiocb->iocb;
6091 oldcmd = &oldiocb->iocb;
6092 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6093 ulp_context = elsiocb->iocb.ulpContext;
6094 icmd->unsli3.rcvsli3.ox_id =
6095 oldcmd->unsli3.rcvsli3.ox_id;
6098 /* Xmit PRLI ACC response tag <ulpIoTag> */
6099 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6100 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
6101 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6102 elsiocb->iotag, ulp_context,
6103 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6105 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6106 memset(pcmd, 0, cmdsize);
6108 *((uint32_t *)(pcmd)) = elsrspcmd;
6109 pcmd += sizeof(uint32_t);
6111 /* For PRLI, remainder of payload is PRLI parameter page */
6114 if (prli_fc4_req == PRLI_FCP_TYPE) {
6116 * If the remote port is a target and our firmware version
6117 * is 3.20 or later, set the following bits for FC-TAPE
6120 npr = (PRLI *) pcmd;
6121 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
6122 (vpd->rev.feaLevelHigh >= 0x02)) {
6123 npr->ConfmComplAllowed = 1;
6125 npr->TaskRetryIdReq = 1;
6127 npr->acceptRspCode = PRLI_REQ_EXECUTED;
6128 npr->estabImagePair = 1;
6129 npr->readXferRdyDis = 1;
6130 npr->ConfmComplAllowed = 1;
6131 npr->prliType = PRLI_FCP_TYPE;
6132 npr->initiatorFunc = 1;
6133 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
6134 /* Respond with an NVME PRLI Type */
6135 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
6136 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
6137 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
6138 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
6139 if (phba->nvmet_support) {
6140 bf_set(prli_tgt, npr_nvme, 1);
6141 bf_set(prli_disc, npr_nvme, 1);
6142 if (phba->cfg_nvme_enable_fb) {
6143 bf_set(prli_fba, npr_nvme, 1);
6145 /* TBD. Target mode needs to post buffers
6146 * that support the configured first burst
6149 bf_set(prli_fb_sz, npr_nvme,
6150 phba->cfg_nvmet_fb_size);
6153 bf_set(prli_init, npr_nvme, 1);
6156 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
6157 "6015 NVME issue PRLI ACC word1 x%08x "
6158 "word4 x%08x word5 x%08x flag x%x, "
6159 "fcp_info x%x nlp_type x%x\n",
6160 npr_nvme->word1, npr_nvme->word4,
6161 npr_nvme->word5, ndlp->nlp_flag,
6162 ndlp->nlp_fcp_info, ndlp->nlp_type);
6163 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
6164 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
6165 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
6167 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6168 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
6169 prli_fc4_req, ndlp->nlp_fc4_type,
6172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6173 "Issue ACC PRLI: did:x%x flg:x%x",
6174 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6176 phba->fc_stat.elsXmitACC++;
6177 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6178 elsiocb->context1 = lpfc_nlp_get(ndlp);
6179 if (!elsiocb->context1) {
6180 lpfc_els_free_iocb(phba, elsiocb);
6184 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6185 if (rc == IOCB_ERROR) {
6186 lpfc_els_free_iocb(phba, elsiocb);
6195 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
6196 * @vport: pointer to a virtual N_Port data structure.
6197 * @format: rnid command format.
6198 * @oldiocb: pointer to the original lpfc command iocb data structure.
6199 * @ndlp: pointer to a node-list data structure.
6201 * This routine issues a Request Node Identification Data (RNID) Accept
6202 * (ACC) response. It constructs the RNID ACC response command according to
6203 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
6204 * issue the response.
6206 * Note that the ndlp reference count will be incremented by 1 for holding the
6207 * ndlp and the reference to ndlp will be stored into the context1 field of
6208 * the IOCB for the completion callback function.
6211 * 0 - Successfully issued acc rnid response
6212 * 1 - Failed to issue acc rnid response
6215 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
6216 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6218 struct lpfc_hba *phba = vport->phba;
6220 IOCB_t *icmd, *oldcmd;
6221 union lpfc_wqe128 *wqe;
6222 struct lpfc_iocbq *elsiocb;
6228 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
6229 + (2 * sizeof(struct lpfc_name));
6231 cmdsize += sizeof(RNID_TOP_DISC);
6233 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6234 ndlp->nlp_DID, ELS_CMD_ACC);
6238 if (phba->sli_rev == LPFC_SLI_REV4) {
6239 wqe = &elsiocb->wqe;
6240 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6241 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6242 ulp_context = get_job_ulpcontext(phba, elsiocb);
6243 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6244 get_job_rcvoxid(phba, oldiocb));
6246 icmd = &elsiocb->iocb;
6247 oldcmd = &oldiocb->iocb;
6248 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6249 ulp_context = elsiocb->iocb.ulpContext;
6250 icmd->unsli3.rcvsli3.ox_id =
6251 oldcmd->unsli3.rcvsli3.ox_id;
6254 /* Xmit RNID ACC response tag <ulpIoTag> */
6255 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6256 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
6257 elsiocb->iotag, ulp_context);
6258 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6259 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6260 pcmd += sizeof(uint32_t);
6262 memset(pcmd, 0, sizeof(RNID));
6263 rn = (RNID *) (pcmd);
6264 rn->Format = format;
6265 rn->CommonLen = (2 * sizeof(struct lpfc_name));
6266 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
6267 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
6270 rn->SpecificLen = 0;
6272 case RNID_TOPOLOGY_DISC:
6273 rn->SpecificLen = sizeof(RNID_TOP_DISC);
6274 memcpy(&rn->un.topologyDisc.portName,
6275 &vport->fc_portname, sizeof(struct lpfc_name));
6276 rn->un.topologyDisc.unitType = RNID_HBA;
6277 rn->un.topologyDisc.physPort = 0;
6278 rn->un.topologyDisc.attachedNodes = 0;
6282 rn->SpecificLen = 0;
6286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6287 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
6288 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6290 phba->fc_stat.elsXmitACC++;
6291 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6292 elsiocb->context1 = lpfc_nlp_get(ndlp);
6293 if (!elsiocb->context1) {
6294 lpfc_els_free_iocb(phba, elsiocb);
6298 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6299 if (rc == IOCB_ERROR) {
6300 lpfc_els_free_iocb(phba, elsiocb);
6309 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
6310 * @vport: pointer to a virtual N_Port data structure.
6311 * @iocb: pointer to the lpfc command iocb data structure.
6312 * @ndlp: pointer to a node-list data structure.
6317 lpfc_els_clear_rrq(struct lpfc_vport *vport,
6318 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
6320 struct lpfc_hba *phba = vport->phba;
6325 struct lpfc_node_rrq *prrq;
6328 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
6329 pcmd += sizeof(uint32_t);
6330 rrq = (struct RRQ *)pcmd;
6331 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
6332 rxid = bf_get(rrq_rxid, rrq);
6334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6335 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
6337 be32_to_cpu(bf_get(rrq_did, rrq)),
6338 bf_get(rrq_oxid, rrq),
6340 get_wqe_reqtag(iocb),
6341 get_job_ulpcontext(phba, iocb));
6343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6344 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
6345 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
6346 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
6347 xri = bf_get(rrq_oxid, rrq);
6350 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
6352 lpfc_clr_rrq_active(phba, xri, prrq);
6357 * lpfc_els_rsp_echo_acc - Issue echo acc response
6358 * @vport: pointer to a virtual N_Port data structure.
6359 * @data: pointer to echo data to return in the accept.
6360 * @oldiocb: pointer to the original lpfc command iocb data structure.
6361 * @ndlp: pointer to a node-list data structure.
6364 * 0 - Successfully issued acc echo response
6365 * 1 - Failed to issue acc echo response
6368 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
6369 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6371 struct lpfc_hba *phba = vport->phba;
6372 IOCB_t *icmd, *oldcmd;
6373 union lpfc_wqe128 *wqe;
6374 struct lpfc_iocbq *elsiocb;
6380 if (phba->sli_rev == LPFC_SLI_REV4)
6381 cmdsize = oldiocb->wcqe_cmpl.total_data_placed;
6383 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
6385 /* The accumulated length can exceed the BPL_SIZE. For
6386 * now, use this as the limit
6388 if (cmdsize > LPFC_BPL_SIZE)
6389 cmdsize = LPFC_BPL_SIZE;
6390 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6391 ndlp->nlp_DID, ELS_CMD_ACC);
6395 if (phba->sli_rev == LPFC_SLI_REV4) {
6396 wqe = &elsiocb->wqe;
6397 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6398 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6399 ulp_context = get_job_ulpcontext(phba, elsiocb);
6400 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6401 get_job_rcvoxid(phba, oldiocb));
6403 icmd = &elsiocb->iocb;
6404 oldcmd = &oldiocb->iocb;
6405 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6406 ulp_context = elsiocb->iocb.ulpContext;
6407 icmd->unsli3.rcvsli3.ox_id =
6408 oldcmd->unsli3.rcvsli3.ox_id;
6411 /* Xmit ECHO ACC response tag <ulpIoTag> */
6412 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6413 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
6414 elsiocb->iotag, ulp_context);
6415 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6416 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6417 pcmd += sizeof(uint32_t);
6418 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
6420 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6421 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
6422 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6424 phba->fc_stat.elsXmitACC++;
6425 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6426 elsiocb->context1 = lpfc_nlp_get(ndlp);
6427 if (!elsiocb->context1) {
6428 lpfc_els_free_iocb(phba, elsiocb);
6432 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6433 if (rc == IOCB_ERROR) {
6434 lpfc_els_free_iocb(phba, elsiocb);
6443 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
6444 * @vport: pointer to a host virtual N_Port data structure.
6446 * This routine issues Address Discover (ADISC) ELS commands to those
6447 * N_Ports which are in node port recovery state and ADISC has not been issued
6448 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
6449 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
6450 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
6451 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
6452 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
6453 * IOCBs quit for later pick up. On the other hand, after walking through
6454 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
6455 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
6456 * no more ADISC need to be sent.
6459 * The number of N_Ports with adisc issued.
6462 lpfc_els_disc_adisc(struct lpfc_vport *vport)
6464 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6465 struct lpfc_nodelist *ndlp, *next_ndlp;
6468 /* go thru NPR nodes and issue any remaining ELS ADISCs */
6469 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6471 if (ndlp->nlp_state != NLP_STE_NPR_NODE ||
6472 !(ndlp->nlp_flag & NLP_NPR_ADISC))
6475 spin_lock_irq(&ndlp->lock);
6476 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
6477 spin_unlock_irq(&ndlp->lock);
6479 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
6480 /* This node was marked for ADISC but was not picked
6481 * for discovery. This is possible if the node was
6482 * missing in gidft response.
6484 * At time of marking node for ADISC, we skipped unreg
6487 lpfc_nlp_unreg_node(vport, ndlp);
6488 lpfc_unreg_rpi(vport, ndlp);
6492 ndlp->nlp_prev_state = ndlp->nlp_state;
6493 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
6494 lpfc_issue_els_adisc(vport, ndlp, 0);
6496 vport->num_disc_nodes++;
6497 if (vport->num_disc_nodes >=
6498 vport->cfg_discovery_threads) {
6499 spin_lock_irq(shost->host_lock);
6500 vport->fc_flag |= FC_NLP_MORE;
6501 spin_unlock_irq(shost->host_lock);
6506 if (sentadisc == 0) {
6507 spin_lock_irq(shost->host_lock);
6508 vport->fc_flag &= ~FC_NLP_MORE;
6509 spin_unlock_irq(shost->host_lock);
6515 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
6516 * @vport: pointer to a host virtual N_Port data structure.
6518 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
6519 * which are in node port recovery state, with a @vport. Each time an ELS
6520 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
6521 * the per @vport number of discover count (num_disc_nodes) shall be
6522 * incremented. If the num_disc_nodes reaches a pre-configured threshold
6523 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
6524 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
6525 * later pick up. On the other hand, after walking through all the ndlps with
6526 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
6527 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
6528 * PLOGI need to be sent.
6531 * The number of N_Ports with plogi issued.
6534 lpfc_els_disc_plogi(struct lpfc_vport *vport)
6536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6537 struct lpfc_nodelist *ndlp, *next_ndlp;
6540 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
6541 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6542 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
6543 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
6544 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
6545 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
6546 ndlp->nlp_prev_state = ndlp->nlp_state;
6547 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6548 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6550 vport->num_disc_nodes++;
6551 if (vport->num_disc_nodes >=
6552 vport->cfg_discovery_threads) {
6553 spin_lock_irq(shost->host_lock);
6554 vport->fc_flag |= FC_NLP_MORE;
6555 spin_unlock_irq(shost->host_lock);
6561 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6562 "6452 Discover PLOGI %d flag x%x\n",
6563 sentplogi, vport->fc_flag);
6566 lpfc_set_disctmo(vport);
6569 spin_lock_irq(shost->host_lock);
6570 vport->fc_flag &= ~FC_NLP_MORE;
6571 spin_unlock_irq(shost->host_lock);
6577 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
6581 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
6582 desc->payload.els_req = word0;
6583 desc->length = cpu_to_be32(sizeof(desc->payload));
6585 return sizeof(struct fc_rdp_link_service_desc);
6589 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
6590 uint8_t *page_a0, uint8_t *page_a2)
6592 uint16_t wavelength;
6593 uint16_t temperature;
6599 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
6600 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
6602 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
6604 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
6605 &page_a0[SSF_TRANSCEIVER_CODE_B4];
6606 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
6607 &page_a0[SSF_TRANSCEIVER_CODE_B5];
6609 if ((trasn_code_byte4->fc_sw_laser) ||
6610 (trasn_code_byte5->fc_sw_laser_sl) ||
6611 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
6612 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
6613 } else if (trasn_code_byte4->fc_lw_laser) {
6614 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
6615 page_a0[SSF_WAVELENGTH_B0];
6616 if (wavelength == SFP_WAVELENGTH_LC1310)
6617 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
6618 if (wavelength == SFP_WAVELENGTH_LL1550)
6619 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
6621 /* check if its SFP+ */
6622 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
6623 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
6624 << SFP_FLAG_CT_SHIFT;
6626 /* check if its OPTICAL */
6627 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
6628 SFP_FLAG_IS_OPTICAL_PORT : 0)
6629 << SFP_FLAG_IS_OPTICAL_SHIFT;
6631 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
6632 page_a2[SFF_TEMPERATURE_B0]);
6633 vcc = (page_a2[SFF_VCC_B1] << 8 |
6634 page_a2[SFF_VCC_B0]);
6635 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
6636 page_a2[SFF_TXPOWER_B0]);
6637 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
6638 page_a2[SFF_TX_BIAS_CURRENT_B0]);
6639 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
6640 page_a2[SFF_RXPOWER_B0]);
6641 desc->sfp_info.temperature = cpu_to_be16(temperature);
6642 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
6643 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
6644 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
6645 desc->sfp_info.vcc = cpu_to_be16(vcc);
6647 desc->sfp_info.flags = cpu_to_be16(flag);
6648 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
6650 return sizeof(struct fc_rdp_sfp_desc);
6654 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
6659 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
6661 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
6663 desc->info.port_type = cpu_to_be32(type);
6665 desc->info.link_status.link_failure_cnt =
6666 cpu_to_be32(stat->linkFailureCnt);
6667 desc->info.link_status.loss_of_synch_cnt =
6668 cpu_to_be32(stat->lossSyncCnt);
6669 desc->info.link_status.loss_of_signal_cnt =
6670 cpu_to_be32(stat->lossSignalCnt);
6671 desc->info.link_status.primitive_seq_proto_err =
6672 cpu_to_be32(stat->primSeqErrCnt);
6673 desc->info.link_status.invalid_trans_word =
6674 cpu_to_be32(stat->invalidXmitWord);
6675 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
6677 desc->length = cpu_to_be32(sizeof(desc->info));
6679 return sizeof(struct fc_rdp_link_error_status_desc);
6683 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
6684 struct lpfc_vport *vport)
6688 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
6690 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
6691 (vport->fc_sparam.cmn.bbCreditMsb << 8);
6692 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
6693 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
6694 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
6695 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
6696 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
6698 desc->bbc_info.attached_port_bbc = 0;
6701 desc->bbc_info.rtt = 0;
6702 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
6704 return sizeof(struct fc_rdp_bbc_desc);
6708 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
6709 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
6713 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6715 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
6716 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
6717 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
6718 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
6720 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6721 flags |= RDP_OET_HIGH_ALARM;
6722 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6723 flags |= RDP_OET_LOW_ALARM;
6724 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6725 flags |= RDP_OET_HIGH_WARNING;
6726 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6727 flags |= RDP_OET_LOW_WARNING;
6729 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
6730 desc->oed_info.function_flags = cpu_to_be32(flags);
6731 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6732 return sizeof(struct fc_rdp_oed_sfp_desc);
6736 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
6737 struct fc_rdp_oed_sfp_desc *desc,
6742 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6744 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
6745 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
6746 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
6747 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
6749 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6750 flags |= RDP_OET_HIGH_ALARM;
6751 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6752 flags |= RDP_OET_LOW_ALARM;
6753 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6754 flags |= RDP_OET_HIGH_WARNING;
6755 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6756 flags |= RDP_OET_LOW_WARNING;
6758 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
6759 desc->oed_info.function_flags = cpu_to_be32(flags);
6760 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6761 return sizeof(struct fc_rdp_oed_sfp_desc);
6765 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
6766 struct fc_rdp_oed_sfp_desc *desc,
6771 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6773 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
6774 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
6775 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
6776 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
6778 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6779 flags |= RDP_OET_HIGH_ALARM;
6780 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
6781 flags |= RDP_OET_LOW_ALARM;
6782 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6783 flags |= RDP_OET_HIGH_WARNING;
6784 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
6785 flags |= RDP_OET_LOW_WARNING;
6787 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
6788 desc->oed_info.function_flags = cpu_to_be32(flags);
6789 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6790 return sizeof(struct fc_rdp_oed_sfp_desc);
6794 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
6795 struct fc_rdp_oed_sfp_desc *desc,
6800 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6802 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
6803 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
6804 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
6805 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
6807 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6808 flags |= RDP_OET_HIGH_ALARM;
6809 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
6810 flags |= RDP_OET_LOW_ALARM;
6811 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6812 flags |= RDP_OET_HIGH_WARNING;
6813 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
6814 flags |= RDP_OET_LOW_WARNING;
6816 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
6817 desc->oed_info.function_flags = cpu_to_be32(flags);
6818 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6819 return sizeof(struct fc_rdp_oed_sfp_desc);
6824 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
6825 struct fc_rdp_oed_sfp_desc *desc,
6830 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6832 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
6833 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
6834 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
6835 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
6837 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6838 flags |= RDP_OET_HIGH_ALARM;
6839 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
6840 flags |= RDP_OET_LOW_ALARM;
6841 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6842 flags |= RDP_OET_HIGH_WARNING;
6843 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
6844 flags |= RDP_OET_LOW_WARNING;
6846 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
6847 desc->oed_info.function_flags = cpu_to_be32(flags);
6848 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6849 return sizeof(struct fc_rdp_oed_sfp_desc);
6853 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
6854 uint8_t *page_a0, struct lpfc_vport *vport)
6856 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
6857 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
6858 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
6859 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
6860 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
6861 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
6862 desc->length = cpu_to_be32(sizeof(desc->opd_info));
6863 return sizeof(struct fc_rdp_opd_sfp_desc);
6867 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
6869 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
6871 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
6873 desc->info.CorrectedBlocks =
6874 cpu_to_be32(stat->fecCorrBlkCount);
6875 desc->info.UncorrectableBlocks =
6876 cpu_to_be32(stat->fecUncorrBlkCount);
6878 desc->length = cpu_to_be32(sizeof(desc->info));
6880 return sizeof(struct fc_fec_rdp_desc);
6884 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
6886 uint16_t rdp_cap = 0;
6889 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
6891 switch (phba->fc_linkspeed) {
6892 case LPFC_LINK_SPEED_1GHZ:
6893 rdp_speed = RDP_PS_1GB;
6895 case LPFC_LINK_SPEED_2GHZ:
6896 rdp_speed = RDP_PS_2GB;
6898 case LPFC_LINK_SPEED_4GHZ:
6899 rdp_speed = RDP_PS_4GB;
6901 case LPFC_LINK_SPEED_8GHZ:
6902 rdp_speed = RDP_PS_8GB;
6904 case LPFC_LINK_SPEED_10GHZ:
6905 rdp_speed = RDP_PS_10GB;
6907 case LPFC_LINK_SPEED_16GHZ:
6908 rdp_speed = RDP_PS_16GB;
6910 case LPFC_LINK_SPEED_32GHZ:
6911 rdp_speed = RDP_PS_32GB;
6913 case LPFC_LINK_SPEED_64GHZ:
6914 rdp_speed = RDP_PS_64GB;
6916 case LPFC_LINK_SPEED_128GHZ:
6917 rdp_speed = RDP_PS_128GB;
6919 case LPFC_LINK_SPEED_256GHZ:
6920 rdp_speed = RDP_PS_256GB;
6923 rdp_speed = RDP_PS_UNKNOWN;
6927 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
6929 if (phba->lmt & LMT_256Gb)
6930 rdp_cap |= RDP_PS_256GB;
6931 if (phba->lmt & LMT_128Gb)
6932 rdp_cap |= RDP_PS_128GB;
6933 if (phba->lmt & LMT_64Gb)
6934 rdp_cap |= RDP_PS_64GB;
6935 if (phba->lmt & LMT_32Gb)
6936 rdp_cap |= RDP_PS_32GB;
6937 if (phba->lmt & LMT_16Gb)
6938 rdp_cap |= RDP_PS_16GB;
6939 if (phba->lmt & LMT_10Gb)
6940 rdp_cap |= RDP_PS_10GB;
6941 if (phba->lmt & LMT_8Gb)
6942 rdp_cap |= RDP_PS_8GB;
6943 if (phba->lmt & LMT_4Gb)
6944 rdp_cap |= RDP_PS_4GB;
6945 if (phba->lmt & LMT_2Gb)
6946 rdp_cap |= RDP_PS_2GB;
6947 if (phba->lmt & LMT_1Gb)
6948 rdp_cap |= RDP_PS_1GB;
6951 rdp_cap = RDP_CAP_UNKNOWN;
6952 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
6953 rdp_cap |= RDP_CAP_USER_CONFIGURED;
6955 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
6956 desc->length = cpu_to_be32(sizeof(desc->info));
6957 return sizeof(struct fc_rdp_port_speed_desc);
6961 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
6962 struct lpfc_vport *vport)
6965 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6967 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
6968 sizeof(desc->port_names.wwnn));
6970 memcpy(desc->port_names.wwpn, &vport->fc_portname,
6971 sizeof(desc->port_names.wwpn));
6973 desc->length = cpu_to_be32(sizeof(desc->port_names));
6974 return sizeof(struct fc_rdp_port_name_desc);
6978 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
6979 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6982 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6983 if (vport->fc_flag & FC_FABRIC) {
6984 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
6985 sizeof(desc->port_names.wwnn));
6987 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
6988 sizeof(desc->port_names.wwpn));
6989 } else { /* Point to Point */
6990 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
6991 sizeof(desc->port_names.wwnn));
6993 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
6994 sizeof(desc->port_names.wwpn));
6997 desc->length = cpu_to_be32(sizeof(desc->port_names));
6998 return sizeof(struct fc_rdp_port_name_desc);
7002 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
7005 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
7006 struct lpfc_vport *vport = ndlp->vport;
7007 struct lpfc_iocbq *elsiocb;
7008 struct ulp_bde64 *bpl;
7010 union lpfc_wqe128 *wqe;
7012 struct ls_rjt *stat;
7013 struct fc_rdp_res_frame *rdp_res;
7014 uint32_t cmdsize, len;
7019 if (status != SUCCESS)
7022 /* This will change once we know the true size of the RDP payload */
7023 cmdsize = sizeof(struct fc_rdp_res_frame);
7025 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
7026 lpfc_max_els_tries, rdp_context->ndlp,
7027 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
7029 goto free_rdp_context;
7031 ulp_context = get_job_ulpcontext(phba, elsiocb);
7032 if (phba->sli_rev == LPFC_SLI_REV4) {
7033 wqe = &elsiocb->wqe;
7034 /* ox-id of the frame */
7035 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7036 rdp_context->ox_id);
7037 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
7038 rdp_context->rx_id);
7040 icmd = &elsiocb->iocb;
7041 icmd->ulpContext = rdp_context->rx_id;
7042 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
7045 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7046 "2171 Xmit RDP response tag x%x xri x%x, "
7047 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
7048 elsiocb->iotag, ulp_context,
7049 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7051 rdp_res = (struct fc_rdp_res_frame *)
7052 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7053 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7054 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
7055 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7057 /* Update Alarm and Warning */
7058 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
7059 phba->sfp_alarm |= *flag_ptr;
7060 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
7061 phba->sfp_warning |= *flag_ptr;
7063 /* For RDP payload */
7065 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
7066 (len + pcmd), ELS_CMD_RDP);
7068 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
7069 rdp_context->page_a0, rdp_context->page_a2);
7070 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
7072 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
7073 (len + pcmd), &rdp_context->link_stat);
7074 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
7075 (len + pcmd), vport);
7076 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
7077 (len + pcmd), vport, ndlp);
7078 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
7079 &rdp_context->link_stat);
7080 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
7081 &rdp_context->link_stat, vport);
7082 len += lpfc_rdp_res_oed_temp_desc(phba,
7083 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7084 rdp_context->page_a2);
7085 len += lpfc_rdp_res_oed_voltage_desc(phba,
7086 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7087 rdp_context->page_a2);
7088 len += lpfc_rdp_res_oed_txbias_desc(phba,
7089 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7090 rdp_context->page_a2);
7091 len += lpfc_rdp_res_oed_txpower_desc(phba,
7092 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7093 rdp_context->page_a2);
7094 len += lpfc_rdp_res_oed_rxpower_desc(phba,
7095 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7096 rdp_context->page_a2);
7097 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
7098 rdp_context->page_a0, vport);
7100 rdp_res->length = cpu_to_be32(len - 8);
7101 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7103 /* Now that we know the true size of the payload, update the BPL */
7104 bpl = (struct ulp_bde64 *)
7105 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
7106 bpl->tus.f.bdeSize = len;
7107 bpl->tus.f.bdeFlags = 0;
7108 bpl->tus.w = le32_to_cpu(bpl->tus.w);
7110 phba->fc_stat.elsXmitACC++;
7111 elsiocb->context1 = lpfc_nlp_get(ndlp);
7112 if (!elsiocb->context1) {
7113 lpfc_els_free_iocb(phba, elsiocb);
7114 goto free_rdp_context;
7117 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7118 if (rc == IOCB_ERROR) {
7119 lpfc_els_free_iocb(phba, elsiocb);
7123 goto free_rdp_context;
7126 cmdsize = 2 * sizeof(uint32_t);
7127 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
7128 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
7130 goto free_rdp_context;
7132 if (phba->sli_rev == LPFC_SLI_REV4) {
7133 wqe = &elsiocb->wqe;
7134 /* ox-id of the frame */
7135 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7136 rdp_context->ox_id);
7137 bf_set(wqe_ctxt_tag,
7138 &wqe->xmit_els_rsp.wqe_com,
7139 rdp_context->rx_id);
7141 icmd = &elsiocb->iocb;
7142 icmd->ulpContext = rdp_context->rx_id;
7143 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
7146 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7148 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
7149 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7150 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7152 phba->fc_stat.elsXmitLSRJT++;
7153 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7154 elsiocb->context1 = lpfc_nlp_get(ndlp);
7155 if (!elsiocb->context1) {
7156 lpfc_els_free_iocb(phba, elsiocb);
7157 goto free_rdp_context;
7160 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7161 if (rc == IOCB_ERROR) {
7162 lpfc_els_free_iocb(phba, elsiocb);
7167 /* This reference put is for the original unsolicited RDP. If the
7168 * prep failed, there is no reference to remove.
7175 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
7177 LPFC_MBOXQ_t *mbox = NULL;
7178 struct lpfc_dmabuf *mp;
7181 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7183 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
7184 "7105 failed to allocate mailbox memory");
7188 if (lpfc_sli4_dump_page_a0(phba, mbox))
7189 goto prep_mbox_fail;
7190 mbox->vport = rdp_context->ndlp->vport;
7191 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
7192 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
7193 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7194 if (rc == MBX_NOT_FINISHED) {
7195 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
7196 lpfc_mbuf_free(phba, mp->virt, mp->phys);
7197 goto issue_mbox_fail;
7204 mempool_free(mbox, phba->mbox_mem_pool);
7209 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
7210 * @vport: pointer to a host virtual N_Port data structure.
7211 * @cmdiocb: pointer to lpfc command iocb data structure.
7212 * @ndlp: pointer to a node-list data structure.
7214 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
7215 * IOCB. First, the payload of the unsolicited RDP is checked.
7216 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
7217 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
7218 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
7219 * gather all data and send RDP response.
7222 * 0 - Sent the acc response
7223 * 1 - Sent the reject response.
7226 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7227 struct lpfc_nodelist *ndlp)
7229 struct lpfc_hba *phba = vport->phba;
7230 struct lpfc_dmabuf *pcmd;
7231 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
7232 struct fc_rdp_req_frame *rdp_req;
7233 struct lpfc_rdp_context *rdp_context;
7234 union lpfc_wqe128 *cmd = NULL;
7237 if (phba->sli_rev < LPFC_SLI_REV4 ||
7238 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7239 LPFC_SLI_INTF_IF_TYPE_2) {
7240 rjt_err = LSRJT_UNABLE_TPC;
7241 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7245 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
7246 rjt_err = LSRJT_UNABLE_TPC;
7247 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7251 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7252 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
7254 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7255 "2422 ELS RDP Request "
7256 "dec len %d tag x%x port_id %d len %d\n",
7257 be32_to_cpu(rdp_req->rdp_des_length),
7258 be32_to_cpu(rdp_req->nport_id_desc.tag),
7259 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
7260 be32_to_cpu(rdp_req->nport_id_desc.length));
7262 if (sizeof(struct fc_rdp_nport_desc) !=
7263 be32_to_cpu(rdp_req->rdp_des_length))
7265 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
7267 if (RDP_NPORT_ID_SIZE !=
7268 be32_to_cpu(rdp_req->nport_id_desc.length))
7270 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
7272 rjt_err = LSRJT_UNABLE_TPC;
7276 cmd = &cmdiocb->wqe;
7277 rdp_context->ndlp = lpfc_nlp_get(ndlp);
7278 if (!rdp_context->ndlp) {
7280 rjt_err = LSRJT_UNABLE_TPC;
7283 rdp_context->ox_id = bf_get(wqe_rcvoxid,
7284 &cmd->xmit_els_rsp.wqe_com);
7285 rdp_context->rx_id = bf_get(wqe_ctxt_tag,
7286 &cmd->xmit_els_rsp.wqe_com);
7287 rdp_context->cmpl = lpfc_els_rdp_cmpl;
7288 if (lpfc_get_rdp_info(phba, rdp_context)) {
7289 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
7290 "2423 Unable to send mailbox");
7292 rjt_err = LSRJT_UNABLE_TPC;
7300 rjt_err = LSRJT_LOGICAL_ERR;
7303 memset(&stat, 0, sizeof(stat));
7304 stat.un.b.lsRjtRsnCode = rjt_err;
7305 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
7306 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7312 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7316 union lpfc_wqe128 *wqe;
7318 struct lpfc_iocbq *elsiocb;
7319 struct lpfc_nodelist *ndlp;
7320 struct ls_rjt *stat;
7321 union lpfc_sli4_cfg_shdr *shdr;
7322 struct lpfc_lcb_context *lcb_context;
7323 struct fc_lcb_res_frame *lcb_res;
7324 uint32_t cmdsize, shdr_status, shdr_add_status;
7328 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
7329 ndlp = lcb_context->ndlp;
7330 pmb->ctx_ndlp = NULL;
7331 pmb->ctx_buf = NULL;
7333 shdr = (union lpfc_sli4_cfg_shdr *)
7334 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
7335 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7336 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7338 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
7339 "0194 SET_BEACON_CONFIG mailbox "
7340 "completed with status x%x add_status x%x,"
7341 " mbx status x%x\n",
7342 shdr_status, shdr_add_status, mb->mbxStatus);
7344 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
7345 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
7346 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
7347 mempool_free(pmb, phba->mbox_mem_pool);
7351 mempool_free(pmb, phba->mbox_mem_pool);
7352 cmdsize = sizeof(struct fc_lcb_res_frame);
7353 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7354 lpfc_max_els_tries, ndlp,
7355 ndlp->nlp_DID, ELS_CMD_ACC);
7357 /* Decrement the ndlp reference count from previous mbox command */
7361 goto free_lcb_context;
7363 lcb_res = (struct fc_lcb_res_frame *)
7364 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
7366 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
7368 if (phba->sli_rev == LPFC_SLI_REV4) {
7369 wqe = &elsiocb->wqe;
7370 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7371 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7372 lcb_context->ox_id);
7374 icmd = &elsiocb->iocb;
7375 icmd->ulpContext = lcb_context->rx_id;
7376 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7379 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
7380 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
7381 lcb_res->lcb_sub_command = lcb_context->sub_command;
7382 lcb_res->lcb_type = lcb_context->type;
7383 lcb_res->capability = lcb_context->capability;
7384 lcb_res->lcb_frequency = lcb_context->frequency;
7385 lcb_res->lcb_duration = lcb_context->duration;
7386 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7387 phba->fc_stat.elsXmitACC++;
7389 elsiocb->context1 = lpfc_nlp_get(ndlp);
7390 if (!elsiocb->context1) {
7391 lpfc_els_free_iocb(phba, elsiocb);
7395 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7396 if (rc == IOCB_ERROR) {
7397 lpfc_els_free_iocb(phba, elsiocb);
7405 cmdsize = sizeof(struct fc_lcb_res_frame);
7406 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7407 lpfc_max_els_tries, ndlp,
7408 ndlp->nlp_DID, ELS_CMD_LS_RJT);
7411 goto free_lcb_context;
7413 if (phba->sli_rev == LPFC_SLI_REV4) {
7414 wqe = &elsiocb->wqe;
7415 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7416 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7417 lcb_context->ox_id);
7419 icmd = &elsiocb->iocb;
7420 icmd->ulpContext = lcb_context->rx_id;
7421 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7424 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
7426 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
7427 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7428 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7430 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
7431 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
7433 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7434 phba->fc_stat.elsXmitLSRJT++;
7435 elsiocb->context1 = lpfc_nlp_get(ndlp);
7436 if (!elsiocb->context1) {
7437 lpfc_els_free_iocb(phba, elsiocb);
7438 goto free_lcb_context;
7441 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7442 if (rc == IOCB_ERROR) {
7443 lpfc_els_free_iocb(phba, elsiocb);
7451 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
7452 struct lpfc_lcb_context *lcb_context,
7453 uint32_t beacon_state)
7455 struct lpfc_hba *phba = vport->phba;
7456 union lpfc_sli4_cfg_shdr *cfg_shdr;
7457 LPFC_MBOXQ_t *mbox = NULL;
7461 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7465 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
7466 len = sizeof(struct lpfc_mbx_set_beacon_config) -
7467 sizeof(struct lpfc_sli4_cfg_mhdr);
7468 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7469 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
7470 LPFC_SLI4_MBX_EMBED);
7471 mbox->ctx_ndlp = (void *)lcb_context;
7472 mbox->vport = phba->pport;
7473 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
7474 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
7475 phba->sli4_hba.physical_port);
7476 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
7478 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
7481 * Check bv1s bit before issuing the mailbox
7482 * if bv1s == 1, LCB V1 supported
7483 * else, LCB V0 supported
7486 if (phba->sli4_hba.pc_sli4_params.bv1s) {
7487 /* COMMON_SET_BEACON_CONFIG_V1 */
7488 cfg_shdr->request.word9 = BEACON_VERSION_V1;
7489 lcb_context->capability |= LCB_CAPABILITY_DURATION;
7490 bf_set(lpfc_mbx_set_beacon_port_type,
7491 &mbox->u.mqe.un.beacon_config, 0);
7492 bf_set(lpfc_mbx_set_beacon_duration_v1,
7493 &mbox->u.mqe.un.beacon_config,
7494 be16_to_cpu(lcb_context->duration));
7496 /* COMMON_SET_BEACON_CONFIG_V0 */
7497 if (be16_to_cpu(lcb_context->duration) != 0) {
7498 mempool_free(mbox, phba->mbox_mem_pool);
7501 cfg_shdr->request.word9 = BEACON_VERSION_V0;
7502 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
7503 bf_set(lpfc_mbx_set_beacon_state,
7504 &mbox->u.mqe.un.beacon_config, beacon_state);
7505 bf_set(lpfc_mbx_set_beacon_port_type,
7506 &mbox->u.mqe.un.beacon_config, 1);
7507 bf_set(lpfc_mbx_set_beacon_duration,
7508 &mbox->u.mqe.un.beacon_config,
7509 be16_to_cpu(lcb_context->duration));
7512 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7513 if (rc == MBX_NOT_FINISHED) {
7514 mempool_free(mbox, phba->mbox_mem_pool);
7523 * lpfc_els_rcv_lcb - Process an unsolicited LCB
7524 * @vport: pointer to a host virtual N_Port data structure.
7525 * @cmdiocb: pointer to lpfc command iocb data structure.
7526 * @ndlp: pointer to a node-list data structure.
7528 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
7529 * First, the payload of the unsolicited LCB is checked.
7530 * Then based on Subcommand beacon will either turn on or off.
7533 * 0 - Sent the acc response
7534 * 1 - Sent the reject response.
7537 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7538 struct lpfc_nodelist *ndlp)
7540 struct lpfc_hba *phba = vport->phba;
7541 struct lpfc_dmabuf *pcmd;
7543 struct fc_lcb_request_frame *beacon;
7544 struct lpfc_lcb_context *lcb_context;
7545 u8 state, rjt_err = 0;
7548 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
7549 lp = (uint8_t *)pcmd->virt;
7550 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
7552 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7553 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
7554 "type x%x frequency %x duration x%x\n",
7555 lp[0], lp[1], lp[2],
7556 beacon->lcb_command,
7557 beacon->lcb_sub_command,
7559 beacon->lcb_frequency,
7560 be16_to_cpu(beacon->lcb_duration));
7562 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
7563 beacon->lcb_sub_command != LPFC_LCB_OFF) {
7564 rjt_err = LSRJT_CMD_UNSUPPORTED;
7568 if (phba->sli_rev < LPFC_SLI_REV4 ||
7569 phba->hba_flag & HBA_FCOE_MODE ||
7570 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7571 LPFC_SLI_INTF_IF_TYPE_2)) {
7572 rjt_err = LSRJT_CMD_UNSUPPORTED;
7576 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
7578 rjt_err = LSRJT_UNABLE_TPC;
7582 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
7583 lcb_context->sub_command = beacon->lcb_sub_command;
7584 lcb_context->capability = 0;
7585 lcb_context->type = beacon->lcb_type;
7586 lcb_context->frequency = beacon->lcb_frequency;
7587 lcb_context->duration = beacon->lcb_duration;
7588 lcb_context->ox_id = get_job_rcvoxid(phba, cmdiocb);
7589 lcb_context->rx_id = get_job_ulpcontext(phba, cmdiocb);
7590 lcb_context->ndlp = lpfc_nlp_get(ndlp);
7591 if (!lcb_context->ndlp) {
7592 rjt_err = LSRJT_UNABLE_TPC;
7596 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
7597 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
7598 "0193 failed to send mail box");
7600 rjt_err = LSRJT_UNABLE_TPC;
7608 memset(&stat, 0, sizeof(stat));
7609 stat.un.b.lsRjtRsnCode = rjt_err;
7610 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7616 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
7617 * @vport: pointer to a host virtual N_Port data structure.
7619 * This routine cleans up any Registration State Change Notification
7620 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
7621 * @vport together with the host_lock is used to prevent multiple thread
7622 * trying to access the RSCN array on a same @vport at the same time.
7625 lpfc_els_flush_rscn(struct lpfc_vport *vport)
7627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7628 struct lpfc_hba *phba = vport->phba;
7631 spin_lock_irq(shost->host_lock);
7632 if (vport->fc_rscn_flush) {
7633 /* Another thread is walking fc_rscn_id_list on this vport */
7634 spin_unlock_irq(shost->host_lock);
7637 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
7638 vport->fc_rscn_flush = 1;
7639 spin_unlock_irq(shost->host_lock);
7641 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7642 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
7643 vport->fc_rscn_id_list[i] = NULL;
7645 spin_lock_irq(shost->host_lock);
7646 vport->fc_rscn_id_cnt = 0;
7647 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
7648 spin_unlock_irq(shost->host_lock);
7649 lpfc_can_disctmo(vport);
7650 /* Indicate we are done walking this fc_rscn_id_list */
7651 vport->fc_rscn_flush = 0;
7655 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
7656 * @vport: pointer to a host virtual N_Port data structure.
7657 * @did: remote destination port identifier.
7659 * This routine checks whether there is any pending Registration State
7660 * Configuration Notification (RSCN) to a @did on @vport.
7663 * None zero - The @did matched with a pending rscn
7664 * 0 - not able to match @did with a pending rscn
7667 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
7672 uint32_t payload_len, i;
7673 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7675 ns_did.un.word = did;
7677 /* Never match fabric nodes for RSCNs */
7678 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7681 /* If we are doing a FULL RSCN rediscovery, match everything */
7682 if (vport->fc_flag & FC_RSCN_DISCOVERY)
7685 spin_lock_irq(shost->host_lock);
7686 if (vport->fc_rscn_flush) {
7687 /* Another thread is walking fc_rscn_id_list on this vport */
7688 spin_unlock_irq(shost->host_lock);
7691 /* Indicate we are walking fc_rscn_id_list on this vport */
7692 vport->fc_rscn_flush = 1;
7693 spin_unlock_irq(shost->host_lock);
7694 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7695 lp = vport->fc_rscn_id_list[i]->virt;
7696 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7697 payload_len -= sizeof(uint32_t); /* take off word 0 */
7698 while (payload_len) {
7699 rscn_did.un.word = be32_to_cpu(*lp++);
7700 payload_len -= sizeof(uint32_t);
7701 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
7702 case RSCN_ADDRESS_FORMAT_PORT:
7703 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7704 && (ns_did.un.b.area == rscn_did.un.b.area)
7705 && (ns_did.un.b.id == rscn_did.un.b.id))
7706 goto return_did_out;
7708 case RSCN_ADDRESS_FORMAT_AREA:
7709 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7710 && (ns_did.un.b.area == rscn_did.un.b.area))
7711 goto return_did_out;
7713 case RSCN_ADDRESS_FORMAT_DOMAIN:
7714 if (ns_did.un.b.domain == rscn_did.un.b.domain)
7715 goto return_did_out;
7717 case RSCN_ADDRESS_FORMAT_FABRIC:
7718 goto return_did_out;
7722 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7723 vport->fc_rscn_flush = 0;
7726 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7727 vport->fc_rscn_flush = 0;
7732 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
7733 * @vport: pointer to a host virtual N_Port data structure.
7735 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
7736 * state machine for a @vport's nodes that are with pending RSCN (Registration
7737 * State Change Notification).
7740 * 0 - Successful (currently alway return 0)
7743 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
7745 struct lpfc_nodelist *ndlp = NULL;
7747 /* Move all affected nodes by pending RSCNs to NPR state. */
7748 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
7749 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
7750 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
7753 /* NVME Target mode does not do RSCN Recovery. */
7754 if (vport->phba->nvmet_support)
7757 /* If we are in the process of doing discovery on this
7758 * NPort, let it continue on its own.
7760 switch (ndlp->nlp_state) {
7761 case NLP_STE_PLOGI_ISSUE:
7762 case NLP_STE_ADISC_ISSUE:
7763 case NLP_STE_REG_LOGIN_ISSUE:
7764 case NLP_STE_PRLI_ISSUE:
7765 case NLP_STE_LOGO_ISSUE:
7769 lpfc_disc_state_machine(vport, ndlp, NULL,
7770 NLP_EVT_DEVICE_RECOVERY);
7771 lpfc_cancel_retry_delay_tmo(vport, ndlp);
7777 * lpfc_send_rscn_event - Send an RSCN event to management application
7778 * @vport: pointer to a host virtual N_Port data structure.
7779 * @cmdiocb: pointer to lpfc command iocb data structure.
7781 * lpfc_send_rscn_event sends an RSCN netlink event to management
7785 lpfc_send_rscn_event(struct lpfc_vport *vport,
7786 struct lpfc_iocbq *cmdiocb)
7788 struct lpfc_dmabuf *pcmd;
7789 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7790 uint32_t *payload_ptr;
7791 uint32_t payload_len;
7792 struct lpfc_rscn_event_header *rscn_event_data;
7794 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7795 payload_ptr = (uint32_t *) pcmd->virt;
7796 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
7798 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
7799 payload_len, GFP_KERNEL);
7800 if (!rscn_event_data) {
7801 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7802 "0147 Failed to allocate memory for RSCN event\n");
7805 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
7806 rscn_event_data->payload_length = payload_len;
7807 memcpy(rscn_event_data->rscn_payload, payload_ptr,
7810 fc_host_post_vendor_event(shost,
7811 fc_get_event_number(),
7812 sizeof(struct lpfc_rscn_event_header) + payload_len,
7813 (char *)rscn_event_data,
7816 kfree(rscn_event_data);
7820 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
7821 * @vport: pointer to a host virtual N_Port data structure.
7822 * @cmdiocb: pointer to lpfc command iocb data structure.
7823 * @ndlp: pointer to a node-list data structure.
7825 * This routine processes an unsolicited RSCN (Registration State Change
7826 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
7827 * to invoke fc_host_post_event() routine to the FC transport layer. If the
7828 * discover state machine is about to begin discovery, it just accepts the
7829 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
7830 * contains N_Port IDs for other vports on this HBA, it just accepts the
7831 * RSCN and ignore processing it. If the state machine is in the recovery
7832 * state, the fc_rscn_id_list of this @vport is walked and the
7833 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
7834 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
7835 * routine is invoked to handle the RSCN event.
7838 * 0 - Just sent the acc response
7839 * 1 - Sent the acc response and waited for name server completion
7842 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7843 struct lpfc_nodelist *ndlp)
7845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7846 struct lpfc_hba *phba = vport->phba;
7847 struct lpfc_dmabuf *pcmd;
7848 uint32_t *lp, *datap;
7849 uint32_t payload_len, length, nportid, *cmd;
7851 int rscn_id = 0, hba_id = 0;
7854 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7855 lp = (uint32_t *) pcmd->virt;
7857 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7858 payload_len -= sizeof(uint32_t); /* take off word 0 */
7860 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7861 "0214 RSCN received Data: x%x x%x x%x x%x\n",
7862 vport->fc_flag, payload_len, *lp,
7863 vport->fc_rscn_id_cnt);
7865 /* Send an RSCN event to the management application */
7866 lpfc_send_rscn_event(vport, cmdiocb);
7868 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
7869 fc_host_post_event(shost, fc_get_event_number(),
7870 FCH_EVT_RSCN, lp[i]);
7872 /* Check if RSCN is coming from a direct-connected remote NPort */
7873 if (vport->fc_flag & FC_PT2PT) {
7874 /* If so, just ACC it, no other action needed for now */
7875 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7876 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
7877 *lp, vport->fc_flag, payload_len);
7878 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7880 /* Check to see if we need to NVME rescan this target
7883 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
7884 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
7885 lpfc_nvme_rescan_port(vport, ndlp);
7889 /* If we are about to begin discovery, just ACC the RSCN.
7890 * Discovery processing will satisfy it.
7892 if (vport->port_state <= LPFC_NS_QRY) {
7893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7894 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
7895 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7897 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7901 /* If this RSCN just contains NPortIDs for other vports on this HBA,
7902 * just ACC and ignore it.
7904 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7905 !(vport->cfg_peer_port_login)) {
7910 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
7911 i -= sizeof(uint32_t);
7913 if (lpfc_find_vport_by_did(phba, nportid))
7916 if (rscn_id == hba_id) {
7917 /* ALL NPortIDs in RSCN are on HBA */
7918 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7920 "Data: x%x x%x x%x x%x\n",
7921 vport->fc_flag, payload_len,
7922 *lp, vport->fc_rscn_id_cnt);
7923 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7924 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
7925 ndlp->nlp_DID, vport->port_state,
7928 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
7930 /* Restart disctmo if its already running */
7931 if (vport->fc_flag & FC_DISC_TMO) {
7932 tmo = ((phba->fc_ratov * 3) + 3);
7933 mod_timer(&vport->fc_disctmo,
7935 msecs_to_jiffies(1000 * tmo));
7941 spin_lock_irq(shost->host_lock);
7942 if (vport->fc_rscn_flush) {
7943 /* Another thread is walking fc_rscn_id_list on this vport */
7944 vport->fc_flag |= FC_RSCN_DISCOVERY;
7945 spin_unlock_irq(shost->host_lock);
7947 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7950 /* Indicate we are walking fc_rscn_id_list on this vport */
7951 vport->fc_rscn_flush = 1;
7952 spin_unlock_irq(shost->host_lock);
7953 /* Get the array count after successfully have the token */
7954 rscn_cnt = vport->fc_rscn_id_cnt;
7955 /* If we are already processing an RSCN, save the received
7956 * RSCN payload buffer, cmdiocb->context2 to process later.
7958 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
7959 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7960 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
7961 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7963 spin_lock_irq(shost->host_lock);
7964 vport->fc_flag |= FC_RSCN_DEFERRED;
7966 /* Restart disctmo if its already running */
7967 if (vport->fc_flag & FC_DISC_TMO) {
7968 tmo = ((phba->fc_ratov * 3) + 3);
7969 mod_timer(&vport->fc_disctmo,
7970 jiffies + msecs_to_jiffies(1000 * tmo));
7972 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
7973 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
7974 vport->fc_flag |= FC_RSCN_MODE;
7975 spin_unlock_irq(shost->host_lock);
7977 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
7978 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
7981 (payload_len + length <= LPFC_BPL_SIZE)) {
7982 *cmd &= ELS_CMD_MASK;
7983 *cmd |= cpu_to_be32(payload_len + length);
7984 memcpy(((uint8_t *)cmd) + length, lp,
7987 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
7988 vport->fc_rscn_id_cnt++;
7989 /* If we zero, cmdiocb->context2, the calling
7990 * routine will not try to free it.
7992 cmdiocb->context2 = NULL;
7995 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7996 "0235 Deferred RSCN "
7997 "Data: x%x x%x x%x\n",
7998 vport->fc_rscn_id_cnt, vport->fc_flag,
8001 vport->fc_flag |= FC_RSCN_DISCOVERY;
8002 spin_unlock_irq(shost->host_lock);
8003 /* ReDiscovery RSCN */
8004 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8005 "0234 ReDiscovery RSCN "
8006 "Data: x%x x%x x%x\n",
8007 vport->fc_rscn_id_cnt, vport->fc_flag,
8010 /* Indicate we are done walking fc_rscn_id_list on this vport */
8011 vport->fc_rscn_flush = 0;
8013 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8014 /* send RECOVERY event for ALL nodes that match RSCN payload */
8015 lpfc_rscn_recovery_check(vport);
8018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8019 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
8020 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
8022 spin_lock_irq(shost->host_lock);
8023 vport->fc_flag |= FC_RSCN_MODE;
8024 spin_unlock_irq(shost->host_lock);
8025 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
8026 /* Indicate we are done walking fc_rscn_id_list on this vport */
8027 vport->fc_rscn_flush = 0;
8029 * If we zero, cmdiocb->context2, the calling routine will
8030 * not try to free it.
8032 cmdiocb->context2 = NULL;
8033 lpfc_set_disctmo(vport);
8035 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8036 /* send RECOVERY event for ALL nodes that match RSCN payload */
8037 lpfc_rscn_recovery_check(vport);
8038 return lpfc_els_handle_rscn(vport);
8042 * lpfc_els_handle_rscn - Handle rscn for a vport
8043 * @vport: pointer to a host virtual N_Port data structure.
8045 * This routine handles the Registration State Configuration Notification
8046 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
8047 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
8048 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
8049 * NameServer shall be issued. If CT command to the NameServer fails to be
8050 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
8051 * RSCN activities with the @vport.
8054 * 0 - Cleaned up rscn on the @vport
8055 * 1 - Wait for plogi to name server before proceed
8058 lpfc_els_handle_rscn(struct lpfc_vport *vport)
8060 struct lpfc_nodelist *ndlp;
8061 struct lpfc_hba *phba = vport->phba;
8063 /* Ignore RSCN if the port is being torn down. */
8064 if (vport->load_flag & FC_UNLOADING) {
8065 lpfc_els_flush_rscn(vport);
8069 /* Start timer for RSCN processing */
8070 lpfc_set_disctmo(vport);
8072 /* RSCN processed */
8073 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8074 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
8075 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
8076 vport->port_state, vport->num_disc_nodes,
8079 /* To process RSCN, first compare RSCN data with NameServer */
8080 vport->fc_ns_retry = 0;
8081 vport->num_disc_nodes = 0;
8083 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8084 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
8085 /* Good ndlp, issue CT Request to NameServer. Need to
8086 * know how many gidfts were issued. If none, then just
8087 * flush the RSCN. Otherwise, the outstanding requests
8090 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
8091 if (lpfc_issue_gidft(vport) > 0)
8093 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
8094 if (lpfc_issue_gidpt(vport) > 0)
8100 /* Nameserver login in question. Revalidate. */
8102 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
8103 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8105 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8107 lpfc_els_flush_rscn(vport);
8110 ndlp->nlp_prev_state = ndlp->nlp_state;
8111 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8113 ndlp->nlp_type |= NLP_FABRIC;
8114 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
8115 /* Wait for NameServer login cmpl before we can
8121 lpfc_els_flush_rscn(vport);
8126 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
8127 * @vport: pointer to a host virtual N_Port data structure.
8128 * @cmdiocb: pointer to lpfc command iocb data structure.
8129 * @ndlp: pointer to a node-list data structure.
8131 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
8132 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
8133 * point topology. As an unsolicited FLOGI should not be received in a loop
8134 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
8135 * lpfc_check_sparm() routine is invoked to check the parameters in the
8136 * unsolicited FLOGI. If parameters validation failed, the routine
8137 * lpfc_els_rsp_reject() shall be called with reject reason code set to
8138 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
8139 * FLOGI shall be compared with the Port WWN of the @vport to determine who
8140 * will initiate PLOGI. The higher lexicographical value party shall has
8141 * higher priority (as the winning port) and will initiate PLOGI and
8142 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
8143 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
8144 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
8147 * 0 - Successfully processed the unsolicited flogi
8148 * 1 - Failed to process the unsolicited flogi
8151 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8152 struct lpfc_nodelist *ndlp)
8154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8155 struct lpfc_hba *phba = vport->phba;
8156 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8157 uint32_t *lp = (uint32_t *) pcmd->virt;
8158 union lpfc_wqe128 *wqe = &cmdiocb->wqe;
8159 struct serv_parm *sp;
8163 uint32_t fc_flag = 0;
8164 uint32_t port_state = 0;
8167 sp = (struct serv_parm *) lp;
8169 /* FLOGI received */
8171 lpfc_set_disctmo(vport);
8173 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8174 /* We should never receive a FLOGI in loop mode, ignore it */
8175 did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
8177 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
8179 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8180 "0113 An FLOGI ELS command x%x was "
8181 "received from DID x%x in Loop Mode\n",
8186 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
8189 * If our portname is greater than the remote portname,
8190 * then we initiate Nport login.
8193 rc = memcmp(&vport->fc_portname, &sp->portName,
8194 sizeof(struct lpfc_name));
8197 if (phba->sli_rev < LPFC_SLI_REV4) {
8198 mbox = mempool_alloc(phba->mbox_mem_pool,
8202 lpfc_linkdown(phba);
8203 lpfc_init_link(phba, mbox,
8205 phba->cfg_link_speed);
8206 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8207 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8208 mbox->vport = vport;
8209 rc = lpfc_sli_issue_mbox(phba, mbox,
8211 lpfc_set_loopback_flag(phba);
8212 if (rc == MBX_NOT_FINISHED)
8213 mempool_free(mbox, phba->mbox_mem_pool);
8217 /* abort the flogi coming back to ourselves
8218 * due to external loopback on the port.
8220 lpfc_els_abort_flogi(phba);
8223 } else if (rc > 0) { /* greater than */
8224 spin_lock_irq(shost->host_lock);
8225 vport->fc_flag |= FC_PT2PT_PLOGI;
8226 spin_unlock_irq(shost->host_lock);
8228 /* If we have the high WWPN we can assign our own
8229 * myDID; otherwise, we have to WAIT for a PLOGI
8230 * from the remote NPort to find out what it
8233 vport->fc_myDID = PT2PT_LocalID;
8235 vport->fc_myDID = PT2PT_RemoteID;
8239 * The vport state should go to LPFC_FLOGI only
8240 * AFTER we issue a FLOGI, not receive one.
8242 spin_lock_irq(shost->host_lock);
8243 fc_flag = vport->fc_flag;
8244 port_state = vport->port_state;
8245 vport->fc_flag |= FC_PT2PT;
8246 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8248 /* Acking an unsol FLOGI. Count 1 for link bounce
8251 vport->rcv_flogi_cnt++;
8252 spin_unlock_irq(shost->host_lock);
8253 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8254 "3311 Rcv Flogi PS x%x new PS x%x "
8255 "fc_flag x%x new fc_flag x%x\n",
8256 port_state, vport->port_state,
8257 fc_flag, vport->fc_flag);
8260 * We temporarily set fc_myDID to make it look like we are
8261 * a Fabric. This is done just so we end up with the right
8262 * did / sid on the FLOGI ACC rsp.
8264 did = vport->fc_myDID;
8265 vport->fc_myDID = Fabric_DID;
8267 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
8269 /* Defer ACC response until AFTER we issue a FLOGI */
8270 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
8271 phba->defer_flogi_acc_rx_id = bf_get(wqe_ctxt_tag,
8272 &wqe->xmit_els_rsp.wqe_com);
8273 phba->defer_flogi_acc_ox_id = bf_get(wqe_rcvoxid,
8274 &wqe->xmit_els_rsp.wqe_com);
8276 vport->fc_myDID = did;
8278 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8279 "3344 Deferring FLOGI ACC: rx_id: x%x,"
8280 " ox_id: x%x, hba_flag x%x\n",
8281 phba->defer_flogi_acc_rx_id,
8282 phba->defer_flogi_acc_ox_id, phba->hba_flag);
8284 phba->defer_flogi_acc_flag = true;
8290 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
8292 /* Now lets put fc_myDID back to what its supposed to be */
8293 vport->fc_myDID = did;
8299 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
8300 * @vport: pointer to a host virtual N_Port data structure.
8301 * @cmdiocb: pointer to lpfc command iocb data structure.
8302 * @ndlp: pointer to a node-list data structure.
8304 * This routine processes Request Node Identification Data (RNID) IOCB
8305 * received as an ELS unsolicited event. Only when the RNID specified format
8306 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
8307 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
8308 * Accept (ACC) the RNID ELS command. All the other RNID formats are
8309 * rejected by invoking the lpfc_els_rsp_reject() routine.
8312 * 0 - Successfully processed rnid iocb (currently always return 0)
8315 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8316 struct lpfc_nodelist *ndlp)
8318 struct lpfc_dmabuf *pcmd;
8323 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8324 lp = (uint32_t *) pcmd->virt;
8331 switch (rn->Format) {
8333 case RNID_TOPOLOGY_DISC:
8335 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
8338 /* Reject this request because format not supported */
8339 stat.un.b.lsRjtRsvd0 = 0;
8340 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8341 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8342 stat.un.b.vendorUnique = 0;
8343 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8350 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
8351 * @vport: pointer to a host virtual N_Port data structure.
8352 * @cmdiocb: pointer to lpfc command iocb data structure.
8353 * @ndlp: pointer to a node-list data structure.
8356 * 0 - Successfully processed echo iocb (currently always return 0)
8359 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8360 struct lpfc_nodelist *ndlp)
8364 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
8366 /* skip over first word of echo command to find echo data */
8367 pcmd += sizeof(uint32_t);
8369 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
8374 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
8375 * @vport: pointer to a host virtual N_Port data structure.
8376 * @cmdiocb: pointer to lpfc command iocb data structure.
8377 * @ndlp: pointer to a node-list data structure.
8379 * This routine processes a Link Incident Report Registration(LIRR) IOCB
8380 * received as an ELS unsolicited event. Currently, this function just invokes
8381 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
8384 * 0 - Successfully processed lirr iocb (currently always return 0)
8387 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8388 struct lpfc_nodelist *ndlp)
8392 /* For now, unconditionally reject this command */
8393 stat.un.b.lsRjtRsvd0 = 0;
8394 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8395 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8396 stat.un.b.vendorUnique = 0;
8397 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8402 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
8403 * @vport: pointer to a host virtual N_Port data structure.
8404 * @cmdiocb: pointer to lpfc command iocb data structure.
8405 * @ndlp: pointer to a node-list data structure.
8407 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
8408 * received as an ELS unsolicited event. A request to RRQ shall only
8409 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
8410 * Nx_Port N_Port_ID of the target Exchange is the same as the
8411 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
8412 * not accepted, an LS_RJT with reason code "Unable to perform
8413 * command request" and reason code explanation "Invalid Originator
8414 * S_ID" shall be returned. For now, we just unconditionally accept
8415 * RRQ from the target.
8418 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8419 struct lpfc_nodelist *ndlp)
8421 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8422 if (vport->phba->sli_rev == LPFC_SLI_REV4)
8423 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
8427 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
8428 * @phba: pointer to lpfc hba data structure.
8429 * @pmb: pointer to the driver internal queue element for mailbox command.
8431 * This routine is the completion callback function for the MBX_READ_LNK_STAT
8432 * mailbox command. This callback function is to actually send the Accept
8433 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
8434 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
8435 * mailbox command, constructs the RLS response with the link statistics
8436 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
8437 * response to the RLS.
8439 * Note that the ndlp reference count will be incremented by 1 for holding the
8440 * ndlp and the reference to ndlp will be stored into the context1 field of
8441 * the IOCB for the completion callback function to the RLS Accept Response
8446 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8451 union lpfc_wqe128 *wqe;
8452 struct RLS_RSP *rls_rsp;
8454 struct lpfc_iocbq *elsiocb;
8455 struct lpfc_nodelist *ndlp;
8463 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
8464 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
8465 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
8466 pmb->ctx_buf = NULL;
8467 pmb->ctx_ndlp = NULL;
8469 if (mb->mbxStatus) {
8470 mempool_free(pmb, phba->mbox_mem_pool);
8474 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
8475 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8476 lpfc_max_els_tries, ndlp,
8477 ndlp->nlp_DID, ELS_CMD_ACC);
8479 /* Decrement the ndlp reference count from previous mbox command */
8483 mempool_free(pmb, phba->mbox_mem_pool);
8487 ulp_context = get_job_ulpcontext(phba, elsiocb);
8488 if (phba->sli_rev == LPFC_SLI_REV4) {
8489 wqe = &elsiocb->wqe;
8491 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, rxid);
8492 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, oxid);
8494 icmd = &elsiocb->iocb;
8495 icmd->ulpContext = rxid;
8496 icmd->unsli3.rcvsli3.ox_id = oxid;
8499 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8500 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8501 pcmd += sizeof(uint32_t); /* Skip past command */
8502 rls_rsp = (struct RLS_RSP *)pcmd;
8504 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
8505 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
8506 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
8507 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
8508 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
8509 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
8510 mempool_free(pmb, phba->mbox_mem_pool);
8511 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8512 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8513 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
8514 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
8515 elsiocb->iotag, ulp_context,
8516 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8518 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8519 phba->fc_stat.elsXmitACC++;
8520 elsiocb->context1 = lpfc_nlp_get(ndlp);
8521 if (!elsiocb->context1) {
8522 lpfc_els_free_iocb(phba, elsiocb);
8526 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8527 if (rc == IOCB_ERROR) {
8528 lpfc_els_free_iocb(phba, elsiocb);
8535 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
8536 * @vport: pointer to a host virtual N_Port data structure.
8537 * @cmdiocb: pointer to lpfc command iocb data structure.
8538 * @ndlp: pointer to a node-list data structure.
8540 * This routine processes Read Link Status (RLS) IOCB received as an
8541 * ELS unsolicited event. It first checks the remote port state. If the
8542 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8543 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8544 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
8545 * for reading the HBA link statistics. It is for the callback function,
8546 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
8547 * to actually sending out RPL Accept (ACC) response.
8550 * 0 - Successfully processed rls iocb (currently always return 0)
8553 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8554 struct lpfc_nodelist *ndlp)
8556 struct lpfc_hba *phba = vport->phba;
8559 u32 ctx = get_job_ulpcontext(phba, cmdiocb);
8560 u32 ox_id = get_job_rcvoxid(phba, cmdiocb);
8562 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8563 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8564 /* reject the unsolicited RLS request and done with it */
8567 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
8569 lpfc_read_lnk_stat(phba, mbox);
8570 mbox->ctx_buf = (void *)((unsigned long)
8571 (ox_id << 16 | ctx));
8572 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
8573 if (!mbox->ctx_ndlp)
8575 mbox->vport = vport;
8576 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
8577 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8578 != MBX_NOT_FINISHED)
8579 /* Mbox completion will send ELS Response */
8581 /* Decrement reference count used for the failed mbox
8586 mempool_free(mbox, phba->mbox_mem_pool);
8589 /* issue rejection response */
8590 stat.un.b.lsRjtRsvd0 = 0;
8591 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8592 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8593 stat.un.b.vendorUnique = 0;
8594 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8599 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
8600 * @vport: pointer to a host virtual N_Port data structure.
8601 * @cmdiocb: pointer to lpfc command iocb data structure.
8602 * @ndlp: pointer to a node-list data structure.
8604 * This routine processes Read Timout Value (RTV) IOCB received as an
8605 * ELS unsolicited event. It first checks the remote port state. If the
8606 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8607 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8608 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
8609 * Value (RTV) unsolicited IOCB event.
8611 * Note that the ndlp reference count will be incremented by 1 for holding the
8612 * ndlp and the reference to ndlp will be stored into the context1 field of
8613 * the IOCB for the completion callback function to the RTV Accept Response
8617 * 0 - Successfully processed rtv iocb (currently always return 0)
8620 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8621 struct lpfc_nodelist *ndlp)
8625 union lpfc_wqe128 *wqe;
8626 struct lpfc_hba *phba = vport->phba;
8628 struct RTV_RSP *rtv_rsp;
8630 struct lpfc_iocbq *elsiocb;
8634 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8635 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8636 /* reject the unsolicited RTV request and done with it */
8639 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
8640 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8641 lpfc_max_els_tries, ndlp,
8642 ndlp->nlp_DID, ELS_CMD_ACC);
8647 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8648 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8649 pcmd += sizeof(uint32_t); /* Skip past command */
8651 ulp_context = get_job_ulpcontext(phba, elsiocb);
8652 /* use the command's xri in the response */
8653 if (phba->sli_rev == LPFC_SLI_REV4) {
8654 wqe = &elsiocb->wqe;
8655 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
8656 get_job_ulpcontext(phba, cmdiocb));
8657 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8658 get_job_rcvoxid(phba, cmdiocb));
8660 icmd = &elsiocb->iocb;
8661 icmd->ulpContext = get_job_ulpcontext(phba, cmdiocb);
8662 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, cmdiocb);
8665 rtv_rsp = (struct RTV_RSP *)pcmd;
8667 /* populate RTV payload */
8668 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
8669 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
8670 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
8671 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
8672 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
8674 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8675 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8676 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
8677 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
8678 "Data: x%x x%x x%x\n",
8679 elsiocb->iotag, ulp_context,
8680 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8682 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
8683 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8684 phba->fc_stat.elsXmitACC++;
8685 elsiocb->context1 = lpfc_nlp_get(ndlp);
8686 if (!elsiocb->context1) {
8687 lpfc_els_free_iocb(phba, elsiocb);
8691 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8692 if (rc == IOCB_ERROR) {
8693 lpfc_els_free_iocb(phba, elsiocb);
8699 /* issue rejection response */
8700 stat.un.b.lsRjtRsvd0 = 0;
8701 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8702 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8703 stat.un.b.vendorUnique = 0;
8704 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8708 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
8709 * @vport: pointer to a host virtual N_Port data structure.
8710 * @ndlp: pointer to a node-list data structure.
8711 * @did: DID of the target.
8712 * @rrq: Pointer to the rrq struct.
8714 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
8715 * Successful the the completion handler will clear the RRQ.
8718 * 0 - Successfully sent rrq els iocb.
8719 * 1 - Failed to send rrq els iocb.
8722 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8723 uint32_t did, struct lpfc_node_rrq *rrq)
8725 struct lpfc_hba *phba = vport->phba;
8726 struct RRQ *els_rrq;
8727 struct lpfc_iocbq *elsiocb;
8735 /* If ndlp is not NULL, we will bump the reference count on it */
8736 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
8737 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
8742 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8744 /* For RRQ request, remainder of payload is Exchange IDs */
8745 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
8746 pcmd += sizeof(uint32_t);
8747 els_rrq = (struct RRQ *) pcmd;
8749 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
8750 bf_set(rrq_rxid, els_rrq, rrq->rxid);
8751 bf_set(rrq_did, els_rrq, vport->fc_myDID);
8752 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
8753 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
8756 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8757 "Issue RRQ: did:x%x",
8758 did, rrq->xritag, rrq->rxid);
8759 elsiocb->context_un.rrq = rrq;
8760 elsiocb->cmd_cmpl = lpfc_cmpl_els_rrq;
8763 elsiocb->context1 = ndlp;
8765 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8766 if (ret == IOCB_ERROR)
8771 lpfc_els_free_iocb(phba, elsiocb);
8777 * lpfc_send_rrq - Sends ELS RRQ if needed.
8778 * @phba: pointer to lpfc hba data structure.
8779 * @rrq: pointer to the active rrq.
8781 * This routine will call the lpfc_issue_els_rrq if the rrq is
8782 * still active for the xri. If this function returns a failure then
8783 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
8785 * Returns 0 Success.
8789 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
8791 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
8796 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
8797 return lpfc_issue_els_rrq(rrq->vport, ndlp,
8804 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
8805 * @vport: pointer to a host virtual N_Port data structure.
8806 * @cmdsize: size of the ELS command.
8807 * @oldiocb: pointer to the original lpfc command iocb data structure.
8808 * @ndlp: pointer to a node-list data structure.
8810 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
8811 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
8813 * Note that the ndlp reference count will be incremented by 1 for holding the
8814 * ndlp and the reference to ndlp will be stored into the context1 field of
8815 * the IOCB for the completion callback function to the RPL Accept Response
8819 * 0 - Successfully issued ACC RPL ELS command
8820 * 1 - Failed to issue ACC RPL ELS command
8823 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
8824 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
8827 struct lpfc_hba *phba = vport->phba;
8829 union lpfc_wqe128 *wqe;
8831 struct lpfc_iocbq *elsiocb;
8835 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
8836 ndlp->nlp_DID, ELS_CMD_ACC);
8841 ulp_context = get_job_ulpcontext(phba, elsiocb);
8842 if (phba->sli_rev == LPFC_SLI_REV4) {
8843 wqe = &elsiocb->wqe;
8845 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
8846 get_job_ulpcontext(phba, oldiocb));
8847 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8848 get_job_rcvoxid(phba, oldiocb));
8850 icmd = &elsiocb->iocb;
8851 icmd->ulpContext = get_job_ulpcontext(phba, oldiocb);
8852 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, oldiocb);
8855 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8856 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8857 pcmd += sizeof(uint16_t);
8858 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
8859 pcmd += sizeof(uint16_t);
8861 /* Setup the RPL ACC payload */
8862 rpl_rsp.listLen = be32_to_cpu(1);
8864 rpl_rsp.port_num_blk.portNum = 0;
8865 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
8866 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
8867 sizeof(struct lpfc_name));
8868 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
8869 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
8870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8871 "0120 Xmit ELS RPL ACC response tag x%x "
8872 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
8874 elsiocb->iotag, ulp_context,
8875 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8877 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8878 phba->fc_stat.elsXmitACC++;
8879 elsiocb->context1 = lpfc_nlp_get(ndlp);
8880 if (!elsiocb->context1) {
8881 lpfc_els_free_iocb(phba, elsiocb);
8885 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8886 if (rc == IOCB_ERROR) {
8887 lpfc_els_free_iocb(phba, elsiocb);
8896 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
8897 * @vport: pointer to a host virtual N_Port data structure.
8898 * @cmdiocb: pointer to lpfc command iocb data structure.
8899 * @ndlp: pointer to a node-list data structure.
8901 * This routine processes Read Port List (RPL) IOCB received as an ELS
8902 * unsolicited event. It first checks the remote port state. If the remote
8903 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
8904 * invokes the lpfc_els_rsp_reject() routine to send reject response.
8905 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
8906 * to accept the RPL.
8909 * 0 - Successfully processed rpl iocb (currently always return 0)
8912 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8913 struct lpfc_nodelist *ndlp)
8915 struct lpfc_dmabuf *pcmd;
8922 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8923 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
8924 /* issue rejection response */
8925 stat.un.b.lsRjtRsvd0 = 0;
8926 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8927 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8928 stat.un.b.vendorUnique = 0;
8929 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8931 /* rejected the unsolicited RPL request and done with it */
8935 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8936 lp = (uint32_t *) pcmd->virt;
8937 rpl = (RPL *) (lp + 1);
8938 maxsize = be32_to_cpu(rpl->maxsize);
8940 /* We support only one port */
8941 if ((rpl->index == 0) &&
8943 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
8944 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
8946 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
8948 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
8954 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
8955 * @vport: pointer to a virtual N_Port data structure.
8956 * @cmdiocb: pointer to lpfc command iocb data structure.
8957 * @ndlp: pointer to a node-list data structure.
8959 * This routine processes Fibre Channel Address Resolution Protocol
8960 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
8961 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
8962 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
8963 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
8964 * remote PortName is compared against the FC PortName stored in the @vport
8965 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
8966 * compared against the FC NodeName stored in the @vport data structure.
8967 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
8968 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
8969 * invoked to send out FARP Response to the remote node. Before sending the
8970 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
8971 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
8972 * routine is invoked to log into the remote port first.
8975 * 0 - Either the FARP Match Mode not supported or successfully processed
8978 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8979 struct lpfc_nodelist *ndlp)
8981 struct lpfc_dmabuf *pcmd;
8986 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
8987 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8988 lp = (uint32_t *) pcmd->virt;
8992 /* FARP-REQ received from DID <did> */
8993 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8994 "0601 FARP-REQ received from DID x%x\n", did);
8995 /* We will only support match on WWPN or WWNN */
8996 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
9001 /* If this FARP command is searching for my portname */
9002 if (fp->Mflags & FARP_MATCH_PORT) {
9003 if (memcmp(&fp->RportName, &vport->fc_portname,
9004 sizeof(struct lpfc_name)) == 0)
9008 /* If this FARP command is searching for my nodename */
9009 if (fp->Mflags & FARP_MATCH_NODE) {
9010 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
9011 sizeof(struct lpfc_name)) == 0)
9016 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
9017 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
9018 /* Log back into the node before sending the FARP. */
9019 if (fp->Rflags & FARP_REQUEST_PLOGI) {
9020 ndlp->nlp_prev_state = ndlp->nlp_state;
9021 lpfc_nlp_set_state(vport, ndlp,
9022 NLP_STE_PLOGI_ISSUE);
9023 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9026 /* Send a FARP response to that node */
9027 if (fp->Rflags & FARP_REQUEST_FARPR)
9028 lpfc_issue_els_farpr(vport, did, 0);
9035 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
9036 * @vport: pointer to a host virtual N_Port data structure.
9037 * @cmdiocb: pointer to lpfc command iocb data structure.
9038 * @ndlp: pointer to a node-list data structure.
9040 * This routine processes Fibre Channel Address Resolution Protocol
9041 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
9042 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
9043 * the FARP response request.
9046 * 0 - Successfully processed FARPR IOCB (currently always return 0)
9049 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9050 struct lpfc_nodelist *ndlp)
9052 struct lpfc_dmabuf *pcmd;
9056 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
9057 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
9058 lp = (uint32_t *) pcmd->virt;
9061 /* FARP-RSP received from DID <did> */
9062 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9063 "0600 FARP-RSP received from DID x%x\n", did);
9064 /* ACCEPT the Farp resp request */
9065 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
9071 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
9072 * @vport: pointer to a host virtual N_Port data structure.
9073 * @cmdiocb: pointer to lpfc command iocb data structure.
9074 * @fan_ndlp: pointer to a node-list data structure.
9076 * This routine processes a Fabric Address Notification (FAN) IOCB
9077 * command received as an ELS unsolicited event. The FAN ELS command will
9078 * only be processed on a physical port (i.e., the @vport represents the
9079 * physical port). The fabric NodeName and PortName from the FAN IOCB are
9080 * compared against those in the phba data structure. If any of those is
9081 * different, the lpfc_initial_flogi() routine is invoked to initialize
9082 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
9083 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
9084 * is invoked to register login to the fabric.
9087 * 0 - Successfully processed fan iocb (currently always return 0).
9090 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9091 struct lpfc_nodelist *fan_ndlp)
9093 struct lpfc_hba *phba = vport->phba;
9097 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
9098 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
9100 /* FAN received; Fan does not have a reply sequence */
9101 if ((vport == phba->pport) &&
9102 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
9103 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
9104 sizeof(struct lpfc_name))) ||
9105 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
9106 sizeof(struct lpfc_name)))) {
9107 /* This port has switched fabrics. FLOGI is required */
9108 lpfc_issue_init_vfi(vport);
9110 /* FAN verified - skip FLOGI */
9111 vport->fc_myDID = vport->fc_prevDID;
9112 if (phba->sli_rev < LPFC_SLI_REV4)
9113 lpfc_issue_fabric_reglogin(vport);
9115 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9116 "3138 Need register VFI: (x%x/%x)\n",
9117 vport->fc_prevDID, vport->fc_myDID);
9118 lpfc_issue_reg_vfi(vport);
9126 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb
9127 * @vport: pointer to a host virtual N_Port data structure.
9128 * @cmdiocb: pointer to lpfc command iocb data structure.
9129 * @ndlp: pointer to a node-list data structure.
9132 * 0 - Successfully processed echo iocb (currently always return 0)
9135 lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9136 struct lpfc_nodelist *ndlp)
9138 struct lpfc_hba *phba = vport->phba;
9139 struct fc_els_edc *edc_req;
9140 struct fc_tlv_desc *tlv;
9142 uint32_t *ptr, dtag;
9143 const char *dtag_nm;
9144 int desc_cnt = 0, bytes_remain;
9145 bool rcv_cap_desc = false;
9147 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
9149 edc_req = (struct fc_els_edc *)payload;
9150 bytes_remain = be32_to_cpu(edc_req->desc_len);
9152 ptr = (uint32_t *)payload;
9153 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
9154 "3319 Rcv EDC payload len %d: x%x x%x x%x\n",
9155 bytes_remain, be32_to_cpu(*ptr),
9156 be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2)));
9158 /* No signal support unless there is a congestion descriptor */
9159 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9160 phba->cgn_sig_freq = 0;
9161 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
9163 if (bytes_remain <= 0)
9166 tlv = edc_req->desc;
9169 * cycle through EDC diagnostic descriptors to find the
9170 * congestion signaling capability descriptor
9172 while (bytes_remain && !rcv_cap_desc) {
9173 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
9174 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9175 "6464 Truncated TLV hdr on "
9176 "Diagnostic descriptor[%d]\n",
9181 dtag = be32_to_cpu(tlv->desc_tag);
9183 case ELS_DTAG_LNK_FAULT_CAP:
9184 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9185 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9186 sizeof(struct fc_diag_lnkflt_desc)) {
9188 phba, KERN_WARNING, LOG_CGN_MGMT,
9189 "6465 Truncated Link Fault Diagnostic "
9190 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9191 desc_cnt, bytes_remain,
9192 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9193 sizeof(struct fc_diag_cg_sig_desc));
9196 /* No action for Link Fault descriptor for now */
9198 case ELS_DTAG_CG_SIGNAL_CAP:
9199 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9200 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9201 sizeof(struct fc_diag_cg_sig_desc)) {
9203 phba, KERN_WARNING, LOG_CGN_MGMT,
9204 "6466 Truncated cgn signal Diagnostic "
9205 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9206 desc_cnt, bytes_remain,
9207 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9208 sizeof(struct fc_diag_cg_sig_desc));
9212 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
9213 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
9215 /* We start negotiation with lpfc_fabric_cgn_frequency.
9216 * When we process the EDC, we will settle on the
9219 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9221 lpfc_least_capable_settings(
9222 phba, (struct fc_diag_cg_sig_desc *)tlv);
9223 rcv_cap_desc = true;
9226 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
9227 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9228 "6467 unknown Diagnostic "
9229 "Descriptor[%d]: tag x%x (%s)\n",
9230 desc_cnt, dtag, dtag_nm);
9232 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
9233 tlv = fc_tlv_next_desc(tlv);
9237 /* Need to send back an ACC */
9238 lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp);
9240 lpfc_config_cgn_signal(phba);
9245 * lpfc_els_timeout - Handler funciton to the els timer
9246 * @t: timer context used to obtain the vport.
9248 * This routine is invoked by the ELS timer after timeout. It posts the ELS
9249 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
9250 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
9251 * up the worker thread. It is for the worker thread to invoke the routine
9252 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
9255 lpfc_els_timeout(struct timer_list *t)
9257 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
9258 struct lpfc_hba *phba = vport->phba;
9259 uint32_t tmo_posted;
9260 unsigned long iflag;
9262 spin_lock_irqsave(&vport->work_port_lock, iflag);
9263 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
9264 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
9265 vport->work_port_events |= WORKER_ELS_TMO;
9266 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
9268 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
9269 lpfc_worker_wake_up(phba);
9275 * lpfc_els_timeout_handler - Process an els timeout event
9276 * @vport: pointer to a virtual N_Port data structure.
9278 * This routine is the actual handler function that processes an ELS timeout
9279 * event. It walks the ELS ring to get and abort all the IOCBs (except the
9280 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
9281 * invoking the lpfc_sli_issue_abort_iotag() routine.
9284 lpfc_els_timeout_handler(struct lpfc_vport *vport)
9286 struct lpfc_hba *phba = vport->phba;
9287 struct lpfc_sli_ring *pring;
9288 struct lpfc_iocbq *tmp_iocb, *piocb;
9290 struct lpfc_dmabuf *pcmd;
9291 uint32_t els_command = 0;
9293 uint32_t remote_ID = 0xffffffff;
9294 LIST_HEAD(abort_list);
9295 u32 ulp_command = 0, ulp_context = 0, did = 0, iotag = 0;
9298 timeout = (uint32_t)(phba->fc_ratov << 1);
9300 pring = lpfc_phba_elsring(phba);
9301 if (unlikely(!pring))
9304 if (phba->pport->load_flag & FC_UNLOADING)
9307 spin_lock_irq(&phba->hbalock);
9308 if (phba->sli_rev == LPFC_SLI_REV4)
9309 spin_lock(&pring->ring_lock);
9311 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9312 ulp_command = get_job_cmnd(phba, piocb);
9313 ulp_context = get_job_ulpcontext(phba, piocb);
9314 did = get_job_els_rsp64_did(phba, piocb);
9316 if (phba->sli_rev == LPFC_SLI_REV4) {
9317 iotag = get_wqe_reqtag(piocb);
9320 iotag = cmd->ulpIoTag;
9323 if ((piocb->cmd_flag & LPFC_IO_LIBDFC) != 0 ||
9324 ulp_command == CMD_ABORT_XRI_CX ||
9325 ulp_command == CMD_ABORT_XRI_CN ||
9326 ulp_command == CMD_CLOSE_XRI_CN)
9329 if (piocb->vport != vport)
9332 pcmd = (struct lpfc_dmabuf *) piocb->context2;
9334 els_command = *(uint32_t *) (pcmd->virt);
9336 if (els_command == ELS_CMD_FARP ||
9337 els_command == ELS_CMD_FARPR ||
9338 els_command == ELS_CMD_FDISC)
9341 if (piocb->drvrTimeout > 0) {
9342 if (piocb->drvrTimeout >= timeout)
9343 piocb->drvrTimeout -= timeout;
9345 piocb->drvrTimeout = 0;
9349 remote_ID = 0xffffffff;
9350 if (ulp_command != CMD_GEN_REQUEST64_CR) {
9353 struct lpfc_nodelist *ndlp;
9354 ndlp = __lpfc_findnode_rpi(vport, ulp_context);
9356 remote_ID = ndlp->nlp_DID;
9358 list_add_tail(&piocb->dlist, &abort_list);
9360 if (phba->sli_rev == LPFC_SLI_REV4)
9361 spin_unlock(&pring->ring_lock);
9362 spin_unlock_irq(&phba->hbalock);
9364 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9365 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9366 "0127 ELS timeout Data: x%x x%x x%x "
9367 "x%x\n", els_command,
9368 remote_ID, ulp_command, iotag);
9370 spin_lock_irq(&phba->hbalock);
9371 list_del_init(&piocb->dlist);
9372 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9373 spin_unlock_irq(&phba->hbalock);
9376 /* Make sure HBA is alive */
9377 lpfc_issue_hb_tmo(phba);
9379 if (!list_empty(&pring->txcmplq))
9380 if (!(phba->pport->load_flag & FC_UNLOADING))
9381 mod_timer(&vport->els_tmofunc,
9382 jiffies + msecs_to_jiffies(1000 * timeout));
9386 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
9387 * @vport: pointer to a host virtual N_Port data structure.
9389 * This routine is used to clean up all the outstanding ELS commands on a
9390 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
9391 * routine. After that, it walks the ELS transmit queue to remove all the
9392 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
9393 * the IOCBs with a non-NULL completion callback function, the callback
9394 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9395 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
9396 * callback function, the IOCB will simply be released. Finally, it walks
9397 * the ELS transmit completion queue to issue an abort IOCB to any transmit
9398 * completion queue IOCB that is associated with the @vport and is not
9399 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
9400 * part of the discovery state machine) out to HBA by invoking the
9401 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
9402 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
9403 * the IOCBs are aborted when this function returns.
9406 lpfc_els_flush_cmd(struct lpfc_vport *vport)
9408 LIST_HEAD(abort_list);
9409 struct lpfc_hba *phba = vport->phba;
9410 struct lpfc_sli_ring *pring;
9411 struct lpfc_iocbq *tmp_iocb, *piocb;
9413 unsigned long iflags = 0;
9415 lpfc_fabric_abort_vport(vport);
9418 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
9419 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
9420 * ultimately grabs the ring_lock, the driver must splice the list into
9421 * a working list and release the locks before calling the abort.
9423 spin_lock_irqsave(&phba->hbalock, iflags);
9424 pring = lpfc_phba_elsring(phba);
9426 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
9427 if (unlikely(!pring)) {
9428 spin_unlock_irqrestore(&phba->hbalock, iflags);
9432 if (phba->sli_rev == LPFC_SLI_REV4)
9433 spin_lock(&pring->ring_lock);
9435 /* First we need to issue aborts to outstanding cmds on txcmpl */
9436 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9437 if (piocb->cmd_flag & LPFC_IO_LIBDFC)
9440 if (piocb->vport != vport)
9443 if (piocb->cmd_flag & LPFC_DRIVER_ABORTED)
9446 /* On the ELS ring we can have ELS_REQUESTs or
9447 * GEN_REQUESTs waiting for a response.
9449 ulp_command = get_job_cmnd(phba, piocb);
9450 if (ulp_command == CMD_ELS_REQUEST64_CR) {
9451 list_add_tail(&piocb->dlist, &abort_list);
9453 /* If the link is down when flushing ELS commands
9454 * the firmware will not complete them till after
9455 * the link comes back up. This may confuse
9456 * discovery for the new link up, so we need to
9457 * change the compl routine to just clean up the iocb
9458 * and avoid any retry logic.
9460 if (phba->link_state == LPFC_LINK_DOWN)
9461 piocb->cmd_cmpl = lpfc_cmpl_els_link_down;
9463 if (ulp_command == CMD_GEN_REQUEST64_CR)
9464 list_add_tail(&piocb->dlist, &abort_list);
9467 if (phba->sli_rev == LPFC_SLI_REV4)
9468 spin_unlock(&pring->ring_lock);
9469 spin_unlock_irqrestore(&phba->hbalock, iflags);
9471 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
9472 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9473 spin_lock_irqsave(&phba->hbalock, iflags);
9474 list_del_init(&piocb->dlist);
9475 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9476 spin_unlock_irqrestore(&phba->hbalock, iflags);
9478 /* Make sure HBA is alive */
9479 lpfc_issue_hb_tmo(phba);
9481 if (!list_empty(&abort_list))
9482 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9483 "3387 abort list for txq not empty\n");
9484 INIT_LIST_HEAD(&abort_list);
9486 spin_lock_irqsave(&phba->hbalock, iflags);
9487 if (phba->sli_rev == LPFC_SLI_REV4)
9488 spin_lock(&pring->ring_lock);
9490 /* No need to abort the txq list,
9491 * just queue them up for lpfc_sli_cancel_iocbs
9493 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
9494 ulp_command = get_job_cmnd(phba, piocb);
9496 if (piocb->cmd_flag & LPFC_IO_LIBDFC)
9499 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
9500 if (ulp_command == CMD_QUE_RING_BUF_CN ||
9501 ulp_command == CMD_QUE_RING_BUF64_CN ||
9502 ulp_command == CMD_CLOSE_XRI_CN ||
9503 ulp_command == CMD_ABORT_XRI_CN ||
9504 ulp_command == CMD_ABORT_XRI_CX)
9507 if (piocb->vport != vport)
9510 list_del_init(&piocb->list);
9511 list_add_tail(&piocb->list, &abort_list);
9514 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
9515 if (vport == phba->pport) {
9516 list_for_each_entry_safe(piocb, tmp_iocb,
9517 &phba->fabric_iocb_list, list) {
9518 list_del_init(&piocb->list);
9519 list_add_tail(&piocb->list, &abort_list);
9523 if (phba->sli_rev == LPFC_SLI_REV4)
9524 spin_unlock(&pring->ring_lock);
9525 spin_unlock_irqrestore(&phba->hbalock, iflags);
9527 /* Cancel all the IOCBs from the completions list */
9528 lpfc_sli_cancel_iocbs(phba, &abort_list,
9529 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
9535 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
9536 * @phba: pointer to lpfc hba data structure.
9538 * This routine is used to clean up all the outstanding ELS commands on a
9539 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
9540 * routine. After that, it walks the ELS transmit queue to remove all the
9541 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
9542 * the IOCBs with the completion callback function associated, the callback
9543 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9544 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
9545 * callback function associated, the IOCB will simply be released. Finally,
9546 * it walks the ELS transmit completion queue to issue an abort IOCB to any
9547 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
9548 * management plane IOCBs that are not part of the discovery state machine)
9549 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
9552 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
9554 struct lpfc_vport *vport;
9556 spin_lock_irq(&phba->port_list_lock);
9557 list_for_each_entry(vport, &phba->port_list, listentry)
9558 lpfc_els_flush_cmd(vport);
9559 spin_unlock_irq(&phba->port_list_lock);
9565 * lpfc_send_els_failure_event - Posts an ELS command failure event
9566 * @phba: Pointer to hba context object.
9567 * @cmdiocbp: Pointer to command iocb which reported error.
9568 * @rspiocbp: Pointer to response iocb which reported error.
9570 * This function sends an event when there is an ELS command
9574 lpfc_send_els_failure_event(struct lpfc_hba *phba,
9575 struct lpfc_iocbq *cmdiocbp,
9576 struct lpfc_iocbq *rspiocbp)
9578 struct lpfc_vport *vport = cmdiocbp->vport;
9579 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9580 struct lpfc_lsrjt_event lsrjt_event;
9581 struct lpfc_fabric_event_header fabric_event;
9583 struct lpfc_nodelist *ndlp;
9585 u32 ulp_status, ulp_word4;
9587 ndlp = cmdiocbp->context1;
9591 ulp_status = get_job_ulpstatus(phba, rspiocbp);
9592 ulp_word4 = get_job_word4(phba, rspiocbp);
9594 if (ulp_status == IOSTAT_LS_RJT) {
9595 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
9596 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
9597 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
9598 sizeof(struct lpfc_name));
9599 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
9600 sizeof(struct lpfc_name));
9601 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
9602 cmdiocbp->context2)->virt);
9603 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
9604 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
9605 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
9606 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
9607 fc_host_post_vendor_event(shost,
9608 fc_get_event_number(),
9609 sizeof(lsrjt_event),
9610 (char *)&lsrjt_event,
9614 if (ulp_status == IOSTAT_NPORT_BSY ||
9615 ulp_status == IOSTAT_FABRIC_BSY) {
9616 fabric_event.event_type = FC_REG_FABRIC_EVENT;
9617 if (ulp_status == IOSTAT_NPORT_BSY)
9618 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
9620 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
9621 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
9622 sizeof(struct lpfc_name));
9623 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
9624 sizeof(struct lpfc_name));
9625 fc_host_post_vendor_event(shost,
9626 fc_get_event_number(),
9627 sizeof(fabric_event),
9628 (char *)&fabric_event,
9636 * lpfc_send_els_event - Posts unsolicited els event
9637 * @vport: Pointer to vport object.
9638 * @ndlp: Pointer FC node object.
9639 * @payload: ELS command code type.
9641 * This function posts an event when there is an incoming
9642 * unsolicited ELS command.
9645 lpfc_send_els_event(struct lpfc_vport *vport,
9646 struct lpfc_nodelist *ndlp,
9649 struct lpfc_els_event_header *els_data = NULL;
9650 struct lpfc_logo_event *logo_data = NULL;
9651 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9653 if (*payload == ELS_CMD_LOGO) {
9654 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
9656 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9657 "0148 Failed to allocate memory "
9658 "for LOGO event\n");
9661 els_data = &logo_data->header;
9663 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
9666 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9667 "0149 Failed to allocate memory "
9672 els_data->event_type = FC_REG_ELS_EVENT;
9675 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
9678 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
9681 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
9684 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
9685 /* Copy the WWPN in the LOGO payload */
9686 memcpy(logo_data->logo_wwpn, &payload[2],
9687 sizeof(struct lpfc_name));
9693 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
9694 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
9695 if (*payload == ELS_CMD_LOGO) {
9696 fc_host_post_vendor_event(shost,
9697 fc_get_event_number(),
9698 sizeof(struct lpfc_logo_event),
9703 fc_host_post_vendor_event(shost,
9704 fc_get_event_number(),
9705 sizeof(struct lpfc_els_event_header),
9715 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
9716 FC_FPIN_LI_EVT_TYPES_INIT);
9718 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types,
9719 FC_FPIN_DELI_EVT_TYPES_INIT);
9721 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types,
9722 FC_FPIN_CONGN_EVT_TYPES_INIT);
9724 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm,
9725 fc_fpin_congn_severity_types,
9726 FC_FPIN_CONGN_SEVERITY_INIT);
9730 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port
9731 * @phba: Pointer to phba object.
9732 * @wwnlist: Pointer to list of WWPNs in FPIN payload
9733 * @cnt: count of WWPNs in FPIN payload
9735 * This routine is called by LI and PC descriptors.
9736 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message
9739 lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt)
9741 char buf[LPFC_FPIN_WWPN_LINE_SZ];
9749 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:");
9750 for (i = 0; i < cnt; i++) {
9751 /* Are we on the last WWPN */
9755 /* Extract the next WWPN from the payload */
9757 wwpn = be64_to_cpu(wwn);
9758 len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len,
9761 /* Log a message if we are on the last WWPN
9762 * or if we hit the max allowed per message.
9765 if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) {
9767 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9770 /* Check if we reached the last WWPN */
9774 /* Limit the number of log message displayed per FPIN */
9776 if (line == LPFC_FPIN_WWPN_NUM_LINE) {
9777 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9778 "4687 %d WWPNs Truncated\n",
9783 /* Start over with next log message */
9785 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ,
9786 "Additional WWPNs:");
9792 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
9793 * @phba: Pointer to phba object.
9794 * @tlv: Pointer to the Link Integrity Notification Descriptor.
9796 * This function processes a Link Integrity FPIN event by logging a message.
9799 lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9801 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
9802 const char *li_evt_str;
9805 li_evt = be16_to_cpu(li->event_type);
9806 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
9807 cnt = be32_to_cpu(li->pname_count);
9809 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9810 "4680 FPIN Link Integrity %s (x%x) "
9811 "Detecting PN x%016llx Attached PN x%016llx "
9812 "Duration %d mSecs Count %d Port Cnt %d\n",
9814 be64_to_cpu(li->detecting_wwpn),
9815 be64_to_cpu(li->attached_wwpn),
9816 be32_to_cpu(li->event_threshold),
9817 be32_to_cpu(li->event_count), cnt);
9819 lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt);
9823 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event.
9824 * @phba: Pointer to hba object.
9825 * @tlv: Pointer to the Delivery Notification Descriptor TLV
9827 * This function processes a Delivery FPIN event by logging a message.
9830 lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9832 struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv;
9833 const char *del_rsn_str;
9837 del_rsn = be16_to_cpu(del->deli_reason_code);
9838 del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn);
9840 /* Skip over desc_tag/desc_len header to payload */
9841 frame = (__be32 *)(del + 1);
9843 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9844 "4681 FPIN Delivery %s (x%x) "
9845 "Detecting PN x%016llx Attached PN x%016llx "
9847 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x "
9848 "DiscHdr4 x%08x DiscHdr5 x%08x\n",
9849 del_rsn_str, del_rsn,
9850 be64_to_cpu(del->detecting_wwpn),
9851 be64_to_cpu(del->attached_wwpn),
9852 be32_to_cpu(frame[0]),
9853 be32_to_cpu(frame[1]),
9854 be32_to_cpu(frame[2]),
9855 be32_to_cpu(frame[3]),
9856 be32_to_cpu(frame[4]),
9857 be32_to_cpu(frame[5]));
9861 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event.
9862 * @phba: Pointer to hba object.
9863 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV
9865 * This function processes a Peer Congestion FPIN event by logging a message.
9868 lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9870 struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv;
9871 const char *pc_evt_str;
9874 pc_evt = be16_to_cpu(pc->event_type);
9875 pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt);
9876 cnt = be32_to_cpu(pc->pname_count);
9878 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS,
9879 "4684 FPIN Peer Congestion %s (x%x) "
9880 "Duration %d mSecs "
9881 "Detecting PN x%016llx Attached PN x%016llx "
9882 "Impacted Port Cnt %d\n",
9884 be32_to_cpu(pc->event_period),
9885 be64_to_cpu(pc->detecting_wwpn),
9886 be64_to_cpu(pc->attached_wwpn),
9889 lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt);
9893 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification
9894 * @phba: Pointer to hba object.
9895 * @tlv: Pointer to the Congestion Notification Descriptor TLV
9897 * This function processes an FPIN Congestion Notifiction. The notification
9898 * could be an Alarm or Warning. This routine feeds that data into driver's
9899 * running congestion algorithm. It also processes the FPIN by
9900 * logging a message. It returns 1 to indicate deliver this message
9901 * to the upper layer or 0 to indicate don't deliver it.
9904 lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9906 struct lpfc_cgn_info *cp;
9907 struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv;
9908 const char *cgn_evt_str;
9910 const char *cgn_sev_str;
9914 bool nm_log = false;
9917 cgn_evt = be16_to_cpu(cgn->event_type);
9918 cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt);
9919 cgn_sev = cgn->severity;
9920 cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev);
9922 /* The driver only takes action on a Credit Stall or Oversubscription
9923 * event type to engage the IO algorithm. The driver prints an
9924 * unmaskable message only for Lost Credit and Credit Stall.
9925 * TODO: Still need to have definition of host action on clear,
9926 * lost credit and device specific event types.
9929 case FPIN_CONGN_LOST_CREDIT:
9932 case FPIN_CONGN_CREDIT_STALL:
9935 case FPIN_CONGN_OVERSUBSCRIPTION:
9936 if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION)
9939 case FPIN_CONGN_SEVERITY_ERROR:
9940 /* Take action here for an Alarm event */
9941 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
9942 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) {
9943 /* Track of alarm cnt for cgn_info */
9944 atomic_inc(&phba->cgn_fabric_alarm_cnt);
9945 /* Track of alarm cnt for SYNC_WQE */
9946 atomic_inc(&phba->cgn_sync_alarm_cnt);
9951 case FPIN_CONGN_SEVERITY_WARNING:
9952 /* Take action here for a Warning event */
9953 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
9954 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) {
9955 /* Track of warning cnt for cgn_info */
9956 atomic_inc(&phba->cgn_fabric_warn_cnt);
9957 /* Track of warning cnt for SYNC_WQE */
9958 atomic_inc(&phba->cgn_sync_warn_cnt);
9961 /* Save frequency in ms */
9962 phba->cgn_fpin_frequency =
9963 be32_to_cpu(cgn->event_period);
9964 value = phba->cgn_fpin_frequency;
9966 cp = (struct lpfc_cgn_info *)
9968 if (phba->cgn_reg_fpin &
9969 LPFC_CGN_FPIN_ALARM)
9970 cp->cgn_alarm_freq =
9972 if (phba->cgn_reg_fpin &
9976 crc = lpfc_cgn_calc_crc32
9979 LPFC_CGN_CRC32_SEED);
9980 cp->cgn_info_crc = cpu_to_le32(crc);
9983 /* Don't deliver to upper layer since
9984 * driver took action on this tlv.
9993 /* Change the log level to unmaskable for the following event types. */
9994 lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO),
9995 LOG_CGN_MGMT | LOG_ELS,
9996 "4683 FPIN CONGESTION %s type %s (x%x) Event "
9997 "Duration %d mSecs\n",
9998 cgn_sev_str, cgn_evt_str, cgn_evt,
9999 be32_to_cpu(cgn->event_period));
10004 lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length)
10006 struct lpfc_hba *phba = vport->phba;
10007 struct fc_els_fpin *fpin = (struct fc_els_fpin *)p;
10008 struct fc_tlv_desc *tlv, *first_tlv, *current_tlv;
10009 const char *dtag_nm;
10010 int desc_cnt = 0, bytes_remain, cnt;
10011 u32 dtag, deliver = 0;
10014 /* FPINs handled only if we are in the right discovery state */
10015 if (vport->port_state < LPFC_DISC_AUTH)
10018 /* make sure there is the full fpin header */
10019 if (fpin_length < sizeof(struct fc_els_fpin))
10022 /* Sanity check descriptor length. The desc_len value does not
10023 * include space for the ELS command and the desc_len fields.
10025 len = be32_to_cpu(fpin->desc_len);
10026 if (fpin_length < len + sizeof(struct fc_els_fpin)) {
10027 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10028 "4671 Bad ELS FPIN length %d: %d\n",
10033 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
10035 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
10036 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
10038 /* process each descriptor separately */
10039 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
10040 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
10041 dtag = be32_to_cpu(tlv->desc_tag);
10043 case ELS_DTAG_LNK_INTEGRITY:
10044 lpfc_els_rcv_fpin_li(phba, tlv);
10047 case ELS_DTAG_DELIVERY:
10048 lpfc_els_rcv_fpin_del(phba, tlv);
10051 case ELS_DTAG_PEER_CONGEST:
10052 lpfc_els_rcv_fpin_peer_cgn(phba, tlv);
10055 case ELS_DTAG_CONGESTION:
10056 deliver = lpfc_els_rcv_fpin_cgn(phba, tlv);
10059 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10060 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10061 "4678 unknown FPIN descriptor[%d]: "
10063 desc_cnt, dtag, dtag_nm);
10065 /* If descriptor is bad, drop the rest of the data */
10068 lpfc_cgn_update_stat(phba, dtag);
10069 cnt = be32_to_cpu(tlv->desc_len);
10071 /* Sanity check descriptor length. The desc_len value does not
10072 * include space for the desc_tag and the desc_len fields.
10074 len -= (cnt + sizeof(struct fc_tlv_desc));
10076 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10077 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10078 "4672 Bad FPIN descriptor TLV length "
10080 cnt, len, fpin_length, dtag_nm);
10085 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
10086 tlv = fc_tlv_next_desc(tlv);
10088 /* Format payload such that the FPIN delivered to the
10089 * upper layer is a single descriptor FPIN.
10092 memcpy(first_tlv, current_tlv,
10093 (cnt + sizeof(struct fc_els_fpin)));
10095 /* Adjust the length so that it only reflects a
10096 * single descriptor FPIN.
10098 fpin_length = cnt + sizeof(struct fc_els_fpin);
10099 fpin->desc_len = cpu_to_be32(fpin_length);
10100 fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */
10102 /* Send every descriptor individually to the upper layer */
10104 fc_host_fpin_rcv(lpfc_shost_from_vport(vport),
10105 fpin_length, (char *)fpin);
10111 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
10112 * @phba: pointer to lpfc hba data structure.
10113 * @pring: pointer to a SLI ring.
10114 * @vport: pointer to a host virtual N_Port data structure.
10115 * @elsiocb: pointer to lpfc els command iocb data structure.
10117 * This routine is used for processing the IOCB associated with a unsolicited
10118 * event. It first determines whether there is an existing ndlp that matches
10119 * the DID from the unsolicited IOCB. If not, it will create a new one with
10120 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
10121 * IOCB is then used to invoke the proper routine and to set up proper state
10122 * of the discovery state machine.
10125 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10126 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
10128 struct lpfc_nodelist *ndlp;
10129 struct ls_rjt stat;
10130 u32 *payload, payload_len;
10131 u32 cmd = 0, did = 0, newnode, status = 0;
10132 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
10133 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10134 LPFC_MBOXQ_t *mbox;
10136 if (!vport || !(elsiocb->context2))
10140 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10141 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
10142 if (phba->sli_rev == LPFC_SLI_REV4)
10143 payload_len = wcqe_cmpl->total_data_placed;
10145 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
10146 status = get_job_ulpstatus(phba, elsiocb);
10148 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
10149 lpfc_sli3_post_buffer(phba, pring, 1);
10151 did = get_job_els_rsp64_did(phba, elsiocb);
10153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10154 "RCV Unsol ELS: status:x%x/x%x did:x%x",
10155 status, get_job_word4(phba, elsiocb), did);
10159 /* Check to see if link went down during discovery */
10160 if (lpfc_els_chk_latt(vport))
10163 /* Ignore traffic received during vport shutdown. */
10164 if (vport->load_flag & FC_UNLOADING)
10167 /* If NPort discovery is delayed drop incoming ELS */
10168 if ((vport->fc_flag & FC_DISC_DELAYED) &&
10169 (cmd != ELS_CMD_PLOGI))
10172 ndlp = lpfc_findnode_did(vport, did);
10174 /* Cannot find existing Fabric ndlp, so allocate a new one */
10175 ndlp = lpfc_nlp_init(vport, did);
10178 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10180 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
10181 ndlp->nlp_type |= NLP_FABRIC;
10182 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
10183 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10187 phba->fc_stat.elsRcvFrame++;
10190 * Do not process any unsolicited ELS commands
10191 * if the ndlp is in DEV_LOSS
10193 spin_lock_irq(&ndlp->lock);
10194 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
10195 spin_unlock_irq(&ndlp->lock);
10197 lpfc_nlp_put(ndlp);
10200 spin_unlock_irq(&ndlp->lock);
10202 elsiocb->context1 = lpfc_nlp_get(ndlp);
10203 if (!elsiocb->context1)
10205 elsiocb->vport = vport;
10207 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
10208 cmd &= ELS_CMD_MASK;
10210 /* ELS command <elsCmd> received from NPORT <did> */
10211 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10212 "0112 ELS command x%x received from NPORT x%x "
10213 "refcnt %d Data: x%x x%x x%x x%x\n",
10214 cmd, did, kref_read(&ndlp->kref), vport->port_state,
10215 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
10217 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
10218 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
10219 (cmd != ELS_CMD_FLOGI) &&
10220 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
10221 rjt_err = LSRJT_LOGICAL_BSY;
10222 rjt_exp = LSEXP_NOTHING_MORE;
10227 case ELS_CMD_PLOGI:
10228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10229 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
10230 did, vport->port_state, ndlp->nlp_flag);
10232 phba->fc_stat.elsRcvPLOGI++;
10233 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
10234 if (phba->sli_rev == LPFC_SLI_REV4 &&
10235 (phba->pport->fc_flag & FC_PT2PT)) {
10236 vport->fc_prevDID = vport->fc_myDID;
10237 /* Our DID needs to be updated before registering
10238 * the vfi. This is done in lpfc_rcv_plogi but
10239 * that is called after the reg_vfi.
10242 bf_get(els_rsp64_sid,
10243 &elsiocb->wqe.xmit_els_rsp);
10244 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10245 "3312 Remote port assigned DID x%x "
10246 "%x\n", vport->fc_myDID,
10247 vport->fc_prevDID);
10250 lpfc_send_els_event(vport, ndlp, payload);
10252 /* If Nport discovery is delayed, reject PLOGIs */
10253 if (vport->fc_flag & FC_DISC_DELAYED) {
10254 rjt_err = LSRJT_UNABLE_TPC;
10255 rjt_exp = LSEXP_NOTHING_MORE;
10259 if (vport->port_state < LPFC_DISC_AUTH) {
10260 if (!(phba->pport->fc_flag & FC_PT2PT) ||
10261 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
10262 rjt_err = LSRJT_UNABLE_TPC;
10263 rjt_exp = LSEXP_NOTHING_MORE;
10268 spin_lock_irq(&ndlp->lock);
10269 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
10270 spin_unlock_irq(&ndlp->lock);
10272 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10273 NLP_EVT_RCV_PLOGI);
10276 case ELS_CMD_FLOGI:
10277 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10278 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
10279 did, vport->port_state, ndlp->nlp_flag);
10281 phba->fc_stat.elsRcvFLOGI++;
10283 /* If the driver believes fabric discovery is done and is ready,
10284 * bounce the link. There is some descrepancy.
10286 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
10287 vport->fc_flag & FC_PT2PT &&
10288 vport->rcv_flogi_cnt >= 1) {
10289 rjt_err = LSRJT_LOGICAL_BSY;
10290 rjt_exp = LSEXP_NOTHING_MORE;
10295 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
10296 /* retain node if our response is deferred */
10297 if (phba->defer_flogi_acc_flag)
10300 lpfc_disc_state_machine(vport, ndlp, NULL,
10301 NLP_EVT_DEVICE_RM);
10304 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10305 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
10306 did, vport->port_state, ndlp->nlp_flag);
10308 phba->fc_stat.elsRcvLOGO++;
10309 lpfc_send_els_event(vport, ndlp, payload);
10310 if (vport->port_state < LPFC_DISC_AUTH) {
10311 rjt_err = LSRJT_UNABLE_TPC;
10312 rjt_exp = LSEXP_NOTHING_MORE;
10315 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
10317 lpfc_disc_state_machine(vport, ndlp, NULL,
10318 NLP_EVT_DEVICE_RM);
10321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10322 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
10323 did, vport->port_state, ndlp->nlp_flag);
10325 phba->fc_stat.elsRcvPRLO++;
10326 lpfc_send_els_event(vport, ndlp, payload);
10327 if (vport->port_state < LPFC_DISC_AUTH) {
10328 rjt_err = LSRJT_UNABLE_TPC;
10329 rjt_exp = LSEXP_NOTHING_MORE;
10332 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
10335 phba->fc_stat.elsRcvLCB++;
10336 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
10339 phba->fc_stat.elsRcvRDP++;
10340 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
10343 phba->fc_stat.elsRcvRSCN++;
10344 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
10346 lpfc_disc_state_machine(vport, ndlp, NULL,
10347 NLP_EVT_DEVICE_RM);
10349 case ELS_CMD_ADISC:
10350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10351 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
10352 did, vport->port_state, ndlp->nlp_flag);
10354 lpfc_send_els_event(vport, ndlp, payload);
10355 phba->fc_stat.elsRcvADISC++;
10356 if (vport->port_state < LPFC_DISC_AUTH) {
10357 rjt_err = LSRJT_UNABLE_TPC;
10358 rjt_exp = LSEXP_NOTHING_MORE;
10361 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10362 NLP_EVT_RCV_ADISC);
10364 case ELS_CMD_PDISC:
10365 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10366 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
10367 did, vport->port_state, ndlp->nlp_flag);
10369 phba->fc_stat.elsRcvPDISC++;
10370 if (vport->port_state < LPFC_DISC_AUTH) {
10371 rjt_err = LSRJT_UNABLE_TPC;
10372 rjt_exp = LSEXP_NOTHING_MORE;
10375 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10376 NLP_EVT_RCV_PDISC);
10378 case ELS_CMD_FARPR:
10379 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10380 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
10381 did, vport->port_state, ndlp->nlp_flag);
10383 phba->fc_stat.elsRcvFARPR++;
10384 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
10387 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10388 "RCV FARP: did:x%x/ste:x%x flg:x%x",
10389 did, vport->port_state, ndlp->nlp_flag);
10391 phba->fc_stat.elsRcvFARP++;
10392 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
10395 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10396 "RCV FAN: did:x%x/ste:x%x flg:x%x",
10397 did, vport->port_state, ndlp->nlp_flag);
10399 phba->fc_stat.elsRcvFAN++;
10400 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
10403 case ELS_CMD_NVMEPRLI:
10404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10405 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
10406 did, vport->port_state, ndlp->nlp_flag);
10408 phba->fc_stat.elsRcvPRLI++;
10409 if ((vport->port_state < LPFC_DISC_AUTH) &&
10410 (vport->fc_flag & FC_FABRIC)) {
10411 rjt_err = LSRJT_UNABLE_TPC;
10412 rjt_exp = LSEXP_NOTHING_MORE;
10415 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
10418 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10419 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
10420 did, vport->port_state, ndlp->nlp_flag);
10422 phba->fc_stat.elsRcvLIRR++;
10423 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
10425 lpfc_disc_state_machine(vport, ndlp, NULL,
10426 NLP_EVT_DEVICE_RM);
10429 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10430 "RCV RLS: did:x%x/ste:x%x flg:x%x",
10431 did, vport->port_state, ndlp->nlp_flag);
10433 phba->fc_stat.elsRcvRLS++;
10434 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
10436 lpfc_disc_state_machine(vport, ndlp, NULL,
10437 NLP_EVT_DEVICE_RM);
10440 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10441 "RCV RPL: did:x%x/ste:x%x flg:x%x",
10442 did, vport->port_state, ndlp->nlp_flag);
10444 phba->fc_stat.elsRcvRPL++;
10445 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
10447 lpfc_disc_state_machine(vport, ndlp, NULL,
10448 NLP_EVT_DEVICE_RM);
10451 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10452 "RCV RNID: did:x%x/ste:x%x flg:x%x",
10453 did, vport->port_state, ndlp->nlp_flag);
10455 phba->fc_stat.elsRcvRNID++;
10456 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
10458 lpfc_disc_state_machine(vport, ndlp, NULL,
10459 NLP_EVT_DEVICE_RM);
10462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10463 "RCV RTV: did:x%x/ste:x%x flg:x%x",
10464 did, vport->port_state, ndlp->nlp_flag);
10465 phba->fc_stat.elsRcvRTV++;
10466 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
10468 lpfc_disc_state_machine(vport, ndlp, NULL,
10469 NLP_EVT_DEVICE_RM);
10472 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10473 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
10474 did, vport->port_state, ndlp->nlp_flag);
10476 phba->fc_stat.elsRcvRRQ++;
10477 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
10479 lpfc_disc_state_machine(vport, ndlp, NULL,
10480 NLP_EVT_DEVICE_RM);
10483 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10484 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
10485 did, vport->port_state, ndlp->nlp_flag);
10487 phba->fc_stat.elsRcvECHO++;
10488 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
10490 lpfc_disc_state_machine(vport, ndlp, NULL,
10491 NLP_EVT_DEVICE_RM);
10494 /* receive this due to exchange closed */
10495 rjt_err = LSRJT_UNABLE_TPC;
10496 rjt_exp = LSEXP_INVALID_OX_RX;
10499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10500 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
10501 did, vport->port_state, ndlp->nlp_flag);
10503 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
10506 /* There are no replies, so no rjt codes */
10509 lpfc_els_rcv_edc(vport, elsiocb, ndlp);
10512 phba->fc_stat.elsRcvRDF++;
10513 /* Accept RDF only from fabric controller */
10514 if (did != Fabric_Cntl_DID) {
10515 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
10516 "1115 Received RDF from invalid DID "
10518 rjt_err = LSRJT_PROTOCOL_ERR;
10519 rjt_exp = LSEXP_NOTHING_MORE;
10523 lpfc_els_rcv_rdf(vport, elsiocb, ndlp);
10526 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10527 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
10528 cmd, did, vport->port_state);
10530 /* Unsupported ELS command, reject */
10531 rjt_err = LSRJT_CMD_UNSUPPORTED;
10532 rjt_exp = LSEXP_NOTHING_MORE;
10534 /* Unknown ELS command <elsCmd> received from NPORT <did> */
10535 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10536 "0115 Unknown ELS command x%x "
10537 "received from NPORT x%x\n", cmd, did);
10539 lpfc_disc_state_machine(vport, ndlp, NULL,
10540 NLP_EVT_DEVICE_RM);
10545 /* check if need to LS_RJT received ELS cmd */
10547 memset(&stat, 0, sizeof(stat));
10548 stat.un.b.lsRjtRsnCode = rjt_err;
10549 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
10550 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
10552 /* Remove the reference from above for new nodes. */
10554 lpfc_disc_state_machine(vport, ndlp, NULL,
10555 NLP_EVT_DEVICE_RM);
10558 /* Release the reference on this elsiocb, not the ndlp. */
10559 lpfc_nlp_put(elsiocb->context1);
10560 elsiocb->context1 = NULL;
10562 /* Special case. Driver received an unsolicited command that
10563 * unsupportable given the driver's current state. Reset the
10564 * link and start over.
10567 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10570 lpfc_linkdown(phba);
10571 lpfc_init_link(phba, mbox,
10572 phba->cfg_topology,
10573 phba->cfg_link_speed);
10574 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
10575 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10576 mbox->vport = vport;
10577 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
10579 mempool_free(mbox, phba->mbox_mem_pool);
10585 if (vport && !(vport->load_flag & FC_UNLOADING))
10586 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10587 "0111 Dropping received ELS cmd "
10588 "Data: x%x x%x x%x x%x\n",
10589 cmd, status, get_job_word4(phba, elsiocb), did);
10591 phba->fc_stat.elsRcvDrop++;
10595 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
10596 * @phba: pointer to lpfc hba data structure.
10597 * @pring: pointer to a SLI ring.
10598 * @elsiocb: pointer to lpfc els iocb data structure.
10600 * This routine is used to process an unsolicited event received from a SLI
10601 * (Service Level Interface) ring. The actual processing of the data buffer
10602 * associated with the unsolicited event is done by invoking the routine
10603 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
10604 * SLI ring on which the unsolicited event was received.
10607 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10608 struct lpfc_iocbq *elsiocb)
10610 struct lpfc_vport *vport = elsiocb->vport;
10611 u32 ulp_command, status, parameter, bde_count = 0;
10613 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10614 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
10615 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
10618 elsiocb->context1 = NULL;
10619 elsiocb->context2 = NULL;
10620 elsiocb->context3 = NULL;
10622 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10623 ulp_command = get_job_cmnd(phba, elsiocb);
10624 status = get_job_ulpstatus(phba, elsiocb);
10625 parameter = get_job_word4(phba, elsiocb);
10626 if (phba->sli_rev == LPFC_SLI_REV4)
10627 bde_count = wcqe_cmpl->word3;
10629 bde_count = elsiocb->iocb.ulpBdeCount;
10631 if (status == IOSTAT_NEED_BUFFER) {
10632 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
10633 } else if (status == IOSTAT_LOCAL_REJECT &&
10634 (parameter & IOERR_PARAM_MASK) ==
10635 IOERR_RCV_BUFFER_WAITING) {
10636 phba->fc_stat.NoRcvBuf++;
10637 /* Not enough posted buffers; Try posting more buffers */
10638 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
10639 lpfc_sli3_post_buffer(phba, pring, 0);
10643 if (phba->sli_rev == LPFC_SLI_REV3) {
10644 icmd = &elsiocb->iocb;
10645 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
10646 (ulp_command == CMD_IOCB_RCV_ELS64_CX ||
10647 ulp_command == CMD_IOCB_RCV_SEQ64_CX)) {
10648 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
10649 vport = phba->pport;
10651 vport = lpfc_find_vport_by_vpid(phba,
10652 icmd->unsli3.rcvsli3.vpi);
10656 /* If there are no BDEs associated
10657 * with this IOCB, there is nothing to do.
10659 if (bde_count == 0)
10662 /* Account for SLI2 or SLI3 and later unsolicited buffering */
10663 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
10664 elsiocb->context2 = bdeBuf1;
10665 if (bde_count == 2)
10666 elsiocb->context3 = bdeBuf2;
10668 icmd = &elsiocb->iocb;
10669 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
10670 icmd->un.cont64[0].addrLow);
10671 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
10673 if (bde_count == 2) {
10674 paddr = getPaddr(icmd->un.cont64[1].addrHigh,
10675 icmd->un.cont64[1].addrLow);
10676 elsiocb->context3 = lpfc_sli_ringpostbuf_get(phba,
10682 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
10684 * The different unsolicited event handlers would tell us
10685 * if they are done with "mp" by setting context2 to NULL.
10687 if (elsiocb->context2) {
10688 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
10689 elsiocb->context2 = NULL;
10692 if (elsiocb->context3) {
10693 lpfc_in_buf_free(phba, elsiocb->context3);
10694 elsiocb->context3 = NULL;
10699 lpfc_start_fdmi(struct lpfc_vport *vport)
10701 struct lpfc_nodelist *ndlp;
10703 /* If this is the first time, allocate an ndlp and initialize
10704 * it. Otherwise, make sure the node is enabled and then do the
10707 ndlp = lpfc_findnode_did(vport, FDMI_DID);
10709 ndlp = lpfc_nlp_init(vport, FDMI_DID);
10711 ndlp->nlp_type |= NLP_FABRIC;
10717 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10718 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
10722 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
10723 * @phba: pointer to lpfc hba data structure.
10724 * @vport: pointer to a virtual N_Port data structure.
10726 * This routine issues a Port Login (PLOGI) to the Name Server with
10727 * State Change Request (SCR) for a @vport. This routine will create an
10728 * ndlp for the Name Server associated to the @vport if such node does
10729 * not already exist. The PLOGI to Name Server is issued by invoking the
10730 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
10731 * (FDMI) is configured to the @vport, a FDMI node will be created and
10732 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
10735 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
10737 struct lpfc_nodelist *ndlp;
10738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10741 * If lpfc_delay_discovery parameter is set and the clean address
10742 * bit is cleared and fc fabric parameters chenged, delay FC NPort
10745 spin_lock_irq(shost->host_lock);
10746 if (vport->fc_flag & FC_DISC_DELAYED) {
10747 spin_unlock_irq(shost->host_lock);
10748 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10749 "3334 Delay fc port discovery for %d secs\n",
10751 mod_timer(&vport->delayed_disc_tmo,
10752 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
10755 spin_unlock_irq(shost->host_lock);
10757 ndlp = lpfc_findnode_did(vport, NameServer_DID);
10759 ndlp = lpfc_nlp_init(vport, NameServer_DID);
10761 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
10762 lpfc_disc_start(vport);
10765 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10766 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10767 "0251 NameServer login: no memory\n");
10772 ndlp->nlp_type |= NLP_FABRIC;
10774 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10776 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
10777 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10778 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10779 "0252 Cannot issue NameServer login\n");
10783 if ((phba->cfg_enable_SmartSAN ||
10784 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
10785 (vport->load_flag & FC_ALLOW_FDMI))
10786 lpfc_start_fdmi(vport);
10790 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
10791 * @phba: pointer to lpfc hba data structure.
10792 * @pmb: pointer to the driver internal queue element for mailbox command.
10794 * This routine is the completion callback function to register new vport
10795 * mailbox command. If the new vport mailbox command completes successfully,
10796 * the fabric registration login shall be performed on physical port (the
10797 * new vport created is actually a physical port, with VPI 0) or the port
10798 * login to Name Server for State Change Request (SCR) will be performed
10799 * on virtual port (real virtual port, with VPI greater than 0).
10802 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
10804 struct lpfc_vport *vport = pmb->vport;
10805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10806 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
10807 MAILBOX_t *mb = &pmb->u.mb;
10810 spin_lock_irq(shost->host_lock);
10811 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
10812 spin_unlock_irq(shost->host_lock);
10814 if (mb->mbxStatus) {
10815 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10816 "0915 Register VPI failed : Status: x%x"
10817 " upd bit: x%x \n", mb->mbxStatus,
10818 mb->un.varRegVpi.upd);
10819 if (phba->sli_rev == LPFC_SLI_REV4 &&
10820 mb->un.varRegVpi.upd)
10821 goto mbox_err_exit ;
10823 switch (mb->mbxStatus) {
10824 case 0x11: /* unsupported feature */
10825 case 0x9603: /* max_vpi exceeded */
10826 case 0x9602: /* Link event since CLEAR_LA */
10827 /* giving up on vport registration */
10828 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10829 spin_lock_irq(shost->host_lock);
10830 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
10831 spin_unlock_irq(shost->host_lock);
10832 lpfc_can_disctmo(vport);
10834 /* If reg_vpi fail with invalid VPI status, re-init VPI */
10836 spin_lock_irq(shost->host_lock);
10837 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
10838 spin_unlock_irq(shost->host_lock);
10839 lpfc_init_vpi(phba, pmb, vport->vpi);
10840 pmb->vport = vport;
10841 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
10842 rc = lpfc_sli_issue_mbox(phba, pmb,
10844 if (rc == MBX_NOT_FINISHED) {
10845 lpfc_printf_vlog(vport, KERN_ERR,
10847 "2732 Failed to issue INIT_VPI"
10848 " mailbox command\n");
10850 lpfc_nlp_put(ndlp);
10855 /* Try to recover from this error */
10856 if (phba->sli_rev == LPFC_SLI_REV4)
10857 lpfc_sli4_unreg_all_rpis(vport);
10858 lpfc_mbx_unreg_vpi(vport);
10859 spin_lock_irq(shost->host_lock);
10860 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
10861 spin_unlock_irq(shost->host_lock);
10862 if (mb->mbxStatus == MBX_NOT_FINISHED)
10864 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
10865 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
10866 if (phba->sli_rev == LPFC_SLI_REV4)
10867 lpfc_issue_init_vfi(vport);
10869 lpfc_initial_flogi(vport);
10871 lpfc_initial_fdisc(vport);
10876 spin_lock_irq(shost->host_lock);
10877 vport->vpi_state |= LPFC_VPI_REGISTERED;
10878 spin_unlock_irq(shost->host_lock);
10879 if (vport == phba->pport) {
10880 if (phba->sli_rev < LPFC_SLI_REV4)
10881 lpfc_issue_fabric_reglogin(vport);
10884 * If the physical port is instantiated using
10885 * FDISC, do not start vport discovery.
10887 if (vport->port_state != LPFC_FDISC)
10888 lpfc_start_fdiscs(phba);
10889 lpfc_do_scr_ns_plogi(phba, vport);
10892 lpfc_do_scr_ns_plogi(phba, vport);
10896 /* Now, we decrement the ndlp reference count held for this
10897 * callback function
10899 lpfc_nlp_put(ndlp);
10901 mempool_free(pmb, phba->mbox_mem_pool);
10906 * lpfc_register_new_vport - Register a new vport with a HBA
10907 * @phba: pointer to lpfc hba data structure.
10908 * @vport: pointer to a host virtual N_Port data structure.
10909 * @ndlp: pointer to a node-list data structure.
10911 * This routine registers the @vport as a new virtual port with a HBA.
10912 * It is done through a registering vpi mailbox command.
10915 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
10916 struct lpfc_nodelist *ndlp)
10918 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10919 LPFC_MBOXQ_t *mbox;
10921 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10923 lpfc_reg_vpi(vport, mbox);
10924 mbox->vport = vport;
10925 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
10926 if (!mbox->ctx_ndlp) {
10927 mempool_free(mbox, phba->mbox_mem_pool);
10928 goto mbox_err_exit;
10931 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
10932 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
10933 == MBX_NOT_FINISHED) {
10934 /* mailbox command not success, decrement ndlp
10935 * reference count for this command
10937 lpfc_nlp_put(ndlp);
10938 mempool_free(mbox, phba->mbox_mem_pool);
10940 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10941 "0253 Register VPI: Can't send mbox\n");
10942 goto mbox_err_exit;
10945 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10946 "0254 Register VPI: no memory\n");
10947 goto mbox_err_exit;
10952 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10953 spin_lock_irq(shost->host_lock);
10954 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
10955 spin_unlock_irq(shost->host_lock);
10960 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
10961 * @phba: pointer to lpfc hba data structure.
10963 * This routine cancels the retry delay timers to all the vports.
10966 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
10968 struct lpfc_vport **vports;
10969 struct lpfc_nodelist *ndlp;
10970 uint32_t link_state;
10973 /* Treat this failure as linkdown for all vports */
10974 link_state = phba->link_state;
10975 lpfc_linkdown(phba);
10976 phba->link_state = link_state;
10978 vports = lpfc_create_vport_work_array(phba);
10981 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10982 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
10984 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
10985 lpfc_els_flush_cmd(vports[i]);
10987 lpfc_destroy_vport_work_array(phba, vports);
10992 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
10993 * @phba: pointer to lpfc hba data structure.
10995 * This routine abort all pending discovery commands and
10996 * start a timer to retry FLOGI for the physical port
11000 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
11002 struct lpfc_nodelist *ndlp;
11004 /* Cancel the all vports retry delay retry timers */
11005 lpfc_cancel_all_vport_retry_delay_timer(phba);
11007 /* If fabric require FLOGI, then re-instantiate physical login */
11008 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
11012 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
11013 spin_lock_irq(&ndlp->lock);
11014 ndlp->nlp_flag |= NLP_DELAY_TMO;
11015 spin_unlock_irq(&ndlp->lock);
11016 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
11017 phba->pport->port_state = LPFC_FLOGI;
11022 * lpfc_fabric_login_reqd - Check if FLOGI required.
11023 * @phba: pointer to lpfc hba data structure.
11024 * @cmdiocb: pointer to FDISC command iocb.
11025 * @rspiocb: pointer to FDISC response iocb.
11027 * This routine checks if a FLOGI is reguired for FDISC
11031 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
11032 struct lpfc_iocbq *cmdiocb,
11033 struct lpfc_iocbq *rspiocb)
11035 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11036 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11038 if (ulp_status != IOSTAT_FABRIC_RJT ||
11039 ulp_word4 != RJT_LOGIN_REQUIRED)
11046 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
11047 * @phba: pointer to lpfc hba data structure.
11048 * @cmdiocb: pointer to lpfc command iocb data structure.
11049 * @rspiocb: pointer to lpfc response iocb data structure.
11051 * This routine is the completion callback function to a Fabric Discover
11052 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
11053 * single threaded, each FDISC completion callback function will reset
11054 * the discovery timer for all vports such that the timers will not get
11055 * unnecessary timeout. The function checks the FDISC IOCB status. If error
11056 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
11057 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
11058 * assigned to the vport has been changed with the completion of the FDISC
11059 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
11060 * are unregistered from the HBA, and then the lpfc_register_new_vport()
11061 * routine is invoked to register new vport with the HBA. Otherwise, the
11062 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
11063 * Server for State Change Request (SCR).
11066 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11067 struct lpfc_iocbq *rspiocb)
11069 struct lpfc_vport *vport = cmdiocb->vport;
11070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11071 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
11072 struct lpfc_nodelist *np;
11073 struct lpfc_nodelist *next_np;
11074 struct lpfc_iocbq *piocb;
11075 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
11076 struct serv_parm *sp;
11077 uint8_t fabric_param_changed;
11078 u32 ulp_status, ulp_word4;
11080 ulp_status = get_job_ulpstatus(phba, rspiocb);
11081 ulp_word4 = get_job_word4(phba, rspiocb);
11083 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11084 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
11085 ulp_status, ulp_word4,
11086 vport->fc_prevDID);
11087 /* Since all FDISCs are being single threaded, we
11088 * must reset the discovery timer for ALL vports
11089 * waiting to send FDISC when one completes.
11091 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
11092 lpfc_set_disctmo(piocb->vport);
11095 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11096 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
11097 ulp_status, ulp_word4, vport->fc_prevDID);
11101 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
11102 lpfc_retry_pport_discovery(phba);
11106 /* Check for retry */
11107 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
11110 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11111 "0126 FDISC failed. (x%x/x%x)\n",
11112 ulp_status, ulp_word4);
11116 lpfc_check_nlp_post_devloss(vport, ndlp);
11118 spin_lock_irq(shost->host_lock);
11119 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
11120 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
11121 vport->fc_flag |= FC_FABRIC;
11122 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
11123 vport->fc_flag |= FC_PUBLIC_LOOP;
11124 spin_unlock_irq(shost->host_lock);
11126 vport->fc_myDID = ulp_word4 & Mask_DID;
11127 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
11128 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
11131 sp = prsp->virt + sizeof(uint32_t);
11132 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
11133 memcpy(&vport->fabric_portname, &sp->portName,
11134 sizeof(struct lpfc_name));
11135 memcpy(&vport->fabric_nodename, &sp->nodeName,
11136 sizeof(struct lpfc_name));
11137 if (fabric_param_changed &&
11138 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
11139 /* If our NportID changed, we need to ensure all
11140 * remaining NPORTs get unreg_login'ed so we can
11143 list_for_each_entry_safe(np, next_np,
11144 &vport->fc_nodes, nlp_listp) {
11145 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
11146 !(np->nlp_flag & NLP_NPR_ADISC))
11148 spin_lock_irq(&ndlp->lock);
11149 np->nlp_flag &= ~NLP_NPR_ADISC;
11150 spin_unlock_irq(&ndlp->lock);
11151 lpfc_unreg_rpi(vport, np);
11153 lpfc_cleanup_pending_mbox(vport);
11155 if (phba->sli_rev == LPFC_SLI_REV4)
11156 lpfc_sli4_unreg_all_rpis(vport);
11158 lpfc_mbx_unreg_vpi(vport);
11159 spin_lock_irq(shost->host_lock);
11160 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
11161 if (phba->sli_rev == LPFC_SLI_REV4)
11162 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
11164 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
11165 spin_unlock_irq(shost->host_lock);
11166 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
11167 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
11169 * Driver needs to re-reg VPI in order for f/w
11170 * to update the MAC address.
11172 lpfc_register_new_vport(phba, vport, ndlp);
11173 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11177 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
11178 lpfc_issue_init_vpi(vport);
11179 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
11180 lpfc_register_new_vport(phba, vport, ndlp);
11182 lpfc_do_scr_ns_plogi(phba, vport);
11184 /* The FDISC completed successfully. Move the fabric ndlp to
11185 * UNMAPPED state and register with the transport.
11187 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11191 if (vport->fc_vport &&
11192 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
11193 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11194 /* Cancel discovery timer */
11195 lpfc_can_disctmo(vport);
11197 lpfc_els_free_iocb(phba, cmdiocb);
11198 lpfc_nlp_put(ndlp);
11202 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
11203 * @vport: pointer to a virtual N_Port data structure.
11204 * @ndlp: pointer to a node-list data structure.
11205 * @retry: number of retries to the command IOCB.
11207 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
11208 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
11209 * routine to issue the IOCB, which makes sure only one outstanding fabric
11210 * IOCB will be sent off HBA at any given time.
11212 * Note that the ndlp reference count will be incremented by 1 for holding the
11213 * ndlp and the reference to ndlp will be stored into the context1 field of
11214 * the IOCB for the completion callback function to the FDISC ELS command.
11217 * 0 - Successfully issued fdisc iocb command
11218 * 1 - Failed to issue fdisc iocb command
11221 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
11224 struct lpfc_hba *phba = vport->phba;
11226 union lpfc_wqe128 *wqe = NULL;
11227 struct lpfc_iocbq *elsiocb;
11228 struct serv_parm *sp;
11231 int did = ndlp->nlp_DID;
11234 vport->port_state = LPFC_FDISC;
11235 vport->fc_myDID = 0;
11236 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
11237 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
11240 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11241 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11242 "0255 Issue FDISC: no IOCB\n");
11246 if (phba->sli_rev == LPFC_SLI_REV4) {
11247 wqe = &elsiocb->wqe;
11248 bf_set(els_req64_sid, &wqe->els_req, 0);
11249 bf_set(els_req64_sp, &wqe->els_req, 1);
11251 icmd = &elsiocb->iocb;
11252 icmd->un.elsreq64.myID = 0;
11253 icmd->un.elsreq64.fl = 1;
11258 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
11259 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
11260 pcmd += sizeof(uint32_t); /* CSP Word 1 */
11261 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
11262 sp = (struct serv_parm *) pcmd;
11263 /* Setup CSPs accordingly for Fabric */
11264 sp->cmn.e_d_tov = 0;
11265 sp->cmn.w2.r_a_tov = 0;
11266 sp->cmn.virtual_fabric_support = 0;
11267 sp->cls1.classValid = 0;
11268 sp->cls2.seqDelivery = 1;
11269 sp->cls3.seqDelivery = 1;
11271 pcmd += sizeof(uint32_t); /* CSP Word 2 */
11272 pcmd += sizeof(uint32_t); /* CSP Word 3 */
11273 pcmd += sizeof(uint32_t); /* CSP Word 4 */
11274 pcmd += sizeof(uint32_t); /* Port Name */
11275 memcpy(pcmd, &vport->fc_portname, 8);
11276 pcmd += sizeof(uint32_t); /* Node Name */
11277 pcmd += sizeof(uint32_t); /* Node Name */
11278 memcpy(pcmd, &vport->fc_nodename, 8);
11279 sp->cmn.valid_vendor_ver_level = 0;
11280 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
11281 lpfc_set_disctmo(vport);
11283 phba->fc_stat.elsXmitFDISC++;
11284 elsiocb->cmd_cmpl = lpfc_cmpl_els_fdisc;
11286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11287 "Issue FDISC: did:x%x",
11290 elsiocb->context1 = lpfc_nlp_get(ndlp);
11291 if (!elsiocb->context1)
11294 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
11295 if (rc == IOCB_ERROR) {
11296 lpfc_nlp_put(ndlp);
11300 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
11304 lpfc_els_free_iocb(phba, elsiocb);
11305 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11306 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11307 "0256 Issue FDISC: Cannot send IOCB\n");
11312 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
11313 * @phba: pointer to lpfc hba data structure.
11314 * @cmdiocb: pointer to lpfc command iocb data structure.
11315 * @rspiocb: pointer to lpfc response iocb data structure.
11317 * This routine is the completion callback function to the issuing of a LOGO
11318 * ELS command off a vport. It frees the command IOCB and then decrement the
11319 * reference count held on ndlp for this completion function, indicating that
11320 * the reference to the ndlp is no long needed. Note that the
11321 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
11322 * callback function and an additional explicit ndlp reference decrementation
11323 * will trigger the actual release of the ndlp.
11326 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11327 struct lpfc_iocbq *rspiocb)
11329 struct lpfc_vport *vport = cmdiocb->vport;
11331 struct lpfc_nodelist *ndlp;
11332 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11333 u32 ulp_status, ulp_word4, did, tmo;
11335 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
11337 ulp_status = get_job_ulpstatus(phba, rspiocb);
11338 ulp_word4 = get_job_word4(phba, rspiocb);
11340 if (phba->sli_rev == LPFC_SLI_REV4) {
11341 did = get_job_els_rsp64_did(phba, cmdiocb);
11342 tmo = get_wqe_tmo(cmdiocb);
11344 irsp = &rspiocb->iocb;
11345 did = get_job_els_rsp64_did(phba, rspiocb);
11346 tmo = irsp->ulpTimeout;
11349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11350 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
11351 ulp_status, ulp_word4, did);
11353 /* NPIV LOGO completes to NPort <nlp_DID> */
11354 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11355 "2928 NPIV LOGO completes to NPort x%x "
11356 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
11357 ndlp->nlp_DID, ulp_status, ulp_word4,
11358 tmo, vport->num_disc_nodes,
11359 kref_read(&ndlp->kref), ndlp->nlp_flag,
11360 ndlp->fc4_xpt_flags);
11362 if (ulp_status == IOSTAT_SUCCESS) {
11363 spin_lock_irq(shost->host_lock);
11364 vport->fc_flag &= ~FC_NDISC_ACTIVE;
11365 vport->fc_flag &= ~FC_FABRIC;
11366 spin_unlock_irq(shost->host_lock);
11367 lpfc_can_disctmo(vport);
11370 if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
11371 /* Wake up lpfc_vport_delete if waiting...*/
11372 if (ndlp->logo_waitq)
11373 wake_up(ndlp->logo_waitq);
11374 spin_lock_irq(&ndlp->lock);
11375 ndlp->nlp_flag &= ~(NLP_ISSUE_LOGO | NLP_LOGO_SND);
11376 ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
11377 spin_unlock_irq(&ndlp->lock);
11380 /* Safe to release resources now. */
11381 lpfc_els_free_iocb(phba, cmdiocb);
11382 lpfc_nlp_put(ndlp);
11386 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
11387 * @vport: pointer to a virtual N_Port data structure.
11388 * @ndlp: pointer to a node-list data structure.
11390 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
11392 * Note that the ndlp reference count will be incremented by 1 for holding the
11393 * ndlp and the reference to ndlp will be stored into the context1 field of
11394 * the IOCB for the completion callback function to the LOGO ELS command.
11397 * 0 - Successfully issued logo off the @vport
11398 * 1 - Failed to issue logo off the @vport
11401 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
11404 struct lpfc_hba *phba = vport->phba;
11405 struct lpfc_iocbq *elsiocb;
11409 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
11410 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
11415 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
11416 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
11417 pcmd += sizeof(uint32_t);
11419 /* Fill in LOGO payload */
11420 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
11421 pcmd += sizeof(uint32_t);
11422 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
11424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11425 "Issue LOGO npiv did:x%x flg:x%x",
11426 ndlp->nlp_DID, ndlp->nlp_flag, 0);
11428 elsiocb->cmd_cmpl = lpfc_cmpl_els_npiv_logo;
11429 spin_lock_irq(&ndlp->lock);
11430 ndlp->nlp_flag |= NLP_LOGO_SND;
11431 spin_unlock_irq(&ndlp->lock);
11432 elsiocb->context1 = lpfc_nlp_get(ndlp);
11433 if (!elsiocb->context1) {
11434 lpfc_els_free_iocb(phba, elsiocb);
11438 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
11439 if (rc == IOCB_ERROR) {
11440 lpfc_els_free_iocb(phba, elsiocb);
11441 lpfc_nlp_put(ndlp);
11447 spin_lock_irq(&ndlp->lock);
11448 ndlp->nlp_flag &= ~NLP_LOGO_SND;
11449 spin_unlock_irq(&ndlp->lock);
11454 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
11455 * @t: timer context used to obtain the lpfc hba.
11457 * This routine is invoked by the fabric iocb block timer after
11458 * timeout. It posts the fabric iocb block timeout event by setting the
11459 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
11460 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
11461 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
11462 * posted event WORKER_FABRIC_BLOCK_TMO.
11465 lpfc_fabric_block_timeout(struct timer_list *t)
11467 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
11468 unsigned long iflags;
11469 uint32_t tmo_posted;
11471 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
11472 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
11474 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
11475 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
11478 lpfc_worker_wake_up(phba);
11483 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
11484 * @phba: pointer to lpfc hba data structure.
11486 * This routine issues one fabric iocb from the driver internal list to
11487 * the HBA. It first checks whether it's ready to issue one fabric iocb to
11488 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
11489 * remove one pending fabric iocb from the driver internal list and invokes
11490 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
11493 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
11495 struct lpfc_iocbq *iocb;
11496 unsigned long iflags;
11501 spin_lock_irqsave(&phba->hbalock, iflags);
11502 /* Post any pending iocb to the SLI layer */
11503 if (atomic_read(&phba->fabric_iocb_count) == 0) {
11504 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
11507 /* Increment fabric iocb count to hold the position */
11508 atomic_inc(&phba->fabric_iocb_count);
11510 spin_unlock_irqrestore(&phba->hbalock, iflags);
11512 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11513 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11514 iocb->cmd_flag |= LPFC_IO_FABRIC;
11516 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11517 "Fabric sched1: ste:x%x",
11518 iocb->vport->port_state, 0, 0);
11520 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11522 if (ret == IOCB_ERROR) {
11523 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11524 iocb->fabric_cmd_cmpl = NULL;
11525 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11526 set_job_ulpstatus(iocb, IOSTAT_LOCAL_REJECT);
11527 iocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
11528 iocb->cmd_cmpl(phba, iocb, iocb);
11530 atomic_dec(&phba->fabric_iocb_count);
11537 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
11538 * @phba: pointer to lpfc hba data structure.
11540 * This routine unblocks the issuing fabric iocb command. The function
11541 * will clear the fabric iocb block bit and then invoke the routine
11542 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
11543 * from the driver internal fabric iocb list.
11546 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
11548 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11550 lpfc_resume_fabric_iocbs(phba);
11555 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
11556 * @phba: pointer to lpfc hba data structure.
11558 * This routine blocks the issuing fabric iocb for a specified amount of
11559 * time (currently 100 ms). This is done by set the fabric iocb block bit
11560 * and set up a timeout timer for 100ms. When the block bit is set, no more
11561 * fabric iocb will be issued out of the HBA.
11564 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
11568 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11569 /* Start a timer to unblock fabric iocbs after 100ms */
11571 mod_timer(&phba->fabric_block_timer,
11572 jiffies + msecs_to_jiffies(100));
11578 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
11579 * @phba: pointer to lpfc hba data structure.
11580 * @cmdiocb: pointer to lpfc command iocb data structure.
11581 * @rspiocb: pointer to lpfc response iocb data structure.
11583 * This routine is the callback function that is put to the fabric iocb's
11584 * callback function pointer (iocb->cmd_cmpl). The original iocb's callback
11585 * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback
11586 * function first restores and invokes the original iocb's callback function
11587 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
11588 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
11591 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11592 struct lpfc_iocbq *rspiocb)
11594 struct ls_rjt stat;
11595 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11596 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11598 WARN_ON((cmdiocb->cmd_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
11600 switch (ulp_status) {
11601 case IOSTAT_NPORT_RJT:
11602 case IOSTAT_FABRIC_RJT:
11603 if (ulp_word4 & RJT_UNAVAIL_TEMP)
11604 lpfc_block_fabric_iocbs(phba);
11607 case IOSTAT_NPORT_BSY:
11608 case IOSTAT_FABRIC_BSY:
11609 lpfc_block_fabric_iocbs(phba);
11612 case IOSTAT_LS_RJT:
11613 stat.un.ls_rjt_error_be =
11614 cpu_to_be32(ulp_word4);
11615 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
11616 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
11617 lpfc_block_fabric_iocbs(phba);
11621 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
11623 cmdiocb->cmd_cmpl = cmdiocb->fabric_cmd_cmpl;
11624 cmdiocb->fabric_cmd_cmpl = NULL;
11625 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
11626 cmdiocb->cmd_cmpl(phba, cmdiocb, rspiocb);
11628 atomic_dec(&phba->fabric_iocb_count);
11629 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
11630 /* Post any pending iocbs to HBA */
11631 lpfc_resume_fabric_iocbs(phba);
11636 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
11637 * @phba: pointer to lpfc hba data structure.
11638 * @iocb: pointer to lpfc command iocb data structure.
11640 * This routine is used as the top-level API for issuing a fabric iocb command
11641 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
11642 * function makes sure that only one fabric bound iocb will be outstanding at
11643 * any given time. As such, this function will first check to see whether there
11644 * is already an outstanding fabric iocb on the wire. If so, it will put the
11645 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
11646 * issued later. Otherwise, it will issue the iocb on the wire and update the
11647 * fabric iocb count it indicate that there is one fabric iocb on the wire.
11649 * Note, this implementation has a potential sending out fabric IOCBs out of
11650 * order. The problem is caused by the construction of the "ready" boolen does
11651 * not include the condition that the internal fabric IOCB list is empty. As
11652 * such, it is possible a fabric IOCB issued by this routine might be "jump"
11653 * ahead of the fabric IOCBs in the internal list.
11656 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
11657 * IOCB_ERROR - failed to issue fabric iocb
11660 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
11662 unsigned long iflags;
11666 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
11668 spin_lock_irqsave(&phba->hbalock, iflags);
11669 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
11670 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11673 /* Increment fabric iocb count to hold the position */
11674 atomic_inc(&phba->fabric_iocb_count);
11675 spin_unlock_irqrestore(&phba->hbalock, iflags);
11677 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11678 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11679 iocb->cmd_flag |= LPFC_IO_FABRIC;
11681 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11682 "Fabric sched2: ste:x%x",
11683 iocb->vport->port_state, 0, 0);
11685 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11687 if (ret == IOCB_ERROR) {
11688 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11689 iocb->fabric_cmd_cmpl = NULL;
11690 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11691 atomic_dec(&phba->fabric_iocb_count);
11694 spin_lock_irqsave(&phba->hbalock, iflags);
11695 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
11696 spin_unlock_irqrestore(&phba->hbalock, iflags);
11697 ret = IOCB_SUCCESS;
11703 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
11704 * @vport: pointer to a virtual N_Port data structure.
11706 * This routine aborts all the IOCBs associated with a @vport from the
11707 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11708 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11709 * list, removes each IOCB associated with the @vport off the list, set the
11710 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11711 * associated with the IOCB.
11713 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
11715 LIST_HEAD(completions);
11716 struct lpfc_hba *phba = vport->phba;
11717 struct lpfc_iocbq *tmp_iocb, *piocb;
11719 spin_lock_irq(&phba->hbalock);
11720 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11723 if (piocb->vport != vport)
11726 list_move_tail(&piocb->list, &completions);
11728 spin_unlock_irq(&phba->hbalock);
11730 /* Cancel all the IOCBs from the completions list */
11731 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11732 IOERR_SLI_ABORTED);
11736 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
11737 * @ndlp: pointer to a node-list data structure.
11739 * This routine aborts all the IOCBs associated with an @ndlp from the
11740 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11741 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11742 * list, removes each IOCB associated with the @ndlp off the list, set the
11743 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11744 * associated with the IOCB.
11746 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
11748 LIST_HEAD(completions);
11749 struct lpfc_hba *phba = ndlp->phba;
11750 struct lpfc_iocbq *tmp_iocb, *piocb;
11751 struct lpfc_sli_ring *pring;
11753 pring = lpfc_phba_elsring(phba);
11755 if (unlikely(!pring))
11758 spin_lock_irq(&phba->hbalock);
11759 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11761 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
11763 list_move_tail(&piocb->list, &completions);
11766 spin_unlock_irq(&phba->hbalock);
11768 /* Cancel all the IOCBs from the completions list */
11769 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11770 IOERR_SLI_ABORTED);
11774 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
11775 * @phba: pointer to lpfc hba data structure.
11777 * This routine aborts all the IOCBs currently on the driver internal
11778 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
11779 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
11780 * list, removes IOCBs off the list, set the status field to
11781 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
11784 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
11786 LIST_HEAD(completions);
11788 spin_lock_irq(&phba->hbalock);
11789 list_splice_init(&phba->fabric_iocb_list, &completions);
11790 spin_unlock_irq(&phba->hbalock);
11792 /* Cancel all the IOCBs from the completions list */
11793 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11794 IOERR_SLI_ABORTED);
11798 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
11799 * @vport: pointer to lpfc vport data structure.
11801 * This routine is invoked by the vport cleanup for deletions and the cleanup
11802 * for an ndlp on removal.
11805 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
11807 struct lpfc_hba *phba = vport->phba;
11808 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
11809 struct lpfc_nodelist *ndlp = NULL;
11810 unsigned long iflag = 0;
11812 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
11813 list_for_each_entry_safe(sglq_entry, sglq_next,
11814 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
11815 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
11816 lpfc_nlp_put(sglq_entry->ndlp);
11817 ndlp = sglq_entry->ndlp;
11818 sglq_entry->ndlp = NULL;
11820 /* If the xri on the abts_els_sgl list is for the Fport
11821 * node and the vport is unloading, the xri aborted wcqe
11822 * likely isn't coming back. Just release the sgl.
11824 if ((vport->load_flag & FC_UNLOADING) &&
11825 ndlp->nlp_DID == Fabric_DID) {
11826 list_del(&sglq_entry->list);
11827 sglq_entry->state = SGL_FREED;
11828 list_add_tail(&sglq_entry->list,
11829 &phba->sli4_hba.lpfc_els_sgl_list);
11833 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
11838 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
11839 * @phba: pointer to lpfc hba data structure.
11840 * @axri: pointer to the els xri abort wcqe structure.
11842 * This routine is invoked by the worker thread to process a SLI4 slow-path
11846 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
11847 struct sli4_wcqe_xri_aborted *axri)
11849 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
11850 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
11853 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
11854 unsigned long iflag = 0;
11855 struct lpfc_nodelist *ndlp;
11856 struct lpfc_sli_ring *pring;
11858 pring = lpfc_phba_elsring(phba);
11860 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
11861 list_for_each_entry_safe(sglq_entry, sglq_next,
11862 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
11863 if (sglq_entry->sli4_xritag == xri) {
11864 list_del(&sglq_entry->list);
11865 ndlp = sglq_entry->ndlp;
11866 sglq_entry->ndlp = NULL;
11867 list_add_tail(&sglq_entry->list,
11868 &phba->sli4_hba.lpfc_els_sgl_list);
11869 sglq_entry->state = SGL_FREED;
11870 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
11874 lpfc_set_rrq_active(phba, ndlp,
11875 sglq_entry->sli4_lxritag,
11877 lpfc_nlp_put(ndlp);
11880 /* Check if TXQ queue needs to be serviced */
11881 if (pring && !list_empty(&pring->txq))
11882 lpfc_worker_wake_up(phba);
11886 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
11887 lxri = lpfc_sli4_xri_inrange(phba, xri);
11888 if (lxri == NO_XRI)
11891 spin_lock_irqsave(&phba->hbalock, iflag);
11892 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
11893 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
11894 spin_unlock_irqrestore(&phba->hbalock, iflag);
11897 sglq_entry->state = SGL_XRI_ABORTED;
11898 spin_unlock_irqrestore(&phba->hbalock, iflag);
11902 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
11903 * @vport: pointer to virtual port object.
11904 * @ndlp: nodelist pointer for the impacted node.
11906 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
11907 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
11908 * the driver is required to send a LOGO to the remote node before it
11909 * attempts to recover its login to the remote node.
11912 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
11913 struct lpfc_nodelist *ndlp)
11915 struct Scsi_Host *shost;
11916 struct lpfc_hba *phba;
11917 unsigned long flags = 0;
11919 shost = lpfc_shost_from_vport(vport);
11920 phba = vport->phba;
11921 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
11922 lpfc_printf_log(phba, KERN_INFO,
11923 LOG_SLI, "3093 No rport recovery needed. "
11924 "rport in state 0x%x\n", ndlp->nlp_state);
11927 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11928 "3094 Start rport recovery on shost id 0x%x "
11929 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
11931 shost->host_no, ndlp->nlp_DID,
11932 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
11935 * The rport is not responding. Remove the FCP-2 flag to prevent
11936 * an ADISC in the follow-up recovery code.
11938 spin_lock_irqsave(&ndlp->lock, flags);
11939 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
11940 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
11941 spin_unlock_irqrestore(&ndlp->lock, flags);
11942 lpfc_unreg_rpi(vport, ndlp);
11945 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport)
11947 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE);
11951 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max)
11955 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE))
11958 for (i = min; i <= max; i++)
11959 set_bit(i, vport->vmid_priority_range);
11962 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid)
11964 set_bit(ctcl_vmid, vport->vmid_priority_range);
11967 u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport)
11971 i = find_first_bit(vport->vmid_priority_range,
11972 LPFC_VMID_MAX_PRIORITY_RANGE);
11974 if (i == LPFC_VMID_MAX_PRIORITY_RANGE)
11977 clear_bit(i, vport->vmid_priority_range);
11981 #define MAX_PRIORITY_DESC 255
11984 lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11985 struct lpfc_iocbq *rspiocb)
11987 struct lpfc_vport *vport = cmdiocb->vport;
11988 struct priority_range_desc *desc;
11989 struct lpfc_dmabuf *prsp = NULL;
11990 struct lpfc_vmid_priority_range *vmid_range = NULL;
11992 struct lpfc_dmabuf *dmabuf = cmdiocb->context2;
11993 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11994 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11995 u8 *pcmd, max_desc;
11997 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
11999 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
12004 data = (u32 *)pcmd;
12005 if (data[0] == ELS_CMD_LS_RJT) {
12006 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12007 "3277 QFPA LS_RJT x%x x%x\n",
12012 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
12013 "6529 QFPA failed with status x%x x%x\n",
12014 ulp_status, ulp_word4);
12018 if (!vport->qfpa_res) {
12019 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res);
12020 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res),
12022 if (!vport->qfpa_res)
12026 len = *((u32 *)(pcmd + 4));
12027 len = be32_to_cpu(len);
12028 memcpy(vport->qfpa_res, pcmd, len + 8);
12029 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE;
12031 desc = (struct priority_range_desc *)(pcmd + 8);
12032 vmid_range = vport->vmid_priority.vmid_range;
12034 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range),
12037 kfree(vport->qfpa_res);
12040 vport->vmid_priority.vmid_range = vmid_range;
12042 vport->vmid_priority.num_descriptors = len;
12044 for (i = 0; i < len; i++, vmid_range++, desc++) {
12045 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12046 "6539 vmid values low=%d, high=%d, qos=%d, "
12047 "local ve id=%d\n", desc->lo_range,
12048 desc->hi_range, desc->qos_priority,
12049 desc->local_ve_id);
12051 vmid_range->low = desc->lo_range << 1;
12052 if (desc->local_ve_id == QFPA_ODD_ONLY)
12054 if (desc->qos_priority)
12055 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED;
12056 vmid_range->qos = desc->qos_priority;
12058 vmid_range->high = desc->hi_range << 1;
12059 if ((desc->local_ve_id == QFPA_ODD_ONLY) ||
12060 (desc->local_ve_id == QFPA_EVEN_ODD))
12061 vmid_range->high++;
12063 lpfc_init_cs_ctl_bitmap(vport);
12064 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) {
12065 lpfc_vmid_set_cs_ctl_range(vport,
12066 vport->vmid_priority.vmid_range[i].low,
12067 vport->vmid_priority.vmid_range[i].high);
12070 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL;
12072 lpfc_els_free_iocb(phba, cmdiocb);
12073 lpfc_nlp_put(ndlp);
12076 int lpfc_issue_els_qfpa(struct lpfc_vport *vport)
12078 struct lpfc_hba *phba = vport->phba;
12079 struct lpfc_nodelist *ndlp;
12080 struct lpfc_iocbq *elsiocb;
12084 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
12085 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12088 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp,
12089 ndlp->nlp_DID, ELS_CMD_QFPA);
12093 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
12095 *((u32 *)(pcmd)) = ELS_CMD_QFPA;
12098 elsiocb->cmd_cmpl = lpfc_cmpl_els_qfpa;
12100 elsiocb->context1 = lpfc_nlp_get(ndlp);
12101 if (!elsiocb->context1) {
12102 lpfc_els_free_iocb(vport->phba, elsiocb);
12106 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2);
12107 if (ret != IOCB_SUCCESS) {
12108 lpfc_els_free_iocb(phba, elsiocb);
12109 lpfc_nlp_put(ndlp);
12112 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED;
12117 lpfc_vmid_uvem(struct lpfc_vport *vport,
12118 struct lpfc_vmid *vmid, bool instantiated)
12120 struct lpfc_vem_id_desc *vem_id_desc;
12121 struct lpfc_nodelist *ndlp;
12122 struct lpfc_iocbq *elsiocb;
12123 struct instantiated_ve_desc *inst_desc;
12124 struct lpfc_vmid_context *vmid_context;
12129 ndlp = lpfc_findnode_did(vport, Fabric_DID);
12130 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12133 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL);
12136 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2,
12137 ndlp, Fabric_DID, ELS_CMD_UVEM);
12141 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12142 "3427 Host vmid %s %d\n",
12143 vmid->host_vmid, instantiated);
12144 vmid_context->vmp = vmid;
12145 vmid_context->nlp = ndlp;
12146 vmid_context->instantiated = instantiated;
12147 elsiocb->vmid_tag.vmid_context = vmid_context;
12148 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
12150 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid))
12151 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid,
12152 LPFC_COMPRESS_VMID_SIZE);
12154 *((u32 *)(pcmd)) = ELS_CMD_UVEM;
12155 len = (u32 *)(pcmd + 4);
12156 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8);
12158 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8);
12159 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG);
12160 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE);
12161 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid,
12162 LPFC_COMPRESS_VMID_SIZE);
12164 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32);
12165 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12166 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE);
12167 memcpy(inst_desc->global_vem_id, vmid->host_vmid,
12168 LPFC_COMPRESS_VMID_SIZE);
12170 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID);
12171 bf_set(lpfc_instantiated_local_id, inst_desc,
12172 vmid->un.cs_ctl_vmid);
12173 if (instantiated) {
12174 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12176 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG);
12177 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid);
12179 inst_desc->word6 = cpu_to_be32(inst_desc->word6);
12181 elsiocb->cmd_cmpl = lpfc_cmpl_els_uvem;
12183 elsiocb->context1 = lpfc_nlp_get(ndlp);
12184 if (!elsiocb->context1) {
12185 lpfc_els_free_iocb(vport->phba, elsiocb);
12189 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0);
12190 if (ret != IOCB_SUCCESS) {
12191 lpfc_els_free_iocb(vport->phba, elsiocb);
12192 lpfc_nlp_put(ndlp);
12198 kfree(vmid_context);
12203 lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb,
12204 struct lpfc_iocbq *rspiocb)
12206 struct lpfc_vport *vport = icmdiocb->vport;
12207 struct lpfc_dmabuf *prsp = NULL;
12208 struct lpfc_vmid_context *vmid_context =
12209 icmdiocb->vmid_tag.vmid_context;
12210 struct lpfc_nodelist *ndlp = icmdiocb->context1;
12213 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
12214 u32 ulp_word4 = get_job_word4(phba, rspiocb);
12215 struct lpfc_dmabuf *dmabuf = icmdiocb->context2;
12216 struct lpfc_vmid *vmid;
12218 vmid = vmid_context->vmp;
12219 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12222 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
12226 data = (u32 *)pcmd;
12227 if (data[0] == ELS_CMD_LS_RJT) {
12228 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12229 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]);
12233 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12234 "4533 UVEM error status %x: %x\n",
12235 ulp_status, ulp_word4);
12238 spin_lock(&phba->hbalock);
12239 /* Set IN USE flag */
12240 vport->vmid_flag |= LPFC_VMID_IN_USE;
12241 phba->pport->vmid_flag |= LPFC_VMID_IN_USE;
12242 spin_unlock(&phba->hbalock);
12244 if (vmid_context->instantiated) {
12245 write_lock(&vport->vmid_lock);
12246 vmid->flag |= LPFC_VMID_REGISTERED;
12247 vmid->flag &= ~LPFC_VMID_REQ_REGISTER;
12248 write_unlock(&vport->vmid_lock);
12252 kfree(vmid_context);
12253 lpfc_els_free_iocb(phba, icmdiocb);
12254 lpfc_nlp_put(ndlp);