1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 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 lpfc_hba *phba = vport->phba;
99 if (vport->port_state >= LPFC_VPORT_READY ||
100 phba->link_state == LPFC_LINK_DOWN ||
101 phba->sli_rev > LPFC_SLI_REV3)
104 /* Read the HBA Host Attention Register */
105 if (lpfc_readl(phba->HAregaddr, &ha_copy))
108 if (!(ha_copy & HA_LATT))
111 /* Pending Link Event during Discovery */
112 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
113 "0237 Pending Link Event during "
114 "Discovery: State x%x\n",
115 phba->pport->port_state);
117 /* CLEAR_LA should re-enable link attention events and
118 * we should then immediately take a LATT event. The
119 * LATT processing should call lpfc_linkdown() which
120 * will cleanup any left over in-progress discovery
123 set_bit(FC_ABORT_DISCOVERY, &vport->fc_flag);
125 if (phba->link_state != LPFC_CLEAR_LA)
126 lpfc_issue_clear_la(phba, vport);
131 static bool lpfc_is_els_acc_rsp(struct lpfc_dmabuf *buf)
133 struct fc_els_ls_acc *rsp = buf->virt;
135 if (rsp && rsp->la_cmd == ELS_LS_ACC)
141 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
142 * @vport: pointer to a host virtual N_Port data structure.
143 * @expect_rsp: flag indicating whether response is expected.
144 * @cmd_size: size of the ELS command.
145 * @retry: number of retries to the command when it fails.
146 * @ndlp: pointer to a node-list data structure.
147 * @did: destination identifier.
148 * @elscmd: the ELS command code.
150 * This routine is used for allocating a lpfc-IOCB data structure from
151 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
152 * passed into the routine for discovery state machine to issue an Extended
153 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
154 * and preparation routine that is used by all the discovery state machine
155 * routines and the ELS command-specific fields will be later set up by
156 * the individual discovery machine routines after calling this routine
157 * allocating and preparing a generic IOCB data structure. It fills in the
158 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
159 * payload and response payload (if expected). The reference count on the
160 * ndlp is incremented by 1 and the reference to the ndlp is put into
161 * ndlp of the IOCB data structure for this IOCB to hold the ndlp
162 * reference for the command's callback function to access later.
165 * Pointer to the newly allocated/prepared els iocb data structure
166 * NULL - when els iocb data structure allocation/preparation failed
169 lpfc_prep_els_iocb(struct lpfc_vport *vport, u8 expect_rsp,
170 u16 cmd_size, u8 retry,
171 struct lpfc_nodelist *ndlp, u32 did,
174 struct lpfc_hba *phba = vport->phba;
175 struct lpfc_iocbq *elsiocb;
176 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist, *bmp;
177 struct ulp_bde64_le *bpl;
180 if (!lpfc_is_link_up(phba))
183 /* Allocate buffer for command iocb */
184 elsiocb = lpfc_sli_get_iocbq(phba);
189 * If this command is for fabric controller and HBA running
190 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
192 if ((did == Fabric_DID) &&
193 (phba->hba_flag & HBA_FIP_SUPPORT) &&
194 ((elscmd == ELS_CMD_FLOGI) ||
195 (elscmd == ELS_CMD_FDISC) ||
196 (elscmd == ELS_CMD_LOGO)))
200 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
201 & LPFC_FIP_ELS_ID_MASK);
205 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
206 & LPFC_FIP_ELS_ID_MASK);
210 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
211 & LPFC_FIP_ELS_ID_MASK);
215 elsiocb->cmd_flag &= ~LPFC_FIP_ELS_ID_MASK;
217 /* fill in BDEs for command */
218 /* Allocate buffer for command payload */
219 pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL);
221 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
222 if (!pcmd || !pcmd->virt)
223 goto els_iocb_free_pcmb_exit;
225 INIT_LIST_HEAD(&pcmd->list);
227 /* Allocate buffer for response payload */
229 prsp = kmalloc(sizeof(*prsp), GFP_KERNEL);
231 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
233 if (!prsp || !prsp->virt)
234 goto els_iocb_free_prsp_exit;
235 INIT_LIST_HEAD(&prsp->list);
240 /* Allocate buffer for Buffer ptr list */
241 pbuflist = kmalloc(sizeof(*pbuflist), GFP_KERNEL);
243 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
245 if (!pbuflist || !pbuflist->virt)
246 goto els_iocb_free_pbuf_exit;
248 INIT_LIST_HEAD(&pbuflist->list);
253 timeout = FF_DEF_RATOV * 2;
256 timeout = phba->fc_ratov;
259 timeout = phba->fc_ratov * 2;
262 /* Fill SGE for the num bde count */
263 elsiocb->num_bdes = 2;
266 if (phba->sli_rev == LPFC_SLI_REV4)
271 lpfc_sli_prep_els_req_rsp(phba, elsiocb, vport, bmp, cmd_size, did,
272 elscmd, timeout, expect_rsp);
274 bpl = (struct ulp_bde64_le *)pbuflist->virt;
275 bpl->addr_low = cpu_to_le32(putPaddrLow(pcmd->phys));
276 bpl->addr_high = cpu_to_le32(putPaddrHigh(pcmd->phys));
277 bpl->type_size = cpu_to_le32(cmd_size);
278 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
282 bpl->addr_low = cpu_to_le32(putPaddrLow(prsp->phys));
283 bpl->addr_high = cpu_to_le32(putPaddrHigh(prsp->phys));
284 bpl->type_size = cpu_to_le32(FCELSSIZE);
285 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
288 elsiocb->cmd_dmabuf = pcmd;
289 elsiocb->bpl_dmabuf = pbuflist;
290 elsiocb->retry = retry;
291 elsiocb->vport = vport;
292 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
295 list_add(&prsp->list, &pcmd->list);
297 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
298 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
299 "0116 Xmit ELS command x%x to remote "
300 "NPORT x%x I/O tag: x%x, port state:x%x "
301 "rpi x%x fc_flag:x%lx\n",
302 elscmd, did, elsiocb->iotag,
303 vport->port_state, ndlp->nlp_rpi,
306 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
307 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
308 "0117 Xmit ELS response x%x to remote "
309 "NPORT x%x I/O tag: x%x, size: x%x "
310 "port_state x%x rpi x%x fc_flag x%lx\n",
311 elscmd, ndlp->nlp_DID, elsiocb->iotag,
312 cmd_size, vport->port_state,
313 ndlp->nlp_rpi, vport->fc_flag);
318 els_iocb_free_pbuf_exit:
320 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
323 els_iocb_free_prsp_exit:
324 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
327 els_iocb_free_pcmb_exit:
329 lpfc_sli_release_iocbq(phba, elsiocb);
334 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
335 * @vport: pointer to a host virtual N_Port data structure.
337 * This routine issues a fabric registration login for a @vport. An
338 * active ndlp node with Fabric_DID must already exist for this @vport.
339 * The routine invokes two mailbox commands to carry out fabric registration
340 * login through the HBA firmware: the first mailbox command requests the
341 * HBA to perform link configuration for the @vport; and the second mailbox
342 * command requests the HBA to perform the actual fabric registration login
346 * 0 - successfully issued fabric registration login for @vport
347 * -ENXIO -- failed to issue fabric registration login for @vport
350 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
352 struct lpfc_hba *phba = vport->phba;
354 struct lpfc_nodelist *ndlp;
355 struct serv_parm *sp;
359 sp = &phba->fc_fabparam;
360 ndlp = lpfc_findnode_did(vport, Fabric_DID);
366 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
372 vport->port_state = LPFC_FABRIC_CFG_LINK;
373 lpfc_config_link(phba, mbox);
374 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
377 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
378 if (rc == MBX_NOT_FINISHED) {
383 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
395 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
397 /* increment the reference count on ndlp to hold reference
398 * for the callback routine.
400 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
401 if (!mbox->ctx_ndlp) {
406 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
407 if (rc == MBX_NOT_FINISHED) {
409 goto fail_issue_reg_login;
414 fail_issue_reg_login:
415 /* decrement the reference count on ndlp just incremented
416 * for the failed mbox command.
420 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
422 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
423 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
424 "0249 Cannot issue Register Fabric login: Err %d\n",
430 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
431 * @vport: pointer to a host virtual N_Port data structure.
433 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
434 * the @vport. This mailbox command is necessary for SLI4 port only.
437 * 0 - successfully issued REG_VFI for @vport
438 * A failure code otherwise.
441 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
443 struct lpfc_hba *phba = vport->phba;
444 LPFC_MBOXQ_t *mboxq = NULL;
445 struct lpfc_nodelist *ndlp;
446 struct lpfc_dmabuf *dmabuf = NULL;
449 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
450 if ((phba->sli_rev == LPFC_SLI_REV4) &&
451 !(phba->link_flag & LS_LOOPBACK_MODE) &&
452 !test_bit(FC_PT2PT, &vport->fc_flag)) {
453 ndlp = lpfc_findnode_did(vport, Fabric_DID);
460 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
466 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
467 if (test_bit(FC_FABRIC, &vport->fc_flag) ||
468 test_bit(FC_PT2PT, &vport->fc_flag)) {
469 rc = lpfc_mbox_rsrc_prep(phba, mboxq);
474 dmabuf = mboxq->ctx_buf;
475 memcpy(dmabuf->virt, &phba->fc_fabparam,
476 sizeof(struct serv_parm));
479 vport->port_state = LPFC_FABRIC_CFG_LINK;
481 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
482 /* lpfc_reg_vfi memsets the mailbox. Restore the ctx_buf. */
483 mboxq->ctx_buf = dmabuf;
485 lpfc_reg_vfi(mboxq, vport, 0);
488 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
489 mboxq->vport = vport;
490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
491 if (rc == MBX_NOT_FINISHED) {
498 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
500 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
501 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
502 "0289 Issue Register VFI failed: Err %d\n", rc);
507 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
508 * @vport: pointer to a host virtual N_Port data structure.
510 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
511 * the @vport. This mailbox command is necessary for SLI4 port only.
514 * 0 - successfully issued REG_VFI for @vport
515 * A failure code otherwise.
518 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
520 struct lpfc_hba *phba = vport->phba;
524 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
526 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
527 "2556 UNREG_VFI mbox allocation failed"
528 "HBA state x%x\n", phba->pport->port_state);
532 lpfc_unreg_vfi(mboxq, vport);
533 mboxq->vport = vport;
534 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
536 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
537 if (rc == MBX_NOT_FINISHED) {
538 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
539 "2557 UNREG_VFI issue mbox failed rc x%x "
541 rc, phba->pport->port_state);
542 mempool_free(mboxq, phba->mbox_mem_pool);
546 clear_bit(FC_VFI_REGISTERED, &vport->fc_flag);
551 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
552 * @vport: pointer to a host virtual N_Port data structure.
553 * @sp: pointer to service parameter data structure.
555 * This routine is called from FLOGI/FDISC completion handler functions.
556 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
557 * node nodename is changed in the completion service parameter else return
558 * 0. This function also set flag in the vport data structure to delay
559 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
560 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
561 * node nodename is changed in the completion service parameter.
564 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
565 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
569 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
570 struct serv_parm *sp)
572 struct lpfc_hba *phba = vport->phba;
573 uint8_t fabric_param_changed = 0;
575 if ((vport->fc_prevDID != vport->fc_myDID) ||
576 memcmp(&vport->fabric_portname, &sp->portName,
577 sizeof(struct lpfc_name)) ||
578 memcmp(&vport->fabric_nodename, &sp->nodeName,
579 sizeof(struct lpfc_name)) ||
580 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
581 fabric_param_changed = 1;
582 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
585 * Word 1 Bit 31 in common service parameter is overloaded.
586 * Word 1 Bit 31 in FLOGI request is multiple NPort request
587 * Word 1 Bit 31 in FLOGI response is clean address bit
589 * If fabric parameter is changed and clean address bit is
590 * cleared delay nport discovery if
591 * - vport->fc_prevDID != 0 (not initial discovery) OR
592 * - lpfc_delay_discovery module parameter is set.
594 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
595 (vport->fc_prevDID || phba->cfg_delay_discovery))
596 set_bit(FC_DISC_DELAYED, &vport->fc_flag);
598 return fabric_param_changed;
603 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
604 * @vport: pointer to a host virtual N_Port data structure.
605 * @ndlp: pointer to a node-list data structure.
606 * @sp: pointer to service parameter data structure.
607 * @ulp_word4: command response value
609 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
610 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
611 * port in a fabric topology. It properly sets up the parameters to the @ndlp
612 * from the IOCB response. It also check the newly assigned N_Port ID to the
613 * @vport against the previously assigned N_Port ID. If it is different from
614 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
615 * is invoked on all the remaining nodes with the @vport to unregister the
616 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
617 * is invoked to register login to the fabric.
620 * 0 - Success (currently, always return 0)
623 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
624 struct serv_parm *sp, uint32_t ulp_word4)
626 struct lpfc_hba *phba = vport->phba;
627 struct lpfc_nodelist *np;
628 struct lpfc_nodelist *next_np;
629 uint8_t fabric_param_changed;
631 set_bit(FC_FABRIC, &vport->fc_flag);
633 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
634 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
635 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
637 phba->fc_edtovResol = sp->cmn.edtovResolution;
638 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
640 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
641 set_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
643 vport->fc_myDID = ulp_word4 & Mask_DID;
644 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
645 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
646 ndlp->nlp_class_sup = 0;
647 if (sp->cls1.classValid)
648 ndlp->nlp_class_sup |= FC_COS_CLASS1;
649 if (sp->cls2.classValid)
650 ndlp->nlp_class_sup |= FC_COS_CLASS2;
651 if (sp->cls3.classValid)
652 ndlp->nlp_class_sup |= FC_COS_CLASS3;
653 if (sp->cls4.classValid)
654 ndlp->nlp_class_sup |= FC_COS_CLASS4;
655 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
656 sp->cmn.bbRcvSizeLsb;
658 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
659 if (fabric_param_changed) {
660 /* Reset FDMI attribute masks based on config parameter */
661 if (phba->cfg_enable_SmartSAN ||
662 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
663 /* Setup appropriate attribute masks */
664 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
665 if (phba->cfg_enable_SmartSAN)
666 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
668 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
670 vport->fdmi_hba_mask = 0;
671 vport->fdmi_port_mask = 0;
675 memcpy(&vport->fabric_portname, &sp->portName,
676 sizeof(struct lpfc_name));
677 memcpy(&vport->fabric_nodename, &sp->nodeName,
678 sizeof(struct lpfc_name));
679 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
681 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
682 if (sp->cmn.response_multiple_NPort) {
683 lpfc_printf_vlog(vport, KERN_WARNING,
685 "1816 FLOGI NPIV supported, "
686 "response data 0x%x\n",
687 sp->cmn.response_multiple_NPort);
688 spin_lock_irq(&phba->hbalock);
689 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
690 spin_unlock_irq(&phba->hbalock);
692 /* Because we asked f/w for NPIV it still expects us
693 to call reg_vnpid at least for the physical host */
694 lpfc_printf_vlog(vport, KERN_WARNING,
696 "1817 Fabric does not support NPIV "
697 "- configuring single port mode.\n");
698 spin_lock_irq(&phba->hbalock);
699 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
700 spin_unlock_irq(&phba->hbalock);
705 * For FC we need to do some special processing because of the SLI
706 * Port's default settings of the Common Service Parameters.
708 if ((phba->sli_rev == LPFC_SLI_REV4) &&
709 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
710 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
711 if (fabric_param_changed)
712 lpfc_unregister_fcf_prep(phba);
714 /* This should just update the VFI CSPs*/
715 if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag))
716 lpfc_issue_reg_vfi(vport);
719 if (fabric_param_changed &&
720 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
722 /* If our NportID changed, we need to ensure all
723 * remaining NPORTs get unreg_login'ed.
725 list_for_each_entry_safe(np, next_np,
726 &vport->fc_nodes, nlp_listp) {
727 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
728 !(np->nlp_flag & NLP_NPR_ADISC))
730 spin_lock_irq(&np->lock);
731 np->nlp_flag &= ~NLP_NPR_ADISC;
732 spin_unlock_irq(&np->lock);
733 lpfc_unreg_rpi(vport, np);
735 lpfc_cleanup_pending_mbox(vport);
737 if (phba->sli_rev == LPFC_SLI_REV4) {
738 lpfc_sli4_unreg_all_rpis(vport);
739 lpfc_mbx_unreg_vpi(vport);
740 set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag);
744 * For SLI3 and SLI4, the VPI needs to be reregistered in
745 * response to this fabric parameter change event.
747 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
748 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
749 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
751 * Driver needs to re-reg VPI in order for f/w
752 * to update the MAC address.
754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
755 lpfc_register_new_vport(phba, vport, ndlp);
759 if (phba->sli_rev < LPFC_SLI_REV4) {
760 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
761 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
762 test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag))
763 lpfc_register_new_vport(phba, vport, ndlp);
765 lpfc_issue_fabric_reglogin(vport);
767 ndlp->nlp_type |= NLP_FABRIC;
768 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
769 if ((!test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) &&
770 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
771 lpfc_start_fdiscs(phba);
772 lpfc_do_scr_ns_plogi(phba, vport);
773 } else if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag))
774 lpfc_issue_init_vpi(vport);
776 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
777 "3135 Need register VFI: (x%x/%x)\n",
778 vport->fc_prevDID, vport->fc_myDID);
779 lpfc_issue_reg_vfi(vport);
786 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
787 * @vport: pointer to a host virtual N_Port data structure.
788 * @ndlp: pointer to a node-list data structure.
789 * @sp: pointer to service parameter data structure.
791 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
792 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
793 * in a point-to-point topology. First, the @vport's N_Port Name is compared
794 * with the received N_Port Name: if the @vport's N_Port Name is greater than
795 * the received N_Port Name lexicographically, this node shall assign local
796 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
797 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
798 * this node shall just wait for the remote node to issue PLOGI and assign
806 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
807 struct serv_parm *sp)
809 struct lpfc_hba *phba = vport->phba;
813 clear_bit(FC_FABRIC, &vport->fc_flag);
814 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
815 set_bit(FC_PT2PT, &vport->fc_flag);
817 /* If we are pt2pt with another NPort, force NPIV off! */
818 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
820 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
821 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
822 lpfc_unregister_fcf_prep(phba);
823 clear_bit(FC_VFI_REGISTERED, &vport->fc_flag);
824 phba->fc_topology_changed = 0;
827 rc = memcmp(&vport->fc_portname, &sp->portName,
828 sizeof(vport->fc_portname));
831 /* This side will initiate the PLOGI */
832 set_bit(FC_PT2PT_PLOGI, &vport->fc_flag);
835 * N_Port ID cannot be 0, set our Id to LocalID
836 * the other side will be RemoteID.
841 vport->fc_myDID = PT2PT_LocalID;
843 /* If not registered with a transport, decrement ndlp reference
844 * count indicating that ndlp can be safely released when other
845 * references are removed.
847 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
850 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
853 * Cannot find existing Fabric ndlp, so allocate a
856 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
861 memcpy(&ndlp->nlp_portname, &sp->portName,
862 sizeof(struct lpfc_name));
863 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
864 sizeof(struct lpfc_name));
865 /* Set state will put ndlp onto node list if not already done */
866 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
867 spin_lock_irq(&ndlp->lock);
868 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
869 spin_unlock_irq(&ndlp->lock);
871 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
875 lpfc_config_link(phba, mbox);
877 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
879 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
880 if (rc == MBX_NOT_FINISHED) {
881 mempool_free(mbox, phba->mbox_mem_pool);
885 /* This side will wait for the PLOGI. If not registered with
886 * a transport, decrement node reference count indicating that
887 * ndlp can be released when other references are removed.
889 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
892 /* Start discovery - this should just do CLEAR_LA */
893 lpfc_disc_start(vport);
902 * lpfc_cmpl_els_flogi - Completion callback function for flogi
903 * @phba: pointer to lpfc hba data structure.
904 * @cmdiocb: pointer to lpfc command iocb data structure.
905 * @rspiocb: pointer to lpfc response iocb data structure.
907 * This routine is the top-level completion callback function for issuing
908 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
909 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
910 * retry has been made (either immediately or delayed with lpfc_els_retry()
911 * returning 1), the command IOCB will be released and function returned.
912 * If the retry attempt has been given up (possibly reach the maximum
913 * number of retries), one additional decrement of ndlp reference shall be
914 * invoked before going out after releasing the command IOCB. This will
915 * actually release the remote node (Note, lpfc_els_free_iocb() will also
916 * invoke one decrement of ndlp reference count). If no error reported in
917 * the IOCB status, the command Port ID field is used to determine whether
918 * this is a point-to-point topology or a fabric topology: if the Port ID
919 * field is assigned, it is a fabric topology; otherwise, it is a
920 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
921 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
922 * specific topology completion conditions.
925 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
926 struct lpfc_iocbq *rspiocb)
928 struct lpfc_vport *vport = cmdiocb->vport;
929 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
931 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
932 struct serv_parm *sp;
935 u32 ulp_status, ulp_word4, tmo;
936 bool flogi_in_retry = false;
938 /* Check to see if link went down during discovery */
939 if (lpfc_els_chk_latt(vport)) {
940 /* One additional decrement on node reference count to
941 * trigger the release of the node
943 if (!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD))
948 ulp_status = get_job_ulpstatus(phba, rspiocb);
949 ulp_word4 = get_job_word4(phba, rspiocb);
951 if (phba->sli_rev == LPFC_SLI_REV4) {
952 tmo = get_wqe_tmo(cmdiocb);
954 irsp = &rspiocb->iocb;
955 tmo = irsp->ulpTimeout;
958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
959 "FLOGI cmpl: status:x%x/x%x state:x%x",
960 ulp_status, ulp_word4,
965 * In case of FIP mode, perform roundrobin FCF failover
966 * due to new FCF discovery
968 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
969 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
970 if (phba->link_state < LPFC_LINK_UP)
971 goto stop_rr_fcf_flogi;
972 if ((phba->fcoe_cvl_eventtag_attn ==
973 phba->fcoe_cvl_eventtag) &&
974 (ulp_status == IOSTAT_LOCAL_REJECT) &&
975 ((ulp_word4 & IOERR_PARAM_MASK) ==
977 goto stop_rr_fcf_flogi;
979 phba->fcoe_cvl_eventtag_attn =
980 phba->fcoe_cvl_eventtag;
981 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
982 "2611 FLOGI failed on FCF (x%x), "
983 "status:x%x/x%x, tmo:x%x, perform "
984 "roundrobin FCF failover\n",
985 phba->fcf.current_rec.fcf_indx,
986 ulp_status, ulp_word4, tmo);
987 lpfc_sli4_set_fcf_flogi_fail(phba,
988 phba->fcf.current_rec.fcf_indx);
989 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
990 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
997 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
998 ((ulp_word4 & IOERR_PARAM_MASK) ==
999 IOERR_LOOP_OPEN_FAILURE)))
1000 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1001 "2858 FLOGI failure Status:x%x/x%x TMO"
1002 ":x%x Data x%x x%x\n",
1003 ulp_status, ulp_word4, tmo,
1004 phba->hba_flag, phba->fcf.fcf_flag);
1006 /* Check for retry */
1007 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1008 /* Address a timing race with dev_loss. If dev_loss
1009 * is active on this FPort node, put the initial ref
1010 * count back to stop premature node release actions.
1012 lpfc_check_nlp_post_devloss(vport, ndlp);
1013 flogi_in_retry = true;
1017 /* The FLOGI will not be retried. If the FPort node is not
1018 * registered with the SCSI transport, remove the initial
1019 * reference to trigger node release.
1021 if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS) &&
1022 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD))
1025 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1026 "0150 FLOGI failure Status:x%x/x%x "
1027 "xri x%x TMO:x%x refcnt %d\n",
1028 ulp_status, ulp_word4, cmdiocb->sli4_xritag,
1029 tmo, kref_read(&ndlp->kref));
1031 /* If this is not a loop open failure, bail out */
1032 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
1033 ((ulp_word4 & IOERR_PARAM_MASK) ==
1034 IOERR_LOOP_OPEN_FAILURE))) {
1036 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1037 "0100 FLOGI failure Status:x%x/x%x "
1039 ulp_status, ulp_word4, tmo);
1043 /* FLOGI failed, so there is no fabric */
1044 clear_bit(FC_FABRIC, &vport->fc_flag);
1045 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
1046 clear_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);
1048 /* If private loop, then allow max outstanding els to be
1049 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1050 * alpa map would take too long otherwise.
1052 if (phba->alpa_map[0] == 0)
1053 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1054 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1055 (!test_bit(FC_VFI_REGISTERED, &vport->fc_flag) ||
1056 (vport->fc_prevDID != vport->fc_myDID) ||
1057 phba->fc_topology_changed)) {
1058 if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag)) {
1059 if (phba->fc_topology_changed) {
1060 lpfc_unregister_fcf_prep(phba);
1061 clear_bit(FC_VFI_REGISTERED,
1063 phba->fc_topology_changed = 0;
1065 lpfc_sli4_unreg_all_rpis(vport);
1069 /* Do not register VFI if the driver aborted FLOGI */
1070 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4))
1071 lpfc_issue_reg_vfi(vport);
1077 clear_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag);
1078 clear_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag);
1081 * The FLOGI succeeded. Sync the data for the CPU before
1084 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1087 if (!lpfc_is_els_acc_rsp(prsp))
1089 sp = prsp->virt + sizeof(uint32_t);
1091 /* FLOGI completes successfully */
1092 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1093 "0101 FLOGI completes successfully, I/O tag:x%x "
1094 "xri x%x Data: x%x x%x x%x x%x x%x x%lx x%x %d\n",
1095 cmdiocb->iotag, cmdiocb->sli4_xritag,
1096 ulp_word4, sp->cmn.e_d_tov,
1097 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1098 vport->port_state, vport->fc_flag,
1099 sp->cmn.priority_tagging, kref_read(&ndlp->kref));
1101 /* reinitialize the VMID datastructure before returning */
1102 if (lpfc_is_vmid_enabled(phba))
1103 lpfc_reinit_vmid(vport);
1104 if (sp->cmn.priority_tagging)
1105 vport->phba->pport->vmid_flag |= (LPFC_VMID_ISSUE_QFPA |
1106 LPFC_VMID_TYPE_PRIO);
1109 * Address a timing race with dev_loss. If dev_loss is active on
1110 * this FPort node, put the initial ref count back to stop premature
1111 * node release actions.
1113 lpfc_check_nlp_post_devloss(vport, ndlp);
1114 if (vport->port_state == LPFC_FLOGI) {
1116 * If Common Service Parameters indicate Nport
1117 * we are point to point, if Fport we are Fabric.
1120 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp,
1122 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1123 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1125 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1126 "2831 FLOGI response with cleared Fabric "
1127 "bit fcf_index 0x%x "
1128 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1130 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1131 phba->fcf.current_rec.fcf_indx,
1132 phba->fcf.current_rec.switch_name[0],
1133 phba->fcf.current_rec.switch_name[1],
1134 phba->fcf.current_rec.switch_name[2],
1135 phba->fcf.current_rec.switch_name[3],
1136 phba->fcf.current_rec.switch_name[4],
1137 phba->fcf.current_rec.switch_name[5],
1138 phba->fcf.current_rec.switch_name[6],
1139 phba->fcf.current_rec.switch_name[7],
1140 phba->fcf.current_rec.fabric_name[0],
1141 phba->fcf.current_rec.fabric_name[1],
1142 phba->fcf.current_rec.fabric_name[2],
1143 phba->fcf.current_rec.fabric_name[3],
1144 phba->fcf.current_rec.fabric_name[4],
1145 phba->fcf.current_rec.fabric_name[5],
1146 phba->fcf.current_rec.fabric_name[6],
1147 phba->fcf.current_rec.fabric_name[7]);
1150 spin_lock_irq(&phba->hbalock);
1151 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1152 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1153 spin_unlock_irq(&phba->hbalock);
1154 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1158 /* Mark the FCF discovery process done */
1159 if (phba->hba_flag & HBA_FIP_SUPPORT)
1160 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1162 "2769 FLOGI to FCF (x%x) "
1163 "completed successfully\n",
1164 phba->fcf.current_rec.fcf_indx);
1165 spin_lock_irq(&phba->hbalock);
1166 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1167 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1168 spin_unlock_irq(&phba->hbalock);
1169 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1172 } else if (vport->port_state > LPFC_FLOGI &&
1173 test_bit(FC_PT2PT, &vport->fc_flag)) {
1175 * In a p2p topology, it is possible that discovery has
1176 * already progressed, and this completion can be ignored.
1177 * Recheck the indicated topology.
1184 spin_lock_irq(&phba->hbalock);
1185 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1186 spin_unlock_irq(&phba->hbalock);
1188 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
1189 /* FLOGI failed, so just use loop map to make discovery list */
1190 lpfc_disc_list_loopmap(vport);
1192 /* Start discovery */
1193 lpfc_disc_start(vport);
1194 } else if (((ulp_status != IOSTAT_LOCAL_REJECT) ||
1195 (((ulp_word4 & IOERR_PARAM_MASK) !=
1196 IOERR_SLI_ABORTED) &&
1197 ((ulp_word4 & IOERR_PARAM_MASK) !=
1198 IOERR_SLI_DOWN))) &&
1199 (phba->link_state != LPFC_CLEAR_LA)) {
1200 /* If FLOGI failed enable link interrupt. */
1201 lpfc_issue_clear_la(phba, vport);
1204 if (!flogi_in_retry)
1205 phba->hba_flag &= ~HBA_FLOGI_OUTSTANDING;
1207 lpfc_els_free_iocb(phba, cmdiocb);
1212 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1213 * aborted during a link down
1214 * @phba: pointer to lpfc hba data structure.
1215 * @cmdiocb: pointer to lpfc command iocb data structure.
1216 * @rspiocb: pointer to lpfc response iocb data structure.
1220 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1221 struct lpfc_iocbq *rspiocb)
1225 u32 ulp_status, ulp_word4;
1227 pcmd = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
1230 ulp_status = get_job_ulpstatus(phba, rspiocb);
1231 ulp_word4 = get_job_word4(phba, rspiocb);
1233 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1234 "6445 ELS completes after LINK_DOWN: "
1235 " Status %x/%x cmd x%x flg x%x\n",
1236 ulp_status, ulp_word4, cmd,
1239 if (cmdiocb->cmd_flag & LPFC_IO_FABRIC) {
1240 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
1241 atomic_dec(&phba->fabric_iocb_count);
1243 lpfc_els_free_iocb(phba, cmdiocb);
1247 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1248 * @vport: pointer to a host virtual N_Port data structure.
1249 * @ndlp: pointer to a node-list data structure.
1250 * @retry: number of retries to the command IOCB.
1252 * This routine issues a Fabric Login (FLOGI) Request ELS command
1253 * for a @vport. The initiator service parameters are put into the payload
1254 * of the FLOGI Request IOCB and the top-level callback function pointer
1255 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1256 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1257 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1259 * Note that the ndlp reference count will be incremented by 1 for holding the
1260 * ndlp and the reference to ndlp will be stored into the ndlp field of
1261 * the IOCB for the completion callback function to the FLOGI ELS command.
1264 * 0 - successfully issued flogi iocb for @vport
1265 * 1 - failed to issue flogi iocb for @vport
1268 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1271 struct lpfc_hba *phba = vport->phba;
1272 struct serv_parm *sp;
1273 union lpfc_wqe128 *wqe = NULL;
1274 IOCB_t *icmd = NULL;
1275 struct lpfc_iocbq *elsiocb;
1276 struct lpfc_iocbq defer_flogi_acc;
1282 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1283 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1284 ndlp->nlp_DID, ELS_CMD_FLOGI);
1289 wqe = &elsiocb->wqe;
1290 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
1291 icmd = &elsiocb->iocb;
1293 /* For FLOGI request, remainder of payload is service parameters */
1294 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1295 pcmd += sizeof(uint32_t);
1296 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1297 sp = (struct serv_parm *) pcmd;
1299 /* Setup CSPs accordingly for Fabric */
1300 sp->cmn.e_d_tov = 0;
1301 sp->cmn.w2.r_a_tov = 0;
1302 sp->cmn.virtual_fabric_support = 0;
1303 sp->cls1.classValid = 0;
1304 if (sp->cmn.fcphLow < FC_PH3)
1305 sp->cmn.fcphLow = FC_PH3;
1306 if (sp->cmn.fcphHigh < FC_PH3)
1307 sp->cmn.fcphHigh = FC_PH3;
1309 /* Determine if switch supports priority tagging */
1310 if (phba->cfg_vmid_priority_tagging) {
1311 sp->cmn.priority_tagging = 1;
1312 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
1313 if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0,
1314 sizeof(vport->lpfc_vmid_host_uuid))) {
1315 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn,
1316 sizeof(phba->wwpn));
1317 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn,
1318 sizeof(phba->wwnn));
1322 if (phba->sli_rev == LPFC_SLI_REV4) {
1323 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1324 LPFC_SLI_INTF_IF_TYPE_0) {
1325 /* FLOGI needs to be 3 for WQE FCFI */
1327 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
1329 /* Set the fcfi to the fcfi we registered with */
1330 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
1334 /* Can't do SLI4 class2 without support sequence coalescing */
1335 sp->cls2.classValid = 0;
1336 sp->cls2.seqDelivery = 0;
1338 /* Historical, setting sequential-delivery bit for SLI3 */
1339 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1340 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1341 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1342 sp->cmn.request_multiple_Nport = 1;
1343 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1347 sp->cmn.request_multiple_Nport = 0;
1350 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1351 icmd->un.elsreq64.myID = 0;
1352 icmd->un.elsreq64.fl = 1;
1356 tmo = phba->fc_ratov;
1357 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1358 lpfc_set_disctmo(vport);
1359 phba->fc_ratov = tmo;
1361 phba->fc_stat.elsXmitFLOGI++;
1362 elsiocb->cmd_cmpl = lpfc_cmpl_els_flogi;
1364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1365 "Issue FLOGI: opt:x%x",
1366 phba->sli3_options, 0, 0);
1368 elsiocb->ndlp = lpfc_nlp_get(ndlp);
1369 if (!elsiocb->ndlp) {
1370 lpfc_els_free_iocb(phba, elsiocb);
1374 /* Avoid race with FLOGI completion and hba_flags. */
1375 phba->hba_flag |= (HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
1377 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1378 if (rc == IOCB_ERROR) {
1379 phba->hba_flag &= ~(HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
1380 lpfc_els_free_iocb(phba, elsiocb);
1385 /* Clear external loopback plug detected flag */
1386 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
1388 /* Check for a deferred FLOGI ACC condition */
1389 if (phba->defer_flogi_acc_flag) {
1390 /* lookup ndlp for received FLOGI */
1391 ndlp = lpfc_findnode_did(vport, 0);
1395 did = vport->fc_myDID;
1396 vport->fc_myDID = Fabric_DID;
1398 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1400 if (phba->sli_rev == LPFC_SLI_REV4) {
1401 bf_set(wqe_ctxt_tag,
1402 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1403 phba->defer_flogi_acc_rx_id);
1405 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1406 phba->defer_flogi_acc_ox_id);
1408 icmd = &defer_flogi_acc.iocb;
1409 icmd->ulpContext = phba->defer_flogi_acc_rx_id;
1410 icmd->unsli3.rcvsli3.ox_id =
1411 phba->defer_flogi_acc_ox_id;
1414 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1415 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1416 " ox_id: x%x, hba_flag x%x\n",
1417 phba->defer_flogi_acc_rx_id,
1418 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1420 /* Send deferred FLOGI ACC */
1421 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1424 phba->defer_flogi_acc_flag = false;
1425 vport->fc_myDID = did;
1427 /* Decrement ndlp reference count to indicate the node can be
1428 * released when other references are removed.
1437 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1438 * @phba: pointer to lpfc hba data structure.
1440 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1441 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1442 * list and issues an abort IOCB commond on each outstanding IOCB that
1443 * contains a active Fabric_DID ndlp. Note that this function is to issue
1444 * the abort IOCB command on all the outstanding IOCBs, thus when this
1445 * function returns, it does not guarantee all the IOCBs are actually aborted.
1448 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1451 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1453 struct lpfc_sli_ring *pring;
1454 struct lpfc_iocbq *iocb, *next_iocb;
1455 struct lpfc_nodelist *ndlp;
1458 /* Abort outstanding I/O on NPort <nlp_DID> */
1459 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1460 "0201 Abort outstanding I/O on NPort x%x\n",
1463 pring = lpfc_phba_elsring(phba);
1464 if (unlikely(!pring))
1468 * Check the txcmplq for an iocb that matches the nport the driver is
1471 spin_lock_irq(&phba->hbalock);
1472 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1473 ulp_command = get_job_cmnd(phba, iocb);
1474 if (ulp_command == CMD_ELS_REQUEST64_CR) {
1476 if (ndlp && ndlp->nlp_DID == Fabric_DID) {
1477 if (test_bit(FC_PT2PT, &phba->pport->fc_flag) &&
1478 !test_bit(FC_PT2PT_PLOGI,
1479 &phba->pport->fc_flag))
1480 iocb->fabric_cmd_cmpl =
1481 lpfc_ignore_els_cmpl;
1482 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1487 /* Make sure HBA is alive */
1488 lpfc_issue_hb_tmo(phba);
1490 spin_unlock_irq(&phba->hbalock);
1496 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1497 * @vport: pointer to a host virtual N_Port data structure.
1499 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1500 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1501 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1502 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1503 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1504 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1508 * 0 - failed to issue initial flogi for @vport
1509 * 1 - successfully issued initial flogi for @vport
1512 lpfc_initial_flogi(struct lpfc_vport *vport)
1514 struct lpfc_nodelist *ndlp;
1516 vport->port_state = LPFC_FLOGI;
1517 lpfc_set_disctmo(vport);
1519 /* First look for the Fabric ndlp */
1520 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1522 /* Cannot find existing Fabric ndlp, so allocate a new one */
1523 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1526 /* Set the node type */
1527 ndlp->nlp_type |= NLP_FABRIC;
1529 /* Put ndlp onto node list */
1530 lpfc_enqueue_node(vport, ndlp);
1533 /* Reset the Fabric flag, topology change may have happened */
1534 clear_bit(FC_FABRIC, &vport->fc_flag);
1535 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1536 /* A node reference should be retained while registered with a
1537 * transport or dev-loss-evt work is pending.
1538 * Otherwise, decrement node reference to trigger release.
1540 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
1541 !(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
1549 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1550 * @vport: pointer to a host virtual N_Port data structure.
1552 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1553 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1554 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1555 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1556 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1557 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1561 * 0 - failed to issue initial fdisc for @vport
1562 * 1 - successfully issued initial fdisc for @vport
1565 lpfc_initial_fdisc(struct lpfc_vport *vport)
1567 struct lpfc_nodelist *ndlp;
1569 /* First look for the Fabric ndlp */
1570 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1572 /* Cannot find existing Fabric ndlp, so allocate a new one */
1573 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1577 /* NPIV is only supported in Fabrics. */
1578 ndlp->nlp_type |= NLP_FABRIC;
1580 /* Put ndlp onto node list */
1581 lpfc_enqueue_node(vport, ndlp);
1584 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1585 /* A node reference should be retained while registered with a
1586 * transport or dev-loss-evt work is pending.
1587 * Otherwise, decrement node reference to trigger release.
1589 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
1590 !(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
1598 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1599 * @vport: pointer to a host virtual N_Port data structure.
1601 * This routine checks whether there are more remaining Port Logins
1602 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1603 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1604 * to issue ELS PLOGIs up to the configured discover threads with the
1605 * @vport (@vport->cfg_discovery_threads). The function also decrement
1606 * the @vport's num_disc_node by 1 if it is not already 0.
1609 lpfc_more_plogi(struct lpfc_vport *vport)
1611 if (vport->num_disc_nodes)
1612 vport->num_disc_nodes--;
1614 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1615 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1616 "0232 Continue discovery with %d PLOGIs to go "
1617 "Data: x%x x%lx x%x\n",
1618 vport->num_disc_nodes,
1619 atomic_read(&vport->fc_plogi_cnt),
1620 vport->fc_flag, vport->port_state);
1621 /* Check to see if there are more PLOGIs to be sent */
1622 if (test_bit(FC_NLP_MORE, &vport->fc_flag))
1623 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1624 lpfc_els_disc_plogi(vport);
1630 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1631 * @phba: pointer to lpfc hba data structure.
1632 * @prsp: pointer to response IOCB payload.
1633 * @ndlp: pointer to a node-list data structure.
1635 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1636 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1637 * The following cases are considered N_Port confirmed:
1638 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1639 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1640 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1641 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1642 * 1) if there is a node on vport list other than the @ndlp with the same
1643 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1644 * on that node to release the RPI associated with the node; 2) if there is
1645 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1646 * into, a new node shall be allocated (or activated). In either case, the
1647 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1648 * be released and the new_ndlp shall be put on to the vport node list and
1649 * its pointer returned as the confirmed node.
1651 * Note that before the @ndlp got "released", the keepDID from not-matching
1652 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1653 * of the @ndlp. This is because the release of @ndlp is actually to put it
1654 * into an inactive state on the vport node list and the vport node list
1655 * management algorithm does not allow two node with a same DID.
1658 * pointer to the PLOGI N_Port @ndlp
1660 static struct lpfc_nodelist *
1661 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1662 struct lpfc_nodelist *ndlp)
1664 struct lpfc_vport *vport = ndlp->vport;
1665 struct lpfc_nodelist *new_ndlp;
1666 struct serv_parm *sp;
1667 uint8_t name[sizeof(struct lpfc_name)];
1668 uint32_t keepDID = 0, keep_nlp_flag = 0;
1670 uint32_t keep_new_nlp_flag = 0;
1671 uint16_t keep_nlp_state;
1672 u32 keep_nlp_fc4_type = 0;
1673 struct lpfc_nvme_rport *keep_nrport = NULL;
1674 unsigned long *active_rrqs_xri_bitmap = NULL;
1676 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1677 memset(name, 0, sizeof(struct lpfc_name));
1679 /* Now we find out if the NPort we are logging into, matches the WWPN
1680 * we have for that ndlp. If not, we have some work to do.
1682 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1684 /* return immediately if the WWPN matches ndlp */
1685 if (new_ndlp == ndlp)
1688 if (phba->sli_rev == LPFC_SLI_REV4) {
1689 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1691 if (active_rrqs_xri_bitmap)
1692 memset(active_rrqs_xri_bitmap, 0,
1693 phba->cfg_rrq_xri_bitmap_sz);
1696 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1697 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1698 "new_ndlp x%x x%x x%x\n",
1699 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1700 (new_ndlp ? new_ndlp->nlp_DID : 0),
1701 (new_ndlp ? new_ndlp->nlp_flag : 0),
1702 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1705 rc = memcmp(&ndlp->nlp_portname, name,
1706 sizeof(struct lpfc_name));
1708 if (active_rrqs_xri_bitmap)
1709 mempool_free(active_rrqs_xri_bitmap,
1710 phba->active_rrq_pool);
1713 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1715 if (active_rrqs_xri_bitmap)
1716 mempool_free(active_rrqs_xri_bitmap,
1717 phba->active_rrq_pool);
1721 if (phba->sli_rev == LPFC_SLI_REV4 &&
1722 active_rrqs_xri_bitmap)
1723 memcpy(active_rrqs_xri_bitmap,
1724 new_ndlp->active_rrqs_xri_bitmap,
1725 phba->cfg_rrq_xri_bitmap_sz);
1728 * Unregister from backend if not done yet. Could have been
1729 * skipped due to ADISC
1731 lpfc_nlp_unreg_node(vport, new_ndlp);
1734 keepDID = new_ndlp->nlp_DID;
1736 /* At this point in this routine, we know new_ndlp will be
1737 * returned. however, any previous GID_FTs that were done
1738 * would have updated nlp_fc4_type in ndlp, so we must ensure
1739 * new_ndlp has the right value.
1741 if (test_bit(FC_FABRIC, &vport->fc_flag)) {
1742 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1743 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1746 lpfc_unreg_rpi(vport, new_ndlp);
1747 new_ndlp->nlp_DID = ndlp->nlp_DID;
1748 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1749 if (phba->sli_rev == LPFC_SLI_REV4)
1750 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1751 ndlp->active_rrqs_xri_bitmap,
1752 phba->cfg_rrq_xri_bitmap_sz);
1754 /* Lock both ndlps */
1755 spin_lock_irq(&ndlp->lock);
1756 spin_lock_irq(&new_ndlp->lock);
1757 keep_new_nlp_flag = new_ndlp->nlp_flag;
1758 keep_nlp_flag = ndlp->nlp_flag;
1759 new_ndlp->nlp_flag = ndlp->nlp_flag;
1761 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1762 if (keep_new_nlp_flag & NLP_UNREG_INP)
1763 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1765 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1767 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1768 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1769 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1771 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1774 * Retain the DROPPED flag. This will take care of the init
1775 * refcount when affecting the state change
1777 if (keep_new_nlp_flag & NLP_DROPPED)
1778 new_ndlp->nlp_flag |= NLP_DROPPED;
1780 new_ndlp->nlp_flag &= ~NLP_DROPPED;
1782 ndlp->nlp_flag = keep_new_nlp_flag;
1784 /* if ndlp had NLP_UNREG_INP set, keep it */
1785 if (keep_nlp_flag & NLP_UNREG_INP)
1786 ndlp->nlp_flag |= NLP_UNREG_INP;
1788 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1790 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1791 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1792 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1794 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1797 * Retain the DROPPED flag. This will take care of the init
1798 * refcount when affecting the state change
1800 if (keep_nlp_flag & NLP_DROPPED)
1801 ndlp->nlp_flag |= NLP_DROPPED;
1803 ndlp->nlp_flag &= ~NLP_DROPPED;
1805 spin_unlock_irq(&new_ndlp->lock);
1806 spin_unlock_irq(&ndlp->lock);
1808 /* Set nlp_states accordingly */
1809 keep_nlp_state = new_ndlp->nlp_state;
1810 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1812 /* interchange the nvme remoteport structs */
1813 keep_nrport = new_ndlp->nrport;
1814 new_ndlp->nrport = ndlp->nrport;
1816 /* Move this back to NPR state */
1817 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1818 /* The ndlp doesn't have a portname yet, but does have an
1819 * NPort ID. The new_ndlp portname matches the Rport's
1820 * portname. Reinstantiate the new_ndlp and reset the ndlp.
1822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1823 "3179 PLOGI confirm NEW: %x %x\n",
1824 new_ndlp->nlp_DID, keepDID);
1826 /* Two ndlps cannot have the same did on the nodelist.
1827 * The KeepDID and keep_nlp_fc4_type need to be swapped
1828 * because ndlp is inflight with no WWPN.
1830 ndlp->nlp_DID = keepDID;
1831 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1832 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1833 if (phba->sli_rev == LPFC_SLI_REV4 &&
1834 active_rrqs_xri_bitmap)
1835 memcpy(ndlp->active_rrqs_xri_bitmap,
1836 active_rrqs_xri_bitmap,
1837 phba->cfg_rrq_xri_bitmap_sz);
1840 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1841 "3180 PLOGI confirm SWAP: %x %x\n",
1842 new_ndlp->nlp_DID, keepDID);
1844 lpfc_unreg_rpi(vport, ndlp);
1846 /* The ndlp and new_ndlp both have WWPNs but are swapping
1847 * NPort Ids and attributes.
1849 ndlp->nlp_DID = keepDID;
1850 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1852 if (phba->sli_rev == LPFC_SLI_REV4 &&
1853 active_rrqs_xri_bitmap)
1854 memcpy(ndlp->active_rrqs_xri_bitmap,
1855 active_rrqs_xri_bitmap,
1856 phba->cfg_rrq_xri_bitmap_sz);
1858 /* Since we are switching over to the new_ndlp,
1859 * reset the old ndlp state
1861 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1862 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1863 keep_nlp_state = NLP_STE_NPR_NODE;
1864 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1865 ndlp->nrport = keep_nrport;
1869 * If ndlp is not associated with any rport we can drop it here else
1870 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1872 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1873 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1875 if (phba->sli_rev == LPFC_SLI_REV4 &&
1876 active_rrqs_xri_bitmap)
1877 mempool_free(active_rrqs_xri_bitmap,
1878 phba->active_rrq_pool);
1880 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1881 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1882 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1883 new_ndlp->nlp_fc4_type);
1889 * lpfc_end_rscn - Check and handle more rscn for a vport
1890 * @vport: pointer to a host virtual N_Port data structure.
1892 * This routine checks whether more Registration State Change
1893 * Notifications (RSCNs) came in while the discovery state machine was in
1894 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1895 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1896 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1897 * handling the RSCNs.
1900 lpfc_end_rscn(struct lpfc_vport *vport)
1903 if (test_bit(FC_RSCN_MODE, &vport->fc_flag)) {
1905 * Check to see if more RSCNs came in while we were
1906 * processing this one.
1908 if (vport->fc_rscn_id_cnt ||
1909 test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag))
1910 lpfc_els_handle_rscn(vport);
1912 clear_bit(FC_RSCN_MODE, &vport->fc_flag);
1917 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1918 * @phba: pointer to lpfc hba data structure.
1919 * @cmdiocb: pointer to lpfc command iocb data structure.
1920 * @rspiocb: pointer to lpfc response iocb data structure.
1922 * This routine will call the clear rrq function to free the rrq and
1923 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1924 * exist then the clear_rrq is still called because the rrq needs to
1929 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1930 struct lpfc_iocbq *rspiocb)
1932 struct lpfc_vport *vport = cmdiocb->vport;
1933 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
1934 struct lpfc_node_rrq *rrq;
1935 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
1936 u32 ulp_word4 = get_job_word4(phba, rspiocb);
1938 /* we pass cmdiocb to state machine which needs rspiocb as well */
1939 rrq = cmdiocb->context_un.rrq;
1940 cmdiocb->rsp_iocb = rspiocb;
1942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1943 "RRQ cmpl: status:x%x/x%x did:x%x",
1944 ulp_status, ulp_word4,
1945 get_job_els_rsp64_did(phba, cmdiocb));
1948 /* rrq completes to NPort <nlp_DID> */
1949 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1950 "2880 RRQ completes to DID x%x "
1951 "Data: x%x x%x x%x x%x x%x\n",
1952 ndlp->nlp_DID, ulp_status, ulp_word4,
1953 get_wqe_tmo(cmdiocb), rrq->xritag, rrq->rxid);
1956 /* Check for retry */
1957 /* RRQ failed Don't print the vport to vport rjts */
1958 if (ulp_status != IOSTAT_LS_RJT ||
1959 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
1960 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
1961 (phba)->pport->cfg_log_verbose & LOG_ELS)
1962 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1963 "2881 RRQ failure DID:%06X Status:"
1965 ndlp->nlp_DID, ulp_status,
1969 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1970 lpfc_els_free_iocb(phba, cmdiocb);
1975 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1976 * @phba: pointer to lpfc hba data structure.
1977 * @cmdiocb: pointer to lpfc command iocb data structure.
1978 * @rspiocb: pointer to lpfc response iocb data structure.
1980 * This routine is the completion callback function for issuing the Port
1981 * Login (PLOGI) command. For PLOGI completion, there must be an active
1982 * ndlp on the vport node list that matches the remote node ID from the
1983 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1984 * ignored and command IOCB released. The PLOGI response IOCB status is
1985 * checked for error conditions. If there is error status reported, PLOGI
1986 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1987 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1988 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1989 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1990 * there are additional N_Port nodes with the vport that need to perform
1991 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1995 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1996 struct lpfc_iocbq *rspiocb)
1998 struct lpfc_vport *vport = cmdiocb->vport;
2000 struct lpfc_nodelist *ndlp, *free_ndlp;
2001 struct lpfc_dmabuf *prsp;
2003 struct serv_parm *sp = NULL;
2004 u32 ulp_status, ulp_word4, did, iotag;
2005 bool release_node = false;
2007 /* we pass cmdiocb to state machine which needs rspiocb as well */
2008 cmdiocb->rsp_iocb = rspiocb;
2010 ulp_status = get_job_ulpstatus(phba, rspiocb);
2011 ulp_word4 = get_job_word4(phba, rspiocb);
2012 did = get_job_els_rsp64_did(phba, cmdiocb);
2014 if (phba->sli_rev == LPFC_SLI_REV4) {
2015 iotag = get_wqe_reqtag(cmdiocb);
2017 irsp = &rspiocb->iocb;
2018 iotag = irsp->ulpIoTag;
2021 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2022 "PLOGI cmpl: status:x%x/x%x did:x%x",
2023 ulp_status, ulp_word4, did);
2025 ndlp = lpfc_findnode_did(vport, did);
2027 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2028 "0136 PLOGI completes to NPort x%x "
2029 "with no ndlp. Data: x%x x%x x%x\n",
2030 did, ulp_status, ulp_word4, iotag);
2034 /* Since ndlp can be freed in the disc state machine, note if this node
2035 * is being used during discovery.
2037 spin_lock_irq(&ndlp->lock);
2038 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2039 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2040 spin_unlock_irq(&ndlp->lock);
2042 /* PLOGI completes to NPort <nlp_DID> */
2043 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2044 "0102 PLOGI completes to NPort x%06x "
2045 "IoTag x%x Data: x%x x%x x%x x%x x%x\n",
2046 ndlp->nlp_DID, iotag,
2048 ulp_status, ulp_word4,
2049 disc, vport->num_disc_nodes);
2051 /* Check to see if link went down during discovery */
2052 if (lpfc_els_chk_latt(vport)) {
2053 spin_lock_irq(&ndlp->lock);
2054 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2055 spin_unlock_irq(&ndlp->lock);
2060 /* Check for retry */
2061 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2062 /* ELS command is being retried */
2064 spin_lock_irq(&ndlp->lock);
2065 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2066 spin_unlock_irq(&ndlp->lock);
2070 /* PLOGI failed Don't print the vport to vport rjts */
2071 if (ulp_status != IOSTAT_LS_RJT ||
2072 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
2073 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
2074 (phba)->pport->cfg_log_verbose & LOG_ELS)
2075 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2076 "2753 PLOGI failure DID:%06X "
2078 ndlp->nlp_DID, ulp_status,
2081 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2082 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4))
2083 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2084 NLP_EVT_CMPL_PLOGI);
2086 /* If a PLOGI collision occurred, the node needs to continue
2087 * with the reglogin process.
2089 spin_lock_irq(&ndlp->lock);
2090 if ((ndlp->nlp_flag & (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI)) &&
2091 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
2092 spin_unlock_irq(&ndlp->lock);
2096 /* No PLOGI collision and the node is not registered with the
2097 * scsi or nvme transport. It is no longer an active node. Just
2098 * start the device remove process.
2100 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2101 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2102 if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
2103 release_node = true;
2105 spin_unlock_irq(&ndlp->lock);
2108 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2111 /* Good status, call state machine */
2112 prsp = list_get_first(&cmdiocb->cmd_dmabuf->list,
2113 struct lpfc_dmabuf, list);
2116 if (!lpfc_is_els_acc_rsp(prsp))
2118 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2120 sp = (struct serv_parm *)((u8 *)prsp->virt +
2123 ndlp->vmid_support = 0;
2124 if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) ||
2125 (phba->cfg_vmid_priority_tagging &&
2126 sp->cmn.priority_tagging)) {
2127 lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS,
2128 "4018 app_hdr_support %d tagging %d DID x%x\n",
2129 sp->cmn.app_hdr_support,
2130 sp->cmn.priority_tagging,
2132 /* if the dest port supports VMID, mark it in ndlp */
2133 ndlp->vmid_support = 1;
2136 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2137 NLP_EVT_CMPL_PLOGI);
2140 if (disc && vport->num_disc_nodes) {
2141 /* Check to see if there are more PLOGIs to be sent */
2142 lpfc_more_plogi(vport);
2144 if (vport->num_disc_nodes == 0) {
2145 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag);
2147 lpfc_can_disctmo(vport);
2148 lpfc_end_rscn(vport);
2153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2154 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2155 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2158 /* Release the reference on the original I/O request. */
2159 free_ndlp = cmdiocb->ndlp;
2161 lpfc_els_free_iocb(phba, cmdiocb);
2162 lpfc_nlp_put(free_ndlp);
2167 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2168 * @vport: pointer to a host virtual N_Port data structure.
2169 * @did: destination port identifier.
2170 * @retry: number of retries to the command IOCB.
2172 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2173 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2174 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2175 * This routine constructs the proper fields of the PLOGI IOCB and invokes
2176 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2178 * Note that the ndlp reference count will be incremented by 1 for holding
2179 * the ndlp and the reference to ndlp will be stored into the ndlp field
2180 * of the IOCB for the completion callback function to the PLOGI ELS command.
2183 * 0 - Successfully issued a plogi for @vport
2184 * 1 - failed to issue a plogi for @vport
2187 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2189 struct lpfc_hba *phba = vport->phba;
2190 struct serv_parm *sp;
2191 struct lpfc_nodelist *ndlp;
2192 struct lpfc_iocbq *elsiocb;
2197 ndlp = lpfc_findnode_did(vport, did);
2201 /* Defer the processing of the issue PLOGI until after the
2202 * outstanding UNREG_RPI mbox command completes, unless we
2203 * are going offline. This logic does not apply for Fabric DIDs
2205 if ((ndlp->nlp_flag & (NLP_IGNR_REG_CMPL | NLP_UNREG_INP)) &&
2206 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2207 !test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
2208 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2209 "4110 Issue PLOGI x%x deferred "
2210 "on NPort x%x rpi x%x flg x%x Data:"
2212 ndlp->nlp_defer_did, ndlp->nlp_DID,
2213 ndlp->nlp_rpi, ndlp->nlp_flag, ndlp);
2215 /* We can only defer 1st PLOGI */
2216 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2217 ndlp->nlp_defer_did = did;
2221 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2222 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2227 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2229 /* For PLOGI request, remainder of payload is service parameters */
2230 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2231 pcmd += sizeof(uint32_t);
2232 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2233 sp = (struct serv_parm *) pcmd;
2236 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2237 * to device on remote loops work.
2239 if (test_bit(FC_FABRIC, &vport->fc_flag) &&
2240 !test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
2241 sp->cmn.altBbCredit = 1;
2243 if (sp->cmn.fcphLow < FC_PH_4_3)
2244 sp->cmn.fcphLow = FC_PH_4_3;
2246 if (sp->cmn.fcphHigh < FC_PH3)
2247 sp->cmn.fcphHigh = FC_PH3;
2249 sp->cmn.valid_vendor_ver_level = 0;
2250 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2251 sp->cmn.bbRcvSizeMsb &= 0xF;
2253 /* Check if the destination port supports VMID */
2254 ndlp->vmid_support = 0;
2255 if (vport->vmid_priority_tagging)
2256 sp->cmn.priority_tagging = 1;
2257 else if (phba->cfg_vmid_app_header &&
2258 bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags))
2259 sp->cmn.app_hdr_support = 1;
2261 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2262 "Issue PLOGI: did:x%x",
2265 /* If our firmware supports this feature, convey that
2266 * information to the target using the vendor specific field.
2268 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2269 sp->cmn.valid_vendor_ver_level = 1;
2270 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2271 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2274 phba->fc_stat.elsXmitPLOGI++;
2275 elsiocb->cmd_cmpl = lpfc_cmpl_els_plogi;
2277 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2278 "Issue PLOGI: did:x%x refcnt %d",
2279 did, kref_read(&ndlp->kref), 0);
2280 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2281 if (!elsiocb->ndlp) {
2282 lpfc_els_free_iocb(phba, elsiocb);
2286 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2288 lpfc_els_free_iocb(phba, elsiocb);
2297 * lpfc_cmpl_els_prli - Completion callback function for prli
2298 * @phba: pointer to lpfc hba data structure.
2299 * @cmdiocb: pointer to lpfc command iocb data structure.
2300 * @rspiocb: pointer to lpfc response iocb data structure.
2302 * This routine is the completion callback function for a Process Login
2303 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2304 * status. If there is error status reported, PRLI retry shall be attempted
2305 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2306 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2307 * ndlp to mark the PRLI completion.
2310 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2311 struct lpfc_iocbq *rspiocb)
2313 struct lpfc_vport *vport = cmdiocb->vport;
2314 struct lpfc_nodelist *ndlp;
2319 bool release_node = false;
2321 /* we pass cmdiocb to state machine which needs rspiocb as well */
2322 cmdiocb->rsp_iocb = rspiocb;
2324 ndlp = cmdiocb->ndlp;
2326 ulp_status = get_job_ulpstatus(phba, rspiocb);
2327 ulp_word4 = get_job_word4(phba, rspiocb);
2329 spin_lock_irq(&ndlp->lock);
2330 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2332 /* Driver supports multiple FC4 types. Counters matter. */
2333 vport->fc_prli_sent--;
2334 ndlp->fc4_prli_sent--;
2335 spin_unlock_irq(&ndlp->lock);
2337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2338 "PRLI cmpl: status:x%x/x%x did:x%x",
2339 ulp_status, ulp_word4,
2342 /* PRLI completes to NPort <nlp_DID> */
2343 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2344 "0103 PRLI completes to NPort x%06x "
2345 "Data: x%x x%x x%x x%x x%x\n",
2346 ndlp->nlp_DID, ulp_status, ulp_word4,
2347 vport->num_disc_nodes, ndlp->fc4_prli_sent,
2348 ndlp->fc4_xpt_flags);
2350 /* Check to see if link went down during discovery */
2351 if (lpfc_els_chk_latt(vport))
2355 /* Check for retry */
2356 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2357 /* ELS command is being retried */
2361 /* If we don't send GFT_ID to Fabric, a PRLI error
2362 * could be expected.
2364 if (test_bit(FC_FABRIC, &vport->fc_flag) ||
2365 vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH) {
2367 loglevel = LOG_TRACE_EVENT;
2374 lpfc_printf_vlog(vport, mode, loglevel,
2375 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2376 "data: x%x x%x x%x\n",
2377 ndlp->nlp_DID, ulp_status,
2378 ulp_word4, ndlp->nlp_state,
2379 ndlp->fc4_prli_sent, ndlp->nlp_flag);
2381 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2382 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4))
2383 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2386 /* The following condition catches an inflight transition
2387 * mismatch typically caused by an RSCN. Skip any
2388 * processing to allow recovery.
2390 if ((ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
2391 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE) ||
2392 (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2393 ndlp->nlp_flag & NLP_DELAY_TMO)) {
2394 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
2395 "2784 PRLI cmpl: Allow Node recovery "
2396 "DID x%06x nstate x%x nflag x%x\n",
2397 ndlp->nlp_DID, ndlp->nlp_state,
2403 * For P2P topology, retain the node so that PLOGI can be
2404 * attempted on it again.
2406 if (test_bit(FC_PT2PT, &vport->fc_flag))
2409 /* As long as this node is not registered with the SCSI
2410 * or NVMe transport and no other PRLIs are outstanding,
2411 * it is no longer an active node. Otherwise devloss
2412 * handles the final cleanup.
2414 spin_lock_irq(&ndlp->lock);
2415 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2416 !ndlp->fc4_prli_sent) {
2417 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2418 if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
2419 release_node = true;
2421 spin_unlock_irq(&ndlp->lock);
2424 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2427 /* Good status, call state machine. However, if another
2428 * PRLI is outstanding, don't call the state machine
2429 * because final disposition to Mapped or Unmapped is
2432 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2437 lpfc_els_free_iocb(phba, cmdiocb);
2443 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2444 * @vport: pointer to a host virtual N_Port data structure.
2445 * @ndlp: pointer to a node-list data structure.
2446 * @retry: number of retries to the command IOCB.
2448 * This routine issues a Process Login (PRLI) ELS command for the
2449 * @vport. The PRLI service parameters are set up in the payload of the
2450 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2451 * is put to the IOCB completion callback func field before invoking the
2452 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2454 * Note that the ndlp reference count will be incremented by 1 for holding the
2455 * ndlp and the reference to ndlp will be stored into the ndlp field of
2456 * the IOCB for the completion callback function to the PRLI ELS command.
2459 * 0 - successfully issued prli iocb command for @vport
2460 * 1 - failed to issue prli iocb command for @vport
2463 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2467 struct lpfc_hba *phba = vport->phba;
2469 struct lpfc_nvme_prli *npr_nvme;
2470 struct lpfc_iocbq *elsiocb;
2473 u32 local_nlp_type, elscmd;
2476 * If we are in RSCN mode, the FC4 types supported from a
2477 * previous GFT_ID command may not be accurate. So, if we
2478 * are a NVME Initiator, always look for the possibility of
2479 * the remote NPort beng a NVME Target.
2481 if (phba->sli_rev == LPFC_SLI_REV4 &&
2482 test_bit(FC_RSCN_MODE, &vport->fc_flag) &&
2483 vport->nvmei_support)
2484 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2485 local_nlp_type = ndlp->nlp_fc4_type;
2487 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2488 * fields here before any of them can complete.
2490 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2491 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2492 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2493 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2494 ndlp->nvme_fb_size = 0;
2497 if (local_nlp_type & NLP_FC4_FCP) {
2498 /* Payload is 4 + 16 = 20 x14 bytes. */
2499 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2500 elscmd = ELS_CMD_PRLI;
2501 } else if (local_nlp_type & NLP_FC4_NVME) {
2502 /* Payload is 4 + 20 = 24 x18 bytes. */
2503 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2504 elscmd = ELS_CMD_NVMEPRLI;
2506 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2507 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2508 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2512 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2513 * FC4 type, implicitly LOGO.
2515 if (phba->sli_rev == LPFC_SLI_REV3 &&
2516 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2517 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2518 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2520 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2524 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2525 ndlp->nlp_DID, elscmd);
2529 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2531 /* For PRLI request, remainder of payload is service parameters */
2532 memset(pcmd, 0, cmdsize);
2534 if (local_nlp_type & NLP_FC4_FCP) {
2535 /* Remainder of payload is FCP PRLI parameter page.
2536 * Note: this data structure is defined as
2537 * BE/LE in the structure definition so no
2538 * byte swap call is made.
2540 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2541 pcmd += sizeof(uint32_t);
2545 * If our firmware version is 3.20 or later,
2546 * set the following bits for FC-TAPE support.
2548 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2549 npr->ConfmComplAllowed = 1;
2551 npr->TaskRetryIdReq = 1;
2553 npr->estabImagePair = 1;
2554 npr->readXferRdyDis = 1;
2555 if (vport->cfg_first_burst_size)
2556 npr->writeXferRdyDis = 1;
2558 /* For FCP support */
2559 npr->prliType = PRLI_FCP_TYPE;
2560 npr->initiatorFunc = 1;
2561 elsiocb->cmd_flag |= LPFC_PRLI_FCP_REQ;
2563 /* Remove FCP type - processed. */
2564 local_nlp_type &= ~NLP_FC4_FCP;
2565 } else if (local_nlp_type & NLP_FC4_NVME) {
2566 /* Remainder of payload is NVME PRLI parameter page.
2567 * This data structure is the newer definition that
2568 * uses bf macros so a byte swap is required.
2570 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2571 pcmd += sizeof(uint32_t);
2572 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2573 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2574 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2576 bf_set(prli_nsler, npr_nvme, 1);
2577 bf_set(prli_conf, npr_nvme, 1);
2580 /* Only initiators request first burst. */
2581 if ((phba->cfg_nvme_enable_fb) &&
2582 !phba->nvmet_support)
2583 bf_set(prli_fba, npr_nvme, 1);
2585 if (phba->nvmet_support) {
2586 bf_set(prli_tgt, npr_nvme, 1);
2587 bf_set(prli_disc, npr_nvme, 1);
2589 bf_set(prli_init, npr_nvme, 1);
2590 bf_set(prli_conf, npr_nvme, 1);
2593 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2594 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2595 elsiocb->cmd_flag |= LPFC_PRLI_NVME_REQ;
2597 /* Remove NVME type - processed. */
2598 local_nlp_type &= ~NLP_FC4_NVME;
2601 phba->fc_stat.elsXmitPRLI++;
2602 elsiocb->cmd_cmpl = lpfc_cmpl_els_prli;
2604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2605 "Issue PRLI: did:x%x refcnt %d",
2606 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2607 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2608 if (!elsiocb->ndlp) {
2609 lpfc_els_free_iocb(phba, elsiocb);
2613 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2614 if (rc == IOCB_ERROR) {
2615 lpfc_els_free_iocb(phba, elsiocb);
2620 /* The vport counters are used for lpfc_scan_finished, but
2621 * the ndlp is used to track outstanding PRLIs for different
2624 spin_lock_irq(&ndlp->lock);
2625 ndlp->nlp_flag |= NLP_PRLI_SND;
2626 vport->fc_prli_sent++;
2627 ndlp->fc4_prli_sent++;
2628 spin_unlock_irq(&ndlp->lock);
2630 /* The driver supports 2 FC4 types. Make sure
2631 * a PRLI is issued for all types before exiting.
2633 if (phba->sli_rev == LPFC_SLI_REV4 &&
2634 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2635 goto send_next_prli;
2641 * lpfc_rscn_disc - Perform rscn discovery for a vport
2642 * @vport: pointer to a host virtual N_Port data structure.
2644 * This routine performs Registration State Change Notification (RSCN)
2645 * discovery for a @vport. If the @vport's node port recovery count is not
2646 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2647 * the nodes that need recovery. If none of the PLOGI were needed through
2648 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2649 * invoked to check and handle possible more RSCN came in during the period
2650 * of processing the current ones.
2653 lpfc_rscn_disc(struct lpfc_vport *vport)
2655 lpfc_can_disctmo(vport);
2657 /* RSCN discovery */
2658 /* go thru NPR nodes and issue ELS PLOGIs */
2659 if (atomic_read(&vport->fc_npr_cnt))
2660 if (lpfc_els_disc_plogi(vport))
2663 lpfc_end_rscn(vport);
2667 * lpfc_adisc_done - Complete the adisc phase of discovery
2668 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2670 * This function is called when the final ADISC is completed during discovery.
2671 * This function handles clearing link attention or issuing reg_vpi depending
2672 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2674 * This function is called with no locks held.
2677 lpfc_adisc_done(struct lpfc_vport *vport)
2679 struct lpfc_hba *phba = vport->phba;
2682 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2683 * and continue discovery.
2685 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2686 !test_bit(FC_RSCN_MODE, &vport->fc_flag) &&
2687 (phba->sli_rev < LPFC_SLI_REV4)) {
2690 * If link is down, clear_la and reg_vpi will be done after
2691 * flogi following a link up event
2693 if (!lpfc_is_link_up(phba))
2696 /* The ADISCs are complete. Doesn't matter if they
2697 * succeeded or failed because the ADISC completion
2698 * routine guarantees to call the state machine and
2699 * the RPI is either unregistered (failed ADISC response)
2700 * or the RPI is still valid and the node is marked
2701 * mapped for a target. The exchanges should be in the
2702 * correct state. This code is specific to SLI3.
2704 lpfc_issue_clear_la(phba, vport);
2705 lpfc_issue_reg_vpi(phba, vport);
2709 * For SLI2, we need to set port_state to READY
2710 * and continue discovery.
2712 if (vport->port_state < LPFC_VPORT_READY) {
2713 /* If we get here, there is nothing to ADISC */
2714 lpfc_issue_clear_la(phba, vport);
2715 if (!test_bit(FC_ABORT_DISCOVERY, &vport->fc_flag)) {
2716 vport->num_disc_nodes = 0;
2717 /* go thru NPR list, issue ELS PLOGIs */
2718 if (atomic_read(&vport->fc_npr_cnt))
2719 lpfc_els_disc_plogi(vport);
2720 if (!vport->num_disc_nodes) {
2721 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag);
2722 lpfc_can_disctmo(vport);
2723 lpfc_end_rscn(vport);
2726 vport->port_state = LPFC_VPORT_READY;
2728 lpfc_rscn_disc(vport);
2732 * lpfc_more_adisc - Issue more adisc as needed
2733 * @vport: pointer to a host virtual N_Port data structure.
2735 * This routine determines whether there are more ndlps on a @vport
2736 * node list need to have Address Discover (ADISC) issued. If so, it will
2737 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2738 * remaining nodes which need to have ADISC sent.
2741 lpfc_more_adisc(struct lpfc_vport *vport)
2743 if (vport->num_disc_nodes)
2744 vport->num_disc_nodes--;
2745 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2746 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2747 "0210 Continue discovery with %d ADISCs to go "
2748 "Data: x%x x%lx x%x\n",
2749 vport->num_disc_nodes,
2750 atomic_read(&vport->fc_adisc_cnt),
2751 vport->fc_flag, vport->port_state);
2752 /* Check to see if there are more ADISCs to be sent */
2753 if (test_bit(FC_NLP_MORE, &vport->fc_flag)) {
2754 lpfc_set_disctmo(vport);
2755 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2756 lpfc_els_disc_adisc(vport);
2758 if (!vport->num_disc_nodes)
2759 lpfc_adisc_done(vport);
2764 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2765 * @phba: pointer to lpfc hba data structure.
2766 * @cmdiocb: pointer to lpfc command iocb data structure.
2767 * @rspiocb: pointer to lpfc response iocb data structure.
2769 * This routine is the completion function for issuing the Address Discover
2770 * (ADISC) command. It first checks to see whether link went down during
2771 * the discovery process. If so, the node will be marked as node port
2772 * recovery for issuing discover IOCB by the link attention handler and
2773 * exit. Otherwise, the response status is checked. If error was reported
2774 * in the response status, the ADISC command shall be retried by invoking
2775 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2776 * the response status, the state machine is invoked to set transition
2777 * with respect to NLP_EVT_CMPL_ADISC event.
2780 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2781 struct lpfc_iocbq *rspiocb)
2783 struct lpfc_vport *vport = cmdiocb->vport;
2785 struct lpfc_nodelist *ndlp;
2787 u32 ulp_status, ulp_word4, tmo, iotag;
2788 bool release_node = false;
2790 /* we pass cmdiocb to state machine which needs rspiocb as well */
2791 cmdiocb->rsp_iocb = rspiocb;
2793 ndlp = cmdiocb->ndlp;
2795 ulp_status = get_job_ulpstatus(phba, rspiocb);
2796 ulp_word4 = get_job_word4(phba, rspiocb);
2798 if (phba->sli_rev == LPFC_SLI_REV4) {
2799 tmo = get_wqe_tmo(cmdiocb);
2800 iotag = get_wqe_reqtag(cmdiocb);
2802 irsp = &rspiocb->iocb;
2803 tmo = irsp->ulpTimeout;
2804 iotag = irsp->ulpIoTag;
2807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2808 "ADISC cmpl: status:x%x/x%x did:x%x",
2809 ulp_status, ulp_word4,
2812 /* Since ndlp can be freed in the disc state machine, note if this node
2813 * is being used during discovery.
2815 spin_lock_irq(&ndlp->lock);
2816 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2817 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2818 spin_unlock_irq(&ndlp->lock);
2819 /* ADISC completes to NPort <nlp_DID> */
2820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2821 "0104 ADISC completes to NPort x%x "
2822 "IoTag x%x Data: x%x x%x x%x x%x x%x\n",
2823 ndlp->nlp_DID, iotag,
2824 ulp_status, ulp_word4,
2825 tmo, disc, vport->num_disc_nodes);
2827 /* Check to see if link went down during discovery */
2828 if (lpfc_els_chk_latt(vport)) {
2829 spin_lock_irq(&ndlp->lock);
2830 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2831 spin_unlock_irq(&ndlp->lock);
2836 /* Check for retry */
2837 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2838 /* ELS command is being retried */
2840 spin_lock_irq(&ndlp->lock);
2841 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2842 spin_unlock_irq(&ndlp->lock);
2843 lpfc_set_disctmo(vport);
2848 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2849 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2850 ndlp->nlp_DID, ulp_status,
2852 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2853 NLP_EVT_CMPL_ADISC);
2855 /* As long as this node is not registered with the SCSI or NVMe
2856 * transport, it is no longer an active node. Otherwise
2857 * devloss handles the final cleanup.
2859 spin_lock_irq(&ndlp->lock);
2860 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2861 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2862 if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
2863 release_node = true;
2865 spin_unlock_irq(&ndlp->lock);
2868 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2871 /* Good status, call state machine */
2872 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2873 NLP_EVT_CMPL_ADISC);
2875 /* Check to see if there are more ADISCs to be sent */
2876 if (disc && vport->num_disc_nodes)
2877 lpfc_more_adisc(vport);
2879 lpfc_els_free_iocb(phba, cmdiocb);
2885 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2886 * @vport: pointer to a virtual N_Port data structure.
2887 * @ndlp: pointer to a node-list data structure.
2888 * @retry: number of retries to the command IOCB.
2890 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2891 * @vport. It prepares the payload of the ADISC ELS command, updates the
2892 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2893 * to issue the ADISC ELS command.
2895 * Note that the ndlp reference count will be incremented by 1 for holding the
2896 * ndlp and the reference to ndlp will be stored into the ndlp field of
2897 * the IOCB for the completion callback function to the ADISC ELS command.
2900 * 0 - successfully issued adisc
2901 * 1 - failed to issue adisc
2904 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2908 struct lpfc_hba *phba = vport->phba;
2910 struct lpfc_iocbq *elsiocb;
2914 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2915 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2916 ndlp->nlp_DID, ELS_CMD_ADISC);
2920 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2922 /* For ADISC request, remainder of payload is service parameters */
2923 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2924 pcmd += sizeof(uint32_t);
2926 /* Fill in ADISC payload */
2927 ap = (ADISC *) pcmd;
2928 ap->hardAL_PA = phba->fc_pref_ALPA;
2929 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2930 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2931 ap->DID = be32_to_cpu(vport->fc_myDID);
2933 phba->fc_stat.elsXmitADISC++;
2934 elsiocb->cmd_cmpl = lpfc_cmpl_els_adisc;
2935 spin_lock_irq(&ndlp->lock);
2936 ndlp->nlp_flag |= NLP_ADISC_SND;
2937 spin_unlock_irq(&ndlp->lock);
2938 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2939 if (!elsiocb->ndlp) {
2940 lpfc_els_free_iocb(phba, elsiocb);
2944 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2945 "Issue ADISC: did:x%x refcnt %d",
2946 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2948 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2949 if (rc == IOCB_ERROR) {
2950 lpfc_els_free_iocb(phba, elsiocb);
2958 spin_lock_irq(&ndlp->lock);
2959 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2960 spin_unlock_irq(&ndlp->lock);
2965 * lpfc_cmpl_els_logo - Completion callback function for logo
2966 * @phba: pointer to lpfc hba data structure.
2967 * @cmdiocb: pointer to lpfc command iocb data structure.
2968 * @rspiocb: pointer to lpfc response iocb data structure.
2970 * This routine is the completion function for issuing the ELS Logout (LOGO)
2971 * command. If no error status was reported from the LOGO response, the
2972 * state machine of the associated ndlp shall be invoked for transition with
2973 * respect to NLP_EVT_CMPL_LOGO event.
2976 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2977 struct lpfc_iocbq *rspiocb)
2979 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
2980 struct lpfc_vport *vport = ndlp->vport;
2982 unsigned long flags;
2983 uint32_t skip_recovery = 0;
2984 int wake_up_waiter = 0;
2989 /* we pass cmdiocb to state machine which needs rspiocb as well */
2990 cmdiocb->rsp_iocb = rspiocb;
2992 ulp_status = get_job_ulpstatus(phba, rspiocb);
2993 ulp_word4 = get_job_word4(phba, rspiocb);
2995 if (phba->sli_rev == LPFC_SLI_REV4) {
2996 tmo = get_wqe_tmo(cmdiocb);
2997 iotag = get_wqe_reqtag(cmdiocb);
2999 irsp = &rspiocb->iocb;
3000 tmo = irsp->ulpTimeout;
3001 iotag = irsp->ulpIoTag;
3004 spin_lock_irq(&ndlp->lock);
3005 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3006 if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
3008 ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
3010 spin_unlock_irq(&ndlp->lock);
3012 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3013 "LOGO cmpl: status:x%x/x%x did:x%x",
3014 ulp_status, ulp_word4,
3017 /* LOGO completes to NPort <nlp_DID> */
3018 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3019 "0105 LOGO completes to NPort x%x "
3020 "IoTag x%x refcnt %d nflags x%x xflags x%x "
3021 "Data: x%x x%x x%x x%x\n",
3022 ndlp->nlp_DID, iotag,
3023 kref_read(&ndlp->kref), ndlp->nlp_flag,
3024 ndlp->fc4_xpt_flags, ulp_status, ulp_word4,
3025 tmo, vport->num_disc_nodes);
3027 if (lpfc_els_chk_latt(vport)) {
3032 /* The LOGO will not be retried on failure. A LOGO was
3033 * issued to the remote rport and a ACC or RJT or no Answer are
3034 * all acceptable. Note the failure and move forward with
3035 * discovery. The PLOGI will retry.
3039 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3040 "2756 LOGO failure, No Retry DID:%06X "
3042 ndlp->nlp_DID, ulp_status,
3045 if (lpfc_error_lost_link(vport, ulp_status, ulp_word4))
3049 /* Call state machine. This will unregister the rpi if needed. */
3050 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
3055 /* The driver sets this flag for an NPIV instance that doesn't want to
3056 * log into the remote port.
3058 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
3059 spin_lock_irq(&ndlp->lock);
3060 if (phba->sli_rev == LPFC_SLI_REV4)
3061 ndlp->nlp_flag |= NLP_RELEASE_RPI;
3062 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3063 spin_unlock_irq(&ndlp->lock);
3064 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3070 /* At this point, the LOGO processing is complete. NOTE: For a
3071 * pt2pt topology, we are assuming the NPortID will only change
3072 * on link up processing. For a LOGO / PLOGI initiated by the
3073 * Initiator, we are assuming the NPortID is not going to change.
3076 if (wake_up_waiter && ndlp->logo_waitq)
3077 wake_up(ndlp->logo_waitq);
3079 * If the node is a target, the handling attempts to recover the port.
3080 * For any other port type, the rpi is unregistered as an implicit
3083 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
3084 skip_recovery == 0) {
3085 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3086 spin_lock_irqsave(&ndlp->lock, flags);
3087 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
3088 spin_unlock_irqrestore(&ndlp->lock, flags);
3090 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3091 "3187 LOGO completes to NPort x%x: Start "
3092 "Recovery Data: x%x x%x x%x x%x\n",
3093 ndlp->nlp_DID, ulp_status,
3095 vport->num_disc_nodes);
3097 lpfc_els_free_iocb(phba, cmdiocb);
3100 lpfc_disc_start(vport);
3104 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
3105 * driver sends a LOGO to the rport to cleanup. For fabric and
3106 * initiator ports cleanup the node as long as it the node is not
3107 * register with the transport.
3109 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
3110 spin_lock_irq(&ndlp->lock);
3111 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3112 spin_unlock_irq(&ndlp->lock);
3113 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3117 /* Driver is done with the I/O. */
3118 lpfc_els_free_iocb(phba, cmdiocb);
3123 * lpfc_issue_els_logo - Issue a logo to an node on a vport
3124 * @vport: pointer to a virtual N_Port data structure.
3125 * @ndlp: pointer to a node-list data structure.
3126 * @retry: number of retries to the command IOCB.
3128 * This routine constructs and issues an ELS Logout (LOGO) iocb command
3129 * to a remote node, referred by an @ndlp on a @vport. It constructs the
3130 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
3131 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
3133 * Note that the ndlp reference count will be incremented by 1 for holding the
3134 * ndlp and the reference to ndlp will be stored into the ndlp field of
3135 * the IOCB for the completion callback function to the LOGO ELS command.
3137 * Callers of this routine are expected to unregister the RPI first
3140 * 0 - successfully issued logo
3141 * 1 - failed to issue logo
3144 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3147 struct lpfc_hba *phba = vport->phba;
3148 struct lpfc_iocbq *elsiocb;
3153 spin_lock_irq(&ndlp->lock);
3154 if (ndlp->nlp_flag & NLP_LOGO_SND) {
3155 spin_unlock_irq(&ndlp->lock);
3158 spin_unlock_irq(&ndlp->lock);
3160 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
3161 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3162 ndlp->nlp_DID, ELS_CMD_LOGO);
3166 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
3167 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
3168 pcmd += sizeof(uint32_t);
3170 /* Fill in LOGO payload */
3171 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
3172 pcmd += sizeof(uint32_t);
3173 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
3175 phba->fc_stat.elsXmitLOGO++;
3176 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo;
3177 spin_lock_irq(&ndlp->lock);
3178 ndlp->nlp_flag |= NLP_LOGO_SND;
3179 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
3180 spin_unlock_irq(&ndlp->lock);
3181 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3182 if (!elsiocb->ndlp) {
3183 lpfc_els_free_iocb(phba, elsiocb);
3187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3188 "Issue LOGO: did:x%x refcnt %d",
3189 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3191 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3192 if (rc == IOCB_ERROR) {
3193 lpfc_els_free_iocb(phba, elsiocb);
3198 spin_lock_irq(&ndlp->lock);
3199 ndlp->nlp_prev_state = ndlp->nlp_state;
3200 spin_unlock_irq(&ndlp->lock);
3201 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3205 spin_lock_irq(&ndlp->lock);
3206 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3207 spin_unlock_irq(&ndlp->lock);
3212 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3213 * @phba: pointer to lpfc hba data structure.
3214 * @cmdiocb: pointer to lpfc command iocb data structure.
3215 * @rspiocb: pointer to lpfc response iocb data structure.
3217 * This routine is a generic completion callback function for ELS commands.
3218 * Specifically, it is the callback function which does not need to perform
3219 * any command specific operations. It is currently used by the ELS command
3220 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3221 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3222 * Other than certain debug loggings, this callback function simply invokes the
3223 * lpfc_els_chk_latt() routine to check whether link went down during the
3224 * discovery process.
3227 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3228 struct lpfc_iocbq *rspiocb)
3230 struct lpfc_vport *vport = cmdiocb->vport;
3231 struct lpfc_nodelist *free_ndlp;
3233 u32 ulp_status, ulp_word4, tmo, did, iotag;
3235 ulp_status = get_job_ulpstatus(phba, rspiocb);
3236 ulp_word4 = get_job_word4(phba, rspiocb);
3237 did = get_job_els_rsp64_did(phba, cmdiocb);
3239 if (phba->sli_rev == LPFC_SLI_REV4) {
3240 tmo = get_wqe_tmo(cmdiocb);
3241 iotag = get_wqe_reqtag(cmdiocb);
3243 irsp = &rspiocb->iocb;
3244 tmo = irsp->ulpTimeout;
3245 iotag = irsp->ulpIoTag;
3248 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3249 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3250 ulp_status, ulp_word4, did);
3252 /* ELS cmd tag <ulpIoTag> completes */
3253 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3254 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3255 iotag, ulp_status, ulp_word4, tmo);
3257 /* Check to see if link went down during discovery */
3258 lpfc_els_chk_latt(vport);
3260 free_ndlp = cmdiocb->ndlp;
3262 lpfc_els_free_iocb(phba, cmdiocb);
3263 lpfc_nlp_put(free_ndlp);
3267 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
3268 * @vport: pointer to lpfc_vport data structure.
3269 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
3271 * This routine registers the rpi assigned to the fabric controller
3272 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
3273 * state triggering a registration with the SCSI transport.
3275 * This routine is single out because the fabric controller node
3276 * does not receive a PLOGI. This routine is consumed by the
3277 * SCR and RDF ELS commands. Callers are expected to qualify
3281 lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp)
3284 struct lpfc_hba *phba = vport->phba;
3285 struct lpfc_nodelist *ns_ndlp;
3288 if (fc_ndlp->nlp_flag & NLP_RPI_REGISTERED)
3291 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
3295 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3296 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
3297 __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID,
3298 ns_ndlp->nlp_state);
3299 if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3302 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3304 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3305 "0936 %s: no memory for reg_login "
3306 "Data: x%x x%x x%x x%x\n", __func__,
3307 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3308 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3311 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID,
3312 (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi);
3318 fc_ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3319 mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login;
3320 mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp);
3321 if (!mbox->ctx_ndlp) {
3326 mbox->vport = vport;
3327 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3328 if (rc == MBX_NOT_FINISHED) {
3330 lpfc_nlp_put(fc_ndlp);
3333 /* Success path. Exit. */
3334 lpfc_nlp_set_state(vport, fc_ndlp,
3335 NLP_STE_REG_LOGIN_ISSUE);
3339 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
3340 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3341 "0938 %s: failed to format reg_login "
3342 "Data: x%x x%x x%x x%x\n", __func__,
3343 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3344 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3349 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3350 * @phba: pointer to lpfc hba data structure.
3351 * @cmdiocb: pointer to lpfc command iocb data structure.
3352 * @rspiocb: pointer to lpfc response iocb data structure.
3354 * This routine is a generic completion callback function for Discovery ELS cmd.
3355 * Currently used by the ELS command issuing routines for the ELS State Change
3356 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3357 * These commands will be retried once only for ELS timeout errors.
3360 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3361 struct lpfc_iocbq *rspiocb)
3363 struct lpfc_vport *vport = cmdiocb->vport;
3365 struct lpfc_els_rdf_rsp *prdf;
3366 struct lpfc_dmabuf *pcmd, *prsp;
3369 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
3370 u32 ulp_status, ulp_word4, tmo, did, iotag;
3372 ulp_status = get_job_ulpstatus(phba, rspiocb);
3373 ulp_word4 = get_job_word4(phba, rspiocb);
3374 did = get_job_els_rsp64_did(phba, cmdiocb);
3376 if (phba->sli_rev == LPFC_SLI_REV4) {
3377 tmo = get_wqe_tmo(cmdiocb);
3378 iotag = get_wqe_reqtag(cmdiocb);
3380 irsp = &rspiocb->iocb;
3381 tmo = irsp->ulpTimeout;
3382 iotag = irsp->ulpIoTag;
3385 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3386 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3387 ulp_status, ulp_word4, did);
3389 /* ELS cmd tag <ulpIoTag> completes */
3390 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3391 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x x%x\n",
3392 iotag, ulp_status, ulp_word4, tmo, cmdiocb->retry);
3394 pcmd = cmdiocb->cmd_dmabuf;
3398 pdata = (u32 *)pcmd->virt;
3403 /* Only 1 retry for ELS Timeout only */
3404 if (ulp_status == IOSTAT_LOCAL_REJECT &&
3405 ((ulp_word4 & IOERR_PARAM_MASK) ==
3406 IOERR_SEQUENCE_TIMEOUT)) {
3408 if (cmdiocb->retry <= 1) {
3411 lpfc_issue_els_scr(vport, cmdiocb->retry);
3414 lpfc_issue_els_edc(vport, cmdiocb->retry);
3417 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3422 phba->fc_stat.elsRetryExceeded++;
3424 if (cmd == ELS_CMD_EDC) {
3425 /* must be called before checking uplStatus and returning */
3426 lpfc_cmpl_els_edc(phba, cmdiocb, rspiocb);
3430 /* ELS discovery cmd completes with error */
3431 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
3432 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3433 ulp_status, ulp_word4);
3437 /* The RDF response doesn't have any impact on the running driver
3438 * but the notification descriptors are dumped here for support.
3440 if (cmd == ELS_CMD_RDF) {
3443 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3447 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3450 if (!lpfc_is_els_acc_rsp(prsp))
3453 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3454 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3455 lpfc_printf_vlog(vport, KERN_INFO,
3456 LOG_ELS | LOG_CGN_MGMT,
3457 "4677 Fabric RDF Notification Grant "
3458 "Data: 0x%08x Reg: %x %x\n",
3460 prdf->reg_d1.desc_tags[i]),
3461 phba->cgn_reg_signal,
3462 phba->cgn_reg_fpin);
3466 /* Check to see if link went down during discovery */
3467 lpfc_els_chk_latt(vport);
3468 lpfc_els_free_iocb(phba, cmdiocb);
3474 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3475 * @vport: pointer to a host virtual N_Port data structure.
3476 * @retry: retry counter for the command IOCB.
3478 * This routine issues a State Change Request (SCR) to a fabric node
3479 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3480 * first search the @vport node list to find the matching ndlp. If no such
3481 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3482 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3483 * routine is invoked to send the SCR IOCB.
3485 * Note that the ndlp reference count will be incremented by 1 for holding the
3486 * ndlp and the reference to ndlp will be stored into the ndlp field of
3487 * the IOCB for the completion callback function to the SCR ELS command.
3490 * 0 - Successfully issued scr command
3491 * 1 - Failed to issue scr command
3494 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3497 struct lpfc_hba *phba = vport->phba;
3498 struct lpfc_iocbq *elsiocb;
3501 struct lpfc_nodelist *ndlp;
3503 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3505 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3507 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3510 lpfc_enqueue_node(vport, ndlp);
3513 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3514 ndlp->nlp_DID, ELS_CMD_SCR);
3518 if (phba->sli_rev == LPFC_SLI_REV4) {
3519 rc = lpfc_reg_fab_ctrl_node(vport, ndlp);
3521 lpfc_els_free_iocb(phba, elsiocb);
3522 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3523 "0937 %s: Failed to reg fc node, rc %d\n",
3528 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
3530 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3531 pcmd += sizeof(uint32_t);
3533 /* For SCR, remainder of payload is SCR parameter page */
3534 memset(pcmd, 0, sizeof(SCR));
3535 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3538 "Issue SCR: did:x%x",
3539 ndlp->nlp_DID, 0, 0);
3541 phba->fc_stat.elsXmitSCR++;
3542 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
3543 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3544 if (!elsiocb->ndlp) {
3545 lpfc_els_free_iocb(phba, elsiocb);
3549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3550 "Issue SCR: did:x%x refcnt %d",
3551 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3553 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3554 if (rc == IOCB_ERROR) {
3555 lpfc_els_free_iocb(phba, elsiocb);
3564 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3565 * or the other nport (pt2pt).
3566 * @vport: pointer to a host virtual N_Port data structure.
3567 * @retry: number of retries to the command IOCB.
3569 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3570 * when connected to a fabric, or to the remote port when connected
3571 * in point-to-point mode. When sent to the Fabric Controller, it will
3572 * replay the RSCN to registered recipients.
3574 * Note that the ndlp reference count will be incremented by 1 for holding the
3575 * ndlp and the reference to ndlp will be stored into the ndlp field of
3576 * the IOCB for the completion callback function to the RSCN ELS command.
3579 * 0 - Successfully issued RSCN command
3580 * 1 - Failed to issue RSCN command
3583 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3586 struct lpfc_hba *phba = vport->phba;
3587 struct lpfc_iocbq *elsiocb;
3588 struct lpfc_nodelist *ndlp;
3590 struct fc_els_rscn rscn;
3591 struct fc_els_rscn_page portid;
3594 uint16_t cmdsize = sizeof(*event);
3596 /* Not supported for private loop */
3597 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3598 !test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
3601 if (test_bit(FC_PT2PT, &vport->fc_flag)) {
3602 /* find any mapped nport - that would be the other nport */
3603 ndlp = lpfc_findnode_mapped(vport);
3607 nportid = FC_FID_FCTRL;
3608 /* find the fabric controller node */
3609 ndlp = lpfc_findnode_did(vport, nportid);
3611 /* if one didn't exist, make one */
3612 ndlp = lpfc_nlp_init(vport, nportid);
3615 lpfc_enqueue_node(vport, ndlp);
3619 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3620 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3625 event = elsiocb->cmd_dmabuf->virt;
3627 event->rscn.rscn_cmd = ELS_RSCN;
3628 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3629 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3631 nportid = vport->fc_myDID;
3632 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3633 event->portid.rscn_page_flags = 0;
3634 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3635 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3636 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3638 phba->fc_stat.elsXmitRSCN++;
3639 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
3640 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3641 if (!elsiocb->ndlp) {
3642 lpfc_els_free_iocb(phba, elsiocb);
3646 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3647 "Issue RSCN: did:x%x",
3648 ndlp->nlp_DID, 0, 0);
3650 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3651 if (rc == IOCB_ERROR) {
3652 lpfc_els_free_iocb(phba, elsiocb);
3661 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3662 * @vport: pointer to a host virtual N_Port data structure.
3663 * @nportid: N_Port identifier to the remote node.
3664 * @retry: number of retries to the command IOCB.
3666 * This routine issues a Fibre Channel Address Resolution Response
3667 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3668 * is passed into the function. It first search the @vport node list to find
3669 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3670 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3671 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3673 * Note that the ndlp reference count will be incremented by 1 for holding the
3674 * ndlp and the reference to ndlp will be stored into the ndlp field of
3675 * the IOCB for the completion callback function to the FARPR ELS command.
3678 * 0 - Successfully issued farpr command
3679 * 1 - Failed to issue farpr command
3682 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3685 struct lpfc_hba *phba = vport->phba;
3686 struct lpfc_iocbq *elsiocb;
3691 struct lpfc_nodelist *ondlp;
3692 struct lpfc_nodelist *ndlp;
3694 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3696 ndlp = lpfc_findnode_did(vport, nportid);
3698 ndlp = lpfc_nlp_init(vport, nportid);
3701 lpfc_enqueue_node(vport, ndlp);
3704 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3705 ndlp->nlp_DID, ELS_CMD_FARPR);
3709 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
3711 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3712 pcmd += sizeof(uint32_t);
3714 /* Fill in FARPR payload */
3715 fp = (FARP *) (pcmd);
3716 memset(fp, 0, sizeof(FARP));
3717 lp = (uint32_t *) pcmd;
3718 *lp++ = be32_to_cpu(nportid);
3719 *lp++ = be32_to_cpu(vport->fc_myDID);
3721 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3723 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3724 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3725 ondlp = lpfc_findnode_did(vport, nportid);
3727 memcpy(&fp->OportName, &ondlp->nlp_portname,
3728 sizeof(struct lpfc_name));
3729 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3730 sizeof(struct lpfc_name));
3733 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3734 "Issue FARPR: did:x%x",
3735 ndlp->nlp_DID, 0, 0);
3737 phba->fc_stat.elsXmitFARPR++;
3738 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
3739 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3740 if (!elsiocb->ndlp) {
3741 lpfc_els_free_iocb(phba, elsiocb);
3745 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3746 if (rc == IOCB_ERROR) {
3747 /* The additional lpfc_nlp_put will cause the following
3748 * lpfc_els_free_iocb routine to trigger the release of
3751 lpfc_els_free_iocb(phba, elsiocb);
3755 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3756 * trigger the release of the node.
3758 /* Don't release reference count as RDF is likely outstanding */
3763 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3764 * @vport: pointer to a host virtual N_Port data structure.
3765 * @retry: retry counter for the command IOCB.
3767 * This routine issues an ELS RDF to the Fabric Controller to register
3768 * for diagnostic functions.
3770 * Note that the ndlp reference count will be incremented by 1 for holding the
3771 * ndlp and the reference to ndlp will be stored into the ndlp field of
3772 * the IOCB for the completion callback function to the RDF ELS command.
3775 * 0 - Successfully issued rdf command
3776 * 1 - Failed to issue rdf command
3779 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3781 struct lpfc_hba *phba = vport->phba;
3782 struct lpfc_iocbq *elsiocb;
3783 struct lpfc_els_rdf_req *prdf;
3784 struct lpfc_nodelist *ndlp;
3788 cmdsize = sizeof(*prdf);
3790 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3792 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3795 lpfc_enqueue_node(vport, ndlp);
3798 /* RDF ELS is not required on an NPIV VN_Port. */
3799 if (vport->port_type == LPFC_NPIV_PORT)
3802 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3803 ndlp->nlp_DID, ELS_CMD_RDF);
3807 /* Configure the payload for the supported FPIN events. */
3808 prdf = (struct lpfc_els_rdf_req *)elsiocb->cmd_dmabuf->virt;
3809 memset(prdf, 0, cmdsize);
3810 prdf->rdf.fpin_cmd = ELS_RDF;
3811 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3812 sizeof(struct fc_els_rdf));
3813 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3814 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3815 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3816 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3817 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3818 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3819 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3820 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3823 "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n",
3824 ndlp->nlp_DID, phba->cgn_reg_signal,
3825 phba->cgn_reg_fpin);
3827 phba->cgn_fpin_frequency = LPFC_FPIN_INIT_FREQ;
3828 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
3829 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3830 if (!elsiocb->ndlp) {
3831 lpfc_els_free_iocb(phba, elsiocb);
3835 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3836 "Issue RDF: did:x%x refcnt %d",
3837 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3839 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3840 if (rc == IOCB_ERROR) {
3841 lpfc_els_free_iocb(phba, elsiocb);
3849 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
3850 * @vport: pointer to a host virtual N_Port data structure.
3851 * @cmdiocb: pointer to lpfc command iocb data structure.
3852 * @ndlp: pointer to a node-list data structure.
3854 * A received RDF implies a possible change to fabric supported diagnostic
3855 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
3856 * RDF request to reregister for supported diagnostic functions.
3860 * -EIO - Failed to process received RDF
3863 lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3864 struct lpfc_nodelist *ndlp)
3867 if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) {
3868 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3869 "1623 Failed to RDF_ACC from x%x for x%x\n",
3870 ndlp->nlp_DID, vport->fc_myDID);
3874 /* Issue new RDF for reregistering */
3875 if (lpfc_issue_els_rdf(vport, 0)) {
3876 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3877 "2623 Failed to re register RDF for x%x\n",
3886 * lpfc_least_capable_settings - helper function for EDC rsp processing
3887 * @phba: pointer to lpfc hba data structure.
3888 * @pcgd: pointer to congestion detection descriptor in EDC rsp.
3890 * This helper routine determines the least capable setting for
3891 * congestion signals, signal freq, including scale, from the
3892 * congestion detection descriptor in the EDC rsp. The routine
3893 * sets @phba values in preparation for a set_featues mailbox.
3896 lpfc_least_capable_settings(struct lpfc_hba *phba,
3897 struct fc_diag_cg_sig_desc *pcgd)
3899 u32 rsp_sig_cap = 0, drv_sig_cap = 0;
3900 u32 rsp_sig_freq_cyc = 0, rsp_sig_freq_scale = 0;
3902 /* Get rsp signal and frequency capabilities. */
3903 rsp_sig_cap = be32_to_cpu(pcgd->xmt_signal_capability);
3904 rsp_sig_freq_cyc = be16_to_cpu(pcgd->xmt_signal_frequency.count);
3905 rsp_sig_freq_scale = be16_to_cpu(pcgd->xmt_signal_frequency.units);
3907 /* If the Fport does not support signals. Set FPIN only */
3908 if (rsp_sig_cap == EDC_CG_SIG_NOTSUPPORTED)
3909 goto out_no_support;
3911 /* Apply the xmt scale to the xmt cycle to get the correct frequency.
3912 * Adapter default is 100 millisSeconds. Convert all xmt cycle values
3915 switch (rsp_sig_freq_scale) {
3916 case EDC_CG_SIGFREQ_SEC:
3917 rsp_sig_freq_cyc *= MSEC_PER_SEC;
3919 case EDC_CG_SIGFREQ_MSEC:
3920 rsp_sig_freq_cyc = 1;
3923 goto out_no_support;
3926 /* Convenient shorthand. */
3927 drv_sig_cap = phba->cgn_reg_signal;
3929 /* Choose the least capable frequency. */
3930 if (rsp_sig_freq_cyc > phba->cgn_sig_freq)
3931 phba->cgn_sig_freq = rsp_sig_freq_cyc;
3933 /* Should be some common signals support. Settle on least capable
3934 * signal and adjust FPIN values. Initialize defaults to ease the
3937 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
3938 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3939 if (rsp_sig_cap == EDC_CG_SIG_WARN_ONLY &&
3940 (drv_sig_cap == EDC_CG_SIG_WARN_ONLY ||
3941 drv_sig_cap == EDC_CG_SIG_WARN_ALARM)) {
3942 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3943 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3945 if (rsp_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3946 if (drv_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3947 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ALARM;
3948 phba->cgn_reg_fpin = LPFC_CGN_FPIN_NONE;
3950 if (drv_sig_cap == EDC_CG_SIG_WARN_ONLY) {
3951 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3952 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3956 /* We are NOT recording signal frequency in congestion info buffer */
3960 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3961 phba->cgn_sig_freq = 0;
3962 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
3965 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
3966 FC_LS_TLV_DTAG_INIT);
3969 * lpfc_cmpl_els_edc - Completion callback function for EDC
3970 * @phba: pointer to lpfc hba data structure.
3971 * @cmdiocb: pointer to lpfc command iocb data structure.
3972 * @rspiocb: pointer to lpfc response iocb data structure.
3974 * This routine is the completion callback function for issuing the Exchange
3975 * Diagnostic Capabilities (EDC) command. The driver issues an EDC to
3976 * notify the FPort of its Congestion and Link Fault capabilities. This
3977 * routine parses the FPort's response and decides on the least common
3978 * values applicable to both FPort and NPort for Warnings and Alarms that
3979 * are communicated via hardware signals.
3982 lpfc_cmpl_els_edc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3983 struct lpfc_iocbq *rspiocb)
3986 struct fc_els_edc_resp *edc_rsp;
3987 struct fc_tlv_desc *tlv;
3988 struct fc_diag_cg_sig_desc *pcgd;
3989 struct fc_diag_lnkflt_desc *plnkflt;
3990 struct lpfc_dmabuf *pcmd, *prsp;
3991 const char *dtag_nm;
3993 int desc_cnt = 0, bytes_remain;
3994 bool rcv_cap_desc = false;
3995 struct lpfc_nodelist *ndlp;
3996 u32 ulp_status, ulp_word4, tmo, did, iotag;
3998 ndlp = cmdiocb->ndlp;
4000 ulp_status = get_job_ulpstatus(phba, rspiocb);
4001 ulp_word4 = get_job_word4(phba, rspiocb);
4002 did = get_job_els_rsp64_did(phba, rspiocb);
4004 if (phba->sli_rev == LPFC_SLI_REV4) {
4005 tmo = get_wqe_tmo(rspiocb);
4006 iotag = get_wqe_reqtag(rspiocb);
4008 irsp_iocb = &rspiocb->iocb;
4009 tmo = irsp_iocb->ulpTimeout;
4010 iotag = irsp_iocb->ulpIoTag;
4013 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
4014 "EDC cmpl: status:x%x/x%x did:x%x",
4015 ulp_status, ulp_word4, did);
4017 /* ELS cmd tag <ulpIoTag> completes */
4018 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4019 "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n",
4020 iotag, ulp_status, ulp_word4, tmo);
4022 pcmd = cmdiocb->cmd_dmabuf;
4026 pdata = (u32 *)pcmd->virt;
4030 /* Need to clear signal values, send features MB and RDF with FPIN. */
4034 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
4038 edc_rsp = prsp->virt;
4042 /* ELS cmd tag <ulpIoTag> completes */
4043 lpfc_printf_log(phba, KERN_INFO,
4044 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
4045 "4676 Fabric EDC Rsp: "
4047 edc_rsp->acc_hdr.la_cmd,
4048 be32_to_cpu(edc_rsp->desc_list_len));
4050 if (!lpfc_is_els_acc_rsp(prsp))
4054 * Payload length in bytes is the response descriptor list
4055 * length minus the 12 bytes of Link Service Request
4056 * Information descriptor in the reply.
4058 bytes_remain = be32_to_cpu(edc_rsp->desc_list_len) -
4059 sizeof(struct fc_els_lsri_desc);
4060 if (bytes_remain <= 0)
4063 tlv = edc_rsp->desc;
4066 * cycle through EDC diagnostic descriptors to find the
4067 * congestion signaling capability descriptor
4069 while (bytes_remain) {
4070 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
4071 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4072 "6461 Truncated TLV hdr on "
4073 "Diagnostic descriptor[%d]\n",
4078 dtag = be32_to_cpu(tlv->desc_tag);
4080 case ELS_DTAG_LNK_FAULT_CAP:
4081 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4082 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4083 sizeof(struct fc_diag_lnkflt_desc)) {
4084 lpfc_printf_log(phba, KERN_WARNING,
4085 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
4086 "6462 Truncated Link Fault Diagnostic "
4087 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4088 desc_cnt, bytes_remain,
4089 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4090 sizeof(struct fc_diag_lnkflt_desc));
4093 plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
4094 lpfc_printf_log(phba, KERN_INFO,
4095 LOG_ELS | LOG_LDS_EVENT,
4096 "4617 Link Fault Desc Data: 0x%08x 0x%08x "
4097 "0x%08x 0x%08x 0x%08x\n",
4098 be32_to_cpu(plnkflt->desc_tag),
4099 be32_to_cpu(plnkflt->desc_len),
4101 plnkflt->degrade_activate_threshold),
4103 plnkflt->degrade_deactivate_threshold),
4104 be32_to_cpu(plnkflt->fec_degrade_interval));
4106 case ELS_DTAG_CG_SIGNAL_CAP:
4107 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4108 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4109 sizeof(struct fc_diag_cg_sig_desc)) {
4111 phba, KERN_WARNING, LOG_CGN_MGMT,
4112 "6463 Truncated Cgn Signal Diagnostic "
4113 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4114 desc_cnt, bytes_remain,
4115 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4116 sizeof(struct fc_diag_cg_sig_desc));
4120 pcgd = (struct fc_diag_cg_sig_desc *)tlv;
4122 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4123 "4616 CGN Desc Data: 0x%08x 0x%08x "
4124 "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n",
4125 be32_to_cpu(pcgd->desc_tag),
4126 be32_to_cpu(pcgd->desc_len),
4127 be32_to_cpu(pcgd->xmt_signal_capability),
4128 be16_to_cpu(pcgd->xmt_signal_frequency.count),
4129 be16_to_cpu(pcgd->xmt_signal_frequency.units),
4130 be32_to_cpu(pcgd->rcv_signal_capability),
4131 be16_to_cpu(pcgd->rcv_signal_frequency.count),
4132 be16_to_cpu(pcgd->rcv_signal_frequency.units));
4134 /* Compare driver and Fport capabilities and choose
4137 lpfc_least_capable_settings(phba, pcgd);
4138 rcv_cap_desc = true;
4141 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
4142 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4143 "4919 unknown Diagnostic "
4144 "Descriptor[%d]: tag x%x (%s)\n",
4145 desc_cnt, dtag, dtag_nm);
4148 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
4149 tlv = fc_tlv_next_desc(tlv);
4154 if (!rcv_cap_desc) {
4155 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
4156 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4157 phba->cgn_sig_freq = 0;
4158 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
4159 "4202 EDC rsp error - sending RDF "
4160 "for FPIN only.\n");
4163 lpfc_config_cgn_signal(phba);
4165 /* Check to see if link went down during discovery */
4166 lpfc_els_chk_latt(phba->pport);
4167 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
4168 "EDC Cmpl: did:x%x refcnt %d",
4169 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4170 lpfc_els_free_iocb(phba, cmdiocb);
4175 lpfc_format_edc_lft_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
4177 struct fc_diag_lnkflt_desc *lft = (struct fc_diag_lnkflt_desc *)tlv;
4179 lft->desc_tag = cpu_to_be32(ELS_DTAG_LNK_FAULT_CAP);
4180 lft->desc_len = cpu_to_be32(
4181 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_lnkflt_desc));
4183 lft->degrade_activate_threshold =
4184 cpu_to_be32(phba->degrade_activate_threshold);
4185 lft->degrade_deactivate_threshold =
4186 cpu_to_be32(phba->degrade_deactivate_threshold);
4187 lft->fec_degrade_interval = cpu_to_be32(phba->fec_degrade_interval);
4191 lpfc_format_edc_cgn_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
4193 struct fc_diag_cg_sig_desc *cgd = (struct fc_diag_cg_sig_desc *)tlv;
4195 /* We are assuming cgd was zero'ed before calling this routine */
4197 /* Configure the congestion detection capability */
4198 cgd->desc_tag = cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP);
4200 /* Descriptor len doesn't include the tag or len fields. */
4201 cgd->desc_len = cpu_to_be32(
4202 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc));
4204 /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4205 * xmt_signal_frequency.count already set to 0.
4206 * xmt_signal_frequency.units already set to 0.
4209 if (phba->cmf_active_mode == LPFC_CFG_OFF) {
4210 /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4211 * rcv_signal_frequency.count already set to 0.
4212 * rcv_signal_frequency.units already set to 0.
4214 phba->cgn_sig_freq = 0;
4217 switch (phba->cgn_reg_signal) {
4218 case EDC_CG_SIG_WARN_ONLY:
4219 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ONLY);
4221 case EDC_CG_SIG_WARN_ALARM:
4222 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ALARM);
4225 /* rcv_signal_capability left 0 thus no support */
4229 /* We start negotiation with lpfc_fabric_cgn_frequency, after
4230 * the completion we settle on the higher frequency.
4232 cgd->rcv_signal_frequency.count =
4233 cpu_to_be16(lpfc_fabric_cgn_frequency);
4234 cgd->rcv_signal_frequency.units =
4235 cpu_to_be16(EDC_CG_SIGFREQ_MSEC);
4239 lpfc_link_is_lds_capable(struct lpfc_hba *phba)
4241 if (!(phba->lmt & LMT_64Gb))
4243 if (phba->sli_rev != LPFC_SLI_REV4)
4246 if (phba->sli4_hba.conf_trunk) {
4247 if (phba->trunk_link.phy_lnk_speed == LPFC_USER_LINK_SPEED_64G)
4249 } else if (phba->fc_linkspeed == LPFC_LINK_SPEED_64GHZ) {
4256 * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric.
4257 * @vport: pointer to a host virtual N_Port data structure.
4258 * @retry: retry counter for the command iocb.
4260 * This routine issues an ELS EDC to the F-Port Controller to communicate
4261 * this N_Port's support of hardware signals in its Congestion
4262 * Capabilities Descriptor.
4264 * Note: This routine does not check if one or more signals are
4265 * set in the cgn_reg_signal parameter. The caller makes the
4266 * decision to enforce cgn_reg_signal as nonzero or zero depending
4267 * on the conditions. During Fabric requests, the driver
4268 * requires cgn_reg_signals to be nonzero. But a dynamic request
4269 * to set the congestion mode to OFF from Monitor or Manage
4270 * would correctly issue an EDC with no signals enabled to
4271 * turn off switch functionality and then update the FW.
4274 * 0 - Successfully issued edc command
4275 * 1 - Failed to issue edc command
4278 lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry)
4280 struct lpfc_hba *phba = vport->phba;
4281 struct lpfc_iocbq *elsiocb;
4282 struct fc_els_edc *edc_req;
4283 struct fc_tlv_desc *tlv;
4285 struct lpfc_nodelist *ndlp;
4287 u32 cgn_desc_size, lft_desc_size;
4290 if (vport->port_type == LPFC_NPIV_PORT)
4293 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4294 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
4297 cgn_desc_size = (phba->cgn_init_reg_signal) ?
4298 sizeof(struct fc_diag_cg_sig_desc) : 0;
4299 lft_desc_size = (lpfc_link_is_lds_capable(phba)) ?
4300 sizeof(struct fc_diag_lnkflt_desc) : 0;
4301 cmdsize = cgn_desc_size + lft_desc_size;
4303 /* Skip EDC if no applicable descriptors */
4307 cmdsize += sizeof(struct fc_els_edc);
4308 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
4309 ndlp->nlp_DID, ELS_CMD_EDC);
4313 /* Configure the payload for the supported Diagnostics capabilities. */
4314 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
4315 memset(pcmd, 0, cmdsize);
4316 edc_req = (struct fc_els_edc *)pcmd;
4317 edc_req->desc_len = cpu_to_be32(cgn_desc_size + lft_desc_size);
4318 edc_req->edc_cmd = ELS_EDC;
4319 tlv = edc_req->desc;
4321 if (cgn_desc_size) {
4322 lpfc_format_edc_cgn_desc(phba, tlv);
4323 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
4324 tlv = fc_tlv_next_desc(tlv);
4328 lpfc_format_edc_lft_desc(phba, tlv);
4330 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4331 "4623 Xmit EDC to remote "
4332 "NPORT x%x reg_sig x%x reg_fpin:x%x\n",
4333 ndlp->nlp_DID, phba->cgn_reg_signal,
4334 phba->cgn_reg_fpin);
4336 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
4337 elsiocb->ndlp = lpfc_nlp_get(ndlp);
4338 if (!elsiocb->ndlp) {
4339 lpfc_els_free_iocb(phba, elsiocb);
4343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4344 "Issue EDC: did:x%x refcnt %d",
4345 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4346 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4347 if (rc == IOCB_ERROR) {
4348 /* The additional lpfc_nlp_put will cause the following
4349 * lpfc_els_free_iocb routine to trigger the rlease of
4352 lpfc_els_free_iocb(phba, elsiocb);
4358 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
4359 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4360 rc = lpfc_issue_els_rdf(vport, 0);
4365 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
4366 * @vport: pointer to a host virtual N_Port data structure.
4367 * @nlp: pointer to a node-list data structure.
4369 * This routine cancels the timer with a delayed IOCB-command retry for
4370 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
4371 * removes the ELS retry event if it presents. In addition, if the
4372 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
4373 * commands are sent for the @vport's nodes that require issuing discovery
4377 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
4379 struct lpfc_work_evt *evtp;
4381 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
4383 spin_lock_irq(&nlp->lock);
4384 nlp->nlp_flag &= ~NLP_DELAY_TMO;
4385 spin_unlock_irq(&nlp->lock);
4386 del_timer_sync(&nlp->nlp_delayfunc);
4387 nlp->nlp_last_elscmd = 0;
4388 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
4389 list_del_init(&nlp->els_retry_evt.evt_listp);
4390 /* Decrement nlp reference count held for the delayed retry */
4391 evtp = &nlp->els_retry_evt;
4392 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
4394 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
4395 spin_lock_irq(&nlp->lock);
4396 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4397 spin_unlock_irq(&nlp->lock);
4398 if (vport->num_disc_nodes) {
4399 if (vport->port_state < LPFC_VPORT_READY) {
4400 /* Check if there are more ADISCs to be sent */
4401 lpfc_more_adisc(vport);
4403 /* Check if there are more PLOGIs to be sent */
4404 lpfc_more_plogi(vport);
4405 if (vport->num_disc_nodes == 0) {
4406 clear_bit(FC_NDISC_ACTIVE,
4408 lpfc_can_disctmo(vport);
4409 lpfc_end_rscn(vport);
4418 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
4419 * @t: pointer to the timer function associated data (ndlp).
4421 * This routine is invoked by the ndlp delayed-function timer to check
4422 * whether there is any pending ELS retry event(s) with the node. If not, it
4423 * simply returns. Otherwise, if there is at least one ELS delayed event, it
4424 * adds the delayed events to the HBA work list and invokes the
4425 * lpfc_worker_wake_up() routine to wake up worker thread to process the
4426 * event. Note that lpfc_nlp_get() is called before posting the event to
4427 * the work list to hold reference count of ndlp so that it guarantees the
4428 * reference to ndlp will still be available when the worker thread gets
4429 * to the event associated with the ndlp.
4432 lpfc_els_retry_delay(struct timer_list *t)
4434 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
4435 struct lpfc_vport *vport = ndlp->vport;
4436 struct lpfc_hba *phba = vport->phba;
4437 unsigned long flags;
4438 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
4440 spin_lock_irqsave(&phba->hbalock, flags);
4441 if (!list_empty(&evtp->evt_listp)) {
4442 spin_unlock_irqrestore(&phba->hbalock, flags);
4446 /* We need to hold the node by incrementing the reference
4447 * count until the queued work is done
4449 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
4450 if (evtp->evt_arg1) {
4451 evtp->evt = LPFC_EVT_ELS_RETRY;
4452 list_add_tail(&evtp->evt_listp, &phba->work_list);
4453 lpfc_worker_wake_up(phba);
4455 spin_unlock_irqrestore(&phba->hbalock, flags);
4460 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
4461 * @ndlp: pointer to a node-list data structure.
4463 * This routine is the worker-thread handler for processing the @ndlp delayed
4464 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
4465 * the last ELS command from the associated ndlp and invokes the proper ELS
4466 * function according to the delayed ELS command to retry the command.
4469 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
4471 struct lpfc_vport *vport = ndlp->vport;
4472 uint32_t cmd, retry;
4474 spin_lock_irq(&ndlp->lock);
4475 cmd = ndlp->nlp_last_elscmd;
4476 ndlp->nlp_last_elscmd = 0;
4478 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
4479 spin_unlock_irq(&ndlp->lock);
4483 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4484 spin_unlock_irq(&ndlp->lock);
4486 * If a discovery event readded nlp_delayfunc after timer
4487 * firing and before processing the timer, cancel the
4490 del_timer_sync(&ndlp->nlp_delayfunc);
4491 retry = ndlp->nlp_retry;
4492 ndlp->nlp_retry = 0;
4496 lpfc_issue_els_flogi(vport, ndlp, retry);
4499 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
4500 ndlp->nlp_prev_state = ndlp->nlp_state;
4501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4505 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
4506 ndlp->nlp_prev_state = ndlp->nlp_state;
4507 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4511 case ELS_CMD_NVMEPRLI:
4512 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
4513 ndlp->nlp_prev_state = ndlp->nlp_state;
4514 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4518 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
4519 ndlp->nlp_prev_state = ndlp->nlp_state;
4520 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4524 if (!test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag))
4525 lpfc_issue_els_fdisc(vport, ndlp, retry);
4532 * lpfc_link_reset - Issue link reset
4533 * @vport: pointer to a virtual N_Port data structure.
4535 * This routine performs link reset by sending INIT_LINK mailbox command.
4536 * For SLI-3 adapter, link attention interrupt is enabled before issuing
4537 * INIT_LINK mailbox command.
4540 * 0 - Link reset initiated successfully
4541 * 1 - Failed to initiate link reset
4544 lpfc_link_reset(struct lpfc_vport *vport)
4546 struct lpfc_hba *phba = vport->phba;
4551 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4552 "2851 Attempt link reset\n");
4553 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4555 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4556 "2852 Failed to allocate mbox memory");
4560 /* Enable Link attention interrupts */
4561 if (phba->sli_rev <= LPFC_SLI_REV3) {
4562 spin_lock_irq(&phba->hbalock);
4563 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4564 control = readl(phba->HCregaddr);
4565 control |= HC_LAINT_ENA;
4566 writel(control, phba->HCregaddr);
4567 readl(phba->HCregaddr); /* flush */
4568 spin_unlock_irq(&phba->hbalock);
4571 lpfc_init_link(phba, mbox, phba->cfg_topology,
4572 phba->cfg_link_speed);
4573 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4574 mbox->vport = vport;
4575 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4576 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
4577 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4578 "2853 Failed to issue INIT_LINK "
4579 "mbox command, rc:x%x\n", rc);
4580 mempool_free(mbox, phba->mbox_mem_pool);
4588 * lpfc_els_retry - Make retry decision on an els command iocb
4589 * @phba: pointer to lpfc hba data structure.
4590 * @cmdiocb: pointer to lpfc command iocb data structure.
4591 * @rspiocb: pointer to lpfc response iocb data structure.
4593 * This routine makes a retry decision on an ELS command IOCB, which has
4594 * failed. The following ELS IOCBs use this function for retrying the command
4595 * when previously issued command responsed with error status: FLOGI, PLOGI,
4596 * PRLI, ADISC and FDISC. Based on the ELS command type and the
4597 * returned error status, it makes the decision whether a retry shall be
4598 * issued for the command, and whether a retry shall be made immediately or
4599 * delayed. In the former case, the corresponding ELS command issuing-function
4600 * is called to retry the command. In the later case, the ELS command shall
4601 * be posted to the ndlp delayed event and delayed function timer set to the
4602 * ndlp for the delayed command issusing.
4605 * 0 - No retry of els command is made
4606 * 1 - Immediate or delayed retry of els command is made
4609 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4610 struct lpfc_iocbq *rspiocb)
4612 struct lpfc_vport *vport = cmdiocb->vport;
4613 union lpfc_wqe128 *irsp = &rspiocb->wqe;
4614 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
4615 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
4618 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
4622 int link_reset = 0, rc;
4623 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
4624 u32 ulp_word4 = get_job_word4(phba, rspiocb);
4627 /* Note: cmd_dmabuf may be 0 for internal driver abort
4628 * of delays ELS command.
4631 if (pcmd && pcmd->virt) {
4632 elscmd = (uint32_t *) (pcmd->virt);
4637 did = ndlp->nlp_DID;
4639 /* We should only hit this case for retrying PLOGI */
4640 did = get_job_els_rsp64_did(phba, rspiocb);
4641 ndlp = lpfc_findnode_did(vport, did);
4642 if (!ndlp && (cmd != ELS_CMD_PLOGI))
4646 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4647 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
4648 *(((uint32_t *)irsp) + 7), ulp_word4, did);
4650 switch (ulp_status) {
4651 case IOSTAT_FCP_RSP_ERROR:
4653 case IOSTAT_REMOTE_STOP:
4654 if (phba->sli_rev == LPFC_SLI_REV4) {
4655 /* This IO was aborted by the target, we don't
4656 * know the rxid and because we did not send the
4657 * ABTS we cannot generate and RRQ.
4659 lpfc_set_rrq_active(phba, ndlp,
4660 cmdiocb->sli4_lxritag, 0, 0);
4663 case IOSTAT_LOCAL_REJECT:
4664 switch ((ulp_word4 & IOERR_PARAM_MASK)) {
4665 case IOERR_LOOP_OPEN_FAILURE:
4666 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
4671 case IOERR_ILLEGAL_COMMAND:
4672 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4673 "0124 Retry illegal cmd x%x "
4674 "retry:x%x delay:x%x\n",
4675 cmd, cmdiocb->retry, delay);
4677 /* All command's retry policy */
4679 if (cmdiocb->retry > 2)
4683 case IOERR_NO_RESOURCES:
4684 logerr = 1; /* HBA out of resources */
4686 if (cmdiocb->retry > 100)
4691 case IOERR_ILLEGAL_FRAME:
4696 case IOERR_INVALID_RPI:
4697 if (cmd == ELS_CMD_PLOGI &&
4698 did == NameServer_DID) {
4699 /* Continue forever if plogi to */
4700 /* the nameserver fails */
4703 } else if (cmd == ELS_CMD_PRLI &&
4704 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) {
4705 /* State-command disagreement. The PRLI was
4706 * failed with an invalid rpi meaning there
4707 * some unexpected state change. Don't retry.
4716 case IOERR_SEQUENCE_TIMEOUT:
4717 if (cmd == ELS_CMD_PLOGI &&
4718 did == NameServer_DID &&
4719 (cmdiocb->retry + 1) == maxretry) {
4720 /* Reset the Link */
4727 case IOERR_SLI_ABORTED:
4728 /* Retry ELS PLOGI command?
4729 * Possibly the rport just wasn't ready.
4731 if (cmd == ELS_CMD_PLOGI) {
4732 /* No retry if state change */
4734 ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
4743 case IOSTAT_NPORT_RJT:
4744 case IOSTAT_FABRIC_RJT:
4745 if (ulp_word4 & RJT_UNAVAIL_TEMP) {
4751 case IOSTAT_NPORT_BSY:
4752 case IOSTAT_FABRIC_BSY:
4753 logerr = 1; /* Fabric / Remote NPort out of resources */
4758 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
4759 /* Added for Vendor specifc support
4760 * Just keep retrying for these Rsn / Exp codes
4762 if (test_bit(FC_PT2PT, &vport->fc_flag) &&
4763 cmd == ELS_CMD_NVMEPRLI) {
4764 switch (stat.un.b.lsRjtRsnCode) {
4765 case LSRJT_UNABLE_TPC:
4766 case LSRJT_INVALID_CMD:
4767 case LSRJT_LOGICAL_ERR:
4768 case LSRJT_CMD_UNSUPPORTED:
4769 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
4770 "0168 NVME PRLI LS_RJT "
4771 "reason %x port doesn't "
4772 "support NVME, disabling NVME\n",
4773 stat.un.b.lsRjtRsnCode);
4775 set_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);
4779 switch (stat.un.b.lsRjtRsnCode) {
4780 case LSRJT_UNABLE_TPC:
4781 /* Special case for PRLI LS_RJTs. Recall that lpfc
4782 * uses a single routine to issue both PRLI FC4 types.
4783 * If the PRLI is rejected because that FC4 type
4784 * isn't really supported, don't retry and cause
4785 * multiple transport registrations. Otherwise, parse
4786 * the reason code/reason code explanation and take the
4787 * appropriate action.
4789 lpfc_printf_vlog(vport, KERN_INFO,
4790 LOG_DISCOVERY | LOG_ELS | LOG_NODE,
4791 "0153 ELS cmd x%x LS_RJT by x%x. "
4792 "RsnCode x%x RsnCodeExp x%x\n",
4793 cmd, did, stat.un.b.lsRjtRsnCode,
4794 stat.un.b.lsRjtRsnCodeExp);
4796 switch (stat.un.b.lsRjtRsnCodeExp) {
4797 case LSEXP_CANT_GIVE_DATA:
4798 case LSEXP_CMD_IN_PROGRESS:
4799 if (cmd == ELS_CMD_PLOGI) {
4805 case LSEXP_REQ_UNSUPPORTED:
4806 case LSEXP_NO_RSRC_ASSIGN:
4807 /* These explanation codes get no retry. */
4808 if (cmd == ELS_CMD_PRLI ||
4809 cmd == ELS_CMD_NVMEPRLI)
4813 /* Limit the delay and retry action to a limited
4814 * cmd set. There are other ELS commands where
4815 * a retry is not expected.
4817 if (cmd == ELS_CMD_PLOGI ||
4818 cmd == ELS_CMD_PRLI ||
4819 cmd == ELS_CMD_NVMEPRLI) {
4821 maxretry = lpfc_max_els_tries + 1;
4827 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4828 (cmd == ELS_CMD_FDISC) &&
4829 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
4830 lpfc_printf_vlog(vport, KERN_ERR,
4832 "0125 FDISC Failed (x%x). "
4833 "Fabric out of resources\n",
4834 stat.un.lsRjtError);
4835 lpfc_vport_set_state(vport,
4836 FC_VPORT_NO_FABRIC_RSCS);
4840 case LSRJT_LOGICAL_BSY:
4841 if ((cmd == ELS_CMD_PLOGI) ||
4842 (cmd == ELS_CMD_PRLI) ||
4843 (cmd == ELS_CMD_NVMEPRLI)) {
4846 } else if (cmd == ELS_CMD_FDISC) {
4847 /* FDISC retry policy */
4849 if (cmdiocb->retry >= 32)
4855 case LSRJT_LOGICAL_ERR:
4856 /* There are some cases where switches return this
4857 * error when they are not ready and should be returning
4858 * Logical Busy. We should delay every time.
4860 if (cmd == ELS_CMD_FDISC &&
4861 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4865 } else if (cmd == ELS_CMD_FLOGI &&
4866 stat.un.b.lsRjtRsnCodeExp ==
4867 LSEXP_NOTHING_MORE) {
4868 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4870 lpfc_printf_vlog(vport, KERN_ERR,
4872 "0820 FLOGI Failed (x%x). "
4873 "BBCredit Not Supported\n",
4874 stat.un.lsRjtError);
4878 case LSRJT_PROTOCOL_ERR:
4879 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4880 (cmd == ELS_CMD_FDISC) &&
4881 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4882 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4884 lpfc_printf_vlog(vport, KERN_ERR,
4886 "0122 FDISC Failed (x%x). "
4887 "Fabric Detected Bad WWN\n",
4888 stat.un.lsRjtError);
4889 lpfc_vport_set_state(vport,
4890 FC_VPORT_FABRIC_REJ_WWN);
4893 case LSRJT_VENDOR_UNIQUE:
4894 if ((stat.un.b.vendorUnique == 0x45) &&
4895 (cmd == ELS_CMD_FLOGI)) {
4899 case LSRJT_CMD_UNSUPPORTED:
4900 /* lpfc nvmet returns this type of LS_RJT when it
4901 * receives an FCP PRLI because lpfc nvmet only
4902 * support NVME. ELS request is terminated for FCP4
4905 if (stat.un.b.lsRjtRsnCodeExp ==
4906 LSEXP_REQ_UNSUPPORTED) {
4907 if (cmd == ELS_CMD_PRLI)
4914 case IOSTAT_INTERMED_RSP:
4923 rc = lpfc_link_reset(vport);
4925 /* Do not give up. Retry PLOGI one more time and attempt
4926 * link reset if PLOGI fails again.
4935 if (did == FDMI_DID)
4938 if ((cmd == ELS_CMD_FLOGI) &&
4939 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4940 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
4941 /* FLOGI retry policy */
4943 /* retry FLOGI forever */
4944 if (phba->link_flag != LS_LOOPBACK_MODE)
4949 if (cmdiocb->retry >= 100)
4951 else if (cmdiocb->retry >= 32)
4953 } else if ((cmd == ELS_CMD_FDISC) &&
4954 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
4955 /* retry FDISCs every second up to devloss */
4957 maxretry = vport->cfg_devloss_tmo;
4962 if (maxretry && (cmdiocb->retry >= maxretry)) {
4963 phba->fc_stat.elsRetryExceeded++;
4967 if (test_bit(FC_UNLOADING, &vport->load_flag))
4972 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4973 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4974 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4975 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4976 "2849 Stop retry ELS command "
4977 "x%x to remote NPORT x%x, "
4978 "Data: x%x x%x\n", cmd, did,
4979 cmdiocb->retry, delay);
4984 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4985 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4986 "0107 Retry ELS command x%x to remote "
4987 "NPORT x%x Data: x%x x%x\n",
4988 cmd, did, cmdiocb->retry, delay);
4990 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4991 ((ulp_status != IOSTAT_LOCAL_REJECT) ||
4992 ((ulp_word4 & IOERR_PARAM_MASK) !=
4993 IOERR_NO_RESOURCES))) {
4994 /* Don't reset timer for no resources */
4996 /* If discovery / RSCN timer is running, reset it */
4997 if (timer_pending(&vport->fc_disctmo) ||
4998 test_bit(FC_RSCN_MODE, &vport->fc_flag))
4999 lpfc_set_disctmo(vport);
5002 phba->fc_stat.elsXmitRetry++;
5003 if (ndlp && delay) {
5004 phba->fc_stat.elsDelayRetry++;
5005 ndlp->nlp_retry = cmdiocb->retry;
5007 /* delay is specified in milliseconds */
5008 mod_timer(&ndlp->nlp_delayfunc,
5009 jiffies + msecs_to_jiffies(delay));
5010 spin_lock_irq(&ndlp->lock);
5011 ndlp->nlp_flag |= NLP_DELAY_TMO;
5012 spin_unlock_irq(&ndlp->lock);
5014 ndlp->nlp_prev_state = ndlp->nlp_state;
5015 if ((cmd == ELS_CMD_PRLI) ||
5016 (cmd == ELS_CMD_NVMEPRLI))
5017 lpfc_nlp_set_state(vport, ndlp,
5018 NLP_STE_PRLI_ISSUE);
5019 else if (cmd != ELS_CMD_ADISC)
5020 lpfc_nlp_set_state(vport, ndlp,
5022 ndlp->nlp_last_elscmd = cmd;
5028 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
5031 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
5035 ndlp->nlp_prev_state = ndlp->nlp_state;
5036 lpfc_nlp_set_state(vport, ndlp,
5037 NLP_STE_PLOGI_ISSUE);
5039 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
5042 ndlp->nlp_prev_state = ndlp->nlp_state;
5043 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5044 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
5047 case ELS_CMD_NVMEPRLI:
5048 ndlp->nlp_prev_state = ndlp->nlp_state;
5049 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
5050 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
5053 ndlp->nlp_prev_state = ndlp->nlp_state;
5054 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
5055 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
5059 /* No retry ELS command <elsCmd> to remote NPORT <did> */
5061 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5062 "0137 No retry ELS command x%x to remote "
5063 "NPORT x%x: Out of Resources: Error:x%x/%x "
5065 cmd, did, ulp_status, ulp_word4,
5069 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5070 "0108 No retry ELS command x%x to remote "
5071 "NPORT x%x Retried:%d Error:x%x/%x "
5072 "IoTag x%x nflags x%x\n",
5073 cmd, did, cmdiocb->retry, ulp_status,
5074 ulp_word4, cmdiocb->iotag,
5075 (ndlp ? ndlp->nlp_flag : 0));
5081 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
5082 * @phba: pointer to lpfc hba data structure.
5083 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
5085 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
5086 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
5087 * checks to see whether there is a lpfc DMA buffer associated with the
5088 * response of the command IOCB. If so, it will be released before releasing
5089 * the lpfc DMA buffer associated with the IOCB itself.
5092 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5095 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
5097 struct lpfc_dmabuf *buf_ptr;
5099 /* Free the response before processing the command. */
5100 if (!list_empty(&buf_ptr1->list)) {
5101 list_remove_head(&buf_ptr1->list, buf_ptr,
5104 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5107 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
5113 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
5114 * @phba: pointer to lpfc hba data structure.
5115 * @buf_ptr: pointer to the lpfc dma buffer data structure.
5117 * This routine releases the lpfc Direct Memory Access (DMA) buffer
5118 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
5122 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5125 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
5127 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5133 * lpfc_els_free_iocb - Free a command iocb and its associated resources
5134 * @phba: pointer to lpfc hba data structure.
5135 * @elsiocb: pointer to lpfc els command iocb data structure.
5137 * This routine frees a command IOCB and its associated resources. The
5138 * command IOCB data structure contains the reference to various associated
5139 * resources, these fields must be set to NULL if the associated reference
5141 * cmd_dmabuf - reference to cmd.
5142 * cmd_dmabuf->next - reference to rsp
5143 * rsp_dmabuf - unused
5144 * bpl_dmabuf - reference to bpl
5146 * It first properly decrements the reference count held on ndlp for the
5147 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
5148 * set, it invokes the lpfc_els_free_data() routine to release the Direct
5149 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
5150 * adds the DMA buffer the @phba data structure for the delayed release.
5151 * If reference to the Buffer Pointer List (BPL) is present, the
5152 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
5153 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
5154 * invoked to release the IOCB data structure back to @phba IOCBQ list.
5157 * 0 - Success (currently, always return 0)
5160 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
5162 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
5164 /* The I/O iocb is complete. Clear the node and first dmbuf */
5165 elsiocb->ndlp = NULL;
5167 /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */
5168 if (elsiocb->cmd_dmabuf) {
5169 if (elsiocb->cmd_flag & LPFC_DELAY_MEM_FREE) {
5170 /* Firmware could still be in progress of DMAing
5171 * payload, so don't free data buffer till after
5174 elsiocb->cmd_flag &= ~LPFC_DELAY_MEM_FREE;
5175 buf_ptr = elsiocb->cmd_dmabuf;
5176 elsiocb->cmd_dmabuf = NULL;
5179 spin_lock_irq(&phba->hbalock);
5180 if (!list_empty(&buf_ptr->list)) {
5181 list_remove_head(&buf_ptr->list,
5182 buf_ptr1, struct lpfc_dmabuf,
5184 INIT_LIST_HEAD(&buf_ptr1->list);
5185 list_add_tail(&buf_ptr1->list,
5189 INIT_LIST_HEAD(&buf_ptr->list);
5190 list_add_tail(&buf_ptr->list, &phba->elsbuf);
5192 spin_unlock_irq(&phba->hbalock);
5195 buf_ptr1 = elsiocb->cmd_dmabuf;
5196 lpfc_els_free_data(phba, buf_ptr1);
5197 elsiocb->cmd_dmabuf = NULL;
5201 if (elsiocb->bpl_dmabuf) {
5202 buf_ptr = elsiocb->bpl_dmabuf;
5203 lpfc_els_free_bpl(phba, buf_ptr);
5204 elsiocb->bpl_dmabuf = NULL;
5206 lpfc_sli_release_iocbq(phba, elsiocb);
5211 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
5212 * @phba: pointer to lpfc hba data structure.
5213 * @cmdiocb: pointer to lpfc command iocb data structure.
5214 * @rspiocb: pointer to lpfc response iocb data structure.
5216 * This routine is the completion callback function to the Logout (LOGO)
5217 * Accept (ACC) Response ELS command. This routine is invoked to indicate
5218 * the completion of the LOGO process. If the node has transitioned to NPR,
5219 * this routine unregisters the RPI if it is still registered. The
5220 * lpfc_els_free_iocb() is invoked to release the IOCB data structure.
5223 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5224 struct lpfc_iocbq *rspiocb)
5226 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
5227 struct lpfc_vport *vport = cmdiocb->vport;
5228 u32 ulp_status, ulp_word4;
5230 ulp_status = get_job_ulpstatus(phba, rspiocb);
5231 ulp_word4 = get_job_word4(phba, rspiocb);
5233 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5234 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
5235 ulp_status, ulp_word4, ndlp->nlp_DID);
5236 /* ACC to LOGO completes to NPort <nlp_DID> */
5237 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5238 "0109 ACC to LOGO completes to NPort x%x refcnt %d "
5239 "Data: x%x x%x x%x\n",
5240 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
5241 ndlp->nlp_state, ndlp->nlp_rpi);
5243 /* This clause allows the LOGO ACC to complete and free resources
5244 * for the Fabric Domain Controller. It does deliberately skip
5245 * the unreg_rpi and release rpi because some fabrics send RDP
5246 * requests after logging out from the initiator.
5248 if (ndlp->nlp_type & NLP_FABRIC &&
5249 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
5252 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
5253 /* If PLOGI is being retried, PLOGI completion will cleanup the
5254 * node. The NLP_NPR_2B_DISC flag needs to be retained to make
5255 * progress on nodes discovered from last RSCN.
5257 if ((ndlp->nlp_flag & NLP_DELAY_TMO) &&
5258 (ndlp->nlp_last_elscmd == ELS_CMD_PLOGI))
5261 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
5262 lpfc_unreg_rpi(vport, ndlp);
5267 * The driver received a LOGO from the rport and has ACK'd it.
5268 * At this point, the driver is done so release the IOCB
5270 lpfc_els_free_iocb(phba, cmdiocb);
5275 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
5276 * @phba: pointer to lpfc hba data structure.
5277 * @pmb: pointer to the driver internal queue element for mailbox command.
5279 * This routine is the completion callback function for unregister default
5280 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
5281 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
5282 * decrements the ndlp reference count held for this completion callback
5283 * function. After that, it invokes the lpfc_drop_node to check
5284 * whether it is appropriate to release the node.
5287 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5289 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
5290 u32 mbx_flag = pmb->mbox_flag;
5291 u32 mbx_cmd = pmb->u.mb.mbxCommand;
5294 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5295 "0006 rpi x%x DID:%x flg:%x %d x%px "
5296 "mbx_cmd x%x mbx_flag x%x x%px\n",
5297 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5298 kref_read(&ndlp->kref), ndlp, mbx_cmd,
5301 /* This ends the default/temporary RPI cleanup logic for this
5302 * ndlp and the node and rpi needs to be released. Free the rpi
5303 * first on an UNREG_LOGIN and then release the final
5306 spin_lock_irq(&ndlp->lock);
5307 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
5308 if (mbx_cmd == MBX_UNREG_LOGIN)
5309 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5310 spin_unlock_irq(&ndlp->lock);
5312 lpfc_drop_node(ndlp->vport, ndlp);
5315 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
5319 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
5320 * @phba: pointer to lpfc hba data structure.
5321 * @cmdiocb: pointer to lpfc command iocb data structure.
5322 * @rspiocb: pointer to lpfc response iocb data structure.
5324 * This routine is the completion callback function for ELS Response IOCB
5325 * command. In normal case, this callback function just properly sets the
5326 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
5327 * field in the command IOCB is not NULL, the referred mailbox command will
5328 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
5332 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5333 struct lpfc_iocbq *rspiocb)
5335 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
5336 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
5337 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
5339 LPFC_MBOXQ_t *mbox = NULL;
5340 u32 ulp_status, ulp_word4, tmo, did, iotag;
5343 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5344 "3177 ELS response failed\n");
5347 if (cmdiocb->context_un.mbox)
5348 mbox = cmdiocb->context_un.mbox;
5350 ulp_status = get_job_ulpstatus(phba, rspiocb);
5351 ulp_word4 = get_job_word4(phba, rspiocb);
5352 did = get_job_els_rsp64_did(phba, cmdiocb);
5354 if (phba->sli_rev == LPFC_SLI_REV4) {
5355 tmo = get_wqe_tmo(cmdiocb);
5356 iotag = get_wqe_reqtag(cmdiocb);
5358 irsp = &rspiocb->iocb;
5359 tmo = irsp->ulpTimeout;
5360 iotag = irsp->ulpIoTag;
5363 /* Check to see if link went down during discovery */
5364 if (!ndlp || lpfc_els_chk_latt(vport)) {
5366 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
5370 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5371 "ELS rsp cmpl: status:x%x/x%x did:x%x",
5372 ulp_status, ulp_word4, did);
5373 /* ELS response tag <ulpIoTag> completes */
5374 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5375 "0110 ELS response tag x%x completes "
5376 "Data: x%x x%x x%x x%x x%x x%x x%x x%x %p %p\n",
5377 iotag, ulp_status, ulp_word4, tmo,
5378 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5379 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox, ndlp);
5382 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
5383 if (!lpfc_unreg_rpi(vport, ndlp) &&
5384 !test_bit(FC_PT2PT, &vport->fc_flag)) {
5385 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5387 NLP_STE_REG_LOGIN_ISSUE) {
5388 lpfc_printf_vlog(vport, KERN_INFO,
5392 "Data: x%x x%x x%x\n",
5401 /* Increment reference count to ndlp to hold the
5402 * reference to ndlp for the callback function.
5404 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5405 if (!mbox->ctx_ndlp)
5408 mbox->vport = vport;
5409 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
5410 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5411 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5414 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
5415 ndlp->nlp_prev_state = ndlp->nlp_state;
5416 lpfc_nlp_set_state(vport, ndlp,
5417 NLP_STE_REG_LOGIN_ISSUE);
5420 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
5421 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5422 != MBX_NOT_FINISHED)
5425 /* Decrement the ndlp reference count we
5426 * set for this failed mailbox command.
5429 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
5431 /* ELS rsp: Cannot issue reg_login for <NPortid> */
5432 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5433 "0138 ELS rsp: Cannot issue reg_login for x%x "
5434 "Data: x%x x%x x%x\n",
5435 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5439 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
5442 if (ndlp && shost) {
5443 spin_lock_irq(&ndlp->lock);
5445 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
5446 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
5447 spin_unlock_irq(&ndlp->lock);
5450 /* An SLI4 NPIV instance wants to drop the node at this point under
5451 * these conditions and release the RPI.
5453 if (phba->sli_rev == LPFC_SLI_REV4 &&
5454 vport && vport->port_type == LPFC_NPIV_PORT &&
5455 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
5456 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5457 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE &&
5458 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
5459 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
5460 spin_lock_irq(&ndlp->lock);
5461 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5462 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5463 spin_unlock_irq(&ndlp->lock);
5465 lpfc_drop_node(vport, ndlp);
5466 } else if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE &&
5467 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE &&
5468 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) {
5469 /* Drop ndlp if there is no planned or outstanding
5472 * In cases when the ndlp is acting as both an initiator
5473 * and target function, let our issued PRLI determine
5474 * the final ndlp kref drop.
5476 lpfc_drop_node(vport, ndlp);
5480 /* Release the originating I/O reference. */
5481 lpfc_els_free_iocb(phba, cmdiocb);
5487 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
5488 * @vport: pointer to a host virtual N_Port data structure.
5489 * @flag: the els command code to be accepted.
5490 * @oldiocb: pointer to the original lpfc command iocb data structure.
5491 * @ndlp: pointer to a node-list data structure.
5492 * @mbox: pointer to the driver internal queue element for mailbox command.
5494 * This routine prepares and issues an Accept (ACC) response IOCB
5495 * command. It uses the @flag to properly set up the IOCB field for the
5496 * specific ACC response command to be issued and invokes the
5497 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
5498 * @mbox pointer is passed in, it will be put into the context_un.mbox
5499 * field of the IOCB for the completion callback function to issue the
5500 * mailbox command to the HBA later when callback is invoked.
5502 * Note that the ndlp reference count will be incremented by 1 for holding the
5503 * ndlp and the reference to ndlp will be stored into the ndlp field of
5504 * the IOCB for the completion callback function to the corresponding
5505 * response ELS IOCB command.
5508 * 0 - Successfully issued acc response
5509 * 1 - Failed to issue acc response
5512 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
5513 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5516 struct lpfc_hba *phba = vport->phba;
5519 union lpfc_wqe128 *wqe;
5520 union lpfc_wqe128 *oldwqe = &oldiocb->wqe;
5521 struct lpfc_iocbq *elsiocb;
5523 struct serv_parm *sp;
5526 ELS_PKT *els_pkt_ptr;
5527 struct fc_els_rdf_resp *rdf_resp;
5531 cmdsize = sizeof(uint32_t);
5532 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5533 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5535 spin_lock_irq(&ndlp->lock);
5536 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5537 spin_unlock_irq(&ndlp->lock);
5541 if (phba->sli_rev == LPFC_SLI_REV4) {
5542 wqe = &elsiocb->wqe;
5544 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5545 bf_get(wqe_ctxt_tag,
5546 &oldwqe->xmit_els_rsp.wqe_com));
5549 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5551 &oldwqe->xmit_els_rsp.wqe_com));
5553 icmd = &elsiocb->iocb;
5554 oldcmd = &oldiocb->iocb;
5555 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5556 icmd->unsli3.rcvsli3.ox_id =
5557 oldcmd->unsli3.rcvsli3.ox_id;
5560 pcmd = elsiocb->cmd_dmabuf->virt;
5561 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5562 pcmd += sizeof(uint32_t);
5564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5565 "Issue ACC: did:x%x flg:x%x",
5566 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5570 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
5571 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5572 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5576 if (phba->sli_rev == LPFC_SLI_REV4) {
5577 wqe = &elsiocb->wqe;
5579 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5580 bf_get(wqe_ctxt_tag,
5581 &oldwqe->xmit_els_rsp.wqe_com));
5584 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5586 &oldwqe->xmit_els_rsp.wqe_com));
5588 icmd = &elsiocb->iocb;
5589 oldcmd = &oldiocb->iocb;
5590 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5591 icmd->unsli3.rcvsli3.ox_id =
5592 oldcmd->unsli3.rcvsli3.ox_id;
5595 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
5598 elsiocb->context_un.mbox = mbox;
5600 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5601 pcmd += sizeof(uint32_t);
5602 sp = (struct serv_parm *)pcmd;
5604 if (flag == ELS_CMD_FLOGI) {
5605 /* Copy the received service parameters back */
5606 memcpy(sp, &phba->fc_fabparam,
5607 sizeof(struct serv_parm));
5609 /* Clear the F_Port bit */
5612 /* Mark all class service parameters as invalid */
5613 sp->cls1.classValid = 0;
5614 sp->cls2.classValid = 0;
5615 sp->cls3.classValid = 0;
5616 sp->cls4.classValid = 0;
5618 /* Copy our worldwide names */
5619 memcpy(&sp->portName, &vport->fc_sparam.portName,
5620 sizeof(struct lpfc_name));
5621 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
5622 sizeof(struct lpfc_name));
5624 memcpy(pcmd, &vport->fc_sparam,
5625 sizeof(struct serv_parm));
5627 sp->cmn.valid_vendor_ver_level = 0;
5628 memset(sp->un.vendorVersion, 0,
5629 sizeof(sp->un.vendorVersion));
5630 sp->cmn.bbRcvSizeMsb &= 0xF;
5632 /* If our firmware supports this feature, convey that
5633 * info to the target using the vendor specific field.
5635 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
5636 sp->cmn.valid_vendor_ver_level = 1;
5637 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
5639 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
5643 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5644 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
5645 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5648 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
5649 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5650 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
5654 if (phba->sli_rev == LPFC_SLI_REV4) {
5655 wqe = &elsiocb->wqe;
5657 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5658 bf_get(wqe_ctxt_tag,
5659 &oldwqe->xmit_els_rsp.wqe_com));
5662 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5664 &oldwqe->xmit_els_rsp.wqe_com));
5666 icmd = &elsiocb->iocb;
5667 oldcmd = &oldiocb->iocb;
5668 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5669 icmd->unsli3.rcvsli3.ox_id =
5670 oldcmd->unsli3.rcvsli3.ox_id;
5673 pcmd = (u8 *) elsiocb->cmd_dmabuf->virt;
5675 memcpy(pcmd, oldiocb->cmd_dmabuf->virt,
5676 sizeof(uint32_t) + sizeof(PRLO));
5677 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
5678 els_pkt_ptr = (ELS_PKT *) pcmd;
5679 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
5681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5682 "Issue ACC PRLO: did:x%x flg:x%x",
5683 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5686 cmdsize = sizeof(*rdf_resp);
5687 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5688 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5692 if (phba->sli_rev == LPFC_SLI_REV4) {
5693 wqe = &elsiocb->wqe;
5695 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5696 bf_get(wqe_ctxt_tag,
5697 &oldwqe->xmit_els_rsp.wqe_com));
5700 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5702 &oldwqe->xmit_els_rsp.wqe_com));
5704 icmd = &elsiocb->iocb;
5705 oldcmd = &oldiocb->iocb;
5706 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5707 icmd->unsli3.rcvsli3.ox_id =
5708 oldcmd->unsli3.rcvsli3.ox_id;
5711 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
5712 rdf_resp = (struct fc_els_rdf_resp *)pcmd;
5713 memset(rdf_resp, 0, sizeof(*rdf_resp));
5714 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC;
5716 /* FC-LS-5 specifies desc_list_len shall be set to 12 */
5717 rdf_resp->desc_list_len = cpu_to_be32(12);
5719 /* FC-LS-5 specifies LS REQ Information descriptor */
5720 rdf_resp->lsri.desc_tag = cpu_to_be32(1);
5721 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32));
5722 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF;
5727 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
5728 spin_lock_irq(&ndlp->lock);
5729 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5730 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
5731 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5732 spin_unlock_irq(&ndlp->lock);
5733 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo_acc;
5735 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5738 phba->fc_stat.elsXmitACC++;
5739 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5740 if (!elsiocb->ndlp) {
5741 lpfc_els_free_iocb(phba, elsiocb);
5745 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5746 if (rc == IOCB_ERROR) {
5747 lpfc_els_free_iocb(phba, elsiocb);
5752 /* Xmit ELS ACC response tag <ulpIoTag> */
5753 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5754 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5755 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5756 "RPI: x%x, fc_flag x%lx refcnt %d\n",
5757 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5758 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5759 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref));
5764 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
5765 * @vport: pointer to a virtual N_Port data structure.
5766 * @rejectError: reject response to issue
5767 * @oldiocb: pointer to the original lpfc command iocb data structure.
5768 * @ndlp: pointer to a node-list data structure.
5769 * @mbox: pointer to the driver internal queue element for mailbox command.
5771 * This routine prepares and issue an Reject (RJT) response IOCB
5772 * command. If a @mbox pointer is passed in, it will be put into the
5773 * context_un.mbox field of the IOCB for the completion callback function
5774 * to issue to the HBA later.
5776 * Note that the ndlp reference count will be incremented by 1 for holding the
5777 * ndlp and the reference to ndlp will be stored into the ndlp field of
5778 * the IOCB for the completion callback function to the reject response
5782 * 0 - Successfully issued reject response
5783 * 1 - Failed to issue reject response
5786 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
5787 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5791 struct lpfc_hba *phba = vport->phba;
5794 union lpfc_wqe128 *wqe;
5795 struct lpfc_iocbq *elsiocb;
5799 cmdsize = 2 * sizeof(uint32_t);
5800 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5801 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5805 if (phba->sli_rev == LPFC_SLI_REV4) {
5806 wqe = &elsiocb->wqe;
5807 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5808 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
5809 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5810 get_job_rcvoxid(phba, oldiocb));
5812 icmd = &elsiocb->iocb;
5813 oldcmd = &oldiocb->iocb;
5814 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5815 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5818 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
5820 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5821 pcmd += sizeof(uint32_t);
5822 *((uint32_t *) (pcmd)) = rejectError;
5825 elsiocb->context_un.mbox = mbox;
5827 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
5828 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5829 "0129 Xmit ELS RJT x%x response tag x%x "
5830 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5832 rejectError, elsiocb->iotag,
5833 get_job_ulpcontext(phba, elsiocb), ndlp->nlp_DID,
5834 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
5835 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5836 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
5837 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
5839 phba->fc_stat.elsXmitLSRJT++;
5840 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5841 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5842 if (!elsiocb->ndlp) {
5843 lpfc_els_free_iocb(phba, elsiocb);
5847 /* The NPIV instance is rejecting this unsolicited ELS. Make sure the
5848 * node's assigned RPI gets released provided this node is not already
5849 * registered with the transport.
5851 if (phba->sli_rev == LPFC_SLI_REV4 &&
5852 vport->port_type == LPFC_NPIV_PORT &&
5853 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
5854 spin_lock_irq(&ndlp->lock);
5855 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5856 spin_unlock_irq(&ndlp->lock);
5859 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5860 if (rc == IOCB_ERROR) {
5861 lpfc_els_free_iocb(phba, elsiocb);
5870 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric.
5871 * @vport: pointer to a host virtual N_Port data structure.
5872 * @cmdiocb: pointer to the original lpfc command iocb data structure.
5873 * @ndlp: NPort to where rsp is directed
5875 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate
5876 * this N_Port's support of hardware signals in its Congestion
5877 * Capabilities Descriptor.
5880 * 0 - Successfully issued edc rsp command
5881 * 1 - Failed to issue edc rsp command
5884 lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5885 struct lpfc_nodelist *ndlp)
5887 struct lpfc_hba *phba = vport->phba;
5888 struct fc_els_edc_resp *edc_rsp;
5889 struct fc_tlv_desc *tlv;
5890 struct lpfc_iocbq *elsiocb;
5892 union lpfc_wqe128 *wqe;
5893 u32 cgn_desc_size, lft_desc_size;
5898 cmdsize = sizeof(struct fc_els_edc_resp);
5899 cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc);
5900 lft_desc_size = (lpfc_link_is_lds_capable(phba)) ?
5901 sizeof(struct fc_diag_lnkflt_desc) : 0;
5902 cmdsize += cgn_desc_size + lft_desc_size;
5903 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry,
5904 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5908 if (phba->sli_rev == LPFC_SLI_REV4) {
5909 wqe = &elsiocb->wqe;
5910 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5911 get_job_ulpcontext(phba, cmdiocb)); /* Xri / rx_id */
5912 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5913 get_job_rcvoxid(phba, cmdiocb));
5915 icmd = &elsiocb->iocb;
5916 cmd = &cmdiocb->iocb;
5917 icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */
5918 icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id;
5921 pcmd = elsiocb->cmd_dmabuf->virt;
5922 memset(pcmd, 0, cmdsize);
5924 edc_rsp = (struct fc_els_edc_resp *)pcmd;
5925 edc_rsp->acc_hdr.la_cmd = ELS_LS_ACC;
5926 edc_rsp->desc_list_len = cpu_to_be32(sizeof(struct fc_els_lsri_desc) +
5927 cgn_desc_size + lft_desc_size);
5928 edc_rsp->lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO);
5929 edc_rsp->lsri.desc_len = cpu_to_be32(
5930 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc));
5931 edc_rsp->lsri.rqst_w0.cmd = ELS_EDC;
5932 tlv = edc_rsp->desc;
5933 lpfc_format_edc_cgn_desc(phba, tlv);
5934 tlv = fc_tlv_next_desc(tlv);
5936 lpfc_format_edc_lft_desc(phba, tlv);
5938 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5939 "Issue EDC ACC: did:x%x flg:x%x refcnt %d",
5940 ndlp->nlp_DID, ndlp->nlp_flag,
5941 kref_read(&ndlp->kref));
5942 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5944 phba->fc_stat.elsXmitACC++;
5945 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5946 if (!elsiocb->ndlp) {
5947 lpfc_els_free_iocb(phba, elsiocb);
5951 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5952 if (rc == IOCB_ERROR) {
5953 lpfc_els_free_iocb(phba, elsiocb);
5958 /* Xmit ELS ACC response tag <ulpIoTag> */
5959 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5960 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, "
5961 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5962 "RPI: x%x, fc_flag x%lx\n",
5963 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5964 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5965 ndlp->nlp_rpi, vport->fc_flag);
5971 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
5972 * @vport: pointer to a virtual N_Port data structure.
5973 * @oldiocb: pointer to the original lpfc command iocb data structure.
5974 * @ndlp: pointer to a node-list data structure.
5976 * This routine prepares and issues an Accept (ACC) response to Address
5977 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
5978 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5980 * Note that the ndlp reference count will be incremented by 1 for holding the
5981 * ndlp and the reference to ndlp will be stored into the ndlp field of
5982 * the IOCB for the completion callback function to the ADISC Accept response
5986 * 0 - Successfully issued acc adisc response
5987 * 1 - Failed to issue adisc acc response
5990 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5991 struct lpfc_nodelist *ndlp)
5993 struct lpfc_hba *phba = vport->phba;
5995 IOCB_t *icmd, *oldcmd;
5996 union lpfc_wqe128 *wqe;
5997 struct lpfc_iocbq *elsiocb;
6003 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
6004 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6005 ndlp->nlp_DID, ELS_CMD_ACC);
6009 if (phba->sli_rev == LPFC_SLI_REV4) {
6010 wqe = &elsiocb->wqe;
6012 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6013 get_job_ulpcontext(phba, oldiocb));
6014 ulp_context = get_job_ulpcontext(phba, elsiocb);
6016 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6017 get_job_rcvoxid(phba, oldiocb));
6019 icmd = &elsiocb->iocb;
6020 oldcmd = &oldiocb->iocb;
6021 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6022 ulp_context = elsiocb->iocb.ulpContext;
6023 icmd->unsli3.rcvsli3.ox_id =
6024 oldcmd->unsli3.rcvsli3.ox_id;
6027 /* Xmit ADISC ACC response tag <ulpIoTag> */
6028 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6029 "0130 Xmit ADISC ACC response iotag x%x xri: "
6030 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
6031 elsiocb->iotag, ulp_context,
6032 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6034 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6036 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6037 pcmd += sizeof(uint32_t);
6039 ap = (ADISC *) (pcmd);
6040 ap->hardAL_PA = phba->fc_pref_ALPA;
6041 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
6042 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
6043 ap->DID = be32_to_cpu(vport->fc_myDID);
6045 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6046 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
6047 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6049 phba->fc_stat.elsXmitACC++;
6050 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6051 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6052 if (!elsiocb->ndlp) {
6053 lpfc_els_free_iocb(phba, elsiocb);
6057 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6058 if (rc == IOCB_ERROR) {
6059 lpfc_els_free_iocb(phba, elsiocb);
6068 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
6069 * @vport: pointer to a virtual N_Port data structure.
6070 * @oldiocb: pointer to the original lpfc command iocb data structure.
6071 * @ndlp: pointer to a node-list data structure.
6073 * This routine prepares and issues an Accept (ACC) response to Process
6074 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
6075 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
6077 * Note that the ndlp reference count will be incremented by 1 for holding the
6078 * ndlp and the reference to ndlp will be stored into the ndlp field of
6079 * the IOCB for the completion callback function to the PRLI Accept response
6083 * 0 - Successfully issued acc prli response
6084 * 1 - Failed to issue acc prli response
6087 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
6088 struct lpfc_nodelist *ndlp)
6090 struct lpfc_hba *phba = vport->phba;
6092 struct lpfc_nvme_prli *npr_nvme;
6096 union lpfc_wqe128 *wqe;
6097 struct lpfc_iocbq *elsiocb;
6100 uint32_t prli_fc4_req, *req_payload;
6101 struct lpfc_dmabuf *req_buf;
6103 u32 elsrspcmd, ulp_context;
6105 /* Need the incoming PRLI payload to determine if the ACC is for an
6106 * FC4 or NVME PRLI type. The PRLI type is at word 1.
6108 req_buf = oldiocb->cmd_dmabuf;
6109 req_payload = (((uint32_t *)req_buf->virt) + 1);
6111 /* PRLI type payload is at byte 3 for FCP or NVME. */
6112 prli_fc4_req = be32_to_cpu(*req_payload);
6113 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
6114 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6115 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
6116 prli_fc4_req, *((uint32_t *)req_payload));
6118 if (prli_fc4_req == PRLI_FCP_TYPE) {
6119 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
6120 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
6121 } else if (prli_fc4_req == PRLI_NVME_TYPE) {
6122 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
6123 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
6128 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6129 ndlp->nlp_DID, elsrspcmd);
6133 if (phba->sli_rev == LPFC_SLI_REV4) {
6134 wqe = &elsiocb->wqe;
6135 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6136 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6137 ulp_context = get_job_ulpcontext(phba, elsiocb);
6138 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6139 get_job_rcvoxid(phba, oldiocb));
6141 icmd = &elsiocb->iocb;
6142 oldcmd = &oldiocb->iocb;
6143 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6144 ulp_context = elsiocb->iocb.ulpContext;
6145 icmd->unsli3.rcvsli3.ox_id =
6146 oldcmd->unsli3.rcvsli3.ox_id;
6149 /* Xmit PRLI ACC response tag <ulpIoTag> */
6150 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6151 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
6152 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6153 elsiocb->iotag, ulp_context,
6154 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6156 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6157 memset(pcmd, 0, cmdsize);
6159 *((uint32_t *)(pcmd)) = elsrspcmd;
6160 pcmd += sizeof(uint32_t);
6162 /* For PRLI, remainder of payload is PRLI parameter page */
6165 if (prli_fc4_req == PRLI_FCP_TYPE) {
6167 * If the remote port is a target and our firmware version
6168 * is 3.20 or later, set the following bits for FC-TAPE
6171 npr = (PRLI *) pcmd;
6172 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
6173 (vpd->rev.feaLevelHigh >= 0x02)) {
6174 npr->ConfmComplAllowed = 1;
6176 npr->TaskRetryIdReq = 1;
6178 npr->acceptRspCode = PRLI_REQ_EXECUTED;
6180 /* Set image pair for complementary pairs only. */
6181 if (ndlp->nlp_type & NLP_FCP_TARGET)
6182 npr->estabImagePair = 1;
6184 npr->estabImagePair = 0;
6185 npr->readXferRdyDis = 1;
6186 npr->ConfmComplAllowed = 1;
6187 npr->prliType = PRLI_FCP_TYPE;
6188 npr->initiatorFunc = 1;
6190 /* Xmit PRLI ACC response tag <ulpIoTag> */
6191 lpfc_printf_vlog(vport, KERN_INFO,
6192 LOG_ELS | LOG_NODE | LOG_DISCOVERY,
6193 "6014 FCP issue PRLI ACC imgpair %d "
6194 "retry %d task %d\n",
6195 npr->estabImagePair,
6196 npr->Retry, npr->TaskRetryIdReq);
6198 } else if (prli_fc4_req == PRLI_NVME_TYPE) {
6199 /* Respond with an NVME PRLI Type */
6200 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
6201 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
6202 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
6203 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
6204 if (phba->nvmet_support) {
6205 bf_set(prli_tgt, npr_nvme, 1);
6206 bf_set(prli_disc, npr_nvme, 1);
6207 if (phba->cfg_nvme_enable_fb) {
6208 bf_set(prli_fba, npr_nvme, 1);
6210 /* TBD. Target mode needs to post buffers
6211 * that support the configured first burst
6214 bf_set(prli_fb_sz, npr_nvme,
6215 phba->cfg_nvmet_fb_size);
6218 bf_set(prli_init, npr_nvme, 1);
6221 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
6222 "6015 NVME issue PRLI ACC word1 x%08x "
6223 "word4 x%08x word5 x%08x flag x%x, "
6224 "fcp_info x%x nlp_type x%x\n",
6225 npr_nvme->word1, npr_nvme->word4,
6226 npr_nvme->word5, ndlp->nlp_flag,
6227 ndlp->nlp_fcp_info, ndlp->nlp_type);
6228 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
6229 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
6230 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
6232 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6233 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
6234 prli_fc4_req, ndlp->nlp_fc4_type,
6237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6238 "Issue ACC PRLI: did:x%x flg:x%x",
6239 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6241 phba->fc_stat.elsXmitACC++;
6242 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6243 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6244 if (!elsiocb->ndlp) {
6245 lpfc_els_free_iocb(phba, elsiocb);
6249 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6250 if (rc == IOCB_ERROR) {
6251 lpfc_els_free_iocb(phba, elsiocb);
6260 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
6261 * @vport: pointer to a virtual N_Port data structure.
6262 * @format: rnid command format.
6263 * @oldiocb: pointer to the original lpfc command iocb data structure.
6264 * @ndlp: pointer to a node-list data structure.
6266 * This routine issues a Request Node Identification Data (RNID) Accept
6267 * (ACC) response. It constructs the RNID ACC response command according to
6268 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
6269 * issue the response.
6271 * Note that the ndlp reference count will be incremented by 1 for holding the
6272 * ndlp and the reference to ndlp will be stored into the ndlp field of
6273 * the IOCB for the completion callback function.
6276 * 0 - Successfully issued acc rnid response
6277 * 1 - Failed to issue acc rnid response
6280 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
6281 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6283 struct lpfc_hba *phba = vport->phba;
6285 IOCB_t *icmd, *oldcmd;
6286 union lpfc_wqe128 *wqe;
6287 struct lpfc_iocbq *elsiocb;
6293 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
6294 + (2 * sizeof(struct lpfc_name));
6296 cmdsize += sizeof(RNID_TOP_DISC);
6298 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6299 ndlp->nlp_DID, ELS_CMD_ACC);
6303 if (phba->sli_rev == LPFC_SLI_REV4) {
6304 wqe = &elsiocb->wqe;
6305 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6306 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6307 ulp_context = get_job_ulpcontext(phba, elsiocb);
6308 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6309 get_job_rcvoxid(phba, oldiocb));
6311 icmd = &elsiocb->iocb;
6312 oldcmd = &oldiocb->iocb;
6313 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6314 ulp_context = elsiocb->iocb.ulpContext;
6315 icmd->unsli3.rcvsli3.ox_id =
6316 oldcmd->unsli3.rcvsli3.ox_id;
6319 /* Xmit RNID ACC response tag <ulpIoTag> */
6320 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6321 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
6322 elsiocb->iotag, ulp_context);
6323 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6324 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6325 pcmd += sizeof(uint32_t);
6327 memset(pcmd, 0, sizeof(RNID));
6328 rn = (RNID *) (pcmd);
6329 rn->Format = format;
6330 rn->CommonLen = (2 * sizeof(struct lpfc_name));
6331 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
6332 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
6335 rn->SpecificLen = 0;
6337 case RNID_TOPOLOGY_DISC:
6338 rn->SpecificLen = sizeof(RNID_TOP_DISC);
6339 memcpy(&rn->un.topologyDisc.portName,
6340 &vport->fc_portname, sizeof(struct lpfc_name));
6341 rn->un.topologyDisc.unitType = RNID_HBA;
6342 rn->un.topologyDisc.physPort = 0;
6343 rn->un.topologyDisc.attachedNodes = 0;
6347 rn->SpecificLen = 0;
6351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6352 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
6353 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6355 phba->fc_stat.elsXmitACC++;
6356 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6357 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6358 if (!elsiocb->ndlp) {
6359 lpfc_els_free_iocb(phba, elsiocb);
6363 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6364 if (rc == IOCB_ERROR) {
6365 lpfc_els_free_iocb(phba, elsiocb);
6374 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
6375 * @vport: pointer to a virtual N_Port data structure.
6376 * @iocb: pointer to the lpfc command iocb data structure.
6377 * @ndlp: pointer to a node-list data structure.
6382 lpfc_els_clear_rrq(struct lpfc_vport *vport,
6383 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
6385 struct lpfc_hba *phba = vport->phba;
6390 struct lpfc_node_rrq *prrq;
6393 pcmd = (uint8_t *)iocb->cmd_dmabuf->virt;
6394 pcmd += sizeof(uint32_t);
6395 rrq = (struct RRQ *)pcmd;
6396 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
6397 rxid = bf_get(rrq_rxid, rrq);
6399 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6400 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
6402 be32_to_cpu(bf_get(rrq_did, rrq)),
6403 bf_get(rrq_oxid, rrq),
6405 get_wqe_reqtag(iocb),
6406 get_job_ulpcontext(phba, iocb));
6408 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6409 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
6410 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
6411 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
6412 xri = bf_get(rrq_oxid, rrq);
6415 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
6417 lpfc_clr_rrq_active(phba, xri, prrq);
6422 * lpfc_els_rsp_echo_acc - Issue echo acc response
6423 * @vport: pointer to a virtual N_Port data structure.
6424 * @data: pointer to echo data to return in the accept.
6425 * @oldiocb: pointer to the original lpfc command iocb data structure.
6426 * @ndlp: pointer to a node-list data structure.
6429 * 0 - Successfully issued acc echo response
6430 * 1 - Failed to issue acc echo response
6433 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
6434 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6436 struct lpfc_hba *phba = vport->phba;
6437 IOCB_t *icmd, *oldcmd;
6438 union lpfc_wqe128 *wqe;
6439 struct lpfc_iocbq *elsiocb;
6445 if (phba->sli_rev == LPFC_SLI_REV4)
6446 cmdsize = oldiocb->wcqe_cmpl.total_data_placed;
6448 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
6450 /* The accumulated length can exceed the BPL_SIZE. For
6451 * now, use this as the limit
6453 if (cmdsize > LPFC_BPL_SIZE)
6454 cmdsize = LPFC_BPL_SIZE;
6455 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6456 ndlp->nlp_DID, ELS_CMD_ACC);
6460 if (phba->sli_rev == LPFC_SLI_REV4) {
6461 wqe = &elsiocb->wqe;
6462 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6463 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6464 ulp_context = get_job_ulpcontext(phba, elsiocb);
6465 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6466 get_job_rcvoxid(phba, oldiocb));
6468 icmd = &elsiocb->iocb;
6469 oldcmd = &oldiocb->iocb;
6470 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6471 ulp_context = elsiocb->iocb.ulpContext;
6472 icmd->unsli3.rcvsli3.ox_id =
6473 oldcmd->unsli3.rcvsli3.ox_id;
6476 /* Xmit ECHO ACC response tag <ulpIoTag> */
6477 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6478 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
6479 elsiocb->iotag, ulp_context);
6480 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6481 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6482 pcmd += sizeof(uint32_t);
6483 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
6485 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6486 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
6487 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6489 phba->fc_stat.elsXmitACC++;
6490 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6491 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6492 if (!elsiocb->ndlp) {
6493 lpfc_els_free_iocb(phba, elsiocb);
6497 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6498 if (rc == IOCB_ERROR) {
6499 lpfc_els_free_iocb(phba, elsiocb);
6508 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
6509 * @vport: pointer to a host virtual N_Port data structure.
6511 * This routine issues Address Discover (ADISC) ELS commands to those
6512 * N_Ports which are in node port recovery state and ADISC has not been issued
6513 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
6514 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
6515 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
6516 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
6517 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
6518 * IOCBs quit for later pick up. On the other hand, after walking through
6519 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
6520 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
6521 * no more ADISC need to be sent.
6524 * The number of N_Ports with adisc issued.
6527 lpfc_els_disc_adisc(struct lpfc_vport *vport)
6529 struct lpfc_nodelist *ndlp, *next_ndlp;
6532 /* go thru NPR nodes and issue any remaining ELS ADISCs */
6533 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6535 if (ndlp->nlp_state != NLP_STE_NPR_NODE ||
6536 !(ndlp->nlp_flag & NLP_NPR_ADISC))
6539 spin_lock_irq(&ndlp->lock);
6540 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
6541 spin_unlock_irq(&ndlp->lock);
6543 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
6544 /* This node was marked for ADISC but was not picked
6545 * for discovery. This is possible if the node was
6546 * missing in gidft response.
6548 * At time of marking node for ADISC, we skipped unreg
6551 lpfc_nlp_unreg_node(vport, ndlp);
6552 lpfc_unreg_rpi(vport, ndlp);
6556 ndlp->nlp_prev_state = ndlp->nlp_state;
6557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
6558 lpfc_issue_els_adisc(vport, ndlp, 0);
6560 vport->num_disc_nodes++;
6561 if (vport->num_disc_nodes >=
6562 vport->cfg_discovery_threads) {
6563 set_bit(FC_NLP_MORE, &vport->fc_flag);
6569 clear_bit(FC_NLP_MORE, &vport->fc_flag);
6574 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
6575 * @vport: pointer to a host virtual N_Port data structure.
6577 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
6578 * which are in node port recovery state, with a @vport. Each time an ELS
6579 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
6580 * the per @vport number of discover count (num_disc_nodes) shall be
6581 * incremented. If the num_disc_nodes reaches a pre-configured threshold
6582 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
6583 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
6584 * later pick up. On the other hand, after walking through all the ndlps with
6585 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
6586 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
6587 * PLOGI need to be sent.
6590 * The number of N_Ports with plogi issued.
6593 lpfc_els_disc_plogi(struct lpfc_vport *vport)
6595 struct lpfc_nodelist *ndlp, *next_ndlp;
6598 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
6599 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6600 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
6601 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
6602 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
6603 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
6604 ndlp->nlp_prev_state = ndlp->nlp_state;
6605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6606 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6608 vport->num_disc_nodes++;
6609 if (vport->num_disc_nodes >=
6610 vport->cfg_discovery_threads) {
6611 set_bit(FC_NLP_MORE, &vport->fc_flag);
6617 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6618 "6452 Discover PLOGI %d flag x%lx\n",
6619 sentplogi, vport->fc_flag);
6622 lpfc_set_disctmo(vport);
6624 clear_bit(FC_NLP_MORE, &vport->fc_flag);
6629 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
6633 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
6634 desc->payload.els_req = word0;
6635 desc->length = cpu_to_be32(sizeof(desc->payload));
6637 return sizeof(struct fc_rdp_link_service_desc);
6641 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
6642 uint8_t *page_a0, uint8_t *page_a2)
6644 uint16_t wavelength;
6645 uint16_t temperature;
6651 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
6652 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
6654 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
6656 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
6657 &page_a0[SSF_TRANSCEIVER_CODE_B4];
6658 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
6659 &page_a0[SSF_TRANSCEIVER_CODE_B5];
6661 if ((trasn_code_byte4->fc_sw_laser) ||
6662 (trasn_code_byte5->fc_sw_laser_sl) ||
6663 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
6664 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
6665 } else if (trasn_code_byte4->fc_lw_laser) {
6666 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
6667 page_a0[SSF_WAVELENGTH_B0];
6668 if (wavelength == SFP_WAVELENGTH_LC1310)
6669 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
6670 if (wavelength == SFP_WAVELENGTH_LL1550)
6671 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
6673 /* check if its SFP+ */
6674 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
6675 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
6676 << SFP_FLAG_CT_SHIFT;
6678 /* check if its OPTICAL */
6679 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
6680 SFP_FLAG_IS_OPTICAL_PORT : 0)
6681 << SFP_FLAG_IS_OPTICAL_SHIFT;
6683 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
6684 page_a2[SFF_TEMPERATURE_B0]);
6685 vcc = (page_a2[SFF_VCC_B1] << 8 |
6686 page_a2[SFF_VCC_B0]);
6687 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
6688 page_a2[SFF_TXPOWER_B0]);
6689 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
6690 page_a2[SFF_TX_BIAS_CURRENT_B0]);
6691 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
6692 page_a2[SFF_RXPOWER_B0]);
6693 desc->sfp_info.temperature = cpu_to_be16(temperature);
6694 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
6695 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
6696 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
6697 desc->sfp_info.vcc = cpu_to_be16(vcc);
6699 desc->sfp_info.flags = cpu_to_be16(flag);
6700 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
6702 return sizeof(struct fc_rdp_sfp_desc);
6706 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
6711 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
6713 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
6715 desc->info.port_type = cpu_to_be32(type);
6717 desc->info.link_status.link_failure_cnt =
6718 cpu_to_be32(stat->linkFailureCnt);
6719 desc->info.link_status.loss_of_synch_cnt =
6720 cpu_to_be32(stat->lossSyncCnt);
6721 desc->info.link_status.loss_of_signal_cnt =
6722 cpu_to_be32(stat->lossSignalCnt);
6723 desc->info.link_status.primitive_seq_proto_err =
6724 cpu_to_be32(stat->primSeqErrCnt);
6725 desc->info.link_status.invalid_trans_word =
6726 cpu_to_be32(stat->invalidXmitWord);
6727 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
6729 desc->length = cpu_to_be32(sizeof(desc->info));
6731 return sizeof(struct fc_rdp_link_error_status_desc);
6735 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
6736 struct lpfc_vport *vport)
6740 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
6742 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
6743 (vport->fc_sparam.cmn.bbCreditMsb << 8);
6744 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
6745 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
6746 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
6747 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
6748 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
6750 desc->bbc_info.attached_port_bbc = 0;
6753 desc->bbc_info.rtt = 0;
6754 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
6756 return sizeof(struct fc_rdp_bbc_desc);
6760 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
6761 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
6765 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6767 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
6768 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
6769 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
6770 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
6772 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6773 flags |= RDP_OET_HIGH_ALARM;
6774 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6775 flags |= RDP_OET_LOW_ALARM;
6776 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6777 flags |= RDP_OET_HIGH_WARNING;
6778 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6779 flags |= RDP_OET_LOW_WARNING;
6781 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
6782 desc->oed_info.function_flags = cpu_to_be32(flags);
6783 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6784 return sizeof(struct fc_rdp_oed_sfp_desc);
6788 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
6789 struct fc_rdp_oed_sfp_desc *desc,
6794 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6796 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
6797 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
6798 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
6799 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
6801 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6802 flags |= RDP_OET_HIGH_ALARM;
6803 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6804 flags |= RDP_OET_LOW_ALARM;
6805 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6806 flags |= RDP_OET_HIGH_WARNING;
6807 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6808 flags |= RDP_OET_LOW_WARNING;
6810 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
6811 desc->oed_info.function_flags = cpu_to_be32(flags);
6812 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6813 return sizeof(struct fc_rdp_oed_sfp_desc);
6817 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
6818 struct fc_rdp_oed_sfp_desc *desc,
6823 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6825 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
6826 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
6827 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
6828 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
6830 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6831 flags |= RDP_OET_HIGH_ALARM;
6832 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
6833 flags |= RDP_OET_LOW_ALARM;
6834 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6835 flags |= RDP_OET_HIGH_WARNING;
6836 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
6837 flags |= RDP_OET_LOW_WARNING;
6839 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
6840 desc->oed_info.function_flags = cpu_to_be32(flags);
6841 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6842 return sizeof(struct fc_rdp_oed_sfp_desc);
6846 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
6847 struct fc_rdp_oed_sfp_desc *desc,
6852 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6854 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
6855 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
6856 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
6857 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
6859 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6860 flags |= RDP_OET_HIGH_ALARM;
6861 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
6862 flags |= RDP_OET_LOW_ALARM;
6863 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6864 flags |= RDP_OET_HIGH_WARNING;
6865 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
6866 flags |= RDP_OET_LOW_WARNING;
6868 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
6869 desc->oed_info.function_flags = cpu_to_be32(flags);
6870 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6871 return sizeof(struct fc_rdp_oed_sfp_desc);
6876 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
6877 struct fc_rdp_oed_sfp_desc *desc,
6882 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6884 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
6885 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
6886 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
6887 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
6889 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6890 flags |= RDP_OET_HIGH_ALARM;
6891 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
6892 flags |= RDP_OET_LOW_ALARM;
6893 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6894 flags |= RDP_OET_HIGH_WARNING;
6895 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
6896 flags |= RDP_OET_LOW_WARNING;
6898 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
6899 desc->oed_info.function_flags = cpu_to_be32(flags);
6900 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6901 return sizeof(struct fc_rdp_oed_sfp_desc);
6905 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
6906 uint8_t *page_a0, struct lpfc_vport *vport)
6908 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
6909 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
6910 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
6911 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
6912 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
6913 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
6914 desc->length = cpu_to_be32(sizeof(desc->opd_info));
6915 return sizeof(struct fc_rdp_opd_sfp_desc);
6919 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
6921 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
6923 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
6925 desc->info.CorrectedBlocks =
6926 cpu_to_be32(stat->fecCorrBlkCount);
6927 desc->info.UncorrectableBlocks =
6928 cpu_to_be32(stat->fecUncorrBlkCount);
6930 desc->length = cpu_to_be32(sizeof(desc->info));
6932 return sizeof(struct fc_fec_rdp_desc);
6936 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
6938 uint16_t rdp_cap = 0;
6941 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
6943 switch (phba->fc_linkspeed) {
6944 case LPFC_LINK_SPEED_1GHZ:
6945 rdp_speed = RDP_PS_1GB;
6947 case LPFC_LINK_SPEED_2GHZ:
6948 rdp_speed = RDP_PS_2GB;
6950 case LPFC_LINK_SPEED_4GHZ:
6951 rdp_speed = RDP_PS_4GB;
6953 case LPFC_LINK_SPEED_8GHZ:
6954 rdp_speed = RDP_PS_8GB;
6956 case LPFC_LINK_SPEED_10GHZ:
6957 rdp_speed = RDP_PS_10GB;
6959 case LPFC_LINK_SPEED_16GHZ:
6960 rdp_speed = RDP_PS_16GB;
6962 case LPFC_LINK_SPEED_32GHZ:
6963 rdp_speed = RDP_PS_32GB;
6965 case LPFC_LINK_SPEED_64GHZ:
6966 rdp_speed = RDP_PS_64GB;
6968 case LPFC_LINK_SPEED_128GHZ:
6969 rdp_speed = RDP_PS_128GB;
6971 case LPFC_LINK_SPEED_256GHZ:
6972 rdp_speed = RDP_PS_256GB;
6975 rdp_speed = RDP_PS_UNKNOWN;
6979 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
6981 if (phba->lmt & LMT_256Gb)
6982 rdp_cap |= RDP_PS_256GB;
6983 if (phba->lmt & LMT_128Gb)
6984 rdp_cap |= RDP_PS_128GB;
6985 if (phba->lmt & LMT_64Gb)
6986 rdp_cap |= RDP_PS_64GB;
6987 if (phba->lmt & LMT_32Gb)
6988 rdp_cap |= RDP_PS_32GB;
6989 if (phba->lmt & LMT_16Gb)
6990 rdp_cap |= RDP_PS_16GB;
6991 if (phba->lmt & LMT_10Gb)
6992 rdp_cap |= RDP_PS_10GB;
6993 if (phba->lmt & LMT_8Gb)
6994 rdp_cap |= RDP_PS_8GB;
6995 if (phba->lmt & LMT_4Gb)
6996 rdp_cap |= RDP_PS_4GB;
6997 if (phba->lmt & LMT_2Gb)
6998 rdp_cap |= RDP_PS_2GB;
6999 if (phba->lmt & LMT_1Gb)
7000 rdp_cap |= RDP_PS_1GB;
7003 rdp_cap = RDP_CAP_UNKNOWN;
7004 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
7005 rdp_cap |= RDP_CAP_USER_CONFIGURED;
7007 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
7008 desc->length = cpu_to_be32(sizeof(desc->info));
7009 return sizeof(struct fc_rdp_port_speed_desc);
7013 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
7014 struct lpfc_vport *vport)
7017 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
7019 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
7020 sizeof(desc->port_names.wwnn));
7022 memcpy(desc->port_names.wwpn, &vport->fc_portname,
7023 sizeof(desc->port_names.wwpn));
7025 desc->length = cpu_to_be32(sizeof(desc->port_names));
7026 return sizeof(struct fc_rdp_port_name_desc);
7030 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
7031 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7034 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
7035 if (test_bit(FC_FABRIC, &vport->fc_flag)) {
7036 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
7037 sizeof(desc->port_names.wwnn));
7039 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
7040 sizeof(desc->port_names.wwpn));
7041 } else { /* Point to Point */
7042 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
7043 sizeof(desc->port_names.wwnn));
7045 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
7046 sizeof(desc->port_names.wwpn));
7049 desc->length = cpu_to_be32(sizeof(desc->port_names));
7050 return sizeof(struct fc_rdp_port_name_desc);
7054 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
7057 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
7058 struct lpfc_vport *vport = ndlp->vport;
7059 struct lpfc_iocbq *elsiocb;
7060 struct ulp_bde64 *bpl;
7062 union lpfc_wqe128 *wqe;
7064 struct ls_rjt *stat;
7065 struct fc_rdp_res_frame *rdp_res;
7066 uint32_t cmdsize, len;
7071 if (status != SUCCESS)
7074 /* This will change once we know the true size of the RDP payload */
7075 cmdsize = sizeof(struct fc_rdp_res_frame);
7077 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
7078 lpfc_max_els_tries, rdp_context->ndlp,
7079 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
7081 goto free_rdp_context;
7083 ulp_context = get_job_ulpcontext(phba, elsiocb);
7084 if (phba->sli_rev == LPFC_SLI_REV4) {
7085 wqe = &elsiocb->wqe;
7086 /* ox-id of the frame */
7087 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7088 rdp_context->ox_id);
7089 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
7090 rdp_context->rx_id);
7092 icmd = &elsiocb->iocb;
7093 icmd->ulpContext = rdp_context->rx_id;
7094 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
7097 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7098 "2171 Xmit RDP response tag x%x xri x%x, "
7099 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
7100 elsiocb->iotag, ulp_context,
7101 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7103 rdp_res = (struct fc_rdp_res_frame *)elsiocb->cmd_dmabuf->virt;
7104 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7105 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
7106 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7108 /* Update Alarm and Warning */
7109 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
7110 phba->sfp_alarm |= *flag_ptr;
7111 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
7112 phba->sfp_warning |= *flag_ptr;
7114 /* For RDP payload */
7116 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
7117 (len + pcmd), ELS_CMD_RDP);
7119 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
7120 rdp_context->page_a0, rdp_context->page_a2);
7121 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
7123 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
7124 (len + pcmd), &rdp_context->link_stat);
7125 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
7126 (len + pcmd), vport);
7127 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
7128 (len + pcmd), vport, ndlp);
7129 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
7130 &rdp_context->link_stat);
7131 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
7132 &rdp_context->link_stat, vport);
7133 len += lpfc_rdp_res_oed_temp_desc(phba,
7134 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7135 rdp_context->page_a2);
7136 len += lpfc_rdp_res_oed_voltage_desc(phba,
7137 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7138 rdp_context->page_a2);
7139 len += lpfc_rdp_res_oed_txbias_desc(phba,
7140 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7141 rdp_context->page_a2);
7142 len += lpfc_rdp_res_oed_txpower_desc(phba,
7143 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7144 rdp_context->page_a2);
7145 len += lpfc_rdp_res_oed_rxpower_desc(phba,
7146 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7147 rdp_context->page_a2);
7148 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
7149 rdp_context->page_a0, vport);
7151 rdp_res->length = cpu_to_be32(len - 8);
7152 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7154 /* Now that we know the true size of the payload, update the BPL */
7155 bpl = (struct ulp_bde64 *)elsiocb->bpl_dmabuf->virt;
7156 bpl->tus.f.bdeSize = len;
7157 bpl->tus.f.bdeFlags = 0;
7158 bpl->tus.w = le32_to_cpu(bpl->tus.w);
7160 phba->fc_stat.elsXmitACC++;
7161 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7162 if (!elsiocb->ndlp) {
7163 lpfc_els_free_iocb(phba, elsiocb);
7164 goto free_rdp_context;
7167 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7168 if (rc == IOCB_ERROR) {
7169 lpfc_els_free_iocb(phba, elsiocb);
7173 goto free_rdp_context;
7176 cmdsize = 2 * sizeof(uint32_t);
7177 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
7178 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
7180 goto free_rdp_context;
7182 if (phba->sli_rev == LPFC_SLI_REV4) {
7183 wqe = &elsiocb->wqe;
7184 /* ox-id of the frame */
7185 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7186 rdp_context->ox_id);
7187 bf_set(wqe_ctxt_tag,
7188 &wqe->xmit_els_rsp.wqe_com,
7189 rdp_context->rx_id);
7191 icmd = &elsiocb->iocb;
7192 icmd->ulpContext = rdp_context->rx_id;
7193 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
7196 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7198 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
7199 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7200 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7202 phba->fc_stat.elsXmitLSRJT++;
7203 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7204 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7205 if (!elsiocb->ndlp) {
7206 lpfc_els_free_iocb(phba, elsiocb);
7207 goto free_rdp_context;
7210 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7211 if (rc == IOCB_ERROR) {
7212 lpfc_els_free_iocb(phba, elsiocb);
7217 /* This reference put is for the original unsolicited RDP. If the
7218 * prep failed, there is no reference to remove.
7225 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
7227 LPFC_MBOXQ_t *mbox = NULL;
7230 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7232 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
7233 "7105 failed to allocate mailbox memory");
7237 if (lpfc_sli4_dump_page_a0(phba, mbox))
7239 mbox->vport = rdp_context->ndlp->vport;
7240 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
7241 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
7242 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7243 if (rc == MBX_NOT_FINISHED) {
7244 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
7251 mempool_free(mbox, phba->mbox_mem_pool);
7255 int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
7256 struct lpfc_rdp_context *rdp_context)
7258 LPFC_MBOXQ_t *mbox = NULL;
7260 struct lpfc_dmabuf *mp;
7261 struct lpfc_dmabuf *mpsave;
7265 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7267 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
7268 "7205 failed to allocate mailbox memory");
7272 if (lpfc_sli4_dump_page_a0(phba, mbox))
7277 if (phba->sli_rev < LPFC_SLI_REV4) {
7279 mb->un.varDmp.cv = 1;
7280 mb->un.varDmp.co = 1;
7281 mb->un.varWords[2] = 0;
7282 mb->un.varWords[3] = DMP_SFF_PAGE_A0_SIZE / 4;
7283 mb->un.varWords[4] = 0;
7284 mb->un.varWords[5] = 0;
7285 mb->un.varWords[6] = 0;
7286 mb->un.varWords[7] = 0;
7287 mb->un.varWords[8] = 0;
7288 mb->un.varWords[9] = 0;
7289 mb->un.varWords[10] = 0;
7290 mbox->in_ext_byte_len = DMP_SFF_PAGE_A0_SIZE;
7291 mbox->out_ext_byte_len = DMP_SFF_PAGE_A0_SIZE;
7292 mbox->mbox_offset_word = 5;
7293 mbox->ctx_buf = virt;
7295 bf_set(lpfc_mbx_memory_dump_type3_length,
7296 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
7297 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
7298 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
7300 mbox->vport = phba->pport;
7301 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
7303 rc = lpfc_sli_issue_mbox_wait(phba, mbox, 30);
7304 if (rc == MBX_NOT_FINISHED) {
7309 if (phba->sli_rev == LPFC_SLI_REV4)
7310 mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
7314 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) {
7319 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
7320 DMP_SFF_PAGE_A0_SIZE);
7322 memset(mbox, 0, sizeof(*mbox));
7323 memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
7324 INIT_LIST_HEAD(&mp->list);
7326 /* save address for completion */
7328 mbox->vport = phba->pport;
7330 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
7331 bf_set(lpfc_mbx_memory_dump_type3_type,
7332 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
7333 bf_set(lpfc_mbx_memory_dump_type3_link,
7334 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
7335 bf_set(lpfc_mbx_memory_dump_type3_page_no,
7336 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
7337 if (phba->sli_rev < LPFC_SLI_REV4) {
7339 mb->un.varDmp.cv = 1;
7340 mb->un.varDmp.co = 1;
7341 mb->un.varWords[2] = 0;
7342 mb->un.varWords[3] = DMP_SFF_PAGE_A2_SIZE / 4;
7343 mb->un.varWords[4] = 0;
7344 mb->un.varWords[5] = 0;
7345 mb->un.varWords[6] = 0;
7346 mb->un.varWords[7] = 0;
7347 mb->un.varWords[8] = 0;
7348 mb->un.varWords[9] = 0;
7349 mb->un.varWords[10] = 0;
7350 mbox->in_ext_byte_len = DMP_SFF_PAGE_A2_SIZE;
7351 mbox->out_ext_byte_len = DMP_SFF_PAGE_A2_SIZE;
7352 mbox->mbox_offset_word = 5;
7353 mbox->ctx_buf = virt;
7355 bf_set(lpfc_mbx_memory_dump_type3_length,
7356 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
7357 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
7358 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
7361 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
7362 rc = lpfc_sli_issue_mbox_wait(phba, mbox, 30);
7363 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) {
7369 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
7370 DMP_SFF_PAGE_A2_SIZE);
7373 mbox->ctx_buf = mpsave;
7374 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
7379 mempool_free(mbox, phba->mbox_mem_pool);
7384 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
7385 * @vport: pointer to a host virtual N_Port data structure.
7386 * @cmdiocb: pointer to lpfc command iocb data structure.
7387 * @ndlp: pointer to a node-list data structure.
7389 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
7390 * IOCB. First, the payload of the unsolicited RDP is checked.
7391 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
7392 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
7393 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
7394 * gather all data and send RDP response.
7397 * 0 - Sent the acc response
7398 * 1 - Sent the reject response.
7401 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7402 struct lpfc_nodelist *ndlp)
7404 struct lpfc_hba *phba = vport->phba;
7405 struct lpfc_dmabuf *pcmd;
7406 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
7407 struct fc_rdp_req_frame *rdp_req;
7408 struct lpfc_rdp_context *rdp_context;
7409 union lpfc_wqe128 *cmd = NULL;
7412 if (phba->sli_rev < LPFC_SLI_REV4 ||
7413 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7414 LPFC_SLI_INTF_IF_TYPE_2) {
7415 rjt_err = LSRJT_UNABLE_TPC;
7416 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7420 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
7421 rjt_err = LSRJT_UNABLE_TPC;
7422 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7426 pcmd = cmdiocb->cmd_dmabuf;
7427 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
7429 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7430 "2422 ELS RDP Request "
7431 "dec len %d tag x%x port_id %d len %d\n",
7432 be32_to_cpu(rdp_req->rdp_des_length),
7433 be32_to_cpu(rdp_req->nport_id_desc.tag),
7434 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
7435 be32_to_cpu(rdp_req->nport_id_desc.length));
7437 if (sizeof(struct fc_rdp_nport_desc) !=
7438 be32_to_cpu(rdp_req->rdp_des_length))
7440 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
7442 if (RDP_NPORT_ID_SIZE !=
7443 be32_to_cpu(rdp_req->nport_id_desc.length))
7445 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
7447 rjt_err = LSRJT_UNABLE_TPC;
7451 cmd = &cmdiocb->wqe;
7452 rdp_context->ndlp = lpfc_nlp_get(ndlp);
7453 if (!rdp_context->ndlp) {
7455 rjt_err = LSRJT_UNABLE_TPC;
7458 rdp_context->ox_id = bf_get(wqe_rcvoxid,
7459 &cmd->xmit_els_rsp.wqe_com);
7460 rdp_context->rx_id = bf_get(wqe_ctxt_tag,
7461 &cmd->xmit_els_rsp.wqe_com);
7462 rdp_context->cmpl = lpfc_els_rdp_cmpl;
7463 if (lpfc_get_rdp_info(phba, rdp_context)) {
7464 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
7465 "2423 Unable to send mailbox");
7467 rjt_err = LSRJT_UNABLE_TPC;
7475 rjt_err = LSRJT_LOGICAL_ERR;
7478 memset(&stat, 0, sizeof(stat));
7479 stat.un.b.lsRjtRsnCode = rjt_err;
7480 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
7481 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7487 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7491 union lpfc_wqe128 *wqe;
7493 struct lpfc_iocbq *elsiocb;
7494 struct lpfc_nodelist *ndlp;
7495 struct ls_rjt *stat;
7496 union lpfc_sli4_cfg_shdr *shdr;
7497 struct lpfc_lcb_context *lcb_context;
7498 struct fc_lcb_res_frame *lcb_res;
7499 uint32_t cmdsize, shdr_status, shdr_add_status;
7503 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
7504 ndlp = lcb_context->ndlp;
7505 pmb->ctx_ndlp = NULL;
7506 pmb->ctx_buf = NULL;
7508 shdr = (union lpfc_sli4_cfg_shdr *)
7509 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
7510 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7511 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7513 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
7514 "0194 SET_BEACON_CONFIG mailbox "
7515 "completed with status x%x add_status x%x,"
7516 " mbx status x%x\n",
7517 shdr_status, shdr_add_status, mb->mbxStatus);
7519 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
7520 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
7521 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
7522 mempool_free(pmb, phba->mbox_mem_pool);
7526 mempool_free(pmb, phba->mbox_mem_pool);
7527 cmdsize = sizeof(struct fc_lcb_res_frame);
7528 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7529 lpfc_max_els_tries, ndlp,
7530 ndlp->nlp_DID, ELS_CMD_ACC);
7532 /* Decrement the ndlp reference count from previous mbox command */
7536 goto free_lcb_context;
7538 lcb_res = (struct fc_lcb_res_frame *)elsiocb->cmd_dmabuf->virt;
7540 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
7542 if (phba->sli_rev == LPFC_SLI_REV4) {
7543 wqe = &elsiocb->wqe;
7544 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7545 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7546 lcb_context->ox_id);
7548 icmd = &elsiocb->iocb;
7549 icmd->ulpContext = lcb_context->rx_id;
7550 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7553 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7554 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
7555 lcb_res->lcb_sub_command = lcb_context->sub_command;
7556 lcb_res->lcb_type = lcb_context->type;
7557 lcb_res->capability = lcb_context->capability;
7558 lcb_res->lcb_frequency = lcb_context->frequency;
7559 lcb_res->lcb_duration = lcb_context->duration;
7560 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7561 phba->fc_stat.elsXmitACC++;
7563 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7564 if (!elsiocb->ndlp) {
7565 lpfc_els_free_iocb(phba, elsiocb);
7569 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7570 if (rc == IOCB_ERROR) {
7571 lpfc_els_free_iocb(phba, elsiocb);
7579 cmdsize = sizeof(struct fc_lcb_res_frame);
7580 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7581 lpfc_max_els_tries, ndlp,
7582 ndlp->nlp_DID, ELS_CMD_LS_RJT);
7585 goto free_lcb_context;
7587 if (phba->sli_rev == LPFC_SLI_REV4) {
7588 wqe = &elsiocb->wqe;
7589 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7590 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7591 lcb_context->ox_id);
7593 icmd = &elsiocb->iocb;
7594 icmd->ulpContext = lcb_context->rx_id;
7595 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7598 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7600 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
7601 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7602 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7604 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
7605 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
7607 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7608 phba->fc_stat.elsXmitLSRJT++;
7609 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7610 if (!elsiocb->ndlp) {
7611 lpfc_els_free_iocb(phba, elsiocb);
7612 goto free_lcb_context;
7615 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7616 if (rc == IOCB_ERROR) {
7617 lpfc_els_free_iocb(phba, elsiocb);
7625 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
7626 struct lpfc_lcb_context *lcb_context,
7627 uint32_t beacon_state)
7629 struct lpfc_hba *phba = vport->phba;
7630 union lpfc_sli4_cfg_shdr *cfg_shdr;
7631 LPFC_MBOXQ_t *mbox = NULL;
7635 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7639 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
7640 len = sizeof(struct lpfc_mbx_set_beacon_config) -
7641 sizeof(struct lpfc_sli4_cfg_mhdr);
7642 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7643 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
7644 LPFC_SLI4_MBX_EMBED);
7645 mbox->ctx_ndlp = (void *)lcb_context;
7646 mbox->vport = phba->pport;
7647 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
7648 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
7649 phba->sli4_hba.physical_port);
7650 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
7652 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
7655 * Check bv1s bit before issuing the mailbox
7656 * if bv1s == 1, LCB V1 supported
7657 * else, LCB V0 supported
7660 if (phba->sli4_hba.pc_sli4_params.bv1s) {
7661 /* COMMON_SET_BEACON_CONFIG_V1 */
7662 cfg_shdr->request.word9 = BEACON_VERSION_V1;
7663 lcb_context->capability |= LCB_CAPABILITY_DURATION;
7664 bf_set(lpfc_mbx_set_beacon_port_type,
7665 &mbox->u.mqe.un.beacon_config, 0);
7666 bf_set(lpfc_mbx_set_beacon_duration_v1,
7667 &mbox->u.mqe.un.beacon_config,
7668 be16_to_cpu(lcb_context->duration));
7670 /* COMMON_SET_BEACON_CONFIG_V0 */
7671 if (be16_to_cpu(lcb_context->duration) != 0) {
7672 mempool_free(mbox, phba->mbox_mem_pool);
7675 cfg_shdr->request.word9 = BEACON_VERSION_V0;
7676 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
7677 bf_set(lpfc_mbx_set_beacon_state,
7678 &mbox->u.mqe.un.beacon_config, beacon_state);
7679 bf_set(lpfc_mbx_set_beacon_port_type,
7680 &mbox->u.mqe.un.beacon_config, 1);
7681 bf_set(lpfc_mbx_set_beacon_duration,
7682 &mbox->u.mqe.un.beacon_config,
7683 be16_to_cpu(lcb_context->duration));
7686 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7687 if (rc == MBX_NOT_FINISHED) {
7688 mempool_free(mbox, phba->mbox_mem_pool);
7697 * lpfc_els_rcv_lcb - Process an unsolicited LCB
7698 * @vport: pointer to a host virtual N_Port data structure.
7699 * @cmdiocb: pointer to lpfc command iocb data structure.
7700 * @ndlp: pointer to a node-list data structure.
7702 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
7703 * First, the payload of the unsolicited LCB is checked.
7704 * Then based on Subcommand beacon will either turn on or off.
7707 * 0 - Sent the acc response
7708 * 1 - Sent the reject response.
7711 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7712 struct lpfc_nodelist *ndlp)
7714 struct lpfc_hba *phba = vport->phba;
7715 struct lpfc_dmabuf *pcmd;
7717 struct fc_lcb_request_frame *beacon;
7718 struct lpfc_lcb_context *lcb_context;
7719 u8 state, rjt_err = 0;
7722 pcmd = cmdiocb->cmd_dmabuf;
7723 lp = (uint8_t *)pcmd->virt;
7724 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
7726 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7727 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
7728 "type x%x frequency %x duration x%x\n",
7729 lp[0], lp[1], lp[2],
7730 beacon->lcb_command,
7731 beacon->lcb_sub_command,
7733 beacon->lcb_frequency,
7734 be16_to_cpu(beacon->lcb_duration));
7736 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
7737 beacon->lcb_sub_command != LPFC_LCB_OFF) {
7738 rjt_err = LSRJT_CMD_UNSUPPORTED;
7742 if (phba->sli_rev < LPFC_SLI_REV4 ||
7743 phba->hba_flag & HBA_FCOE_MODE ||
7744 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7745 LPFC_SLI_INTF_IF_TYPE_2)) {
7746 rjt_err = LSRJT_CMD_UNSUPPORTED;
7750 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
7752 rjt_err = LSRJT_UNABLE_TPC;
7756 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
7757 lcb_context->sub_command = beacon->lcb_sub_command;
7758 lcb_context->capability = 0;
7759 lcb_context->type = beacon->lcb_type;
7760 lcb_context->frequency = beacon->lcb_frequency;
7761 lcb_context->duration = beacon->lcb_duration;
7762 lcb_context->ox_id = get_job_rcvoxid(phba, cmdiocb);
7763 lcb_context->rx_id = get_job_ulpcontext(phba, cmdiocb);
7764 lcb_context->ndlp = lpfc_nlp_get(ndlp);
7765 if (!lcb_context->ndlp) {
7766 rjt_err = LSRJT_UNABLE_TPC;
7770 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
7771 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
7772 "0193 failed to send mail box");
7774 rjt_err = LSRJT_UNABLE_TPC;
7782 memset(&stat, 0, sizeof(stat));
7783 stat.un.b.lsRjtRsnCode = rjt_err;
7784 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7790 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
7791 * @vport: pointer to a host virtual N_Port data structure.
7793 * This routine cleans up any Registration State Change Notification
7794 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
7795 * @vport together with the host_lock is used to prevent multiple thread
7796 * trying to access the RSCN array on a same @vport at the same time.
7799 lpfc_els_flush_rscn(struct lpfc_vport *vport)
7801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7802 struct lpfc_hba *phba = vport->phba;
7805 spin_lock_irq(shost->host_lock);
7806 if (vport->fc_rscn_flush) {
7807 /* Another thread is walking fc_rscn_id_list on this vport */
7808 spin_unlock_irq(shost->host_lock);
7811 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
7812 vport->fc_rscn_flush = 1;
7813 spin_unlock_irq(shost->host_lock);
7815 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7816 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
7817 vport->fc_rscn_id_list[i] = NULL;
7819 clear_bit(FC_RSCN_MODE, &vport->fc_flag);
7820 clear_bit(FC_RSCN_DISCOVERY, &vport->fc_flag);
7821 spin_lock_irq(shost->host_lock);
7822 vport->fc_rscn_id_cnt = 0;
7823 spin_unlock_irq(shost->host_lock);
7824 lpfc_can_disctmo(vport);
7825 /* Indicate we are done walking this fc_rscn_id_list */
7826 vport->fc_rscn_flush = 0;
7830 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
7831 * @vport: pointer to a host virtual N_Port data structure.
7832 * @did: remote destination port identifier.
7834 * This routine checks whether there is any pending Registration State
7835 * Configuration Notification (RSCN) to a @did on @vport.
7838 * None zero - The @did matched with a pending rscn
7839 * 0 - not able to match @did with a pending rscn
7842 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
7847 uint32_t payload_len, i;
7848 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7850 ns_did.un.word = did;
7852 /* Never match fabric nodes for RSCNs */
7853 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7856 /* If we are doing a FULL RSCN rediscovery, match everything */
7857 if (test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag))
7860 spin_lock_irq(shost->host_lock);
7861 if (vport->fc_rscn_flush) {
7862 /* Another thread is walking fc_rscn_id_list on this vport */
7863 spin_unlock_irq(shost->host_lock);
7866 /* Indicate we are walking fc_rscn_id_list on this vport */
7867 vport->fc_rscn_flush = 1;
7868 spin_unlock_irq(shost->host_lock);
7869 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7870 lp = vport->fc_rscn_id_list[i]->virt;
7871 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7872 payload_len -= sizeof(uint32_t); /* take off word 0 */
7873 while (payload_len) {
7874 rscn_did.un.word = be32_to_cpu(*lp++);
7875 payload_len -= sizeof(uint32_t);
7876 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
7877 case RSCN_ADDRESS_FORMAT_PORT:
7878 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7879 && (ns_did.un.b.area == rscn_did.un.b.area)
7880 && (ns_did.un.b.id == rscn_did.un.b.id))
7881 goto return_did_out;
7883 case RSCN_ADDRESS_FORMAT_AREA:
7884 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7885 && (ns_did.un.b.area == rscn_did.un.b.area))
7886 goto return_did_out;
7888 case RSCN_ADDRESS_FORMAT_DOMAIN:
7889 if (ns_did.un.b.domain == rscn_did.un.b.domain)
7890 goto return_did_out;
7892 case RSCN_ADDRESS_FORMAT_FABRIC:
7893 goto return_did_out;
7897 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7898 vport->fc_rscn_flush = 0;
7901 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7902 vport->fc_rscn_flush = 0;
7907 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
7908 * @vport: pointer to a host virtual N_Port data structure.
7910 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
7911 * state machine for a @vport's nodes that are with pending RSCN (Registration
7912 * State Change Notification).
7915 * 0 - Successful (currently alway return 0)
7918 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
7920 struct lpfc_nodelist *ndlp = NULL, *n;
7922 /* Move all affected nodes by pending RSCNs to NPR state. */
7923 list_for_each_entry_safe(ndlp, n, &vport->fc_nodes, nlp_listp) {
7924 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
7925 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
7928 /* NVME Target mode does not do RSCN Recovery. */
7929 if (vport->phba->nvmet_support)
7932 /* If we are in the process of doing discovery on this
7933 * NPort, let it continue on its own.
7935 switch (ndlp->nlp_state) {
7936 case NLP_STE_PLOGI_ISSUE:
7937 case NLP_STE_ADISC_ISSUE:
7938 case NLP_STE_REG_LOGIN_ISSUE:
7939 case NLP_STE_PRLI_ISSUE:
7940 case NLP_STE_LOGO_ISSUE:
7944 lpfc_disc_state_machine(vport, ndlp, NULL,
7945 NLP_EVT_DEVICE_RECOVERY);
7946 lpfc_cancel_retry_delay_tmo(vport, ndlp);
7952 * lpfc_send_rscn_event - Send an RSCN event to management application
7953 * @vport: pointer to a host virtual N_Port data structure.
7954 * @cmdiocb: pointer to lpfc command iocb data structure.
7956 * lpfc_send_rscn_event sends an RSCN netlink event to management
7960 lpfc_send_rscn_event(struct lpfc_vport *vport,
7961 struct lpfc_iocbq *cmdiocb)
7963 struct lpfc_dmabuf *pcmd;
7964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7965 uint32_t *payload_ptr;
7966 uint32_t payload_len;
7967 struct lpfc_rscn_event_header *rscn_event_data;
7969 pcmd = cmdiocb->cmd_dmabuf;
7970 payload_ptr = (uint32_t *) pcmd->virt;
7971 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
7973 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
7974 payload_len, GFP_KERNEL);
7975 if (!rscn_event_data) {
7976 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7977 "0147 Failed to allocate memory for RSCN event\n");
7980 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
7981 rscn_event_data->payload_length = payload_len;
7982 memcpy(rscn_event_data->rscn_payload, payload_ptr,
7985 fc_host_post_vendor_event(shost,
7986 fc_get_event_number(),
7987 sizeof(struct lpfc_rscn_event_header) + payload_len,
7988 (char *)rscn_event_data,
7991 kfree(rscn_event_data);
7995 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
7996 * @vport: pointer to a host virtual N_Port data structure.
7997 * @cmdiocb: pointer to lpfc command iocb data structure.
7998 * @ndlp: pointer to a node-list data structure.
8000 * This routine processes an unsolicited RSCN (Registration State Change
8001 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
8002 * to invoke fc_host_post_event() routine to the FC transport layer. If the
8003 * discover state machine is about to begin discovery, it just accepts the
8004 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
8005 * contains N_Port IDs for other vports on this HBA, it just accepts the
8006 * RSCN and ignore processing it. If the state machine is in the recovery
8007 * state, the fc_rscn_id_list of this @vport is walked and the
8008 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
8009 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
8010 * routine is invoked to handle the RSCN event.
8013 * 0 - Just sent the acc response
8014 * 1 - Sent the acc response and waited for name server completion
8017 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8018 struct lpfc_nodelist *ndlp)
8020 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8021 struct lpfc_hba *phba = vport->phba;
8022 struct lpfc_dmabuf *pcmd;
8023 uint32_t *lp, *datap;
8024 uint32_t payload_len, length, nportid, *cmd;
8026 int rscn_id = 0, hba_id = 0;
8029 pcmd = cmdiocb->cmd_dmabuf;
8030 lp = (uint32_t *) pcmd->virt;
8032 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
8033 payload_len -= sizeof(uint32_t); /* take off word 0 */
8035 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8036 "0214 RSCN received Data: x%lx x%x x%x x%x\n",
8037 vport->fc_flag, payload_len, *lp,
8038 vport->fc_rscn_id_cnt);
8040 /* Send an RSCN event to the management application */
8041 lpfc_send_rscn_event(vport, cmdiocb);
8043 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
8044 fc_host_post_event(shost, fc_get_event_number(),
8045 FCH_EVT_RSCN, lp[i]);
8047 /* Check if RSCN is coming from a direct-connected remote NPort */
8048 if (test_bit(FC_PT2PT, &vport->fc_flag)) {
8049 /* If so, just ACC it, no other action needed for now */
8050 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8051 "2024 pt2pt RSCN %08x Data: x%lx x%x\n",
8052 *lp, vport->fc_flag, payload_len);
8053 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8055 /* Check to see if we need to NVME rescan this target
8058 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
8059 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
8060 lpfc_nvme_rescan_port(vport, ndlp);
8064 /* If we are about to begin discovery, just ACC the RSCN.
8065 * Discovery processing will satisfy it.
8067 if (vport->port_state <= LPFC_NS_QRY) {
8068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8069 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
8070 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
8072 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8076 /* If this RSCN just contains NPortIDs for other vports on this HBA,
8077 * just ACC and ignore it.
8079 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8080 !(vport->cfg_peer_port_login)) {
8085 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
8086 i -= sizeof(uint32_t);
8088 if (lpfc_find_vport_by_did(phba, nportid))
8091 if (rscn_id == hba_id) {
8092 /* ALL NPortIDs in RSCN are on HBA */
8093 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8095 "Data: x%lx x%x x%x x%x\n",
8096 vport->fc_flag, payload_len,
8097 *lp, vport->fc_rscn_id_cnt);
8098 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8099 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
8100 ndlp->nlp_DID, vport->port_state,
8103 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
8105 /* Restart disctmo if its already running */
8106 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) {
8107 tmo = ((phba->fc_ratov * 3) + 3);
8108 mod_timer(&vport->fc_disctmo,
8110 msecs_to_jiffies(1000 * tmo));
8116 spin_lock_irq(shost->host_lock);
8117 if (vport->fc_rscn_flush) {
8118 /* Another thread is walking fc_rscn_id_list on this vport */
8119 spin_unlock_irq(shost->host_lock);
8120 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag);
8122 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8125 /* Indicate we are walking fc_rscn_id_list on this vport */
8126 vport->fc_rscn_flush = 1;
8127 spin_unlock_irq(shost->host_lock);
8128 /* Get the array count after successfully have the token */
8129 rscn_cnt = vport->fc_rscn_id_cnt;
8130 /* If we are already processing an RSCN, save the received
8131 * RSCN payload buffer, cmdiocb->cmd_dmabuf to process later.
8133 if (test_bit(FC_RSCN_MODE, &vport->fc_flag) ||
8134 test_bit(FC_NDISC_ACTIVE, &vport->fc_flag)) {
8135 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8136 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
8137 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
8139 set_bit(FC_RSCN_DEFERRED, &vport->fc_flag);
8141 /* Restart disctmo if its already running */
8142 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) {
8143 tmo = ((phba->fc_ratov * 3) + 3);
8144 mod_timer(&vport->fc_disctmo,
8145 jiffies + msecs_to_jiffies(1000 * tmo));
8147 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
8148 !test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag)) {
8149 set_bit(FC_RSCN_MODE, &vport->fc_flag);
8151 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
8152 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
8155 (payload_len + length <= LPFC_BPL_SIZE)) {
8156 *cmd &= ELS_CMD_MASK;
8157 *cmd |= cpu_to_be32(payload_len + length);
8158 memcpy(((uint8_t *)cmd) + length, lp,
8161 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
8162 vport->fc_rscn_id_cnt++;
8163 /* If we zero, cmdiocb->cmd_dmabuf, the calling
8164 * routine will not try to free it.
8166 cmdiocb->cmd_dmabuf = NULL;
8169 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8170 "0235 Deferred RSCN "
8171 "Data: x%x x%lx x%x\n",
8172 vport->fc_rscn_id_cnt, vport->fc_flag,
8175 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag);
8176 /* ReDiscovery RSCN */
8177 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8178 "0234 ReDiscovery RSCN "
8179 "Data: x%x x%lx x%x\n",
8180 vport->fc_rscn_id_cnt, vport->fc_flag,
8183 /* Indicate we are done walking fc_rscn_id_list on this vport */
8184 vport->fc_rscn_flush = 0;
8186 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8187 /* send RECOVERY event for ALL nodes that match RSCN payload */
8188 lpfc_rscn_recovery_check(vport);
8191 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8192 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
8193 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
8195 set_bit(FC_RSCN_MODE, &vport->fc_flag);
8196 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
8197 /* Indicate we are done walking fc_rscn_id_list on this vport */
8198 vport->fc_rscn_flush = 0;
8200 * If we zero, cmdiocb->cmd_dmabuf, the calling routine will
8201 * not try to free it.
8203 cmdiocb->cmd_dmabuf = NULL;
8204 lpfc_set_disctmo(vport);
8206 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8207 /* send RECOVERY event for ALL nodes that match RSCN payload */
8208 lpfc_rscn_recovery_check(vport);
8209 return lpfc_els_handle_rscn(vport);
8213 * lpfc_els_handle_rscn - Handle rscn for a vport
8214 * @vport: pointer to a host virtual N_Port data structure.
8216 * This routine handles the Registration State Configuration Notification
8217 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
8218 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
8219 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
8220 * NameServer shall be issued. If CT command to the NameServer fails to be
8221 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
8222 * RSCN activities with the @vport.
8225 * 0 - Cleaned up rscn on the @vport
8226 * 1 - Wait for plogi to name server before proceed
8229 lpfc_els_handle_rscn(struct lpfc_vport *vport)
8231 struct lpfc_nodelist *ndlp;
8232 struct lpfc_hba *phba = vport->phba;
8234 /* Ignore RSCN if the port is being torn down. */
8235 if (test_bit(FC_UNLOADING, &vport->load_flag)) {
8236 lpfc_els_flush_rscn(vport);
8240 /* Start timer for RSCN processing */
8241 lpfc_set_disctmo(vport);
8243 /* RSCN processed */
8244 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8245 "0215 RSCN processed Data: x%lx x%x x%x x%x x%x x%x\n",
8246 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
8247 vport->port_state, vport->num_disc_nodes,
8250 /* To process RSCN, first compare RSCN data with NameServer */
8251 vport->fc_ns_retry = 0;
8252 vport->num_disc_nodes = 0;
8254 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8255 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
8256 /* Good ndlp, issue CT Request to NameServer. Need to
8257 * know how many gidfts were issued. If none, then just
8258 * flush the RSCN. Otherwise, the outstanding requests
8261 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
8262 if (lpfc_issue_gidft(vport) > 0)
8264 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
8265 if (lpfc_issue_gidpt(vport) > 0)
8271 /* Nameserver login in question. Revalidate. */
8273 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
8274 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8276 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8278 lpfc_els_flush_rscn(vport);
8281 ndlp->nlp_prev_state = ndlp->nlp_state;
8282 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8284 ndlp->nlp_type |= NLP_FABRIC;
8285 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
8286 /* Wait for NameServer login cmpl before we can
8292 lpfc_els_flush_rscn(vport);
8297 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
8298 * @vport: pointer to a host virtual N_Port data structure.
8299 * @cmdiocb: pointer to lpfc command iocb data structure.
8300 * @ndlp: pointer to a node-list data structure.
8302 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
8303 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
8304 * point topology. As an unsolicited FLOGI should not be received in a loop
8305 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
8306 * lpfc_check_sparm() routine is invoked to check the parameters in the
8307 * unsolicited FLOGI. If parameters validation failed, the routine
8308 * lpfc_els_rsp_reject() shall be called with reject reason code set to
8309 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
8310 * FLOGI shall be compared with the Port WWN of the @vport to determine who
8311 * will initiate PLOGI. The higher lexicographical value party shall has
8312 * higher priority (as the winning port) and will initiate PLOGI and
8313 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
8314 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
8315 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
8318 * 0 - Successfully processed the unsolicited flogi
8319 * 1 - Failed to process the unsolicited flogi
8322 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8323 struct lpfc_nodelist *ndlp)
8325 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8326 struct lpfc_hba *phba = vport->phba;
8327 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
8328 uint32_t *lp = (uint32_t *) pcmd->virt;
8329 union lpfc_wqe128 *wqe = &cmdiocb->wqe;
8330 struct serv_parm *sp;
8334 unsigned long fc_flag = 0;
8335 uint32_t port_state = 0;
8337 /* Clear external loopback plug detected flag */
8338 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
8341 sp = (struct serv_parm *) lp;
8343 /* FLOGI received */
8345 lpfc_set_disctmo(vport);
8347 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8348 /* We should never receive a FLOGI in loop mode, ignore it */
8349 did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
8351 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
8353 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8354 "0113 An FLOGI ELS command x%x was "
8355 "received from DID x%x in Loop Mode\n",
8360 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
8363 * If our portname is greater than the remote portname,
8364 * then we initiate Nport login.
8367 rc = memcmp(&vport->fc_portname, &sp->portName,
8368 sizeof(struct lpfc_name));
8371 if (phba->sli_rev < LPFC_SLI_REV4) {
8372 mbox = mempool_alloc(phba->mbox_mem_pool,
8376 lpfc_linkdown(phba);
8377 lpfc_init_link(phba, mbox,
8379 phba->cfg_link_speed);
8380 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8381 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8382 mbox->vport = vport;
8383 rc = lpfc_sli_issue_mbox(phba, mbox,
8385 lpfc_set_loopback_flag(phba);
8386 if (rc == MBX_NOT_FINISHED)
8387 mempool_free(mbox, phba->mbox_mem_pool);
8391 /* External loopback plug insertion detected */
8392 phba->link_flag |= LS_EXTERNAL_LOOPBACK;
8394 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_LIBDFC,
8395 "1119 External Loopback plug detected\n");
8397 /* abort the flogi coming back to ourselves
8398 * due to external loopback on the port.
8400 lpfc_els_abort_flogi(phba);
8403 } else if (rc > 0) { /* greater than */
8404 set_bit(FC_PT2PT_PLOGI, &vport->fc_flag);
8406 /* If we have the high WWPN we can assign our own
8407 * myDID; otherwise, we have to WAIT for a PLOGI
8408 * from the remote NPort to find out what it
8411 vport->fc_myDID = PT2PT_LocalID;
8413 vport->fc_myDID = PT2PT_RemoteID;
8417 * The vport state should go to LPFC_FLOGI only
8418 * AFTER we issue a FLOGI, not receive one.
8420 spin_lock_irq(shost->host_lock);
8421 fc_flag = vport->fc_flag;
8422 port_state = vport->port_state;
8423 /* Acking an unsol FLOGI. Count 1 for link bounce
8426 vport->rcv_flogi_cnt++;
8427 spin_unlock_irq(shost->host_lock);
8428 set_bit(FC_PT2PT, &vport->fc_flag);
8429 clear_bit(FC_FABRIC, &vport->fc_flag);
8430 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
8431 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8432 "3311 Rcv Flogi PS x%x new PS x%x "
8433 "fc_flag x%lx new fc_flag x%lx\n",
8434 port_state, vport->port_state,
8435 fc_flag, vport->fc_flag);
8438 * We temporarily set fc_myDID to make it look like we are
8439 * a Fabric. This is done just so we end up with the right
8440 * did / sid on the FLOGI ACC rsp.
8442 did = vport->fc_myDID;
8443 vport->fc_myDID = Fabric_DID;
8445 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
8447 /* Defer ACC response until AFTER we issue a FLOGI */
8448 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
8449 phba->defer_flogi_acc_rx_id = bf_get(wqe_ctxt_tag,
8450 &wqe->xmit_els_rsp.wqe_com);
8451 phba->defer_flogi_acc_ox_id = bf_get(wqe_rcvoxid,
8452 &wqe->xmit_els_rsp.wqe_com);
8454 vport->fc_myDID = did;
8456 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8457 "3344 Deferring FLOGI ACC: rx_id: x%x,"
8458 " ox_id: x%x, hba_flag x%x\n",
8459 phba->defer_flogi_acc_rx_id,
8460 phba->defer_flogi_acc_ox_id, phba->hba_flag);
8462 phba->defer_flogi_acc_flag = true;
8468 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
8470 /* Now lets put fc_myDID back to what its supposed to be */
8471 vport->fc_myDID = did;
8477 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
8478 * @vport: pointer to a host virtual N_Port data structure.
8479 * @cmdiocb: pointer to lpfc command iocb data structure.
8480 * @ndlp: pointer to a node-list data structure.
8482 * This routine processes Request Node Identification Data (RNID) IOCB
8483 * received as an ELS unsolicited event. Only when the RNID specified format
8484 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
8485 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
8486 * Accept (ACC) the RNID ELS command. All the other RNID formats are
8487 * rejected by invoking the lpfc_els_rsp_reject() routine.
8490 * 0 - Successfully processed rnid iocb (currently always return 0)
8493 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8494 struct lpfc_nodelist *ndlp)
8496 struct lpfc_dmabuf *pcmd;
8501 pcmd = cmdiocb->cmd_dmabuf;
8502 lp = (uint32_t *) pcmd->virt;
8509 switch (rn->Format) {
8511 case RNID_TOPOLOGY_DISC:
8513 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
8516 /* Reject this request because format not supported */
8517 stat.un.b.lsRjtRsvd0 = 0;
8518 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8519 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8520 stat.un.b.vendorUnique = 0;
8521 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8528 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
8529 * @vport: pointer to a host virtual N_Port data structure.
8530 * @cmdiocb: pointer to lpfc command iocb data structure.
8531 * @ndlp: pointer to a node-list data structure.
8534 * 0 - Successfully processed echo iocb (currently always return 0)
8537 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8538 struct lpfc_nodelist *ndlp)
8542 pcmd = (uint8_t *)cmdiocb->cmd_dmabuf->virt;
8544 /* skip over first word of echo command to find echo data */
8545 pcmd += sizeof(uint32_t);
8547 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
8552 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
8553 * @vport: pointer to a host virtual N_Port data structure.
8554 * @cmdiocb: pointer to lpfc command iocb data structure.
8555 * @ndlp: pointer to a node-list data structure.
8557 * This routine processes a Link Incident Report Registration(LIRR) IOCB
8558 * received as an ELS unsolicited event. Currently, this function just invokes
8559 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
8562 * 0 - Successfully processed lirr iocb (currently always return 0)
8565 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8566 struct lpfc_nodelist *ndlp)
8570 /* For now, unconditionally reject this command */
8571 stat.un.b.lsRjtRsvd0 = 0;
8572 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8573 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8574 stat.un.b.vendorUnique = 0;
8575 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8580 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
8581 * @vport: pointer to a host virtual N_Port data structure.
8582 * @cmdiocb: pointer to lpfc command iocb data structure.
8583 * @ndlp: pointer to a node-list data structure.
8585 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
8586 * received as an ELS unsolicited event. A request to RRQ shall only
8587 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
8588 * Nx_Port N_Port_ID of the target Exchange is the same as the
8589 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
8590 * not accepted, an LS_RJT with reason code "Unable to perform
8591 * command request" and reason code explanation "Invalid Originator
8592 * S_ID" shall be returned. For now, we just unconditionally accept
8593 * RRQ from the target.
8596 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8597 struct lpfc_nodelist *ndlp)
8599 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8600 if (vport->phba->sli_rev == LPFC_SLI_REV4)
8601 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
8605 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
8606 * @phba: pointer to lpfc hba data structure.
8607 * @pmb: pointer to the driver internal queue element for mailbox command.
8609 * This routine is the completion callback function for the MBX_READ_LNK_STAT
8610 * mailbox command. This callback function is to actually send the Accept
8611 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
8612 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
8613 * mailbox command, constructs the RLS response with the link statistics
8614 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
8615 * response to the RLS.
8617 * Note that the ndlp reference count will be incremented by 1 for holding the
8618 * ndlp and the reference to ndlp will be stored into the ndlp field of
8619 * the IOCB for the completion callback function to the RLS Accept Response
8624 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8629 union lpfc_wqe128 *wqe;
8630 struct RLS_RSP *rls_rsp;
8632 struct lpfc_iocbq *elsiocb;
8633 struct lpfc_nodelist *ndlp;
8641 ndlp = pmb->ctx_ndlp;
8642 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
8643 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
8644 pmb->ctx_buf = NULL;
8645 pmb->ctx_ndlp = NULL;
8647 if (mb->mbxStatus) {
8648 mempool_free(pmb, phba->mbox_mem_pool);
8652 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
8653 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8654 lpfc_max_els_tries, ndlp,
8655 ndlp->nlp_DID, ELS_CMD_ACC);
8657 /* Decrement the ndlp reference count from previous mbox command */
8661 mempool_free(pmb, phba->mbox_mem_pool);
8665 ulp_context = get_job_ulpcontext(phba, elsiocb);
8666 if (phba->sli_rev == LPFC_SLI_REV4) {
8667 wqe = &elsiocb->wqe;
8669 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, rxid);
8670 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, oxid);
8672 icmd = &elsiocb->iocb;
8673 icmd->ulpContext = rxid;
8674 icmd->unsli3.rcvsli3.ox_id = oxid;
8677 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8678 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8679 pcmd += sizeof(uint32_t); /* Skip past command */
8680 rls_rsp = (struct RLS_RSP *)pcmd;
8682 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
8683 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
8684 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
8685 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
8686 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
8687 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
8688 mempool_free(pmb, phba->mbox_mem_pool);
8689 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8690 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8691 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
8692 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
8693 elsiocb->iotag, ulp_context,
8694 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8696 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8697 phba->fc_stat.elsXmitACC++;
8698 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8699 if (!elsiocb->ndlp) {
8700 lpfc_els_free_iocb(phba, elsiocb);
8704 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8705 if (rc == IOCB_ERROR) {
8706 lpfc_els_free_iocb(phba, elsiocb);
8713 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
8714 * @vport: pointer to a host virtual N_Port data structure.
8715 * @cmdiocb: pointer to lpfc command iocb data structure.
8716 * @ndlp: pointer to a node-list data structure.
8718 * This routine processes Read Link Status (RLS) IOCB received as an
8719 * ELS unsolicited event. It first checks the remote port state. If the
8720 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8721 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8722 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
8723 * for reading the HBA link statistics. It is for the callback function,
8724 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
8725 * to actually sending out RPL Accept (ACC) response.
8728 * 0 - Successfully processed rls iocb (currently always return 0)
8731 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8732 struct lpfc_nodelist *ndlp)
8734 struct lpfc_hba *phba = vport->phba;
8737 u32 ctx = get_job_ulpcontext(phba, cmdiocb);
8738 u32 ox_id = get_job_rcvoxid(phba, cmdiocb);
8740 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8741 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8742 /* reject the unsolicited RLS request and done with it */
8745 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
8747 lpfc_read_lnk_stat(phba, mbox);
8748 mbox->ctx_buf = (void *)((unsigned long)
8749 (ox_id << 16 | ctx));
8750 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
8751 if (!mbox->ctx_ndlp)
8753 mbox->vport = vport;
8754 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
8755 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8756 != MBX_NOT_FINISHED)
8757 /* Mbox completion will send ELS Response */
8759 /* Decrement reference count used for the failed mbox
8764 mempool_free(mbox, phba->mbox_mem_pool);
8767 /* issue rejection response */
8768 stat.un.b.lsRjtRsvd0 = 0;
8769 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8770 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8771 stat.un.b.vendorUnique = 0;
8772 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8777 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
8778 * @vport: pointer to a host virtual N_Port data structure.
8779 * @cmdiocb: pointer to lpfc command iocb data structure.
8780 * @ndlp: pointer to a node-list data structure.
8782 * This routine processes Read Timout Value (RTV) IOCB received as an
8783 * ELS unsolicited event. It first checks the remote port state. If the
8784 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8785 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8786 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
8787 * Value (RTV) unsolicited IOCB event.
8789 * Note that the ndlp reference count will be incremented by 1 for holding the
8790 * ndlp and the reference to ndlp will be stored into the ndlp field of
8791 * the IOCB for the completion callback function to the RTV Accept Response
8795 * 0 - Successfully processed rtv iocb (currently always return 0)
8798 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8799 struct lpfc_nodelist *ndlp)
8803 union lpfc_wqe128 *wqe;
8804 struct lpfc_hba *phba = vport->phba;
8806 struct RTV_RSP *rtv_rsp;
8808 struct lpfc_iocbq *elsiocb;
8812 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8813 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8814 /* reject the unsolicited RTV request and done with it */
8817 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
8818 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8819 lpfc_max_els_tries, ndlp,
8820 ndlp->nlp_DID, ELS_CMD_ACC);
8825 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8826 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8827 pcmd += sizeof(uint32_t); /* Skip past command */
8829 ulp_context = get_job_ulpcontext(phba, elsiocb);
8830 /* use the command's xri in the response */
8831 if (phba->sli_rev == LPFC_SLI_REV4) {
8832 wqe = &elsiocb->wqe;
8833 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
8834 get_job_ulpcontext(phba, cmdiocb));
8835 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8836 get_job_rcvoxid(phba, cmdiocb));
8838 icmd = &elsiocb->iocb;
8839 icmd->ulpContext = get_job_ulpcontext(phba, cmdiocb);
8840 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, cmdiocb);
8843 rtv_rsp = (struct RTV_RSP *)pcmd;
8845 /* populate RTV payload */
8846 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
8847 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
8848 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
8849 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
8850 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
8852 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8853 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8854 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
8855 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
8856 "Data: x%x x%x x%x\n",
8857 elsiocb->iotag, ulp_context,
8858 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8860 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
8861 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8862 phba->fc_stat.elsXmitACC++;
8863 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8864 if (!elsiocb->ndlp) {
8865 lpfc_els_free_iocb(phba, elsiocb);
8869 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8870 if (rc == IOCB_ERROR) {
8871 lpfc_els_free_iocb(phba, elsiocb);
8877 /* issue rejection response */
8878 stat.un.b.lsRjtRsvd0 = 0;
8879 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8880 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8881 stat.un.b.vendorUnique = 0;
8882 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8886 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
8887 * @vport: pointer to a host virtual N_Port data structure.
8888 * @ndlp: pointer to a node-list data structure.
8889 * @did: DID of the target.
8890 * @rrq: Pointer to the rrq struct.
8892 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
8893 * successful, the completion handler will clear the RRQ.
8896 * 0 - Successfully sent rrq els iocb.
8897 * 1 - Failed to send rrq els iocb.
8900 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8901 uint32_t did, struct lpfc_node_rrq *rrq)
8903 struct lpfc_hba *phba = vport->phba;
8904 struct RRQ *els_rrq;
8905 struct lpfc_iocbq *elsiocb;
8913 /* If ndlp is not NULL, we will bump the reference count on it */
8914 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
8915 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
8920 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8922 /* For RRQ request, remainder of payload is Exchange IDs */
8923 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
8924 pcmd += sizeof(uint32_t);
8925 els_rrq = (struct RRQ *) pcmd;
8927 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
8928 bf_set(rrq_rxid, els_rrq, rrq->rxid);
8929 bf_set(rrq_did, els_rrq, vport->fc_myDID);
8930 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
8931 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
8934 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8935 "Issue RRQ: did:x%x",
8936 did, rrq->xritag, rrq->rxid);
8937 elsiocb->context_un.rrq = rrq;
8938 elsiocb->cmd_cmpl = lpfc_cmpl_els_rrq;
8940 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8944 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8945 if (ret == IOCB_ERROR) {
8952 lpfc_els_free_iocb(phba, elsiocb);
8957 * lpfc_send_rrq - Sends ELS RRQ if needed.
8958 * @phba: pointer to lpfc hba data structure.
8959 * @rrq: pointer to the active rrq.
8961 * This routine will call the lpfc_issue_els_rrq if the rrq is
8962 * still active for the xri. If this function returns a failure then
8963 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
8965 * Returns 0 Success.
8969 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
8971 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
8976 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
8977 return lpfc_issue_els_rrq(rrq->vport, ndlp,
8984 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
8985 * @vport: pointer to a host virtual N_Port data structure.
8986 * @cmdsize: size of the ELS command.
8987 * @oldiocb: pointer to the original lpfc command iocb data structure.
8988 * @ndlp: pointer to a node-list data structure.
8990 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
8991 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
8993 * Note that the ndlp reference count will be incremented by 1 for holding the
8994 * ndlp and the reference to ndlp will be stored into the ndlp field of
8995 * the IOCB for the completion callback function to the RPL Accept Response
8999 * 0 - Successfully issued ACC RPL ELS command
9000 * 1 - Failed to issue ACC RPL ELS command
9003 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
9004 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
9007 struct lpfc_hba *phba = vport->phba;
9009 union lpfc_wqe128 *wqe;
9011 struct lpfc_iocbq *elsiocb;
9015 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
9016 ndlp->nlp_DID, ELS_CMD_ACC);
9021 ulp_context = get_job_ulpcontext(phba, elsiocb);
9022 if (phba->sli_rev == LPFC_SLI_REV4) {
9023 wqe = &elsiocb->wqe;
9025 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
9026 get_job_ulpcontext(phba, oldiocb));
9027 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
9028 get_job_rcvoxid(phba, oldiocb));
9030 icmd = &elsiocb->iocb;
9031 icmd->ulpContext = get_job_ulpcontext(phba, oldiocb);
9032 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, oldiocb);
9035 pcmd = elsiocb->cmd_dmabuf->virt;
9036 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
9037 pcmd += sizeof(uint16_t);
9038 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
9039 pcmd += sizeof(uint16_t);
9041 /* Setup the RPL ACC payload */
9042 rpl_rsp.listLen = be32_to_cpu(1);
9044 rpl_rsp.port_num_blk.portNum = 0;
9045 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
9046 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
9047 sizeof(struct lpfc_name));
9048 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
9049 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
9050 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9051 "0120 Xmit ELS RPL ACC response tag x%x "
9052 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
9054 elsiocb->iotag, ulp_context,
9055 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
9057 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
9058 phba->fc_stat.elsXmitACC++;
9059 elsiocb->ndlp = lpfc_nlp_get(ndlp);
9060 if (!elsiocb->ndlp) {
9061 lpfc_els_free_iocb(phba, elsiocb);
9065 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9066 if (rc == IOCB_ERROR) {
9067 lpfc_els_free_iocb(phba, elsiocb);
9076 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
9077 * @vport: pointer to a host virtual N_Port data structure.
9078 * @cmdiocb: pointer to lpfc command iocb data structure.
9079 * @ndlp: pointer to a node-list data structure.
9081 * This routine processes Read Port List (RPL) IOCB received as an ELS
9082 * unsolicited event. It first checks the remote port state. If the remote
9083 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
9084 * invokes the lpfc_els_rsp_reject() routine to send reject response.
9085 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
9086 * to accept the RPL.
9089 * 0 - Successfully processed rpl iocb (currently always return 0)
9092 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9093 struct lpfc_nodelist *ndlp)
9095 struct lpfc_dmabuf *pcmd;
9102 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
9103 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
9104 /* issue rejection response */
9105 stat.un.b.lsRjtRsvd0 = 0;
9106 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
9107 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
9108 stat.un.b.vendorUnique = 0;
9109 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
9111 /* rejected the unsolicited RPL request and done with it */
9115 pcmd = cmdiocb->cmd_dmabuf;
9116 lp = (uint32_t *) pcmd->virt;
9117 rpl = (RPL *) (lp + 1);
9118 maxsize = be32_to_cpu(rpl->maxsize);
9120 /* We support only one port */
9121 if ((rpl->index == 0) &&
9123 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
9124 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
9126 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
9128 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
9134 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
9135 * @vport: pointer to a virtual N_Port data structure.
9136 * @cmdiocb: pointer to lpfc command iocb data structure.
9137 * @ndlp: pointer to a node-list data structure.
9139 * This routine processes Fibre Channel Address Resolution Protocol
9140 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
9141 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
9142 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
9143 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
9144 * remote PortName is compared against the FC PortName stored in the @vport
9145 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
9146 * compared against the FC NodeName stored in the @vport data structure.
9147 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
9148 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
9149 * invoked to send out FARP Response to the remote node. Before sending the
9150 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
9151 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
9152 * routine is invoked to log into the remote port first.
9155 * 0 - Either the FARP Match Mode not supported or successfully processed
9158 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9159 struct lpfc_nodelist *ndlp)
9161 struct lpfc_dmabuf *pcmd;
9166 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
9167 pcmd = cmdiocb->cmd_dmabuf;
9168 lp = (uint32_t *) pcmd->virt;
9172 /* FARP-REQ received from DID <did> */
9173 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9174 "0601 FARP-REQ received from DID x%x\n", did);
9175 /* We will only support match on WWPN or WWNN */
9176 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
9181 /* If this FARP command is searching for my portname */
9182 if (fp->Mflags & FARP_MATCH_PORT) {
9183 if (memcmp(&fp->RportName, &vport->fc_portname,
9184 sizeof(struct lpfc_name)) == 0)
9188 /* If this FARP command is searching for my nodename */
9189 if (fp->Mflags & FARP_MATCH_NODE) {
9190 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
9191 sizeof(struct lpfc_name)) == 0)
9196 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
9197 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
9198 /* Log back into the node before sending the FARP. */
9199 if (fp->Rflags & FARP_REQUEST_PLOGI) {
9200 ndlp->nlp_prev_state = ndlp->nlp_state;
9201 lpfc_nlp_set_state(vport, ndlp,
9202 NLP_STE_PLOGI_ISSUE);
9203 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9206 /* Send a FARP response to that node */
9207 if (fp->Rflags & FARP_REQUEST_FARPR)
9208 lpfc_issue_els_farpr(vport, did, 0);
9215 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
9216 * @vport: pointer to a host virtual N_Port data structure.
9217 * @cmdiocb: pointer to lpfc command iocb data structure.
9218 * @ndlp: pointer to a node-list data structure.
9220 * This routine processes Fibre Channel Address Resolution Protocol
9221 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
9222 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
9223 * the FARP response request.
9226 * 0 - Successfully processed FARPR IOCB (currently always return 0)
9229 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9230 struct lpfc_nodelist *ndlp)
9234 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
9236 /* FARP-RSP received from DID <did> */
9237 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9238 "0600 FARP-RSP received from DID x%x\n", did);
9239 /* ACCEPT the Farp resp request */
9240 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
9246 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
9247 * @vport: pointer to a host virtual N_Port data structure.
9248 * @cmdiocb: pointer to lpfc command iocb data structure.
9249 * @fan_ndlp: pointer to a node-list data structure.
9251 * This routine processes a Fabric Address Notification (FAN) IOCB
9252 * command received as an ELS unsolicited event. The FAN ELS command will
9253 * only be processed on a physical port (i.e., the @vport represents the
9254 * physical port). The fabric NodeName and PortName from the FAN IOCB are
9255 * compared against those in the phba data structure. If any of those is
9256 * different, the lpfc_initial_flogi() routine is invoked to initialize
9257 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
9258 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
9259 * is invoked to register login to the fabric.
9262 * 0 - Successfully processed fan iocb (currently always return 0).
9265 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9266 struct lpfc_nodelist *fan_ndlp)
9268 struct lpfc_hba *phba = vport->phba;
9272 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
9273 lp = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
9275 /* FAN received; Fan does not have a reply sequence */
9276 if ((vport == phba->pport) &&
9277 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
9278 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
9279 sizeof(struct lpfc_name))) ||
9280 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
9281 sizeof(struct lpfc_name)))) {
9282 /* This port has switched fabrics. FLOGI is required */
9283 lpfc_issue_init_vfi(vport);
9285 /* FAN verified - skip FLOGI */
9286 vport->fc_myDID = vport->fc_prevDID;
9287 if (phba->sli_rev < LPFC_SLI_REV4)
9288 lpfc_issue_fabric_reglogin(vport);
9290 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9291 "3138 Need register VFI: (x%x/%x)\n",
9292 vport->fc_prevDID, vport->fc_myDID);
9293 lpfc_issue_reg_vfi(vport);
9301 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb
9302 * @vport: pointer to a host virtual N_Port data structure.
9303 * @cmdiocb: pointer to lpfc command iocb data structure.
9304 * @ndlp: pointer to a node-list data structure.
9307 * 0 - Successfully processed echo iocb (currently always return 0)
9310 lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9311 struct lpfc_nodelist *ndlp)
9313 struct lpfc_hba *phba = vport->phba;
9314 struct fc_els_edc *edc_req;
9315 struct fc_tlv_desc *tlv;
9317 uint32_t *ptr, dtag;
9318 const char *dtag_nm;
9319 int desc_cnt = 0, bytes_remain;
9320 struct fc_diag_lnkflt_desc *plnkflt;
9322 payload = cmdiocb->cmd_dmabuf->virt;
9324 edc_req = (struct fc_els_edc *)payload;
9325 bytes_remain = be32_to_cpu(edc_req->desc_len);
9327 ptr = (uint32_t *)payload;
9328 lpfc_printf_vlog(vport, KERN_INFO,
9329 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9330 "3319 Rcv EDC payload len %d: x%x x%x x%x\n",
9331 bytes_remain, be32_to_cpu(*ptr),
9332 be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2)));
9334 /* No signal support unless there is a congestion descriptor */
9335 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9336 phba->cgn_sig_freq = 0;
9337 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
9339 if (bytes_remain <= 0)
9342 tlv = edc_req->desc;
9345 * cycle through EDC diagnostic descriptors to find the
9346 * congestion signaling capability descriptor
9348 while (bytes_remain) {
9349 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
9350 lpfc_printf_log(phba, KERN_WARNING,
9351 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9352 "6464 Truncated TLV hdr on "
9353 "Diagnostic descriptor[%d]\n",
9358 dtag = be32_to_cpu(tlv->desc_tag);
9360 case ELS_DTAG_LNK_FAULT_CAP:
9361 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9362 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9363 sizeof(struct fc_diag_lnkflt_desc)) {
9364 lpfc_printf_log(phba, KERN_WARNING,
9365 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9366 "6465 Truncated Link Fault Diagnostic "
9367 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9368 desc_cnt, bytes_remain,
9369 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9370 sizeof(struct fc_diag_lnkflt_desc));
9373 plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
9374 lpfc_printf_log(phba, KERN_INFO,
9375 LOG_ELS | LOG_LDS_EVENT,
9376 "4626 Link Fault Desc Data: x%08x len x%x "
9377 "da x%x dd x%x interval x%x\n",
9378 be32_to_cpu(plnkflt->desc_tag),
9379 be32_to_cpu(plnkflt->desc_len),
9381 plnkflt->degrade_activate_threshold),
9383 plnkflt->degrade_deactivate_threshold),
9384 be32_to_cpu(plnkflt->fec_degrade_interval));
9386 case ELS_DTAG_CG_SIGNAL_CAP:
9387 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9388 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9389 sizeof(struct fc_diag_cg_sig_desc)) {
9391 phba, KERN_WARNING, LOG_CGN_MGMT,
9392 "6466 Truncated cgn signal Diagnostic "
9393 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9394 desc_cnt, bytes_remain,
9395 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9396 sizeof(struct fc_diag_cg_sig_desc));
9400 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
9401 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
9403 /* We start negotiation with lpfc_fabric_cgn_frequency.
9404 * When we process the EDC, we will settle on the
9407 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9409 lpfc_least_capable_settings(
9410 phba, (struct fc_diag_cg_sig_desc *)tlv);
9413 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
9414 lpfc_printf_log(phba, KERN_WARNING,
9415 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9416 "6467 unknown Diagnostic "
9417 "Descriptor[%d]: tag x%x (%s)\n",
9418 desc_cnt, dtag, dtag_nm);
9420 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
9421 tlv = fc_tlv_next_desc(tlv);
9425 /* Need to send back an ACC */
9426 lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp);
9428 lpfc_config_cgn_signal(phba);
9433 * lpfc_els_timeout - Handler funciton to the els timer
9434 * @t: timer context used to obtain the vport.
9436 * This routine is invoked by the ELS timer after timeout. It posts the ELS
9437 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
9438 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
9439 * up the worker thread. It is for the worker thread to invoke the routine
9440 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
9443 lpfc_els_timeout(struct timer_list *t)
9445 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
9446 struct lpfc_hba *phba = vport->phba;
9447 uint32_t tmo_posted;
9448 unsigned long iflag;
9450 spin_lock_irqsave(&vport->work_port_lock, iflag);
9451 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
9452 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag))
9453 vport->work_port_events |= WORKER_ELS_TMO;
9454 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
9456 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag))
9457 lpfc_worker_wake_up(phba);
9463 * lpfc_els_timeout_handler - Process an els timeout event
9464 * @vport: pointer to a virtual N_Port data structure.
9466 * This routine is the actual handler function that processes an ELS timeout
9467 * event. It walks the ELS ring to get and abort all the IOCBs (except the
9468 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
9469 * invoking the lpfc_sli_issue_abort_iotag() routine.
9472 lpfc_els_timeout_handler(struct lpfc_vport *vport)
9474 struct lpfc_hba *phba = vport->phba;
9475 struct lpfc_sli_ring *pring;
9476 struct lpfc_iocbq *tmp_iocb, *piocb;
9478 struct lpfc_dmabuf *pcmd;
9479 uint32_t els_command = 0;
9481 uint32_t remote_ID = 0xffffffff;
9482 LIST_HEAD(abort_list);
9483 u32 ulp_command = 0, ulp_context = 0, did = 0, iotag = 0;
9486 timeout = (uint32_t)(phba->fc_ratov << 1);
9488 pring = lpfc_phba_elsring(phba);
9489 if (unlikely(!pring))
9492 if (test_bit(FC_UNLOADING, &phba->pport->load_flag))
9495 spin_lock_irq(&phba->hbalock);
9496 if (phba->sli_rev == LPFC_SLI_REV4)
9497 spin_lock(&pring->ring_lock);
9499 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9500 ulp_command = get_job_cmnd(phba, piocb);
9501 ulp_context = get_job_ulpcontext(phba, piocb);
9502 did = get_job_els_rsp64_did(phba, piocb);
9504 if (phba->sli_rev == LPFC_SLI_REV4) {
9505 iotag = get_wqe_reqtag(piocb);
9508 iotag = cmd->ulpIoTag;
9511 if ((piocb->cmd_flag & LPFC_IO_LIBDFC) != 0 ||
9512 ulp_command == CMD_ABORT_XRI_CX ||
9513 ulp_command == CMD_ABORT_XRI_CN ||
9514 ulp_command == CMD_CLOSE_XRI_CN)
9517 if (piocb->vport != vport)
9520 pcmd = piocb->cmd_dmabuf;
9522 els_command = *(uint32_t *) (pcmd->virt);
9524 if (els_command == ELS_CMD_FARP ||
9525 els_command == ELS_CMD_FARPR ||
9526 els_command == ELS_CMD_FDISC)
9529 if (piocb->drvrTimeout > 0) {
9530 if (piocb->drvrTimeout >= timeout)
9531 piocb->drvrTimeout -= timeout;
9533 piocb->drvrTimeout = 0;
9537 remote_ID = 0xffffffff;
9538 if (ulp_command != CMD_GEN_REQUEST64_CR) {
9541 struct lpfc_nodelist *ndlp;
9542 ndlp = __lpfc_findnode_rpi(vport, ulp_context);
9544 remote_ID = ndlp->nlp_DID;
9546 list_add_tail(&piocb->dlist, &abort_list);
9548 if (phba->sli_rev == LPFC_SLI_REV4)
9549 spin_unlock(&pring->ring_lock);
9550 spin_unlock_irq(&phba->hbalock);
9552 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9553 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9554 "0127 ELS timeout Data: x%x x%x x%x "
9555 "x%x\n", els_command,
9556 remote_ID, ulp_command, iotag);
9558 spin_lock_irq(&phba->hbalock);
9559 list_del_init(&piocb->dlist);
9560 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9561 spin_unlock_irq(&phba->hbalock);
9564 /* Make sure HBA is alive */
9565 lpfc_issue_hb_tmo(phba);
9567 if (!list_empty(&pring->txcmplq))
9568 if (!test_bit(FC_UNLOADING, &phba->pport->load_flag))
9569 mod_timer(&vport->els_tmofunc,
9570 jiffies + msecs_to_jiffies(1000 * timeout));
9574 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
9575 * @vport: pointer to a host virtual N_Port data structure.
9577 * This routine is used to clean up all the outstanding ELS commands on a
9578 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
9579 * routine. After that, it walks the ELS transmit queue to remove all the
9580 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
9581 * the IOCBs with a non-NULL completion callback function, the callback
9582 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9583 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
9584 * callback function, the IOCB will simply be released. Finally, it walks
9585 * the ELS transmit completion queue to issue an abort IOCB to any transmit
9586 * completion queue IOCB that is associated with the @vport and is not
9587 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
9588 * part of the discovery state machine) out to HBA by invoking the
9589 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
9590 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
9591 * the IOCBs are aborted when this function returns.
9594 lpfc_els_flush_cmd(struct lpfc_vport *vport)
9596 LIST_HEAD(abort_list);
9597 LIST_HEAD(cancel_list);
9598 struct lpfc_hba *phba = vport->phba;
9599 struct lpfc_sli_ring *pring;
9600 struct lpfc_iocbq *tmp_iocb, *piocb;
9602 unsigned long iflags = 0;
9605 lpfc_fabric_abort_vport(vport);
9608 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
9609 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
9610 * ultimately grabs the ring_lock, the driver must splice the list into
9611 * a working list and release the locks before calling the abort.
9613 spin_lock_irqsave(&phba->hbalock, iflags);
9614 pring = lpfc_phba_elsring(phba);
9616 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
9617 if (unlikely(!pring)) {
9618 spin_unlock_irqrestore(&phba->hbalock, iflags);
9622 if (phba->sli_rev == LPFC_SLI_REV4)
9623 spin_lock(&pring->ring_lock);
9625 mbx_tmo_err = test_bit(MBX_TMO_ERR, &phba->bit_flags);
9626 /* First we need to issue aborts to outstanding cmds on txcmpl */
9627 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9628 if (piocb->cmd_flag & LPFC_IO_LIBDFC && !mbx_tmo_err)
9631 if (piocb->vport != vport)
9634 if (piocb->cmd_flag & LPFC_DRIVER_ABORTED && !mbx_tmo_err)
9637 /* On the ELS ring we can have ELS_REQUESTs or
9638 * GEN_REQUESTs waiting for a response.
9640 ulp_command = get_job_cmnd(phba, piocb);
9641 if (ulp_command == CMD_ELS_REQUEST64_CR) {
9642 list_add_tail(&piocb->dlist, &abort_list);
9644 /* If the link is down when flushing ELS commands
9645 * the firmware will not complete them till after
9646 * the link comes back up. This may confuse
9647 * discovery for the new link up, so we need to
9648 * change the compl routine to just clean up the iocb
9649 * and avoid any retry logic.
9651 if (phba->link_state == LPFC_LINK_DOWN)
9652 piocb->cmd_cmpl = lpfc_cmpl_els_link_down;
9653 } else if (ulp_command == CMD_GEN_REQUEST64_CR ||
9655 list_add_tail(&piocb->dlist, &abort_list);
9658 if (phba->sli_rev == LPFC_SLI_REV4)
9659 spin_unlock(&pring->ring_lock);
9660 spin_unlock_irqrestore(&phba->hbalock, iflags);
9662 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
9663 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9664 spin_lock_irqsave(&phba->hbalock, iflags);
9665 list_del_init(&piocb->dlist);
9667 list_move_tail(&piocb->list, &cancel_list);
9669 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9671 spin_unlock_irqrestore(&phba->hbalock, iflags);
9673 if (!list_empty(&cancel_list))
9674 lpfc_sli_cancel_iocbs(phba, &cancel_list, IOSTAT_LOCAL_REJECT,
9677 /* Make sure HBA is alive */
9678 lpfc_issue_hb_tmo(phba);
9680 if (!list_empty(&abort_list))
9681 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9682 "3387 abort list for txq not empty\n");
9683 INIT_LIST_HEAD(&abort_list);
9685 spin_lock_irqsave(&phba->hbalock, iflags);
9686 if (phba->sli_rev == LPFC_SLI_REV4)
9687 spin_lock(&pring->ring_lock);
9689 /* No need to abort the txq list,
9690 * just queue them up for lpfc_sli_cancel_iocbs
9692 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
9693 ulp_command = get_job_cmnd(phba, piocb);
9695 if (piocb->cmd_flag & LPFC_IO_LIBDFC)
9698 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
9699 if (ulp_command == CMD_QUE_RING_BUF_CN ||
9700 ulp_command == CMD_QUE_RING_BUF64_CN ||
9701 ulp_command == CMD_CLOSE_XRI_CN ||
9702 ulp_command == CMD_ABORT_XRI_CN ||
9703 ulp_command == CMD_ABORT_XRI_CX)
9706 if (piocb->vport != vport)
9709 list_del_init(&piocb->list);
9710 list_add_tail(&piocb->list, &abort_list);
9713 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
9714 if (vport == phba->pport) {
9715 list_for_each_entry_safe(piocb, tmp_iocb,
9716 &phba->fabric_iocb_list, list) {
9717 list_del_init(&piocb->list);
9718 list_add_tail(&piocb->list, &abort_list);
9722 if (phba->sli_rev == LPFC_SLI_REV4)
9723 spin_unlock(&pring->ring_lock);
9724 spin_unlock_irqrestore(&phba->hbalock, iflags);
9726 /* Cancel all the IOCBs from the completions list */
9727 lpfc_sli_cancel_iocbs(phba, &abort_list,
9728 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
9734 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
9735 * @phba: pointer to lpfc hba data structure.
9737 * This routine is used to clean up all the outstanding ELS commands on a
9738 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
9739 * routine. After that, it walks the ELS transmit queue to remove all the
9740 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
9741 * the IOCBs with the completion callback function associated, the callback
9742 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9743 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
9744 * callback function associated, the IOCB will simply be released. Finally,
9745 * it walks the ELS transmit completion queue to issue an abort IOCB to any
9746 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
9747 * management plane IOCBs that are not part of the discovery state machine)
9748 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
9751 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
9753 struct lpfc_vport *vport;
9755 spin_lock_irq(&phba->port_list_lock);
9756 list_for_each_entry(vport, &phba->port_list, listentry)
9757 lpfc_els_flush_cmd(vport);
9758 spin_unlock_irq(&phba->port_list_lock);
9764 * lpfc_send_els_failure_event - Posts an ELS command failure event
9765 * @phba: Pointer to hba context object.
9766 * @cmdiocbp: Pointer to command iocb which reported error.
9767 * @rspiocbp: Pointer to response iocb which reported error.
9769 * This function sends an event when there is an ELS command
9773 lpfc_send_els_failure_event(struct lpfc_hba *phba,
9774 struct lpfc_iocbq *cmdiocbp,
9775 struct lpfc_iocbq *rspiocbp)
9777 struct lpfc_vport *vport = cmdiocbp->vport;
9778 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9779 struct lpfc_lsrjt_event lsrjt_event;
9780 struct lpfc_fabric_event_header fabric_event;
9782 struct lpfc_nodelist *ndlp;
9784 u32 ulp_status, ulp_word4;
9786 ndlp = cmdiocbp->ndlp;
9790 ulp_status = get_job_ulpstatus(phba, rspiocbp);
9791 ulp_word4 = get_job_word4(phba, rspiocbp);
9793 if (ulp_status == IOSTAT_LS_RJT) {
9794 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
9795 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
9796 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
9797 sizeof(struct lpfc_name));
9798 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
9799 sizeof(struct lpfc_name));
9800 pcmd = (uint32_t *)cmdiocbp->cmd_dmabuf->virt;
9801 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
9802 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
9803 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
9804 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
9805 fc_host_post_vendor_event(shost,
9806 fc_get_event_number(),
9807 sizeof(lsrjt_event),
9808 (char *)&lsrjt_event,
9812 if (ulp_status == IOSTAT_NPORT_BSY ||
9813 ulp_status == IOSTAT_FABRIC_BSY) {
9814 fabric_event.event_type = FC_REG_FABRIC_EVENT;
9815 if (ulp_status == IOSTAT_NPORT_BSY)
9816 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
9818 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
9819 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
9820 sizeof(struct lpfc_name));
9821 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
9822 sizeof(struct lpfc_name));
9823 fc_host_post_vendor_event(shost,
9824 fc_get_event_number(),
9825 sizeof(fabric_event),
9826 (char *)&fabric_event,
9834 * lpfc_send_els_event - Posts unsolicited els event
9835 * @vport: Pointer to vport object.
9836 * @ndlp: Pointer FC node object.
9837 * @payload: ELS command code type.
9839 * This function posts an event when there is an incoming
9840 * unsolicited ELS command.
9843 lpfc_send_els_event(struct lpfc_vport *vport,
9844 struct lpfc_nodelist *ndlp,
9847 struct lpfc_els_event_header *els_data = NULL;
9848 struct lpfc_logo_event *logo_data = NULL;
9849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9851 if (*payload == ELS_CMD_LOGO) {
9852 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
9854 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9855 "0148 Failed to allocate memory "
9856 "for LOGO event\n");
9859 els_data = &logo_data->header;
9861 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
9864 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9865 "0149 Failed to allocate memory "
9870 els_data->event_type = FC_REG_ELS_EVENT;
9873 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
9876 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
9879 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
9882 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
9883 /* Copy the WWPN in the LOGO payload */
9884 memcpy(logo_data->logo_wwpn, &payload[2],
9885 sizeof(struct lpfc_name));
9891 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
9892 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
9893 if (*payload == ELS_CMD_LOGO) {
9894 fc_host_post_vendor_event(shost,
9895 fc_get_event_number(),
9896 sizeof(struct lpfc_logo_event),
9901 fc_host_post_vendor_event(shost,
9902 fc_get_event_number(),
9903 sizeof(struct lpfc_els_event_header),
9913 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
9914 FC_FPIN_LI_EVT_TYPES_INIT);
9916 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types,
9917 FC_FPIN_DELI_EVT_TYPES_INIT);
9919 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types,
9920 FC_FPIN_CONGN_EVT_TYPES_INIT);
9922 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm,
9923 fc_fpin_congn_severity_types,
9924 FC_FPIN_CONGN_SEVERITY_INIT);
9928 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port
9929 * @phba: Pointer to phba object.
9930 * @wwnlist: Pointer to list of WWPNs in FPIN payload
9931 * @cnt: count of WWPNs in FPIN payload
9933 * This routine is called by LI and PC descriptors.
9934 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message
9937 lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt)
9939 char buf[LPFC_FPIN_WWPN_LINE_SZ];
9947 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:");
9948 for (i = 0; i < cnt; i++) {
9949 /* Are we on the last WWPN */
9953 /* Extract the next WWPN from the payload */
9955 wwpn = be64_to_cpu(wwn);
9956 len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len,
9959 /* Log a message if we are on the last WWPN
9960 * or if we hit the max allowed per message.
9963 if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) {
9965 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9968 /* Check if we reached the last WWPN */
9972 /* Limit the number of log message displayed per FPIN */
9974 if (line == LPFC_FPIN_WWPN_NUM_LINE) {
9975 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9976 "4687 %d WWPNs Truncated\n",
9981 /* Start over with next log message */
9983 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ,
9984 "Additional WWPNs:");
9990 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
9991 * @phba: Pointer to phba object.
9992 * @tlv: Pointer to the Link Integrity Notification Descriptor.
9994 * This function processes a Link Integrity FPIN event by logging a message.
9997 lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9999 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
10000 const char *li_evt_str;
10003 li_evt = be16_to_cpu(li->event_type);
10004 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
10005 cnt = be32_to_cpu(li->pname_count);
10007 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
10008 "4680 FPIN Link Integrity %s (x%x) "
10009 "Detecting PN x%016llx Attached PN x%016llx "
10010 "Duration %d mSecs Count %d Port Cnt %d\n",
10011 li_evt_str, li_evt,
10012 be64_to_cpu(li->detecting_wwpn),
10013 be64_to_cpu(li->attached_wwpn),
10014 be32_to_cpu(li->event_threshold),
10015 be32_to_cpu(li->event_count), cnt);
10017 lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt);
10021 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event.
10022 * @phba: Pointer to hba object.
10023 * @tlv: Pointer to the Delivery Notification Descriptor TLV
10025 * This function processes a Delivery FPIN event by logging a message.
10028 lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
10030 struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv;
10031 const char *del_rsn_str;
10035 del_rsn = be16_to_cpu(del->deli_reason_code);
10036 del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn);
10038 /* Skip over desc_tag/desc_len header to payload */
10039 frame = (__be32 *)(del + 1);
10041 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
10042 "4681 FPIN Delivery %s (x%x) "
10043 "Detecting PN x%016llx Attached PN x%016llx "
10045 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x "
10046 "DiscHdr4 x%08x DiscHdr5 x%08x\n",
10047 del_rsn_str, del_rsn,
10048 be64_to_cpu(del->detecting_wwpn),
10049 be64_to_cpu(del->attached_wwpn),
10050 be32_to_cpu(frame[0]),
10051 be32_to_cpu(frame[1]),
10052 be32_to_cpu(frame[2]),
10053 be32_to_cpu(frame[3]),
10054 be32_to_cpu(frame[4]),
10055 be32_to_cpu(frame[5]));
10059 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event.
10060 * @phba: Pointer to hba object.
10061 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV
10063 * This function processes a Peer Congestion FPIN event by logging a message.
10066 lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
10068 struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv;
10069 const char *pc_evt_str;
10072 pc_evt = be16_to_cpu(pc->event_type);
10073 pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt);
10074 cnt = be32_to_cpu(pc->pname_count);
10076 /* Capture FPIN frequency */
10077 phba->cgn_fpin_frequency = be32_to_cpu(pc->event_period);
10079 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS,
10080 "4684 FPIN Peer Congestion %s (x%x) "
10081 "Duration %d mSecs "
10082 "Detecting PN x%016llx Attached PN x%016llx "
10083 "Impacted Port Cnt %d\n",
10084 pc_evt_str, pc_evt,
10085 be32_to_cpu(pc->event_period),
10086 be64_to_cpu(pc->detecting_wwpn),
10087 be64_to_cpu(pc->attached_wwpn),
10090 lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt);
10094 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification
10095 * @phba: Pointer to hba object.
10096 * @tlv: Pointer to the Congestion Notification Descriptor TLV
10098 * This function processes an FPIN Congestion Notifiction. The notification
10099 * could be an Alarm or Warning. This routine feeds that data into driver's
10100 * running congestion algorithm. It also processes the FPIN by
10101 * logging a message. It returns 1 to indicate deliver this message
10102 * to the upper layer or 0 to indicate don't deliver it.
10105 lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
10107 struct lpfc_cgn_info *cp;
10108 struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv;
10109 const char *cgn_evt_str;
10111 const char *cgn_sev_str;
10115 bool nm_log = false;
10118 cgn_evt = be16_to_cpu(cgn->event_type);
10119 cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt);
10120 cgn_sev = cgn->severity;
10121 cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev);
10123 /* The driver only takes action on a Credit Stall or Oversubscription
10124 * event type to engage the IO algorithm. The driver prints an
10125 * unmaskable message only for Lost Credit and Credit Stall.
10126 * TODO: Still need to have definition of host action on clear,
10127 * lost credit and device specific event types.
10130 case FPIN_CONGN_LOST_CREDIT:
10133 case FPIN_CONGN_CREDIT_STALL:
10136 case FPIN_CONGN_OVERSUBSCRIPTION:
10137 if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION)
10140 case FPIN_CONGN_SEVERITY_ERROR:
10141 /* Take action here for an Alarm event */
10142 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
10143 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) {
10144 /* Track of alarm cnt for SYNC_WQE */
10145 atomic_inc(&phba->cgn_sync_alarm_cnt);
10147 /* Track alarm cnt for cgn_info regardless
10148 * of whether CMF is configured for Signals
10151 atomic_inc(&phba->cgn_fabric_alarm_cnt);
10155 case FPIN_CONGN_SEVERITY_WARNING:
10156 /* Take action here for a Warning event */
10157 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
10158 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) {
10159 /* Track of warning cnt for SYNC_WQE */
10160 atomic_inc(&phba->cgn_sync_warn_cnt);
10162 /* Track warning cnt and freq for cgn_info
10163 * regardless of whether CMF is configured for
10164 * Signals or FPINs.
10166 atomic_inc(&phba->cgn_fabric_warn_cnt);
10168 /* Save frequency in ms */
10169 phba->cgn_fpin_frequency =
10170 be32_to_cpu(cgn->event_period);
10171 value = phba->cgn_fpin_frequency;
10173 cp = (struct lpfc_cgn_info *)
10175 cp->cgn_alarm_freq =
10176 cpu_to_le16(value);
10177 cp->cgn_warn_freq =
10178 cpu_to_le16(value);
10179 crc = lpfc_cgn_calc_crc32
10182 LPFC_CGN_CRC32_SEED);
10183 cp->cgn_info_crc = cpu_to_le32(crc);
10186 /* Don't deliver to upper layer since
10187 * driver took action on this tlv.
10196 /* Change the log level to unmaskable for the following event types. */
10197 lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO),
10198 LOG_CGN_MGMT | LOG_ELS,
10199 "4683 FPIN CONGESTION %s type %s (x%x) Event "
10200 "Duration %d mSecs\n",
10201 cgn_sev_str, cgn_evt_str, cgn_evt,
10202 be32_to_cpu(cgn->event_period));
10207 lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length)
10209 struct lpfc_hba *phba = vport->phba;
10210 struct fc_els_fpin *fpin = (struct fc_els_fpin *)p;
10211 struct fc_tlv_desc *tlv, *first_tlv, *current_tlv;
10212 const char *dtag_nm;
10213 int desc_cnt = 0, bytes_remain, cnt;
10214 u32 dtag, deliver = 0;
10217 /* FPINs handled only if we are in the right discovery state */
10218 if (vport->port_state < LPFC_DISC_AUTH)
10221 /* make sure there is the full fpin header */
10222 if (fpin_length < sizeof(struct fc_els_fpin))
10225 /* Sanity check descriptor length. The desc_len value does not
10226 * include space for the ELS command and the desc_len fields.
10228 len = be32_to_cpu(fpin->desc_len);
10229 if (fpin_length < len + sizeof(struct fc_els_fpin)) {
10230 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10231 "4671 Bad ELS FPIN length %d: %d\n",
10236 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
10238 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
10239 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
10241 /* process each descriptor separately */
10242 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
10243 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
10244 dtag = be32_to_cpu(tlv->desc_tag);
10246 case ELS_DTAG_LNK_INTEGRITY:
10247 lpfc_els_rcv_fpin_li(phba, tlv);
10250 case ELS_DTAG_DELIVERY:
10251 lpfc_els_rcv_fpin_del(phba, tlv);
10254 case ELS_DTAG_PEER_CONGEST:
10255 lpfc_els_rcv_fpin_peer_cgn(phba, tlv);
10258 case ELS_DTAG_CONGESTION:
10259 deliver = lpfc_els_rcv_fpin_cgn(phba, tlv);
10262 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10263 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10264 "4678 unknown FPIN descriptor[%d]: "
10266 desc_cnt, dtag, dtag_nm);
10268 /* If descriptor is bad, drop the rest of the data */
10271 lpfc_cgn_update_stat(phba, dtag);
10272 cnt = be32_to_cpu(tlv->desc_len);
10274 /* Sanity check descriptor length. The desc_len value does not
10275 * include space for the desc_tag and the desc_len fields.
10277 len -= (cnt + sizeof(struct fc_tlv_desc));
10279 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10280 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10281 "4672 Bad FPIN descriptor TLV length "
10283 cnt, len, fpin_length, dtag_nm);
10288 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
10289 tlv = fc_tlv_next_desc(tlv);
10291 /* Format payload such that the FPIN delivered to the
10292 * upper layer is a single descriptor FPIN.
10295 memcpy(first_tlv, current_tlv,
10296 (cnt + sizeof(struct fc_els_fpin)));
10298 /* Adjust the length so that it only reflects a
10299 * single descriptor FPIN.
10301 fpin_length = cnt + sizeof(struct fc_els_fpin);
10302 fpin->desc_len = cpu_to_be32(fpin_length);
10303 fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */
10305 /* Send every descriptor individually to the upper layer */
10307 fc_host_fpin_rcv(lpfc_shost_from_vport(vport),
10308 fpin_length, (char *)fpin, 0);
10314 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
10315 * @phba: pointer to lpfc hba data structure.
10316 * @pring: pointer to a SLI ring.
10317 * @vport: pointer to a host virtual N_Port data structure.
10318 * @elsiocb: pointer to lpfc els command iocb data structure.
10320 * This routine is used for processing the IOCB associated with a unsolicited
10321 * event. It first determines whether there is an existing ndlp that matches
10322 * the DID from the unsolicited IOCB. If not, it will create a new one with
10323 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
10324 * IOCB is then used to invoke the proper routine and to set up proper state
10325 * of the discovery state machine.
10328 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10329 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
10331 struct lpfc_nodelist *ndlp;
10332 struct ls_rjt stat;
10333 u32 *payload, payload_len;
10334 u32 cmd = 0, did = 0, newnode, status = 0;
10335 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
10336 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10337 LPFC_MBOXQ_t *mbox;
10339 if (!vport || !elsiocb->cmd_dmabuf)
10343 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10344 payload = elsiocb->cmd_dmabuf->virt;
10345 if (phba->sli_rev == LPFC_SLI_REV4)
10346 payload_len = wcqe_cmpl->total_data_placed;
10348 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
10349 status = get_job_ulpstatus(phba, elsiocb);
10351 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
10352 lpfc_sli3_post_buffer(phba, pring, 1);
10354 did = get_job_els_rsp64_did(phba, elsiocb);
10356 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10357 "RCV Unsol ELS: status:x%x/x%x did:x%x",
10358 status, get_job_word4(phba, elsiocb), did);
10362 /* Check to see if link went down during discovery */
10363 if (lpfc_els_chk_latt(vport))
10366 /* Ignore traffic received during vport shutdown. */
10367 if (test_bit(FC_UNLOADING, &vport->load_flag))
10370 /* If NPort discovery is delayed drop incoming ELS */
10371 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag) &&
10372 cmd != ELS_CMD_PLOGI)
10375 ndlp = lpfc_findnode_did(vport, did);
10377 /* Cannot find existing Fabric ndlp, so allocate a new one */
10378 ndlp = lpfc_nlp_init(vport, did);
10381 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10383 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
10384 ndlp->nlp_type |= NLP_FABRIC;
10385 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
10386 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10390 phba->fc_stat.elsRcvFrame++;
10393 * Do not process any unsolicited ELS commands
10394 * if the ndlp is in DEV_LOSS
10396 spin_lock_irq(&ndlp->lock);
10397 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
10398 spin_unlock_irq(&ndlp->lock);
10400 lpfc_nlp_put(ndlp);
10403 spin_unlock_irq(&ndlp->lock);
10405 elsiocb->ndlp = lpfc_nlp_get(ndlp);
10406 if (!elsiocb->ndlp)
10408 elsiocb->vport = vport;
10410 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
10411 cmd &= ELS_CMD_MASK;
10413 /* ELS command <elsCmd> received from NPORT <did> */
10414 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10415 "0112 ELS command x%x received from NPORT x%x "
10416 "refcnt %d Data: x%x x%lx x%x x%x\n",
10417 cmd, did, kref_read(&ndlp->kref), vport->port_state,
10418 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
10420 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
10421 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
10422 (cmd != ELS_CMD_FLOGI) &&
10423 !((cmd == ELS_CMD_PLOGI) && test_bit(FC_PT2PT, &vport->fc_flag))) {
10424 rjt_err = LSRJT_LOGICAL_BSY;
10425 rjt_exp = LSEXP_NOTHING_MORE;
10430 case ELS_CMD_PLOGI:
10431 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10432 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
10433 did, vport->port_state, ndlp->nlp_flag);
10435 phba->fc_stat.elsRcvPLOGI++;
10436 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
10437 if (phba->sli_rev == LPFC_SLI_REV4 &&
10438 test_bit(FC_PT2PT, &phba->pport->fc_flag)) {
10439 vport->fc_prevDID = vport->fc_myDID;
10440 /* Our DID needs to be updated before registering
10441 * the vfi. This is done in lpfc_rcv_plogi but
10442 * that is called after the reg_vfi.
10445 bf_get(els_rsp64_sid,
10446 &elsiocb->wqe.xmit_els_rsp);
10447 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10448 "3312 Remote port assigned DID x%x "
10449 "%x\n", vport->fc_myDID,
10450 vport->fc_prevDID);
10453 lpfc_send_els_event(vport, ndlp, payload);
10455 /* If Nport discovery is delayed, reject PLOGIs */
10456 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) {
10457 rjt_err = LSRJT_UNABLE_TPC;
10458 rjt_exp = LSEXP_NOTHING_MORE;
10462 if (vport->port_state < LPFC_DISC_AUTH) {
10463 if (!test_bit(FC_PT2PT, &phba->pport->fc_flag) ||
10464 test_bit(FC_PT2PT_PLOGI, &phba->pport->fc_flag)) {
10465 rjt_err = LSRJT_UNABLE_TPC;
10466 rjt_exp = LSEXP_NOTHING_MORE;
10471 spin_lock_irq(&ndlp->lock);
10472 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
10473 spin_unlock_irq(&ndlp->lock);
10475 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10476 NLP_EVT_RCV_PLOGI);
10479 case ELS_CMD_FLOGI:
10480 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10481 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
10482 did, vport->port_state, ndlp->nlp_flag);
10484 phba->fc_stat.elsRcvFLOGI++;
10486 /* If the driver believes fabric discovery is done and is ready,
10487 * bounce the link. There is some descrepancy.
10489 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
10490 test_bit(FC_PT2PT, &vport->fc_flag) &&
10491 vport->rcv_flogi_cnt >= 1) {
10492 rjt_err = LSRJT_LOGICAL_BSY;
10493 rjt_exp = LSEXP_NOTHING_MORE;
10498 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
10499 /* retain node if our response is deferred */
10500 if (phba->defer_flogi_acc_flag)
10503 lpfc_disc_state_machine(vport, ndlp, NULL,
10504 NLP_EVT_DEVICE_RM);
10507 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10508 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
10509 did, vport->port_state, ndlp->nlp_flag);
10511 phba->fc_stat.elsRcvLOGO++;
10512 lpfc_send_els_event(vport, ndlp, payload);
10513 if (vport->port_state < LPFC_DISC_AUTH) {
10514 rjt_err = LSRJT_UNABLE_TPC;
10515 rjt_exp = LSEXP_NOTHING_MORE;
10518 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
10520 lpfc_disc_state_machine(vport, ndlp, NULL,
10521 NLP_EVT_DEVICE_RM);
10524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10525 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
10526 did, vport->port_state, ndlp->nlp_flag);
10528 phba->fc_stat.elsRcvPRLO++;
10529 lpfc_send_els_event(vport, ndlp, payload);
10530 if (vport->port_state < LPFC_DISC_AUTH) {
10531 rjt_err = LSRJT_UNABLE_TPC;
10532 rjt_exp = LSEXP_NOTHING_MORE;
10535 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
10538 phba->fc_stat.elsRcvLCB++;
10539 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
10542 phba->fc_stat.elsRcvRDP++;
10543 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
10546 phba->fc_stat.elsRcvRSCN++;
10547 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
10549 lpfc_disc_state_machine(vport, ndlp, NULL,
10550 NLP_EVT_DEVICE_RM);
10552 case ELS_CMD_ADISC:
10553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10554 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
10555 did, vport->port_state, ndlp->nlp_flag);
10557 lpfc_send_els_event(vport, ndlp, payload);
10558 phba->fc_stat.elsRcvADISC++;
10559 if (vport->port_state < LPFC_DISC_AUTH) {
10560 rjt_err = LSRJT_UNABLE_TPC;
10561 rjt_exp = LSEXP_NOTHING_MORE;
10564 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10565 NLP_EVT_RCV_ADISC);
10567 case ELS_CMD_PDISC:
10568 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10569 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
10570 did, vport->port_state, ndlp->nlp_flag);
10572 phba->fc_stat.elsRcvPDISC++;
10573 if (vport->port_state < LPFC_DISC_AUTH) {
10574 rjt_err = LSRJT_UNABLE_TPC;
10575 rjt_exp = LSEXP_NOTHING_MORE;
10578 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10579 NLP_EVT_RCV_PDISC);
10581 case ELS_CMD_FARPR:
10582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10583 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
10584 did, vport->port_state, ndlp->nlp_flag);
10586 phba->fc_stat.elsRcvFARPR++;
10587 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
10590 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10591 "RCV FARP: did:x%x/ste:x%x flg:x%x",
10592 did, vport->port_state, ndlp->nlp_flag);
10594 phba->fc_stat.elsRcvFARP++;
10595 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
10598 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10599 "RCV FAN: did:x%x/ste:x%x flg:x%x",
10600 did, vport->port_state, ndlp->nlp_flag);
10602 phba->fc_stat.elsRcvFAN++;
10603 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
10606 case ELS_CMD_NVMEPRLI:
10607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10608 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
10609 did, vport->port_state, ndlp->nlp_flag);
10611 phba->fc_stat.elsRcvPRLI++;
10612 if ((vport->port_state < LPFC_DISC_AUTH) &&
10613 test_bit(FC_FABRIC, &vport->fc_flag)) {
10614 rjt_err = LSRJT_UNABLE_TPC;
10615 rjt_exp = LSEXP_NOTHING_MORE;
10618 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
10621 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10622 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
10623 did, vport->port_state, ndlp->nlp_flag);
10625 phba->fc_stat.elsRcvLIRR++;
10626 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
10628 lpfc_disc_state_machine(vport, ndlp, NULL,
10629 NLP_EVT_DEVICE_RM);
10632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10633 "RCV RLS: did:x%x/ste:x%x flg:x%x",
10634 did, vport->port_state, ndlp->nlp_flag);
10636 phba->fc_stat.elsRcvRLS++;
10637 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
10639 lpfc_disc_state_machine(vport, ndlp, NULL,
10640 NLP_EVT_DEVICE_RM);
10643 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10644 "RCV RPL: did:x%x/ste:x%x flg:x%x",
10645 did, vport->port_state, ndlp->nlp_flag);
10647 phba->fc_stat.elsRcvRPL++;
10648 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
10650 lpfc_disc_state_machine(vport, ndlp, NULL,
10651 NLP_EVT_DEVICE_RM);
10654 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10655 "RCV RNID: did:x%x/ste:x%x flg:x%x",
10656 did, vport->port_state, ndlp->nlp_flag);
10658 phba->fc_stat.elsRcvRNID++;
10659 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
10661 lpfc_disc_state_machine(vport, ndlp, NULL,
10662 NLP_EVT_DEVICE_RM);
10665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10666 "RCV RTV: did:x%x/ste:x%x flg:x%x",
10667 did, vport->port_state, ndlp->nlp_flag);
10668 phba->fc_stat.elsRcvRTV++;
10669 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
10671 lpfc_disc_state_machine(vport, ndlp, NULL,
10672 NLP_EVT_DEVICE_RM);
10675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10676 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
10677 did, vport->port_state, ndlp->nlp_flag);
10679 phba->fc_stat.elsRcvRRQ++;
10680 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
10682 lpfc_disc_state_machine(vport, ndlp, NULL,
10683 NLP_EVT_DEVICE_RM);
10686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10687 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
10688 did, vport->port_state, ndlp->nlp_flag);
10690 phba->fc_stat.elsRcvECHO++;
10691 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
10693 lpfc_disc_state_machine(vport, ndlp, NULL,
10694 NLP_EVT_DEVICE_RM);
10697 /* receive this due to exchange closed */
10698 rjt_err = LSRJT_UNABLE_TPC;
10699 rjt_exp = LSEXP_INVALID_OX_RX;
10702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10703 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
10704 did, vport->port_state, ndlp->nlp_flag);
10706 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
10709 /* There are no replies, so no rjt codes */
10712 lpfc_els_rcv_edc(vport, elsiocb, ndlp);
10715 phba->fc_stat.elsRcvRDF++;
10716 /* Accept RDF only from fabric controller */
10717 if (did != Fabric_Cntl_DID) {
10718 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
10719 "1115 Received RDF from invalid DID "
10721 rjt_err = LSRJT_PROTOCOL_ERR;
10722 rjt_exp = LSEXP_NOTHING_MORE;
10726 lpfc_els_rcv_rdf(vport, elsiocb, ndlp);
10729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10730 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
10731 cmd, did, vport->port_state);
10733 /* Unsupported ELS command, reject */
10734 rjt_err = LSRJT_CMD_UNSUPPORTED;
10735 rjt_exp = LSEXP_NOTHING_MORE;
10737 /* Unknown ELS command <elsCmd> received from NPORT <did> */
10738 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10739 "0115 Unknown ELS command x%x "
10740 "received from NPORT x%x\n", cmd, did);
10742 lpfc_disc_state_machine(vport, ndlp, NULL,
10743 NLP_EVT_DEVICE_RM);
10748 /* check if need to LS_RJT received ELS cmd */
10750 memset(&stat, 0, sizeof(stat));
10751 stat.un.b.lsRjtRsnCode = rjt_err;
10752 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
10753 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
10755 /* Remove the reference from above for new nodes. */
10757 lpfc_disc_state_machine(vport, ndlp, NULL,
10758 NLP_EVT_DEVICE_RM);
10761 /* Release the reference on this elsiocb, not the ndlp. */
10762 lpfc_nlp_put(elsiocb->ndlp);
10763 elsiocb->ndlp = NULL;
10765 /* Special case. Driver received an unsolicited command that
10766 * unsupportable given the driver's current state. Reset the
10767 * link and start over.
10770 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10773 lpfc_linkdown(phba);
10774 lpfc_init_link(phba, mbox,
10775 phba->cfg_topology,
10776 phba->cfg_link_speed);
10777 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
10778 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10779 mbox->vport = vport;
10780 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
10782 mempool_free(mbox, phba->mbox_mem_pool);
10788 if (vport && !test_bit(FC_UNLOADING, &vport->load_flag))
10789 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10790 "0111 Dropping received ELS cmd "
10791 "Data: x%x x%x x%x x%x\n",
10792 cmd, status, get_job_word4(phba, elsiocb), did);
10794 phba->fc_stat.elsRcvDrop++;
10798 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
10799 * @phba: pointer to lpfc hba data structure.
10800 * @pring: pointer to a SLI ring.
10801 * @elsiocb: pointer to lpfc els iocb data structure.
10803 * This routine is used to process an unsolicited event received from a SLI
10804 * (Service Level Interface) ring. The actual processing of the data buffer
10805 * associated with the unsolicited event is done by invoking the routine
10806 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
10807 * SLI ring on which the unsolicited event was received.
10810 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10811 struct lpfc_iocbq *elsiocb)
10813 struct lpfc_vport *vport = elsiocb->vport;
10814 u32 ulp_command, status, parameter, bde_count = 0;
10816 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10817 struct lpfc_dmabuf *bdeBuf1 = elsiocb->cmd_dmabuf;
10818 struct lpfc_dmabuf *bdeBuf2 = elsiocb->bpl_dmabuf;
10821 elsiocb->cmd_dmabuf = NULL;
10822 elsiocb->rsp_dmabuf = NULL;
10823 elsiocb->bpl_dmabuf = NULL;
10825 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10826 ulp_command = get_job_cmnd(phba, elsiocb);
10827 status = get_job_ulpstatus(phba, elsiocb);
10828 parameter = get_job_word4(phba, elsiocb);
10829 if (phba->sli_rev == LPFC_SLI_REV4)
10830 bde_count = wcqe_cmpl->word3;
10832 bde_count = elsiocb->iocb.ulpBdeCount;
10834 if (status == IOSTAT_NEED_BUFFER) {
10835 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
10836 } else if (status == IOSTAT_LOCAL_REJECT &&
10837 (parameter & IOERR_PARAM_MASK) ==
10838 IOERR_RCV_BUFFER_WAITING) {
10839 phba->fc_stat.NoRcvBuf++;
10840 /* Not enough posted buffers; Try posting more buffers */
10841 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
10842 lpfc_sli3_post_buffer(phba, pring, 0);
10846 if (phba->sli_rev == LPFC_SLI_REV3) {
10847 icmd = &elsiocb->iocb;
10848 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
10849 (ulp_command == CMD_IOCB_RCV_ELS64_CX ||
10850 ulp_command == CMD_IOCB_RCV_SEQ64_CX)) {
10851 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
10852 vport = phba->pport;
10854 vport = lpfc_find_vport_by_vpid(phba,
10855 icmd->unsli3.rcvsli3.vpi);
10859 /* If there are no BDEs associated
10860 * with this IOCB, there is nothing to do.
10862 if (bde_count == 0)
10865 /* Account for SLI2 or SLI3 and later unsolicited buffering */
10866 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
10867 elsiocb->cmd_dmabuf = bdeBuf1;
10868 if (bde_count == 2)
10869 elsiocb->bpl_dmabuf = bdeBuf2;
10871 icmd = &elsiocb->iocb;
10872 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
10873 icmd->un.cont64[0].addrLow);
10874 elsiocb->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring,
10876 if (bde_count == 2) {
10877 paddr = getPaddr(icmd->un.cont64[1].addrHigh,
10878 icmd->un.cont64[1].addrLow);
10879 elsiocb->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba,
10885 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
10887 * The different unsolicited event handlers would tell us
10888 * if they are done with "mp" by setting cmd_dmabuf to NULL.
10890 if (elsiocb->cmd_dmabuf) {
10891 lpfc_in_buf_free(phba, elsiocb->cmd_dmabuf);
10892 elsiocb->cmd_dmabuf = NULL;
10895 if (elsiocb->bpl_dmabuf) {
10896 lpfc_in_buf_free(phba, elsiocb->bpl_dmabuf);
10897 elsiocb->bpl_dmabuf = NULL;
10903 lpfc_start_fdmi(struct lpfc_vport *vport)
10905 struct lpfc_nodelist *ndlp;
10907 /* If this is the first time, allocate an ndlp and initialize
10908 * it. Otherwise, make sure the node is enabled and then do the
10911 ndlp = lpfc_findnode_did(vport, FDMI_DID);
10913 ndlp = lpfc_nlp_init(vport, FDMI_DID);
10915 ndlp->nlp_type |= NLP_FABRIC;
10921 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10922 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
10926 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
10927 * @phba: pointer to lpfc hba data structure.
10928 * @vport: pointer to a virtual N_Port data structure.
10930 * This routine issues a Port Login (PLOGI) to the Name Server with
10931 * State Change Request (SCR) for a @vport. This routine will create an
10932 * ndlp for the Name Server associated to the @vport if such node does
10933 * not already exist. The PLOGI to Name Server is issued by invoking the
10934 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
10935 * (FDMI) is configured to the @vport, a FDMI node will be created and
10936 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
10939 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
10941 struct lpfc_nodelist *ndlp;
10944 * If lpfc_delay_discovery parameter is set and the clean address
10945 * bit is cleared and fc fabric parameters chenged, delay FC NPort
10948 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) {
10949 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10950 "3334 Delay fc port discovery for %d secs\n",
10952 mod_timer(&vport->delayed_disc_tmo,
10953 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
10957 ndlp = lpfc_findnode_did(vport, NameServer_DID);
10959 ndlp = lpfc_nlp_init(vport, NameServer_DID);
10961 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
10962 lpfc_disc_start(vport);
10965 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10966 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10967 "0251 NameServer login: no memory\n");
10972 ndlp->nlp_type |= NLP_FABRIC;
10974 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10976 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
10977 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10978 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10979 "0252 Cannot issue NameServer login\n");
10983 if ((phba->cfg_enable_SmartSAN ||
10984 phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) &&
10985 test_bit(FC_ALLOW_FDMI, &vport->load_flag))
10986 lpfc_start_fdmi(vport);
10990 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
10991 * @phba: pointer to lpfc hba data structure.
10992 * @pmb: pointer to the driver internal queue element for mailbox command.
10994 * This routine is the completion callback function to register new vport
10995 * mailbox command. If the new vport mailbox command completes successfully,
10996 * the fabric registration login shall be performed on physical port (the
10997 * new vport created is actually a physical port, with VPI 0) or the port
10998 * login to Name Server for State Change Request (SCR) will be performed
10999 * on virtual port (real virtual port, with VPI greater than 0).
11002 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
11004 struct lpfc_vport *vport = pmb->vport;
11005 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
11006 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
11007 MAILBOX_t *mb = &pmb->u.mb;
11010 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11012 if (mb->mbxStatus) {
11013 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11014 "0915 Register VPI failed : Status: x%x"
11015 " upd bit: x%x \n", mb->mbxStatus,
11016 mb->un.varRegVpi.upd);
11017 if (phba->sli_rev == LPFC_SLI_REV4 &&
11018 mb->un.varRegVpi.upd)
11019 goto mbox_err_exit ;
11021 switch (mb->mbxStatus) {
11022 case 0x11: /* unsupported feature */
11023 case 0x9603: /* max_vpi exceeded */
11024 case 0x9602: /* Link event since CLEAR_LA */
11025 /* giving up on vport registration */
11026 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11027 clear_bit(FC_FABRIC, &vport->fc_flag);
11028 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
11029 lpfc_can_disctmo(vport);
11031 /* If reg_vpi fail with invalid VPI status, re-init VPI */
11033 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11034 lpfc_init_vpi(phba, pmb, vport->vpi);
11035 pmb->vport = vport;
11036 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
11037 rc = lpfc_sli_issue_mbox(phba, pmb,
11039 if (rc == MBX_NOT_FINISHED) {
11040 lpfc_printf_vlog(vport, KERN_ERR,
11042 "2732 Failed to issue INIT_VPI"
11043 " mailbox command\n");
11045 lpfc_nlp_put(ndlp);
11050 /* Try to recover from this error */
11051 if (phba->sli_rev == LPFC_SLI_REV4)
11052 lpfc_sli4_unreg_all_rpis(vport);
11053 lpfc_mbx_unreg_vpi(vport);
11054 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11055 if (mb->mbxStatus == MBX_NOT_FINISHED)
11057 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
11058 !test_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag)) {
11059 if (phba->sli_rev == LPFC_SLI_REV4)
11060 lpfc_issue_init_vfi(vport);
11062 lpfc_initial_flogi(vport);
11064 lpfc_initial_fdisc(vport);
11069 spin_lock_irq(shost->host_lock);
11070 vport->vpi_state |= LPFC_VPI_REGISTERED;
11071 spin_unlock_irq(shost->host_lock);
11072 if (vport == phba->pport) {
11073 if (phba->sli_rev < LPFC_SLI_REV4)
11074 lpfc_issue_fabric_reglogin(vport);
11077 * If the physical port is instantiated using
11078 * FDISC, do not start vport discovery.
11080 if (vport->port_state != LPFC_FDISC)
11081 lpfc_start_fdiscs(phba);
11082 lpfc_do_scr_ns_plogi(phba, vport);
11085 lpfc_do_scr_ns_plogi(phba, vport);
11089 /* Now, we decrement the ndlp reference count held for this
11090 * callback function
11092 lpfc_nlp_put(ndlp);
11094 mempool_free(pmb, phba->mbox_mem_pool);
11096 /* reinitialize the VMID datastructure before returning.
11097 * this is specifically for vport
11099 if (lpfc_is_vmid_enabled(phba))
11100 lpfc_reinit_vmid(vport);
11101 vport->vmid_flag = vport->phba->pport->vmid_flag;
11107 * lpfc_register_new_vport - Register a new vport with a HBA
11108 * @phba: pointer to lpfc hba data structure.
11109 * @vport: pointer to a host virtual N_Port data structure.
11110 * @ndlp: pointer to a node-list data structure.
11112 * This routine registers the @vport as a new virtual port with a HBA.
11113 * It is done through a registering vpi mailbox command.
11116 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
11117 struct lpfc_nodelist *ndlp)
11119 LPFC_MBOXQ_t *mbox;
11121 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11123 lpfc_reg_vpi(vport, mbox);
11124 mbox->vport = vport;
11125 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
11126 if (!mbox->ctx_ndlp) {
11127 mempool_free(mbox, phba->mbox_mem_pool);
11128 goto mbox_err_exit;
11131 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
11132 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
11133 == MBX_NOT_FINISHED) {
11134 /* mailbox command not success, decrement ndlp
11135 * reference count for this command
11137 lpfc_nlp_put(ndlp);
11138 mempool_free(mbox, phba->mbox_mem_pool);
11140 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11141 "0253 Register VPI: Can't send mbox\n");
11142 goto mbox_err_exit;
11145 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11146 "0254 Register VPI: no memory\n");
11147 goto mbox_err_exit;
11152 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11153 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11158 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
11159 * @phba: pointer to lpfc hba data structure.
11161 * This routine cancels the retry delay timers to all the vports.
11164 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
11166 struct lpfc_vport **vports;
11167 struct lpfc_nodelist *ndlp;
11168 uint32_t link_state;
11171 /* Treat this failure as linkdown for all vports */
11172 link_state = phba->link_state;
11173 lpfc_linkdown(phba);
11174 phba->link_state = link_state;
11176 vports = lpfc_create_vport_work_array(phba);
11179 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11180 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
11182 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
11183 lpfc_els_flush_cmd(vports[i]);
11185 lpfc_destroy_vport_work_array(phba, vports);
11190 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
11191 * @phba: pointer to lpfc hba data structure.
11193 * This routine abort all pending discovery commands and
11194 * start a timer to retry FLOGI for the physical port
11198 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
11200 struct lpfc_nodelist *ndlp;
11202 /* Cancel the all vports retry delay retry timers */
11203 lpfc_cancel_all_vport_retry_delay_timer(phba);
11205 /* If fabric require FLOGI, then re-instantiate physical login */
11206 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
11210 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
11211 spin_lock_irq(&ndlp->lock);
11212 ndlp->nlp_flag |= NLP_DELAY_TMO;
11213 spin_unlock_irq(&ndlp->lock);
11214 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
11215 phba->pport->port_state = LPFC_FLOGI;
11220 * lpfc_fabric_login_reqd - Check if FLOGI required.
11221 * @phba: pointer to lpfc hba data structure.
11222 * @cmdiocb: pointer to FDISC command iocb.
11223 * @rspiocb: pointer to FDISC response iocb.
11225 * This routine checks if a FLOGI is reguired for FDISC
11229 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
11230 struct lpfc_iocbq *cmdiocb,
11231 struct lpfc_iocbq *rspiocb)
11233 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11234 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11236 if (ulp_status != IOSTAT_FABRIC_RJT ||
11237 ulp_word4 != RJT_LOGIN_REQUIRED)
11244 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
11245 * @phba: pointer to lpfc hba data structure.
11246 * @cmdiocb: pointer to lpfc command iocb data structure.
11247 * @rspiocb: pointer to lpfc response iocb data structure.
11249 * This routine is the completion callback function to a Fabric Discover
11250 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
11251 * single threaded, each FDISC completion callback function will reset
11252 * the discovery timer for all vports such that the timers will not get
11253 * unnecessary timeout. The function checks the FDISC IOCB status. If error
11254 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
11255 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
11256 * assigned to the vport has been changed with the completion of the FDISC
11257 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
11258 * are unregistered from the HBA, and then the lpfc_register_new_vport()
11259 * routine is invoked to register new vport with the HBA. Otherwise, the
11260 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
11261 * Server for State Change Request (SCR).
11264 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11265 struct lpfc_iocbq *rspiocb)
11267 struct lpfc_vport *vport = cmdiocb->vport;
11268 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
11269 struct lpfc_nodelist *np;
11270 struct lpfc_nodelist *next_np;
11271 struct lpfc_iocbq *piocb;
11272 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
11273 struct serv_parm *sp;
11274 uint8_t fabric_param_changed;
11275 u32 ulp_status, ulp_word4;
11277 ulp_status = get_job_ulpstatus(phba, rspiocb);
11278 ulp_word4 = get_job_word4(phba, rspiocb);
11280 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11281 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
11282 ulp_status, ulp_word4,
11283 vport->fc_prevDID);
11284 /* Since all FDISCs are being single threaded, we
11285 * must reset the discovery timer for ALL vports
11286 * waiting to send FDISC when one completes.
11288 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
11289 lpfc_set_disctmo(piocb->vport);
11292 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11293 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
11294 ulp_status, ulp_word4, vport->fc_prevDID);
11298 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
11299 lpfc_retry_pport_discovery(phba);
11303 /* Check for retry */
11304 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
11307 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11308 "0126 FDISC failed. (x%x/x%x)\n",
11309 ulp_status, ulp_word4);
11313 lpfc_check_nlp_post_devloss(vport, ndlp);
11315 clear_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag);
11316 clear_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag);
11317 set_bit(FC_FABRIC, &vport->fc_flag);
11318 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
11319 set_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
11321 vport->fc_myDID = ulp_word4 & Mask_DID;
11322 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
11323 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
11326 if (!lpfc_is_els_acc_rsp(prsp))
11329 sp = prsp->virt + sizeof(uint32_t);
11330 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
11331 memcpy(&vport->fabric_portname, &sp->portName,
11332 sizeof(struct lpfc_name));
11333 memcpy(&vport->fabric_nodename, &sp->nodeName,
11334 sizeof(struct lpfc_name));
11335 if (fabric_param_changed &&
11336 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
11337 /* If our NportID changed, we need to ensure all
11338 * remaining NPORTs get unreg_login'ed so we can
11341 list_for_each_entry_safe(np, next_np,
11342 &vport->fc_nodes, nlp_listp) {
11343 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
11344 !(np->nlp_flag & NLP_NPR_ADISC))
11346 spin_lock_irq(&ndlp->lock);
11347 np->nlp_flag &= ~NLP_NPR_ADISC;
11348 spin_unlock_irq(&ndlp->lock);
11349 lpfc_unreg_rpi(vport, np);
11351 lpfc_cleanup_pending_mbox(vport);
11353 if (phba->sli_rev == LPFC_SLI_REV4)
11354 lpfc_sli4_unreg_all_rpis(vport);
11356 lpfc_mbx_unreg_vpi(vport);
11357 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11358 if (phba->sli_rev == LPFC_SLI_REV4)
11359 set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag);
11361 set_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag);
11362 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
11363 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
11365 * Driver needs to re-reg VPI in order for f/w
11366 * to update the MAC address.
11368 lpfc_register_new_vport(phba, vport, ndlp);
11369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11373 if (test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag))
11374 lpfc_issue_init_vpi(vport);
11375 else if (test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag))
11376 lpfc_register_new_vport(phba, vport, ndlp);
11378 lpfc_do_scr_ns_plogi(phba, vport);
11380 /* The FDISC completed successfully. Move the fabric ndlp to
11381 * UNMAPPED state and register with the transport.
11383 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11387 if (vport->fc_vport &&
11388 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
11389 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11390 /* Cancel discovery timer */
11391 lpfc_can_disctmo(vport);
11393 lpfc_els_free_iocb(phba, cmdiocb);
11394 lpfc_nlp_put(ndlp);
11398 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
11399 * @vport: pointer to a virtual N_Port data structure.
11400 * @ndlp: pointer to a node-list data structure.
11401 * @retry: number of retries to the command IOCB.
11403 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
11404 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
11405 * routine to issue the IOCB, which makes sure only one outstanding fabric
11406 * IOCB will be sent off HBA at any given time.
11408 * Note that the ndlp reference count will be incremented by 1 for holding the
11409 * ndlp and the reference to ndlp will be stored into the ndlp field of
11410 * the IOCB for the completion callback function to the FDISC ELS command.
11413 * 0 - Successfully issued fdisc iocb command
11414 * 1 - Failed to issue fdisc iocb command
11417 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
11420 struct lpfc_hba *phba = vport->phba;
11422 union lpfc_wqe128 *wqe = NULL;
11423 struct lpfc_iocbq *elsiocb;
11424 struct serv_parm *sp;
11427 int did = ndlp->nlp_DID;
11430 vport->port_state = LPFC_FDISC;
11431 vport->fc_myDID = 0;
11432 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
11433 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
11436 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11437 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11438 "0255 Issue FDISC: no IOCB\n");
11442 if (phba->sli_rev == LPFC_SLI_REV4) {
11443 wqe = &elsiocb->wqe;
11444 bf_set(els_req64_sid, &wqe->els_req, 0);
11445 bf_set(els_req64_sp, &wqe->els_req, 1);
11447 icmd = &elsiocb->iocb;
11448 icmd->un.elsreq64.myID = 0;
11449 icmd->un.elsreq64.fl = 1;
11454 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
11455 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
11456 pcmd += sizeof(uint32_t); /* CSP Word 1 */
11457 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
11458 sp = (struct serv_parm *) pcmd;
11459 /* Setup CSPs accordingly for Fabric */
11460 sp->cmn.e_d_tov = 0;
11461 sp->cmn.w2.r_a_tov = 0;
11462 sp->cmn.virtual_fabric_support = 0;
11463 sp->cls1.classValid = 0;
11464 sp->cls2.seqDelivery = 1;
11465 sp->cls3.seqDelivery = 1;
11467 pcmd += sizeof(uint32_t); /* CSP Word 2 */
11468 pcmd += sizeof(uint32_t); /* CSP Word 3 */
11469 pcmd += sizeof(uint32_t); /* CSP Word 4 */
11470 pcmd += sizeof(uint32_t); /* Port Name */
11471 memcpy(pcmd, &vport->fc_portname, 8);
11472 pcmd += sizeof(uint32_t); /* Node Name */
11473 pcmd += sizeof(uint32_t); /* Node Name */
11474 memcpy(pcmd, &vport->fc_nodename, 8);
11475 sp->cmn.valid_vendor_ver_level = 0;
11476 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
11477 lpfc_set_disctmo(vport);
11479 phba->fc_stat.elsXmitFDISC++;
11480 elsiocb->cmd_cmpl = lpfc_cmpl_els_fdisc;
11482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11483 "Issue FDISC: did:x%x",
11486 elsiocb->ndlp = lpfc_nlp_get(ndlp);
11487 if (!elsiocb->ndlp)
11490 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
11491 if (rc == IOCB_ERROR) {
11492 lpfc_nlp_put(ndlp);
11496 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
11500 lpfc_els_free_iocb(phba, elsiocb);
11501 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11502 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11503 "0256 Issue FDISC: Cannot send IOCB\n");
11508 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
11509 * @phba: pointer to lpfc hba data structure.
11510 * @cmdiocb: pointer to lpfc command iocb data structure.
11511 * @rspiocb: pointer to lpfc response iocb data structure.
11513 * This routine is the completion callback function to the issuing of a LOGO
11514 * ELS command off a vport. It frees the command IOCB and then decrement the
11515 * reference count held on ndlp for this completion function, indicating that
11516 * the reference to the ndlp is no long needed. Note that the
11517 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
11518 * callback function and an additional explicit ndlp reference decrementation
11519 * will trigger the actual release of the ndlp.
11522 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11523 struct lpfc_iocbq *rspiocb)
11525 struct lpfc_vport *vport = cmdiocb->vport;
11527 struct lpfc_nodelist *ndlp;
11528 u32 ulp_status, ulp_word4, did, tmo;
11530 ndlp = cmdiocb->ndlp;
11532 ulp_status = get_job_ulpstatus(phba, rspiocb);
11533 ulp_word4 = get_job_word4(phba, rspiocb);
11535 if (phba->sli_rev == LPFC_SLI_REV4) {
11536 did = get_job_els_rsp64_did(phba, cmdiocb);
11537 tmo = get_wqe_tmo(cmdiocb);
11539 irsp = &rspiocb->iocb;
11540 did = get_job_els_rsp64_did(phba, rspiocb);
11541 tmo = irsp->ulpTimeout;
11544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11545 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
11546 ulp_status, ulp_word4, did);
11548 /* NPIV LOGO completes to NPort <nlp_DID> */
11549 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11550 "2928 NPIV LOGO completes to NPort x%x "
11551 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
11552 ndlp->nlp_DID, ulp_status, ulp_word4,
11553 tmo, vport->num_disc_nodes,
11554 kref_read(&ndlp->kref), ndlp->nlp_flag,
11555 ndlp->fc4_xpt_flags);
11557 if (ulp_status == IOSTAT_SUCCESS) {
11558 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag);
11559 clear_bit(FC_FABRIC, &vport->fc_flag);
11560 lpfc_can_disctmo(vport);
11563 if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
11564 /* Wake up lpfc_vport_delete if waiting...*/
11565 if (ndlp->logo_waitq)
11566 wake_up(ndlp->logo_waitq);
11567 spin_lock_irq(&ndlp->lock);
11568 ndlp->nlp_flag &= ~(NLP_ISSUE_LOGO | NLP_LOGO_SND);
11569 ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
11570 spin_unlock_irq(&ndlp->lock);
11573 /* Safe to release resources now. */
11574 lpfc_els_free_iocb(phba, cmdiocb);
11575 lpfc_nlp_put(ndlp);
11579 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
11580 * @vport: pointer to a virtual N_Port data structure.
11581 * @ndlp: pointer to a node-list data structure.
11583 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
11585 * Note that the ndlp reference count will be incremented by 1 for holding the
11586 * ndlp and the reference to ndlp will be stored into the ndlp field of
11587 * the IOCB for the completion callback function to the LOGO ELS command.
11590 * 0 - Successfully issued logo off the @vport
11591 * 1 - Failed to issue logo off the @vport
11594 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
11597 struct lpfc_hba *phba = vport->phba;
11598 struct lpfc_iocbq *elsiocb;
11602 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
11603 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
11608 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
11609 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
11610 pcmd += sizeof(uint32_t);
11612 /* Fill in LOGO payload */
11613 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
11614 pcmd += sizeof(uint32_t);
11615 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
11617 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11618 "Issue LOGO npiv did:x%x flg:x%x",
11619 ndlp->nlp_DID, ndlp->nlp_flag, 0);
11621 elsiocb->cmd_cmpl = lpfc_cmpl_els_npiv_logo;
11622 spin_lock_irq(&ndlp->lock);
11623 ndlp->nlp_flag |= NLP_LOGO_SND;
11624 spin_unlock_irq(&ndlp->lock);
11625 elsiocb->ndlp = lpfc_nlp_get(ndlp);
11626 if (!elsiocb->ndlp) {
11627 lpfc_els_free_iocb(phba, elsiocb);
11631 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
11632 if (rc == IOCB_ERROR) {
11633 lpfc_els_free_iocb(phba, elsiocb);
11634 lpfc_nlp_put(ndlp);
11640 spin_lock_irq(&ndlp->lock);
11641 ndlp->nlp_flag &= ~NLP_LOGO_SND;
11642 spin_unlock_irq(&ndlp->lock);
11647 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
11648 * @t: timer context used to obtain the lpfc hba.
11650 * This routine is invoked by the fabric iocb block timer after
11651 * timeout. It posts the fabric iocb block timeout event by setting the
11652 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
11653 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
11654 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
11655 * posted event WORKER_FABRIC_BLOCK_TMO.
11658 lpfc_fabric_block_timeout(struct timer_list *t)
11660 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
11661 unsigned long iflags;
11662 uint32_t tmo_posted;
11664 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
11665 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
11667 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
11668 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
11671 lpfc_worker_wake_up(phba);
11676 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
11677 * @phba: pointer to lpfc hba data structure.
11679 * This routine issues one fabric iocb from the driver internal list to
11680 * the HBA. It first checks whether it's ready to issue one fabric iocb to
11681 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
11682 * remove one pending fabric iocb from the driver internal list and invokes
11683 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
11686 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
11688 struct lpfc_iocbq *iocb;
11689 unsigned long iflags;
11694 spin_lock_irqsave(&phba->hbalock, iflags);
11695 /* Post any pending iocb to the SLI layer */
11696 if (atomic_read(&phba->fabric_iocb_count) == 0) {
11697 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
11700 /* Increment fabric iocb count to hold the position */
11701 atomic_inc(&phba->fabric_iocb_count);
11703 spin_unlock_irqrestore(&phba->hbalock, iflags);
11705 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11706 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11707 iocb->cmd_flag |= LPFC_IO_FABRIC;
11709 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11710 "Fabric sched1: ste:x%x",
11711 iocb->vport->port_state, 0, 0);
11713 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11715 if (ret == IOCB_ERROR) {
11716 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11717 iocb->fabric_cmd_cmpl = NULL;
11718 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11719 set_job_ulpstatus(iocb, IOSTAT_LOCAL_REJECT);
11720 iocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
11721 iocb->cmd_cmpl(phba, iocb, iocb);
11723 atomic_dec(&phba->fabric_iocb_count);
11730 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
11731 * @phba: pointer to lpfc hba data structure.
11733 * This routine unblocks the issuing fabric iocb command. The function
11734 * will clear the fabric iocb block bit and then invoke the routine
11735 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
11736 * from the driver internal fabric iocb list.
11739 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
11741 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11743 lpfc_resume_fabric_iocbs(phba);
11748 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
11749 * @phba: pointer to lpfc hba data structure.
11751 * This routine blocks the issuing fabric iocb for a specified amount of
11752 * time (currently 100 ms). This is done by set the fabric iocb block bit
11753 * and set up a timeout timer for 100ms. When the block bit is set, no more
11754 * fabric iocb will be issued out of the HBA.
11757 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
11761 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11762 /* Start a timer to unblock fabric iocbs after 100ms */
11764 mod_timer(&phba->fabric_block_timer,
11765 jiffies + msecs_to_jiffies(100));
11771 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
11772 * @phba: pointer to lpfc hba data structure.
11773 * @cmdiocb: pointer to lpfc command iocb data structure.
11774 * @rspiocb: pointer to lpfc response iocb data structure.
11776 * This routine is the callback function that is put to the fabric iocb's
11777 * callback function pointer (iocb->cmd_cmpl). The original iocb's callback
11778 * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback
11779 * function first restores and invokes the original iocb's callback function
11780 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
11781 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
11784 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11785 struct lpfc_iocbq *rspiocb)
11787 struct ls_rjt stat;
11788 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11789 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11791 WARN_ON((cmdiocb->cmd_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
11793 switch (ulp_status) {
11794 case IOSTAT_NPORT_RJT:
11795 case IOSTAT_FABRIC_RJT:
11796 if (ulp_word4 & RJT_UNAVAIL_TEMP)
11797 lpfc_block_fabric_iocbs(phba);
11800 case IOSTAT_NPORT_BSY:
11801 case IOSTAT_FABRIC_BSY:
11802 lpfc_block_fabric_iocbs(phba);
11805 case IOSTAT_LS_RJT:
11806 stat.un.ls_rjt_error_be =
11807 cpu_to_be32(ulp_word4);
11808 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
11809 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
11810 lpfc_block_fabric_iocbs(phba);
11814 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
11816 cmdiocb->cmd_cmpl = cmdiocb->fabric_cmd_cmpl;
11817 cmdiocb->fabric_cmd_cmpl = NULL;
11818 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
11819 cmdiocb->cmd_cmpl(phba, cmdiocb, rspiocb);
11821 atomic_dec(&phba->fabric_iocb_count);
11822 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
11823 /* Post any pending iocbs to HBA */
11824 lpfc_resume_fabric_iocbs(phba);
11829 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
11830 * @phba: pointer to lpfc hba data structure.
11831 * @iocb: pointer to lpfc command iocb data structure.
11833 * This routine is used as the top-level API for issuing a fabric iocb command
11834 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
11835 * function makes sure that only one fabric bound iocb will be outstanding at
11836 * any given time. As such, this function will first check to see whether there
11837 * is already an outstanding fabric iocb on the wire. If so, it will put the
11838 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
11839 * issued later. Otherwise, it will issue the iocb on the wire and update the
11840 * fabric iocb count it indicate that there is one fabric iocb on the wire.
11842 * Note, this implementation has a potential sending out fabric IOCBs out of
11843 * order. The problem is caused by the construction of the "ready" boolen does
11844 * not include the condition that the internal fabric IOCB list is empty. As
11845 * such, it is possible a fabric IOCB issued by this routine might be "jump"
11846 * ahead of the fabric IOCBs in the internal list.
11849 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
11850 * IOCB_ERROR - failed to issue fabric iocb
11853 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
11855 unsigned long iflags;
11859 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
11861 spin_lock_irqsave(&phba->hbalock, iflags);
11862 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
11863 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11866 /* Increment fabric iocb count to hold the position */
11867 atomic_inc(&phba->fabric_iocb_count);
11868 spin_unlock_irqrestore(&phba->hbalock, iflags);
11870 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11871 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11872 iocb->cmd_flag |= LPFC_IO_FABRIC;
11874 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11875 "Fabric sched2: ste:x%x",
11876 iocb->vport->port_state, 0, 0);
11878 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11880 if (ret == IOCB_ERROR) {
11881 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11882 iocb->fabric_cmd_cmpl = NULL;
11883 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11884 atomic_dec(&phba->fabric_iocb_count);
11887 spin_lock_irqsave(&phba->hbalock, iflags);
11888 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
11889 spin_unlock_irqrestore(&phba->hbalock, iflags);
11890 ret = IOCB_SUCCESS;
11896 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
11897 * @vport: pointer to a virtual N_Port data structure.
11899 * This routine aborts all the IOCBs associated with a @vport from the
11900 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11901 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11902 * list, removes each IOCB associated with the @vport off the list, set the
11903 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11904 * associated with the IOCB.
11906 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
11908 LIST_HEAD(completions);
11909 struct lpfc_hba *phba = vport->phba;
11910 struct lpfc_iocbq *tmp_iocb, *piocb;
11912 spin_lock_irq(&phba->hbalock);
11913 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11916 if (piocb->vport != vport)
11919 list_move_tail(&piocb->list, &completions);
11921 spin_unlock_irq(&phba->hbalock);
11923 /* Cancel all the IOCBs from the completions list */
11924 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11925 IOERR_SLI_ABORTED);
11929 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
11930 * @ndlp: pointer to a node-list data structure.
11932 * This routine aborts all the IOCBs associated with an @ndlp from the
11933 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11934 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11935 * list, removes each IOCB associated with the @ndlp off the list, set the
11936 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11937 * associated with the IOCB.
11939 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
11941 LIST_HEAD(completions);
11942 struct lpfc_hba *phba = ndlp->phba;
11943 struct lpfc_iocbq *tmp_iocb, *piocb;
11944 struct lpfc_sli_ring *pring;
11946 pring = lpfc_phba_elsring(phba);
11948 if (unlikely(!pring))
11951 spin_lock_irq(&phba->hbalock);
11952 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11954 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
11956 list_move_tail(&piocb->list, &completions);
11959 spin_unlock_irq(&phba->hbalock);
11961 /* Cancel all the IOCBs from the completions list */
11962 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11963 IOERR_SLI_ABORTED);
11967 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
11968 * @phba: pointer to lpfc hba data structure.
11970 * This routine aborts all the IOCBs currently on the driver internal
11971 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
11972 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
11973 * list, removes IOCBs off the list, set the status field to
11974 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
11977 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
11979 LIST_HEAD(completions);
11981 spin_lock_irq(&phba->hbalock);
11982 list_splice_init(&phba->fabric_iocb_list, &completions);
11983 spin_unlock_irq(&phba->hbalock);
11985 /* Cancel all the IOCBs from the completions list */
11986 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11987 IOERR_SLI_ABORTED);
11991 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
11992 * @vport: pointer to lpfc vport data structure.
11994 * This routine is invoked by the vport cleanup for deletions and the cleanup
11995 * for an ndlp on removal.
11998 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
12000 struct lpfc_hba *phba = vport->phba;
12001 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
12002 struct lpfc_nodelist *ndlp = NULL;
12003 unsigned long iflag = 0;
12005 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
12006 list_for_each_entry_safe(sglq_entry, sglq_next,
12007 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
12008 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
12009 lpfc_nlp_put(sglq_entry->ndlp);
12010 ndlp = sglq_entry->ndlp;
12011 sglq_entry->ndlp = NULL;
12013 /* If the xri on the abts_els_sgl list is for the Fport
12014 * node and the vport is unloading, the xri aborted wcqe
12015 * likely isn't coming back. Just release the sgl.
12017 if (test_bit(FC_UNLOADING, &vport->load_flag) &&
12018 ndlp->nlp_DID == Fabric_DID) {
12019 list_del(&sglq_entry->list);
12020 sglq_entry->state = SGL_FREED;
12021 list_add_tail(&sglq_entry->list,
12022 &phba->sli4_hba.lpfc_els_sgl_list);
12026 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
12031 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
12032 * @phba: pointer to lpfc hba data structure.
12033 * @axri: pointer to the els xri abort wcqe structure.
12035 * This routine is invoked by the worker thread to process a SLI4 slow-path
12039 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
12040 struct sli4_wcqe_xri_aborted *axri)
12042 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
12043 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
12046 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
12047 unsigned long iflag = 0;
12048 struct lpfc_nodelist *ndlp;
12049 struct lpfc_sli_ring *pring;
12051 pring = lpfc_phba_elsring(phba);
12053 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
12054 list_for_each_entry_safe(sglq_entry, sglq_next,
12055 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
12056 if (sglq_entry->sli4_xritag == xri) {
12057 list_del(&sglq_entry->list);
12058 ndlp = sglq_entry->ndlp;
12059 sglq_entry->ndlp = NULL;
12060 list_add_tail(&sglq_entry->list,
12061 &phba->sli4_hba.lpfc_els_sgl_list);
12062 sglq_entry->state = SGL_FREED;
12063 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
12067 lpfc_set_rrq_active(phba, ndlp,
12068 sglq_entry->sli4_lxritag,
12070 lpfc_nlp_put(ndlp);
12073 /* Check if TXQ queue needs to be serviced */
12074 if (pring && !list_empty(&pring->txq))
12075 lpfc_worker_wake_up(phba);
12079 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
12080 lxri = lpfc_sli4_xri_inrange(phba, xri);
12081 if (lxri == NO_XRI)
12084 spin_lock_irqsave(&phba->hbalock, iflag);
12085 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
12086 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
12087 spin_unlock_irqrestore(&phba->hbalock, iflag);
12090 sglq_entry->state = SGL_XRI_ABORTED;
12091 spin_unlock_irqrestore(&phba->hbalock, iflag);
12095 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
12096 * @vport: pointer to virtual port object.
12097 * @ndlp: nodelist pointer for the impacted node.
12099 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
12100 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
12101 * the driver is required to send a LOGO to the remote node before it
12102 * attempts to recover its login to the remote node.
12105 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
12106 struct lpfc_nodelist *ndlp)
12108 struct Scsi_Host *shost;
12109 struct lpfc_hba *phba;
12110 unsigned long flags = 0;
12112 shost = lpfc_shost_from_vport(vport);
12113 phba = vport->phba;
12114 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
12115 lpfc_printf_log(phba, KERN_INFO,
12116 LOG_SLI, "3093 No rport recovery needed. "
12117 "rport in state 0x%x\n", ndlp->nlp_state);
12120 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12121 "3094 Start rport recovery on shost id 0x%x "
12122 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
12124 shost->host_no, ndlp->nlp_DID,
12125 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
12128 * The rport is not responding. Remove the FCP-2 flag to prevent
12129 * an ADISC in the follow-up recovery code.
12131 spin_lock_irqsave(&ndlp->lock, flags);
12132 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
12133 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
12134 spin_unlock_irqrestore(&ndlp->lock, flags);
12135 lpfc_unreg_rpi(vport, ndlp);
12138 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport)
12140 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE);
12144 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max)
12148 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE))
12151 for (i = min; i <= max; i++)
12152 set_bit(i, vport->vmid_priority_range);
12155 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid)
12157 set_bit(ctcl_vmid, vport->vmid_priority_range);
12160 u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport)
12164 i = find_first_bit(vport->vmid_priority_range,
12165 LPFC_VMID_MAX_PRIORITY_RANGE);
12167 if (i == LPFC_VMID_MAX_PRIORITY_RANGE)
12170 clear_bit(i, vport->vmid_priority_range);
12174 #define MAX_PRIORITY_DESC 255
12177 lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12178 struct lpfc_iocbq *rspiocb)
12180 struct lpfc_vport *vport = cmdiocb->vport;
12181 struct priority_range_desc *desc;
12182 struct lpfc_dmabuf *prsp = NULL;
12183 struct lpfc_vmid_priority_range *vmid_range = NULL;
12185 struct lpfc_dmabuf *dmabuf = cmdiocb->cmd_dmabuf;
12186 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
12187 u32 ulp_word4 = get_job_word4(phba, rspiocb);
12188 u8 *pcmd, max_desc;
12190 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
12192 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
12197 data = (u32 *)pcmd;
12198 if (data[0] == ELS_CMD_LS_RJT) {
12199 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12200 "3277 QFPA LS_RJT x%x x%x\n",
12205 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
12206 "6529 QFPA failed with status x%x x%x\n",
12207 ulp_status, ulp_word4);
12211 if (!vport->qfpa_res) {
12212 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res);
12213 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res),
12215 if (!vport->qfpa_res)
12219 len = *((u32 *)(pcmd + 4));
12220 len = be32_to_cpu(len);
12221 memcpy(vport->qfpa_res, pcmd, len + 8);
12222 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE;
12224 desc = (struct priority_range_desc *)(pcmd + 8);
12225 vmid_range = vport->vmid_priority.vmid_range;
12227 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range),
12230 kfree(vport->qfpa_res);
12233 vport->vmid_priority.vmid_range = vmid_range;
12235 vport->vmid_priority.num_descriptors = len;
12237 for (i = 0; i < len; i++, vmid_range++, desc++) {
12238 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12239 "6539 vmid values low=%d, high=%d, qos=%d, "
12240 "local ve id=%d\n", desc->lo_range,
12241 desc->hi_range, desc->qos_priority,
12242 desc->local_ve_id);
12244 vmid_range->low = desc->lo_range << 1;
12245 if (desc->local_ve_id == QFPA_ODD_ONLY)
12247 if (desc->qos_priority)
12248 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED;
12249 vmid_range->qos = desc->qos_priority;
12251 vmid_range->high = desc->hi_range << 1;
12252 if ((desc->local_ve_id == QFPA_ODD_ONLY) ||
12253 (desc->local_ve_id == QFPA_EVEN_ODD))
12254 vmid_range->high++;
12256 lpfc_init_cs_ctl_bitmap(vport);
12257 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) {
12258 lpfc_vmid_set_cs_ctl_range(vport,
12259 vport->vmid_priority.vmid_range[i].low,
12260 vport->vmid_priority.vmid_range[i].high);
12263 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL;
12265 lpfc_els_free_iocb(phba, cmdiocb);
12266 lpfc_nlp_put(ndlp);
12269 int lpfc_issue_els_qfpa(struct lpfc_vport *vport)
12271 struct lpfc_hba *phba = vport->phba;
12272 struct lpfc_nodelist *ndlp;
12273 struct lpfc_iocbq *elsiocb;
12277 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
12278 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12281 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp,
12282 ndlp->nlp_DID, ELS_CMD_QFPA);
12286 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
12288 *((u32 *)(pcmd)) = ELS_CMD_QFPA;
12291 elsiocb->cmd_cmpl = lpfc_cmpl_els_qfpa;
12293 elsiocb->ndlp = lpfc_nlp_get(ndlp);
12294 if (!elsiocb->ndlp) {
12295 lpfc_els_free_iocb(vport->phba, elsiocb);
12299 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2);
12300 if (ret != IOCB_SUCCESS) {
12301 lpfc_els_free_iocb(phba, elsiocb);
12302 lpfc_nlp_put(ndlp);
12305 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED;
12310 lpfc_vmid_uvem(struct lpfc_vport *vport,
12311 struct lpfc_vmid *vmid, bool instantiated)
12313 struct lpfc_vem_id_desc *vem_id_desc;
12314 struct lpfc_nodelist *ndlp;
12315 struct lpfc_iocbq *elsiocb;
12316 struct instantiated_ve_desc *inst_desc;
12317 struct lpfc_vmid_context *vmid_context;
12322 ndlp = lpfc_findnode_did(vport, Fabric_DID);
12323 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12326 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL);
12329 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2,
12330 ndlp, Fabric_DID, ELS_CMD_UVEM);
12334 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12335 "3427 Host vmid %s %d\n",
12336 vmid->host_vmid, instantiated);
12337 vmid_context->vmp = vmid;
12338 vmid_context->nlp = ndlp;
12339 vmid_context->instantiated = instantiated;
12340 elsiocb->vmid_tag.vmid_context = vmid_context;
12341 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
12343 if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0,
12344 sizeof(vport->lpfc_vmid_host_uuid)))
12345 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid,
12346 sizeof(vport->lpfc_vmid_host_uuid));
12348 *((u32 *)(pcmd)) = ELS_CMD_UVEM;
12349 len = (u32 *)(pcmd + 4);
12350 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8);
12352 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8);
12353 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG);
12354 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE);
12355 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid,
12356 sizeof(vem_id_desc->vem_id));
12358 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32);
12359 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12360 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE);
12361 memcpy(inst_desc->global_vem_id, vmid->host_vmid,
12362 sizeof(inst_desc->global_vem_id));
12364 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID);
12365 bf_set(lpfc_instantiated_local_id, inst_desc,
12366 vmid->un.cs_ctl_vmid);
12367 if (instantiated) {
12368 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12370 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG);
12371 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid);
12373 inst_desc->word6 = cpu_to_be32(inst_desc->word6);
12375 elsiocb->cmd_cmpl = lpfc_cmpl_els_uvem;
12377 elsiocb->ndlp = lpfc_nlp_get(ndlp);
12378 if (!elsiocb->ndlp) {
12379 lpfc_els_free_iocb(vport->phba, elsiocb);
12383 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0);
12384 if (ret != IOCB_SUCCESS) {
12385 lpfc_els_free_iocb(vport->phba, elsiocb);
12386 lpfc_nlp_put(ndlp);
12392 kfree(vmid_context);
12397 lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb,
12398 struct lpfc_iocbq *rspiocb)
12400 struct lpfc_vport *vport = icmdiocb->vport;
12401 struct lpfc_dmabuf *prsp = NULL;
12402 struct lpfc_vmid_context *vmid_context =
12403 icmdiocb->vmid_tag.vmid_context;
12404 struct lpfc_nodelist *ndlp = icmdiocb->ndlp;
12407 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
12408 u32 ulp_word4 = get_job_word4(phba, rspiocb);
12409 struct lpfc_dmabuf *dmabuf = icmdiocb->cmd_dmabuf;
12410 struct lpfc_vmid *vmid;
12412 vmid = vmid_context->vmp;
12413 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12416 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
12420 data = (u32 *)pcmd;
12421 if (data[0] == ELS_CMD_LS_RJT) {
12422 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12423 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]);
12427 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12428 "4533 UVEM error status %x: %x\n",
12429 ulp_status, ulp_word4);
12432 spin_lock(&phba->hbalock);
12433 /* Set IN USE flag */
12434 vport->vmid_flag |= LPFC_VMID_IN_USE;
12435 phba->pport->vmid_flag |= LPFC_VMID_IN_USE;
12436 spin_unlock(&phba->hbalock);
12438 if (vmid_context->instantiated) {
12439 write_lock(&vport->vmid_lock);
12440 vmid->flag |= LPFC_VMID_REGISTERED;
12441 vmid->flag &= ~LPFC_VMID_REQ_REGISTER;
12442 write_unlock(&vport->vmid_lock);
12446 kfree(vmid_context);
12447 lpfc_els_free_iocb(phba, icmdiocb);
12448 lpfc_nlp_put(ndlp);