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 * ndlp 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->cmd_dmabuf = pcmd;
283 elsiocb->bpl_dmabuf = 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_nodelist *ndlp;
349 struct serv_parm *sp;
353 sp = &phba->fc_fabparam;
354 ndlp = lpfc_findnode_did(vport, Fabric_DID);
360 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
366 vport->port_state = LPFC_FABRIC_CFG_LINK;
367 lpfc_config_link(phba, mbox);
368 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
371 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
372 if (rc == MBX_NOT_FINISHED) {
377 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
382 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
389 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
391 /* increment the reference count on ndlp to hold reference
392 * for the callback routine.
394 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
395 if (!mbox->ctx_ndlp) {
400 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
401 if (rc == MBX_NOT_FINISHED) {
403 goto fail_issue_reg_login;
408 fail_issue_reg_login:
409 /* decrement the reference count on ndlp just incremented
410 * for the failed mbox command.
414 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
416 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
417 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
418 "0249 Cannot issue Register Fabric login: Err %d\n",
424 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
425 * @vport: pointer to a host virtual N_Port data structure.
427 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
428 * the @vport. This mailbox command is necessary for SLI4 port only.
431 * 0 - successfully issued REG_VFI for @vport
432 * A failure code otherwise.
435 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
437 struct lpfc_hba *phba = vport->phba;
438 LPFC_MBOXQ_t *mboxq = NULL;
439 struct lpfc_nodelist *ndlp;
440 struct lpfc_dmabuf *dmabuf = NULL;
443 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
444 if ((phba->sli_rev == LPFC_SLI_REV4) &&
445 !(phba->link_flag & LS_LOOPBACK_MODE) &&
446 !(vport->fc_flag & FC_PT2PT)) {
447 ndlp = lpfc_findnode_did(vport, Fabric_DID);
454 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
460 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
461 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
462 rc = lpfc_mbox_rsrc_prep(phba, mboxq);
467 dmabuf = mboxq->ctx_buf;
468 memcpy(dmabuf->virt, &phba->fc_fabparam,
469 sizeof(struct serv_parm));
472 vport->port_state = LPFC_FABRIC_CFG_LINK;
474 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
475 /* lpfc_reg_vfi memsets the mailbox. Restore the ctx_buf. */
476 mboxq->ctx_buf = dmabuf;
478 lpfc_reg_vfi(mboxq, vport, 0);
481 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
482 mboxq->vport = vport;
483 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
484 if (rc == MBX_NOT_FINISHED) {
491 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
493 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
494 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
495 "0289 Issue Register VFI failed: Err %d\n", rc);
500 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
501 * @vport: pointer to a host virtual N_Port data structure.
503 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
504 * the @vport. This mailbox command is necessary for SLI4 port only.
507 * 0 - successfully issued REG_VFI for @vport
508 * A failure code otherwise.
511 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
513 struct lpfc_hba *phba = vport->phba;
514 struct Scsi_Host *shost;
518 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
520 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
521 "2556 UNREG_VFI mbox allocation failed"
522 "HBA state x%x\n", phba->pport->port_state);
526 lpfc_unreg_vfi(mboxq, vport);
527 mboxq->vport = vport;
528 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
530 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
531 if (rc == MBX_NOT_FINISHED) {
532 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
533 "2557 UNREG_VFI issue mbox failed rc x%x "
535 rc, phba->pport->port_state);
536 mempool_free(mboxq, phba->mbox_mem_pool);
540 shost = lpfc_shost_from_vport(vport);
541 spin_lock_irq(shost->host_lock);
542 vport->fc_flag &= ~FC_VFI_REGISTERED;
543 spin_unlock_irq(shost->host_lock);
548 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
549 * @vport: pointer to a host virtual N_Port data structure.
550 * @sp: pointer to service parameter data structure.
552 * This routine is called from FLOGI/FDISC completion handler functions.
553 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
554 * node nodename is changed in the completion service parameter else return
555 * 0. This function also set flag in the vport data structure to delay
556 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
557 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
558 * node nodename is changed in the completion service parameter.
561 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
562 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
566 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
567 struct serv_parm *sp)
569 struct lpfc_hba *phba = vport->phba;
570 uint8_t fabric_param_changed = 0;
571 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
573 if ((vport->fc_prevDID != vport->fc_myDID) ||
574 memcmp(&vport->fabric_portname, &sp->portName,
575 sizeof(struct lpfc_name)) ||
576 memcmp(&vport->fabric_nodename, &sp->nodeName,
577 sizeof(struct lpfc_name)) ||
578 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
579 fabric_param_changed = 1;
580 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
583 * Word 1 Bit 31 in common service parameter is overloaded.
584 * Word 1 Bit 31 in FLOGI request is multiple NPort request
585 * Word 1 Bit 31 in FLOGI response is clean address bit
587 * If fabric parameter is changed and clean address bit is
588 * cleared delay nport discovery if
589 * - vport->fc_prevDID != 0 (not initial discovery) OR
590 * - lpfc_delay_discovery module parameter is set.
592 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
593 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
594 spin_lock_irq(shost->host_lock);
595 vport->fc_flag |= FC_DISC_DELAYED;
596 spin_unlock_irq(shost->host_lock);
599 return fabric_param_changed;
604 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
605 * @vport: pointer to a host virtual N_Port data structure.
606 * @ndlp: pointer to a node-list data structure.
607 * @sp: pointer to service parameter data structure.
608 * @ulp_word4: command response value
610 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
611 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
612 * port in a fabric topology. It properly sets up the parameters to the @ndlp
613 * from the IOCB response. It also check the newly assigned N_Port ID to the
614 * @vport against the previously assigned N_Port ID. If it is different from
615 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
616 * is invoked on all the remaining nodes with the @vport to unregister the
617 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
618 * is invoked to register login to the fabric.
621 * 0 - Success (currently, always return 0)
624 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
625 struct serv_parm *sp, uint32_t ulp_word4)
627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
628 struct lpfc_hba *phba = vport->phba;
629 struct lpfc_nodelist *np;
630 struct lpfc_nodelist *next_np;
631 uint8_t fabric_param_changed;
633 spin_lock_irq(shost->host_lock);
634 vport->fc_flag |= FC_FABRIC;
635 spin_unlock_irq(shost->host_lock);
637 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
638 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
639 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
641 phba->fc_edtovResol = sp->cmn.edtovResolution;
642 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
644 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
645 spin_lock_irq(shost->host_lock);
646 vport->fc_flag |= FC_PUBLIC_LOOP;
647 spin_unlock_irq(shost->host_lock);
650 vport->fc_myDID = ulp_word4 & Mask_DID;
651 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
652 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
653 ndlp->nlp_class_sup = 0;
654 if (sp->cls1.classValid)
655 ndlp->nlp_class_sup |= FC_COS_CLASS1;
656 if (sp->cls2.classValid)
657 ndlp->nlp_class_sup |= FC_COS_CLASS2;
658 if (sp->cls3.classValid)
659 ndlp->nlp_class_sup |= FC_COS_CLASS3;
660 if (sp->cls4.classValid)
661 ndlp->nlp_class_sup |= FC_COS_CLASS4;
662 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
663 sp->cmn.bbRcvSizeLsb;
665 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
666 if (fabric_param_changed) {
667 /* Reset FDMI attribute masks based on config parameter */
668 if (phba->cfg_enable_SmartSAN ||
669 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
670 /* Setup appropriate attribute masks */
671 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
672 if (phba->cfg_enable_SmartSAN)
673 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
675 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
677 vport->fdmi_hba_mask = 0;
678 vport->fdmi_port_mask = 0;
682 memcpy(&vport->fabric_portname, &sp->portName,
683 sizeof(struct lpfc_name));
684 memcpy(&vport->fabric_nodename, &sp->nodeName,
685 sizeof(struct lpfc_name));
686 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
688 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
689 if (sp->cmn.response_multiple_NPort) {
690 lpfc_printf_vlog(vport, KERN_WARNING,
692 "1816 FLOGI NPIV supported, "
693 "response data 0x%x\n",
694 sp->cmn.response_multiple_NPort);
695 spin_lock_irq(&phba->hbalock);
696 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
697 spin_unlock_irq(&phba->hbalock);
699 /* Because we asked f/w for NPIV it still expects us
700 to call reg_vnpid at least for the physical host */
701 lpfc_printf_vlog(vport, KERN_WARNING,
703 "1817 Fabric does not support NPIV "
704 "- configuring single port mode.\n");
705 spin_lock_irq(&phba->hbalock);
706 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
707 spin_unlock_irq(&phba->hbalock);
712 * For FC we need to do some special processing because of the SLI
713 * Port's default settings of the Common Service Parameters.
715 if ((phba->sli_rev == LPFC_SLI_REV4) &&
716 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
717 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
718 if (fabric_param_changed)
719 lpfc_unregister_fcf_prep(phba);
721 /* This should just update the VFI CSPs*/
722 if (vport->fc_flag & FC_VFI_REGISTERED)
723 lpfc_issue_reg_vfi(vport);
726 if (fabric_param_changed &&
727 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
729 /* If our NportID changed, we need to ensure all
730 * remaining NPORTs get unreg_login'ed.
732 list_for_each_entry_safe(np, next_np,
733 &vport->fc_nodes, nlp_listp) {
734 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
735 !(np->nlp_flag & NLP_NPR_ADISC))
737 spin_lock_irq(&np->lock);
738 np->nlp_flag &= ~NLP_NPR_ADISC;
739 spin_unlock_irq(&np->lock);
740 lpfc_unreg_rpi(vport, np);
742 lpfc_cleanup_pending_mbox(vport);
744 if (phba->sli_rev == LPFC_SLI_REV4) {
745 lpfc_sli4_unreg_all_rpis(vport);
746 lpfc_mbx_unreg_vpi(vport);
747 spin_lock_irq(shost->host_lock);
748 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
749 spin_unlock_irq(shost->host_lock);
753 * For SLI3 and SLI4, the VPI needs to be reregistered in
754 * response to this fabric parameter change event.
756 spin_lock_irq(shost->host_lock);
757 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
758 spin_unlock_irq(shost->host_lock);
759 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
760 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
762 * Driver needs to re-reg VPI in order for f/w
763 * to update the MAC address.
765 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
766 lpfc_register_new_vport(phba, vport, ndlp);
770 if (phba->sli_rev < LPFC_SLI_REV4) {
771 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
772 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
773 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
774 lpfc_register_new_vport(phba, vport, ndlp);
776 lpfc_issue_fabric_reglogin(vport);
778 ndlp->nlp_type |= NLP_FABRIC;
779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
780 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
781 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
782 lpfc_start_fdiscs(phba);
783 lpfc_do_scr_ns_plogi(phba, vport);
784 } else if (vport->fc_flag & FC_VFI_REGISTERED)
785 lpfc_issue_init_vpi(vport);
787 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
788 "3135 Need register VFI: (x%x/%x)\n",
789 vport->fc_prevDID, vport->fc_myDID);
790 lpfc_issue_reg_vfi(vport);
797 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
798 * @vport: pointer to a host virtual N_Port data structure.
799 * @ndlp: pointer to a node-list data structure.
800 * @sp: pointer to service parameter data structure.
802 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
803 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
804 * in a point-to-point topology. First, the @vport's N_Port Name is compared
805 * with the received N_Port Name: if the @vport's N_Port Name is greater than
806 * the received N_Port Name lexicographically, this node shall assign local
807 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
808 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
809 * this node shall just wait for the remote node to issue PLOGI and assign
817 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
818 struct serv_parm *sp)
820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
821 struct lpfc_hba *phba = vport->phba;
825 spin_lock_irq(shost->host_lock);
826 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
827 vport->fc_flag |= FC_PT2PT;
828 spin_unlock_irq(shost->host_lock);
830 /* If we are pt2pt with another NPort, force NPIV off! */
831 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
833 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
834 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
835 lpfc_unregister_fcf_prep(phba);
837 spin_lock_irq(shost->host_lock);
838 vport->fc_flag &= ~FC_VFI_REGISTERED;
839 spin_unlock_irq(shost->host_lock);
840 phba->fc_topology_changed = 0;
843 rc = memcmp(&vport->fc_portname, &sp->portName,
844 sizeof(vport->fc_portname));
847 /* This side will initiate the PLOGI */
848 spin_lock_irq(shost->host_lock);
849 vport->fc_flag |= FC_PT2PT_PLOGI;
850 spin_unlock_irq(shost->host_lock);
853 * N_Port ID cannot be 0, set our Id to LocalID
854 * the other side will be RemoteID.
859 vport->fc_myDID = PT2PT_LocalID;
861 /* If not registered with a transport, decrement ndlp reference
862 * count indicating that ndlp can be safely released when other
863 * references are removed.
865 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
868 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
871 * Cannot find existing Fabric ndlp, so allocate a
874 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
879 memcpy(&ndlp->nlp_portname, &sp->portName,
880 sizeof(struct lpfc_name));
881 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
882 sizeof(struct lpfc_name));
883 /* Set state will put ndlp onto node list if not already done */
884 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
885 spin_lock_irq(&ndlp->lock);
886 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
887 spin_unlock_irq(&ndlp->lock);
889 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
893 lpfc_config_link(phba, mbox);
895 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
897 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
898 if (rc == MBX_NOT_FINISHED) {
899 mempool_free(mbox, phba->mbox_mem_pool);
903 /* This side will wait for the PLOGI. If not registered with
904 * a transport, decrement node reference count indicating that
905 * ndlp can be released when other references are removed.
907 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
910 /* Start discovery - this should just do CLEAR_LA */
911 lpfc_disc_start(vport);
920 * lpfc_cmpl_els_flogi - Completion callback function for flogi
921 * @phba: pointer to lpfc hba data structure.
922 * @cmdiocb: pointer to lpfc command iocb data structure.
923 * @rspiocb: pointer to lpfc response iocb data structure.
925 * This routine is the top-level completion callback function for issuing
926 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
927 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
928 * retry has been made (either immediately or delayed with lpfc_els_retry()
929 * returning 1), the command IOCB will be released and function returned.
930 * If the retry attempt has been given up (possibly reach the maximum
931 * number of retries), one additional decrement of ndlp reference shall be
932 * invoked before going out after releasing the command IOCB. This will
933 * actually release the remote node (Note, lpfc_els_free_iocb() will also
934 * invoke one decrement of ndlp reference count). If no error reported in
935 * the IOCB status, the command Port ID field is used to determine whether
936 * this is a point-to-point topology or a fabric topology: if the Port ID
937 * field is assigned, it is a fabric topology; otherwise, it is a
938 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
939 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
940 * specific topology completion conditions.
943 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
944 struct lpfc_iocbq *rspiocb)
946 struct lpfc_vport *vport = cmdiocb->vport;
947 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
948 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
950 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
951 struct serv_parm *sp;
954 u32 ulp_status, ulp_word4, tmo;
956 /* Check to see if link went down during discovery */
957 if (lpfc_els_chk_latt(vport)) {
958 /* One additional decrement on node reference count to
959 * trigger the release of the node
961 if (!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD))
966 ulp_status = get_job_ulpstatus(phba, rspiocb);
967 ulp_word4 = get_job_word4(phba, rspiocb);
969 if (phba->sli_rev == LPFC_SLI_REV4) {
970 tmo = get_wqe_tmo(cmdiocb);
972 irsp = &rspiocb->iocb;
973 tmo = irsp->ulpTimeout;
976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
977 "FLOGI cmpl: status:x%x/x%x state:x%x",
978 ulp_status, ulp_word4,
983 * In case of FIP mode, perform roundrobin FCF failover
984 * due to new FCF discovery
986 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
987 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
988 if (phba->link_state < LPFC_LINK_UP)
989 goto stop_rr_fcf_flogi;
990 if ((phba->fcoe_cvl_eventtag_attn ==
991 phba->fcoe_cvl_eventtag) &&
992 (ulp_status == IOSTAT_LOCAL_REJECT) &&
993 ((ulp_word4 & IOERR_PARAM_MASK) ==
995 goto stop_rr_fcf_flogi;
997 phba->fcoe_cvl_eventtag_attn =
998 phba->fcoe_cvl_eventtag;
999 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1000 "2611 FLOGI failed on FCF (x%x), "
1001 "status:x%x/x%x, tmo:x%x, perform "
1002 "roundrobin FCF failover\n",
1003 phba->fcf.current_rec.fcf_indx,
1004 ulp_status, ulp_word4, tmo);
1005 lpfc_sli4_set_fcf_flogi_fail(phba,
1006 phba->fcf.current_rec.fcf_indx);
1007 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1008 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1015 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
1016 ((ulp_word4 & IOERR_PARAM_MASK) ==
1017 IOERR_LOOP_OPEN_FAILURE)))
1018 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1019 "2858 FLOGI failure Status:x%x/x%x TMO"
1020 ":x%x Data x%x x%x\n",
1021 ulp_status, ulp_word4, tmo,
1022 phba->hba_flag, phba->fcf.fcf_flag);
1024 /* Check for retry */
1025 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1028 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1029 "0150 FLOGI failure Status:x%x/x%x "
1030 "xri x%x TMO:x%x refcnt %d\n",
1031 ulp_status, ulp_word4, cmdiocb->sli4_xritag,
1032 tmo, kref_read(&ndlp->kref));
1034 /* If this is not a loop open failure, bail out */
1035 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
1036 ((ulp_word4 & IOERR_PARAM_MASK) ==
1037 IOERR_LOOP_OPEN_FAILURE))) {
1039 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1040 "0100 FLOGI failure Status:x%x/x%x "
1042 ulp_status, ulp_word4, tmo);
1046 /* FLOGI failed, so there is no fabric */
1047 spin_lock_irq(shost->host_lock);
1048 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP |
1050 spin_unlock_irq(shost->host_lock);
1052 /* If private loop, then allow max outstanding els to be
1053 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1054 * alpa map would take too long otherwise.
1056 if (phba->alpa_map[0] == 0)
1057 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1058 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1059 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1060 (vport->fc_prevDID != vport->fc_myDID) ||
1061 phba->fc_topology_changed)) {
1062 if (vport->fc_flag & FC_VFI_REGISTERED) {
1063 if (phba->fc_topology_changed) {
1064 lpfc_unregister_fcf_prep(phba);
1065 spin_lock_irq(shost->host_lock);
1066 vport->fc_flag &= ~FC_VFI_REGISTERED;
1067 spin_unlock_irq(shost->host_lock);
1068 phba->fc_topology_changed = 0;
1070 lpfc_sli4_unreg_all_rpis(vport);
1074 /* Do not register VFI if the driver aborted FLOGI */
1075 if (!lpfc_error_lost_link(ulp_status, ulp_word4))
1076 lpfc_issue_reg_vfi(vport);
1083 spin_lock_irq(shost->host_lock);
1084 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1085 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1086 spin_unlock_irq(shost->host_lock);
1089 * The FLogI succeeded. Sync the data for the CPU before
1092 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1095 sp = prsp->virt + sizeof(uint32_t);
1097 /* FLOGI completes successfully */
1098 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1099 "0101 FLOGI completes successfully, I/O tag:x%x "
1100 "xri x%x Data: x%x x%x x%x x%x x%x x%x x%x %d\n",
1101 cmdiocb->iotag, cmdiocb->sli4_xritag,
1102 ulp_word4, sp->cmn.e_d_tov,
1103 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1104 vport->port_state, vport->fc_flag,
1105 sp->cmn.priority_tagging, kref_read(&ndlp->kref));
1107 if (sp->cmn.priority_tagging)
1108 vport->phba->pport->vmid_flag |= (LPFC_VMID_ISSUE_QFPA |
1109 LPFC_VMID_TYPE_PRIO);
1111 if (vport->port_state == LPFC_FLOGI) {
1113 * If Common Service Parameters indicate Nport
1114 * we are point to point, if Fport we are Fabric.
1117 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp,
1119 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1120 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1122 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1123 "2831 FLOGI response with cleared Fabric "
1124 "bit fcf_index 0x%x "
1125 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1127 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1128 phba->fcf.current_rec.fcf_indx,
1129 phba->fcf.current_rec.switch_name[0],
1130 phba->fcf.current_rec.switch_name[1],
1131 phba->fcf.current_rec.switch_name[2],
1132 phba->fcf.current_rec.switch_name[3],
1133 phba->fcf.current_rec.switch_name[4],
1134 phba->fcf.current_rec.switch_name[5],
1135 phba->fcf.current_rec.switch_name[6],
1136 phba->fcf.current_rec.switch_name[7],
1137 phba->fcf.current_rec.fabric_name[0],
1138 phba->fcf.current_rec.fabric_name[1],
1139 phba->fcf.current_rec.fabric_name[2],
1140 phba->fcf.current_rec.fabric_name[3],
1141 phba->fcf.current_rec.fabric_name[4],
1142 phba->fcf.current_rec.fabric_name[5],
1143 phba->fcf.current_rec.fabric_name[6],
1144 phba->fcf.current_rec.fabric_name[7]);
1147 spin_lock_irq(&phba->hbalock);
1148 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1149 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1150 spin_unlock_irq(&phba->hbalock);
1151 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1155 /* Mark the FCF discovery process done */
1156 if (phba->hba_flag & HBA_FIP_SUPPORT)
1157 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1159 "2769 FLOGI to FCF (x%x) "
1160 "completed successfully\n",
1161 phba->fcf.current_rec.fcf_indx);
1162 spin_lock_irq(&phba->hbalock);
1163 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1164 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1165 spin_unlock_irq(&phba->hbalock);
1166 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1169 } else if (vport->port_state > LPFC_FLOGI &&
1170 vport->fc_flag & FC_PT2PT) {
1172 * In a p2p topology, it is possible that discovery has
1173 * already progressed, and this completion can be ignored.
1174 * Recheck the indicated topology.
1181 spin_lock_irq(&phba->hbalock);
1182 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1183 spin_unlock_irq(&phba->hbalock);
1185 if (!lpfc_error_lost_link(ulp_status, ulp_word4)) {
1186 /* FLOGI failed, so just use loop map to make discovery list */
1187 lpfc_disc_list_loopmap(vport);
1189 /* Start discovery */
1190 lpfc_disc_start(vport);
1191 } else if (((ulp_status != IOSTAT_LOCAL_REJECT) ||
1192 (((ulp_word4 & IOERR_PARAM_MASK) !=
1193 IOERR_SLI_ABORTED) &&
1194 ((ulp_word4 & IOERR_PARAM_MASK) !=
1195 IOERR_SLI_DOWN))) &&
1196 (phba->link_state != LPFC_CLEAR_LA)) {
1197 /* If FLOGI failed enable link interrupt. */
1198 lpfc_issue_clear_la(phba, vport);
1201 phba->hba_flag &= ~HBA_FLOGI_OUTSTANDING;
1202 lpfc_els_free_iocb(phba, cmdiocb);
1207 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1208 * aborted during a link down
1209 * @phba: pointer to lpfc hba data structure.
1210 * @cmdiocb: pointer to lpfc command iocb data structure.
1211 * @rspiocb: pointer to lpfc response iocb data structure.
1215 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1216 struct lpfc_iocbq *rspiocb)
1220 u32 ulp_status, ulp_word4;
1222 pcmd = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
1225 ulp_status = get_job_ulpstatus(phba, rspiocb);
1226 ulp_word4 = get_job_word4(phba, rspiocb);
1228 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1229 "6445 ELS completes after LINK_DOWN: "
1230 " Status %x/%x cmd x%x flg x%x\n",
1231 ulp_status, ulp_word4, cmd,
1234 if (cmdiocb->cmd_flag & LPFC_IO_FABRIC) {
1235 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
1236 atomic_dec(&phba->fabric_iocb_count);
1238 lpfc_els_free_iocb(phba, cmdiocb);
1242 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1243 * @vport: pointer to a host virtual N_Port data structure.
1244 * @ndlp: pointer to a node-list data structure.
1245 * @retry: number of retries to the command IOCB.
1247 * This routine issues a Fabric Login (FLOGI) Request ELS command
1248 * for a @vport. The initiator service parameters are put into the payload
1249 * of the FLOGI Request IOCB and the top-level callback function pointer
1250 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1251 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1252 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1254 * Note that the ndlp reference count will be incremented by 1 for holding the
1255 * ndlp and the reference to ndlp will be stored into the ndlp field of
1256 * the IOCB for the completion callback function to the FLOGI ELS command.
1259 * 0 - successfully issued flogi iocb for @vport
1260 * 1 - failed to issue flogi iocb for @vport
1263 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1266 struct lpfc_hba *phba = vport->phba;
1267 struct serv_parm *sp;
1268 union lpfc_wqe128 *wqe = NULL;
1269 IOCB_t *icmd = NULL;
1270 struct lpfc_iocbq *elsiocb;
1271 struct lpfc_iocbq defer_flogi_acc;
1277 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1278 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1279 ndlp->nlp_DID, ELS_CMD_FLOGI);
1284 wqe = &elsiocb->wqe;
1285 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
1286 icmd = &elsiocb->iocb;
1288 /* For FLOGI request, remainder of payload is service parameters */
1289 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1290 pcmd += sizeof(uint32_t);
1291 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1292 sp = (struct serv_parm *) pcmd;
1294 /* Setup CSPs accordingly for Fabric */
1295 sp->cmn.e_d_tov = 0;
1296 sp->cmn.w2.r_a_tov = 0;
1297 sp->cmn.virtual_fabric_support = 0;
1298 sp->cls1.classValid = 0;
1299 if (sp->cmn.fcphLow < FC_PH3)
1300 sp->cmn.fcphLow = FC_PH3;
1301 if (sp->cmn.fcphHigh < FC_PH3)
1302 sp->cmn.fcphHigh = FC_PH3;
1304 /* Determine if switch supports priority tagging */
1305 if (phba->cfg_vmid_priority_tagging) {
1306 sp->cmn.priority_tagging = 1;
1307 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
1308 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid)) {
1309 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn,
1310 sizeof(phba->wwpn));
1311 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn,
1312 sizeof(phba->wwnn));
1316 if (phba->sli_rev == LPFC_SLI_REV4) {
1317 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1318 LPFC_SLI_INTF_IF_TYPE_0) {
1319 /* FLOGI needs to be 3 for WQE FCFI */
1321 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
1323 /* Set the fcfi to the fcfi we registered with */
1324 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
1328 /* Can't do SLI4 class2 without support sequence coalescing */
1329 sp->cls2.classValid = 0;
1330 sp->cls2.seqDelivery = 0;
1332 /* Historical, setting sequential-delivery bit for SLI3 */
1333 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1334 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1335 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1336 sp->cmn.request_multiple_Nport = 1;
1337 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1341 sp->cmn.request_multiple_Nport = 0;
1344 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1345 icmd->un.elsreq64.myID = 0;
1346 icmd->un.elsreq64.fl = 1;
1350 tmo = phba->fc_ratov;
1351 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1352 lpfc_set_disctmo(vport);
1353 phba->fc_ratov = tmo;
1355 phba->fc_stat.elsXmitFLOGI++;
1356 elsiocb->cmd_cmpl = lpfc_cmpl_els_flogi;
1358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1359 "Issue FLOGI: opt:x%x",
1360 phba->sli3_options, 0, 0);
1362 elsiocb->ndlp = lpfc_nlp_get(ndlp);
1363 if (!elsiocb->ndlp) {
1364 lpfc_els_free_iocb(phba, elsiocb);
1368 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1369 if (rc == IOCB_ERROR) {
1370 lpfc_els_free_iocb(phba, elsiocb);
1375 phba->hba_flag |= (HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
1377 /* Clear external loopback plug detected flag */
1378 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
1380 /* Check for a deferred FLOGI ACC condition */
1381 if (phba->defer_flogi_acc_flag) {
1382 /* lookup ndlp for received FLOGI */
1383 ndlp = lpfc_findnode_did(vport, 0);
1387 did = vport->fc_myDID;
1388 vport->fc_myDID = Fabric_DID;
1390 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1392 if (phba->sli_rev == LPFC_SLI_REV4) {
1393 bf_set(wqe_ctxt_tag,
1394 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1395 phba->defer_flogi_acc_rx_id);
1397 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1398 phba->defer_flogi_acc_ox_id);
1400 icmd = &defer_flogi_acc.iocb;
1401 icmd->ulpContext = phba->defer_flogi_acc_rx_id;
1402 icmd->unsli3.rcvsli3.ox_id =
1403 phba->defer_flogi_acc_ox_id;
1406 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1407 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1408 " ox_id: x%x, hba_flag x%x\n",
1409 phba->defer_flogi_acc_rx_id,
1410 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1412 /* Send deferred FLOGI ACC */
1413 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1416 phba->defer_flogi_acc_flag = false;
1417 vport->fc_myDID = did;
1419 /* Decrement ndlp reference count to indicate the node can be
1420 * released when other references are removed.
1429 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1430 * @phba: pointer to lpfc hba data structure.
1432 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1433 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1434 * list and issues an abort IOCB commond on each outstanding IOCB that
1435 * contains a active Fabric_DID ndlp. Note that this function is to issue
1436 * the abort IOCB command on all the outstanding IOCBs, thus when this
1437 * function returns, it does not guarantee all the IOCBs are actually aborted.
1440 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1443 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1445 struct lpfc_sli_ring *pring;
1446 struct lpfc_iocbq *iocb, *next_iocb;
1447 struct lpfc_nodelist *ndlp;
1450 /* Abort outstanding I/O on NPort <nlp_DID> */
1451 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1452 "0201 Abort outstanding I/O on NPort x%x\n",
1455 pring = lpfc_phba_elsring(phba);
1456 if (unlikely(!pring))
1460 * Check the txcmplq for an iocb that matches the nport the driver is
1463 spin_lock_irq(&phba->hbalock);
1464 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1465 ulp_command = get_job_cmnd(phba, iocb);
1466 if (ulp_command == CMD_ELS_REQUEST64_CR) {
1468 if (ndlp && ndlp->nlp_DID == Fabric_DID) {
1469 if ((phba->pport->fc_flag & FC_PT2PT) &&
1470 !(phba->pport->fc_flag & FC_PT2PT_PLOGI))
1471 iocb->fabric_cmd_cmpl =
1472 lpfc_ignore_els_cmpl;
1473 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1478 /* Make sure HBA is alive */
1479 lpfc_issue_hb_tmo(phba);
1481 spin_unlock_irq(&phba->hbalock);
1487 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1488 * @vport: pointer to a host virtual N_Port data structure.
1490 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1491 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1492 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1493 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1494 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1495 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1499 * 0 - failed to issue initial flogi for @vport
1500 * 1 - successfully issued initial flogi for @vport
1503 lpfc_initial_flogi(struct lpfc_vport *vport)
1505 struct lpfc_nodelist *ndlp;
1507 vport->port_state = LPFC_FLOGI;
1508 lpfc_set_disctmo(vport);
1510 /* First look for the Fabric ndlp */
1511 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1513 /* Cannot find existing Fabric ndlp, so allocate a new one */
1514 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1517 /* Set the node type */
1518 ndlp->nlp_type |= NLP_FABRIC;
1520 /* Put ndlp onto node list */
1521 lpfc_enqueue_node(vport, ndlp);
1524 /* Reset the Fabric flag, topology change may have happened */
1525 vport->fc_flag &= ~FC_FABRIC;
1526 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1527 /* A node reference should be retained while registered with a
1528 * transport or dev-loss-evt work is pending.
1529 * Otherwise, decrement node reference to trigger release.
1531 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
1532 !(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
1540 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1541 * @vport: pointer to a host virtual N_Port data structure.
1543 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1544 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1545 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1546 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1547 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1548 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1552 * 0 - failed to issue initial fdisc for @vport
1553 * 1 - successfully issued initial fdisc for @vport
1556 lpfc_initial_fdisc(struct lpfc_vport *vport)
1558 struct lpfc_nodelist *ndlp;
1560 /* First look for the Fabric ndlp */
1561 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1563 /* Cannot find existing Fabric ndlp, so allocate a new one */
1564 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1568 /* NPIV is only supported in Fabrics. */
1569 ndlp->nlp_type |= NLP_FABRIC;
1571 /* Put ndlp onto node list */
1572 lpfc_enqueue_node(vport, ndlp);
1575 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1576 /* A node reference should be retained while registered with a
1577 * transport or dev-loss-evt work is pending.
1578 * Otherwise, decrement node reference to trigger release.
1580 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
1581 !(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
1589 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1590 * @vport: pointer to a host virtual N_Port data structure.
1592 * This routine checks whether there are more remaining Port Logins
1593 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1594 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1595 * to issue ELS PLOGIs up to the configured discover threads with the
1596 * @vport (@vport->cfg_discovery_threads). The function also decrement
1597 * the @vport's num_disc_node by 1 if it is not already 0.
1600 lpfc_more_plogi(struct lpfc_vport *vport)
1602 if (vport->num_disc_nodes)
1603 vport->num_disc_nodes--;
1605 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1606 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1607 "0232 Continue discovery with %d PLOGIs to go "
1608 "Data: x%x x%x x%x\n",
1609 vport->num_disc_nodes, vport->fc_plogi_cnt,
1610 vport->fc_flag, vport->port_state);
1611 /* Check to see if there are more PLOGIs to be sent */
1612 if (vport->fc_flag & FC_NLP_MORE)
1613 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1614 lpfc_els_disc_plogi(vport);
1620 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1621 * @phba: pointer to lpfc hba data structure.
1622 * @prsp: pointer to response IOCB payload.
1623 * @ndlp: pointer to a node-list data structure.
1625 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1626 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1627 * The following cases are considered N_Port confirmed:
1628 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1629 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1630 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1631 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1632 * 1) if there is a node on vport list other than the @ndlp with the same
1633 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1634 * on that node to release the RPI associated with the node; 2) if there is
1635 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1636 * into, a new node shall be allocated (or activated). In either case, the
1637 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1638 * be released and the new_ndlp shall be put on to the vport node list and
1639 * its pointer returned as the confirmed node.
1641 * Note that before the @ndlp got "released", the keepDID from not-matching
1642 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1643 * of the @ndlp. This is because the release of @ndlp is actually to put it
1644 * into an inactive state on the vport node list and the vport node list
1645 * management algorithm does not allow two node with a same DID.
1648 * pointer to the PLOGI N_Port @ndlp
1650 static struct lpfc_nodelist *
1651 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1652 struct lpfc_nodelist *ndlp)
1654 struct lpfc_vport *vport = ndlp->vport;
1655 struct lpfc_nodelist *new_ndlp;
1656 struct serv_parm *sp;
1657 uint8_t name[sizeof(struct lpfc_name)];
1658 uint32_t keepDID = 0, keep_nlp_flag = 0;
1659 uint32_t keep_new_nlp_flag = 0;
1660 uint16_t keep_nlp_state;
1661 u32 keep_nlp_fc4_type = 0;
1662 struct lpfc_nvme_rport *keep_nrport = NULL;
1663 unsigned long *active_rrqs_xri_bitmap = NULL;
1665 /* Fabric nodes can have the same WWPN so we don't bother searching
1666 * by WWPN. Just return the ndlp that was given to us.
1668 if (ndlp->nlp_type & NLP_FABRIC)
1671 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1672 memset(name, 0, sizeof(struct lpfc_name));
1674 /* Now we find out if the NPort we are logging into, matches the WWPN
1675 * we have for that ndlp. If not, we have some work to do.
1677 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1679 /* return immediately if the WWPN matches ndlp */
1680 if (!new_ndlp || (new_ndlp == ndlp))
1684 * Unregister from backend if not done yet. Could have been skipped
1687 lpfc_nlp_unreg_node(vport, new_ndlp);
1689 if (phba->sli_rev == LPFC_SLI_REV4) {
1690 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1692 if (active_rrqs_xri_bitmap)
1693 memset(active_rrqs_xri_bitmap, 0,
1694 phba->cfg_rrq_xri_bitmap_sz);
1697 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1698 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1699 "new_ndlp x%x x%x x%x\n",
1700 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1701 (new_ndlp ? new_ndlp->nlp_DID : 0),
1702 (new_ndlp ? new_ndlp->nlp_flag : 0),
1703 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1705 keepDID = new_ndlp->nlp_DID;
1707 if (phba->sli_rev == LPFC_SLI_REV4 && active_rrqs_xri_bitmap)
1708 memcpy(active_rrqs_xri_bitmap, new_ndlp->active_rrqs_xri_bitmap,
1709 phba->cfg_rrq_xri_bitmap_sz);
1711 /* At this point in this routine, we know new_ndlp will be
1712 * returned. however, any previous GID_FTs that were done
1713 * would have updated nlp_fc4_type in ndlp, so we must ensure
1714 * new_ndlp has the right value.
1716 if (vport->fc_flag & FC_FABRIC) {
1717 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1718 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1721 lpfc_unreg_rpi(vport, new_ndlp);
1722 new_ndlp->nlp_DID = ndlp->nlp_DID;
1723 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1724 if (phba->sli_rev == LPFC_SLI_REV4)
1725 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1726 ndlp->active_rrqs_xri_bitmap,
1727 phba->cfg_rrq_xri_bitmap_sz);
1729 /* Lock both ndlps */
1730 spin_lock_irq(&ndlp->lock);
1731 spin_lock_irq(&new_ndlp->lock);
1732 keep_new_nlp_flag = new_ndlp->nlp_flag;
1733 keep_nlp_flag = ndlp->nlp_flag;
1734 new_ndlp->nlp_flag = ndlp->nlp_flag;
1736 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1737 if (keep_new_nlp_flag & NLP_UNREG_INP)
1738 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1740 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1742 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1743 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1744 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1746 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1749 * Retain the DROPPED flag. This will take care of the init
1750 * refcount when affecting the state change
1752 if (keep_new_nlp_flag & NLP_DROPPED)
1753 new_ndlp->nlp_flag |= NLP_DROPPED;
1755 new_ndlp->nlp_flag &= ~NLP_DROPPED;
1757 ndlp->nlp_flag = keep_new_nlp_flag;
1759 /* if ndlp had NLP_UNREG_INP set, keep it */
1760 if (keep_nlp_flag & NLP_UNREG_INP)
1761 ndlp->nlp_flag |= NLP_UNREG_INP;
1763 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1765 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1766 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1767 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1769 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1772 * Retain the DROPPED flag. This will take care of the init
1773 * refcount when affecting the state change
1775 if (keep_nlp_flag & NLP_DROPPED)
1776 ndlp->nlp_flag |= NLP_DROPPED;
1778 ndlp->nlp_flag &= ~NLP_DROPPED;
1780 spin_unlock_irq(&new_ndlp->lock);
1781 spin_unlock_irq(&ndlp->lock);
1783 /* Set nlp_states accordingly */
1784 keep_nlp_state = new_ndlp->nlp_state;
1785 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1787 /* interchange the nvme remoteport structs */
1788 keep_nrport = new_ndlp->nrport;
1789 new_ndlp->nrport = ndlp->nrport;
1791 /* Move this back to NPR state */
1792 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1793 /* The new_ndlp is replacing ndlp totally, so we need
1794 * to put ndlp on UNUSED list and try to free it.
1796 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1797 "3179 PLOGI confirm NEW: %x %x\n",
1798 new_ndlp->nlp_DID, keepDID);
1800 /* Two ndlps cannot have the same did on the nodelist.
1801 * Note: for this case, ndlp has a NULL WWPN so setting
1802 * the nlp_fc4_type isn't required.
1804 ndlp->nlp_DID = keepDID;
1805 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1806 if (phba->sli_rev == LPFC_SLI_REV4 &&
1807 active_rrqs_xri_bitmap)
1808 memcpy(ndlp->active_rrqs_xri_bitmap,
1809 active_rrqs_xri_bitmap,
1810 phba->cfg_rrq_xri_bitmap_sz);
1813 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1814 "3180 PLOGI confirm SWAP: %x %x\n",
1815 new_ndlp->nlp_DID, keepDID);
1817 lpfc_unreg_rpi(vport, ndlp);
1819 /* Two ndlps cannot have the same did and the fc4
1820 * type must be transferred because the ndlp is in
1823 ndlp->nlp_DID = keepDID;
1824 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1826 if (phba->sli_rev == LPFC_SLI_REV4 &&
1827 active_rrqs_xri_bitmap)
1828 memcpy(ndlp->active_rrqs_xri_bitmap,
1829 active_rrqs_xri_bitmap,
1830 phba->cfg_rrq_xri_bitmap_sz);
1832 /* Since we are switching over to the new_ndlp,
1833 * reset the old ndlp state
1835 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1836 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1837 keep_nlp_state = NLP_STE_NPR_NODE;
1838 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1839 ndlp->nrport = keep_nrport;
1843 * If ndlp is not associated with any rport we can drop it here else
1844 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1846 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1847 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1849 if (phba->sli_rev == LPFC_SLI_REV4 &&
1850 active_rrqs_xri_bitmap)
1851 mempool_free(active_rrqs_xri_bitmap,
1852 phba->active_rrq_pool);
1854 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1855 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1856 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1857 new_ndlp->nlp_fc4_type);
1863 * lpfc_end_rscn - Check and handle more rscn for a vport
1864 * @vport: pointer to a host virtual N_Port data structure.
1866 * This routine checks whether more Registration State Change
1867 * Notifications (RSCNs) came in while the discovery state machine was in
1868 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1869 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1870 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1871 * handling the RSCNs.
1874 lpfc_end_rscn(struct lpfc_vport *vport)
1876 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1878 if (vport->fc_flag & FC_RSCN_MODE) {
1880 * Check to see if more RSCNs came in while we were
1881 * processing this one.
1883 if (vport->fc_rscn_id_cnt ||
1884 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1885 lpfc_els_handle_rscn(vport);
1887 spin_lock_irq(shost->host_lock);
1888 vport->fc_flag &= ~FC_RSCN_MODE;
1889 vport->fc_flag |= FC_RSCN_MEMENTO;
1890 spin_unlock_irq(shost->host_lock);
1896 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1897 * @phba: pointer to lpfc hba data structure.
1898 * @cmdiocb: pointer to lpfc command iocb data structure.
1899 * @rspiocb: pointer to lpfc response iocb data structure.
1901 * This routine will call the clear rrq function to free the rrq and
1902 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1903 * exist then the clear_rrq is still called because the rrq needs to
1908 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1909 struct lpfc_iocbq *rspiocb)
1911 struct lpfc_vport *vport = cmdiocb->vport;
1912 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
1913 struct lpfc_node_rrq *rrq;
1914 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
1915 u32 ulp_word4 = get_job_word4(phba, rspiocb);
1917 /* we pass cmdiocb to state machine which needs rspiocb as well */
1918 rrq = cmdiocb->context_un.rrq;
1919 cmdiocb->rsp_iocb = rspiocb;
1921 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1922 "RRQ cmpl: status:x%x/x%x did:x%x",
1923 ulp_status, ulp_word4,
1924 get_job_els_rsp64_did(phba, cmdiocb));
1927 /* rrq completes to NPort <nlp_DID> */
1928 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1929 "2880 RRQ completes to DID x%x "
1930 "Data: x%x x%x x%x x%x x%x\n",
1931 ndlp->nlp_DID, ulp_status, ulp_word4,
1932 get_wqe_tmo(cmdiocb), rrq->xritag, rrq->rxid);
1935 /* Check for retry */
1936 /* RRQ failed Don't print the vport to vport rjts */
1937 if (ulp_status != IOSTAT_LS_RJT ||
1938 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
1939 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
1940 (phba)->pport->cfg_log_verbose & LOG_ELS)
1941 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1942 "2881 RRQ failure DID:%06X Status:"
1944 ndlp->nlp_DID, ulp_status,
1948 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1949 lpfc_els_free_iocb(phba, cmdiocb);
1954 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1955 * @phba: pointer to lpfc hba data structure.
1956 * @cmdiocb: pointer to lpfc command iocb data structure.
1957 * @rspiocb: pointer to lpfc response iocb data structure.
1959 * This routine is the completion callback function for issuing the Port
1960 * Login (PLOGI) command. For PLOGI completion, there must be an active
1961 * ndlp on the vport node list that matches the remote node ID from the
1962 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1963 * ignored and command IOCB released. The PLOGI response IOCB status is
1964 * checked for error conditions. If there is error status reported, PLOGI
1965 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1966 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1967 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1968 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1969 * there are additional N_Port nodes with the vport that need to perform
1970 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1974 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1975 struct lpfc_iocbq *rspiocb)
1977 struct lpfc_vport *vport = cmdiocb->vport;
1978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1980 struct lpfc_nodelist *ndlp, *free_ndlp;
1981 struct lpfc_dmabuf *prsp;
1983 struct serv_parm *sp = NULL;
1984 u32 ulp_status, ulp_word4, did, iotag;
1985 bool release_node = false;
1987 /* we pass cmdiocb to state machine which needs rspiocb as well */
1988 cmdiocb->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);
2075 /* No PLOGI collision and the node is not registered with the
2076 * scsi or nvme transport. It is no longer an active node. Just
2077 * start the device remove process.
2079 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2080 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2081 if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
2082 release_node = true;
2084 spin_unlock_irq(&ndlp->lock);
2087 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2090 /* Good status, call state machine */
2091 prsp = list_entry(cmdiocb->cmd_dmabuf->list.next,
2092 struct lpfc_dmabuf, list);
2093 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2095 sp = (struct serv_parm *)((u8 *)prsp->virt +
2098 ndlp->vmid_support = 0;
2099 if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) ||
2100 (phba->cfg_vmid_priority_tagging &&
2101 sp->cmn.priority_tagging)) {
2102 lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS,
2103 "4018 app_hdr_support %d tagging %d DID x%x\n",
2104 sp->cmn.app_hdr_support,
2105 sp->cmn.priority_tagging,
2107 /* if the dest port supports VMID, mark it in ndlp */
2108 ndlp->vmid_support = 1;
2111 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2112 NLP_EVT_CMPL_PLOGI);
2115 if (disc && vport->num_disc_nodes) {
2116 /* Check to see if there are more PLOGIs to be sent */
2117 lpfc_more_plogi(vport);
2119 if (vport->num_disc_nodes == 0) {
2120 spin_lock_irq(shost->host_lock);
2121 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2122 spin_unlock_irq(shost->host_lock);
2124 lpfc_can_disctmo(vport);
2125 lpfc_end_rscn(vport);
2130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2131 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2132 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2135 /* Release the reference on the original I/O request. */
2136 free_ndlp = cmdiocb->ndlp;
2138 lpfc_els_free_iocb(phba, cmdiocb);
2139 lpfc_nlp_put(free_ndlp);
2144 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2145 * @vport: pointer to a host virtual N_Port data structure.
2146 * @did: destination port identifier.
2147 * @retry: number of retries to the command IOCB.
2149 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2150 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2151 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2152 * This routine constructs the proper fields of the PLOGI IOCB and invokes
2153 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2155 * Note that the ndlp reference count will be incremented by 1 for holding
2156 * the ndlp and the reference to ndlp will be stored into the ndlp field
2157 * of the IOCB for the completion callback function to the PLOGI ELS command.
2160 * 0 - Successfully issued a plogi for @vport
2161 * 1 - failed to issue a plogi for @vport
2164 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2166 struct lpfc_hba *phba = vport->phba;
2167 struct serv_parm *sp;
2168 struct lpfc_nodelist *ndlp;
2169 struct lpfc_iocbq *elsiocb;
2174 ndlp = lpfc_findnode_did(vport, did);
2178 /* Defer the processing of the issue PLOGI until after the
2179 * outstanding UNREG_RPI mbox command completes, unless we
2180 * are going offline. This logic does not apply for Fabric DIDs
2182 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2183 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2184 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2185 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2186 "4110 Issue PLOGI x%x deferred "
2187 "on NPort x%x rpi x%x Data: x%px\n",
2188 ndlp->nlp_defer_did, ndlp->nlp_DID,
2189 ndlp->nlp_rpi, ndlp);
2191 /* We can only defer 1st PLOGI */
2192 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2193 ndlp->nlp_defer_did = did;
2197 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2198 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2203 spin_lock_irq(&ndlp->lock);
2204 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2205 spin_unlock_irq(&ndlp->lock);
2207 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2209 /* For PLOGI request, remainder of payload is service parameters */
2210 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2211 pcmd += sizeof(uint32_t);
2212 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2213 sp = (struct serv_parm *) pcmd;
2216 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2217 * to device on remote loops work.
2219 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2220 sp->cmn.altBbCredit = 1;
2222 if (sp->cmn.fcphLow < FC_PH_4_3)
2223 sp->cmn.fcphLow = FC_PH_4_3;
2225 if (sp->cmn.fcphHigh < FC_PH3)
2226 sp->cmn.fcphHigh = FC_PH3;
2228 sp->cmn.valid_vendor_ver_level = 0;
2229 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2230 sp->cmn.bbRcvSizeMsb &= 0xF;
2232 /* Check if the destination port supports VMID */
2233 ndlp->vmid_support = 0;
2234 if (vport->vmid_priority_tagging)
2235 sp->cmn.priority_tagging = 1;
2236 else if (phba->cfg_vmid_app_header &&
2237 bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags))
2238 sp->cmn.app_hdr_support = 1;
2240 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2241 "Issue PLOGI: did:x%x",
2244 /* If our firmware supports this feature, convey that
2245 * information to the target using the vendor specific field.
2247 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2248 sp->cmn.valid_vendor_ver_level = 1;
2249 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2250 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2253 phba->fc_stat.elsXmitPLOGI++;
2254 elsiocb->cmd_cmpl = lpfc_cmpl_els_plogi;
2256 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2257 "Issue PLOGI: did:x%x refcnt %d",
2258 did, kref_read(&ndlp->kref), 0);
2259 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2260 if (!elsiocb->ndlp) {
2261 lpfc_els_free_iocb(phba, elsiocb);
2265 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2267 lpfc_els_free_iocb(phba, elsiocb);
2276 * lpfc_cmpl_els_prli - Completion callback function for prli
2277 * @phba: pointer to lpfc hba data structure.
2278 * @cmdiocb: pointer to lpfc command iocb data structure.
2279 * @rspiocb: pointer to lpfc response iocb data structure.
2281 * This routine is the completion callback function for a Process Login
2282 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2283 * status. If there is error status reported, PRLI retry shall be attempted
2284 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2285 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2286 * ndlp to mark the PRLI completion.
2289 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2290 struct lpfc_iocbq *rspiocb)
2292 struct lpfc_vport *vport = cmdiocb->vport;
2293 struct lpfc_nodelist *ndlp;
2298 bool release_node = false;
2300 /* we pass cmdiocb to state machine which needs rspiocb as well */
2301 cmdiocb->rsp_iocb = rspiocb;
2303 ndlp = cmdiocb->ndlp;
2305 ulp_status = get_job_ulpstatus(phba, rspiocb);
2306 ulp_word4 = get_job_word4(phba, rspiocb);
2308 spin_lock_irq(&ndlp->lock);
2309 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2311 /* Driver supports multiple FC4 types. Counters matter. */
2312 vport->fc_prli_sent--;
2313 ndlp->fc4_prli_sent--;
2314 spin_unlock_irq(&ndlp->lock);
2316 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2317 "PRLI cmpl: status:x%x/x%x did:x%x",
2318 ulp_status, ulp_word4,
2321 /* PRLI completes to NPort <nlp_DID> */
2322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2323 "0103 PRLI completes to NPort x%06x "
2324 "Data: x%x x%x x%x x%x\n",
2325 ndlp->nlp_DID, ulp_status, ulp_word4,
2326 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2328 /* Check to see if link went down during discovery */
2329 if (lpfc_els_chk_latt(vport))
2333 /* Check for retry */
2334 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2335 /* ELS command is being retried */
2339 /* If we don't send GFT_ID to Fabric, a PRLI error
2340 * could be expected.
2342 if ((vport->fc_flag & FC_FABRIC) ||
2343 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2345 loglevel = LOG_TRACE_EVENT;
2352 lpfc_printf_vlog(vport, mode, loglevel,
2353 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2355 ndlp->nlp_DID, ulp_status,
2356 ulp_word4, ndlp->fc4_prli_sent);
2358 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2359 if (!lpfc_error_lost_link(ulp_status, ulp_word4))
2360 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2364 * For P2P topology, retain the node so that PLOGI can be
2365 * attempted on it again.
2367 if (vport->fc_flag & FC_PT2PT)
2370 /* As long as this node is not registered with the SCSI
2371 * or NVMe transport and no other PRLIs are outstanding,
2372 * it is no longer an active node. Otherwise devloss
2373 * handles the final cleanup.
2375 spin_lock_irq(&ndlp->lock);
2376 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2377 !ndlp->fc4_prli_sent) {
2378 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2379 if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
2380 release_node = true;
2382 spin_unlock_irq(&ndlp->lock);
2385 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2388 /* Good status, call state machine. However, if another
2389 * PRLI is outstanding, don't call the state machine
2390 * because final disposition to Mapped or Unmapped is
2393 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2398 lpfc_els_free_iocb(phba, cmdiocb);
2404 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2405 * @vport: pointer to a host virtual N_Port data structure.
2406 * @ndlp: pointer to a node-list data structure.
2407 * @retry: number of retries to the command IOCB.
2409 * This routine issues a Process Login (PRLI) ELS command for the
2410 * @vport. The PRLI service parameters are set up in the payload of the
2411 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2412 * is put to the IOCB completion callback func field before invoking the
2413 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2415 * Note that the ndlp reference count will be incremented by 1 for holding the
2416 * ndlp and the reference to ndlp will be stored into the ndlp field of
2417 * the IOCB for the completion callback function to the PRLI ELS command.
2420 * 0 - successfully issued prli iocb command for @vport
2421 * 1 - failed to issue prli iocb command for @vport
2424 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2428 struct lpfc_hba *phba = vport->phba;
2430 struct lpfc_nvme_prli *npr_nvme;
2431 struct lpfc_iocbq *elsiocb;
2434 u32 local_nlp_type, elscmd;
2437 * If discovery was kicked off from RSCN mode,
2438 * the FC4 types supported from a
2439 * previous GFT_ID command may not be accurate. So, if we
2440 * are a NVME Initiator, always look for the possibility of
2441 * the remote NPort beng a NVME Target.
2443 if (phba->sli_rev == LPFC_SLI_REV4 &&
2444 vport->fc_flag & (FC_RSCN_MODE | FC_RSCN_MEMENTO) &&
2445 vport->nvmei_support)
2446 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2447 local_nlp_type = ndlp->nlp_fc4_type;
2449 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2450 * fields here before any of them can complete.
2452 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2453 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2454 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2455 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2456 ndlp->nvme_fb_size = 0;
2459 if (local_nlp_type & NLP_FC4_FCP) {
2460 /* Payload is 4 + 16 = 20 x14 bytes. */
2461 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2462 elscmd = ELS_CMD_PRLI;
2463 } else if (local_nlp_type & NLP_FC4_NVME) {
2464 /* Payload is 4 + 20 = 24 x18 bytes. */
2465 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2466 elscmd = ELS_CMD_NVMEPRLI;
2468 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2469 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2470 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2474 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2475 * FC4 type, implicitly LOGO.
2477 if (phba->sli_rev == LPFC_SLI_REV3 &&
2478 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2479 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2480 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2482 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2486 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2487 ndlp->nlp_DID, elscmd);
2491 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2493 /* For PRLI request, remainder of payload is service parameters */
2494 memset(pcmd, 0, cmdsize);
2496 if (local_nlp_type & NLP_FC4_FCP) {
2497 /* Remainder of payload is FCP PRLI parameter page.
2498 * Note: this data structure is defined as
2499 * BE/LE in the structure definition so no
2500 * byte swap call is made.
2502 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2503 pcmd += sizeof(uint32_t);
2507 * If our firmware version is 3.20 or later,
2508 * set the following bits for FC-TAPE support.
2510 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2511 npr->ConfmComplAllowed = 1;
2513 npr->TaskRetryIdReq = 1;
2515 npr->estabImagePair = 1;
2516 npr->readXferRdyDis = 1;
2517 if (vport->cfg_first_burst_size)
2518 npr->writeXferRdyDis = 1;
2520 /* For FCP support */
2521 npr->prliType = PRLI_FCP_TYPE;
2522 npr->initiatorFunc = 1;
2523 elsiocb->cmd_flag |= LPFC_PRLI_FCP_REQ;
2525 /* Remove FCP type - processed. */
2526 local_nlp_type &= ~NLP_FC4_FCP;
2527 } else if (local_nlp_type & NLP_FC4_NVME) {
2528 /* Remainder of payload is NVME PRLI parameter page.
2529 * This data structure is the newer definition that
2530 * uses bf macros so a byte swap is required.
2532 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2533 pcmd += sizeof(uint32_t);
2534 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2535 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2536 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2538 bf_set(prli_nsler, npr_nvme, 1);
2539 bf_set(prli_conf, npr_nvme, 1);
2542 /* Only initiators request first burst. */
2543 if ((phba->cfg_nvme_enable_fb) &&
2544 !phba->nvmet_support)
2545 bf_set(prli_fba, npr_nvme, 1);
2547 if (phba->nvmet_support) {
2548 bf_set(prli_tgt, npr_nvme, 1);
2549 bf_set(prli_disc, npr_nvme, 1);
2551 bf_set(prli_init, npr_nvme, 1);
2552 bf_set(prli_conf, npr_nvme, 1);
2555 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2556 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2557 elsiocb->cmd_flag |= LPFC_PRLI_NVME_REQ;
2559 /* Remove NVME type - processed. */
2560 local_nlp_type &= ~NLP_FC4_NVME;
2563 phba->fc_stat.elsXmitPRLI++;
2564 elsiocb->cmd_cmpl = lpfc_cmpl_els_prli;
2566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2567 "Issue PRLI: did:x%x refcnt %d",
2568 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2569 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2570 if (!elsiocb->ndlp) {
2571 lpfc_els_free_iocb(phba, elsiocb);
2575 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2576 if (rc == IOCB_ERROR) {
2577 lpfc_els_free_iocb(phba, elsiocb);
2582 /* The vport counters are used for lpfc_scan_finished, but
2583 * the ndlp is used to track outstanding PRLIs for different
2586 spin_lock_irq(&ndlp->lock);
2587 ndlp->nlp_flag |= NLP_PRLI_SND;
2588 vport->fc_prli_sent++;
2589 ndlp->fc4_prli_sent++;
2590 spin_unlock_irq(&ndlp->lock);
2592 /* The driver supports 2 FC4 types. Make sure
2593 * a PRLI is issued for all types before exiting.
2595 if (phba->sli_rev == LPFC_SLI_REV4 &&
2596 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2597 goto send_next_prli;
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;
2752 bool release_node = false;
2754 /* we pass cmdiocb to state machine which needs rspiocb as well */
2755 cmdiocb->rsp_iocb = rspiocb;
2757 ndlp = cmdiocb->ndlp;
2759 ulp_status = get_job_ulpstatus(phba, rspiocb);
2760 ulp_word4 = get_job_word4(phba, rspiocb);
2762 if (phba->sli_rev == LPFC_SLI_REV4) {
2763 tmo = get_wqe_tmo(cmdiocb);
2765 irsp = &rspiocb->iocb;
2766 tmo = irsp->ulpTimeout;
2769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2770 "ADISC cmpl: status:x%x/x%x did:x%x",
2771 ulp_status, ulp_word4,
2774 /* Since ndlp can be freed in the disc state machine, note if this node
2775 * is being used during discovery.
2777 spin_lock_irq(&ndlp->lock);
2778 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2779 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2780 spin_unlock_irq(&ndlp->lock);
2781 /* ADISC completes to NPort <nlp_DID> */
2782 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2783 "0104 ADISC completes to NPort x%x "
2784 "Data: x%x x%x x%x x%x x%x\n",
2785 ndlp->nlp_DID, ulp_status, ulp_word4,
2786 tmo, disc, vport->num_disc_nodes);
2787 /* Check to see if link went down during discovery */
2788 if (lpfc_els_chk_latt(vport)) {
2789 spin_lock_irq(&ndlp->lock);
2790 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2791 spin_unlock_irq(&ndlp->lock);
2796 /* Check for retry */
2797 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2798 /* ELS command is being retried */
2800 spin_lock_irq(&ndlp->lock);
2801 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2802 spin_unlock_irq(&ndlp->lock);
2803 lpfc_set_disctmo(vport);
2808 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2809 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2810 ndlp->nlp_DID, ulp_status,
2812 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2813 NLP_EVT_CMPL_ADISC);
2815 /* As long as this node is not registered with the SCSI or NVMe
2816 * transport, it is no longer an active node. Otherwise
2817 * devloss handles the final cleanup.
2819 spin_lock_irq(&ndlp->lock);
2820 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2821 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2822 if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
2823 release_node = true;
2825 spin_unlock_irq(&ndlp->lock);
2828 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2831 /* Good status, call state machine */
2832 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2833 NLP_EVT_CMPL_ADISC);
2835 /* Check to see if there are more ADISCs to be sent */
2836 if (disc && vport->num_disc_nodes)
2837 lpfc_more_adisc(vport);
2839 lpfc_els_free_iocb(phba, cmdiocb);
2845 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2846 * @vport: pointer to a virtual N_Port data structure.
2847 * @ndlp: pointer to a node-list data structure.
2848 * @retry: number of retries to the command IOCB.
2850 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2851 * @vport. It prepares the payload of the ADISC ELS command, updates the
2852 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2853 * to issue the ADISC ELS command.
2855 * Note that the ndlp reference count will be incremented by 1 for holding the
2856 * ndlp and the reference to ndlp will be stored into the ndlp field of
2857 * the IOCB for the completion callback function to the ADISC ELS command.
2860 * 0 - successfully issued adisc
2861 * 1 - failed to issue adisc
2864 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2868 struct lpfc_hba *phba = vport->phba;
2870 struct lpfc_iocbq *elsiocb;
2874 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2875 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2876 ndlp->nlp_DID, ELS_CMD_ADISC);
2880 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2882 /* For ADISC request, remainder of payload is service parameters */
2883 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2884 pcmd += sizeof(uint32_t);
2886 /* Fill in ADISC payload */
2887 ap = (ADISC *) pcmd;
2888 ap->hardAL_PA = phba->fc_pref_ALPA;
2889 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2890 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2891 ap->DID = be32_to_cpu(vport->fc_myDID);
2893 phba->fc_stat.elsXmitADISC++;
2894 elsiocb->cmd_cmpl = lpfc_cmpl_els_adisc;
2895 spin_lock_irq(&ndlp->lock);
2896 ndlp->nlp_flag |= NLP_ADISC_SND;
2897 spin_unlock_irq(&ndlp->lock);
2898 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2899 if (!elsiocb->ndlp) {
2900 lpfc_els_free_iocb(phba, elsiocb);
2904 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2905 "Issue ADISC: did:x%x refcnt %d",
2906 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2908 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2909 if (rc == IOCB_ERROR) {
2910 lpfc_els_free_iocb(phba, elsiocb);
2918 spin_lock_irq(&ndlp->lock);
2919 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2920 spin_unlock_irq(&ndlp->lock);
2925 * lpfc_cmpl_els_logo - Completion callback function for logo
2926 * @phba: pointer to lpfc hba data structure.
2927 * @cmdiocb: pointer to lpfc command iocb data structure.
2928 * @rspiocb: pointer to lpfc response iocb data structure.
2930 * This routine is the completion function for issuing the ELS Logout (LOGO)
2931 * command. If no error status was reported from the LOGO response, the
2932 * state machine of the associated ndlp shall be invoked for transition with
2933 * respect to NLP_EVT_CMPL_LOGO event.
2936 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2937 struct lpfc_iocbq *rspiocb)
2939 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
2940 struct lpfc_vport *vport = ndlp->vport;
2942 unsigned long flags;
2943 uint32_t skip_recovery = 0;
2944 int wake_up_waiter = 0;
2949 /* we pass cmdiocb to state machine which needs rspiocb as well */
2950 cmdiocb->rsp_iocb = rspiocb;
2952 ulp_status = get_job_ulpstatus(phba, rspiocb);
2953 ulp_word4 = get_job_word4(phba, rspiocb);
2955 if (phba->sli_rev == LPFC_SLI_REV4) {
2956 tmo = get_wqe_tmo(cmdiocb);
2958 irsp = &rspiocb->iocb;
2959 tmo = irsp->ulpTimeout;
2962 spin_lock_irq(&ndlp->lock);
2963 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2964 if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
2966 ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
2968 spin_unlock_irq(&ndlp->lock);
2970 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2971 "LOGO cmpl: status:x%x/x%x did:x%x",
2972 ulp_status, ulp_word4,
2975 /* LOGO completes to NPort <nlp_DID> */
2976 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2977 "0105 LOGO completes to NPort x%x "
2978 "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
2979 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
2980 ulp_status, ulp_word4,
2981 tmo, vport->num_disc_nodes);
2983 if (lpfc_els_chk_latt(vport)) {
2988 /* The LOGO will not be retried on failure. A LOGO was
2989 * issued to the remote rport and a ACC or RJT or no Answer are
2990 * all acceptable. Note the failure and move forward with
2991 * discovery. The PLOGI will retry.
2995 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2996 "2756 LOGO failure, No Retry DID:%06X "
2998 ndlp->nlp_DID, ulp_status,
3001 /* Call NLP_EVT_DEVICE_RM if link is down or LOGO is aborted */
3002 if (lpfc_error_lost_link(ulp_status, ulp_word4)) {
3003 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3010 /* Call state machine. This will unregister the rpi if needed. */
3011 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
3013 /* The driver sets this flag for an NPIV instance that doesn't want to
3014 * log into the remote port.
3016 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
3017 spin_lock_irq(&ndlp->lock);
3018 if (phba->sli_rev == LPFC_SLI_REV4)
3019 ndlp->nlp_flag |= NLP_RELEASE_RPI;
3020 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3021 spin_unlock_irq(&ndlp->lock);
3022 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3024 lpfc_els_free_iocb(phba, cmdiocb);
3027 /* Presume the node was released. */
3032 /* Driver is done with the IO. */
3033 lpfc_els_free_iocb(phba, cmdiocb);
3036 /* At this point, the LOGO processing is complete. NOTE: For a
3037 * pt2pt topology, we are assuming the NPortID will only change
3038 * on link up processing. For a LOGO / PLOGI initiated by the
3039 * Initiator, we are assuming the NPortID is not going to change.
3042 if (wake_up_waiter && ndlp->logo_waitq)
3043 wake_up(ndlp->logo_waitq);
3045 * If the node is a target, the handling attempts to recover the port.
3046 * For any other port type, the rpi is unregistered as an implicit
3049 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
3050 skip_recovery == 0) {
3051 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3052 spin_lock_irqsave(&ndlp->lock, flags);
3053 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
3054 spin_unlock_irqrestore(&ndlp->lock, flags);
3056 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3057 "3187 LOGO completes to NPort x%x: Start "
3058 "Recovery Data: x%x x%x x%x x%x\n",
3059 ndlp->nlp_DID, ulp_status,
3061 vport->num_disc_nodes);
3062 lpfc_disc_start(vport);
3066 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
3067 * driver sends a LOGO to the rport to cleanup. For fabric and
3068 * initiator ports cleanup the node as long as it the node is not
3069 * register with the transport.
3071 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
3072 spin_lock_irq(&ndlp->lock);
3073 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3074 spin_unlock_irq(&ndlp->lock);
3075 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3081 * lpfc_issue_els_logo - Issue a logo to an node on a vport
3082 * @vport: pointer to a virtual N_Port data structure.
3083 * @ndlp: pointer to a node-list data structure.
3084 * @retry: number of retries to the command IOCB.
3086 * This routine constructs and issues an ELS Logout (LOGO) iocb command
3087 * to a remote node, referred by an @ndlp on a @vport. It constructs the
3088 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
3089 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
3091 * Note that the ndlp reference count will be incremented by 1 for holding the
3092 * ndlp and the reference to ndlp will be stored into the ndlp field of
3093 * the IOCB for the completion callback function to the LOGO ELS command.
3095 * Callers of this routine are expected to unregister the RPI first
3098 * 0 - successfully issued logo
3099 * 1 - failed to issue logo
3102 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3105 struct lpfc_hba *phba = vport->phba;
3106 struct lpfc_iocbq *elsiocb;
3111 spin_lock_irq(&ndlp->lock);
3112 if (ndlp->nlp_flag & NLP_LOGO_SND) {
3113 spin_unlock_irq(&ndlp->lock);
3116 spin_unlock_irq(&ndlp->lock);
3118 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
3119 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3120 ndlp->nlp_DID, ELS_CMD_LOGO);
3124 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
3125 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
3126 pcmd += sizeof(uint32_t);
3128 /* Fill in LOGO payload */
3129 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
3130 pcmd += sizeof(uint32_t);
3131 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
3133 phba->fc_stat.elsXmitLOGO++;
3134 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo;
3135 spin_lock_irq(&ndlp->lock);
3136 ndlp->nlp_flag |= NLP_LOGO_SND;
3137 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
3138 spin_unlock_irq(&ndlp->lock);
3139 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3140 if (!elsiocb->ndlp) {
3141 lpfc_els_free_iocb(phba, elsiocb);
3145 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3146 "Issue LOGO: did:x%x refcnt %d",
3147 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3149 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3150 if (rc == IOCB_ERROR) {
3151 lpfc_els_free_iocb(phba, elsiocb);
3156 spin_lock_irq(&ndlp->lock);
3157 ndlp->nlp_prev_state = ndlp->nlp_state;
3158 spin_unlock_irq(&ndlp->lock);
3159 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3163 spin_lock_irq(&ndlp->lock);
3164 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3165 spin_unlock_irq(&ndlp->lock);
3170 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3171 * @phba: pointer to lpfc hba data structure.
3172 * @cmdiocb: pointer to lpfc command iocb data structure.
3173 * @rspiocb: pointer to lpfc response iocb data structure.
3175 * This routine is a generic completion callback function for ELS commands.
3176 * Specifically, it is the callback function which does not need to perform
3177 * any command specific operations. It is currently used by the ELS command
3178 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3179 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3180 * Other than certain debug loggings, this callback function simply invokes the
3181 * lpfc_els_chk_latt() routine to check whether link went down during the
3182 * discovery process.
3185 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3186 struct lpfc_iocbq *rspiocb)
3188 struct lpfc_vport *vport = cmdiocb->vport;
3189 struct lpfc_nodelist *free_ndlp;
3191 u32 ulp_status, ulp_word4, tmo, did, iotag;
3193 ulp_status = get_job_ulpstatus(phba, rspiocb);
3194 ulp_word4 = get_job_word4(phba, rspiocb);
3195 did = get_job_els_rsp64_did(phba, cmdiocb);
3197 if (phba->sli_rev == LPFC_SLI_REV4) {
3198 tmo = get_wqe_tmo(cmdiocb);
3199 iotag = get_wqe_reqtag(cmdiocb);
3201 irsp = &rspiocb->iocb;
3202 tmo = irsp->ulpTimeout;
3203 iotag = irsp->ulpIoTag;
3206 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3207 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3208 ulp_status, ulp_word4, did);
3210 /* ELS cmd tag <ulpIoTag> completes */
3211 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3212 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3213 iotag, ulp_status, ulp_word4, tmo);
3215 /* Check to see if link went down during discovery */
3216 lpfc_els_chk_latt(vport);
3218 free_ndlp = cmdiocb->ndlp;
3220 lpfc_els_free_iocb(phba, cmdiocb);
3221 lpfc_nlp_put(free_ndlp);
3225 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
3226 * @vport: pointer to lpfc_vport data structure.
3227 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
3229 * This routine registers the rpi assigned to the fabric controller
3230 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
3231 * state triggering a registration with the SCSI transport.
3233 * This routine is single out because the fabric controller node
3234 * does not receive a PLOGI. This routine is consumed by the
3235 * SCR and RDF ELS commands. Callers are expected to qualify
3239 lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp)
3242 struct lpfc_hba *phba = vport->phba;
3243 struct lpfc_nodelist *ns_ndlp;
3246 if (fc_ndlp->nlp_flag & NLP_RPI_REGISTERED)
3249 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
3253 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3254 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
3255 __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID,
3256 ns_ndlp->nlp_state);
3257 if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3260 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3262 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3263 "0936 %s: no memory for reg_login "
3264 "Data: x%x x%x x%x x%x\n", __func__,
3265 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3266 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3269 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID,
3270 (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi);
3276 fc_ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3277 mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login;
3278 mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp);
3279 if (!mbox->ctx_ndlp) {
3284 mbox->vport = vport;
3285 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3286 if (rc == MBX_NOT_FINISHED) {
3288 lpfc_nlp_put(fc_ndlp);
3291 /* Success path. Exit. */
3292 lpfc_nlp_set_state(vport, fc_ndlp,
3293 NLP_STE_REG_LOGIN_ISSUE);
3297 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
3298 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3299 "0938 %s: failed to format reg_login "
3300 "Data: x%x x%x x%x x%x\n", __func__,
3301 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3302 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3307 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3308 * @phba: pointer to lpfc hba data structure.
3309 * @cmdiocb: pointer to lpfc command iocb data structure.
3310 * @rspiocb: pointer to lpfc response iocb data structure.
3312 * This routine is a generic completion callback function for Discovery ELS cmd.
3313 * Currently used by the ELS command issuing routines for the ELS State Change
3314 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3315 * These commands will be retried once only for ELS timeout errors.
3318 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3319 struct lpfc_iocbq *rspiocb)
3321 struct lpfc_vport *vport = cmdiocb->vport;
3323 struct lpfc_els_rdf_rsp *prdf;
3324 struct lpfc_dmabuf *pcmd, *prsp;
3327 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
3328 u32 ulp_status, ulp_word4, tmo, did, iotag;
3330 ulp_status = get_job_ulpstatus(phba, rspiocb);
3331 ulp_word4 = get_job_word4(phba, rspiocb);
3332 did = get_job_els_rsp64_did(phba, cmdiocb);
3334 if (phba->sli_rev == LPFC_SLI_REV4) {
3335 tmo = get_wqe_tmo(cmdiocb);
3336 iotag = get_wqe_reqtag(cmdiocb);
3338 irsp = &rspiocb->iocb;
3339 tmo = irsp->ulpTimeout;
3340 iotag = irsp->ulpIoTag;
3343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3344 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3345 ulp_status, ulp_word4, did);
3347 /* ELS cmd tag <ulpIoTag> completes */
3348 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3349 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x x%x\n",
3350 iotag, ulp_status, ulp_word4, tmo, cmdiocb->retry);
3352 pcmd = cmdiocb->cmd_dmabuf;
3356 pdata = (u32 *)pcmd->virt;
3361 /* Only 1 retry for ELS Timeout only */
3362 if (ulp_status == IOSTAT_LOCAL_REJECT &&
3363 ((ulp_word4 & IOERR_PARAM_MASK) ==
3364 IOERR_SEQUENCE_TIMEOUT)) {
3366 if (cmdiocb->retry <= 1) {
3369 lpfc_issue_els_scr(vport, cmdiocb->retry);
3372 lpfc_issue_els_edc(vport, cmdiocb->retry);
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 ndlp 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 *)elsiocb->cmd_dmabuf->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->ndlp = lpfc_nlp_get(ndlp);
3500 if (!elsiocb->ndlp) {
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 ndlp 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 = elsiocb->cmd_dmabuf->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->ndlp = lpfc_nlp_get(ndlp);
3597 if (!elsiocb->ndlp) {
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 ndlp 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 *)elsiocb->cmd_dmabuf->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->ndlp = lpfc_nlp_get(ndlp);
3696 if (!elsiocb->ndlp) {
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 ndlp 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 *)elsiocb->cmd_dmabuf->virt;
3765 memset(prdf, 0, cmdsize);
3766 prdf->rdf.fpin_cmd = ELS_RDF;
3767 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3768 sizeof(struct fc_els_rdf));
3769 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3770 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3771 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3772 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3773 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3774 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3775 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3776 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3778 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3779 "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n",
3780 ndlp->nlp_DID, phba->cgn_reg_signal,
3781 phba->cgn_reg_fpin);
3783 phba->cgn_fpin_frequency = LPFC_FPIN_INIT_FREQ;
3784 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
3785 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3786 if (!elsiocb->ndlp) {
3787 lpfc_els_free_iocb(phba, elsiocb);
3791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3792 "Issue RDF: did:x%x refcnt %d",
3793 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3795 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3796 if (rc == IOCB_ERROR) {
3797 lpfc_els_free_iocb(phba, elsiocb);
3805 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
3806 * @vport: pointer to a host virtual N_Port data structure.
3807 * @cmdiocb: pointer to lpfc command iocb data structure.
3808 * @ndlp: pointer to a node-list data structure.
3810 * A received RDF implies a possible change to fabric supported diagnostic
3811 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
3812 * RDF request to reregister for supported diagnostic functions.
3816 * -EIO - Failed to process received RDF
3819 lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3820 struct lpfc_nodelist *ndlp)
3823 if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) {
3824 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3825 "1623 Failed to RDF_ACC from x%x for x%x\n",
3826 ndlp->nlp_DID, vport->fc_myDID);
3830 /* Issue new RDF for reregistering */
3831 if (lpfc_issue_els_rdf(vport, 0)) {
3832 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3833 "2623 Failed to re register RDF for x%x\n",
3842 * lpfc_least_capable_settings - helper function for EDC rsp processing
3843 * @phba: pointer to lpfc hba data structure.
3844 * @pcgd: pointer to congestion detection descriptor in EDC rsp.
3846 * This helper routine determines the least capable setting for
3847 * congestion signals, signal freq, including scale, from the
3848 * congestion detection descriptor in the EDC rsp. The routine
3849 * sets @phba values in preparation for a set_featues mailbox.
3852 lpfc_least_capable_settings(struct lpfc_hba *phba,
3853 struct fc_diag_cg_sig_desc *pcgd)
3855 u32 rsp_sig_cap = 0, drv_sig_cap = 0;
3856 u32 rsp_sig_freq_cyc = 0, rsp_sig_freq_scale = 0;
3858 /* Get rsp signal and frequency capabilities. */
3859 rsp_sig_cap = be32_to_cpu(pcgd->xmt_signal_capability);
3860 rsp_sig_freq_cyc = be16_to_cpu(pcgd->xmt_signal_frequency.count);
3861 rsp_sig_freq_scale = be16_to_cpu(pcgd->xmt_signal_frequency.units);
3863 /* If the Fport does not support signals. Set FPIN only */
3864 if (rsp_sig_cap == EDC_CG_SIG_NOTSUPPORTED)
3865 goto out_no_support;
3867 /* Apply the xmt scale to the xmt cycle to get the correct frequency.
3868 * Adapter default is 100 millisSeconds. Convert all xmt cycle values
3871 switch (rsp_sig_freq_scale) {
3872 case EDC_CG_SIGFREQ_SEC:
3873 rsp_sig_freq_cyc *= MSEC_PER_SEC;
3875 case EDC_CG_SIGFREQ_MSEC:
3876 rsp_sig_freq_cyc = 1;
3879 goto out_no_support;
3882 /* Convenient shorthand. */
3883 drv_sig_cap = phba->cgn_reg_signal;
3885 /* Choose the least capable frequency. */
3886 if (rsp_sig_freq_cyc > phba->cgn_sig_freq)
3887 phba->cgn_sig_freq = rsp_sig_freq_cyc;
3889 /* Should be some common signals support. Settle on least capable
3890 * signal and adjust FPIN values. Initialize defaults to ease the
3893 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
3894 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3895 if (rsp_sig_cap == EDC_CG_SIG_WARN_ONLY &&
3896 (drv_sig_cap == EDC_CG_SIG_WARN_ONLY ||
3897 drv_sig_cap == EDC_CG_SIG_WARN_ALARM)) {
3898 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3899 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3901 if (rsp_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3902 if (drv_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3903 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ALARM;
3904 phba->cgn_reg_fpin = LPFC_CGN_FPIN_NONE;
3906 if (drv_sig_cap == EDC_CG_SIG_WARN_ONLY) {
3907 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3908 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3912 /* We are NOT recording signal frequency in congestion info buffer */
3916 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3917 phba->cgn_sig_freq = 0;
3918 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
3921 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
3922 FC_LS_TLV_DTAG_INIT);
3925 * lpfc_cmpl_els_edc - Completion callback function for EDC
3926 * @phba: pointer to lpfc hba data structure.
3927 * @cmdiocb: pointer to lpfc command iocb data structure.
3928 * @rspiocb: pointer to lpfc response iocb data structure.
3930 * This routine is the completion callback function for issuing the Exchange
3931 * Diagnostic Capabilities (EDC) command. The driver issues an EDC to
3932 * notify the FPort of its Congestion and Link Fault capabilities. This
3933 * routine parses the FPort's response and decides on the least common
3934 * values applicable to both FPort and NPort for Warnings and Alarms that
3935 * are communicated via hardware signals.
3938 lpfc_cmpl_els_edc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3939 struct lpfc_iocbq *rspiocb)
3942 struct fc_els_edc_resp *edc_rsp;
3943 struct fc_tlv_desc *tlv;
3944 struct fc_diag_cg_sig_desc *pcgd;
3945 struct fc_diag_lnkflt_desc *plnkflt;
3946 struct lpfc_dmabuf *pcmd, *prsp;
3947 const char *dtag_nm;
3949 int desc_cnt = 0, bytes_remain;
3950 bool rcv_cap_desc = false;
3951 struct lpfc_nodelist *ndlp;
3952 u32 ulp_status, ulp_word4, tmo, did, iotag;
3954 ndlp = cmdiocb->ndlp;
3956 ulp_status = get_job_ulpstatus(phba, rspiocb);
3957 ulp_word4 = get_job_word4(phba, rspiocb);
3958 did = get_job_els_rsp64_did(phba, rspiocb);
3960 if (phba->sli_rev == LPFC_SLI_REV4) {
3961 tmo = get_wqe_tmo(rspiocb);
3962 iotag = get_wqe_reqtag(rspiocb);
3964 irsp_iocb = &rspiocb->iocb;
3965 tmo = irsp_iocb->ulpTimeout;
3966 iotag = irsp_iocb->ulpIoTag;
3969 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
3970 "EDC cmpl: status:x%x/x%x did:x%x",
3971 ulp_status, ulp_word4, did);
3973 /* ELS cmd tag <ulpIoTag> completes */
3974 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3975 "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n",
3976 iotag, ulp_status, ulp_word4, tmo);
3978 pcmd = cmdiocb->cmd_dmabuf;
3982 pdata = (u32 *)pcmd->virt;
3986 /* Need to clear signal values, send features MB and RDF with FPIN. */
3990 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3994 edc_rsp = prsp->virt;
3998 /* ELS cmd tag <ulpIoTag> completes */
3999 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4000 "4676 Fabric EDC Rsp: "
4002 edc_rsp->acc_hdr.la_cmd,
4003 be32_to_cpu(edc_rsp->desc_list_len));
4006 * Payload length in bytes is the response descriptor list
4007 * length minus the 12 bytes of Link Service Request
4008 * Information descriptor in the reply.
4010 bytes_remain = be32_to_cpu(edc_rsp->desc_list_len) -
4011 sizeof(struct fc_els_lsri_desc);
4012 if (bytes_remain <= 0)
4015 tlv = edc_rsp->desc;
4018 * cycle through EDC diagnostic descriptors to find the
4019 * congestion signaling capability descriptor
4021 while (bytes_remain) {
4022 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
4023 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4024 "6461 Truncated TLV hdr on "
4025 "Diagnostic descriptor[%d]\n",
4030 dtag = be32_to_cpu(tlv->desc_tag);
4032 case ELS_DTAG_LNK_FAULT_CAP:
4033 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4034 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4035 sizeof(struct fc_diag_lnkflt_desc)) {
4037 phba, KERN_WARNING, LOG_CGN_MGMT,
4038 "6462 Truncated Link Fault Diagnostic "
4039 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4040 desc_cnt, bytes_remain,
4041 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4042 sizeof(struct fc_diag_cg_sig_desc));
4045 plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
4047 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4048 "4617 Link Fault Desc Data: 0x%08x 0x%08x "
4049 "0x%08x 0x%08x 0x%08x\n",
4050 be32_to_cpu(plnkflt->desc_tag),
4051 be32_to_cpu(plnkflt->desc_len),
4053 plnkflt->degrade_activate_threshold),
4055 plnkflt->degrade_deactivate_threshold),
4056 be32_to_cpu(plnkflt->fec_degrade_interval));
4058 case ELS_DTAG_CG_SIGNAL_CAP:
4059 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4060 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4061 sizeof(struct fc_diag_cg_sig_desc)) {
4063 phba, KERN_WARNING, LOG_CGN_MGMT,
4064 "6463 Truncated Cgn Signal Diagnostic "
4065 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4066 desc_cnt, bytes_remain,
4067 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4068 sizeof(struct fc_diag_cg_sig_desc));
4072 pcgd = (struct fc_diag_cg_sig_desc *)tlv;
4074 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4075 "4616 CGN Desc Data: 0x%08x 0x%08x "
4076 "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n",
4077 be32_to_cpu(pcgd->desc_tag),
4078 be32_to_cpu(pcgd->desc_len),
4079 be32_to_cpu(pcgd->xmt_signal_capability),
4080 be16_to_cpu(pcgd->xmt_signal_frequency.count),
4081 be16_to_cpu(pcgd->xmt_signal_frequency.units),
4082 be32_to_cpu(pcgd->rcv_signal_capability),
4083 be16_to_cpu(pcgd->rcv_signal_frequency.count),
4084 be16_to_cpu(pcgd->rcv_signal_frequency.units));
4086 /* Compare driver and Fport capabilities and choose
4089 lpfc_least_capable_settings(phba, pcgd);
4090 rcv_cap_desc = true;
4093 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
4094 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4095 "4919 unknown Diagnostic "
4096 "Descriptor[%d]: tag x%x (%s)\n",
4097 desc_cnt, dtag, dtag_nm);
4100 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
4101 tlv = fc_tlv_next_desc(tlv);
4106 if (!rcv_cap_desc) {
4107 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
4108 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4109 phba->cgn_sig_freq = 0;
4110 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
4111 "4202 EDC rsp error - sending RDF "
4112 "for FPIN only.\n");
4115 lpfc_config_cgn_signal(phba);
4117 /* Check to see if link went down during discovery */
4118 lpfc_els_chk_latt(phba->pport);
4119 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
4120 "EDC Cmpl: did:x%x refcnt %d",
4121 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4122 lpfc_els_free_iocb(phba, cmdiocb);
4127 lpfc_format_edc_cgn_desc(struct lpfc_hba *phba, struct fc_diag_cg_sig_desc *cgd)
4129 /* We are assuming cgd was zero'ed before calling this routine */
4131 /* Configure the congestion detection capability */
4132 cgd->desc_tag = cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP);
4134 /* Descriptor len doesn't include the tag or len fields. */
4135 cgd->desc_len = cpu_to_be32(
4136 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc));
4138 /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4139 * xmt_signal_frequency.count already set to 0.
4140 * xmt_signal_frequency.units already set to 0.
4143 if (phba->cmf_active_mode == LPFC_CFG_OFF) {
4144 /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4145 * rcv_signal_frequency.count already set to 0.
4146 * rcv_signal_frequency.units already set to 0.
4148 phba->cgn_sig_freq = 0;
4151 switch (phba->cgn_reg_signal) {
4152 case EDC_CG_SIG_WARN_ONLY:
4153 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ONLY);
4155 case EDC_CG_SIG_WARN_ALARM:
4156 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ALARM);
4159 /* rcv_signal_capability left 0 thus no support */
4163 /* We start negotiation with lpfc_fabric_cgn_frequency, after
4164 * the completion we settle on the higher frequency.
4166 cgd->rcv_signal_frequency.count =
4167 cpu_to_be16(lpfc_fabric_cgn_frequency);
4168 cgd->rcv_signal_frequency.units =
4169 cpu_to_be16(EDC_CG_SIGFREQ_MSEC);
4173 * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric.
4174 * @vport: pointer to a host virtual N_Port data structure.
4175 * @retry: retry counter for the command iocb.
4177 * This routine issues an ELS EDC to the F-Port Controller to communicate
4178 * this N_Port's support of hardware signals in its Congestion
4179 * Capabilities Descriptor.
4181 * Note: This routine does not check if one or more signals are
4182 * set in the cgn_reg_signal parameter. The caller makes the
4183 * decision to enforce cgn_reg_signal as nonzero or zero depending
4184 * on the conditions. During Fabric requests, the driver
4185 * requires cgn_reg_signals to be nonzero. But a dynamic request
4186 * to set the congestion mode to OFF from Monitor or Manage
4187 * would correctly issue an EDC with no signals enabled to
4188 * turn off switch functionality and then update the FW.
4191 * 0 - Successfully issued edc command
4192 * 1 - Failed to issue edc command
4195 lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry)
4197 struct lpfc_hba *phba = vport->phba;
4198 struct lpfc_iocbq *elsiocb;
4199 struct lpfc_els_edc_req *edc_req;
4200 struct fc_diag_cg_sig_desc *cgn_desc;
4202 struct lpfc_nodelist *ndlp;
4204 u32 edc_req_size, cgn_desc_size;
4207 if (vport->port_type == LPFC_NPIV_PORT)
4210 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4211 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
4214 /* If HBA doesn't support signals, drop into RDF */
4215 if (!phba->cgn_init_reg_signal)
4218 edc_req_size = sizeof(struct fc_els_edc);
4219 cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc);
4220 cmdsize = edc_req_size + cgn_desc_size;
4221 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
4222 ndlp->nlp_DID, ELS_CMD_EDC);
4226 /* Configure the payload for the supported Diagnostics capabilities. */
4227 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
4228 memset(pcmd, 0, cmdsize);
4229 edc_req = (struct lpfc_els_edc_req *)pcmd;
4230 edc_req->edc.desc_len = cpu_to_be32(cgn_desc_size);
4231 edc_req->edc.edc_cmd = ELS_EDC;
4233 cgn_desc = &edc_req->cgn_desc;
4235 lpfc_format_edc_cgn_desc(phba, cgn_desc);
4237 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
4239 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4240 "4623 Xmit EDC to remote "
4241 "NPORT x%x reg_sig x%x reg_fpin:x%x\n",
4242 ndlp->nlp_DID, phba->cgn_reg_signal,
4243 phba->cgn_reg_fpin);
4245 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
4246 elsiocb->ndlp = lpfc_nlp_get(ndlp);
4247 if (!elsiocb->ndlp) {
4248 lpfc_els_free_iocb(phba, elsiocb);
4252 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4253 "Issue EDC: did:x%x refcnt %d",
4254 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4255 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4256 if (rc == IOCB_ERROR) {
4257 /* The additional lpfc_nlp_put will cause the following
4258 * lpfc_els_free_iocb routine to trigger the rlease of
4261 lpfc_els_free_iocb(phba, elsiocb);
4267 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
4268 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4269 rc = lpfc_issue_els_rdf(vport, 0);
4274 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
4275 * @vport: pointer to a host virtual N_Port data structure.
4276 * @nlp: pointer to a node-list data structure.
4278 * This routine cancels the timer with a delayed IOCB-command retry for
4279 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
4280 * removes the ELS retry event if it presents. In addition, if the
4281 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
4282 * commands are sent for the @vport's nodes that require issuing discovery
4286 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
4288 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4289 struct lpfc_work_evt *evtp;
4291 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
4293 spin_lock_irq(&nlp->lock);
4294 nlp->nlp_flag &= ~NLP_DELAY_TMO;
4295 spin_unlock_irq(&nlp->lock);
4296 del_timer_sync(&nlp->nlp_delayfunc);
4297 nlp->nlp_last_elscmd = 0;
4298 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
4299 list_del_init(&nlp->els_retry_evt.evt_listp);
4300 /* Decrement nlp reference count held for the delayed retry */
4301 evtp = &nlp->els_retry_evt;
4302 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
4304 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
4305 spin_lock_irq(&nlp->lock);
4306 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4307 spin_unlock_irq(&nlp->lock);
4308 if (vport->num_disc_nodes) {
4309 if (vport->port_state < LPFC_VPORT_READY) {
4310 /* Check if there are more ADISCs to be sent */
4311 lpfc_more_adisc(vport);
4313 /* Check if there are more PLOGIs to be sent */
4314 lpfc_more_plogi(vport);
4315 if (vport->num_disc_nodes == 0) {
4316 spin_lock_irq(shost->host_lock);
4317 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4318 spin_unlock_irq(shost->host_lock);
4319 lpfc_can_disctmo(vport);
4320 lpfc_end_rscn(vport);
4329 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
4330 * @t: pointer to the timer function associated data (ndlp).
4332 * This routine is invoked by the ndlp delayed-function timer to check
4333 * whether there is any pending ELS retry event(s) with the node. If not, it
4334 * simply returns. Otherwise, if there is at least one ELS delayed event, it
4335 * adds the delayed events to the HBA work list and invokes the
4336 * lpfc_worker_wake_up() routine to wake up worker thread to process the
4337 * event. Note that lpfc_nlp_get() is called before posting the event to
4338 * the work list to hold reference count of ndlp so that it guarantees the
4339 * reference to ndlp will still be available when the worker thread gets
4340 * to the event associated with the ndlp.
4343 lpfc_els_retry_delay(struct timer_list *t)
4345 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
4346 struct lpfc_vport *vport = ndlp->vport;
4347 struct lpfc_hba *phba = vport->phba;
4348 unsigned long flags;
4349 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
4351 spin_lock_irqsave(&phba->hbalock, flags);
4352 if (!list_empty(&evtp->evt_listp)) {
4353 spin_unlock_irqrestore(&phba->hbalock, flags);
4357 /* We need to hold the node by incrementing the reference
4358 * count until the queued work is done
4360 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
4361 if (evtp->evt_arg1) {
4362 evtp->evt = LPFC_EVT_ELS_RETRY;
4363 list_add_tail(&evtp->evt_listp, &phba->work_list);
4364 lpfc_worker_wake_up(phba);
4366 spin_unlock_irqrestore(&phba->hbalock, flags);
4371 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
4372 * @ndlp: pointer to a node-list data structure.
4374 * This routine is the worker-thread handler for processing the @ndlp delayed
4375 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
4376 * the last ELS command from the associated ndlp and invokes the proper ELS
4377 * function according to the delayed ELS command to retry the command.
4380 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
4382 struct lpfc_vport *vport = ndlp->vport;
4383 uint32_t cmd, retry;
4385 spin_lock_irq(&ndlp->lock);
4386 cmd = ndlp->nlp_last_elscmd;
4387 ndlp->nlp_last_elscmd = 0;
4389 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
4390 spin_unlock_irq(&ndlp->lock);
4394 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4395 spin_unlock_irq(&ndlp->lock);
4397 * If a discovery event readded nlp_delayfunc after timer
4398 * firing and before processing the timer, cancel the
4401 del_timer_sync(&ndlp->nlp_delayfunc);
4402 retry = ndlp->nlp_retry;
4403 ndlp->nlp_retry = 0;
4407 lpfc_issue_els_flogi(vport, ndlp, retry);
4410 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
4411 ndlp->nlp_prev_state = ndlp->nlp_state;
4412 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4416 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
4417 ndlp->nlp_prev_state = ndlp->nlp_state;
4418 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4422 case ELS_CMD_NVMEPRLI:
4423 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
4424 ndlp->nlp_prev_state = ndlp->nlp_state;
4425 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4429 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
4430 ndlp->nlp_prev_state = ndlp->nlp_state;
4431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4435 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
4436 lpfc_issue_els_fdisc(vport, ndlp, retry);
4443 * lpfc_link_reset - Issue link reset
4444 * @vport: pointer to a virtual N_Port data structure.
4446 * This routine performs link reset by sending INIT_LINK mailbox command.
4447 * For SLI-3 adapter, link attention interrupt is enabled before issuing
4448 * INIT_LINK mailbox command.
4451 * 0 - Link reset initiated successfully
4452 * 1 - Failed to initiate link reset
4455 lpfc_link_reset(struct lpfc_vport *vport)
4457 struct lpfc_hba *phba = vport->phba;
4462 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4463 "2851 Attempt link reset\n");
4464 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4466 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4467 "2852 Failed to allocate mbox memory");
4471 /* Enable Link attention interrupts */
4472 if (phba->sli_rev <= LPFC_SLI_REV3) {
4473 spin_lock_irq(&phba->hbalock);
4474 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4475 control = readl(phba->HCregaddr);
4476 control |= HC_LAINT_ENA;
4477 writel(control, phba->HCregaddr);
4478 readl(phba->HCregaddr); /* flush */
4479 spin_unlock_irq(&phba->hbalock);
4482 lpfc_init_link(phba, mbox, phba->cfg_topology,
4483 phba->cfg_link_speed);
4484 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4485 mbox->vport = vport;
4486 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4487 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
4488 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4489 "2853 Failed to issue INIT_LINK "
4490 "mbox command, rc:x%x\n", rc);
4491 mempool_free(mbox, phba->mbox_mem_pool);
4499 * lpfc_els_retry - Make retry decision on an els command iocb
4500 * @phba: pointer to lpfc hba data structure.
4501 * @cmdiocb: pointer to lpfc command iocb data structure.
4502 * @rspiocb: pointer to lpfc response iocb data structure.
4504 * This routine makes a retry decision on an ELS command IOCB, which has
4505 * failed. The following ELS IOCBs use this function for retrying the command
4506 * when previously issued command responsed with error status: FLOGI, PLOGI,
4507 * PRLI, ADISC and FDISC. Based on the ELS command type and the
4508 * returned error status, it makes the decision whether a retry shall be
4509 * issued for the command, and whether a retry shall be made immediately or
4510 * delayed. In the former case, the corresponding ELS command issuing-function
4511 * is called to retry the command. In the later case, the ELS command shall
4512 * be posted to the ndlp delayed event and delayed function timer set to the
4513 * ndlp for the delayed command issusing.
4516 * 0 - No retry of els command is made
4517 * 1 - Immediate or delayed retry of els command is made
4520 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4521 struct lpfc_iocbq *rspiocb)
4523 struct lpfc_vport *vport = cmdiocb->vport;
4524 union lpfc_wqe128 *irsp = &rspiocb->wqe;
4525 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
4526 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
4529 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
4533 int link_reset = 0, rc;
4534 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
4535 u32 ulp_word4 = get_job_word4(phba, rspiocb);
4538 /* Note: cmd_dmabuf may be 0 for internal driver abort
4539 * of delays ELS command.
4542 if (pcmd && pcmd->virt) {
4543 elscmd = (uint32_t *) (pcmd->virt);
4548 did = ndlp->nlp_DID;
4550 /* We should only hit this case for retrying PLOGI */
4551 did = get_job_els_rsp64_did(phba, rspiocb);
4552 ndlp = lpfc_findnode_did(vport, did);
4553 if (!ndlp && (cmd != ELS_CMD_PLOGI))
4557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4558 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
4559 *(((uint32_t *)irsp) + 7), ulp_word4, did);
4561 switch (ulp_status) {
4562 case IOSTAT_FCP_RSP_ERROR:
4564 case IOSTAT_REMOTE_STOP:
4565 if (phba->sli_rev == LPFC_SLI_REV4) {
4566 /* This IO was aborted by the target, we don't
4567 * know the rxid and because we did not send the
4568 * ABTS we cannot generate and RRQ.
4570 lpfc_set_rrq_active(phba, ndlp,
4571 cmdiocb->sli4_lxritag, 0, 0);
4574 case IOSTAT_LOCAL_REJECT:
4575 switch ((ulp_word4 & IOERR_PARAM_MASK)) {
4576 case IOERR_LOOP_OPEN_FAILURE:
4577 if (cmd == ELS_CMD_FLOGI) {
4578 if (PCI_DEVICE_ID_HORNET ==
4579 phba->pcidev->device) {
4580 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
4581 phba->pport->fc_myDID = 0;
4582 phba->alpa_map[0] = 0;
4583 phba->alpa_map[1] = 0;
4586 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
4591 case IOERR_ILLEGAL_COMMAND:
4592 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4593 "0124 Retry illegal cmd x%x "
4594 "retry:x%x delay:x%x\n",
4595 cmd, cmdiocb->retry, delay);
4597 /* All command's retry policy */
4599 if (cmdiocb->retry > 2)
4603 case IOERR_NO_RESOURCES:
4604 logerr = 1; /* HBA out of resources */
4606 if (cmdiocb->retry > 100)
4611 case IOERR_ILLEGAL_FRAME:
4616 case IOERR_INVALID_RPI:
4617 if (cmd == ELS_CMD_PLOGI &&
4618 did == NameServer_DID) {
4619 /* Continue forever if plogi to */
4620 /* the nameserver fails */
4627 case IOERR_SEQUENCE_TIMEOUT:
4628 if (cmd == ELS_CMD_PLOGI &&
4629 did == NameServer_DID &&
4630 (cmdiocb->retry + 1) == maxretry) {
4631 /* Reset the Link */
4638 case IOERR_SLI_ABORTED:
4639 /* Retry ELS PLOGI command?
4640 * Possibly the rport just wasn't ready.
4642 if (cmd == ELS_CMD_PLOGI) {
4643 /* No retry if state change */
4645 ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
4654 case IOSTAT_NPORT_RJT:
4655 case IOSTAT_FABRIC_RJT:
4656 if (ulp_word4 & RJT_UNAVAIL_TEMP) {
4662 case IOSTAT_NPORT_BSY:
4663 case IOSTAT_FABRIC_BSY:
4664 logerr = 1; /* Fabric / Remote NPort out of resources */
4669 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
4670 /* Added for Vendor specifc support
4671 * Just keep retrying for these Rsn / Exp codes
4673 if ((vport->fc_flag & FC_PT2PT) &&
4674 cmd == ELS_CMD_NVMEPRLI) {
4675 switch (stat.un.b.lsRjtRsnCode) {
4676 case LSRJT_UNABLE_TPC:
4677 case LSRJT_INVALID_CMD:
4678 case LSRJT_LOGICAL_ERR:
4679 case LSRJT_CMD_UNSUPPORTED:
4680 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
4681 "0168 NVME PRLI LS_RJT "
4682 "reason %x port doesn't "
4683 "support NVME, disabling NVME\n",
4684 stat.un.b.lsRjtRsnCode);
4686 vport->fc_flag |= FC_PT2PT_NO_NVME;
4690 switch (stat.un.b.lsRjtRsnCode) {
4691 case LSRJT_UNABLE_TPC:
4692 /* The driver has a VALID PLOGI but the rport has
4693 * rejected the PRLI - can't do it now. Delay
4694 * for 1 second and try again.
4696 * However, if explanation is REQ_UNSUPPORTED there's
4697 * no point to retry PRLI.
4699 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
4700 stat.un.b.lsRjtRsnCodeExp !=
4701 LSEXP_REQ_UNSUPPORTED) {
4703 maxretry = lpfc_max_els_tries + 1;
4708 /* Legacy bug fix code for targets with PLOGI delays. */
4709 if (stat.un.b.lsRjtRsnCodeExp ==
4710 LSEXP_CMD_IN_PROGRESS) {
4711 if (cmd == ELS_CMD_PLOGI) {
4718 if (stat.un.b.lsRjtRsnCodeExp ==
4719 LSEXP_CANT_GIVE_DATA) {
4720 if (cmd == ELS_CMD_PLOGI) {
4727 if (cmd == ELS_CMD_PLOGI) {
4729 maxretry = lpfc_max_els_tries + 1;
4733 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4734 (cmd == ELS_CMD_FDISC) &&
4735 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
4736 lpfc_printf_vlog(vport, KERN_ERR,
4738 "0125 FDISC Failed (x%x). "
4739 "Fabric out of resources\n",
4740 stat.un.lsRjtError);
4741 lpfc_vport_set_state(vport,
4742 FC_VPORT_NO_FABRIC_RSCS);
4746 case LSRJT_LOGICAL_BSY:
4747 if ((cmd == ELS_CMD_PLOGI) ||
4748 (cmd == ELS_CMD_PRLI) ||
4749 (cmd == ELS_CMD_NVMEPRLI)) {
4752 } else if (cmd == ELS_CMD_FDISC) {
4753 /* FDISC retry policy */
4755 if (cmdiocb->retry >= 32)
4761 case LSRJT_LOGICAL_ERR:
4762 /* There are some cases where switches return this
4763 * error when they are not ready and should be returning
4764 * Logical Busy. We should delay every time.
4766 if (cmd == ELS_CMD_FDISC &&
4767 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4771 } else if (cmd == ELS_CMD_FLOGI &&
4772 stat.un.b.lsRjtRsnCodeExp ==
4773 LSEXP_NOTHING_MORE) {
4774 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4776 lpfc_printf_vlog(vport, KERN_ERR,
4778 "0820 FLOGI Failed (x%x). "
4779 "BBCredit Not Supported\n",
4780 stat.un.lsRjtError);
4784 case LSRJT_PROTOCOL_ERR:
4785 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4786 (cmd == ELS_CMD_FDISC) &&
4787 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4788 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4790 lpfc_printf_vlog(vport, KERN_ERR,
4792 "0122 FDISC Failed (x%x). "
4793 "Fabric Detected Bad WWN\n",
4794 stat.un.lsRjtError);
4795 lpfc_vport_set_state(vport,
4796 FC_VPORT_FABRIC_REJ_WWN);
4799 case LSRJT_VENDOR_UNIQUE:
4800 if ((stat.un.b.vendorUnique == 0x45) &&
4801 (cmd == ELS_CMD_FLOGI)) {
4805 case LSRJT_CMD_UNSUPPORTED:
4806 /* lpfc nvmet returns this type of LS_RJT when it
4807 * receives an FCP PRLI because lpfc nvmet only
4808 * support NVME. ELS request is terminated for FCP4
4811 if (stat.un.b.lsRjtRsnCodeExp ==
4812 LSEXP_REQ_UNSUPPORTED) {
4813 if (cmd == ELS_CMD_PRLI) {
4814 spin_lock_irq(&ndlp->lock);
4815 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4816 spin_unlock_irq(&ndlp->lock);
4825 case IOSTAT_INTERMED_RSP:
4834 rc = lpfc_link_reset(vport);
4836 /* Do not give up. Retry PLOGI one more time and attempt
4837 * link reset if PLOGI fails again.
4846 if (did == FDMI_DID)
4849 if ((cmd == ELS_CMD_FLOGI) &&
4850 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4851 !lpfc_error_lost_link(ulp_status, ulp_word4)) {
4852 /* FLOGI retry policy */
4854 /* retry FLOGI forever */
4855 if (phba->link_flag != LS_LOOPBACK_MODE)
4860 if (cmdiocb->retry >= 100)
4862 else if (cmdiocb->retry >= 32)
4864 } else if ((cmd == ELS_CMD_FDISC) &&
4865 !lpfc_error_lost_link(ulp_status, ulp_word4)) {
4866 /* retry FDISCs every second up to devloss */
4868 maxretry = vport->cfg_devloss_tmo;
4873 if (maxretry && (cmdiocb->retry >= maxretry)) {
4874 phba->fc_stat.elsRetryExceeded++;
4878 if ((vport->load_flag & FC_UNLOADING) != 0)
4883 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4884 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4885 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4886 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4887 "2849 Stop retry ELS command "
4888 "x%x to remote NPORT x%x, "
4889 "Data: x%x x%x\n", cmd, did,
4890 cmdiocb->retry, delay);
4895 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4896 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4897 "0107 Retry ELS command x%x to remote "
4898 "NPORT x%x Data: x%x x%x\n",
4899 cmd, did, cmdiocb->retry, delay);
4901 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4902 ((ulp_status != IOSTAT_LOCAL_REJECT) ||
4903 ((ulp_word4 & IOERR_PARAM_MASK) !=
4904 IOERR_NO_RESOURCES))) {
4905 /* Don't reset timer for no resources */
4907 /* If discovery / RSCN timer is running, reset it */
4908 if (timer_pending(&vport->fc_disctmo) ||
4909 (vport->fc_flag & FC_RSCN_MODE))
4910 lpfc_set_disctmo(vport);
4913 phba->fc_stat.elsXmitRetry++;
4914 if (ndlp && delay) {
4915 phba->fc_stat.elsDelayRetry++;
4916 ndlp->nlp_retry = cmdiocb->retry;
4918 /* delay is specified in milliseconds */
4919 mod_timer(&ndlp->nlp_delayfunc,
4920 jiffies + msecs_to_jiffies(delay));
4921 spin_lock_irq(&ndlp->lock);
4922 ndlp->nlp_flag |= NLP_DELAY_TMO;
4923 spin_unlock_irq(&ndlp->lock);
4925 ndlp->nlp_prev_state = ndlp->nlp_state;
4926 if ((cmd == ELS_CMD_PRLI) ||
4927 (cmd == ELS_CMD_NVMEPRLI))
4928 lpfc_nlp_set_state(vport, ndlp,
4929 NLP_STE_PRLI_ISSUE);
4930 else if (cmd != ELS_CMD_ADISC)
4931 lpfc_nlp_set_state(vport, ndlp,
4933 ndlp->nlp_last_elscmd = cmd;
4939 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4942 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4946 ndlp->nlp_prev_state = ndlp->nlp_state;
4947 lpfc_nlp_set_state(vport, ndlp,
4948 NLP_STE_PLOGI_ISSUE);
4950 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4953 ndlp->nlp_prev_state = ndlp->nlp_state;
4954 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4955 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4958 case ELS_CMD_NVMEPRLI:
4959 ndlp->nlp_prev_state = ndlp->nlp_state;
4960 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4961 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4964 ndlp->nlp_prev_state = ndlp->nlp_state;
4965 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4966 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4970 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4972 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4973 "0137 No retry ELS command x%x to remote "
4974 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4975 cmd, did, ulp_status,
4979 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4980 "0108 No retry ELS command x%x to remote "
4981 "NPORT x%x Retried:%d Error:x%x/%x\n",
4982 cmd, did, cmdiocb->retry, ulp_status,
4989 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4990 * @phba: pointer to lpfc hba data structure.
4991 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4993 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4994 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4995 * checks to see whether there is a lpfc DMA buffer associated with the
4996 * response of the command IOCB. If so, it will be released before releasing
4997 * the lpfc DMA buffer associated with the IOCB itself.
5000 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5003 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
5005 struct lpfc_dmabuf *buf_ptr;
5007 /* Free the response before processing the command. */
5008 if (!list_empty(&buf_ptr1->list)) {
5009 list_remove_head(&buf_ptr1->list, buf_ptr,
5012 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5015 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
5021 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
5022 * @phba: pointer to lpfc hba data structure.
5023 * @buf_ptr: pointer to the lpfc dma buffer data structure.
5025 * This routine releases the lpfc Direct Memory Access (DMA) buffer
5026 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
5030 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5033 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
5035 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5041 * lpfc_els_free_iocb - Free a command iocb and its associated resources
5042 * @phba: pointer to lpfc hba data structure.
5043 * @elsiocb: pointer to lpfc els command iocb data structure.
5045 * This routine frees a command IOCB and its associated resources. The
5046 * command IOCB data structure contains the reference to various associated
5047 * resources, these fields must be set to NULL if the associated reference
5049 * cmd_dmabuf - reference to cmd.
5050 * cmd_dmabuf->next - reference to rsp
5051 * rsp_dmabuf - unused
5052 * bpl_dmabuf - reference to bpl
5054 * It first properly decrements the reference count held on ndlp for the
5055 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
5056 * set, it invokes the lpfc_els_free_data() routine to release the Direct
5057 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
5058 * adds the DMA buffer the @phba data structure for the delayed release.
5059 * If reference to the Buffer Pointer List (BPL) is present, the
5060 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
5061 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
5062 * invoked to release the IOCB data structure back to @phba IOCBQ list.
5065 * 0 - Success (currently, always return 0)
5068 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
5070 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
5072 /* The I/O iocb is complete. Clear the node and first dmbuf */
5073 elsiocb->ndlp = NULL;
5075 /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */
5076 if (elsiocb->cmd_dmabuf) {
5077 if (elsiocb->cmd_flag & LPFC_DELAY_MEM_FREE) {
5078 /* Firmware could still be in progress of DMAing
5079 * payload, so don't free data buffer till after
5082 elsiocb->cmd_flag &= ~LPFC_DELAY_MEM_FREE;
5083 buf_ptr = elsiocb->cmd_dmabuf;
5084 elsiocb->cmd_dmabuf = NULL;
5087 spin_lock_irq(&phba->hbalock);
5088 if (!list_empty(&buf_ptr->list)) {
5089 list_remove_head(&buf_ptr->list,
5090 buf_ptr1, struct lpfc_dmabuf,
5092 INIT_LIST_HEAD(&buf_ptr1->list);
5093 list_add_tail(&buf_ptr1->list,
5097 INIT_LIST_HEAD(&buf_ptr->list);
5098 list_add_tail(&buf_ptr->list, &phba->elsbuf);
5100 spin_unlock_irq(&phba->hbalock);
5103 buf_ptr1 = elsiocb->cmd_dmabuf;
5104 lpfc_els_free_data(phba, buf_ptr1);
5105 elsiocb->cmd_dmabuf = NULL;
5109 if (elsiocb->bpl_dmabuf) {
5110 buf_ptr = elsiocb->bpl_dmabuf;
5111 lpfc_els_free_bpl(phba, buf_ptr);
5112 elsiocb->bpl_dmabuf = NULL;
5114 lpfc_sli_release_iocbq(phba, elsiocb);
5119 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
5120 * @phba: pointer to lpfc hba data structure.
5121 * @cmdiocb: pointer to lpfc command iocb data structure.
5122 * @rspiocb: pointer to lpfc response iocb data structure.
5124 * This routine is the completion callback function to the Logout (LOGO)
5125 * Accept (ACC) Response ELS command. This routine is invoked to indicate
5126 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
5127 * release the ndlp if it has the last reference remaining (reference count
5128 * is 1). If succeeded (meaning ndlp released), it sets the iocb ndlp
5129 * field to NULL to inform the following lpfc_els_free_iocb() routine no
5130 * ndlp reference count needs to be decremented. Otherwise, the ndlp
5131 * reference use-count shall be decremented by the lpfc_els_free_iocb()
5132 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
5133 * IOCB data structure.
5136 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5137 struct lpfc_iocbq *rspiocb)
5139 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
5140 struct lpfc_vport *vport = cmdiocb->vport;
5141 u32 ulp_status, ulp_word4;
5143 ulp_status = get_job_ulpstatus(phba, rspiocb);
5144 ulp_word4 = get_job_word4(phba, rspiocb);
5146 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5147 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
5148 ulp_status, ulp_word4, ndlp->nlp_DID);
5149 /* ACC to LOGO completes to NPort <nlp_DID> */
5150 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5151 "0109 ACC to LOGO completes to NPort x%x refcnt %d "
5152 "Data: x%x x%x x%x\n",
5153 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
5154 ndlp->nlp_state, ndlp->nlp_rpi);
5156 /* This clause allows the LOGO ACC to complete and free resources
5157 * for the Fabric Domain Controller. It does deliberately skip
5158 * the unreg_rpi and release rpi because some fabrics send RDP
5159 * requests after logging out from the initiator.
5161 if (ndlp->nlp_type & NLP_FABRIC &&
5162 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
5165 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
5166 /* If PLOGI is being retried, PLOGI completion will cleanup the
5167 * node. The NLP_NPR_2B_DISC flag needs to be retained to make
5168 * progress on nodes discovered from last RSCN.
5170 if ((ndlp->nlp_flag & NLP_DELAY_TMO) &&
5171 (ndlp->nlp_last_elscmd == ELS_CMD_PLOGI))
5174 /* NPort Recovery mode or node is just allocated */
5175 if (!lpfc_nlp_not_used(ndlp)) {
5176 /* A LOGO is completing and the node is in NPR state.
5177 * Just unregister the RPI because the node is still
5180 lpfc_unreg_rpi(vport, ndlp);
5182 /* Indicate the node has already released, should
5183 * not reference to it from within lpfc_els_free_iocb.
5185 cmdiocb->ndlp = NULL;
5190 * The driver received a LOGO from the rport and has ACK'd it.
5191 * At this point, the driver is done so release the IOCB
5193 lpfc_els_free_iocb(phba, cmdiocb);
5198 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
5199 * @phba: pointer to lpfc hba data structure.
5200 * @pmb: pointer to the driver internal queue element for mailbox command.
5202 * This routine is the completion callback function for unregister default
5203 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
5204 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
5205 * decrements the ndlp reference count held for this completion callback
5206 * function. After that, it invokes the lpfc_nlp_not_used() to check
5207 * whether there is only one reference left on the ndlp. If so, it will
5208 * perform one more decrement and trigger the release of the ndlp.
5211 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5213 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
5214 u32 mbx_flag = pmb->mbox_flag;
5215 u32 mbx_cmd = pmb->u.mb.mbxCommand;
5218 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5219 "0006 rpi x%x DID:%x flg:%x %d x%px "
5220 "mbx_cmd x%x mbx_flag x%x x%px\n",
5221 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5222 kref_read(&ndlp->kref), ndlp, mbx_cmd,
5225 /* This ends the default/temporary RPI cleanup logic for this
5226 * ndlp and the node and rpi needs to be released. Free the rpi
5227 * first on an UNREG_LOGIN and then release the final
5230 spin_lock_irq(&ndlp->lock);
5231 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
5232 if (mbx_cmd == MBX_UNREG_LOGIN)
5233 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5234 spin_unlock_irq(&ndlp->lock);
5236 lpfc_drop_node(ndlp->vport, ndlp);
5239 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
5243 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
5244 * @phba: pointer to lpfc hba data structure.
5245 * @cmdiocb: pointer to lpfc command iocb data structure.
5246 * @rspiocb: pointer to lpfc response iocb data structure.
5248 * This routine is the completion callback function for ELS Response IOCB
5249 * command. In normal case, this callback function just properly sets the
5250 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
5251 * field in the command IOCB is not NULL, the referred mailbox command will
5252 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
5256 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5257 struct lpfc_iocbq *rspiocb)
5259 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
5260 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
5261 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
5263 LPFC_MBOXQ_t *mbox = NULL;
5264 u32 ulp_status, ulp_word4, tmo, did, iotag;
5267 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5268 "3177 ELS response failed\n");
5271 if (cmdiocb->context_un.mbox)
5272 mbox = cmdiocb->context_un.mbox;
5274 ulp_status = get_job_ulpstatus(phba, rspiocb);
5275 ulp_word4 = get_job_word4(phba, rspiocb);
5276 did = get_job_els_rsp64_did(phba, cmdiocb);
5278 if (phba->sli_rev == LPFC_SLI_REV4) {
5279 tmo = get_wqe_tmo(cmdiocb);
5280 iotag = get_wqe_reqtag(cmdiocb);
5282 irsp = &rspiocb->iocb;
5283 tmo = irsp->ulpTimeout;
5284 iotag = irsp->ulpIoTag;
5287 /* Check to see if link went down during discovery */
5288 if (!ndlp || lpfc_els_chk_latt(vport)) {
5290 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
5294 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5295 "ELS rsp cmpl: status:x%x/x%x did:x%x",
5296 ulp_status, ulp_word4, did);
5297 /* ELS response tag <ulpIoTag> completes */
5298 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5299 "0110 ELS response tag x%x completes "
5300 "Data: x%x x%x x%x x%x x%x x%x x%x x%x %p %p\n",
5301 iotag, ulp_status, ulp_word4, tmo,
5302 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5303 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox, ndlp);
5306 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
5307 if (!lpfc_unreg_rpi(vport, ndlp) &&
5308 (!(vport->fc_flag & FC_PT2PT))) {
5309 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5311 NLP_STE_REG_LOGIN_ISSUE) {
5312 lpfc_printf_vlog(vport, KERN_INFO,
5316 "Data: x%x x%x x%x\n",
5325 /* Increment reference count to ndlp to hold the
5326 * reference to ndlp for the callback function.
5328 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5329 if (!mbox->ctx_ndlp)
5332 mbox->vport = vport;
5333 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
5334 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5335 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5338 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
5339 ndlp->nlp_prev_state = ndlp->nlp_state;
5340 lpfc_nlp_set_state(vport, ndlp,
5341 NLP_STE_REG_LOGIN_ISSUE);
5344 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
5345 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5346 != MBX_NOT_FINISHED)
5349 /* Decrement the ndlp reference count we
5350 * set for this failed mailbox command.
5353 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
5355 /* ELS rsp: Cannot issue reg_login for <NPortid> */
5356 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5357 "0138 ELS rsp: Cannot issue reg_login for x%x "
5358 "Data: x%x x%x x%x\n",
5359 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5363 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
5366 if (ndlp && shost) {
5367 spin_lock_irq(&ndlp->lock);
5369 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
5370 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
5371 spin_unlock_irq(&ndlp->lock);
5374 /* An SLI4 NPIV instance wants to drop the node at this point under
5375 * these conditions and release the RPI.
5377 if (phba->sli_rev == LPFC_SLI_REV4 &&
5378 (vport && vport->port_type == LPFC_NPIV_PORT) &&
5379 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD) &&
5380 ndlp->nlp_flag & NLP_RELEASE_RPI) {
5381 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE &&
5382 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
5383 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
5384 spin_lock_irq(&ndlp->lock);
5385 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5386 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5387 spin_unlock_irq(&ndlp->lock);
5388 lpfc_drop_node(vport, ndlp);
5392 /* Release the originating I/O reference. */
5393 lpfc_els_free_iocb(phba, cmdiocb);
5399 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
5400 * @vport: pointer to a host virtual N_Port data structure.
5401 * @flag: the els command code to be accepted.
5402 * @oldiocb: pointer to the original lpfc command iocb data structure.
5403 * @ndlp: pointer to a node-list data structure.
5404 * @mbox: pointer to the driver internal queue element for mailbox command.
5406 * This routine prepares and issues an Accept (ACC) response IOCB
5407 * command. It uses the @flag to properly set up the IOCB field for the
5408 * specific ACC response command to be issued and invokes the
5409 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
5410 * @mbox pointer is passed in, it will be put into the context_un.mbox
5411 * field of the IOCB for the completion callback function to issue the
5412 * mailbox command to the HBA later when callback is invoked.
5414 * Note that the ndlp reference count will be incremented by 1 for holding the
5415 * ndlp and the reference to ndlp will be stored into the ndlp field of
5416 * the IOCB for the completion callback function to the corresponding
5417 * response ELS IOCB command.
5420 * 0 - Successfully issued acc response
5421 * 1 - Failed to issue acc response
5424 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
5425 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5428 struct lpfc_hba *phba = vport->phba;
5431 union lpfc_wqe128 *wqe;
5432 union lpfc_wqe128 *oldwqe = &oldiocb->wqe;
5433 struct lpfc_iocbq *elsiocb;
5435 struct serv_parm *sp;
5438 ELS_PKT *els_pkt_ptr;
5439 struct fc_els_rdf_resp *rdf_resp;
5443 cmdsize = sizeof(uint32_t);
5444 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5445 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5447 spin_lock_irq(&ndlp->lock);
5448 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5449 spin_unlock_irq(&ndlp->lock);
5453 if (phba->sli_rev == LPFC_SLI_REV4) {
5454 wqe = &elsiocb->wqe;
5456 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5457 bf_get(wqe_ctxt_tag,
5458 &oldwqe->xmit_els_rsp.wqe_com));
5461 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5463 &oldwqe->xmit_els_rsp.wqe_com));
5465 icmd = &elsiocb->iocb;
5466 oldcmd = &oldiocb->iocb;
5467 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5468 icmd->unsli3.rcvsli3.ox_id =
5469 oldcmd->unsli3.rcvsli3.ox_id;
5472 pcmd = elsiocb->cmd_dmabuf->virt;
5473 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5474 pcmd += sizeof(uint32_t);
5476 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5477 "Issue ACC: did:x%x flg:x%x",
5478 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5482 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
5483 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5484 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5488 if (phba->sli_rev == LPFC_SLI_REV4) {
5489 wqe = &elsiocb->wqe;
5491 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5492 bf_get(wqe_ctxt_tag,
5493 &oldwqe->xmit_els_rsp.wqe_com));
5496 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5498 &oldwqe->xmit_els_rsp.wqe_com));
5500 icmd = &elsiocb->iocb;
5501 oldcmd = &oldiocb->iocb;
5502 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5503 icmd->unsli3.rcvsli3.ox_id =
5504 oldcmd->unsli3.rcvsli3.ox_id;
5507 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
5510 elsiocb->context_un.mbox = mbox;
5512 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5513 pcmd += sizeof(uint32_t);
5514 sp = (struct serv_parm *)pcmd;
5516 if (flag == ELS_CMD_FLOGI) {
5517 /* Copy the received service parameters back */
5518 memcpy(sp, &phba->fc_fabparam,
5519 sizeof(struct serv_parm));
5521 /* Clear the F_Port bit */
5524 /* Mark all class service parameters as invalid */
5525 sp->cls1.classValid = 0;
5526 sp->cls2.classValid = 0;
5527 sp->cls3.classValid = 0;
5528 sp->cls4.classValid = 0;
5530 /* Copy our worldwide names */
5531 memcpy(&sp->portName, &vport->fc_sparam.portName,
5532 sizeof(struct lpfc_name));
5533 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
5534 sizeof(struct lpfc_name));
5536 memcpy(pcmd, &vport->fc_sparam,
5537 sizeof(struct serv_parm));
5539 sp->cmn.valid_vendor_ver_level = 0;
5540 memset(sp->un.vendorVersion, 0,
5541 sizeof(sp->un.vendorVersion));
5542 sp->cmn.bbRcvSizeMsb &= 0xF;
5544 /* If our firmware supports this feature, convey that
5545 * info to the target using the vendor specific field.
5547 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
5548 sp->cmn.valid_vendor_ver_level = 1;
5549 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
5551 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
5555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5556 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
5557 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5560 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
5561 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5562 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
5566 if (phba->sli_rev == LPFC_SLI_REV4) {
5567 wqe = &elsiocb->wqe;
5569 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5570 bf_get(wqe_ctxt_tag,
5571 &oldwqe->xmit_els_rsp.wqe_com));
5574 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5576 &oldwqe->xmit_els_rsp.wqe_com));
5578 icmd = &elsiocb->iocb;
5579 oldcmd = &oldiocb->iocb;
5580 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5581 icmd->unsli3.rcvsli3.ox_id =
5582 oldcmd->unsli3.rcvsli3.ox_id;
5585 pcmd = (u8 *) elsiocb->cmd_dmabuf->virt;
5587 memcpy(pcmd, oldiocb->cmd_dmabuf->virt,
5588 sizeof(uint32_t) + sizeof(PRLO));
5589 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
5590 els_pkt_ptr = (ELS_PKT *) pcmd;
5591 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
5593 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5594 "Issue ACC PRLO: did:x%x flg:x%x",
5595 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5598 cmdsize = sizeof(*rdf_resp);
5599 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5600 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5604 if (phba->sli_rev == LPFC_SLI_REV4) {
5605 wqe = &elsiocb->wqe;
5607 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5608 bf_get(wqe_ctxt_tag,
5609 &oldwqe->xmit_els_rsp.wqe_com));
5612 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5614 &oldwqe->xmit_els_rsp.wqe_com));
5616 icmd = &elsiocb->iocb;
5617 oldcmd = &oldiocb->iocb;
5618 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5619 icmd->unsli3.rcvsli3.ox_id =
5620 oldcmd->unsli3.rcvsli3.ox_id;
5623 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
5624 rdf_resp = (struct fc_els_rdf_resp *)pcmd;
5625 memset(rdf_resp, 0, sizeof(*rdf_resp));
5626 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC;
5628 /* FC-LS-5 specifies desc_list_len shall be set to 12 */
5629 rdf_resp->desc_list_len = cpu_to_be32(12);
5631 /* FC-LS-5 specifies LS REQ Information descriptor */
5632 rdf_resp->lsri.desc_tag = cpu_to_be32(1);
5633 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32));
5634 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF;
5639 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
5640 spin_lock_irq(&ndlp->lock);
5641 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5642 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
5643 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5644 spin_unlock_irq(&ndlp->lock);
5645 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo_acc;
5647 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5650 phba->fc_stat.elsXmitACC++;
5651 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5652 if (!elsiocb->ndlp) {
5653 lpfc_els_free_iocb(phba, elsiocb);
5657 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5658 if (rc == IOCB_ERROR) {
5659 lpfc_els_free_iocb(phba, elsiocb);
5664 /* Xmit ELS ACC response tag <ulpIoTag> */
5665 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5666 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5667 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5668 "RPI: x%x, fc_flag x%x refcnt %d\n",
5669 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5670 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5671 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref));
5676 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
5677 * @vport: pointer to a virtual N_Port data structure.
5678 * @rejectError: reject response to issue
5679 * @oldiocb: pointer to the original lpfc command iocb data structure.
5680 * @ndlp: pointer to a node-list data structure.
5681 * @mbox: pointer to the driver internal queue element for mailbox command.
5683 * This routine prepares and issue an Reject (RJT) response IOCB
5684 * command. If a @mbox pointer is passed in, it will be put into the
5685 * context_un.mbox field of the IOCB for the completion callback function
5686 * to issue to the HBA later.
5688 * Note that the ndlp reference count will be incremented by 1 for holding the
5689 * ndlp and the reference to ndlp will be stored into the ndlp field of
5690 * the IOCB for the completion callback function to the reject response
5694 * 0 - Successfully issued reject response
5695 * 1 - Failed to issue reject response
5698 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
5699 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5703 struct lpfc_hba *phba = vport->phba;
5706 union lpfc_wqe128 *wqe;
5707 struct lpfc_iocbq *elsiocb;
5711 cmdsize = 2 * sizeof(uint32_t);
5712 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5713 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5717 if (phba->sli_rev == LPFC_SLI_REV4) {
5718 wqe = &elsiocb->wqe;
5719 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5720 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
5721 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5722 get_job_rcvoxid(phba, oldiocb));
5724 icmd = &elsiocb->iocb;
5725 oldcmd = &oldiocb->iocb;
5726 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5727 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5730 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
5732 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5733 pcmd += sizeof(uint32_t);
5734 *((uint32_t *) (pcmd)) = rejectError;
5737 elsiocb->context_un.mbox = mbox;
5739 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
5740 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5741 "0129 Xmit ELS RJT x%x response tag x%x "
5742 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5744 rejectError, elsiocb->iotag,
5745 get_job_ulpcontext(phba, elsiocb), ndlp->nlp_DID,
5746 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
5747 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5748 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
5749 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
5751 phba->fc_stat.elsXmitLSRJT++;
5752 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5753 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5754 if (!elsiocb->ndlp) {
5755 lpfc_els_free_iocb(phba, elsiocb);
5759 /* The NPIV instance is rejecting this unsolicited ELS. Make sure the
5760 * node's assigned RPI gets released provided this node is not already
5761 * registered with the transport.
5763 if (phba->sli_rev == LPFC_SLI_REV4 &&
5764 vport->port_type == LPFC_NPIV_PORT &&
5765 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
5766 spin_lock_irq(&ndlp->lock);
5767 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5768 spin_unlock_irq(&ndlp->lock);
5771 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5772 if (rc == IOCB_ERROR) {
5773 lpfc_els_free_iocb(phba, elsiocb);
5782 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric.
5783 * @vport: pointer to a host virtual N_Port data structure.
5784 * @cmdiocb: pointer to the original lpfc command iocb data structure.
5785 * @ndlp: NPort to where rsp is directed
5787 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate
5788 * this N_Port's support of hardware signals in its Congestion
5789 * Capabilities Descriptor.
5792 * 0 - Successfully issued edc rsp command
5793 * 1 - Failed to issue edc rsp command
5796 lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5797 struct lpfc_nodelist *ndlp)
5799 struct lpfc_hba *phba = vport->phba;
5800 struct lpfc_els_edc_rsp *edc_rsp;
5801 struct lpfc_iocbq *elsiocb;
5803 union lpfc_wqe128 *wqe;
5807 cmdsize = sizeof(struct lpfc_els_edc_rsp);
5808 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry,
5809 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5813 if (phba->sli_rev == LPFC_SLI_REV4) {
5814 wqe = &elsiocb->wqe;
5815 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5816 get_job_ulpcontext(phba, cmdiocb)); /* Xri / rx_id */
5817 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5818 get_job_rcvoxid(phba, cmdiocb));
5820 icmd = &elsiocb->iocb;
5821 cmd = &cmdiocb->iocb;
5822 icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */
5823 icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id;
5826 pcmd = elsiocb->cmd_dmabuf->virt;
5827 memset(pcmd, 0, cmdsize);
5829 edc_rsp = (struct lpfc_els_edc_rsp *)pcmd;
5830 edc_rsp->edc_rsp.acc_hdr.la_cmd = ELS_LS_ACC;
5831 edc_rsp->edc_rsp.desc_list_len = cpu_to_be32(
5832 FC_TLV_DESC_LENGTH_FROM_SZ(struct lpfc_els_edc_rsp));
5833 edc_rsp->edc_rsp.lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO);
5834 edc_rsp->edc_rsp.lsri.desc_len = cpu_to_be32(
5835 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc));
5836 edc_rsp->edc_rsp.lsri.rqst_w0.cmd = ELS_EDC;
5837 lpfc_format_edc_cgn_desc(phba, &edc_rsp->cgn_desc);
5839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5840 "Issue EDC ACC: did:x%x flg:x%x refcnt %d",
5841 ndlp->nlp_DID, ndlp->nlp_flag,
5842 kref_read(&ndlp->kref));
5843 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5845 phba->fc_stat.elsXmitACC++;
5846 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5847 if (!elsiocb->ndlp) {
5848 lpfc_els_free_iocb(phba, elsiocb);
5852 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5853 if (rc == IOCB_ERROR) {
5854 lpfc_els_free_iocb(phba, elsiocb);
5859 /* Xmit ELS ACC response tag <ulpIoTag> */
5860 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5861 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, "
5862 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5863 "RPI: x%x, fc_flag x%x\n",
5864 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5865 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5866 ndlp->nlp_rpi, vport->fc_flag);
5872 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
5873 * @vport: pointer to a virtual N_Port data structure.
5874 * @oldiocb: pointer to the original lpfc command iocb data structure.
5875 * @ndlp: pointer to a node-list data structure.
5877 * This routine prepares and issues an Accept (ACC) response to Address
5878 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
5879 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5881 * Note that the ndlp reference count will be incremented by 1 for holding the
5882 * ndlp and the reference to ndlp will be stored into the ndlp field of
5883 * the IOCB for the completion callback function to the ADISC Accept response
5887 * 0 - Successfully issued acc adisc response
5888 * 1 - Failed to issue adisc acc response
5891 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5892 struct lpfc_nodelist *ndlp)
5894 struct lpfc_hba *phba = vport->phba;
5896 IOCB_t *icmd, *oldcmd;
5897 union lpfc_wqe128 *wqe;
5898 struct lpfc_iocbq *elsiocb;
5904 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
5905 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5906 ndlp->nlp_DID, ELS_CMD_ACC);
5910 if (phba->sli_rev == LPFC_SLI_REV4) {
5911 wqe = &elsiocb->wqe;
5913 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5914 get_job_ulpcontext(phba, oldiocb));
5915 ulp_context = get_job_ulpcontext(phba, elsiocb);
5917 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5918 get_job_rcvoxid(phba, oldiocb));
5920 icmd = &elsiocb->iocb;
5921 oldcmd = &oldiocb->iocb;
5922 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5923 ulp_context = elsiocb->iocb.ulpContext;
5924 icmd->unsli3.rcvsli3.ox_id =
5925 oldcmd->unsli3.rcvsli3.ox_id;
5928 /* Xmit ADISC ACC response tag <ulpIoTag> */
5929 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5930 "0130 Xmit ADISC ACC response iotag x%x xri: "
5931 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
5932 elsiocb->iotag, ulp_context,
5933 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5935 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
5937 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5938 pcmd += sizeof(uint32_t);
5940 ap = (ADISC *) (pcmd);
5941 ap->hardAL_PA = phba->fc_pref_ALPA;
5942 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5943 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5944 ap->DID = be32_to_cpu(vport->fc_myDID);
5946 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5947 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5948 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5950 phba->fc_stat.elsXmitACC++;
5951 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5952 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5953 if (!elsiocb->ndlp) {
5954 lpfc_els_free_iocb(phba, elsiocb);
5958 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5959 if (rc == IOCB_ERROR) {
5960 lpfc_els_free_iocb(phba, elsiocb);
5969 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5970 * @vport: pointer to a virtual N_Port data structure.
5971 * @oldiocb: pointer to the original lpfc command iocb data structure.
5972 * @ndlp: pointer to a node-list data structure.
5974 * This routine prepares and issues an Accept (ACC) response to Process
5975 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5976 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5978 * Note that the ndlp reference count will be incremented by 1 for holding the
5979 * ndlp and the reference to ndlp will be stored into the ndlp field of
5980 * the IOCB for the completion callback function to the PRLI Accept response
5984 * 0 - Successfully issued acc prli response
5985 * 1 - Failed to issue acc prli response
5988 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5989 struct lpfc_nodelist *ndlp)
5991 struct lpfc_hba *phba = vport->phba;
5993 struct lpfc_nvme_prli *npr_nvme;
5997 union lpfc_wqe128 *wqe;
5998 struct lpfc_iocbq *elsiocb;
6001 uint32_t prli_fc4_req, *req_payload;
6002 struct lpfc_dmabuf *req_buf;
6004 u32 elsrspcmd, ulp_context;
6006 /* Need the incoming PRLI payload to determine if the ACC is for an
6007 * FC4 or NVME PRLI type. The PRLI type is at word 1.
6009 req_buf = oldiocb->cmd_dmabuf;
6010 req_payload = (((uint32_t *)req_buf->virt) + 1);
6012 /* PRLI type payload is at byte 3 for FCP or NVME. */
6013 prli_fc4_req = be32_to_cpu(*req_payload);
6014 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
6015 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6016 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
6017 prli_fc4_req, *((uint32_t *)req_payload));
6019 if (prli_fc4_req == PRLI_FCP_TYPE) {
6020 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
6021 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
6022 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
6023 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
6024 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
6029 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6030 ndlp->nlp_DID, elsrspcmd);
6034 if (phba->sli_rev == LPFC_SLI_REV4) {
6035 wqe = &elsiocb->wqe;
6036 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6037 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6038 ulp_context = get_job_ulpcontext(phba, elsiocb);
6039 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6040 get_job_rcvoxid(phba, oldiocb));
6042 icmd = &elsiocb->iocb;
6043 oldcmd = &oldiocb->iocb;
6044 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6045 ulp_context = elsiocb->iocb.ulpContext;
6046 icmd->unsli3.rcvsli3.ox_id =
6047 oldcmd->unsli3.rcvsli3.ox_id;
6050 /* Xmit PRLI ACC response tag <ulpIoTag> */
6051 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6052 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
6053 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6054 elsiocb->iotag, ulp_context,
6055 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6057 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6058 memset(pcmd, 0, cmdsize);
6060 *((uint32_t *)(pcmd)) = elsrspcmd;
6061 pcmd += sizeof(uint32_t);
6063 /* For PRLI, remainder of payload is PRLI parameter page */
6066 if (prli_fc4_req == PRLI_FCP_TYPE) {
6068 * If the remote port is a target and our firmware version
6069 * is 3.20 or later, set the following bits for FC-TAPE
6072 npr = (PRLI *) pcmd;
6073 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
6074 (vpd->rev.feaLevelHigh >= 0x02)) {
6075 npr->ConfmComplAllowed = 1;
6077 npr->TaskRetryIdReq = 1;
6079 npr->acceptRspCode = PRLI_REQ_EXECUTED;
6080 npr->estabImagePair = 1;
6081 npr->readXferRdyDis = 1;
6082 npr->ConfmComplAllowed = 1;
6083 npr->prliType = PRLI_FCP_TYPE;
6084 npr->initiatorFunc = 1;
6085 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
6086 /* Respond with an NVME PRLI Type */
6087 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
6088 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
6089 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
6090 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
6091 if (phba->nvmet_support) {
6092 bf_set(prli_tgt, npr_nvme, 1);
6093 bf_set(prli_disc, npr_nvme, 1);
6094 if (phba->cfg_nvme_enable_fb) {
6095 bf_set(prli_fba, npr_nvme, 1);
6097 /* TBD. Target mode needs to post buffers
6098 * that support the configured first burst
6101 bf_set(prli_fb_sz, npr_nvme,
6102 phba->cfg_nvmet_fb_size);
6105 bf_set(prli_init, npr_nvme, 1);
6108 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
6109 "6015 NVME issue PRLI ACC word1 x%08x "
6110 "word4 x%08x word5 x%08x flag x%x, "
6111 "fcp_info x%x nlp_type x%x\n",
6112 npr_nvme->word1, npr_nvme->word4,
6113 npr_nvme->word5, ndlp->nlp_flag,
6114 ndlp->nlp_fcp_info, ndlp->nlp_type);
6115 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
6116 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
6117 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
6119 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6120 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
6121 prli_fc4_req, ndlp->nlp_fc4_type,
6124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6125 "Issue ACC PRLI: did:x%x flg:x%x",
6126 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6128 phba->fc_stat.elsXmitACC++;
6129 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6130 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6131 if (!elsiocb->ndlp) {
6132 lpfc_els_free_iocb(phba, elsiocb);
6136 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6137 if (rc == IOCB_ERROR) {
6138 lpfc_els_free_iocb(phba, elsiocb);
6147 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
6148 * @vport: pointer to a virtual N_Port data structure.
6149 * @format: rnid command format.
6150 * @oldiocb: pointer to the original lpfc command iocb data structure.
6151 * @ndlp: pointer to a node-list data structure.
6153 * This routine issues a Request Node Identification Data (RNID) Accept
6154 * (ACC) response. It constructs the RNID ACC response command according to
6155 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
6156 * issue the response.
6158 * Note that the ndlp reference count will be incremented by 1 for holding the
6159 * ndlp and the reference to ndlp will be stored into the ndlp field of
6160 * the IOCB for the completion callback function.
6163 * 0 - Successfully issued acc rnid response
6164 * 1 - Failed to issue acc rnid response
6167 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
6168 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6170 struct lpfc_hba *phba = vport->phba;
6172 IOCB_t *icmd, *oldcmd;
6173 union lpfc_wqe128 *wqe;
6174 struct lpfc_iocbq *elsiocb;
6180 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
6181 + (2 * sizeof(struct lpfc_name));
6183 cmdsize += sizeof(RNID_TOP_DISC);
6185 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6186 ndlp->nlp_DID, ELS_CMD_ACC);
6190 if (phba->sli_rev == LPFC_SLI_REV4) {
6191 wqe = &elsiocb->wqe;
6192 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6193 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6194 ulp_context = get_job_ulpcontext(phba, elsiocb);
6195 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6196 get_job_rcvoxid(phba, oldiocb));
6198 icmd = &elsiocb->iocb;
6199 oldcmd = &oldiocb->iocb;
6200 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6201 ulp_context = elsiocb->iocb.ulpContext;
6202 icmd->unsli3.rcvsli3.ox_id =
6203 oldcmd->unsli3.rcvsli3.ox_id;
6206 /* Xmit RNID ACC response tag <ulpIoTag> */
6207 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6208 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
6209 elsiocb->iotag, ulp_context);
6210 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6211 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6212 pcmd += sizeof(uint32_t);
6214 memset(pcmd, 0, sizeof(RNID));
6215 rn = (RNID *) (pcmd);
6216 rn->Format = format;
6217 rn->CommonLen = (2 * sizeof(struct lpfc_name));
6218 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
6219 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
6222 rn->SpecificLen = 0;
6224 case RNID_TOPOLOGY_DISC:
6225 rn->SpecificLen = sizeof(RNID_TOP_DISC);
6226 memcpy(&rn->un.topologyDisc.portName,
6227 &vport->fc_portname, sizeof(struct lpfc_name));
6228 rn->un.topologyDisc.unitType = RNID_HBA;
6229 rn->un.topologyDisc.physPort = 0;
6230 rn->un.topologyDisc.attachedNodes = 0;
6234 rn->SpecificLen = 0;
6238 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6239 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
6240 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6242 phba->fc_stat.elsXmitACC++;
6243 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6244 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6245 if (!elsiocb->ndlp) {
6246 lpfc_els_free_iocb(phba, elsiocb);
6250 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6251 if (rc == IOCB_ERROR) {
6252 lpfc_els_free_iocb(phba, elsiocb);
6261 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
6262 * @vport: pointer to a virtual N_Port data structure.
6263 * @iocb: pointer to the lpfc command iocb data structure.
6264 * @ndlp: pointer to a node-list data structure.
6269 lpfc_els_clear_rrq(struct lpfc_vport *vport,
6270 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
6272 struct lpfc_hba *phba = vport->phba;
6277 struct lpfc_node_rrq *prrq;
6280 pcmd = (uint8_t *)iocb->cmd_dmabuf->virt;
6281 pcmd += sizeof(uint32_t);
6282 rrq = (struct RRQ *)pcmd;
6283 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
6284 rxid = bf_get(rrq_rxid, rrq);
6286 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6287 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
6289 be32_to_cpu(bf_get(rrq_did, rrq)),
6290 bf_get(rrq_oxid, rrq),
6292 get_wqe_reqtag(iocb),
6293 get_job_ulpcontext(phba, iocb));
6295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6296 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
6297 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
6298 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
6299 xri = bf_get(rrq_oxid, rrq);
6302 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
6304 lpfc_clr_rrq_active(phba, xri, prrq);
6309 * lpfc_els_rsp_echo_acc - Issue echo acc response
6310 * @vport: pointer to a virtual N_Port data structure.
6311 * @data: pointer to echo data to return in the accept.
6312 * @oldiocb: pointer to the original lpfc command iocb data structure.
6313 * @ndlp: pointer to a node-list data structure.
6316 * 0 - Successfully issued acc echo response
6317 * 1 - Failed to issue acc echo response
6320 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
6321 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6323 struct lpfc_hba *phba = vport->phba;
6324 IOCB_t *icmd, *oldcmd;
6325 union lpfc_wqe128 *wqe;
6326 struct lpfc_iocbq *elsiocb;
6332 if (phba->sli_rev == LPFC_SLI_REV4)
6333 cmdsize = oldiocb->wcqe_cmpl.total_data_placed;
6335 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
6337 /* The accumulated length can exceed the BPL_SIZE. For
6338 * now, use this as the limit
6340 if (cmdsize > LPFC_BPL_SIZE)
6341 cmdsize = LPFC_BPL_SIZE;
6342 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6343 ndlp->nlp_DID, ELS_CMD_ACC);
6347 if (phba->sli_rev == LPFC_SLI_REV4) {
6348 wqe = &elsiocb->wqe;
6349 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6350 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6351 ulp_context = get_job_ulpcontext(phba, elsiocb);
6352 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6353 get_job_rcvoxid(phba, oldiocb));
6355 icmd = &elsiocb->iocb;
6356 oldcmd = &oldiocb->iocb;
6357 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6358 ulp_context = elsiocb->iocb.ulpContext;
6359 icmd->unsli3.rcvsli3.ox_id =
6360 oldcmd->unsli3.rcvsli3.ox_id;
6363 /* Xmit ECHO ACC response tag <ulpIoTag> */
6364 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6365 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
6366 elsiocb->iotag, ulp_context);
6367 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6368 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6369 pcmd += sizeof(uint32_t);
6370 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
6372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6373 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
6374 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6376 phba->fc_stat.elsXmitACC++;
6377 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6378 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6379 if (!elsiocb->ndlp) {
6380 lpfc_els_free_iocb(phba, elsiocb);
6384 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6385 if (rc == IOCB_ERROR) {
6386 lpfc_els_free_iocb(phba, elsiocb);
6395 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
6396 * @vport: pointer to a host virtual N_Port data structure.
6398 * This routine issues Address Discover (ADISC) ELS commands to those
6399 * N_Ports which are in node port recovery state and ADISC has not been issued
6400 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
6401 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
6402 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
6403 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
6404 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
6405 * IOCBs quit for later pick up. On the other hand, after walking through
6406 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
6407 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
6408 * no more ADISC need to be sent.
6411 * The number of N_Ports with adisc issued.
6414 lpfc_els_disc_adisc(struct lpfc_vport *vport)
6416 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6417 struct lpfc_nodelist *ndlp, *next_ndlp;
6420 /* go thru NPR nodes and issue any remaining ELS ADISCs */
6421 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6423 if (ndlp->nlp_state != NLP_STE_NPR_NODE ||
6424 !(ndlp->nlp_flag & NLP_NPR_ADISC))
6427 spin_lock_irq(&ndlp->lock);
6428 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
6429 spin_unlock_irq(&ndlp->lock);
6431 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
6432 /* This node was marked for ADISC but was not picked
6433 * for discovery. This is possible if the node was
6434 * missing in gidft response.
6436 * At time of marking node for ADISC, we skipped unreg
6439 lpfc_nlp_unreg_node(vport, ndlp);
6440 lpfc_unreg_rpi(vport, ndlp);
6444 ndlp->nlp_prev_state = ndlp->nlp_state;
6445 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
6446 lpfc_issue_els_adisc(vport, ndlp, 0);
6448 vport->num_disc_nodes++;
6449 if (vport->num_disc_nodes >=
6450 vport->cfg_discovery_threads) {
6451 spin_lock_irq(shost->host_lock);
6452 vport->fc_flag |= FC_NLP_MORE;
6453 spin_unlock_irq(shost->host_lock);
6458 if (sentadisc == 0) {
6459 spin_lock_irq(shost->host_lock);
6460 vport->fc_flag &= ~FC_NLP_MORE;
6461 spin_unlock_irq(shost->host_lock);
6467 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
6468 * @vport: pointer to a host virtual N_Port data structure.
6470 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
6471 * which are in node port recovery state, with a @vport. Each time an ELS
6472 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
6473 * the per @vport number of discover count (num_disc_nodes) shall be
6474 * incremented. If the num_disc_nodes reaches a pre-configured threshold
6475 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
6476 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
6477 * later pick up. On the other hand, after walking through all the ndlps with
6478 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
6479 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
6480 * PLOGI need to be sent.
6483 * The number of N_Ports with plogi issued.
6486 lpfc_els_disc_plogi(struct lpfc_vport *vport)
6488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6489 struct lpfc_nodelist *ndlp, *next_ndlp;
6492 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
6493 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6494 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
6495 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
6496 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
6497 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
6498 ndlp->nlp_prev_state = ndlp->nlp_state;
6499 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6500 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6502 vport->num_disc_nodes++;
6503 if (vport->num_disc_nodes >=
6504 vport->cfg_discovery_threads) {
6505 spin_lock_irq(shost->host_lock);
6506 vport->fc_flag |= FC_NLP_MORE;
6507 spin_unlock_irq(shost->host_lock);
6513 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6514 "6452 Discover PLOGI %d flag x%x\n",
6515 sentplogi, vport->fc_flag);
6518 lpfc_set_disctmo(vport);
6521 spin_lock_irq(shost->host_lock);
6522 vport->fc_flag &= ~FC_NLP_MORE;
6523 spin_unlock_irq(shost->host_lock);
6529 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
6533 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
6534 desc->payload.els_req = word0;
6535 desc->length = cpu_to_be32(sizeof(desc->payload));
6537 return sizeof(struct fc_rdp_link_service_desc);
6541 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
6542 uint8_t *page_a0, uint8_t *page_a2)
6544 uint16_t wavelength;
6545 uint16_t temperature;
6551 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
6552 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
6554 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
6556 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
6557 &page_a0[SSF_TRANSCEIVER_CODE_B4];
6558 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
6559 &page_a0[SSF_TRANSCEIVER_CODE_B5];
6561 if ((trasn_code_byte4->fc_sw_laser) ||
6562 (trasn_code_byte5->fc_sw_laser_sl) ||
6563 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
6564 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
6565 } else if (trasn_code_byte4->fc_lw_laser) {
6566 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
6567 page_a0[SSF_WAVELENGTH_B0];
6568 if (wavelength == SFP_WAVELENGTH_LC1310)
6569 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
6570 if (wavelength == SFP_WAVELENGTH_LL1550)
6571 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
6573 /* check if its SFP+ */
6574 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
6575 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
6576 << SFP_FLAG_CT_SHIFT;
6578 /* check if its OPTICAL */
6579 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
6580 SFP_FLAG_IS_OPTICAL_PORT : 0)
6581 << SFP_FLAG_IS_OPTICAL_SHIFT;
6583 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
6584 page_a2[SFF_TEMPERATURE_B0]);
6585 vcc = (page_a2[SFF_VCC_B1] << 8 |
6586 page_a2[SFF_VCC_B0]);
6587 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
6588 page_a2[SFF_TXPOWER_B0]);
6589 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
6590 page_a2[SFF_TX_BIAS_CURRENT_B0]);
6591 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
6592 page_a2[SFF_RXPOWER_B0]);
6593 desc->sfp_info.temperature = cpu_to_be16(temperature);
6594 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
6595 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
6596 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
6597 desc->sfp_info.vcc = cpu_to_be16(vcc);
6599 desc->sfp_info.flags = cpu_to_be16(flag);
6600 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
6602 return sizeof(struct fc_rdp_sfp_desc);
6606 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
6611 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
6613 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
6615 desc->info.port_type = cpu_to_be32(type);
6617 desc->info.link_status.link_failure_cnt =
6618 cpu_to_be32(stat->linkFailureCnt);
6619 desc->info.link_status.loss_of_synch_cnt =
6620 cpu_to_be32(stat->lossSyncCnt);
6621 desc->info.link_status.loss_of_signal_cnt =
6622 cpu_to_be32(stat->lossSignalCnt);
6623 desc->info.link_status.primitive_seq_proto_err =
6624 cpu_to_be32(stat->primSeqErrCnt);
6625 desc->info.link_status.invalid_trans_word =
6626 cpu_to_be32(stat->invalidXmitWord);
6627 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
6629 desc->length = cpu_to_be32(sizeof(desc->info));
6631 return sizeof(struct fc_rdp_link_error_status_desc);
6635 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
6636 struct lpfc_vport *vport)
6640 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
6642 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
6643 (vport->fc_sparam.cmn.bbCreditMsb << 8);
6644 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
6645 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
6646 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
6647 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
6648 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
6650 desc->bbc_info.attached_port_bbc = 0;
6653 desc->bbc_info.rtt = 0;
6654 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
6656 return sizeof(struct fc_rdp_bbc_desc);
6660 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
6661 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
6665 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6667 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
6668 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
6669 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
6670 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
6672 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6673 flags |= RDP_OET_HIGH_ALARM;
6674 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6675 flags |= RDP_OET_LOW_ALARM;
6676 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6677 flags |= RDP_OET_HIGH_WARNING;
6678 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6679 flags |= RDP_OET_LOW_WARNING;
6681 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
6682 desc->oed_info.function_flags = cpu_to_be32(flags);
6683 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6684 return sizeof(struct fc_rdp_oed_sfp_desc);
6688 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
6689 struct fc_rdp_oed_sfp_desc *desc,
6694 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6696 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
6697 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
6698 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
6699 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
6701 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6702 flags |= RDP_OET_HIGH_ALARM;
6703 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6704 flags |= RDP_OET_LOW_ALARM;
6705 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6706 flags |= RDP_OET_HIGH_WARNING;
6707 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6708 flags |= RDP_OET_LOW_WARNING;
6710 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
6711 desc->oed_info.function_flags = cpu_to_be32(flags);
6712 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6713 return sizeof(struct fc_rdp_oed_sfp_desc);
6717 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
6718 struct fc_rdp_oed_sfp_desc *desc,
6723 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6725 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
6726 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
6727 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
6728 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
6730 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6731 flags |= RDP_OET_HIGH_ALARM;
6732 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
6733 flags |= RDP_OET_LOW_ALARM;
6734 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6735 flags |= RDP_OET_HIGH_WARNING;
6736 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
6737 flags |= RDP_OET_LOW_WARNING;
6739 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
6740 desc->oed_info.function_flags = cpu_to_be32(flags);
6741 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6742 return sizeof(struct fc_rdp_oed_sfp_desc);
6746 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
6747 struct fc_rdp_oed_sfp_desc *desc,
6752 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6754 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
6755 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
6756 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
6757 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
6759 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6760 flags |= RDP_OET_HIGH_ALARM;
6761 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
6762 flags |= RDP_OET_LOW_ALARM;
6763 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6764 flags |= RDP_OET_HIGH_WARNING;
6765 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
6766 flags |= RDP_OET_LOW_WARNING;
6768 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
6769 desc->oed_info.function_flags = cpu_to_be32(flags);
6770 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6771 return sizeof(struct fc_rdp_oed_sfp_desc);
6776 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
6777 struct fc_rdp_oed_sfp_desc *desc,
6782 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6784 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
6785 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
6786 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
6787 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
6789 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6790 flags |= RDP_OET_HIGH_ALARM;
6791 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
6792 flags |= RDP_OET_LOW_ALARM;
6793 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6794 flags |= RDP_OET_HIGH_WARNING;
6795 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
6796 flags |= RDP_OET_LOW_WARNING;
6798 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
6799 desc->oed_info.function_flags = cpu_to_be32(flags);
6800 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6801 return sizeof(struct fc_rdp_oed_sfp_desc);
6805 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
6806 uint8_t *page_a0, struct lpfc_vport *vport)
6808 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
6809 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
6810 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
6811 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
6812 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
6813 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
6814 desc->length = cpu_to_be32(sizeof(desc->opd_info));
6815 return sizeof(struct fc_rdp_opd_sfp_desc);
6819 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
6821 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
6823 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
6825 desc->info.CorrectedBlocks =
6826 cpu_to_be32(stat->fecCorrBlkCount);
6827 desc->info.UncorrectableBlocks =
6828 cpu_to_be32(stat->fecUncorrBlkCount);
6830 desc->length = cpu_to_be32(sizeof(desc->info));
6832 return sizeof(struct fc_fec_rdp_desc);
6836 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
6838 uint16_t rdp_cap = 0;
6841 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
6843 switch (phba->fc_linkspeed) {
6844 case LPFC_LINK_SPEED_1GHZ:
6845 rdp_speed = RDP_PS_1GB;
6847 case LPFC_LINK_SPEED_2GHZ:
6848 rdp_speed = RDP_PS_2GB;
6850 case LPFC_LINK_SPEED_4GHZ:
6851 rdp_speed = RDP_PS_4GB;
6853 case LPFC_LINK_SPEED_8GHZ:
6854 rdp_speed = RDP_PS_8GB;
6856 case LPFC_LINK_SPEED_10GHZ:
6857 rdp_speed = RDP_PS_10GB;
6859 case LPFC_LINK_SPEED_16GHZ:
6860 rdp_speed = RDP_PS_16GB;
6862 case LPFC_LINK_SPEED_32GHZ:
6863 rdp_speed = RDP_PS_32GB;
6865 case LPFC_LINK_SPEED_64GHZ:
6866 rdp_speed = RDP_PS_64GB;
6868 case LPFC_LINK_SPEED_128GHZ:
6869 rdp_speed = RDP_PS_128GB;
6871 case LPFC_LINK_SPEED_256GHZ:
6872 rdp_speed = RDP_PS_256GB;
6875 rdp_speed = RDP_PS_UNKNOWN;
6879 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
6881 if (phba->lmt & LMT_256Gb)
6882 rdp_cap |= RDP_PS_256GB;
6883 if (phba->lmt & LMT_128Gb)
6884 rdp_cap |= RDP_PS_128GB;
6885 if (phba->lmt & LMT_64Gb)
6886 rdp_cap |= RDP_PS_64GB;
6887 if (phba->lmt & LMT_32Gb)
6888 rdp_cap |= RDP_PS_32GB;
6889 if (phba->lmt & LMT_16Gb)
6890 rdp_cap |= RDP_PS_16GB;
6891 if (phba->lmt & LMT_10Gb)
6892 rdp_cap |= RDP_PS_10GB;
6893 if (phba->lmt & LMT_8Gb)
6894 rdp_cap |= RDP_PS_8GB;
6895 if (phba->lmt & LMT_4Gb)
6896 rdp_cap |= RDP_PS_4GB;
6897 if (phba->lmt & LMT_2Gb)
6898 rdp_cap |= RDP_PS_2GB;
6899 if (phba->lmt & LMT_1Gb)
6900 rdp_cap |= RDP_PS_1GB;
6903 rdp_cap = RDP_CAP_UNKNOWN;
6904 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
6905 rdp_cap |= RDP_CAP_USER_CONFIGURED;
6907 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
6908 desc->length = cpu_to_be32(sizeof(desc->info));
6909 return sizeof(struct fc_rdp_port_speed_desc);
6913 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
6914 struct lpfc_vport *vport)
6917 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6919 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
6920 sizeof(desc->port_names.wwnn));
6922 memcpy(desc->port_names.wwpn, &vport->fc_portname,
6923 sizeof(desc->port_names.wwpn));
6925 desc->length = cpu_to_be32(sizeof(desc->port_names));
6926 return sizeof(struct fc_rdp_port_name_desc);
6930 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
6931 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6934 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6935 if (vport->fc_flag & FC_FABRIC) {
6936 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
6937 sizeof(desc->port_names.wwnn));
6939 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
6940 sizeof(desc->port_names.wwpn));
6941 } else { /* Point to Point */
6942 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
6943 sizeof(desc->port_names.wwnn));
6945 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
6946 sizeof(desc->port_names.wwpn));
6949 desc->length = cpu_to_be32(sizeof(desc->port_names));
6950 return sizeof(struct fc_rdp_port_name_desc);
6954 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
6957 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
6958 struct lpfc_vport *vport = ndlp->vport;
6959 struct lpfc_iocbq *elsiocb;
6960 struct ulp_bde64 *bpl;
6962 union lpfc_wqe128 *wqe;
6964 struct ls_rjt *stat;
6965 struct fc_rdp_res_frame *rdp_res;
6966 uint32_t cmdsize, len;
6971 if (status != SUCCESS)
6974 /* This will change once we know the true size of the RDP payload */
6975 cmdsize = sizeof(struct fc_rdp_res_frame);
6977 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
6978 lpfc_max_els_tries, rdp_context->ndlp,
6979 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
6981 goto free_rdp_context;
6983 ulp_context = get_job_ulpcontext(phba, elsiocb);
6984 if (phba->sli_rev == LPFC_SLI_REV4) {
6985 wqe = &elsiocb->wqe;
6986 /* ox-id of the frame */
6987 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6988 rdp_context->ox_id);
6989 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
6990 rdp_context->rx_id);
6992 icmd = &elsiocb->iocb;
6993 icmd->ulpContext = rdp_context->rx_id;
6994 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6997 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6998 "2171 Xmit RDP response tag x%x xri x%x, "
6999 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
7000 elsiocb->iotag, ulp_context,
7001 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7003 rdp_res = (struct fc_rdp_res_frame *)elsiocb->cmd_dmabuf->virt;
7004 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7005 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
7006 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7008 /* Update Alarm and Warning */
7009 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
7010 phba->sfp_alarm |= *flag_ptr;
7011 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
7012 phba->sfp_warning |= *flag_ptr;
7014 /* For RDP payload */
7016 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
7017 (len + pcmd), ELS_CMD_RDP);
7019 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
7020 rdp_context->page_a0, rdp_context->page_a2);
7021 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
7023 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
7024 (len + pcmd), &rdp_context->link_stat);
7025 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
7026 (len + pcmd), vport);
7027 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
7028 (len + pcmd), vport, ndlp);
7029 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
7030 &rdp_context->link_stat);
7031 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
7032 &rdp_context->link_stat, vport);
7033 len += lpfc_rdp_res_oed_temp_desc(phba,
7034 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7035 rdp_context->page_a2);
7036 len += lpfc_rdp_res_oed_voltage_desc(phba,
7037 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7038 rdp_context->page_a2);
7039 len += lpfc_rdp_res_oed_txbias_desc(phba,
7040 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7041 rdp_context->page_a2);
7042 len += lpfc_rdp_res_oed_txpower_desc(phba,
7043 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7044 rdp_context->page_a2);
7045 len += lpfc_rdp_res_oed_rxpower_desc(phba,
7046 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7047 rdp_context->page_a2);
7048 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
7049 rdp_context->page_a0, vport);
7051 rdp_res->length = cpu_to_be32(len - 8);
7052 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7054 /* Now that we know the true size of the payload, update the BPL */
7055 bpl = (struct ulp_bde64 *)elsiocb->bpl_dmabuf->virt;
7056 bpl->tus.f.bdeSize = len;
7057 bpl->tus.f.bdeFlags = 0;
7058 bpl->tus.w = le32_to_cpu(bpl->tus.w);
7060 phba->fc_stat.elsXmitACC++;
7061 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7062 if (!elsiocb->ndlp) {
7063 lpfc_els_free_iocb(phba, elsiocb);
7064 goto free_rdp_context;
7067 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7068 if (rc == IOCB_ERROR) {
7069 lpfc_els_free_iocb(phba, elsiocb);
7073 goto free_rdp_context;
7076 cmdsize = 2 * sizeof(uint32_t);
7077 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
7078 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
7080 goto free_rdp_context;
7082 if (phba->sli_rev == LPFC_SLI_REV4) {
7083 wqe = &elsiocb->wqe;
7084 /* ox-id of the frame */
7085 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7086 rdp_context->ox_id);
7087 bf_set(wqe_ctxt_tag,
7088 &wqe->xmit_els_rsp.wqe_com,
7089 rdp_context->rx_id);
7091 icmd = &elsiocb->iocb;
7092 icmd->ulpContext = rdp_context->rx_id;
7093 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
7096 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7098 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
7099 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7100 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7102 phba->fc_stat.elsXmitLSRJT++;
7103 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7104 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7105 if (!elsiocb->ndlp) {
7106 lpfc_els_free_iocb(phba, elsiocb);
7107 goto free_rdp_context;
7110 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7111 if (rc == IOCB_ERROR) {
7112 lpfc_els_free_iocb(phba, elsiocb);
7117 /* This reference put is for the original unsolicited RDP. If the
7118 * prep failed, there is no reference to remove.
7125 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
7127 LPFC_MBOXQ_t *mbox = NULL;
7130 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7132 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
7133 "7105 failed to allocate mailbox memory");
7137 if (lpfc_sli4_dump_page_a0(phba, mbox))
7139 mbox->vport = rdp_context->ndlp->vport;
7140 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
7141 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
7142 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7143 if (rc == MBX_NOT_FINISHED) {
7144 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
7151 mempool_free(mbox, phba->mbox_mem_pool);
7156 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
7157 * @vport: pointer to a host virtual N_Port data structure.
7158 * @cmdiocb: pointer to lpfc command iocb data structure.
7159 * @ndlp: pointer to a node-list data structure.
7161 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
7162 * IOCB. First, the payload of the unsolicited RDP is checked.
7163 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
7164 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
7165 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
7166 * gather all data and send RDP response.
7169 * 0 - Sent the acc response
7170 * 1 - Sent the reject response.
7173 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7174 struct lpfc_nodelist *ndlp)
7176 struct lpfc_hba *phba = vport->phba;
7177 struct lpfc_dmabuf *pcmd;
7178 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
7179 struct fc_rdp_req_frame *rdp_req;
7180 struct lpfc_rdp_context *rdp_context;
7181 union lpfc_wqe128 *cmd = NULL;
7184 if (phba->sli_rev < LPFC_SLI_REV4 ||
7185 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7186 LPFC_SLI_INTF_IF_TYPE_2) {
7187 rjt_err = LSRJT_UNABLE_TPC;
7188 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7192 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
7193 rjt_err = LSRJT_UNABLE_TPC;
7194 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7198 pcmd = cmdiocb->cmd_dmabuf;
7199 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
7201 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7202 "2422 ELS RDP Request "
7203 "dec len %d tag x%x port_id %d len %d\n",
7204 be32_to_cpu(rdp_req->rdp_des_length),
7205 be32_to_cpu(rdp_req->nport_id_desc.tag),
7206 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
7207 be32_to_cpu(rdp_req->nport_id_desc.length));
7209 if (sizeof(struct fc_rdp_nport_desc) !=
7210 be32_to_cpu(rdp_req->rdp_des_length))
7212 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
7214 if (RDP_NPORT_ID_SIZE !=
7215 be32_to_cpu(rdp_req->nport_id_desc.length))
7217 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
7219 rjt_err = LSRJT_UNABLE_TPC;
7223 cmd = &cmdiocb->wqe;
7224 rdp_context->ndlp = lpfc_nlp_get(ndlp);
7225 if (!rdp_context->ndlp) {
7227 rjt_err = LSRJT_UNABLE_TPC;
7230 rdp_context->ox_id = bf_get(wqe_rcvoxid,
7231 &cmd->xmit_els_rsp.wqe_com);
7232 rdp_context->rx_id = bf_get(wqe_ctxt_tag,
7233 &cmd->xmit_els_rsp.wqe_com);
7234 rdp_context->cmpl = lpfc_els_rdp_cmpl;
7235 if (lpfc_get_rdp_info(phba, rdp_context)) {
7236 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
7237 "2423 Unable to send mailbox");
7239 rjt_err = LSRJT_UNABLE_TPC;
7247 rjt_err = LSRJT_LOGICAL_ERR;
7250 memset(&stat, 0, sizeof(stat));
7251 stat.un.b.lsRjtRsnCode = rjt_err;
7252 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
7253 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7259 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7263 union lpfc_wqe128 *wqe;
7265 struct lpfc_iocbq *elsiocb;
7266 struct lpfc_nodelist *ndlp;
7267 struct ls_rjt *stat;
7268 union lpfc_sli4_cfg_shdr *shdr;
7269 struct lpfc_lcb_context *lcb_context;
7270 struct fc_lcb_res_frame *lcb_res;
7271 uint32_t cmdsize, shdr_status, shdr_add_status;
7275 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
7276 ndlp = lcb_context->ndlp;
7277 pmb->ctx_ndlp = NULL;
7278 pmb->ctx_buf = NULL;
7280 shdr = (union lpfc_sli4_cfg_shdr *)
7281 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
7282 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7283 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7285 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
7286 "0194 SET_BEACON_CONFIG mailbox "
7287 "completed with status x%x add_status x%x,"
7288 " mbx status x%x\n",
7289 shdr_status, shdr_add_status, mb->mbxStatus);
7291 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
7292 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
7293 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
7294 mempool_free(pmb, phba->mbox_mem_pool);
7298 mempool_free(pmb, phba->mbox_mem_pool);
7299 cmdsize = sizeof(struct fc_lcb_res_frame);
7300 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7301 lpfc_max_els_tries, ndlp,
7302 ndlp->nlp_DID, ELS_CMD_ACC);
7304 /* Decrement the ndlp reference count from previous mbox command */
7308 goto free_lcb_context;
7310 lcb_res = (struct fc_lcb_res_frame *)elsiocb->cmd_dmabuf->virt;
7312 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
7314 if (phba->sli_rev == LPFC_SLI_REV4) {
7315 wqe = &elsiocb->wqe;
7316 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7317 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7318 lcb_context->ox_id);
7320 icmd = &elsiocb->iocb;
7321 icmd->ulpContext = lcb_context->rx_id;
7322 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7325 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7326 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
7327 lcb_res->lcb_sub_command = lcb_context->sub_command;
7328 lcb_res->lcb_type = lcb_context->type;
7329 lcb_res->capability = lcb_context->capability;
7330 lcb_res->lcb_frequency = lcb_context->frequency;
7331 lcb_res->lcb_duration = lcb_context->duration;
7332 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7333 phba->fc_stat.elsXmitACC++;
7335 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7336 if (!elsiocb->ndlp) {
7337 lpfc_els_free_iocb(phba, elsiocb);
7341 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7342 if (rc == IOCB_ERROR) {
7343 lpfc_els_free_iocb(phba, elsiocb);
7351 cmdsize = sizeof(struct fc_lcb_res_frame);
7352 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7353 lpfc_max_els_tries, ndlp,
7354 ndlp->nlp_DID, ELS_CMD_LS_RJT);
7357 goto free_lcb_context;
7359 if (phba->sli_rev == LPFC_SLI_REV4) {
7360 wqe = &elsiocb->wqe;
7361 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7362 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7363 lcb_context->ox_id);
7365 icmd = &elsiocb->iocb;
7366 icmd->ulpContext = lcb_context->rx_id;
7367 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7370 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7372 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
7373 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7374 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7376 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
7377 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
7379 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7380 phba->fc_stat.elsXmitLSRJT++;
7381 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7382 if (!elsiocb->ndlp) {
7383 lpfc_els_free_iocb(phba, elsiocb);
7384 goto free_lcb_context;
7387 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7388 if (rc == IOCB_ERROR) {
7389 lpfc_els_free_iocb(phba, elsiocb);
7397 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
7398 struct lpfc_lcb_context *lcb_context,
7399 uint32_t beacon_state)
7401 struct lpfc_hba *phba = vport->phba;
7402 union lpfc_sli4_cfg_shdr *cfg_shdr;
7403 LPFC_MBOXQ_t *mbox = NULL;
7407 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7411 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
7412 len = sizeof(struct lpfc_mbx_set_beacon_config) -
7413 sizeof(struct lpfc_sli4_cfg_mhdr);
7414 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7415 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
7416 LPFC_SLI4_MBX_EMBED);
7417 mbox->ctx_ndlp = (void *)lcb_context;
7418 mbox->vport = phba->pport;
7419 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
7420 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
7421 phba->sli4_hba.physical_port);
7422 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
7424 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
7427 * Check bv1s bit before issuing the mailbox
7428 * if bv1s == 1, LCB V1 supported
7429 * else, LCB V0 supported
7432 if (phba->sli4_hba.pc_sli4_params.bv1s) {
7433 /* COMMON_SET_BEACON_CONFIG_V1 */
7434 cfg_shdr->request.word9 = BEACON_VERSION_V1;
7435 lcb_context->capability |= LCB_CAPABILITY_DURATION;
7436 bf_set(lpfc_mbx_set_beacon_port_type,
7437 &mbox->u.mqe.un.beacon_config, 0);
7438 bf_set(lpfc_mbx_set_beacon_duration_v1,
7439 &mbox->u.mqe.un.beacon_config,
7440 be16_to_cpu(lcb_context->duration));
7442 /* COMMON_SET_BEACON_CONFIG_V0 */
7443 if (be16_to_cpu(lcb_context->duration) != 0) {
7444 mempool_free(mbox, phba->mbox_mem_pool);
7447 cfg_shdr->request.word9 = BEACON_VERSION_V0;
7448 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
7449 bf_set(lpfc_mbx_set_beacon_state,
7450 &mbox->u.mqe.un.beacon_config, beacon_state);
7451 bf_set(lpfc_mbx_set_beacon_port_type,
7452 &mbox->u.mqe.un.beacon_config, 1);
7453 bf_set(lpfc_mbx_set_beacon_duration,
7454 &mbox->u.mqe.un.beacon_config,
7455 be16_to_cpu(lcb_context->duration));
7458 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7459 if (rc == MBX_NOT_FINISHED) {
7460 mempool_free(mbox, phba->mbox_mem_pool);
7469 * lpfc_els_rcv_lcb - Process an unsolicited LCB
7470 * @vport: pointer to a host virtual N_Port data structure.
7471 * @cmdiocb: pointer to lpfc command iocb data structure.
7472 * @ndlp: pointer to a node-list data structure.
7474 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
7475 * First, the payload of the unsolicited LCB is checked.
7476 * Then based on Subcommand beacon will either turn on or off.
7479 * 0 - Sent the acc response
7480 * 1 - Sent the reject response.
7483 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7484 struct lpfc_nodelist *ndlp)
7486 struct lpfc_hba *phba = vport->phba;
7487 struct lpfc_dmabuf *pcmd;
7489 struct fc_lcb_request_frame *beacon;
7490 struct lpfc_lcb_context *lcb_context;
7491 u8 state, rjt_err = 0;
7494 pcmd = cmdiocb->cmd_dmabuf;
7495 lp = (uint8_t *)pcmd->virt;
7496 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
7498 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7499 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
7500 "type x%x frequency %x duration x%x\n",
7501 lp[0], lp[1], lp[2],
7502 beacon->lcb_command,
7503 beacon->lcb_sub_command,
7505 beacon->lcb_frequency,
7506 be16_to_cpu(beacon->lcb_duration));
7508 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
7509 beacon->lcb_sub_command != LPFC_LCB_OFF) {
7510 rjt_err = LSRJT_CMD_UNSUPPORTED;
7514 if (phba->sli_rev < LPFC_SLI_REV4 ||
7515 phba->hba_flag & HBA_FCOE_MODE ||
7516 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7517 LPFC_SLI_INTF_IF_TYPE_2)) {
7518 rjt_err = LSRJT_CMD_UNSUPPORTED;
7522 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
7524 rjt_err = LSRJT_UNABLE_TPC;
7528 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
7529 lcb_context->sub_command = beacon->lcb_sub_command;
7530 lcb_context->capability = 0;
7531 lcb_context->type = beacon->lcb_type;
7532 lcb_context->frequency = beacon->lcb_frequency;
7533 lcb_context->duration = beacon->lcb_duration;
7534 lcb_context->ox_id = get_job_rcvoxid(phba, cmdiocb);
7535 lcb_context->rx_id = get_job_ulpcontext(phba, cmdiocb);
7536 lcb_context->ndlp = lpfc_nlp_get(ndlp);
7537 if (!lcb_context->ndlp) {
7538 rjt_err = LSRJT_UNABLE_TPC;
7542 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
7543 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
7544 "0193 failed to send mail box");
7546 rjt_err = LSRJT_UNABLE_TPC;
7554 memset(&stat, 0, sizeof(stat));
7555 stat.un.b.lsRjtRsnCode = rjt_err;
7556 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7562 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
7563 * @vport: pointer to a host virtual N_Port data structure.
7565 * This routine cleans up any Registration State Change Notification
7566 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
7567 * @vport together with the host_lock is used to prevent multiple thread
7568 * trying to access the RSCN array on a same @vport at the same time.
7571 lpfc_els_flush_rscn(struct lpfc_vport *vport)
7573 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7574 struct lpfc_hba *phba = vport->phba;
7577 spin_lock_irq(shost->host_lock);
7578 if (vport->fc_rscn_flush) {
7579 /* Another thread is walking fc_rscn_id_list on this vport */
7580 spin_unlock_irq(shost->host_lock);
7583 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
7584 vport->fc_rscn_flush = 1;
7585 spin_unlock_irq(shost->host_lock);
7587 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7588 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
7589 vport->fc_rscn_id_list[i] = NULL;
7591 spin_lock_irq(shost->host_lock);
7592 vport->fc_rscn_id_cnt = 0;
7593 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
7594 spin_unlock_irq(shost->host_lock);
7595 lpfc_can_disctmo(vport);
7596 /* Indicate we are done walking this fc_rscn_id_list */
7597 vport->fc_rscn_flush = 0;
7601 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
7602 * @vport: pointer to a host virtual N_Port data structure.
7603 * @did: remote destination port identifier.
7605 * This routine checks whether there is any pending Registration State
7606 * Configuration Notification (RSCN) to a @did on @vport.
7609 * None zero - The @did matched with a pending rscn
7610 * 0 - not able to match @did with a pending rscn
7613 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
7618 uint32_t payload_len, i;
7619 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7621 ns_did.un.word = did;
7623 /* Never match fabric nodes for RSCNs */
7624 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7627 /* If we are doing a FULL RSCN rediscovery, match everything */
7628 if (vport->fc_flag & FC_RSCN_DISCOVERY)
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 fc_rscn_id_list on this vport */
7638 vport->fc_rscn_flush = 1;
7639 spin_unlock_irq(shost->host_lock);
7640 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7641 lp = vport->fc_rscn_id_list[i]->virt;
7642 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7643 payload_len -= sizeof(uint32_t); /* take off word 0 */
7644 while (payload_len) {
7645 rscn_did.un.word = be32_to_cpu(*lp++);
7646 payload_len -= sizeof(uint32_t);
7647 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
7648 case RSCN_ADDRESS_FORMAT_PORT:
7649 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7650 && (ns_did.un.b.area == rscn_did.un.b.area)
7651 && (ns_did.un.b.id == rscn_did.un.b.id))
7652 goto return_did_out;
7654 case RSCN_ADDRESS_FORMAT_AREA:
7655 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7656 && (ns_did.un.b.area == rscn_did.un.b.area))
7657 goto return_did_out;
7659 case RSCN_ADDRESS_FORMAT_DOMAIN:
7660 if (ns_did.un.b.domain == rscn_did.un.b.domain)
7661 goto return_did_out;
7663 case RSCN_ADDRESS_FORMAT_FABRIC:
7664 goto return_did_out;
7668 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7669 vport->fc_rscn_flush = 0;
7672 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7673 vport->fc_rscn_flush = 0;
7678 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
7679 * @vport: pointer to a host virtual N_Port data structure.
7681 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
7682 * state machine for a @vport's nodes that are with pending RSCN (Registration
7683 * State Change Notification).
7686 * 0 - Successful (currently alway return 0)
7689 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
7691 struct lpfc_nodelist *ndlp = NULL, *n;
7693 /* Move all affected nodes by pending RSCNs to NPR state. */
7694 list_for_each_entry_safe(ndlp, n, &vport->fc_nodes, nlp_listp) {
7695 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
7696 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
7699 /* NVME Target mode does not do RSCN Recovery. */
7700 if (vport->phba->nvmet_support)
7703 /* If we are in the process of doing discovery on this
7704 * NPort, let it continue on its own.
7706 switch (ndlp->nlp_state) {
7707 case NLP_STE_PLOGI_ISSUE:
7708 case NLP_STE_ADISC_ISSUE:
7709 case NLP_STE_REG_LOGIN_ISSUE:
7710 case NLP_STE_PRLI_ISSUE:
7711 case NLP_STE_LOGO_ISSUE:
7715 lpfc_disc_state_machine(vport, ndlp, NULL,
7716 NLP_EVT_DEVICE_RECOVERY);
7717 lpfc_cancel_retry_delay_tmo(vport, ndlp);
7723 * lpfc_send_rscn_event - Send an RSCN event to management application
7724 * @vport: pointer to a host virtual N_Port data structure.
7725 * @cmdiocb: pointer to lpfc command iocb data structure.
7727 * lpfc_send_rscn_event sends an RSCN netlink event to management
7731 lpfc_send_rscn_event(struct lpfc_vport *vport,
7732 struct lpfc_iocbq *cmdiocb)
7734 struct lpfc_dmabuf *pcmd;
7735 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7736 uint32_t *payload_ptr;
7737 uint32_t payload_len;
7738 struct lpfc_rscn_event_header *rscn_event_data;
7740 pcmd = cmdiocb->cmd_dmabuf;
7741 payload_ptr = (uint32_t *) pcmd->virt;
7742 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
7744 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
7745 payload_len, GFP_KERNEL);
7746 if (!rscn_event_data) {
7747 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7748 "0147 Failed to allocate memory for RSCN event\n");
7751 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
7752 rscn_event_data->payload_length = payload_len;
7753 memcpy(rscn_event_data->rscn_payload, payload_ptr,
7756 fc_host_post_vendor_event(shost,
7757 fc_get_event_number(),
7758 sizeof(struct lpfc_rscn_event_header) + payload_len,
7759 (char *)rscn_event_data,
7762 kfree(rscn_event_data);
7766 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
7767 * @vport: pointer to a host virtual N_Port data structure.
7768 * @cmdiocb: pointer to lpfc command iocb data structure.
7769 * @ndlp: pointer to a node-list data structure.
7771 * This routine processes an unsolicited RSCN (Registration State Change
7772 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
7773 * to invoke fc_host_post_event() routine to the FC transport layer. If the
7774 * discover state machine is about to begin discovery, it just accepts the
7775 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
7776 * contains N_Port IDs for other vports on this HBA, it just accepts the
7777 * RSCN and ignore processing it. If the state machine is in the recovery
7778 * state, the fc_rscn_id_list of this @vport is walked and the
7779 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
7780 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
7781 * routine is invoked to handle the RSCN event.
7784 * 0 - Just sent the acc response
7785 * 1 - Sent the acc response and waited for name server completion
7788 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7789 struct lpfc_nodelist *ndlp)
7791 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7792 struct lpfc_hba *phba = vport->phba;
7793 struct lpfc_dmabuf *pcmd;
7794 uint32_t *lp, *datap;
7795 uint32_t payload_len, length, nportid, *cmd;
7797 int rscn_id = 0, hba_id = 0;
7800 pcmd = cmdiocb->cmd_dmabuf;
7801 lp = (uint32_t *) pcmd->virt;
7803 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7804 payload_len -= sizeof(uint32_t); /* take off word 0 */
7806 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7807 "0214 RSCN received Data: x%x x%x x%x x%x\n",
7808 vport->fc_flag, payload_len, *lp,
7809 vport->fc_rscn_id_cnt);
7811 /* Send an RSCN event to the management application */
7812 lpfc_send_rscn_event(vport, cmdiocb);
7814 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
7815 fc_host_post_event(shost, fc_get_event_number(),
7816 FCH_EVT_RSCN, lp[i]);
7818 /* Check if RSCN is coming from a direct-connected remote NPort */
7819 if (vport->fc_flag & FC_PT2PT) {
7820 /* If so, just ACC it, no other action needed for now */
7821 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7822 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
7823 *lp, vport->fc_flag, payload_len);
7824 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7826 /* Check to see if we need to NVME rescan this target
7829 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
7830 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
7831 lpfc_nvme_rescan_port(vport, ndlp);
7835 /* If we are about to begin discovery, just ACC the RSCN.
7836 * Discovery processing will satisfy it.
7838 if (vport->port_state <= LPFC_NS_QRY) {
7839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7840 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
7841 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7843 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7847 /* If this RSCN just contains NPortIDs for other vports on this HBA,
7848 * just ACC and ignore it.
7850 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7851 !(vport->cfg_peer_port_login)) {
7856 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
7857 i -= sizeof(uint32_t);
7859 if (lpfc_find_vport_by_did(phba, nportid))
7862 if (rscn_id == hba_id) {
7863 /* ALL NPortIDs in RSCN are on HBA */
7864 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7866 "Data: x%x x%x x%x x%x\n",
7867 vport->fc_flag, payload_len,
7868 *lp, vport->fc_rscn_id_cnt);
7869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7870 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
7871 ndlp->nlp_DID, vport->port_state,
7874 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
7876 /* Restart disctmo if its already running */
7877 if (vport->fc_flag & FC_DISC_TMO) {
7878 tmo = ((phba->fc_ratov * 3) + 3);
7879 mod_timer(&vport->fc_disctmo,
7881 msecs_to_jiffies(1000 * tmo));
7887 spin_lock_irq(shost->host_lock);
7888 if (vport->fc_rscn_flush) {
7889 /* Another thread is walking fc_rscn_id_list on this vport */
7890 vport->fc_flag |= FC_RSCN_DISCOVERY;
7891 spin_unlock_irq(shost->host_lock);
7893 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7896 /* Indicate we are walking fc_rscn_id_list on this vport */
7897 vport->fc_rscn_flush = 1;
7898 spin_unlock_irq(shost->host_lock);
7899 /* Get the array count after successfully have the token */
7900 rscn_cnt = vport->fc_rscn_id_cnt;
7901 /* If we are already processing an RSCN, save the received
7902 * RSCN payload buffer, cmdiocb->cmd_dmabuf to process later.
7904 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
7905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7906 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
7907 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7909 spin_lock_irq(shost->host_lock);
7910 vport->fc_flag |= FC_RSCN_DEFERRED;
7912 /* Restart disctmo if its already running */
7913 if (vport->fc_flag & FC_DISC_TMO) {
7914 tmo = ((phba->fc_ratov * 3) + 3);
7915 mod_timer(&vport->fc_disctmo,
7916 jiffies + msecs_to_jiffies(1000 * tmo));
7918 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
7919 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
7920 vport->fc_flag |= FC_RSCN_MODE;
7921 vport->fc_flag &= ~FC_RSCN_MEMENTO;
7922 spin_unlock_irq(shost->host_lock);
7924 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
7925 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
7928 (payload_len + length <= LPFC_BPL_SIZE)) {
7929 *cmd &= ELS_CMD_MASK;
7930 *cmd |= cpu_to_be32(payload_len + length);
7931 memcpy(((uint8_t *)cmd) + length, lp,
7934 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
7935 vport->fc_rscn_id_cnt++;
7936 /* If we zero, cmdiocb->cmd_dmabuf, the calling
7937 * routine will not try to free it.
7939 cmdiocb->cmd_dmabuf = NULL;
7942 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7943 "0235 Deferred RSCN "
7944 "Data: x%x x%x x%x\n",
7945 vport->fc_rscn_id_cnt, vport->fc_flag,
7948 vport->fc_flag |= FC_RSCN_DISCOVERY;
7949 spin_unlock_irq(shost->host_lock);
7950 /* ReDiscovery RSCN */
7951 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7952 "0234 ReDiscovery RSCN "
7953 "Data: x%x x%x x%x\n",
7954 vport->fc_rscn_id_cnt, vport->fc_flag,
7957 /* Indicate we are done walking fc_rscn_id_list on this vport */
7958 vport->fc_rscn_flush = 0;
7960 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7961 /* send RECOVERY event for ALL nodes that match RSCN payload */
7962 lpfc_rscn_recovery_check(vport);
7965 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7966 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
7967 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7969 spin_lock_irq(shost->host_lock);
7970 vport->fc_flag |= FC_RSCN_MODE;
7971 vport->fc_flag &= ~FC_RSCN_MEMENTO;
7972 spin_unlock_irq(shost->host_lock);
7973 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
7974 /* Indicate we are done walking fc_rscn_id_list on this vport */
7975 vport->fc_rscn_flush = 0;
7977 * If we zero, cmdiocb->cmd_dmabuf, the calling routine will
7978 * not try to free it.
7980 cmdiocb->cmd_dmabuf = NULL;
7981 lpfc_set_disctmo(vport);
7983 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7984 /* send RECOVERY event for ALL nodes that match RSCN payload */
7985 lpfc_rscn_recovery_check(vport);
7986 return lpfc_els_handle_rscn(vport);
7990 * lpfc_els_handle_rscn - Handle rscn for a vport
7991 * @vport: pointer to a host virtual N_Port data structure.
7993 * This routine handles the Registration State Configuration Notification
7994 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
7995 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
7996 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
7997 * NameServer shall be issued. If CT command to the NameServer fails to be
7998 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
7999 * RSCN activities with the @vport.
8002 * 0 - Cleaned up rscn on the @vport
8003 * 1 - Wait for plogi to name server before proceed
8006 lpfc_els_handle_rscn(struct lpfc_vport *vport)
8008 struct lpfc_nodelist *ndlp;
8009 struct lpfc_hba *phba = vport->phba;
8011 /* Ignore RSCN if the port is being torn down. */
8012 if (vport->load_flag & FC_UNLOADING) {
8013 lpfc_els_flush_rscn(vport);
8017 /* Start timer for RSCN processing */
8018 lpfc_set_disctmo(vport);
8020 /* RSCN processed */
8021 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8022 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
8023 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
8024 vport->port_state, vport->num_disc_nodes,
8027 /* To process RSCN, first compare RSCN data with NameServer */
8028 vport->fc_ns_retry = 0;
8029 vport->num_disc_nodes = 0;
8031 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8032 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
8033 /* Good ndlp, issue CT Request to NameServer. Need to
8034 * know how many gidfts were issued. If none, then just
8035 * flush the RSCN. Otherwise, the outstanding requests
8038 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
8039 if (lpfc_issue_gidft(vport) > 0)
8041 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
8042 if (lpfc_issue_gidpt(vport) > 0)
8048 /* Nameserver login in question. Revalidate. */
8050 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
8051 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8053 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8055 lpfc_els_flush_rscn(vport);
8058 ndlp->nlp_prev_state = ndlp->nlp_state;
8059 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8061 ndlp->nlp_type |= NLP_FABRIC;
8062 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
8063 /* Wait for NameServer login cmpl before we can
8069 lpfc_els_flush_rscn(vport);
8074 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
8075 * @vport: pointer to a host virtual N_Port data structure.
8076 * @cmdiocb: pointer to lpfc command iocb data structure.
8077 * @ndlp: pointer to a node-list data structure.
8079 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
8080 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
8081 * point topology. As an unsolicited FLOGI should not be received in a loop
8082 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
8083 * lpfc_check_sparm() routine is invoked to check the parameters in the
8084 * unsolicited FLOGI. If parameters validation failed, the routine
8085 * lpfc_els_rsp_reject() shall be called with reject reason code set to
8086 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
8087 * FLOGI shall be compared with the Port WWN of the @vport to determine who
8088 * will initiate PLOGI. The higher lexicographical value party shall has
8089 * higher priority (as the winning port) and will initiate PLOGI and
8090 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
8091 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
8092 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
8095 * 0 - Successfully processed the unsolicited flogi
8096 * 1 - Failed to process the unsolicited flogi
8099 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8100 struct lpfc_nodelist *ndlp)
8102 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8103 struct lpfc_hba *phba = vport->phba;
8104 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
8105 uint32_t *lp = (uint32_t *) pcmd->virt;
8106 union lpfc_wqe128 *wqe = &cmdiocb->wqe;
8107 struct serv_parm *sp;
8111 uint32_t fc_flag = 0;
8112 uint32_t port_state = 0;
8114 /* Clear external loopback plug detected flag */
8115 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
8118 sp = (struct serv_parm *) lp;
8120 /* FLOGI received */
8122 lpfc_set_disctmo(vport);
8124 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8125 /* We should never receive a FLOGI in loop mode, ignore it */
8126 did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
8128 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
8130 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8131 "0113 An FLOGI ELS command x%x was "
8132 "received from DID x%x in Loop Mode\n",
8137 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
8140 * If our portname is greater than the remote portname,
8141 * then we initiate Nport login.
8144 rc = memcmp(&vport->fc_portname, &sp->portName,
8145 sizeof(struct lpfc_name));
8148 if (phba->sli_rev < LPFC_SLI_REV4) {
8149 mbox = mempool_alloc(phba->mbox_mem_pool,
8153 lpfc_linkdown(phba);
8154 lpfc_init_link(phba, mbox,
8156 phba->cfg_link_speed);
8157 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8158 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8159 mbox->vport = vport;
8160 rc = lpfc_sli_issue_mbox(phba, mbox,
8162 lpfc_set_loopback_flag(phba);
8163 if (rc == MBX_NOT_FINISHED)
8164 mempool_free(mbox, phba->mbox_mem_pool);
8168 /* External loopback plug insertion detected */
8169 phba->link_flag |= LS_EXTERNAL_LOOPBACK;
8171 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_LIBDFC,
8172 "1119 External Loopback plug detected\n");
8174 /* abort the flogi coming back to ourselves
8175 * due to external loopback on the port.
8177 lpfc_els_abort_flogi(phba);
8180 } else if (rc > 0) { /* greater than */
8181 spin_lock_irq(shost->host_lock);
8182 vport->fc_flag |= FC_PT2PT_PLOGI;
8183 spin_unlock_irq(shost->host_lock);
8185 /* If we have the high WWPN we can assign our own
8186 * myDID; otherwise, we have to WAIT for a PLOGI
8187 * from the remote NPort to find out what it
8190 vport->fc_myDID = PT2PT_LocalID;
8192 vport->fc_myDID = PT2PT_RemoteID;
8196 * The vport state should go to LPFC_FLOGI only
8197 * AFTER we issue a FLOGI, not receive one.
8199 spin_lock_irq(shost->host_lock);
8200 fc_flag = vport->fc_flag;
8201 port_state = vport->port_state;
8202 vport->fc_flag |= FC_PT2PT;
8203 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8205 /* Acking an unsol FLOGI. Count 1 for link bounce
8208 vport->rcv_flogi_cnt++;
8209 spin_unlock_irq(shost->host_lock);
8210 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8211 "3311 Rcv Flogi PS x%x new PS x%x "
8212 "fc_flag x%x new fc_flag x%x\n",
8213 port_state, vport->port_state,
8214 fc_flag, vport->fc_flag);
8217 * We temporarily set fc_myDID to make it look like we are
8218 * a Fabric. This is done just so we end up with the right
8219 * did / sid on the FLOGI ACC rsp.
8221 did = vport->fc_myDID;
8222 vport->fc_myDID = Fabric_DID;
8224 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
8226 /* Defer ACC response until AFTER we issue a FLOGI */
8227 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
8228 phba->defer_flogi_acc_rx_id = bf_get(wqe_ctxt_tag,
8229 &wqe->xmit_els_rsp.wqe_com);
8230 phba->defer_flogi_acc_ox_id = bf_get(wqe_rcvoxid,
8231 &wqe->xmit_els_rsp.wqe_com);
8233 vport->fc_myDID = did;
8235 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8236 "3344 Deferring FLOGI ACC: rx_id: x%x,"
8237 " ox_id: x%x, hba_flag x%x\n",
8238 phba->defer_flogi_acc_rx_id,
8239 phba->defer_flogi_acc_ox_id, phba->hba_flag);
8241 phba->defer_flogi_acc_flag = true;
8247 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
8249 /* Now lets put fc_myDID back to what its supposed to be */
8250 vport->fc_myDID = did;
8256 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
8257 * @vport: pointer to a host virtual N_Port data structure.
8258 * @cmdiocb: pointer to lpfc command iocb data structure.
8259 * @ndlp: pointer to a node-list data structure.
8261 * This routine processes Request Node Identification Data (RNID) IOCB
8262 * received as an ELS unsolicited event. Only when the RNID specified format
8263 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
8264 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
8265 * Accept (ACC) the RNID ELS command. All the other RNID formats are
8266 * rejected by invoking the lpfc_els_rsp_reject() routine.
8269 * 0 - Successfully processed rnid iocb (currently always return 0)
8272 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8273 struct lpfc_nodelist *ndlp)
8275 struct lpfc_dmabuf *pcmd;
8280 pcmd = cmdiocb->cmd_dmabuf;
8281 lp = (uint32_t *) pcmd->virt;
8288 switch (rn->Format) {
8290 case RNID_TOPOLOGY_DISC:
8292 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
8295 /* Reject this request because format not supported */
8296 stat.un.b.lsRjtRsvd0 = 0;
8297 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8298 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8299 stat.un.b.vendorUnique = 0;
8300 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8307 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
8308 * @vport: pointer to a host virtual N_Port data structure.
8309 * @cmdiocb: pointer to lpfc command iocb data structure.
8310 * @ndlp: pointer to a node-list data structure.
8313 * 0 - Successfully processed echo iocb (currently always return 0)
8316 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8317 struct lpfc_nodelist *ndlp)
8321 pcmd = (uint8_t *)cmdiocb->cmd_dmabuf->virt;
8323 /* skip over first word of echo command to find echo data */
8324 pcmd += sizeof(uint32_t);
8326 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
8331 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
8332 * @vport: pointer to a host virtual N_Port data structure.
8333 * @cmdiocb: pointer to lpfc command iocb data structure.
8334 * @ndlp: pointer to a node-list data structure.
8336 * This routine processes a Link Incident Report Registration(LIRR) IOCB
8337 * received as an ELS unsolicited event. Currently, this function just invokes
8338 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
8341 * 0 - Successfully processed lirr iocb (currently always return 0)
8344 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8345 struct lpfc_nodelist *ndlp)
8349 /* For now, unconditionally reject this command */
8350 stat.un.b.lsRjtRsvd0 = 0;
8351 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8352 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8353 stat.un.b.vendorUnique = 0;
8354 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8359 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
8360 * @vport: pointer to a host virtual N_Port data structure.
8361 * @cmdiocb: pointer to lpfc command iocb data structure.
8362 * @ndlp: pointer to a node-list data structure.
8364 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
8365 * received as an ELS unsolicited event. A request to RRQ shall only
8366 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
8367 * Nx_Port N_Port_ID of the target Exchange is the same as the
8368 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
8369 * not accepted, an LS_RJT with reason code "Unable to perform
8370 * command request" and reason code explanation "Invalid Originator
8371 * S_ID" shall be returned. For now, we just unconditionally accept
8372 * RRQ from the target.
8375 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8376 struct lpfc_nodelist *ndlp)
8378 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8379 if (vport->phba->sli_rev == LPFC_SLI_REV4)
8380 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
8384 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
8385 * @phba: pointer to lpfc hba data structure.
8386 * @pmb: pointer to the driver internal queue element for mailbox command.
8388 * This routine is the completion callback function for the MBX_READ_LNK_STAT
8389 * mailbox command. This callback function is to actually send the Accept
8390 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
8391 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
8392 * mailbox command, constructs the RLS response with the link statistics
8393 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
8394 * response to the RLS.
8396 * Note that the ndlp reference count will be incremented by 1 for holding the
8397 * ndlp and the reference to ndlp will be stored into the ndlp field of
8398 * the IOCB for the completion callback function to the RLS Accept Response
8403 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8408 union lpfc_wqe128 *wqe;
8409 struct RLS_RSP *rls_rsp;
8411 struct lpfc_iocbq *elsiocb;
8412 struct lpfc_nodelist *ndlp;
8420 ndlp = pmb->ctx_ndlp;
8421 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
8422 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
8423 pmb->ctx_buf = NULL;
8424 pmb->ctx_ndlp = NULL;
8426 if (mb->mbxStatus) {
8427 mempool_free(pmb, phba->mbox_mem_pool);
8431 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
8432 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8433 lpfc_max_els_tries, ndlp,
8434 ndlp->nlp_DID, ELS_CMD_ACC);
8436 /* Decrement the ndlp reference count from previous mbox command */
8440 mempool_free(pmb, phba->mbox_mem_pool);
8444 ulp_context = get_job_ulpcontext(phba, elsiocb);
8445 if (phba->sli_rev == LPFC_SLI_REV4) {
8446 wqe = &elsiocb->wqe;
8448 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, rxid);
8449 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, oxid);
8451 icmd = &elsiocb->iocb;
8452 icmd->ulpContext = rxid;
8453 icmd->unsli3.rcvsli3.ox_id = oxid;
8456 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8457 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8458 pcmd += sizeof(uint32_t); /* Skip past command */
8459 rls_rsp = (struct RLS_RSP *)pcmd;
8461 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
8462 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
8463 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
8464 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
8465 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
8466 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
8467 mempool_free(pmb, phba->mbox_mem_pool);
8468 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8469 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8470 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
8471 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
8472 elsiocb->iotag, ulp_context,
8473 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8475 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8476 phba->fc_stat.elsXmitACC++;
8477 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8478 if (!elsiocb->ndlp) {
8479 lpfc_els_free_iocb(phba, elsiocb);
8483 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8484 if (rc == IOCB_ERROR) {
8485 lpfc_els_free_iocb(phba, elsiocb);
8492 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
8493 * @vport: pointer to a host virtual N_Port data structure.
8494 * @cmdiocb: pointer to lpfc command iocb data structure.
8495 * @ndlp: pointer to a node-list data structure.
8497 * This routine processes Read Link Status (RLS) IOCB received as an
8498 * ELS unsolicited event. It first checks the remote port state. If the
8499 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8500 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8501 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
8502 * for reading the HBA link statistics. It is for the callback function,
8503 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
8504 * to actually sending out RPL Accept (ACC) response.
8507 * 0 - Successfully processed rls iocb (currently always return 0)
8510 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8511 struct lpfc_nodelist *ndlp)
8513 struct lpfc_hba *phba = vport->phba;
8516 u32 ctx = get_job_ulpcontext(phba, cmdiocb);
8517 u32 ox_id = get_job_rcvoxid(phba, cmdiocb);
8519 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8520 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8521 /* reject the unsolicited RLS request and done with it */
8524 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
8526 lpfc_read_lnk_stat(phba, mbox);
8527 mbox->ctx_buf = (void *)((unsigned long)
8528 (ox_id << 16 | ctx));
8529 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
8530 if (!mbox->ctx_ndlp)
8532 mbox->vport = vport;
8533 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
8534 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8535 != MBX_NOT_FINISHED)
8536 /* Mbox completion will send ELS Response */
8538 /* Decrement reference count used for the failed mbox
8543 mempool_free(mbox, phba->mbox_mem_pool);
8546 /* issue rejection response */
8547 stat.un.b.lsRjtRsvd0 = 0;
8548 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8549 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8550 stat.un.b.vendorUnique = 0;
8551 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8556 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
8557 * @vport: pointer to a host virtual N_Port data structure.
8558 * @cmdiocb: pointer to lpfc command iocb data structure.
8559 * @ndlp: pointer to a node-list data structure.
8561 * This routine processes Read Timout Value (RTV) IOCB received as an
8562 * ELS unsolicited event. It first checks the remote port state. If the
8563 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8564 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8565 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
8566 * Value (RTV) unsolicited IOCB event.
8568 * Note that the ndlp reference count will be incremented by 1 for holding the
8569 * ndlp and the reference to ndlp will be stored into the ndlp field of
8570 * the IOCB for the completion callback function to the RTV Accept Response
8574 * 0 - Successfully processed rtv iocb (currently always return 0)
8577 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8578 struct lpfc_nodelist *ndlp)
8582 union lpfc_wqe128 *wqe;
8583 struct lpfc_hba *phba = vport->phba;
8585 struct RTV_RSP *rtv_rsp;
8587 struct lpfc_iocbq *elsiocb;
8591 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8592 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8593 /* reject the unsolicited RTV request and done with it */
8596 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
8597 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8598 lpfc_max_els_tries, ndlp,
8599 ndlp->nlp_DID, ELS_CMD_ACC);
8604 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8605 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8606 pcmd += sizeof(uint32_t); /* Skip past command */
8608 ulp_context = get_job_ulpcontext(phba, elsiocb);
8609 /* use the command's xri in the response */
8610 if (phba->sli_rev == LPFC_SLI_REV4) {
8611 wqe = &elsiocb->wqe;
8612 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
8613 get_job_ulpcontext(phba, cmdiocb));
8614 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8615 get_job_rcvoxid(phba, cmdiocb));
8617 icmd = &elsiocb->iocb;
8618 icmd->ulpContext = get_job_ulpcontext(phba, cmdiocb);
8619 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, cmdiocb);
8622 rtv_rsp = (struct RTV_RSP *)pcmd;
8624 /* populate RTV payload */
8625 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
8626 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
8627 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
8628 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
8629 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
8631 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8632 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8633 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
8634 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
8635 "Data: x%x x%x x%x\n",
8636 elsiocb->iotag, ulp_context,
8637 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8639 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
8640 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8641 phba->fc_stat.elsXmitACC++;
8642 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8643 if (!elsiocb->ndlp) {
8644 lpfc_els_free_iocb(phba, elsiocb);
8648 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8649 if (rc == IOCB_ERROR) {
8650 lpfc_els_free_iocb(phba, elsiocb);
8656 /* issue rejection response */
8657 stat.un.b.lsRjtRsvd0 = 0;
8658 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8659 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8660 stat.un.b.vendorUnique = 0;
8661 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8665 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
8666 * @vport: pointer to a host virtual N_Port data structure.
8667 * @ndlp: pointer to a node-list data structure.
8668 * @did: DID of the target.
8669 * @rrq: Pointer to the rrq struct.
8671 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
8672 * Successful the the completion handler will clear the RRQ.
8675 * 0 - Successfully sent rrq els iocb.
8676 * 1 - Failed to send rrq els iocb.
8679 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8680 uint32_t did, struct lpfc_node_rrq *rrq)
8682 struct lpfc_hba *phba = vport->phba;
8683 struct RRQ *els_rrq;
8684 struct lpfc_iocbq *elsiocb;
8692 /* If ndlp is not NULL, we will bump the reference count on it */
8693 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
8694 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
8699 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8701 /* For RRQ request, remainder of payload is Exchange IDs */
8702 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
8703 pcmd += sizeof(uint32_t);
8704 els_rrq = (struct RRQ *) pcmd;
8706 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
8707 bf_set(rrq_rxid, els_rrq, rrq->rxid);
8708 bf_set(rrq_did, els_rrq, vport->fc_myDID);
8709 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
8710 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
8713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8714 "Issue RRQ: did:x%x",
8715 did, rrq->xritag, rrq->rxid);
8716 elsiocb->context_un.rrq = rrq;
8717 elsiocb->cmd_cmpl = lpfc_cmpl_els_rrq;
8719 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8723 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8724 if (ret == IOCB_ERROR) {
8731 lpfc_els_free_iocb(phba, elsiocb);
8736 * lpfc_send_rrq - Sends ELS RRQ if needed.
8737 * @phba: pointer to lpfc hba data structure.
8738 * @rrq: pointer to the active rrq.
8740 * This routine will call the lpfc_issue_els_rrq if the rrq is
8741 * still active for the xri. If this function returns a failure then
8742 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
8744 * Returns 0 Success.
8748 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
8750 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
8755 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
8756 return lpfc_issue_els_rrq(rrq->vport, ndlp,
8763 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
8764 * @vport: pointer to a host virtual N_Port data structure.
8765 * @cmdsize: size of the ELS command.
8766 * @oldiocb: pointer to the original lpfc command iocb data structure.
8767 * @ndlp: pointer to a node-list data structure.
8769 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
8770 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
8772 * Note that the ndlp reference count will be incremented by 1 for holding the
8773 * ndlp and the reference to ndlp will be stored into the ndlp field of
8774 * the IOCB for the completion callback function to the RPL Accept Response
8778 * 0 - Successfully issued ACC RPL ELS command
8779 * 1 - Failed to issue ACC RPL ELS command
8782 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
8783 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
8786 struct lpfc_hba *phba = vport->phba;
8788 union lpfc_wqe128 *wqe;
8790 struct lpfc_iocbq *elsiocb;
8794 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
8795 ndlp->nlp_DID, ELS_CMD_ACC);
8800 ulp_context = get_job_ulpcontext(phba, elsiocb);
8801 if (phba->sli_rev == LPFC_SLI_REV4) {
8802 wqe = &elsiocb->wqe;
8804 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
8805 get_job_ulpcontext(phba, oldiocb));
8806 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8807 get_job_rcvoxid(phba, oldiocb));
8809 icmd = &elsiocb->iocb;
8810 icmd->ulpContext = get_job_ulpcontext(phba, oldiocb);
8811 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, oldiocb);
8814 pcmd = elsiocb->cmd_dmabuf->virt;
8815 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8816 pcmd += sizeof(uint16_t);
8817 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
8818 pcmd += sizeof(uint16_t);
8820 /* Setup the RPL ACC payload */
8821 rpl_rsp.listLen = be32_to_cpu(1);
8823 rpl_rsp.port_num_blk.portNum = 0;
8824 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
8825 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
8826 sizeof(struct lpfc_name));
8827 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
8828 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
8829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8830 "0120 Xmit ELS RPL ACC response tag x%x "
8831 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
8833 elsiocb->iotag, ulp_context,
8834 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8836 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8837 phba->fc_stat.elsXmitACC++;
8838 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8839 if (!elsiocb->ndlp) {
8840 lpfc_els_free_iocb(phba, elsiocb);
8844 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8845 if (rc == IOCB_ERROR) {
8846 lpfc_els_free_iocb(phba, elsiocb);
8855 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
8856 * @vport: pointer to a host virtual N_Port data structure.
8857 * @cmdiocb: pointer to lpfc command iocb data structure.
8858 * @ndlp: pointer to a node-list data structure.
8860 * This routine processes Read Port List (RPL) IOCB received as an ELS
8861 * unsolicited event. It first checks the remote port state. If the remote
8862 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
8863 * invokes the lpfc_els_rsp_reject() routine to send reject response.
8864 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
8865 * to accept the RPL.
8868 * 0 - Successfully processed rpl iocb (currently always return 0)
8871 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8872 struct lpfc_nodelist *ndlp)
8874 struct lpfc_dmabuf *pcmd;
8881 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8882 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
8883 /* issue rejection response */
8884 stat.un.b.lsRjtRsvd0 = 0;
8885 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8886 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8887 stat.un.b.vendorUnique = 0;
8888 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8890 /* rejected the unsolicited RPL request and done with it */
8894 pcmd = cmdiocb->cmd_dmabuf;
8895 lp = (uint32_t *) pcmd->virt;
8896 rpl = (RPL *) (lp + 1);
8897 maxsize = be32_to_cpu(rpl->maxsize);
8899 /* We support only one port */
8900 if ((rpl->index == 0) &&
8902 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
8903 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
8905 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
8907 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
8913 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
8914 * @vport: pointer to a virtual N_Port data structure.
8915 * @cmdiocb: pointer to lpfc command iocb data structure.
8916 * @ndlp: pointer to a node-list data structure.
8918 * This routine processes Fibre Channel Address Resolution Protocol
8919 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
8920 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
8921 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
8922 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
8923 * remote PortName is compared against the FC PortName stored in the @vport
8924 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
8925 * compared against the FC NodeName stored in the @vport data structure.
8926 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
8927 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
8928 * invoked to send out FARP Response to the remote node. Before sending the
8929 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
8930 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
8931 * routine is invoked to log into the remote port first.
8934 * 0 - Either the FARP Match Mode not supported or successfully processed
8937 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8938 struct lpfc_nodelist *ndlp)
8940 struct lpfc_dmabuf *pcmd;
8945 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
8946 pcmd = cmdiocb->cmd_dmabuf;
8947 lp = (uint32_t *) pcmd->virt;
8951 /* FARP-REQ received from DID <did> */
8952 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8953 "0601 FARP-REQ received from DID x%x\n", did);
8954 /* We will only support match on WWPN or WWNN */
8955 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
8960 /* If this FARP command is searching for my portname */
8961 if (fp->Mflags & FARP_MATCH_PORT) {
8962 if (memcmp(&fp->RportName, &vport->fc_portname,
8963 sizeof(struct lpfc_name)) == 0)
8967 /* If this FARP command is searching for my nodename */
8968 if (fp->Mflags & FARP_MATCH_NODE) {
8969 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
8970 sizeof(struct lpfc_name)) == 0)
8975 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
8976 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
8977 /* Log back into the node before sending the FARP. */
8978 if (fp->Rflags & FARP_REQUEST_PLOGI) {
8979 ndlp->nlp_prev_state = ndlp->nlp_state;
8980 lpfc_nlp_set_state(vport, ndlp,
8981 NLP_STE_PLOGI_ISSUE);
8982 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8985 /* Send a FARP response to that node */
8986 if (fp->Rflags & FARP_REQUEST_FARPR)
8987 lpfc_issue_els_farpr(vport, did, 0);
8994 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
8995 * @vport: pointer to a host virtual N_Port data structure.
8996 * @cmdiocb: pointer to lpfc command iocb data structure.
8997 * @ndlp: pointer to a node-list data structure.
8999 * This routine processes Fibre Channel Address Resolution Protocol
9000 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
9001 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
9002 * the FARP response request.
9005 * 0 - Successfully processed FARPR IOCB (currently always return 0)
9008 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9009 struct lpfc_nodelist *ndlp)
9011 struct lpfc_dmabuf *pcmd;
9015 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
9016 pcmd = cmdiocb->cmd_dmabuf;
9017 lp = (uint32_t *)pcmd->virt;
9020 /* FARP-RSP received from DID <did> */
9021 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9022 "0600 FARP-RSP received from DID x%x\n", did);
9023 /* ACCEPT the Farp resp request */
9024 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
9030 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
9031 * @vport: pointer to a host virtual N_Port data structure.
9032 * @cmdiocb: pointer to lpfc command iocb data structure.
9033 * @fan_ndlp: pointer to a node-list data structure.
9035 * This routine processes a Fabric Address Notification (FAN) IOCB
9036 * command received as an ELS unsolicited event. The FAN ELS command will
9037 * only be processed on a physical port (i.e., the @vport represents the
9038 * physical port). The fabric NodeName and PortName from the FAN IOCB are
9039 * compared against those in the phba data structure. If any of those is
9040 * different, the lpfc_initial_flogi() routine is invoked to initialize
9041 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
9042 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
9043 * is invoked to register login to the fabric.
9046 * 0 - Successfully processed fan iocb (currently always return 0).
9049 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9050 struct lpfc_nodelist *fan_ndlp)
9052 struct lpfc_hba *phba = vport->phba;
9056 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
9057 lp = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
9059 /* FAN received; Fan does not have a reply sequence */
9060 if ((vport == phba->pport) &&
9061 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
9062 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
9063 sizeof(struct lpfc_name))) ||
9064 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
9065 sizeof(struct lpfc_name)))) {
9066 /* This port has switched fabrics. FLOGI is required */
9067 lpfc_issue_init_vfi(vport);
9069 /* FAN verified - skip FLOGI */
9070 vport->fc_myDID = vport->fc_prevDID;
9071 if (phba->sli_rev < LPFC_SLI_REV4)
9072 lpfc_issue_fabric_reglogin(vport);
9074 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9075 "3138 Need register VFI: (x%x/%x)\n",
9076 vport->fc_prevDID, vport->fc_myDID);
9077 lpfc_issue_reg_vfi(vport);
9085 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb
9086 * @vport: pointer to a host virtual N_Port data structure.
9087 * @cmdiocb: pointer to lpfc command iocb data structure.
9088 * @ndlp: pointer to a node-list data structure.
9091 * 0 - Successfully processed echo iocb (currently always return 0)
9094 lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9095 struct lpfc_nodelist *ndlp)
9097 struct lpfc_hba *phba = vport->phba;
9098 struct fc_els_edc *edc_req;
9099 struct fc_tlv_desc *tlv;
9101 uint32_t *ptr, dtag;
9102 const char *dtag_nm;
9103 int desc_cnt = 0, bytes_remain;
9104 bool rcv_cap_desc = false;
9106 payload = cmdiocb->cmd_dmabuf->virt;
9108 edc_req = (struct fc_els_edc *)payload;
9109 bytes_remain = be32_to_cpu(edc_req->desc_len);
9111 ptr = (uint32_t *)payload;
9112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
9113 "3319 Rcv EDC payload len %d: x%x x%x x%x\n",
9114 bytes_remain, be32_to_cpu(*ptr),
9115 be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2)));
9117 /* No signal support unless there is a congestion descriptor */
9118 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9119 phba->cgn_sig_freq = 0;
9120 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
9122 if (bytes_remain <= 0)
9125 tlv = edc_req->desc;
9128 * cycle through EDC diagnostic descriptors to find the
9129 * congestion signaling capability descriptor
9131 while (bytes_remain && !rcv_cap_desc) {
9132 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
9133 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9134 "6464 Truncated TLV hdr on "
9135 "Diagnostic descriptor[%d]\n",
9140 dtag = be32_to_cpu(tlv->desc_tag);
9142 case ELS_DTAG_LNK_FAULT_CAP:
9143 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9144 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9145 sizeof(struct fc_diag_lnkflt_desc)) {
9147 phba, KERN_WARNING, LOG_CGN_MGMT,
9148 "6465 Truncated Link Fault Diagnostic "
9149 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9150 desc_cnt, bytes_remain,
9151 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9152 sizeof(struct fc_diag_cg_sig_desc));
9155 /* No action for Link Fault descriptor for now */
9157 case ELS_DTAG_CG_SIGNAL_CAP:
9158 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9159 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9160 sizeof(struct fc_diag_cg_sig_desc)) {
9162 phba, KERN_WARNING, LOG_CGN_MGMT,
9163 "6466 Truncated cgn signal Diagnostic "
9164 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9165 desc_cnt, bytes_remain,
9166 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9167 sizeof(struct fc_diag_cg_sig_desc));
9171 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
9172 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
9174 /* We start negotiation with lpfc_fabric_cgn_frequency.
9175 * When we process the EDC, we will settle on the
9178 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9180 lpfc_least_capable_settings(
9181 phba, (struct fc_diag_cg_sig_desc *)tlv);
9182 rcv_cap_desc = true;
9185 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
9186 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9187 "6467 unknown Diagnostic "
9188 "Descriptor[%d]: tag x%x (%s)\n",
9189 desc_cnt, dtag, dtag_nm);
9191 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
9192 tlv = fc_tlv_next_desc(tlv);
9196 /* Need to send back an ACC */
9197 lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp);
9199 lpfc_config_cgn_signal(phba);
9204 * lpfc_els_timeout - Handler funciton to the els timer
9205 * @t: timer context used to obtain the vport.
9207 * This routine is invoked by the ELS timer after timeout. It posts the ELS
9208 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
9209 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
9210 * up the worker thread. It is for the worker thread to invoke the routine
9211 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
9214 lpfc_els_timeout(struct timer_list *t)
9216 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
9217 struct lpfc_hba *phba = vport->phba;
9218 uint32_t tmo_posted;
9219 unsigned long iflag;
9221 spin_lock_irqsave(&vport->work_port_lock, iflag);
9222 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
9223 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
9224 vport->work_port_events |= WORKER_ELS_TMO;
9225 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
9227 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
9228 lpfc_worker_wake_up(phba);
9234 * lpfc_els_timeout_handler - Process an els timeout event
9235 * @vport: pointer to a virtual N_Port data structure.
9237 * This routine is the actual handler function that processes an ELS timeout
9238 * event. It walks the ELS ring to get and abort all the IOCBs (except the
9239 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
9240 * invoking the lpfc_sli_issue_abort_iotag() routine.
9243 lpfc_els_timeout_handler(struct lpfc_vport *vport)
9245 struct lpfc_hba *phba = vport->phba;
9246 struct lpfc_sli_ring *pring;
9247 struct lpfc_iocbq *tmp_iocb, *piocb;
9249 struct lpfc_dmabuf *pcmd;
9250 uint32_t els_command = 0;
9252 uint32_t remote_ID = 0xffffffff;
9253 LIST_HEAD(abort_list);
9254 u32 ulp_command = 0, ulp_context = 0, did = 0, iotag = 0;
9257 timeout = (uint32_t)(phba->fc_ratov << 1);
9259 pring = lpfc_phba_elsring(phba);
9260 if (unlikely(!pring))
9263 if (phba->pport->load_flag & FC_UNLOADING)
9266 spin_lock_irq(&phba->hbalock);
9267 if (phba->sli_rev == LPFC_SLI_REV4)
9268 spin_lock(&pring->ring_lock);
9270 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9271 ulp_command = get_job_cmnd(phba, piocb);
9272 ulp_context = get_job_ulpcontext(phba, piocb);
9273 did = get_job_els_rsp64_did(phba, piocb);
9275 if (phba->sli_rev == LPFC_SLI_REV4) {
9276 iotag = get_wqe_reqtag(piocb);
9279 iotag = cmd->ulpIoTag;
9282 if ((piocb->cmd_flag & LPFC_IO_LIBDFC) != 0 ||
9283 ulp_command == CMD_ABORT_XRI_CX ||
9284 ulp_command == CMD_ABORT_XRI_CN ||
9285 ulp_command == CMD_CLOSE_XRI_CN)
9288 if (piocb->vport != vport)
9291 pcmd = piocb->cmd_dmabuf;
9293 els_command = *(uint32_t *) (pcmd->virt);
9295 if (els_command == ELS_CMD_FARP ||
9296 els_command == ELS_CMD_FARPR ||
9297 els_command == ELS_CMD_FDISC)
9300 if (piocb->drvrTimeout > 0) {
9301 if (piocb->drvrTimeout >= timeout)
9302 piocb->drvrTimeout -= timeout;
9304 piocb->drvrTimeout = 0;
9308 remote_ID = 0xffffffff;
9309 if (ulp_command != CMD_GEN_REQUEST64_CR) {
9312 struct lpfc_nodelist *ndlp;
9313 ndlp = __lpfc_findnode_rpi(vport, ulp_context);
9315 remote_ID = ndlp->nlp_DID;
9317 list_add_tail(&piocb->dlist, &abort_list);
9319 if (phba->sli_rev == LPFC_SLI_REV4)
9320 spin_unlock(&pring->ring_lock);
9321 spin_unlock_irq(&phba->hbalock);
9323 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9324 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9325 "0127 ELS timeout Data: x%x x%x x%x "
9326 "x%x\n", els_command,
9327 remote_ID, ulp_command, iotag);
9329 spin_lock_irq(&phba->hbalock);
9330 list_del_init(&piocb->dlist);
9331 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9332 spin_unlock_irq(&phba->hbalock);
9335 /* Make sure HBA is alive */
9336 lpfc_issue_hb_tmo(phba);
9338 if (!list_empty(&pring->txcmplq))
9339 if (!(phba->pport->load_flag & FC_UNLOADING))
9340 mod_timer(&vport->els_tmofunc,
9341 jiffies + msecs_to_jiffies(1000 * timeout));
9345 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
9346 * @vport: pointer to a host virtual N_Port data structure.
9348 * This routine is used to clean up all the outstanding ELS commands on a
9349 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
9350 * routine. After that, it walks the ELS transmit queue to remove all the
9351 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
9352 * the IOCBs with a non-NULL completion callback function, the callback
9353 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9354 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
9355 * callback function, the IOCB will simply be released. Finally, it walks
9356 * the ELS transmit completion queue to issue an abort IOCB to any transmit
9357 * completion queue IOCB that is associated with the @vport and is not
9358 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
9359 * part of the discovery state machine) out to HBA by invoking the
9360 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
9361 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
9362 * the IOCBs are aborted when this function returns.
9365 lpfc_els_flush_cmd(struct lpfc_vport *vport)
9367 LIST_HEAD(abort_list);
9368 struct lpfc_hba *phba = vport->phba;
9369 struct lpfc_sli_ring *pring;
9370 struct lpfc_iocbq *tmp_iocb, *piocb;
9372 unsigned long iflags = 0;
9374 lpfc_fabric_abort_vport(vport);
9377 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
9378 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
9379 * ultimately grabs the ring_lock, the driver must splice the list into
9380 * a working list and release the locks before calling the abort.
9382 spin_lock_irqsave(&phba->hbalock, iflags);
9383 pring = lpfc_phba_elsring(phba);
9385 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
9386 if (unlikely(!pring)) {
9387 spin_unlock_irqrestore(&phba->hbalock, iflags);
9391 if (phba->sli_rev == LPFC_SLI_REV4)
9392 spin_lock(&pring->ring_lock);
9394 /* First we need to issue aborts to outstanding cmds on txcmpl */
9395 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9396 if (piocb->cmd_flag & LPFC_IO_LIBDFC)
9399 if (piocb->vport != vport)
9402 if (piocb->cmd_flag & LPFC_DRIVER_ABORTED)
9405 /* On the ELS ring we can have ELS_REQUESTs or
9406 * GEN_REQUESTs waiting for a response.
9408 ulp_command = get_job_cmnd(phba, piocb);
9409 if (ulp_command == CMD_ELS_REQUEST64_CR) {
9410 list_add_tail(&piocb->dlist, &abort_list);
9412 /* If the link is down when flushing ELS commands
9413 * the firmware will not complete them till after
9414 * the link comes back up. This may confuse
9415 * discovery for the new link up, so we need to
9416 * change the compl routine to just clean up the iocb
9417 * and avoid any retry logic.
9419 if (phba->link_state == LPFC_LINK_DOWN)
9420 piocb->cmd_cmpl = lpfc_cmpl_els_link_down;
9422 if (ulp_command == CMD_GEN_REQUEST64_CR)
9423 list_add_tail(&piocb->dlist, &abort_list);
9426 if (phba->sli_rev == LPFC_SLI_REV4)
9427 spin_unlock(&pring->ring_lock);
9428 spin_unlock_irqrestore(&phba->hbalock, iflags);
9430 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
9431 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9432 spin_lock_irqsave(&phba->hbalock, iflags);
9433 list_del_init(&piocb->dlist);
9434 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9435 spin_unlock_irqrestore(&phba->hbalock, iflags);
9437 /* Make sure HBA is alive */
9438 lpfc_issue_hb_tmo(phba);
9440 if (!list_empty(&abort_list))
9441 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9442 "3387 abort list for txq not empty\n");
9443 INIT_LIST_HEAD(&abort_list);
9445 spin_lock_irqsave(&phba->hbalock, iflags);
9446 if (phba->sli_rev == LPFC_SLI_REV4)
9447 spin_lock(&pring->ring_lock);
9449 /* No need to abort the txq list,
9450 * just queue them up for lpfc_sli_cancel_iocbs
9452 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
9453 ulp_command = get_job_cmnd(phba, piocb);
9455 if (piocb->cmd_flag & LPFC_IO_LIBDFC)
9458 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
9459 if (ulp_command == CMD_QUE_RING_BUF_CN ||
9460 ulp_command == CMD_QUE_RING_BUF64_CN ||
9461 ulp_command == CMD_CLOSE_XRI_CN ||
9462 ulp_command == CMD_ABORT_XRI_CN ||
9463 ulp_command == CMD_ABORT_XRI_CX)
9466 if (piocb->vport != vport)
9469 list_del_init(&piocb->list);
9470 list_add_tail(&piocb->list, &abort_list);
9473 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
9474 if (vport == phba->pport) {
9475 list_for_each_entry_safe(piocb, tmp_iocb,
9476 &phba->fabric_iocb_list, list) {
9477 list_del_init(&piocb->list);
9478 list_add_tail(&piocb->list, &abort_list);
9482 if (phba->sli_rev == LPFC_SLI_REV4)
9483 spin_unlock(&pring->ring_lock);
9484 spin_unlock_irqrestore(&phba->hbalock, iflags);
9486 /* Cancel all the IOCBs from the completions list */
9487 lpfc_sli_cancel_iocbs(phba, &abort_list,
9488 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
9494 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
9495 * @phba: pointer to lpfc hba data structure.
9497 * This routine is used to clean up all the outstanding ELS commands on a
9498 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
9499 * routine. After that, it walks the ELS transmit queue to remove all the
9500 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
9501 * the IOCBs with the completion callback function associated, the callback
9502 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9503 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
9504 * callback function associated, the IOCB will simply be released. Finally,
9505 * it walks the ELS transmit completion queue to issue an abort IOCB to any
9506 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
9507 * management plane IOCBs that are not part of the discovery state machine)
9508 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
9511 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
9513 struct lpfc_vport *vport;
9515 spin_lock_irq(&phba->port_list_lock);
9516 list_for_each_entry(vport, &phba->port_list, listentry)
9517 lpfc_els_flush_cmd(vport);
9518 spin_unlock_irq(&phba->port_list_lock);
9524 * lpfc_send_els_failure_event - Posts an ELS command failure event
9525 * @phba: Pointer to hba context object.
9526 * @cmdiocbp: Pointer to command iocb which reported error.
9527 * @rspiocbp: Pointer to response iocb which reported error.
9529 * This function sends an event when there is an ELS command
9533 lpfc_send_els_failure_event(struct lpfc_hba *phba,
9534 struct lpfc_iocbq *cmdiocbp,
9535 struct lpfc_iocbq *rspiocbp)
9537 struct lpfc_vport *vport = cmdiocbp->vport;
9538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9539 struct lpfc_lsrjt_event lsrjt_event;
9540 struct lpfc_fabric_event_header fabric_event;
9542 struct lpfc_nodelist *ndlp;
9544 u32 ulp_status, ulp_word4;
9546 ndlp = cmdiocbp->ndlp;
9550 ulp_status = get_job_ulpstatus(phba, rspiocbp);
9551 ulp_word4 = get_job_word4(phba, rspiocbp);
9553 if (ulp_status == IOSTAT_LS_RJT) {
9554 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
9555 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
9556 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
9557 sizeof(struct lpfc_name));
9558 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
9559 sizeof(struct lpfc_name));
9560 pcmd = (uint32_t *)cmdiocbp->cmd_dmabuf->virt;
9561 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
9562 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
9563 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
9564 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
9565 fc_host_post_vendor_event(shost,
9566 fc_get_event_number(),
9567 sizeof(lsrjt_event),
9568 (char *)&lsrjt_event,
9572 if (ulp_status == IOSTAT_NPORT_BSY ||
9573 ulp_status == IOSTAT_FABRIC_BSY) {
9574 fabric_event.event_type = FC_REG_FABRIC_EVENT;
9575 if (ulp_status == IOSTAT_NPORT_BSY)
9576 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
9578 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
9579 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
9580 sizeof(struct lpfc_name));
9581 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
9582 sizeof(struct lpfc_name));
9583 fc_host_post_vendor_event(shost,
9584 fc_get_event_number(),
9585 sizeof(fabric_event),
9586 (char *)&fabric_event,
9594 * lpfc_send_els_event - Posts unsolicited els event
9595 * @vport: Pointer to vport object.
9596 * @ndlp: Pointer FC node object.
9597 * @payload: ELS command code type.
9599 * This function posts an event when there is an incoming
9600 * unsolicited ELS command.
9603 lpfc_send_els_event(struct lpfc_vport *vport,
9604 struct lpfc_nodelist *ndlp,
9607 struct lpfc_els_event_header *els_data = NULL;
9608 struct lpfc_logo_event *logo_data = NULL;
9609 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9611 if (*payload == ELS_CMD_LOGO) {
9612 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
9614 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9615 "0148 Failed to allocate memory "
9616 "for LOGO event\n");
9619 els_data = &logo_data->header;
9621 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
9624 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9625 "0149 Failed to allocate memory "
9630 els_data->event_type = FC_REG_ELS_EVENT;
9633 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
9636 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
9639 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
9642 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
9643 /* Copy the WWPN in the LOGO payload */
9644 memcpy(logo_data->logo_wwpn, &payload[2],
9645 sizeof(struct lpfc_name));
9651 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
9652 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
9653 if (*payload == ELS_CMD_LOGO) {
9654 fc_host_post_vendor_event(shost,
9655 fc_get_event_number(),
9656 sizeof(struct lpfc_logo_event),
9661 fc_host_post_vendor_event(shost,
9662 fc_get_event_number(),
9663 sizeof(struct lpfc_els_event_header),
9673 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
9674 FC_FPIN_LI_EVT_TYPES_INIT);
9676 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types,
9677 FC_FPIN_DELI_EVT_TYPES_INIT);
9679 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types,
9680 FC_FPIN_CONGN_EVT_TYPES_INIT);
9682 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm,
9683 fc_fpin_congn_severity_types,
9684 FC_FPIN_CONGN_SEVERITY_INIT);
9688 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port
9689 * @phba: Pointer to phba object.
9690 * @wwnlist: Pointer to list of WWPNs in FPIN payload
9691 * @cnt: count of WWPNs in FPIN payload
9693 * This routine is called by LI and PC descriptors.
9694 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message
9697 lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt)
9699 char buf[LPFC_FPIN_WWPN_LINE_SZ];
9707 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:");
9708 for (i = 0; i < cnt; i++) {
9709 /* Are we on the last WWPN */
9713 /* Extract the next WWPN from the payload */
9715 wwpn = be64_to_cpu(wwn);
9716 len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len,
9719 /* Log a message if we are on the last WWPN
9720 * or if we hit the max allowed per message.
9723 if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) {
9725 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9728 /* Check if we reached the last WWPN */
9732 /* Limit the number of log message displayed per FPIN */
9734 if (line == LPFC_FPIN_WWPN_NUM_LINE) {
9735 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9736 "4687 %d WWPNs Truncated\n",
9741 /* Start over with next log message */
9743 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ,
9744 "Additional WWPNs:");
9750 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
9751 * @phba: Pointer to phba object.
9752 * @tlv: Pointer to the Link Integrity Notification Descriptor.
9754 * This function processes a Link Integrity FPIN event by logging a message.
9757 lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9759 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
9760 const char *li_evt_str;
9763 li_evt = be16_to_cpu(li->event_type);
9764 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
9765 cnt = be32_to_cpu(li->pname_count);
9767 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9768 "4680 FPIN Link Integrity %s (x%x) "
9769 "Detecting PN x%016llx Attached PN x%016llx "
9770 "Duration %d mSecs Count %d Port Cnt %d\n",
9772 be64_to_cpu(li->detecting_wwpn),
9773 be64_to_cpu(li->attached_wwpn),
9774 be32_to_cpu(li->event_threshold),
9775 be32_to_cpu(li->event_count), cnt);
9777 lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt);
9781 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event.
9782 * @phba: Pointer to hba object.
9783 * @tlv: Pointer to the Delivery Notification Descriptor TLV
9785 * This function processes a Delivery FPIN event by logging a message.
9788 lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9790 struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv;
9791 const char *del_rsn_str;
9795 del_rsn = be16_to_cpu(del->deli_reason_code);
9796 del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn);
9798 /* Skip over desc_tag/desc_len header to payload */
9799 frame = (__be32 *)(del + 1);
9801 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9802 "4681 FPIN Delivery %s (x%x) "
9803 "Detecting PN x%016llx Attached PN x%016llx "
9805 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x "
9806 "DiscHdr4 x%08x DiscHdr5 x%08x\n",
9807 del_rsn_str, del_rsn,
9808 be64_to_cpu(del->detecting_wwpn),
9809 be64_to_cpu(del->attached_wwpn),
9810 be32_to_cpu(frame[0]),
9811 be32_to_cpu(frame[1]),
9812 be32_to_cpu(frame[2]),
9813 be32_to_cpu(frame[3]),
9814 be32_to_cpu(frame[4]),
9815 be32_to_cpu(frame[5]));
9819 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event.
9820 * @phba: Pointer to hba object.
9821 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV
9823 * This function processes a Peer Congestion FPIN event by logging a message.
9826 lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9828 struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv;
9829 const char *pc_evt_str;
9832 pc_evt = be16_to_cpu(pc->event_type);
9833 pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt);
9834 cnt = be32_to_cpu(pc->pname_count);
9836 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS,
9837 "4684 FPIN Peer Congestion %s (x%x) "
9838 "Duration %d mSecs "
9839 "Detecting PN x%016llx Attached PN x%016llx "
9840 "Impacted Port Cnt %d\n",
9842 be32_to_cpu(pc->event_period),
9843 be64_to_cpu(pc->detecting_wwpn),
9844 be64_to_cpu(pc->attached_wwpn),
9847 lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt);
9851 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification
9852 * @phba: Pointer to hba object.
9853 * @tlv: Pointer to the Congestion Notification Descriptor TLV
9855 * This function processes an FPIN Congestion Notifiction. The notification
9856 * could be an Alarm or Warning. This routine feeds that data into driver's
9857 * running congestion algorithm. It also processes the FPIN by
9858 * logging a message. It returns 1 to indicate deliver this message
9859 * to the upper layer or 0 to indicate don't deliver it.
9862 lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9864 struct lpfc_cgn_info *cp;
9865 struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv;
9866 const char *cgn_evt_str;
9868 const char *cgn_sev_str;
9872 bool nm_log = false;
9875 cgn_evt = be16_to_cpu(cgn->event_type);
9876 cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt);
9877 cgn_sev = cgn->severity;
9878 cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev);
9880 /* The driver only takes action on a Credit Stall or Oversubscription
9881 * event type to engage the IO algorithm. The driver prints an
9882 * unmaskable message only for Lost Credit and Credit Stall.
9883 * TODO: Still need to have definition of host action on clear,
9884 * lost credit and device specific event types.
9887 case FPIN_CONGN_LOST_CREDIT:
9890 case FPIN_CONGN_CREDIT_STALL:
9893 case FPIN_CONGN_OVERSUBSCRIPTION:
9894 if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION)
9897 case FPIN_CONGN_SEVERITY_ERROR:
9898 /* Take action here for an Alarm event */
9899 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
9900 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) {
9901 /* Track of alarm cnt for SYNC_WQE */
9902 atomic_inc(&phba->cgn_sync_alarm_cnt);
9904 /* Track alarm cnt for cgn_info regardless
9905 * of whether CMF is configured for Signals
9908 atomic_inc(&phba->cgn_fabric_alarm_cnt);
9912 case FPIN_CONGN_SEVERITY_WARNING:
9913 /* Take action here for a Warning event */
9914 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
9915 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) {
9916 /* Track of warning cnt for SYNC_WQE */
9917 atomic_inc(&phba->cgn_sync_warn_cnt);
9919 /* Track warning cnt and freq for cgn_info
9920 * regardless of whether CMF is configured for
9923 atomic_inc(&phba->cgn_fabric_warn_cnt);
9925 /* Save frequency in ms */
9926 phba->cgn_fpin_frequency =
9927 be32_to_cpu(cgn->event_period);
9928 value = phba->cgn_fpin_frequency;
9930 cp = (struct lpfc_cgn_info *)
9932 cp->cgn_alarm_freq =
9936 crc = lpfc_cgn_calc_crc32
9939 LPFC_CGN_CRC32_SEED);
9940 cp->cgn_info_crc = cpu_to_le32(crc);
9943 /* Don't deliver to upper layer since
9944 * driver took action on this tlv.
9953 /* Change the log level to unmaskable for the following event types. */
9954 lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO),
9955 LOG_CGN_MGMT | LOG_ELS,
9956 "4683 FPIN CONGESTION %s type %s (x%x) Event "
9957 "Duration %d mSecs\n",
9958 cgn_sev_str, cgn_evt_str, cgn_evt,
9959 be32_to_cpu(cgn->event_period));
9964 lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length)
9966 struct lpfc_hba *phba = vport->phba;
9967 struct fc_els_fpin *fpin = (struct fc_els_fpin *)p;
9968 struct fc_tlv_desc *tlv, *first_tlv, *current_tlv;
9969 const char *dtag_nm;
9970 int desc_cnt = 0, bytes_remain, cnt;
9971 u32 dtag, deliver = 0;
9974 /* FPINs handled only if we are in the right discovery state */
9975 if (vport->port_state < LPFC_DISC_AUTH)
9978 /* make sure there is the full fpin header */
9979 if (fpin_length < sizeof(struct fc_els_fpin))
9982 /* Sanity check descriptor length. The desc_len value does not
9983 * include space for the ELS command and the desc_len fields.
9985 len = be32_to_cpu(fpin->desc_len);
9986 if (fpin_length < len + sizeof(struct fc_els_fpin)) {
9987 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
9988 "4671 Bad ELS FPIN length %d: %d\n",
9993 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
9995 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
9996 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
9998 /* process each descriptor separately */
9999 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
10000 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
10001 dtag = be32_to_cpu(tlv->desc_tag);
10003 case ELS_DTAG_LNK_INTEGRITY:
10004 lpfc_els_rcv_fpin_li(phba, tlv);
10007 case ELS_DTAG_DELIVERY:
10008 lpfc_els_rcv_fpin_del(phba, tlv);
10011 case ELS_DTAG_PEER_CONGEST:
10012 lpfc_els_rcv_fpin_peer_cgn(phba, tlv);
10015 case ELS_DTAG_CONGESTION:
10016 deliver = lpfc_els_rcv_fpin_cgn(phba, tlv);
10019 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10020 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10021 "4678 unknown FPIN descriptor[%d]: "
10023 desc_cnt, dtag, dtag_nm);
10025 /* If descriptor is bad, drop the rest of the data */
10028 lpfc_cgn_update_stat(phba, dtag);
10029 cnt = be32_to_cpu(tlv->desc_len);
10031 /* Sanity check descriptor length. The desc_len value does not
10032 * include space for the desc_tag and the desc_len fields.
10034 len -= (cnt + sizeof(struct fc_tlv_desc));
10036 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10037 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10038 "4672 Bad FPIN descriptor TLV length "
10040 cnt, len, fpin_length, dtag_nm);
10045 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
10046 tlv = fc_tlv_next_desc(tlv);
10048 /* Format payload such that the FPIN delivered to the
10049 * upper layer is a single descriptor FPIN.
10052 memcpy(first_tlv, current_tlv,
10053 (cnt + sizeof(struct fc_els_fpin)));
10055 /* Adjust the length so that it only reflects a
10056 * single descriptor FPIN.
10058 fpin_length = cnt + sizeof(struct fc_els_fpin);
10059 fpin->desc_len = cpu_to_be32(fpin_length);
10060 fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */
10062 /* Send every descriptor individually to the upper layer */
10064 fc_host_fpin_rcv(lpfc_shost_from_vport(vport),
10065 fpin_length, (char *)fpin);
10071 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
10072 * @phba: pointer to lpfc hba data structure.
10073 * @pring: pointer to a SLI ring.
10074 * @vport: pointer to a host virtual N_Port data structure.
10075 * @elsiocb: pointer to lpfc els command iocb data structure.
10077 * This routine is used for processing the IOCB associated with a unsolicited
10078 * event. It first determines whether there is an existing ndlp that matches
10079 * the DID from the unsolicited IOCB. If not, it will create a new one with
10080 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
10081 * IOCB is then used to invoke the proper routine and to set up proper state
10082 * of the discovery state machine.
10085 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10086 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
10088 struct lpfc_nodelist *ndlp;
10089 struct ls_rjt stat;
10090 u32 *payload, payload_len;
10091 u32 cmd = 0, did = 0, newnode, status = 0;
10092 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
10093 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10094 LPFC_MBOXQ_t *mbox;
10096 if (!vport || !elsiocb->cmd_dmabuf)
10100 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10101 payload = elsiocb->cmd_dmabuf->virt;
10102 if (phba->sli_rev == LPFC_SLI_REV4)
10103 payload_len = wcqe_cmpl->total_data_placed;
10105 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
10106 status = get_job_ulpstatus(phba, elsiocb);
10108 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
10109 lpfc_sli3_post_buffer(phba, pring, 1);
10111 did = get_job_els_rsp64_did(phba, elsiocb);
10113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10114 "RCV Unsol ELS: status:x%x/x%x did:x%x",
10115 status, get_job_word4(phba, elsiocb), did);
10119 /* Check to see if link went down during discovery */
10120 if (lpfc_els_chk_latt(vport))
10123 /* Ignore traffic received during vport shutdown. */
10124 if (vport->load_flag & FC_UNLOADING)
10127 /* If NPort discovery is delayed drop incoming ELS */
10128 if ((vport->fc_flag & FC_DISC_DELAYED) &&
10129 (cmd != ELS_CMD_PLOGI))
10132 ndlp = lpfc_findnode_did(vport, did);
10134 /* Cannot find existing Fabric ndlp, so allocate a new one */
10135 ndlp = lpfc_nlp_init(vport, did);
10138 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10140 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
10141 ndlp->nlp_type |= NLP_FABRIC;
10142 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
10143 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10147 phba->fc_stat.elsRcvFrame++;
10150 * Do not process any unsolicited ELS commands
10151 * if the ndlp is in DEV_LOSS
10153 spin_lock_irq(&ndlp->lock);
10154 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
10155 spin_unlock_irq(&ndlp->lock);
10157 lpfc_nlp_put(ndlp);
10160 spin_unlock_irq(&ndlp->lock);
10162 elsiocb->ndlp = lpfc_nlp_get(ndlp);
10163 if (!elsiocb->ndlp)
10165 elsiocb->vport = vport;
10167 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
10168 cmd &= ELS_CMD_MASK;
10170 /* ELS command <elsCmd> received from NPORT <did> */
10171 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10172 "0112 ELS command x%x received from NPORT x%x "
10173 "refcnt %d Data: x%x x%x x%x x%x\n",
10174 cmd, did, kref_read(&ndlp->kref), vport->port_state,
10175 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
10177 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
10178 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
10179 (cmd != ELS_CMD_FLOGI) &&
10180 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
10181 rjt_err = LSRJT_LOGICAL_BSY;
10182 rjt_exp = LSEXP_NOTHING_MORE;
10187 case ELS_CMD_PLOGI:
10188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10189 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
10190 did, vport->port_state, ndlp->nlp_flag);
10192 phba->fc_stat.elsRcvPLOGI++;
10193 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
10194 if (phba->sli_rev == LPFC_SLI_REV4 &&
10195 (phba->pport->fc_flag & FC_PT2PT)) {
10196 vport->fc_prevDID = vport->fc_myDID;
10197 /* Our DID needs to be updated before registering
10198 * the vfi. This is done in lpfc_rcv_plogi but
10199 * that is called after the reg_vfi.
10202 bf_get(els_rsp64_sid,
10203 &elsiocb->wqe.xmit_els_rsp);
10204 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10205 "3312 Remote port assigned DID x%x "
10206 "%x\n", vport->fc_myDID,
10207 vport->fc_prevDID);
10210 lpfc_send_els_event(vport, ndlp, payload);
10212 /* If Nport discovery is delayed, reject PLOGIs */
10213 if (vport->fc_flag & FC_DISC_DELAYED) {
10214 rjt_err = LSRJT_UNABLE_TPC;
10215 rjt_exp = LSEXP_NOTHING_MORE;
10219 if (vport->port_state < LPFC_DISC_AUTH) {
10220 if (!(phba->pport->fc_flag & FC_PT2PT) ||
10221 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
10222 rjt_err = LSRJT_UNABLE_TPC;
10223 rjt_exp = LSEXP_NOTHING_MORE;
10228 spin_lock_irq(&ndlp->lock);
10229 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
10230 spin_unlock_irq(&ndlp->lock);
10232 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10233 NLP_EVT_RCV_PLOGI);
10236 case ELS_CMD_FLOGI:
10237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10238 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
10239 did, vport->port_state, ndlp->nlp_flag);
10241 phba->fc_stat.elsRcvFLOGI++;
10243 /* If the driver believes fabric discovery is done and is ready,
10244 * bounce the link. There is some descrepancy.
10246 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
10247 vport->fc_flag & FC_PT2PT &&
10248 vport->rcv_flogi_cnt >= 1) {
10249 rjt_err = LSRJT_LOGICAL_BSY;
10250 rjt_exp = LSEXP_NOTHING_MORE;
10255 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
10256 /* retain node if our response is deferred */
10257 if (phba->defer_flogi_acc_flag)
10260 lpfc_disc_state_machine(vport, ndlp, NULL,
10261 NLP_EVT_DEVICE_RM);
10264 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10265 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
10266 did, vport->port_state, ndlp->nlp_flag);
10268 phba->fc_stat.elsRcvLOGO++;
10269 lpfc_send_els_event(vport, ndlp, payload);
10270 if (vport->port_state < LPFC_DISC_AUTH) {
10271 rjt_err = LSRJT_UNABLE_TPC;
10272 rjt_exp = LSEXP_NOTHING_MORE;
10275 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
10277 lpfc_disc_state_machine(vport, ndlp, NULL,
10278 NLP_EVT_DEVICE_RM);
10281 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10282 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
10283 did, vport->port_state, ndlp->nlp_flag);
10285 phba->fc_stat.elsRcvPRLO++;
10286 lpfc_send_els_event(vport, ndlp, payload);
10287 if (vport->port_state < LPFC_DISC_AUTH) {
10288 rjt_err = LSRJT_UNABLE_TPC;
10289 rjt_exp = LSEXP_NOTHING_MORE;
10292 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
10295 phba->fc_stat.elsRcvLCB++;
10296 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
10299 phba->fc_stat.elsRcvRDP++;
10300 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
10303 phba->fc_stat.elsRcvRSCN++;
10304 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
10306 lpfc_disc_state_machine(vport, ndlp, NULL,
10307 NLP_EVT_DEVICE_RM);
10309 case ELS_CMD_ADISC:
10310 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10311 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
10312 did, vport->port_state, ndlp->nlp_flag);
10314 lpfc_send_els_event(vport, ndlp, payload);
10315 phba->fc_stat.elsRcvADISC++;
10316 if (vport->port_state < LPFC_DISC_AUTH) {
10317 rjt_err = LSRJT_UNABLE_TPC;
10318 rjt_exp = LSEXP_NOTHING_MORE;
10321 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10322 NLP_EVT_RCV_ADISC);
10324 case ELS_CMD_PDISC:
10325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10326 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
10327 did, vport->port_state, ndlp->nlp_flag);
10329 phba->fc_stat.elsRcvPDISC++;
10330 if (vport->port_state < LPFC_DISC_AUTH) {
10331 rjt_err = LSRJT_UNABLE_TPC;
10332 rjt_exp = LSEXP_NOTHING_MORE;
10335 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10336 NLP_EVT_RCV_PDISC);
10338 case ELS_CMD_FARPR:
10339 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10340 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
10341 did, vport->port_state, ndlp->nlp_flag);
10343 phba->fc_stat.elsRcvFARPR++;
10344 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
10347 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10348 "RCV FARP: did:x%x/ste:x%x flg:x%x",
10349 did, vport->port_state, ndlp->nlp_flag);
10351 phba->fc_stat.elsRcvFARP++;
10352 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
10355 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10356 "RCV FAN: did:x%x/ste:x%x flg:x%x",
10357 did, vport->port_state, ndlp->nlp_flag);
10359 phba->fc_stat.elsRcvFAN++;
10360 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
10363 case ELS_CMD_NVMEPRLI:
10364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10365 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
10366 did, vport->port_state, ndlp->nlp_flag);
10368 phba->fc_stat.elsRcvPRLI++;
10369 if ((vport->port_state < LPFC_DISC_AUTH) &&
10370 (vport->fc_flag & FC_FABRIC)) {
10371 rjt_err = LSRJT_UNABLE_TPC;
10372 rjt_exp = LSEXP_NOTHING_MORE;
10375 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
10378 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10379 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
10380 did, vport->port_state, ndlp->nlp_flag);
10382 phba->fc_stat.elsRcvLIRR++;
10383 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
10385 lpfc_disc_state_machine(vport, ndlp, NULL,
10386 NLP_EVT_DEVICE_RM);
10389 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10390 "RCV RLS: did:x%x/ste:x%x flg:x%x",
10391 did, vport->port_state, ndlp->nlp_flag);
10393 phba->fc_stat.elsRcvRLS++;
10394 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
10396 lpfc_disc_state_machine(vport, ndlp, NULL,
10397 NLP_EVT_DEVICE_RM);
10400 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10401 "RCV RPL: did:x%x/ste:x%x flg:x%x",
10402 did, vport->port_state, ndlp->nlp_flag);
10404 phba->fc_stat.elsRcvRPL++;
10405 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
10407 lpfc_disc_state_machine(vport, ndlp, NULL,
10408 NLP_EVT_DEVICE_RM);
10411 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10412 "RCV RNID: did:x%x/ste:x%x flg:x%x",
10413 did, vport->port_state, ndlp->nlp_flag);
10415 phba->fc_stat.elsRcvRNID++;
10416 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
10418 lpfc_disc_state_machine(vport, ndlp, NULL,
10419 NLP_EVT_DEVICE_RM);
10422 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10423 "RCV RTV: did:x%x/ste:x%x flg:x%x",
10424 did, vport->port_state, ndlp->nlp_flag);
10425 phba->fc_stat.elsRcvRTV++;
10426 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
10428 lpfc_disc_state_machine(vport, ndlp, NULL,
10429 NLP_EVT_DEVICE_RM);
10432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10433 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
10434 did, vport->port_state, ndlp->nlp_flag);
10436 phba->fc_stat.elsRcvRRQ++;
10437 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
10439 lpfc_disc_state_machine(vport, ndlp, NULL,
10440 NLP_EVT_DEVICE_RM);
10443 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10444 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
10445 did, vport->port_state, ndlp->nlp_flag);
10447 phba->fc_stat.elsRcvECHO++;
10448 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
10450 lpfc_disc_state_machine(vport, ndlp, NULL,
10451 NLP_EVT_DEVICE_RM);
10454 /* receive this due to exchange closed */
10455 rjt_err = LSRJT_UNABLE_TPC;
10456 rjt_exp = LSEXP_INVALID_OX_RX;
10459 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10460 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
10461 did, vport->port_state, ndlp->nlp_flag);
10463 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
10466 /* There are no replies, so no rjt codes */
10469 lpfc_els_rcv_edc(vport, elsiocb, ndlp);
10472 phba->fc_stat.elsRcvRDF++;
10473 /* Accept RDF only from fabric controller */
10474 if (did != Fabric_Cntl_DID) {
10475 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
10476 "1115 Received RDF from invalid DID "
10478 rjt_err = LSRJT_PROTOCOL_ERR;
10479 rjt_exp = LSEXP_NOTHING_MORE;
10483 lpfc_els_rcv_rdf(vport, elsiocb, ndlp);
10486 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10487 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
10488 cmd, did, vport->port_state);
10490 /* Unsupported ELS command, reject */
10491 rjt_err = LSRJT_CMD_UNSUPPORTED;
10492 rjt_exp = LSEXP_NOTHING_MORE;
10494 /* Unknown ELS command <elsCmd> received from NPORT <did> */
10495 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10496 "0115 Unknown ELS command x%x "
10497 "received from NPORT x%x\n", cmd, did);
10499 lpfc_disc_state_machine(vport, ndlp, NULL,
10500 NLP_EVT_DEVICE_RM);
10505 /* check if need to LS_RJT received ELS cmd */
10507 memset(&stat, 0, sizeof(stat));
10508 stat.un.b.lsRjtRsnCode = rjt_err;
10509 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
10510 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
10512 /* Remove the reference from above for new nodes. */
10514 lpfc_disc_state_machine(vport, ndlp, NULL,
10515 NLP_EVT_DEVICE_RM);
10518 /* Release the reference on this elsiocb, not the ndlp. */
10519 lpfc_nlp_put(elsiocb->ndlp);
10520 elsiocb->ndlp = NULL;
10522 /* Special case. Driver received an unsolicited command that
10523 * unsupportable given the driver's current state. Reset the
10524 * link and start over.
10527 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10530 lpfc_linkdown(phba);
10531 lpfc_init_link(phba, mbox,
10532 phba->cfg_topology,
10533 phba->cfg_link_speed);
10534 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
10535 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10536 mbox->vport = vport;
10537 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
10539 mempool_free(mbox, phba->mbox_mem_pool);
10545 if (vport && !(vport->load_flag & FC_UNLOADING))
10546 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10547 "0111 Dropping received ELS cmd "
10548 "Data: x%x x%x x%x x%x\n",
10549 cmd, status, get_job_word4(phba, elsiocb), did);
10551 phba->fc_stat.elsRcvDrop++;
10555 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
10556 * @phba: pointer to lpfc hba data structure.
10557 * @pring: pointer to a SLI ring.
10558 * @elsiocb: pointer to lpfc els iocb data structure.
10560 * This routine is used to process an unsolicited event received from a SLI
10561 * (Service Level Interface) ring. The actual processing of the data buffer
10562 * associated with the unsolicited event is done by invoking the routine
10563 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
10564 * SLI ring on which the unsolicited event was received.
10567 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10568 struct lpfc_iocbq *elsiocb)
10570 struct lpfc_vport *vport = elsiocb->vport;
10571 u32 ulp_command, status, parameter, bde_count = 0;
10573 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10574 struct lpfc_dmabuf *bdeBuf1 = elsiocb->cmd_dmabuf;
10575 struct lpfc_dmabuf *bdeBuf2 = elsiocb->bpl_dmabuf;
10578 elsiocb->cmd_dmabuf = NULL;
10579 elsiocb->rsp_dmabuf = NULL;
10580 elsiocb->bpl_dmabuf = NULL;
10582 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10583 ulp_command = get_job_cmnd(phba, elsiocb);
10584 status = get_job_ulpstatus(phba, elsiocb);
10585 parameter = get_job_word4(phba, elsiocb);
10586 if (phba->sli_rev == LPFC_SLI_REV4)
10587 bde_count = wcqe_cmpl->word3;
10589 bde_count = elsiocb->iocb.ulpBdeCount;
10591 if (status == IOSTAT_NEED_BUFFER) {
10592 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
10593 } else if (status == IOSTAT_LOCAL_REJECT &&
10594 (parameter & IOERR_PARAM_MASK) ==
10595 IOERR_RCV_BUFFER_WAITING) {
10596 phba->fc_stat.NoRcvBuf++;
10597 /* Not enough posted buffers; Try posting more buffers */
10598 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
10599 lpfc_sli3_post_buffer(phba, pring, 0);
10603 if (phba->sli_rev == LPFC_SLI_REV3) {
10604 icmd = &elsiocb->iocb;
10605 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
10606 (ulp_command == CMD_IOCB_RCV_ELS64_CX ||
10607 ulp_command == CMD_IOCB_RCV_SEQ64_CX)) {
10608 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
10609 vport = phba->pport;
10611 vport = lpfc_find_vport_by_vpid(phba,
10612 icmd->unsli3.rcvsli3.vpi);
10616 /* If there are no BDEs associated
10617 * with this IOCB, there is nothing to do.
10619 if (bde_count == 0)
10622 /* Account for SLI2 or SLI3 and later unsolicited buffering */
10623 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
10624 elsiocb->cmd_dmabuf = bdeBuf1;
10625 if (bde_count == 2)
10626 elsiocb->bpl_dmabuf = bdeBuf2;
10628 icmd = &elsiocb->iocb;
10629 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
10630 icmd->un.cont64[0].addrLow);
10631 elsiocb->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring,
10633 if (bde_count == 2) {
10634 paddr = getPaddr(icmd->un.cont64[1].addrHigh,
10635 icmd->un.cont64[1].addrLow);
10636 elsiocb->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba,
10642 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
10644 * The different unsolicited event handlers would tell us
10645 * if they are done with "mp" by setting cmd_dmabuf to NULL.
10647 if (elsiocb->cmd_dmabuf) {
10648 lpfc_in_buf_free(phba, elsiocb->cmd_dmabuf);
10649 elsiocb->cmd_dmabuf = NULL;
10652 if (elsiocb->bpl_dmabuf) {
10653 lpfc_in_buf_free(phba, elsiocb->bpl_dmabuf);
10654 elsiocb->bpl_dmabuf = NULL;
10660 lpfc_start_fdmi(struct lpfc_vport *vport)
10662 struct lpfc_nodelist *ndlp;
10664 /* If this is the first time, allocate an ndlp and initialize
10665 * it. Otherwise, make sure the node is enabled and then do the
10668 ndlp = lpfc_findnode_did(vport, FDMI_DID);
10670 ndlp = lpfc_nlp_init(vport, FDMI_DID);
10672 ndlp->nlp_type |= NLP_FABRIC;
10678 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10679 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
10683 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
10684 * @phba: pointer to lpfc hba data structure.
10685 * @vport: pointer to a virtual N_Port data structure.
10687 * This routine issues a Port Login (PLOGI) to the Name Server with
10688 * State Change Request (SCR) for a @vport. This routine will create an
10689 * ndlp for the Name Server associated to the @vport if such node does
10690 * not already exist. The PLOGI to Name Server is issued by invoking the
10691 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
10692 * (FDMI) is configured to the @vport, a FDMI node will be created and
10693 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
10696 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
10698 struct lpfc_nodelist *ndlp;
10699 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10702 * If lpfc_delay_discovery parameter is set and the clean address
10703 * bit is cleared and fc fabric parameters chenged, delay FC NPort
10706 spin_lock_irq(shost->host_lock);
10707 if (vport->fc_flag & FC_DISC_DELAYED) {
10708 spin_unlock_irq(shost->host_lock);
10709 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10710 "3334 Delay fc port discovery for %d secs\n",
10712 mod_timer(&vport->delayed_disc_tmo,
10713 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
10716 spin_unlock_irq(shost->host_lock);
10718 ndlp = lpfc_findnode_did(vport, NameServer_DID);
10720 ndlp = lpfc_nlp_init(vport, NameServer_DID);
10722 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
10723 lpfc_disc_start(vport);
10726 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10727 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10728 "0251 NameServer login: no memory\n");
10733 ndlp->nlp_type |= NLP_FABRIC;
10735 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10737 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
10738 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10739 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10740 "0252 Cannot issue NameServer login\n");
10744 if ((phba->cfg_enable_SmartSAN ||
10745 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
10746 (vport->load_flag & FC_ALLOW_FDMI))
10747 lpfc_start_fdmi(vport);
10751 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
10752 * @phba: pointer to lpfc hba data structure.
10753 * @pmb: pointer to the driver internal queue element for mailbox command.
10755 * This routine is the completion callback function to register new vport
10756 * mailbox command. If the new vport mailbox command completes successfully,
10757 * the fabric registration login shall be performed on physical port (the
10758 * new vport created is actually a physical port, with VPI 0) or the port
10759 * login to Name Server for State Change Request (SCR) will be performed
10760 * on virtual port (real virtual port, with VPI greater than 0).
10763 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
10765 struct lpfc_vport *vport = pmb->vport;
10766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10767 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
10768 MAILBOX_t *mb = &pmb->u.mb;
10771 spin_lock_irq(shost->host_lock);
10772 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
10773 spin_unlock_irq(shost->host_lock);
10775 if (mb->mbxStatus) {
10776 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10777 "0915 Register VPI failed : Status: x%x"
10778 " upd bit: x%x \n", mb->mbxStatus,
10779 mb->un.varRegVpi.upd);
10780 if (phba->sli_rev == LPFC_SLI_REV4 &&
10781 mb->un.varRegVpi.upd)
10782 goto mbox_err_exit ;
10784 switch (mb->mbxStatus) {
10785 case 0x11: /* unsupported feature */
10786 case 0x9603: /* max_vpi exceeded */
10787 case 0x9602: /* Link event since CLEAR_LA */
10788 /* giving up on vport registration */
10789 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10790 spin_lock_irq(shost->host_lock);
10791 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
10792 spin_unlock_irq(shost->host_lock);
10793 lpfc_can_disctmo(vport);
10795 /* If reg_vpi fail with invalid VPI status, re-init VPI */
10797 spin_lock_irq(shost->host_lock);
10798 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
10799 spin_unlock_irq(shost->host_lock);
10800 lpfc_init_vpi(phba, pmb, vport->vpi);
10801 pmb->vport = vport;
10802 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
10803 rc = lpfc_sli_issue_mbox(phba, pmb,
10805 if (rc == MBX_NOT_FINISHED) {
10806 lpfc_printf_vlog(vport, KERN_ERR,
10808 "2732 Failed to issue INIT_VPI"
10809 " mailbox command\n");
10811 lpfc_nlp_put(ndlp);
10816 /* Try to recover from this error */
10817 if (phba->sli_rev == LPFC_SLI_REV4)
10818 lpfc_sli4_unreg_all_rpis(vport);
10819 lpfc_mbx_unreg_vpi(vport);
10820 spin_lock_irq(shost->host_lock);
10821 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
10822 spin_unlock_irq(shost->host_lock);
10823 if (mb->mbxStatus == MBX_NOT_FINISHED)
10825 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
10826 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
10827 if (phba->sli_rev == LPFC_SLI_REV4)
10828 lpfc_issue_init_vfi(vport);
10830 lpfc_initial_flogi(vport);
10832 lpfc_initial_fdisc(vport);
10837 spin_lock_irq(shost->host_lock);
10838 vport->vpi_state |= LPFC_VPI_REGISTERED;
10839 spin_unlock_irq(shost->host_lock);
10840 if (vport == phba->pport) {
10841 if (phba->sli_rev < LPFC_SLI_REV4)
10842 lpfc_issue_fabric_reglogin(vport);
10845 * If the physical port is instantiated using
10846 * FDISC, do not start vport discovery.
10848 if (vport->port_state != LPFC_FDISC)
10849 lpfc_start_fdiscs(phba);
10850 lpfc_do_scr_ns_plogi(phba, vport);
10853 lpfc_do_scr_ns_plogi(phba, vport);
10857 /* Now, we decrement the ndlp reference count held for this
10858 * callback function
10860 lpfc_nlp_put(ndlp);
10862 mempool_free(pmb, phba->mbox_mem_pool);
10867 * lpfc_register_new_vport - Register a new vport with a HBA
10868 * @phba: pointer to lpfc hba data structure.
10869 * @vport: pointer to a host virtual N_Port data structure.
10870 * @ndlp: pointer to a node-list data structure.
10872 * This routine registers the @vport as a new virtual port with a HBA.
10873 * It is done through a registering vpi mailbox command.
10876 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
10877 struct lpfc_nodelist *ndlp)
10879 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10880 LPFC_MBOXQ_t *mbox;
10882 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10884 lpfc_reg_vpi(vport, mbox);
10885 mbox->vport = vport;
10886 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
10887 if (!mbox->ctx_ndlp) {
10888 mempool_free(mbox, phba->mbox_mem_pool);
10889 goto mbox_err_exit;
10892 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
10893 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
10894 == MBX_NOT_FINISHED) {
10895 /* mailbox command not success, decrement ndlp
10896 * reference count for this command
10898 lpfc_nlp_put(ndlp);
10899 mempool_free(mbox, phba->mbox_mem_pool);
10901 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10902 "0253 Register VPI: Can't send mbox\n");
10903 goto mbox_err_exit;
10906 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10907 "0254 Register VPI: no memory\n");
10908 goto mbox_err_exit;
10913 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10914 spin_lock_irq(shost->host_lock);
10915 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
10916 spin_unlock_irq(shost->host_lock);
10921 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
10922 * @phba: pointer to lpfc hba data structure.
10924 * This routine cancels the retry delay timers to all the vports.
10927 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
10929 struct lpfc_vport **vports;
10930 struct lpfc_nodelist *ndlp;
10931 uint32_t link_state;
10934 /* Treat this failure as linkdown for all vports */
10935 link_state = phba->link_state;
10936 lpfc_linkdown(phba);
10937 phba->link_state = link_state;
10939 vports = lpfc_create_vport_work_array(phba);
10942 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10943 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
10945 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
10946 lpfc_els_flush_cmd(vports[i]);
10948 lpfc_destroy_vport_work_array(phba, vports);
10953 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
10954 * @phba: pointer to lpfc hba data structure.
10956 * This routine abort all pending discovery commands and
10957 * start a timer to retry FLOGI for the physical port
10961 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
10963 struct lpfc_nodelist *ndlp;
10965 /* Cancel the all vports retry delay retry timers */
10966 lpfc_cancel_all_vport_retry_delay_timer(phba);
10968 /* If fabric require FLOGI, then re-instantiate physical login */
10969 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
10973 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
10974 spin_lock_irq(&ndlp->lock);
10975 ndlp->nlp_flag |= NLP_DELAY_TMO;
10976 spin_unlock_irq(&ndlp->lock);
10977 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
10978 phba->pport->port_state = LPFC_FLOGI;
10983 * lpfc_fabric_login_reqd - Check if FLOGI required.
10984 * @phba: pointer to lpfc hba data structure.
10985 * @cmdiocb: pointer to FDISC command iocb.
10986 * @rspiocb: pointer to FDISC response iocb.
10988 * This routine checks if a FLOGI is reguired for FDISC
10992 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
10993 struct lpfc_iocbq *cmdiocb,
10994 struct lpfc_iocbq *rspiocb)
10996 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
10997 u32 ulp_word4 = get_job_word4(phba, rspiocb);
10999 if (ulp_status != IOSTAT_FABRIC_RJT ||
11000 ulp_word4 != RJT_LOGIN_REQUIRED)
11007 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
11008 * @phba: pointer to lpfc hba data structure.
11009 * @cmdiocb: pointer to lpfc command iocb data structure.
11010 * @rspiocb: pointer to lpfc response iocb data structure.
11012 * This routine is the completion callback function to a Fabric Discover
11013 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
11014 * single threaded, each FDISC completion callback function will reset
11015 * the discovery timer for all vports such that the timers will not get
11016 * unnecessary timeout. The function checks the FDISC IOCB status. If error
11017 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
11018 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
11019 * assigned to the vport has been changed with the completion of the FDISC
11020 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
11021 * are unregistered from the HBA, and then the lpfc_register_new_vport()
11022 * routine is invoked to register new vport with the HBA. Otherwise, the
11023 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
11024 * Server for State Change Request (SCR).
11027 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11028 struct lpfc_iocbq *rspiocb)
11030 struct lpfc_vport *vport = cmdiocb->vport;
11031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11032 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
11033 struct lpfc_nodelist *np;
11034 struct lpfc_nodelist *next_np;
11035 struct lpfc_iocbq *piocb;
11036 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
11037 struct serv_parm *sp;
11038 uint8_t fabric_param_changed;
11039 u32 ulp_status, ulp_word4;
11041 ulp_status = get_job_ulpstatus(phba, rspiocb);
11042 ulp_word4 = get_job_word4(phba, rspiocb);
11044 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11045 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
11046 ulp_status, ulp_word4,
11047 vport->fc_prevDID);
11048 /* Since all FDISCs are being single threaded, we
11049 * must reset the discovery timer for ALL vports
11050 * waiting to send FDISC when one completes.
11052 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
11053 lpfc_set_disctmo(piocb->vport);
11056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11057 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
11058 ulp_status, ulp_word4, vport->fc_prevDID);
11062 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
11063 lpfc_retry_pport_discovery(phba);
11067 /* Check for retry */
11068 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
11071 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11072 "0126 FDISC failed. (x%x/x%x)\n",
11073 ulp_status, ulp_word4);
11077 lpfc_check_nlp_post_devloss(vport, ndlp);
11079 spin_lock_irq(shost->host_lock);
11080 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
11081 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
11082 vport->fc_flag |= FC_FABRIC;
11083 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
11084 vport->fc_flag |= FC_PUBLIC_LOOP;
11085 spin_unlock_irq(shost->host_lock);
11087 vport->fc_myDID = ulp_word4 & Mask_DID;
11088 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
11089 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
11092 sp = prsp->virt + sizeof(uint32_t);
11093 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
11094 memcpy(&vport->fabric_portname, &sp->portName,
11095 sizeof(struct lpfc_name));
11096 memcpy(&vport->fabric_nodename, &sp->nodeName,
11097 sizeof(struct lpfc_name));
11098 if (fabric_param_changed &&
11099 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
11100 /* If our NportID changed, we need to ensure all
11101 * remaining NPORTs get unreg_login'ed so we can
11104 list_for_each_entry_safe(np, next_np,
11105 &vport->fc_nodes, nlp_listp) {
11106 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
11107 !(np->nlp_flag & NLP_NPR_ADISC))
11109 spin_lock_irq(&ndlp->lock);
11110 np->nlp_flag &= ~NLP_NPR_ADISC;
11111 spin_unlock_irq(&ndlp->lock);
11112 lpfc_unreg_rpi(vport, np);
11114 lpfc_cleanup_pending_mbox(vport);
11116 if (phba->sli_rev == LPFC_SLI_REV4)
11117 lpfc_sli4_unreg_all_rpis(vport);
11119 lpfc_mbx_unreg_vpi(vport);
11120 spin_lock_irq(shost->host_lock);
11121 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
11122 if (phba->sli_rev == LPFC_SLI_REV4)
11123 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
11125 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
11126 spin_unlock_irq(shost->host_lock);
11127 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
11128 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
11130 * Driver needs to re-reg VPI in order for f/w
11131 * to update the MAC address.
11133 lpfc_register_new_vport(phba, vport, ndlp);
11134 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11138 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
11139 lpfc_issue_init_vpi(vport);
11140 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
11141 lpfc_register_new_vport(phba, vport, ndlp);
11143 lpfc_do_scr_ns_plogi(phba, vport);
11145 /* The FDISC completed successfully. Move the fabric ndlp to
11146 * UNMAPPED state and register with the transport.
11148 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11152 if (vport->fc_vport &&
11153 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
11154 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11155 /* Cancel discovery timer */
11156 lpfc_can_disctmo(vport);
11158 lpfc_els_free_iocb(phba, cmdiocb);
11159 lpfc_nlp_put(ndlp);
11163 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
11164 * @vport: pointer to a virtual N_Port data structure.
11165 * @ndlp: pointer to a node-list data structure.
11166 * @retry: number of retries to the command IOCB.
11168 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
11169 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
11170 * routine to issue the IOCB, which makes sure only one outstanding fabric
11171 * IOCB will be sent off HBA at any given time.
11173 * Note that the ndlp reference count will be incremented by 1 for holding the
11174 * ndlp and the reference to ndlp will be stored into the ndlp field of
11175 * the IOCB for the completion callback function to the FDISC ELS command.
11178 * 0 - Successfully issued fdisc iocb command
11179 * 1 - Failed to issue fdisc iocb command
11182 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
11185 struct lpfc_hba *phba = vport->phba;
11187 union lpfc_wqe128 *wqe = NULL;
11188 struct lpfc_iocbq *elsiocb;
11189 struct serv_parm *sp;
11192 int did = ndlp->nlp_DID;
11195 vport->port_state = LPFC_FDISC;
11196 vport->fc_myDID = 0;
11197 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
11198 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
11201 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11202 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11203 "0255 Issue FDISC: no IOCB\n");
11207 if (phba->sli_rev == LPFC_SLI_REV4) {
11208 wqe = &elsiocb->wqe;
11209 bf_set(els_req64_sid, &wqe->els_req, 0);
11210 bf_set(els_req64_sp, &wqe->els_req, 1);
11212 icmd = &elsiocb->iocb;
11213 icmd->un.elsreq64.myID = 0;
11214 icmd->un.elsreq64.fl = 1;
11219 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
11220 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
11221 pcmd += sizeof(uint32_t); /* CSP Word 1 */
11222 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
11223 sp = (struct serv_parm *) pcmd;
11224 /* Setup CSPs accordingly for Fabric */
11225 sp->cmn.e_d_tov = 0;
11226 sp->cmn.w2.r_a_tov = 0;
11227 sp->cmn.virtual_fabric_support = 0;
11228 sp->cls1.classValid = 0;
11229 sp->cls2.seqDelivery = 1;
11230 sp->cls3.seqDelivery = 1;
11232 pcmd += sizeof(uint32_t); /* CSP Word 2 */
11233 pcmd += sizeof(uint32_t); /* CSP Word 3 */
11234 pcmd += sizeof(uint32_t); /* CSP Word 4 */
11235 pcmd += sizeof(uint32_t); /* Port Name */
11236 memcpy(pcmd, &vport->fc_portname, 8);
11237 pcmd += sizeof(uint32_t); /* Node Name */
11238 pcmd += sizeof(uint32_t); /* Node Name */
11239 memcpy(pcmd, &vport->fc_nodename, 8);
11240 sp->cmn.valid_vendor_ver_level = 0;
11241 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
11242 lpfc_set_disctmo(vport);
11244 phba->fc_stat.elsXmitFDISC++;
11245 elsiocb->cmd_cmpl = lpfc_cmpl_els_fdisc;
11247 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11248 "Issue FDISC: did:x%x",
11251 elsiocb->ndlp = lpfc_nlp_get(ndlp);
11252 if (!elsiocb->ndlp)
11255 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
11256 if (rc == IOCB_ERROR) {
11257 lpfc_nlp_put(ndlp);
11261 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
11265 lpfc_els_free_iocb(phba, elsiocb);
11266 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11267 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11268 "0256 Issue FDISC: Cannot send IOCB\n");
11273 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
11274 * @phba: pointer to lpfc hba data structure.
11275 * @cmdiocb: pointer to lpfc command iocb data structure.
11276 * @rspiocb: pointer to lpfc response iocb data structure.
11278 * This routine is the completion callback function to the issuing of a LOGO
11279 * ELS command off a vport. It frees the command IOCB and then decrement the
11280 * reference count held on ndlp for this completion function, indicating that
11281 * the reference to the ndlp is no long needed. Note that the
11282 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
11283 * callback function and an additional explicit ndlp reference decrementation
11284 * will trigger the actual release of the ndlp.
11287 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11288 struct lpfc_iocbq *rspiocb)
11290 struct lpfc_vport *vport = cmdiocb->vport;
11292 struct lpfc_nodelist *ndlp;
11293 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11294 u32 ulp_status, ulp_word4, did, tmo;
11296 ndlp = cmdiocb->ndlp;
11298 ulp_status = get_job_ulpstatus(phba, rspiocb);
11299 ulp_word4 = get_job_word4(phba, rspiocb);
11301 if (phba->sli_rev == LPFC_SLI_REV4) {
11302 did = get_job_els_rsp64_did(phba, cmdiocb);
11303 tmo = get_wqe_tmo(cmdiocb);
11305 irsp = &rspiocb->iocb;
11306 did = get_job_els_rsp64_did(phba, rspiocb);
11307 tmo = irsp->ulpTimeout;
11310 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11311 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
11312 ulp_status, ulp_word4, did);
11314 /* NPIV LOGO completes to NPort <nlp_DID> */
11315 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11316 "2928 NPIV LOGO completes to NPort x%x "
11317 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
11318 ndlp->nlp_DID, ulp_status, ulp_word4,
11319 tmo, vport->num_disc_nodes,
11320 kref_read(&ndlp->kref), ndlp->nlp_flag,
11321 ndlp->fc4_xpt_flags);
11323 if (ulp_status == IOSTAT_SUCCESS) {
11324 spin_lock_irq(shost->host_lock);
11325 vport->fc_flag &= ~FC_NDISC_ACTIVE;
11326 vport->fc_flag &= ~FC_FABRIC;
11327 spin_unlock_irq(shost->host_lock);
11328 lpfc_can_disctmo(vport);
11331 if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
11332 /* Wake up lpfc_vport_delete if waiting...*/
11333 if (ndlp->logo_waitq)
11334 wake_up(ndlp->logo_waitq);
11335 spin_lock_irq(&ndlp->lock);
11336 ndlp->nlp_flag &= ~(NLP_ISSUE_LOGO | NLP_LOGO_SND);
11337 ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
11338 spin_unlock_irq(&ndlp->lock);
11341 /* Safe to release resources now. */
11342 lpfc_els_free_iocb(phba, cmdiocb);
11343 lpfc_nlp_put(ndlp);
11347 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
11348 * @vport: pointer to a virtual N_Port data structure.
11349 * @ndlp: pointer to a node-list data structure.
11351 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
11353 * Note that the ndlp reference count will be incremented by 1 for holding the
11354 * ndlp and the reference to ndlp will be stored into the ndlp field of
11355 * the IOCB for the completion callback function to the LOGO ELS command.
11358 * 0 - Successfully issued logo off the @vport
11359 * 1 - Failed to issue logo off the @vport
11362 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
11365 struct lpfc_hba *phba = vport->phba;
11366 struct lpfc_iocbq *elsiocb;
11370 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
11371 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
11376 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
11377 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
11378 pcmd += sizeof(uint32_t);
11380 /* Fill in LOGO payload */
11381 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
11382 pcmd += sizeof(uint32_t);
11383 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
11385 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11386 "Issue LOGO npiv did:x%x flg:x%x",
11387 ndlp->nlp_DID, ndlp->nlp_flag, 0);
11389 elsiocb->cmd_cmpl = lpfc_cmpl_els_npiv_logo;
11390 spin_lock_irq(&ndlp->lock);
11391 ndlp->nlp_flag |= NLP_LOGO_SND;
11392 spin_unlock_irq(&ndlp->lock);
11393 elsiocb->ndlp = lpfc_nlp_get(ndlp);
11394 if (!elsiocb->ndlp) {
11395 lpfc_els_free_iocb(phba, elsiocb);
11399 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
11400 if (rc == IOCB_ERROR) {
11401 lpfc_els_free_iocb(phba, elsiocb);
11402 lpfc_nlp_put(ndlp);
11408 spin_lock_irq(&ndlp->lock);
11409 ndlp->nlp_flag &= ~NLP_LOGO_SND;
11410 spin_unlock_irq(&ndlp->lock);
11415 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
11416 * @t: timer context used to obtain the lpfc hba.
11418 * This routine is invoked by the fabric iocb block timer after
11419 * timeout. It posts the fabric iocb block timeout event by setting the
11420 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
11421 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
11422 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
11423 * posted event WORKER_FABRIC_BLOCK_TMO.
11426 lpfc_fabric_block_timeout(struct timer_list *t)
11428 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
11429 unsigned long iflags;
11430 uint32_t tmo_posted;
11432 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
11433 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
11435 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
11436 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
11439 lpfc_worker_wake_up(phba);
11444 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
11445 * @phba: pointer to lpfc hba data structure.
11447 * This routine issues one fabric iocb from the driver internal list to
11448 * the HBA. It first checks whether it's ready to issue one fabric iocb to
11449 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
11450 * remove one pending fabric iocb from the driver internal list and invokes
11451 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
11454 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
11456 struct lpfc_iocbq *iocb;
11457 unsigned long iflags;
11462 spin_lock_irqsave(&phba->hbalock, iflags);
11463 /* Post any pending iocb to the SLI layer */
11464 if (atomic_read(&phba->fabric_iocb_count) == 0) {
11465 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
11468 /* Increment fabric iocb count to hold the position */
11469 atomic_inc(&phba->fabric_iocb_count);
11471 spin_unlock_irqrestore(&phba->hbalock, iflags);
11473 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11474 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11475 iocb->cmd_flag |= LPFC_IO_FABRIC;
11477 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11478 "Fabric sched1: ste:x%x",
11479 iocb->vport->port_state, 0, 0);
11481 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11483 if (ret == IOCB_ERROR) {
11484 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11485 iocb->fabric_cmd_cmpl = NULL;
11486 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11487 set_job_ulpstatus(iocb, IOSTAT_LOCAL_REJECT);
11488 iocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
11489 iocb->cmd_cmpl(phba, iocb, iocb);
11491 atomic_dec(&phba->fabric_iocb_count);
11498 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
11499 * @phba: pointer to lpfc hba data structure.
11501 * This routine unblocks the issuing fabric iocb command. The function
11502 * will clear the fabric iocb block bit and then invoke the routine
11503 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
11504 * from the driver internal fabric iocb list.
11507 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
11509 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11511 lpfc_resume_fabric_iocbs(phba);
11516 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
11517 * @phba: pointer to lpfc hba data structure.
11519 * This routine blocks the issuing fabric iocb for a specified amount of
11520 * time (currently 100 ms). This is done by set the fabric iocb block bit
11521 * and set up a timeout timer for 100ms. When the block bit is set, no more
11522 * fabric iocb will be issued out of the HBA.
11525 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
11529 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11530 /* Start a timer to unblock fabric iocbs after 100ms */
11532 mod_timer(&phba->fabric_block_timer,
11533 jiffies + msecs_to_jiffies(100));
11539 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
11540 * @phba: pointer to lpfc hba data structure.
11541 * @cmdiocb: pointer to lpfc command iocb data structure.
11542 * @rspiocb: pointer to lpfc response iocb data structure.
11544 * This routine is the callback function that is put to the fabric iocb's
11545 * callback function pointer (iocb->cmd_cmpl). The original iocb's callback
11546 * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback
11547 * function first restores and invokes the original iocb's callback function
11548 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
11549 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
11552 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11553 struct lpfc_iocbq *rspiocb)
11555 struct ls_rjt stat;
11556 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11557 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11559 WARN_ON((cmdiocb->cmd_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
11561 switch (ulp_status) {
11562 case IOSTAT_NPORT_RJT:
11563 case IOSTAT_FABRIC_RJT:
11564 if (ulp_word4 & RJT_UNAVAIL_TEMP)
11565 lpfc_block_fabric_iocbs(phba);
11568 case IOSTAT_NPORT_BSY:
11569 case IOSTAT_FABRIC_BSY:
11570 lpfc_block_fabric_iocbs(phba);
11573 case IOSTAT_LS_RJT:
11574 stat.un.ls_rjt_error_be =
11575 cpu_to_be32(ulp_word4);
11576 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
11577 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
11578 lpfc_block_fabric_iocbs(phba);
11582 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
11584 cmdiocb->cmd_cmpl = cmdiocb->fabric_cmd_cmpl;
11585 cmdiocb->fabric_cmd_cmpl = NULL;
11586 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
11587 cmdiocb->cmd_cmpl(phba, cmdiocb, rspiocb);
11589 atomic_dec(&phba->fabric_iocb_count);
11590 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
11591 /* Post any pending iocbs to HBA */
11592 lpfc_resume_fabric_iocbs(phba);
11597 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
11598 * @phba: pointer to lpfc hba data structure.
11599 * @iocb: pointer to lpfc command iocb data structure.
11601 * This routine is used as the top-level API for issuing a fabric iocb command
11602 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
11603 * function makes sure that only one fabric bound iocb will be outstanding at
11604 * any given time. As such, this function will first check to see whether there
11605 * is already an outstanding fabric iocb on the wire. If so, it will put the
11606 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
11607 * issued later. Otherwise, it will issue the iocb on the wire and update the
11608 * fabric iocb count it indicate that there is one fabric iocb on the wire.
11610 * Note, this implementation has a potential sending out fabric IOCBs out of
11611 * order. The problem is caused by the construction of the "ready" boolen does
11612 * not include the condition that the internal fabric IOCB list is empty. As
11613 * such, it is possible a fabric IOCB issued by this routine might be "jump"
11614 * ahead of the fabric IOCBs in the internal list.
11617 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
11618 * IOCB_ERROR - failed to issue fabric iocb
11621 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
11623 unsigned long iflags;
11627 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
11629 spin_lock_irqsave(&phba->hbalock, iflags);
11630 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
11631 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11634 /* Increment fabric iocb count to hold the position */
11635 atomic_inc(&phba->fabric_iocb_count);
11636 spin_unlock_irqrestore(&phba->hbalock, iflags);
11638 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11639 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11640 iocb->cmd_flag |= LPFC_IO_FABRIC;
11642 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11643 "Fabric sched2: ste:x%x",
11644 iocb->vport->port_state, 0, 0);
11646 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11648 if (ret == IOCB_ERROR) {
11649 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11650 iocb->fabric_cmd_cmpl = NULL;
11651 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11652 atomic_dec(&phba->fabric_iocb_count);
11655 spin_lock_irqsave(&phba->hbalock, iflags);
11656 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
11657 spin_unlock_irqrestore(&phba->hbalock, iflags);
11658 ret = IOCB_SUCCESS;
11664 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
11665 * @vport: pointer to a virtual N_Port data structure.
11667 * This routine aborts all the IOCBs associated with a @vport from the
11668 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11669 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11670 * list, removes each IOCB associated with the @vport off the list, set the
11671 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11672 * associated with the IOCB.
11674 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
11676 LIST_HEAD(completions);
11677 struct lpfc_hba *phba = vport->phba;
11678 struct lpfc_iocbq *tmp_iocb, *piocb;
11680 spin_lock_irq(&phba->hbalock);
11681 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11684 if (piocb->vport != vport)
11687 list_move_tail(&piocb->list, &completions);
11689 spin_unlock_irq(&phba->hbalock);
11691 /* Cancel all the IOCBs from the completions list */
11692 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11693 IOERR_SLI_ABORTED);
11697 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
11698 * @ndlp: pointer to a node-list data structure.
11700 * This routine aborts all the IOCBs associated with an @ndlp from the
11701 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11702 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11703 * list, removes each IOCB associated with the @ndlp off the list, set the
11704 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11705 * associated with the IOCB.
11707 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
11709 LIST_HEAD(completions);
11710 struct lpfc_hba *phba = ndlp->phba;
11711 struct lpfc_iocbq *tmp_iocb, *piocb;
11712 struct lpfc_sli_ring *pring;
11714 pring = lpfc_phba_elsring(phba);
11716 if (unlikely(!pring))
11719 spin_lock_irq(&phba->hbalock);
11720 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11722 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
11724 list_move_tail(&piocb->list, &completions);
11727 spin_unlock_irq(&phba->hbalock);
11729 /* Cancel all the IOCBs from the completions list */
11730 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11731 IOERR_SLI_ABORTED);
11735 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
11736 * @phba: pointer to lpfc hba data structure.
11738 * This routine aborts all the IOCBs currently on the driver internal
11739 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
11740 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
11741 * list, removes IOCBs off the list, set the status field to
11742 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
11745 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
11747 LIST_HEAD(completions);
11749 spin_lock_irq(&phba->hbalock);
11750 list_splice_init(&phba->fabric_iocb_list, &completions);
11751 spin_unlock_irq(&phba->hbalock);
11753 /* Cancel all the IOCBs from the completions list */
11754 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11755 IOERR_SLI_ABORTED);
11759 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
11760 * @vport: pointer to lpfc vport data structure.
11762 * This routine is invoked by the vport cleanup for deletions and the cleanup
11763 * for an ndlp on removal.
11766 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
11768 struct lpfc_hba *phba = vport->phba;
11769 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
11770 struct lpfc_nodelist *ndlp = NULL;
11771 unsigned long iflag = 0;
11773 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
11774 list_for_each_entry_safe(sglq_entry, sglq_next,
11775 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
11776 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
11777 lpfc_nlp_put(sglq_entry->ndlp);
11778 ndlp = sglq_entry->ndlp;
11779 sglq_entry->ndlp = NULL;
11781 /* If the xri on the abts_els_sgl list is for the Fport
11782 * node and the vport is unloading, the xri aborted wcqe
11783 * likely isn't coming back. Just release the sgl.
11785 if ((vport->load_flag & FC_UNLOADING) &&
11786 ndlp->nlp_DID == Fabric_DID) {
11787 list_del(&sglq_entry->list);
11788 sglq_entry->state = SGL_FREED;
11789 list_add_tail(&sglq_entry->list,
11790 &phba->sli4_hba.lpfc_els_sgl_list);
11794 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
11799 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
11800 * @phba: pointer to lpfc hba data structure.
11801 * @axri: pointer to the els xri abort wcqe structure.
11803 * This routine is invoked by the worker thread to process a SLI4 slow-path
11807 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
11808 struct sli4_wcqe_xri_aborted *axri)
11810 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
11811 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
11814 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
11815 unsigned long iflag = 0;
11816 struct lpfc_nodelist *ndlp;
11817 struct lpfc_sli_ring *pring;
11819 pring = lpfc_phba_elsring(phba);
11821 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
11822 list_for_each_entry_safe(sglq_entry, sglq_next,
11823 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
11824 if (sglq_entry->sli4_xritag == xri) {
11825 list_del(&sglq_entry->list);
11826 ndlp = sglq_entry->ndlp;
11827 sglq_entry->ndlp = NULL;
11828 list_add_tail(&sglq_entry->list,
11829 &phba->sli4_hba.lpfc_els_sgl_list);
11830 sglq_entry->state = SGL_FREED;
11831 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
11835 lpfc_set_rrq_active(phba, ndlp,
11836 sglq_entry->sli4_lxritag,
11838 lpfc_nlp_put(ndlp);
11841 /* Check if TXQ queue needs to be serviced */
11842 if (pring && !list_empty(&pring->txq))
11843 lpfc_worker_wake_up(phba);
11847 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
11848 lxri = lpfc_sli4_xri_inrange(phba, xri);
11849 if (lxri == NO_XRI)
11852 spin_lock_irqsave(&phba->hbalock, iflag);
11853 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
11854 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
11855 spin_unlock_irqrestore(&phba->hbalock, iflag);
11858 sglq_entry->state = SGL_XRI_ABORTED;
11859 spin_unlock_irqrestore(&phba->hbalock, iflag);
11863 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
11864 * @vport: pointer to virtual port object.
11865 * @ndlp: nodelist pointer for the impacted node.
11867 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
11868 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
11869 * the driver is required to send a LOGO to the remote node before it
11870 * attempts to recover its login to the remote node.
11873 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
11874 struct lpfc_nodelist *ndlp)
11876 struct Scsi_Host *shost;
11877 struct lpfc_hba *phba;
11878 unsigned long flags = 0;
11880 shost = lpfc_shost_from_vport(vport);
11881 phba = vport->phba;
11882 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
11883 lpfc_printf_log(phba, KERN_INFO,
11884 LOG_SLI, "3093 No rport recovery needed. "
11885 "rport in state 0x%x\n", ndlp->nlp_state);
11888 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11889 "3094 Start rport recovery on shost id 0x%x "
11890 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
11892 shost->host_no, ndlp->nlp_DID,
11893 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
11896 * The rport is not responding. Remove the FCP-2 flag to prevent
11897 * an ADISC in the follow-up recovery code.
11899 spin_lock_irqsave(&ndlp->lock, flags);
11900 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
11901 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
11902 spin_unlock_irqrestore(&ndlp->lock, flags);
11903 lpfc_unreg_rpi(vport, ndlp);
11906 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport)
11908 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE);
11912 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max)
11916 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE))
11919 for (i = min; i <= max; i++)
11920 set_bit(i, vport->vmid_priority_range);
11923 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid)
11925 set_bit(ctcl_vmid, vport->vmid_priority_range);
11928 u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport)
11932 i = find_first_bit(vport->vmid_priority_range,
11933 LPFC_VMID_MAX_PRIORITY_RANGE);
11935 if (i == LPFC_VMID_MAX_PRIORITY_RANGE)
11938 clear_bit(i, vport->vmid_priority_range);
11942 #define MAX_PRIORITY_DESC 255
11945 lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11946 struct lpfc_iocbq *rspiocb)
11948 struct lpfc_vport *vport = cmdiocb->vport;
11949 struct priority_range_desc *desc;
11950 struct lpfc_dmabuf *prsp = NULL;
11951 struct lpfc_vmid_priority_range *vmid_range = NULL;
11953 struct lpfc_dmabuf *dmabuf = cmdiocb->cmd_dmabuf;
11954 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11955 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11956 u8 *pcmd, max_desc;
11958 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
11960 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
11965 data = (u32 *)pcmd;
11966 if (data[0] == ELS_CMD_LS_RJT) {
11967 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
11968 "3277 QFPA LS_RJT x%x x%x\n",
11973 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
11974 "6529 QFPA failed with status x%x x%x\n",
11975 ulp_status, ulp_word4);
11979 if (!vport->qfpa_res) {
11980 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res);
11981 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res),
11983 if (!vport->qfpa_res)
11987 len = *((u32 *)(pcmd + 4));
11988 len = be32_to_cpu(len);
11989 memcpy(vport->qfpa_res, pcmd, len + 8);
11990 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE;
11992 desc = (struct priority_range_desc *)(pcmd + 8);
11993 vmid_range = vport->vmid_priority.vmid_range;
11995 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range),
11998 kfree(vport->qfpa_res);
12001 vport->vmid_priority.vmid_range = vmid_range;
12003 vport->vmid_priority.num_descriptors = len;
12005 for (i = 0; i < len; i++, vmid_range++, desc++) {
12006 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12007 "6539 vmid values low=%d, high=%d, qos=%d, "
12008 "local ve id=%d\n", desc->lo_range,
12009 desc->hi_range, desc->qos_priority,
12010 desc->local_ve_id);
12012 vmid_range->low = desc->lo_range << 1;
12013 if (desc->local_ve_id == QFPA_ODD_ONLY)
12015 if (desc->qos_priority)
12016 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED;
12017 vmid_range->qos = desc->qos_priority;
12019 vmid_range->high = desc->hi_range << 1;
12020 if ((desc->local_ve_id == QFPA_ODD_ONLY) ||
12021 (desc->local_ve_id == QFPA_EVEN_ODD))
12022 vmid_range->high++;
12024 lpfc_init_cs_ctl_bitmap(vport);
12025 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) {
12026 lpfc_vmid_set_cs_ctl_range(vport,
12027 vport->vmid_priority.vmid_range[i].low,
12028 vport->vmid_priority.vmid_range[i].high);
12031 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL;
12033 lpfc_els_free_iocb(phba, cmdiocb);
12034 lpfc_nlp_put(ndlp);
12037 int lpfc_issue_els_qfpa(struct lpfc_vport *vport)
12039 struct lpfc_hba *phba = vport->phba;
12040 struct lpfc_nodelist *ndlp;
12041 struct lpfc_iocbq *elsiocb;
12045 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
12046 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12049 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp,
12050 ndlp->nlp_DID, ELS_CMD_QFPA);
12054 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
12056 *((u32 *)(pcmd)) = ELS_CMD_QFPA;
12059 elsiocb->cmd_cmpl = lpfc_cmpl_els_qfpa;
12061 elsiocb->ndlp = lpfc_nlp_get(ndlp);
12062 if (!elsiocb->ndlp) {
12063 lpfc_els_free_iocb(vport->phba, elsiocb);
12067 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2);
12068 if (ret != IOCB_SUCCESS) {
12069 lpfc_els_free_iocb(phba, elsiocb);
12070 lpfc_nlp_put(ndlp);
12073 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED;
12078 lpfc_vmid_uvem(struct lpfc_vport *vport,
12079 struct lpfc_vmid *vmid, bool instantiated)
12081 struct lpfc_vem_id_desc *vem_id_desc;
12082 struct lpfc_nodelist *ndlp;
12083 struct lpfc_iocbq *elsiocb;
12084 struct instantiated_ve_desc *inst_desc;
12085 struct lpfc_vmid_context *vmid_context;
12090 ndlp = lpfc_findnode_did(vport, Fabric_DID);
12091 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12094 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL);
12097 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2,
12098 ndlp, Fabric_DID, ELS_CMD_UVEM);
12102 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12103 "3427 Host vmid %s %d\n",
12104 vmid->host_vmid, instantiated);
12105 vmid_context->vmp = vmid;
12106 vmid_context->nlp = ndlp;
12107 vmid_context->instantiated = instantiated;
12108 elsiocb->vmid_tag.vmid_context = vmid_context;
12109 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
12111 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid))
12112 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid,
12113 LPFC_COMPRESS_VMID_SIZE);
12115 *((u32 *)(pcmd)) = ELS_CMD_UVEM;
12116 len = (u32 *)(pcmd + 4);
12117 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8);
12119 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8);
12120 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG);
12121 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE);
12122 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid,
12123 LPFC_COMPRESS_VMID_SIZE);
12125 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32);
12126 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12127 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE);
12128 memcpy(inst_desc->global_vem_id, vmid->host_vmid,
12129 LPFC_COMPRESS_VMID_SIZE);
12131 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID);
12132 bf_set(lpfc_instantiated_local_id, inst_desc,
12133 vmid->un.cs_ctl_vmid);
12134 if (instantiated) {
12135 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12137 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG);
12138 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid);
12140 inst_desc->word6 = cpu_to_be32(inst_desc->word6);
12142 elsiocb->cmd_cmpl = lpfc_cmpl_els_uvem;
12144 elsiocb->ndlp = lpfc_nlp_get(ndlp);
12145 if (!elsiocb->ndlp) {
12146 lpfc_els_free_iocb(vport->phba, elsiocb);
12150 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0);
12151 if (ret != IOCB_SUCCESS) {
12152 lpfc_els_free_iocb(vport->phba, elsiocb);
12153 lpfc_nlp_put(ndlp);
12159 kfree(vmid_context);
12164 lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb,
12165 struct lpfc_iocbq *rspiocb)
12167 struct lpfc_vport *vport = icmdiocb->vport;
12168 struct lpfc_dmabuf *prsp = NULL;
12169 struct lpfc_vmid_context *vmid_context =
12170 icmdiocb->vmid_tag.vmid_context;
12171 struct lpfc_nodelist *ndlp = icmdiocb->ndlp;
12174 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
12175 u32 ulp_word4 = get_job_word4(phba, rspiocb);
12176 struct lpfc_dmabuf *dmabuf = icmdiocb->cmd_dmabuf;
12177 struct lpfc_vmid *vmid;
12179 vmid = vmid_context->vmp;
12180 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12183 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
12187 data = (u32 *)pcmd;
12188 if (data[0] == ELS_CMD_LS_RJT) {
12189 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12190 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]);
12194 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12195 "4533 UVEM error status %x: %x\n",
12196 ulp_status, ulp_word4);
12199 spin_lock(&phba->hbalock);
12200 /* Set IN USE flag */
12201 vport->vmid_flag |= LPFC_VMID_IN_USE;
12202 phba->pport->vmid_flag |= LPFC_VMID_IN_USE;
12203 spin_unlock(&phba->hbalock);
12205 if (vmid_context->instantiated) {
12206 write_lock(&vport->vmid_lock);
12207 vmid->flag |= LPFC_VMID_REGISTERED;
12208 vmid->flag &= ~LPFC_VMID_REQ_REGISTER;
12209 write_unlock(&vport->vmid_lock);
12213 kfree(vmid_context);
12214 lpfc_els_free_iocb(phba, icmdiocb);
12215 lpfc_nlp_put(ndlp);