1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 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_uvem(struct lpfc_hba *, struct lpfc_iocbq *,
62 static int lpfc_max_els_tries = 3;
64 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport);
65 static void lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max);
66 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid);
69 * lpfc_els_chk_latt - Check host link attention event for a vport
70 * @vport: pointer to a host virtual N_Port data structure.
72 * This routine checks whether there is an outstanding host link
73 * attention event during the discovery process with the @vport. It is done
74 * by reading the HBA's Host Attention (HA) register. If there is any host
75 * link attention events during this @vport's discovery process, the @vport
76 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
77 * be issued if the link state is not already in host link cleared state,
78 * and a return code shall indicate whether the host link attention event
81 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
82 * state in LPFC_VPORT_READY, the request for checking host link attention
83 * event will be ignored and a return code shall indicate no host link
84 * attention event had happened.
87 * 0 - no host link attention event happened
88 * 1 - host link attention event happened
91 lpfc_els_chk_latt(struct lpfc_vport *vport)
93 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
94 struct lpfc_hba *phba = vport->phba;
97 if (vport->port_state >= LPFC_VPORT_READY ||
98 phba->link_state == LPFC_LINK_DOWN ||
99 phba->sli_rev > LPFC_SLI_REV3)
102 /* Read the HBA Host Attention Register */
103 if (lpfc_readl(phba->HAregaddr, &ha_copy))
106 if (!(ha_copy & HA_LATT))
109 /* Pending Link Event during Discovery */
110 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
111 "0237 Pending Link Event during "
112 "Discovery: State x%x\n",
113 phba->pport->port_state);
115 /* CLEAR_LA should re-enable link attention events and
116 * we should then immediately take a LATT event. The
117 * LATT processing should call lpfc_linkdown() which
118 * will cleanup any left over in-progress discovery
121 spin_lock_irq(shost->host_lock);
122 vport->fc_flag |= FC_ABORT_DISCOVERY;
123 spin_unlock_irq(shost->host_lock);
125 if (phba->link_state != LPFC_CLEAR_LA)
126 lpfc_issue_clear_la(phba, vport);
132 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
133 * @vport: pointer to a host virtual N_Port data structure.
134 * @expectRsp: flag indicating whether response is expected.
135 * @cmdSize: size of the ELS command.
136 * @retry: number of retries to the command IOCB when it fails.
137 * @ndlp: pointer to a node-list data structure.
138 * @did: destination identifier.
139 * @elscmd: the ELS command code.
141 * This routine is used for allocating a lpfc-IOCB data structure from
142 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
143 * passed into the routine for discovery state machine to issue an Extended
144 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
145 * and preparation routine that is used by all the discovery state machine
146 * routines and the ELS command-specific fields will be later set up by
147 * the individual discovery machine routines after calling this routine
148 * allocating and preparing a generic IOCB data structure. It fills in the
149 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
150 * payload and response payload (if expected). The reference count on the
151 * ndlp is incremented by 1 and the reference to the ndlp is put into
152 * context1 of the IOCB data structure for this IOCB to hold the ndlp
153 * reference for the command's callback function to access later.
156 * Pointer to the newly allocated/prepared els iocb data structure
157 * NULL - when els iocb data structure allocation/preparation failed
160 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
161 uint16_t cmdSize, uint8_t retry,
162 struct lpfc_nodelist *ndlp, uint32_t did,
165 struct lpfc_hba *phba = vport->phba;
166 struct lpfc_iocbq *elsiocb;
167 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
168 struct ulp_bde64 *bpl;
172 if (!lpfc_is_link_up(phba))
175 /* Allocate buffer for command iocb */
176 elsiocb = lpfc_sli_get_iocbq(phba);
182 * If this command is for fabric controller and HBA running
183 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
185 if ((did == Fabric_DID) &&
186 (phba->hba_flag & HBA_FIP_SUPPORT) &&
187 ((elscmd == ELS_CMD_FLOGI) ||
188 (elscmd == ELS_CMD_FDISC) ||
189 (elscmd == ELS_CMD_LOGO)))
192 elsiocb->iocb_flag |=
193 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
194 & LPFC_FIP_ELS_ID_MASK);
197 elsiocb->iocb_flag |=
198 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
199 & LPFC_FIP_ELS_ID_MASK);
202 elsiocb->iocb_flag |=
203 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
204 & LPFC_FIP_ELS_ID_MASK);
208 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
210 icmd = &elsiocb->iocb;
212 /* fill in BDEs for command */
213 /* Allocate buffer for command payload */
214 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
216 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
217 if (!pcmd || !pcmd->virt)
218 goto els_iocb_free_pcmb_exit;
220 INIT_LIST_HEAD(&pcmd->list);
222 /* Allocate buffer for response payload */
224 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
226 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
228 if (!prsp || !prsp->virt)
229 goto els_iocb_free_prsp_exit;
230 INIT_LIST_HEAD(&prsp->list);
234 /* Allocate buffer for Buffer ptr list */
235 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
237 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
239 if (!pbuflist || !pbuflist->virt)
240 goto els_iocb_free_pbuf_exit;
242 INIT_LIST_HEAD(&pbuflist->list);
245 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
246 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
247 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
248 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
250 icmd->un.elsreq64.remoteID = did; /* DID */
251 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
252 if (elscmd == ELS_CMD_FLOGI)
253 icmd->ulpTimeout = FF_DEF_RATOV * 2;
254 else if (elscmd == ELS_CMD_LOGO)
255 icmd->ulpTimeout = phba->fc_ratov;
257 icmd->ulpTimeout = phba->fc_ratov * 2;
259 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
260 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
261 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
262 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
263 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
264 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
266 icmd->ulpBdeCount = 1;
268 icmd->ulpClass = CLASS3;
271 * If we have NPIV enabled, we want to send ELS traffic by VPI.
272 * For SLI4, since the driver controls VPIs we also want to include
273 * all ELS pt2pt protocol traffic as well.
275 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
276 ((phba->sli_rev == LPFC_SLI_REV4) &&
277 (vport->fc_flag & FC_PT2PT))) {
280 icmd->un.elsreq64.myID = vport->fc_myDID;
282 /* For ELS_REQUEST64_CR, use the VPI by default */
283 icmd->ulpContext = phba->vpi_ids[vport->vpi];
287 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
288 if (elscmd == ELS_CMD_ECHO)
289 icmd->ulpCt_l = 0; /* context = invalid RPI */
291 icmd->ulpCt_l = 1; /* context = VPI */
294 bpl = (struct ulp_bde64 *) pbuflist->virt;
295 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
296 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
297 bpl->tus.f.bdeSize = cmdSize;
298 bpl->tus.f.bdeFlags = 0;
299 bpl->tus.w = le32_to_cpu(bpl->tus.w);
303 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
304 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
305 bpl->tus.f.bdeSize = FCELSSIZE;
306 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
307 bpl->tus.w = le32_to_cpu(bpl->tus.w);
310 elsiocb->context2 = pcmd;
311 elsiocb->context3 = pbuflist;
312 elsiocb->retry = retry;
313 elsiocb->vport = vport;
314 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
317 list_add(&prsp->list, &pcmd->list);
320 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
321 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
322 "0116 Xmit ELS command x%x to remote "
323 "NPORT x%x I/O tag: x%x, port state:x%x "
324 "rpi x%x fc_flag:x%x nlp_flag:x%x vport:x%p\n",
325 elscmd, did, elsiocb->iotag,
326 vport->port_state, ndlp->nlp_rpi,
327 vport->fc_flag, ndlp->nlp_flag, vport);
329 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
330 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
331 "0117 Xmit ELS response x%x to remote "
332 "NPORT x%x I/O tag: x%x, size: x%x "
333 "port_state x%x rpi x%x fc_flag x%x\n",
334 elscmd, ndlp->nlp_DID, elsiocb->iotag,
335 cmdSize, vport->port_state,
336 ndlp->nlp_rpi, vport->fc_flag);
340 els_iocb_free_pbuf_exit:
342 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
345 els_iocb_free_prsp_exit:
346 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
349 els_iocb_free_pcmb_exit:
351 lpfc_sli_release_iocbq(phba, elsiocb);
356 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
357 * @vport: pointer to a host virtual N_Port data structure.
359 * This routine issues a fabric registration login for a @vport. An
360 * active ndlp node with Fabric_DID must already exist for this @vport.
361 * The routine invokes two mailbox commands to carry out fabric registration
362 * login through the HBA firmware: the first mailbox command requests the
363 * HBA to perform link configuration for the @vport; and the second mailbox
364 * command requests the HBA to perform the actual fabric registration login
368 * 0 - successfully issued fabric registration login for @vport
369 * -ENXIO -- failed to issue fabric registration login for @vport
372 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
374 struct lpfc_hba *phba = vport->phba;
376 struct lpfc_dmabuf *mp;
377 struct lpfc_nodelist *ndlp;
378 struct serv_parm *sp;
382 sp = &phba->fc_fabparam;
383 ndlp = lpfc_findnode_did(vport, Fabric_DID);
389 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
395 vport->port_state = LPFC_FABRIC_CFG_LINK;
396 lpfc_config_link(phba, mbox);
397 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
400 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
401 if (rc == MBX_NOT_FINISHED) {
406 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
411 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
418 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
420 /* increment the reference count on ndlp to hold reference
421 * for the callback routine.
423 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
424 if (!mbox->ctx_ndlp) {
429 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
430 if (rc == MBX_NOT_FINISHED) {
432 goto fail_issue_reg_login;
437 fail_issue_reg_login:
438 /* decrement the reference count on ndlp just incremented
439 * for the failed mbox command.
443 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
444 lpfc_mbuf_free(phba, mp->virt, mp->phys);
447 mempool_free(mbox, phba->mbox_mem_pool);
450 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
451 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
452 "0249 Cannot issue Register Fabric login: Err %d\n",
458 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
459 * @vport: pointer to a host virtual N_Port data structure.
461 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
462 * the @vport. This mailbox command is necessary for SLI4 port only.
465 * 0 - successfully issued REG_VFI for @vport
466 * A failure code otherwise.
469 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
471 struct lpfc_hba *phba = vport->phba;
472 LPFC_MBOXQ_t *mboxq = NULL;
473 struct lpfc_nodelist *ndlp;
474 struct lpfc_dmabuf *dmabuf = NULL;
477 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
478 if ((phba->sli_rev == LPFC_SLI_REV4) &&
479 !(phba->link_flag & LS_LOOPBACK_MODE) &&
480 !(vport->fc_flag & FC_PT2PT)) {
481 ndlp = lpfc_findnode_did(vport, Fabric_DID);
488 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
494 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
495 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
496 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
501 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
506 memcpy(dmabuf->virt, &phba->fc_fabparam,
507 sizeof(struct serv_parm));
510 vport->port_state = LPFC_FABRIC_CFG_LINK;
512 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
514 lpfc_reg_vfi(mboxq, vport, 0);
516 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
517 mboxq->vport = vport;
518 mboxq->ctx_buf = dmabuf;
519 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
520 if (rc == MBX_NOT_FINISHED) {
528 mempool_free(mboxq, phba->mbox_mem_pool);
531 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
535 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
536 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
537 "0289 Issue Register VFI failed: Err %d\n", rc);
542 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
543 * @vport: pointer to a host virtual N_Port data structure.
545 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
546 * the @vport. This mailbox command is necessary for SLI4 port only.
549 * 0 - successfully issued REG_VFI for @vport
550 * A failure code otherwise.
553 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
555 struct lpfc_hba *phba = vport->phba;
556 struct Scsi_Host *shost;
560 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
562 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
563 "2556 UNREG_VFI mbox allocation failed"
564 "HBA state x%x\n", phba->pport->port_state);
568 lpfc_unreg_vfi(mboxq, vport);
569 mboxq->vport = vport;
570 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
572 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
573 if (rc == MBX_NOT_FINISHED) {
574 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
575 "2557 UNREG_VFI issue mbox failed rc x%x "
577 rc, phba->pport->port_state);
578 mempool_free(mboxq, phba->mbox_mem_pool);
582 shost = lpfc_shost_from_vport(vport);
583 spin_lock_irq(shost->host_lock);
584 vport->fc_flag &= ~FC_VFI_REGISTERED;
585 spin_unlock_irq(shost->host_lock);
590 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
591 * @vport: pointer to a host virtual N_Port data structure.
592 * @sp: pointer to service parameter data structure.
594 * This routine is called from FLOGI/FDISC completion handler functions.
595 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
596 * node nodename is changed in the completion service parameter else return
597 * 0. This function also set flag in the vport data structure to delay
598 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
599 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
600 * node nodename is changed in the completion service parameter.
603 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
604 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
608 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
609 struct serv_parm *sp)
611 struct lpfc_hba *phba = vport->phba;
612 uint8_t fabric_param_changed = 0;
613 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
615 if ((vport->fc_prevDID != vport->fc_myDID) ||
616 memcmp(&vport->fabric_portname, &sp->portName,
617 sizeof(struct lpfc_name)) ||
618 memcmp(&vport->fabric_nodename, &sp->nodeName,
619 sizeof(struct lpfc_name)) ||
620 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
621 fabric_param_changed = 1;
622 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
625 * Word 1 Bit 31 in common service parameter is overloaded.
626 * Word 1 Bit 31 in FLOGI request is multiple NPort request
627 * Word 1 Bit 31 in FLOGI response is clean address bit
629 * If fabric parameter is changed and clean address bit is
630 * cleared delay nport discovery if
631 * - vport->fc_prevDID != 0 (not initial discovery) OR
632 * - lpfc_delay_discovery module parameter is set.
634 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
635 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
636 spin_lock_irq(shost->host_lock);
637 vport->fc_flag |= FC_DISC_DELAYED;
638 spin_unlock_irq(shost->host_lock);
641 return fabric_param_changed;
646 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
647 * @vport: pointer to a host virtual N_Port data structure.
648 * @ndlp: pointer to a node-list data structure.
649 * @sp: pointer to service parameter data structure.
650 * @irsp: pointer to the IOCB within the lpfc response IOCB.
652 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
653 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
654 * port in a fabric topology. It properly sets up the parameters to the @ndlp
655 * from the IOCB response. It also check the newly assigned N_Port ID to the
656 * @vport against the previously assigned N_Port ID. If it is different from
657 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
658 * is invoked on all the remaining nodes with the @vport to unregister the
659 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
660 * is invoked to register login to the fabric.
663 * 0 - Success (currently, always return 0)
666 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
667 struct serv_parm *sp, IOCB_t *irsp)
669 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
670 struct lpfc_hba *phba = vport->phba;
671 struct lpfc_nodelist *np;
672 struct lpfc_nodelist *next_np;
673 uint8_t fabric_param_changed;
675 spin_lock_irq(shost->host_lock);
676 vport->fc_flag |= FC_FABRIC;
677 spin_unlock_irq(shost->host_lock);
679 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
680 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
681 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
683 phba->fc_edtovResol = sp->cmn.edtovResolution;
684 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
686 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
687 spin_lock_irq(shost->host_lock);
688 vport->fc_flag |= FC_PUBLIC_LOOP;
689 spin_unlock_irq(shost->host_lock);
692 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
693 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
694 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
695 ndlp->nlp_class_sup = 0;
696 if (sp->cls1.classValid)
697 ndlp->nlp_class_sup |= FC_COS_CLASS1;
698 if (sp->cls2.classValid)
699 ndlp->nlp_class_sup |= FC_COS_CLASS2;
700 if (sp->cls3.classValid)
701 ndlp->nlp_class_sup |= FC_COS_CLASS3;
702 if (sp->cls4.classValid)
703 ndlp->nlp_class_sup |= FC_COS_CLASS4;
704 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
705 sp->cmn.bbRcvSizeLsb;
707 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
708 if (fabric_param_changed) {
709 /* Reset FDMI attribute masks based on config parameter */
710 if (phba->cfg_enable_SmartSAN ||
711 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
712 /* Setup appropriate attribute masks */
713 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
714 if (phba->cfg_enable_SmartSAN)
715 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
717 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
719 vport->fdmi_hba_mask = 0;
720 vport->fdmi_port_mask = 0;
724 memcpy(&vport->fabric_portname, &sp->portName,
725 sizeof(struct lpfc_name));
726 memcpy(&vport->fabric_nodename, &sp->nodeName,
727 sizeof(struct lpfc_name));
728 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
730 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
731 if (sp->cmn.response_multiple_NPort) {
732 lpfc_printf_vlog(vport, KERN_WARNING,
734 "1816 FLOGI NPIV supported, "
735 "response data 0x%x\n",
736 sp->cmn.response_multiple_NPort);
737 spin_lock_irq(&phba->hbalock);
738 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
739 spin_unlock_irq(&phba->hbalock);
741 /* Because we asked f/w for NPIV it still expects us
742 to call reg_vnpid at least for the physical host */
743 lpfc_printf_vlog(vport, KERN_WARNING,
745 "1817 Fabric does not support NPIV "
746 "- configuring single port mode.\n");
747 spin_lock_irq(&phba->hbalock);
748 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
749 spin_unlock_irq(&phba->hbalock);
754 * For FC we need to do some special processing because of the SLI
755 * Port's default settings of the Common Service Parameters.
757 if ((phba->sli_rev == LPFC_SLI_REV4) &&
758 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
759 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
760 if (fabric_param_changed)
761 lpfc_unregister_fcf_prep(phba);
763 /* This should just update the VFI CSPs*/
764 if (vport->fc_flag & FC_VFI_REGISTERED)
765 lpfc_issue_reg_vfi(vport);
768 if (fabric_param_changed &&
769 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
771 /* If our NportID changed, we need to ensure all
772 * remaining NPORTs get unreg_login'ed.
774 list_for_each_entry_safe(np, next_np,
775 &vport->fc_nodes, nlp_listp) {
776 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
777 !(np->nlp_flag & NLP_NPR_ADISC))
779 spin_lock_irq(&np->lock);
780 np->nlp_flag &= ~NLP_NPR_ADISC;
781 spin_unlock_irq(&np->lock);
782 lpfc_unreg_rpi(vport, np);
784 lpfc_cleanup_pending_mbox(vport);
786 if (phba->sli_rev == LPFC_SLI_REV4) {
787 lpfc_sli4_unreg_all_rpis(vport);
788 lpfc_mbx_unreg_vpi(vport);
789 spin_lock_irq(shost->host_lock);
790 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
791 spin_unlock_irq(shost->host_lock);
795 * For SLI3 and SLI4, the VPI needs to be reregistered in
796 * response to this fabric parameter change event.
798 spin_lock_irq(shost->host_lock);
799 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
800 spin_unlock_irq(shost->host_lock);
801 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
802 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
804 * Driver needs to re-reg VPI in order for f/w
805 * to update the MAC address.
807 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
808 lpfc_register_new_vport(phba, vport, ndlp);
812 if (phba->sli_rev < LPFC_SLI_REV4) {
813 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
814 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
815 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
816 lpfc_register_new_vport(phba, vport, ndlp);
818 lpfc_issue_fabric_reglogin(vport);
820 ndlp->nlp_type |= NLP_FABRIC;
821 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
822 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
823 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
824 lpfc_start_fdiscs(phba);
825 lpfc_do_scr_ns_plogi(phba, vport);
826 } else if (vport->fc_flag & FC_VFI_REGISTERED)
827 lpfc_issue_init_vpi(vport);
829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
830 "3135 Need register VFI: (x%x/%x)\n",
831 vport->fc_prevDID, vport->fc_myDID);
832 lpfc_issue_reg_vfi(vport);
839 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
840 * @vport: pointer to a host virtual N_Port data structure.
841 * @ndlp: pointer to a node-list data structure.
842 * @sp: pointer to service parameter data structure.
844 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
845 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
846 * in a point-to-point topology. First, the @vport's N_Port Name is compared
847 * with the received N_Port Name: if the @vport's N_Port Name is greater than
848 * the received N_Port Name lexicographically, this node shall assign local
849 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
850 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
851 * this node shall just wait for the remote node to issue PLOGI and assign
859 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
860 struct serv_parm *sp)
862 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
863 struct lpfc_hba *phba = vport->phba;
867 spin_lock_irq(shost->host_lock);
868 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
869 vport->fc_flag |= FC_PT2PT;
870 spin_unlock_irq(shost->host_lock);
872 /* If we are pt2pt with another NPort, force NPIV off! */
873 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
875 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
876 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
877 lpfc_unregister_fcf_prep(phba);
879 spin_lock_irq(shost->host_lock);
880 vport->fc_flag &= ~FC_VFI_REGISTERED;
881 spin_unlock_irq(shost->host_lock);
882 phba->fc_topology_changed = 0;
885 rc = memcmp(&vport->fc_portname, &sp->portName,
886 sizeof(vport->fc_portname));
889 /* This side will initiate the PLOGI */
890 spin_lock_irq(shost->host_lock);
891 vport->fc_flag |= FC_PT2PT_PLOGI;
892 spin_unlock_irq(shost->host_lock);
895 * N_Port ID cannot be 0, set our Id to LocalID
896 * the other side will be RemoteID.
901 vport->fc_myDID = PT2PT_LocalID;
903 /* Decrement ndlp reference count indicating that ndlp can be
904 * safely released when other references to it are done.
908 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
911 * Cannot find existing Fabric ndlp, so allocate a
914 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
919 memcpy(&ndlp->nlp_portname, &sp->portName,
920 sizeof(struct lpfc_name));
921 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
922 sizeof(struct lpfc_name));
923 /* Set state will put ndlp onto node list if not already done */
924 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
925 spin_lock_irq(&ndlp->lock);
926 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
927 spin_unlock_irq(&ndlp->lock);
929 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
933 lpfc_config_link(phba, mbox);
935 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
937 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
938 if (rc == MBX_NOT_FINISHED) {
939 mempool_free(mbox, phba->mbox_mem_pool);
943 /* This side will wait for the PLOGI, decrement ndlp reference
944 * count indicating that ndlp can be released when other
945 * references to it are done.
949 /* Start discovery - this should just do CLEAR_LA */
950 lpfc_disc_start(vport);
959 * lpfc_cmpl_els_flogi - Completion callback function for flogi
960 * @phba: pointer to lpfc hba data structure.
961 * @cmdiocb: pointer to lpfc command iocb data structure.
962 * @rspiocb: pointer to lpfc response iocb data structure.
964 * This routine is the top-level completion callback function for issuing
965 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
966 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
967 * retry has been made (either immediately or delayed with lpfc_els_retry()
968 * returning 1), the command IOCB will be released and function returned.
969 * If the retry attempt has been given up (possibly reach the maximum
970 * number of retries), one additional decrement of ndlp reference shall be
971 * invoked before going out after releasing the command IOCB. This will
972 * actually release the remote node (Note, lpfc_els_free_iocb() will also
973 * invoke one decrement of ndlp reference count). If no error reported in
974 * the IOCB status, the command Port ID field is used to determine whether
975 * this is a point-to-point topology or a fabric topology: if the Port ID
976 * field is assigned, it is a fabric topology; otherwise, it is a
977 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
978 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
979 * specific topology completion conditions.
982 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
983 struct lpfc_iocbq *rspiocb)
985 struct lpfc_vport *vport = cmdiocb->vport;
986 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
987 IOCB_t *irsp = &rspiocb->iocb;
988 struct lpfc_nodelist *ndlp = cmdiocb->context1;
989 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
990 struct serv_parm *sp;
994 /* Check to see if link went down during discovery */
995 if (lpfc_els_chk_latt(vport)) {
996 /* One additional decrement on node reference count to
997 * trigger the release of the node
1003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1004 "FLOGI cmpl: status:x%x/x%x state:x%x",
1005 irsp->ulpStatus, irsp->un.ulpWord[4],
1008 if (irsp->ulpStatus) {
1010 * In case of FIP mode, perform roundrobin FCF failover
1011 * due to new FCF discovery
1013 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1014 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1015 if (phba->link_state < LPFC_LINK_UP)
1016 goto stop_rr_fcf_flogi;
1017 if ((phba->fcoe_cvl_eventtag_attn ==
1018 phba->fcoe_cvl_eventtag) &&
1019 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1020 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1022 goto stop_rr_fcf_flogi;
1024 phba->fcoe_cvl_eventtag_attn =
1025 phba->fcoe_cvl_eventtag;
1026 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1027 "2611 FLOGI failed on FCF (x%x), "
1028 "status:x%x/x%x, tmo:x%x, perform "
1029 "roundrobin FCF failover\n",
1030 phba->fcf.current_rec.fcf_indx,
1031 irsp->ulpStatus, irsp->un.ulpWord[4],
1033 lpfc_sli4_set_fcf_flogi_fail(phba,
1034 phba->fcf.current_rec.fcf_indx);
1035 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1036 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1043 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1044 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1045 IOERR_LOOP_OPEN_FAILURE)))
1046 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1047 "2858 FLOGI failure Status:x%x/x%x TMO"
1048 ":x%x Data x%x x%x\n",
1049 irsp->ulpStatus, irsp->un.ulpWord[4],
1050 irsp->ulpTimeout, phba->hba_flag,
1051 phba->fcf.fcf_flag);
1053 /* Check for retry */
1054 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1057 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1058 "0150 FLOGI failure Status:x%x/x%x "
1059 "xri x%x TMO:x%x\n",
1060 irsp->ulpStatus, irsp->un.ulpWord[4],
1061 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1063 /* If this is not a loop open failure, bail out */
1064 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1065 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1066 IOERR_LOOP_OPEN_FAILURE)))
1069 /* FLOGI failed, so there is no fabric */
1070 spin_lock_irq(shost->host_lock);
1071 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1072 spin_unlock_irq(shost->host_lock);
1074 /* If private loop, then allow max outstanding els to be
1075 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1076 * alpa map would take too long otherwise.
1078 if (phba->alpa_map[0] == 0)
1079 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1080 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1081 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1082 (vport->fc_prevDID != vport->fc_myDID) ||
1083 phba->fc_topology_changed)) {
1084 if (vport->fc_flag & FC_VFI_REGISTERED) {
1085 if (phba->fc_topology_changed) {
1086 lpfc_unregister_fcf_prep(phba);
1087 spin_lock_irq(shost->host_lock);
1088 vport->fc_flag &= ~FC_VFI_REGISTERED;
1089 spin_unlock_irq(shost->host_lock);
1090 phba->fc_topology_changed = 0;
1092 lpfc_sli4_unreg_all_rpis(vport);
1096 /* Do not register VFI if the driver aborted FLOGI */
1097 if (!lpfc_error_lost_link(irsp))
1098 lpfc_issue_reg_vfi(vport);
1105 spin_lock_irq(shost->host_lock);
1106 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1107 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1108 spin_unlock_irq(shost->host_lock);
1111 * The FLogI succeeded. Sync the data for the CPU before
1114 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1117 sp = prsp->virt + sizeof(uint32_t);
1119 /* FLOGI completes successfully */
1120 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1121 "0101 FLOGI completes successfully, I/O tag:x%x, "
1122 "xri x%x Data: x%x x%x x%x x%x x%x x%x x%x\n",
1123 cmdiocb->iotag, cmdiocb->sli4_xritag,
1124 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1125 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1126 vport->port_state, vport->fc_flag,
1127 sp->cmn.priority_tagging);
1129 if (sp->cmn.priority_tagging)
1130 vport->vmid_flag |= LPFC_VMID_ISSUE_QFPA;
1132 if (vport->port_state == LPFC_FLOGI) {
1134 * If Common Service Parameters indicate Nport
1135 * we are point to point, if Fport we are Fabric.
1138 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1139 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1140 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1142 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1143 "2831 FLOGI response with cleared Fabric "
1144 "bit fcf_index 0x%x "
1145 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1147 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1148 phba->fcf.current_rec.fcf_indx,
1149 phba->fcf.current_rec.switch_name[0],
1150 phba->fcf.current_rec.switch_name[1],
1151 phba->fcf.current_rec.switch_name[2],
1152 phba->fcf.current_rec.switch_name[3],
1153 phba->fcf.current_rec.switch_name[4],
1154 phba->fcf.current_rec.switch_name[5],
1155 phba->fcf.current_rec.switch_name[6],
1156 phba->fcf.current_rec.switch_name[7],
1157 phba->fcf.current_rec.fabric_name[0],
1158 phba->fcf.current_rec.fabric_name[1],
1159 phba->fcf.current_rec.fabric_name[2],
1160 phba->fcf.current_rec.fabric_name[3],
1161 phba->fcf.current_rec.fabric_name[4],
1162 phba->fcf.current_rec.fabric_name[5],
1163 phba->fcf.current_rec.fabric_name[6],
1164 phba->fcf.current_rec.fabric_name[7]);
1167 spin_lock_irq(&phba->hbalock);
1168 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1169 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1170 spin_unlock_irq(&phba->hbalock);
1171 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1175 /* Mark the FCF discovery process done */
1176 if (phba->hba_flag & HBA_FIP_SUPPORT)
1177 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1179 "2769 FLOGI to FCF (x%x) "
1180 "completed successfully\n",
1181 phba->fcf.current_rec.fcf_indx);
1182 spin_lock_irq(&phba->hbalock);
1183 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1184 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1185 spin_unlock_irq(&phba->hbalock);
1186 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1189 } else if (vport->port_state > LPFC_FLOGI &&
1190 vport->fc_flag & FC_PT2PT) {
1192 * In a p2p topology, it is possible that discovery has
1193 * already progressed, and this completion can be ignored.
1194 * Recheck the indicated topology.
1201 spin_lock_irq(&phba->hbalock);
1202 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1203 spin_unlock_irq(&phba->hbalock);
1205 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
1207 if (!lpfc_error_lost_link(irsp)) {
1208 /* FLOGI failed, so just use loop map to make discovery list */
1209 lpfc_disc_list_loopmap(vport);
1211 /* Start discovery */
1212 lpfc_disc_start(vport);
1213 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1214 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1215 IOERR_SLI_ABORTED) &&
1216 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1217 IOERR_SLI_DOWN))) &&
1218 (phba->link_state != LPFC_CLEAR_LA)) {
1219 /* If FLOGI failed enable link interrupt. */
1220 lpfc_issue_clear_la(phba, vport);
1223 phba->hba_flag &= ~HBA_FLOGI_OUTSTANDING;
1224 lpfc_els_free_iocb(phba, cmdiocb);
1229 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1230 * aborted during a link down
1231 * @phba: pointer to lpfc hba data structure.
1232 * @cmdiocb: pointer to lpfc command iocb data structure.
1233 * @rspiocb: pointer to lpfc response iocb data structure.
1237 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1238 struct lpfc_iocbq *rspiocb)
1244 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1246 irsp = &rspiocb->iocb;
1248 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1249 "6445 ELS completes after LINK_DOWN: "
1250 " Status %x/%x cmd x%x flg x%x\n",
1251 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1252 cmdiocb->iocb_flag);
1254 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1255 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1256 atomic_dec(&phba->fabric_iocb_count);
1258 lpfc_els_free_iocb(phba, cmdiocb);
1262 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1263 * @vport: pointer to a host virtual N_Port data structure.
1264 * @ndlp: pointer to a node-list data structure.
1265 * @retry: number of retries to the command IOCB.
1267 * This routine issues a Fabric Login (FLOGI) Request ELS command
1268 * for a @vport. The initiator service parameters are put into the payload
1269 * of the FLOGI Request IOCB and the top-level callback function pointer
1270 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1271 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1272 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1274 * Note that the ndlp reference count will be incremented by 1 for holding the
1275 * ndlp and the reference to ndlp will be stored into the context1 field of
1276 * the IOCB for the completion callback function to the FLOGI ELS command.
1279 * 0 - successfully issued flogi iocb for @vport
1280 * 1 - failed to issue flogi iocb for @vport
1283 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1286 struct lpfc_hba *phba = vport->phba;
1287 struct serv_parm *sp;
1289 struct lpfc_iocbq *elsiocb;
1290 struct lpfc_iocbq defer_flogi_acc;
1296 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1297 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1298 ndlp->nlp_DID, ELS_CMD_FLOGI);
1303 icmd = &elsiocb->iocb;
1304 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1306 /* For FLOGI request, remainder of payload is service parameters */
1307 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1308 pcmd += sizeof(uint32_t);
1309 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1310 sp = (struct serv_parm *) pcmd;
1312 /* Setup CSPs accordingly for Fabric */
1313 sp->cmn.e_d_tov = 0;
1314 sp->cmn.w2.r_a_tov = 0;
1315 sp->cmn.virtual_fabric_support = 0;
1316 sp->cls1.classValid = 0;
1317 if (sp->cmn.fcphLow < FC_PH3)
1318 sp->cmn.fcphLow = FC_PH3;
1319 if (sp->cmn.fcphHigh < FC_PH3)
1320 sp->cmn.fcphHigh = FC_PH3;
1322 /* Determine if switch supports priority tagging */
1323 if (phba->cfg_vmid_priority_tagging) {
1324 sp->cmn.priority_tagging = 1;
1325 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
1326 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid)) {
1327 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn,
1328 sizeof(phba->wwpn));
1329 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn,
1330 sizeof(phba->wwnn));
1334 if (phba->sli_rev == LPFC_SLI_REV4) {
1335 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1336 LPFC_SLI_INTF_IF_TYPE_0) {
1337 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1338 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1339 /* FLOGI needs to be 3 for WQE FCFI */
1340 /* Set the fcfi to the fcfi we registered with */
1341 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1343 /* Can't do SLI4 class2 without support sequence coalescing */
1344 sp->cls2.classValid = 0;
1345 sp->cls2.seqDelivery = 0;
1347 /* Historical, setting sequential-delivery bit for SLI3 */
1348 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1349 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1350 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1351 sp->cmn.request_multiple_Nport = 1;
1352 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1356 sp->cmn.request_multiple_Nport = 0;
1359 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1360 icmd->un.elsreq64.myID = 0;
1361 icmd->un.elsreq64.fl = 1;
1364 tmo = phba->fc_ratov;
1365 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1366 lpfc_set_disctmo(vport);
1367 phba->fc_ratov = tmo;
1369 phba->fc_stat.elsXmitFLOGI++;
1370 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1373 "Issue FLOGI: opt:x%x",
1374 phba->sli3_options, 0, 0);
1376 elsiocb->context1 = lpfc_nlp_get(ndlp);
1377 if (!elsiocb->context1) {
1378 lpfc_els_free_iocb(phba, elsiocb);
1382 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1383 if (rc == IOCB_ERROR) {
1384 lpfc_els_free_iocb(phba, elsiocb);
1389 phba->hba_flag |= (HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
1391 /* Check for a deferred FLOGI ACC condition */
1392 if (phba->defer_flogi_acc_flag) {
1393 did = vport->fc_myDID;
1394 vport->fc_myDID = Fabric_DID;
1396 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1398 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1399 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1400 phba->defer_flogi_acc_ox_id;
1402 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1403 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1404 " ox_id: x%x, hba_flag x%x\n",
1405 phba->defer_flogi_acc_rx_id,
1406 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1408 /* Send deferred FLOGI ACC */
1409 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1412 phba->defer_flogi_acc_flag = false;
1414 vport->fc_myDID = did;
1421 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1422 * @phba: pointer to lpfc hba data structure.
1424 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1425 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1426 * list and issues an abort IOCB commond on each outstanding IOCB that
1427 * contains a active Fabric_DID ndlp. Note that this function is to issue
1428 * the abort IOCB command on all the outstanding IOCBs, thus when this
1429 * function returns, it does not guarantee all the IOCBs are actually aborted.
1432 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1435 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1437 struct lpfc_sli_ring *pring;
1438 struct lpfc_iocbq *iocb, *next_iocb;
1439 struct lpfc_nodelist *ndlp;
1442 /* Abort outstanding I/O on NPort <nlp_DID> */
1443 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1444 "0201 Abort outstanding I/O on NPort x%x\n",
1447 pring = lpfc_phba_elsring(phba);
1448 if (unlikely(!pring))
1452 * Check the txcmplq for an iocb that matches the nport the driver is
1455 spin_lock_irq(&phba->hbalock);
1456 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1458 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1459 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1460 if (ndlp && ndlp->nlp_DID == Fabric_DID) {
1461 if ((phba->pport->fc_flag & FC_PT2PT) &&
1462 !(phba->pport->fc_flag & FC_PT2PT_PLOGI))
1463 iocb->fabric_iocb_cmpl =
1464 lpfc_ignore_els_cmpl;
1465 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1470 /* Make sure HBA is alive */
1471 lpfc_issue_hb_tmo(phba);
1473 spin_unlock_irq(&phba->hbalock);
1479 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1480 * @vport: pointer to a host virtual N_Port data structure.
1482 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1483 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1484 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1485 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1486 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1487 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1491 * 0 - failed to issue initial flogi for @vport
1492 * 1 - successfully issued initial flogi for @vport
1495 lpfc_initial_flogi(struct lpfc_vport *vport)
1497 struct lpfc_nodelist *ndlp;
1499 vport->port_state = LPFC_FLOGI;
1500 lpfc_set_disctmo(vport);
1502 /* First look for the Fabric ndlp */
1503 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1505 /* Cannot find existing Fabric ndlp, so allocate a new one */
1506 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1509 /* Set the node type */
1510 ndlp->nlp_type |= NLP_FABRIC;
1512 /* Put ndlp onto node list */
1513 lpfc_enqueue_node(vport, ndlp);
1516 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1517 /* This decrement of reference count to node shall kick off
1518 * the release of the node.
1527 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1528 * @vport: pointer to a host virtual N_Port data structure.
1530 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1531 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1532 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1533 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1534 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1535 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1539 * 0 - failed to issue initial fdisc for @vport
1540 * 1 - successfully issued initial fdisc for @vport
1543 lpfc_initial_fdisc(struct lpfc_vport *vport)
1545 struct lpfc_nodelist *ndlp;
1547 /* First look for the Fabric ndlp */
1548 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1550 /* Cannot find existing Fabric ndlp, so allocate a new one */
1551 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1555 /* NPIV is only supported in Fabrics. */
1556 ndlp->nlp_type |= NLP_FABRIC;
1558 /* Put ndlp onto node list */
1559 lpfc_enqueue_node(vport, ndlp);
1562 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1563 /* decrement node reference count to trigger the release of
1573 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1574 * @vport: pointer to a host virtual N_Port data structure.
1576 * This routine checks whether there are more remaining Port Logins
1577 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1578 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1579 * to issue ELS PLOGIs up to the configured discover threads with the
1580 * @vport (@vport->cfg_discovery_threads). The function also decrement
1581 * the @vport's num_disc_node by 1 if it is not already 0.
1584 lpfc_more_plogi(struct lpfc_vport *vport)
1586 if (vport->num_disc_nodes)
1587 vport->num_disc_nodes--;
1589 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1590 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1591 "0232 Continue discovery with %d PLOGIs to go "
1592 "Data: x%x x%x x%x\n",
1593 vport->num_disc_nodes, vport->fc_plogi_cnt,
1594 vport->fc_flag, vport->port_state);
1595 /* Check to see if there are more PLOGIs to be sent */
1596 if (vport->fc_flag & FC_NLP_MORE)
1597 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1598 lpfc_els_disc_plogi(vport);
1604 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1605 * @phba: pointer to lpfc hba data structure.
1606 * @prsp: pointer to response IOCB payload.
1607 * @ndlp: pointer to a node-list data structure.
1609 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1610 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1611 * The following cases are considered N_Port confirmed:
1612 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1613 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1614 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1615 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1616 * 1) if there is a node on vport list other than the @ndlp with the same
1617 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1618 * on that node to release the RPI associated with the node; 2) if there is
1619 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1620 * into, a new node shall be allocated (or activated). In either case, the
1621 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1622 * be released and the new_ndlp shall be put on to the vport node list and
1623 * its pointer returned as the confirmed node.
1625 * Note that before the @ndlp got "released", the keepDID from not-matching
1626 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1627 * of the @ndlp. This is because the release of @ndlp is actually to put it
1628 * into an inactive state on the vport node list and the vport node list
1629 * management algorithm does not allow two node with a same DID.
1632 * pointer to the PLOGI N_Port @ndlp
1634 static struct lpfc_nodelist *
1635 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1636 struct lpfc_nodelist *ndlp)
1638 struct lpfc_vport *vport = ndlp->vport;
1639 struct lpfc_nodelist *new_ndlp;
1640 struct serv_parm *sp;
1641 uint8_t name[sizeof(struct lpfc_name)];
1642 uint32_t keepDID = 0, keep_nlp_flag = 0;
1643 uint32_t keep_new_nlp_flag = 0;
1644 uint16_t keep_nlp_state;
1645 u32 keep_nlp_fc4_type = 0;
1646 struct lpfc_nvme_rport *keep_nrport = NULL;
1647 unsigned long *active_rrqs_xri_bitmap = NULL;
1649 /* Fabric nodes can have the same WWPN so we don't bother searching
1650 * by WWPN. Just return the ndlp that was given to us.
1652 if (ndlp->nlp_type & NLP_FABRIC)
1655 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1656 memset(name, 0, sizeof(struct lpfc_name));
1658 /* Now we find out if the NPort we are logging into, matches the WWPN
1659 * we have for that ndlp. If not, we have some work to do.
1661 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1663 /* return immediately if the WWPN matches ndlp */
1664 if (!new_ndlp || (new_ndlp == ndlp))
1667 if (phba->sli_rev == LPFC_SLI_REV4) {
1668 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1670 if (active_rrqs_xri_bitmap)
1671 memset(active_rrqs_xri_bitmap, 0,
1672 phba->cfg_rrq_xri_bitmap_sz);
1675 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1676 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1677 "new_ndlp x%x x%x x%x\n",
1678 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1679 (new_ndlp ? new_ndlp->nlp_DID : 0),
1680 (new_ndlp ? new_ndlp->nlp_flag : 0),
1681 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1683 keepDID = new_ndlp->nlp_DID;
1685 if (phba->sli_rev == LPFC_SLI_REV4 && active_rrqs_xri_bitmap)
1686 memcpy(active_rrqs_xri_bitmap, new_ndlp->active_rrqs_xri_bitmap,
1687 phba->cfg_rrq_xri_bitmap_sz);
1689 /* At this point in this routine, we know new_ndlp will be
1690 * returned. however, any previous GID_FTs that were done
1691 * would have updated nlp_fc4_type in ndlp, so we must ensure
1692 * new_ndlp has the right value.
1694 if (vport->fc_flag & FC_FABRIC) {
1695 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1696 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1699 lpfc_unreg_rpi(vport, new_ndlp);
1700 new_ndlp->nlp_DID = ndlp->nlp_DID;
1701 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1702 if (phba->sli_rev == LPFC_SLI_REV4)
1703 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1704 ndlp->active_rrqs_xri_bitmap,
1705 phba->cfg_rrq_xri_bitmap_sz);
1707 /* Lock both ndlps */
1708 spin_lock_irq(&ndlp->lock);
1709 spin_lock_irq(&new_ndlp->lock);
1710 keep_new_nlp_flag = new_ndlp->nlp_flag;
1711 keep_nlp_flag = ndlp->nlp_flag;
1712 new_ndlp->nlp_flag = ndlp->nlp_flag;
1714 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1715 if (keep_new_nlp_flag & NLP_UNREG_INP)
1716 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1718 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1720 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1721 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1722 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1724 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1727 * Retain the DROPPED flag. This will take care of the init
1728 * refcount when affecting the state change
1730 if (keep_new_nlp_flag & NLP_DROPPED)
1731 new_ndlp->nlp_flag |= NLP_DROPPED;
1733 new_ndlp->nlp_flag &= ~NLP_DROPPED;
1735 ndlp->nlp_flag = keep_new_nlp_flag;
1737 /* if ndlp had NLP_UNREG_INP set, keep it */
1738 if (keep_nlp_flag & NLP_UNREG_INP)
1739 ndlp->nlp_flag |= NLP_UNREG_INP;
1741 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1743 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1744 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1745 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1747 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1750 * Retain the DROPPED flag. This will take care of the init
1751 * refcount when affecting the state change
1753 if (keep_nlp_flag & NLP_DROPPED)
1754 ndlp->nlp_flag |= NLP_DROPPED;
1756 ndlp->nlp_flag &= ~NLP_DROPPED;
1758 spin_unlock_irq(&new_ndlp->lock);
1759 spin_unlock_irq(&ndlp->lock);
1761 /* Set nlp_states accordingly */
1762 keep_nlp_state = new_ndlp->nlp_state;
1763 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1765 /* interchange the nvme remoteport structs */
1766 keep_nrport = new_ndlp->nrport;
1767 new_ndlp->nrport = ndlp->nrport;
1769 /* Move this back to NPR state */
1770 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1771 /* The new_ndlp is replacing ndlp totally, so we need
1772 * to put ndlp on UNUSED list and try to free it.
1774 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1775 "3179 PLOGI confirm NEW: %x %x\n",
1776 new_ndlp->nlp_DID, keepDID);
1778 /* Two ndlps cannot have the same did on the nodelist.
1779 * Note: for this case, ndlp has a NULL WWPN so setting
1780 * the nlp_fc4_type isn't required.
1782 ndlp->nlp_DID = keepDID;
1783 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1784 if (phba->sli_rev == LPFC_SLI_REV4 &&
1785 active_rrqs_xri_bitmap)
1786 memcpy(ndlp->active_rrqs_xri_bitmap,
1787 active_rrqs_xri_bitmap,
1788 phba->cfg_rrq_xri_bitmap_sz);
1791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1792 "3180 PLOGI confirm SWAP: %x %x\n",
1793 new_ndlp->nlp_DID, keepDID);
1795 lpfc_unreg_rpi(vport, ndlp);
1797 /* Two ndlps cannot have the same did and the fc4
1798 * type must be transferred because the ndlp is in
1801 ndlp->nlp_DID = keepDID;
1802 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1804 if (phba->sli_rev == LPFC_SLI_REV4 &&
1805 active_rrqs_xri_bitmap)
1806 memcpy(ndlp->active_rrqs_xri_bitmap,
1807 active_rrqs_xri_bitmap,
1808 phba->cfg_rrq_xri_bitmap_sz);
1810 /* Since we are switching over to the new_ndlp,
1811 * reset the old ndlp state
1813 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1814 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1815 keep_nlp_state = NLP_STE_NPR_NODE;
1816 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1817 ndlp->nrport = keep_nrport;
1821 * If ndlp is not associated with any rport we can drop it here else
1822 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1824 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1825 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1827 if (phba->sli_rev == LPFC_SLI_REV4 &&
1828 active_rrqs_xri_bitmap)
1829 mempool_free(active_rrqs_xri_bitmap,
1830 phba->active_rrq_pool);
1832 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1833 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1834 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1835 new_ndlp->nlp_fc4_type);
1841 * lpfc_end_rscn - Check and handle more rscn for a vport
1842 * @vport: pointer to a host virtual N_Port data structure.
1844 * This routine checks whether more Registration State Change
1845 * Notifications (RSCNs) came in while the discovery state machine was in
1846 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1847 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1848 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1849 * handling the RSCNs.
1852 lpfc_end_rscn(struct lpfc_vport *vport)
1854 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1856 if (vport->fc_flag & FC_RSCN_MODE) {
1858 * Check to see if more RSCNs came in while we were
1859 * processing this one.
1861 if (vport->fc_rscn_id_cnt ||
1862 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1863 lpfc_els_handle_rscn(vport);
1865 spin_lock_irq(shost->host_lock);
1866 vport->fc_flag &= ~FC_RSCN_MODE;
1867 spin_unlock_irq(shost->host_lock);
1873 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1874 * @phba: pointer to lpfc hba data structure.
1875 * @cmdiocb: pointer to lpfc command iocb data structure.
1876 * @rspiocb: pointer to lpfc response iocb data structure.
1878 * This routine will call the clear rrq function to free the rrq and
1879 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1880 * exist then the clear_rrq is still called because the rrq needs to
1885 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1886 struct lpfc_iocbq *rspiocb)
1888 struct lpfc_vport *vport = cmdiocb->vport;
1890 struct lpfc_nodelist *ndlp = cmdiocb->context1;
1891 struct lpfc_node_rrq *rrq;
1893 /* we pass cmdiocb to state machine which needs rspiocb as well */
1894 rrq = cmdiocb->context_un.rrq;
1895 cmdiocb->context_un.rsp_iocb = rspiocb;
1897 irsp = &rspiocb->iocb;
1898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1899 "RRQ cmpl: status:x%x/x%x did:x%x",
1900 irsp->ulpStatus, irsp->un.ulpWord[4],
1901 irsp->un.elsreq64.remoteID);
1903 /* rrq completes to NPort <nlp_DID> */
1904 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1905 "2880 RRQ completes to DID x%x "
1906 "Data: x%x x%x x%x x%x x%x\n",
1907 irsp->un.elsreq64.remoteID,
1908 irsp->ulpStatus, irsp->un.ulpWord[4],
1909 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1911 if (irsp->ulpStatus) {
1912 /* Check for retry */
1913 /* RRQ failed Don't print the vport to vport rjts */
1914 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1915 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1916 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1917 (phba)->pport->cfg_log_verbose & LOG_ELS)
1918 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1919 "2881 RRQ failure DID:%06X Status:"
1921 ndlp->nlp_DID, irsp->ulpStatus,
1922 irsp->un.ulpWord[4]);
1925 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1926 lpfc_els_free_iocb(phba, cmdiocb);
1931 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1932 * @phba: pointer to lpfc hba data structure.
1933 * @cmdiocb: pointer to lpfc command iocb data structure.
1934 * @rspiocb: pointer to lpfc response iocb data structure.
1936 * This routine is the completion callback function for issuing the Port
1937 * Login (PLOGI) command. For PLOGI completion, there must be an active
1938 * ndlp on the vport node list that matches the remote node ID from the
1939 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1940 * ignored and command IOCB released. The PLOGI response IOCB status is
1941 * checked for error conditions. If there is error status reported, PLOGI
1942 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1943 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1944 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1945 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1946 * there are additional N_Port nodes with the vport that need to perform
1947 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1951 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1952 struct lpfc_iocbq *rspiocb)
1954 struct lpfc_vport *vport = cmdiocb->vport;
1955 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1957 struct lpfc_nodelist *ndlp, *free_ndlp;
1958 struct lpfc_dmabuf *prsp;
1960 struct serv_parm *sp = NULL;
1962 /* we pass cmdiocb to state machine which needs rspiocb as well */
1963 cmdiocb->context_un.rsp_iocb = rspiocb;
1965 irsp = &rspiocb->iocb;
1966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1967 "PLOGI cmpl: status:x%x/x%x did:x%x",
1968 irsp->ulpStatus, irsp->un.ulpWord[4],
1969 irsp->un.elsreq64.remoteID);
1971 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1973 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1974 "0136 PLOGI completes to NPort x%x "
1975 "with no ndlp. Data: x%x x%x x%x\n",
1976 irsp->un.elsreq64.remoteID,
1977 irsp->ulpStatus, irsp->un.ulpWord[4],
1982 /* Since ndlp can be freed in the disc state machine, note if this node
1983 * is being used during discovery.
1985 spin_lock_irq(&ndlp->lock);
1986 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1987 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1988 spin_unlock_irq(&ndlp->lock);
1990 /* PLOGI completes to NPort <nlp_DID> */
1991 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1992 "0102 PLOGI completes to NPort x%06x "
1993 "Data: x%x x%x x%x x%x x%x\n",
1994 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1995 irsp->ulpStatus, irsp->un.ulpWord[4],
1996 disc, vport->num_disc_nodes);
1998 /* Check to see if link went down during discovery */
1999 if (lpfc_els_chk_latt(vport)) {
2000 spin_lock_irq(&ndlp->lock);
2001 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2002 spin_unlock_irq(&ndlp->lock);
2006 if (irsp->ulpStatus) {
2007 /* Check for retry */
2008 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2009 /* ELS command is being retried */
2011 spin_lock_irq(&ndlp->lock);
2012 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2013 spin_unlock_irq(&ndlp->lock);
2017 /* PLOGI failed Don't print the vport to vport rjts */
2018 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2019 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2020 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2021 (phba)->pport->cfg_log_verbose & LOG_ELS)
2022 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2023 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2024 ndlp->nlp_DID, irsp->ulpStatus,
2025 irsp->un.ulpWord[4]);
2027 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2028 if (lpfc_error_lost_link(irsp))
2031 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2032 NLP_EVT_CMPL_PLOGI);
2034 /* If a PLOGI collision occurred, the node needs to continue
2035 * with the reglogin process.
2037 spin_lock_irq(&ndlp->lock);
2038 if ((ndlp->nlp_flag & (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI)) &&
2039 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
2040 spin_unlock_irq(&ndlp->lock);
2043 spin_unlock_irq(&ndlp->lock);
2045 /* No PLOGI collision and the node is not registered with the
2046 * scsi or nvme transport. It is no longer an active node. Just
2047 * start the device remove process.
2049 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2050 spin_lock_irq(&ndlp->lock);
2051 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2052 spin_unlock_irq(&ndlp->lock);
2053 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2057 /* Good status, call state machine */
2058 prsp = list_entry(((struct lpfc_dmabuf *)
2059 cmdiocb->context2)->list.next,
2060 struct lpfc_dmabuf, list);
2061 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2063 sp = (struct serv_parm *)((u8 *)prsp->virt +
2066 ndlp->vmid_support = 0;
2067 if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) ||
2068 (phba->cfg_vmid_priority_tagging &&
2069 sp->cmn.priority_tagging)) {
2070 lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS,
2071 "4018 app_hdr_support %d tagging %d DID x%x\n",
2072 sp->cmn.app_hdr_support,
2073 sp->cmn.priority_tagging,
2075 /* if the dest port supports VMID, mark it in ndlp */
2076 ndlp->vmid_support = 1;
2079 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2080 NLP_EVT_CMPL_PLOGI);
2084 if (disc && vport->num_disc_nodes) {
2085 /* Check to see if there are more PLOGIs to be sent */
2086 lpfc_more_plogi(vport);
2088 if (vport->num_disc_nodes == 0) {
2089 spin_lock_irq(shost->host_lock);
2090 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2091 spin_unlock_irq(shost->host_lock);
2093 lpfc_can_disctmo(vport);
2094 lpfc_end_rscn(vport);
2099 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2100 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2101 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2104 /* Release the reference on the original I/O request. */
2105 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2107 lpfc_els_free_iocb(phba, cmdiocb);
2108 lpfc_nlp_put(free_ndlp);
2113 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2114 * @vport: pointer to a host virtual N_Port data structure.
2115 * @did: destination port identifier.
2116 * @retry: number of retries to the command IOCB.
2118 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2119 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2120 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2121 * This routine constructs the proper fields of the PLOGI IOCB and invokes
2122 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2124 * Note that the ndlp reference count will be incremented by 1 for holding
2125 * the ndlp and the reference to ndlp will be stored into the context1 field
2126 * of the IOCB for the completion callback function to the PLOGI ELS command.
2129 * 0 - Successfully issued a plogi for @vport
2130 * 1 - failed to issue a plogi for @vport
2133 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2135 struct lpfc_hba *phba = vport->phba;
2136 struct serv_parm *sp;
2137 struct lpfc_nodelist *ndlp;
2138 struct lpfc_iocbq *elsiocb;
2143 ndlp = lpfc_findnode_did(vport, did);
2147 /* Defer the processing of the issue PLOGI until after the
2148 * outstanding UNREG_RPI mbox command completes, unless we
2149 * are going offline. This logic does not apply for Fabric DIDs
2151 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2152 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2153 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2154 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2155 "4110 Issue PLOGI x%x deferred "
2156 "on NPort x%x rpi x%x Data: x%px\n",
2157 ndlp->nlp_defer_did, ndlp->nlp_DID,
2158 ndlp->nlp_rpi, ndlp);
2160 /* We can only defer 1st PLOGI */
2161 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2162 ndlp->nlp_defer_did = did;
2166 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2167 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2172 spin_lock_irq(&ndlp->lock);
2173 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2174 spin_unlock_irq(&ndlp->lock);
2176 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2178 /* For PLOGI request, remainder of payload is service parameters */
2179 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2180 pcmd += sizeof(uint32_t);
2181 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2182 sp = (struct serv_parm *) pcmd;
2185 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2186 * to device on remote loops work.
2188 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2189 sp->cmn.altBbCredit = 1;
2191 if (sp->cmn.fcphLow < FC_PH_4_3)
2192 sp->cmn.fcphLow = FC_PH_4_3;
2194 if (sp->cmn.fcphHigh < FC_PH3)
2195 sp->cmn.fcphHigh = FC_PH3;
2197 sp->cmn.valid_vendor_ver_level = 0;
2198 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2199 sp->cmn.bbRcvSizeMsb &= 0xF;
2201 /* Check if the destination port supports VMID */
2202 ndlp->vmid_support = 0;
2203 if (vport->vmid_priority_tagging)
2204 sp->cmn.priority_tagging = 1;
2205 else if (phba->cfg_vmid_app_header &&
2206 bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags))
2207 sp->cmn.app_hdr_support = 1;
2209 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2210 "Issue PLOGI: did:x%x",
2213 /* If our firmware supports this feature, convey that
2214 * information to the target using the vendor specific field.
2216 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2217 sp->cmn.valid_vendor_ver_level = 1;
2218 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2219 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2222 phba->fc_stat.elsXmitPLOGI++;
2223 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2225 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2226 "Issue PLOGI: did:x%x refcnt %d",
2227 did, kref_read(&ndlp->kref), 0);
2228 elsiocb->context1 = lpfc_nlp_get(ndlp);
2229 if (!elsiocb->context1) {
2230 lpfc_els_free_iocb(phba, elsiocb);
2234 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2236 lpfc_els_free_iocb(phba, elsiocb);
2245 * lpfc_cmpl_els_prli - Completion callback function for prli
2246 * @phba: pointer to lpfc hba data structure.
2247 * @cmdiocb: pointer to lpfc command iocb data structure.
2248 * @rspiocb: pointer to lpfc response iocb data structure.
2250 * This routine is the completion callback function for a Process Login
2251 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2252 * status. If there is error status reported, PRLI retry shall be attempted
2253 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2254 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2255 * ndlp to mark the PRLI completion.
2258 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2259 struct lpfc_iocbq *rspiocb)
2261 struct lpfc_vport *vport = cmdiocb->vport;
2263 struct lpfc_nodelist *ndlp;
2267 /* we pass cmdiocb to state machine which needs rspiocb as well */
2268 cmdiocb->context_un.rsp_iocb = rspiocb;
2270 irsp = &(rspiocb->iocb);
2271 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2272 spin_lock_irq(&ndlp->lock);
2273 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2275 /* Driver supports multiple FC4 types. Counters matter. */
2276 vport->fc_prli_sent--;
2277 ndlp->fc4_prli_sent--;
2278 spin_unlock_irq(&ndlp->lock);
2280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2281 "PRLI cmpl: status:x%x/x%x did:x%x",
2282 irsp->ulpStatus, irsp->un.ulpWord[4],
2285 /* PRLI completes to NPort <nlp_DID> */
2286 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2287 "0103 PRLI completes to NPort x%06x "
2288 "Data: x%x x%x x%x x%x\n",
2289 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2290 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2292 /* Check to see if link went down during discovery */
2293 if (lpfc_els_chk_latt(vport))
2296 if (irsp->ulpStatus) {
2297 /* Check for retry */
2298 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2299 /* ELS command is being retried */
2303 /* If we don't send GFT_ID to Fabric, a PRLI error
2304 * could be expected.
2306 if ((vport->fc_flag & FC_FABRIC) ||
2307 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2309 loglevel = LOG_TRACE_EVENT;
2316 lpfc_printf_vlog(vport, mode, loglevel,
2317 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2319 ndlp->nlp_DID, irsp->ulpStatus,
2320 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2322 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2323 if (!lpfc_error_lost_link(irsp))
2324 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2327 /* As long as this node is not registered with the SCSI
2328 * or NVMe transport and no other PRLIs are outstanding,
2329 * it is no longer an active node. Otherwise devloss
2330 * handles the final cleanup.
2332 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2333 !ndlp->fc4_prli_sent) {
2334 spin_lock_irq(&ndlp->lock);
2335 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2336 spin_unlock_irq(&ndlp->lock);
2337 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2341 /* Good status, call state machine. However, if another
2342 * PRLI is outstanding, don't call the state machine
2343 * because final disposition to Mapped or Unmapped is
2346 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2351 lpfc_els_free_iocb(phba, cmdiocb);
2357 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2358 * @vport: pointer to a host virtual N_Port data structure.
2359 * @ndlp: pointer to a node-list data structure.
2360 * @retry: number of retries to the command IOCB.
2362 * This routine issues a Process Login (PRLI) ELS command for the
2363 * @vport. The PRLI service parameters are set up in the payload of the
2364 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2365 * is put to the IOCB completion callback func field before invoking the
2366 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2368 * Note that the ndlp reference count will be incremented by 1 for holding the
2369 * ndlp and the reference to ndlp will be stored into the context1 field of
2370 * the IOCB for the completion callback function to the PRLI ELS command.
2373 * 0 - successfully issued prli iocb command for @vport
2374 * 1 - failed to issue prli iocb command for @vport
2377 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2381 struct lpfc_hba *phba = vport->phba;
2383 struct lpfc_nvme_prli *npr_nvme;
2384 struct lpfc_iocbq *elsiocb;
2387 u32 local_nlp_type, elscmd;
2390 * If we are in RSCN mode, the FC4 types supported from a
2391 * previous GFT_ID command may not be accurate. So, if we
2392 * are a NVME Initiator, always look for the possibility of
2393 * the remote NPort beng a NVME Target.
2395 if (phba->sli_rev == LPFC_SLI_REV4 &&
2396 vport->fc_flag & FC_RSCN_MODE &&
2397 vport->nvmei_support)
2398 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2399 local_nlp_type = ndlp->nlp_fc4_type;
2401 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2402 * fields here before any of them can complete.
2404 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2405 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2406 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2407 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2408 ndlp->nvme_fb_size = 0;
2411 if (local_nlp_type & NLP_FC4_FCP) {
2412 /* Payload is 4 + 16 = 20 x14 bytes. */
2413 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2414 elscmd = ELS_CMD_PRLI;
2415 } else if (local_nlp_type & NLP_FC4_NVME) {
2416 /* Payload is 4 + 20 = 24 x18 bytes. */
2417 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2418 elscmd = ELS_CMD_NVMEPRLI;
2420 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2421 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2422 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2426 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2427 * FC4 type, implicitly LOGO.
2429 if (phba->sli_rev == LPFC_SLI_REV3 &&
2430 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2431 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2432 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2434 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2438 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2439 ndlp->nlp_DID, elscmd);
2443 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2445 /* For PRLI request, remainder of payload is service parameters */
2446 memset(pcmd, 0, cmdsize);
2448 if (local_nlp_type & NLP_FC4_FCP) {
2449 /* Remainder of payload is FCP PRLI parameter page.
2450 * Note: this data structure is defined as
2451 * BE/LE in the structure definition so no
2452 * byte swap call is made.
2454 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2455 pcmd += sizeof(uint32_t);
2459 * If our firmware version is 3.20 or later,
2460 * set the following bits for FC-TAPE support.
2462 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2463 npr->ConfmComplAllowed = 1;
2465 npr->TaskRetryIdReq = 1;
2467 npr->estabImagePair = 1;
2468 npr->readXferRdyDis = 1;
2469 if (vport->cfg_first_burst_size)
2470 npr->writeXferRdyDis = 1;
2472 /* For FCP support */
2473 npr->prliType = PRLI_FCP_TYPE;
2474 npr->initiatorFunc = 1;
2475 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2477 /* Remove FCP type - processed. */
2478 local_nlp_type &= ~NLP_FC4_FCP;
2479 } else if (local_nlp_type & NLP_FC4_NVME) {
2480 /* Remainder of payload is NVME PRLI parameter page.
2481 * This data structure is the newer definition that
2482 * uses bf macros so a byte swap is required.
2484 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2485 pcmd += sizeof(uint32_t);
2486 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2487 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2488 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2490 bf_set(prli_nsler, npr_nvme, 1);
2491 bf_set(prli_conf, npr_nvme, 1);
2494 /* Only initiators request first burst. */
2495 if ((phba->cfg_nvme_enable_fb) &&
2496 !phba->nvmet_support)
2497 bf_set(prli_fba, npr_nvme, 1);
2499 if (phba->nvmet_support) {
2500 bf_set(prli_tgt, npr_nvme, 1);
2501 bf_set(prli_disc, npr_nvme, 1);
2503 bf_set(prli_init, npr_nvme, 1);
2504 bf_set(prli_conf, npr_nvme, 1);
2507 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2508 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2509 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2511 /* Remove NVME type - processed. */
2512 local_nlp_type &= ~NLP_FC4_NVME;
2515 phba->fc_stat.elsXmitPRLI++;
2516 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2517 spin_lock_irq(&ndlp->lock);
2518 ndlp->nlp_flag |= NLP_PRLI_SND;
2520 /* The vport counters are used for lpfc_scan_finished, but
2521 * the ndlp is used to track outstanding PRLIs for different
2524 vport->fc_prli_sent++;
2525 ndlp->fc4_prli_sent++;
2526 spin_unlock_irq(&ndlp->lock);
2528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2529 "Issue PRLI: did:x%x refcnt %d",
2530 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2531 elsiocb->context1 = lpfc_nlp_get(ndlp);
2532 if (!elsiocb->context1) {
2533 lpfc_els_free_iocb(phba, elsiocb);
2537 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2538 if (rc == IOCB_ERROR) {
2539 lpfc_els_free_iocb(phba, elsiocb);
2545 /* The driver supports 2 FC4 types. Make sure
2546 * a PRLI is issued for all types before exiting.
2548 if (phba->sli_rev == LPFC_SLI_REV4 &&
2549 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2550 goto send_next_prli;
2555 spin_lock_irq(&ndlp->lock);
2556 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2557 spin_unlock_irq(&ndlp->lock);
2562 * lpfc_rscn_disc - Perform rscn discovery for a vport
2563 * @vport: pointer to a host virtual N_Port data structure.
2565 * This routine performs Registration State Change Notification (RSCN)
2566 * discovery for a @vport. If the @vport's node port recovery count is not
2567 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2568 * the nodes that need recovery. If none of the PLOGI were needed through
2569 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2570 * invoked to check and handle possible more RSCN came in during the period
2571 * of processing the current ones.
2574 lpfc_rscn_disc(struct lpfc_vport *vport)
2576 lpfc_can_disctmo(vport);
2578 /* RSCN discovery */
2579 /* go thru NPR nodes and issue ELS PLOGIs */
2580 if (vport->fc_npr_cnt)
2581 if (lpfc_els_disc_plogi(vport))
2584 lpfc_end_rscn(vport);
2588 * lpfc_adisc_done - Complete the adisc phase of discovery
2589 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2591 * This function is called when the final ADISC is completed during discovery.
2592 * This function handles clearing link attention or issuing reg_vpi depending
2593 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2595 * This function is called with no locks held.
2598 lpfc_adisc_done(struct lpfc_vport *vport)
2600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2601 struct lpfc_hba *phba = vport->phba;
2604 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2605 * and continue discovery.
2607 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2608 !(vport->fc_flag & FC_RSCN_MODE) &&
2609 (phba->sli_rev < LPFC_SLI_REV4)) {
2610 /* The ADISCs are complete. Doesn't matter if they
2611 * succeeded or failed because the ADISC completion
2612 * routine guarantees to call the state machine and
2613 * the RPI is either unregistered (failed ADISC response)
2614 * or the RPI is still valid and the node is marked
2615 * mapped for a target. The exchanges should be in the
2616 * correct state. This code is specific to SLI3.
2618 lpfc_issue_clear_la(phba, vport);
2619 lpfc_issue_reg_vpi(phba, vport);
2623 * For SLI2, we need to set port_state to READY
2624 * and continue discovery.
2626 if (vport->port_state < LPFC_VPORT_READY) {
2627 /* If we get here, there is nothing to ADISC */
2628 lpfc_issue_clear_la(phba, vport);
2629 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2630 vport->num_disc_nodes = 0;
2631 /* go thru NPR list, issue ELS PLOGIs */
2632 if (vport->fc_npr_cnt)
2633 lpfc_els_disc_plogi(vport);
2634 if (!vport->num_disc_nodes) {
2635 spin_lock_irq(shost->host_lock);
2636 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2637 spin_unlock_irq(shost->host_lock);
2638 lpfc_can_disctmo(vport);
2639 lpfc_end_rscn(vport);
2642 vport->port_state = LPFC_VPORT_READY;
2644 lpfc_rscn_disc(vport);
2648 * lpfc_more_adisc - Issue more adisc as needed
2649 * @vport: pointer to a host virtual N_Port data structure.
2651 * This routine determines whether there are more ndlps on a @vport
2652 * node list need to have Address Discover (ADISC) issued. If so, it will
2653 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2654 * remaining nodes which need to have ADISC sent.
2657 lpfc_more_adisc(struct lpfc_vport *vport)
2659 if (vport->num_disc_nodes)
2660 vport->num_disc_nodes--;
2661 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2662 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2663 "0210 Continue discovery with %d ADISCs to go "
2664 "Data: x%x x%x x%x\n",
2665 vport->num_disc_nodes, vport->fc_adisc_cnt,
2666 vport->fc_flag, vport->port_state);
2667 /* Check to see if there are more ADISCs to be sent */
2668 if (vport->fc_flag & FC_NLP_MORE) {
2669 lpfc_set_disctmo(vport);
2670 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2671 lpfc_els_disc_adisc(vport);
2673 if (!vport->num_disc_nodes)
2674 lpfc_adisc_done(vport);
2679 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2680 * @phba: pointer to lpfc hba data structure.
2681 * @cmdiocb: pointer to lpfc command iocb data structure.
2682 * @rspiocb: pointer to lpfc response iocb data structure.
2684 * This routine is the completion function for issuing the Address Discover
2685 * (ADISC) command. It first checks to see whether link went down during
2686 * the discovery process. If so, the node will be marked as node port
2687 * recovery for issuing discover IOCB by the link attention handler and
2688 * exit. Otherwise, the response status is checked. If error was reported
2689 * in the response status, the ADISC command shall be retried by invoking
2690 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2691 * the response status, the state machine is invoked to set transition
2692 * with respect to NLP_EVT_CMPL_ADISC event.
2695 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2696 struct lpfc_iocbq *rspiocb)
2698 struct lpfc_vport *vport = cmdiocb->vport;
2700 struct lpfc_nodelist *ndlp;
2703 /* we pass cmdiocb to state machine which needs rspiocb as well */
2704 cmdiocb->context_un.rsp_iocb = rspiocb;
2706 irsp = &(rspiocb->iocb);
2707 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2709 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2710 "ADISC cmpl: status:x%x/x%x did:x%x",
2711 irsp->ulpStatus, irsp->un.ulpWord[4],
2714 /* Since ndlp can be freed in the disc state machine, note if this node
2715 * is being used during discovery.
2717 spin_lock_irq(&ndlp->lock);
2718 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2719 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2720 spin_unlock_irq(&ndlp->lock);
2721 /* ADISC completes to NPort <nlp_DID> */
2722 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2723 "0104 ADISC completes to NPort x%x "
2724 "Data: x%x x%x x%x x%x x%x\n",
2725 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2726 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2727 /* Check to see if link went down during discovery */
2728 if (lpfc_els_chk_latt(vport)) {
2729 spin_lock_irq(&ndlp->lock);
2730 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2731 spin_unlock_irq(&ndlp->lock);
2735 if (irsp->ulpStatus) {
2736 /* Check for retry */
2737 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2738 /* ELS command is being retried */
2740 spin_lock_irq(&ndlp->lock);
2741 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2742 spin_unlock_irq(&ndlp->lock);
2743 lpfc_set_disctmo(vport);
2748 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2749 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2750 ndlp->nlp_DID, irsp->ulpStatus,
2751 irsp->un.ulpWord[4]);
2752 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2753 if (lpfc_error_lost_link(irsp))
2756 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2757 NLP_EVT_CMPL_ADISC);
2759 /* As long as this node is not registered with the SCSI or NVMe
2760 * transport, it is no longer an active node. Otherwise
2761 * devloss handles the final cleanup.
2763 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2764 spin_lock_irq(&ndlp->lock);
2765 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2766 spin_unlock_irq(&ndlp->lock);
2767 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2771 /* Good status, call state machine */
2772 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2773 NLP_EVT_CMPL_ADISC);
2776 /* Check to see if there are more ADISCs to be sent */
2777 if (disc && vport->num_disc_nodes)
2778 lpfc_more_adisc(vport);
2780 lpfc_els_free_iocb(phba, cmdiocb);
2786 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2787 * @vport: pointer to a virtual N_Port data structure.
2788 * @ndlp: pointer to a node-list data structure.
2789 * @retry: number of retries to the command IOCB.
2791 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2792 * @vport. It prepares the payload of the ADISC ELS command, updates the
2793 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2794 * to issue the ADISC ELS command.
2796 * Note that the ndlp reference count will be incremented by 1 for holding the
2797 * ndlp and the reference to ndlp will be stored into the context1 field of
2798 * the IOCB for the completion callback function to the ADISC ELS command.
2801 * 0 - successfully issued adisc
2802 * 1 - failed to issue adisc
2805 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2809 struct lpfc_hba *phba = vport->phba;
2811 struct lpfc_iocbq *elsiocb;
2815 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2816 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2817 ndlp->nlp_DID, ELS_CMD_ADISC);
2821 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2823 /* For ADISC request, remainder of payload is service parameters */
2824 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2825 pcmd += sizeof(uint32_t);
2827 /* Fill in ADISC payload */
2828 ap = (ADISC *) pcmd;
2829 ap->hardAL_PA = phba->fc_pref_ALPA;
2830 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2831 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2832 ap->DID = be32_to_cpu(vport->fc_myDID);
2834 phba->fc_stat.elsXmitADISC++;
2835 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2836 spin_lock_irq(&ndlp->lock);
2837 ndlp->nlp_flag |= NLP_ADISC_SND;
2838 spin_unlock_irq(&ndlp->lock);
2839 elsiocb->context1 = lpfc_nlp_get(ndlp);
2840 if (!elsiocb->context1) {
2841 lpfc_els_free_iocb(phba, elsiocb);
2845 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2846 "Issue ADISC: did:x%x refcnt %d",
2847 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2848 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2849 if (rc == IOCB_ERROR) {
2850 lpfc_els_free_iocb(phba, elsiocb);
2858 spin_lock_irq(&ndlp->lock);
2859 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2860 spin_unlock_irq(&ndlp->lock);
2865 * lpfc_cmpl_els_logo - Completion callback function for logo
2866 * @phba: pointer to lpfc hba data structure.
2867 * @cmdiocb: pointer to lpfc command iocb data structure.
2868 * @rspiocb: pointer to lpfc response iocb data structure.
2870 * This routine is the completion function for issuing the ELS Logout (LOGO)
2871 * command. If no error status was reported from the LOGO response, the
2872 * state machine of the associated ndlp shall be invoked for transition with
2873 * respect to NLP_EVT_CMPL_LOGO event.
2876 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2877 struct lpfc_iocbq *rspiocb)
2879 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2880 struct lpfc_vport *vport = ndlp->vport;
2882 unsigned long flags;
2883 uint32_t skip_recovery = 0;
2884 int wake_up_waiter = 0;
2886 /* we pass cmdiocb to state machine which needs rspiocb as well */
2887 cmdiocb->context_un.rsp_iocb = rspiocb;
2889 irsp = &(rspiocb->iocb);
2890 spin_lock_irq(&ndlp->lock);
2891 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2892 if (ndlp->upcall_flags & NLP_WAIT_FOR_LOGO) {
2894 ndlp->upcall_flags &= ~NLP_WAIT_FOR_LOGO;
2896 spin_unlock_irq(&ndlp->lock);
2898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2899 "LOGO cmpl: status:x%x/x%x did:x%x",
2900 irsp->ulpStatus, irsp->un.ulpWord[4],
2903 /* LOGO completes to NPort <nlp_DID> */
2904 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2905 "0105 LOGO completes to NPort x%x "
2906 "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
2907 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
2908 irsp->ulpStatus, irsp->un.ulpWord[4],
2909 irsp->ulpTimeout, vport->num_disc_nodes);
2911 if (lpfc_els_chk_latt(vport)) {
2916 /* The LOGO will not be retried on failure. A LOGO was
2917 * issued to the remote rport and a ACC or RJT or no Answer are
2918 * all acceptable. Note the failure and move forward with
2919 * discovery. The PLOGI will retry.
2921 if (irsp->ulpStatus) {
2923 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2924 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2925 ndlp->nlp_DID, irsp->ulpStatus,
2926 irsp->un.ulpWord[4]);
2927 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2928 if (lpfc_error_lost_link(irsp)) {
2934 /* Call state machine. This will unregister the rpi if needed. */
2935 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2937 /* The driver sets this flag for an NPIV instance that doesn't want to
2938 * log into the remote port.
2940 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2941 spin_lock_irq(&ndlp->lock);
2942 if (phba->sli_rev == LPFC_SLI_REV4)
2943 ndlp->nlp_flag |= NLP_RELEASE_RPI;
2944 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2945 spin_unlock_irq(&ndlp->lock);
2946 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2948 lpfc_els_free_iocb(phba, cmdiocb);
2951 /* Presume the node was released. */
2956 /* Driver is done with the IO. */
2957 lpfc_els_free_iocb(phba, cmdiocb);
2960 /* At this point, the LOGO processing is complete. NOTE: For a
2961 * pt2pt topology, we are assuming the NPortID will only change
2962 * on link up processing. For a LOGO / PLOGI initiated by the
2963 * Initiator, we are assuming the NPortID is not going to change.
2966 if (wake_up_waiter && ndlp->logo_waitq)
2967 wake_up(ndlp->logo_waitq);
2969 * If the node is a target, the handling attempts to recover the port.
2970 * For any other port type, the rpi is unregistered as an implicit
2973 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2974 skip_recovery == 0) {
2975 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2976 spin_lock_irqsave(&ndlp->lock, flags);
2977 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2978 spin_unlock_irqrestore(&ndlp->lock, flags);
2980 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2981 "3187 LOGO completes to NPort x%x: Start "
2982 "Recovery Data: x%x x%x x%x x%x\n",
2983 ndlp->nlp_DID, irsp->ulpStatus,
2984 irsp->un.ulpWord[4], irsp->ulpTimeout,
2985 vport->num_disc_nodes);
2986 lpfc_disc_start(vport);
2990 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
2991 * driver sends a LOGO to the rport to cleanup. For fabric and
2992 * initiator ports cleanup the node as long as it the node is not
2993 * register with the transport.
2995 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2996 spin_lock_irq(&ndlp->lock);
2997 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2998 spin_unlock_irq(&ndlp->lock);
2999 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3005 * lpfc_issue_els_logo - Issue a logo to an node on a vport
3006 * @vport: pointer to a virtual N_Port data structure.
3007 * @ndlp: pointer to a node-list data structure.
3008 * @retry: number of retries to the command IOCB.
3010 * This routine constructs and issues an ELS Logout (LOGO) iocb command
3011 * to a remote node, referred by an @ndlp on a @vport. It constructs the
3012 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
3013 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
3015 * Note that the ndlp reference count will be incremented by 1 for holding the
3016 * ndlp and the reference to ndlp will be stored into the context1 field of
3017 * the IOCB for the completion callback function to the LOGO ELS command.
3019 * Callers of this routine are expected to unregister the RPI first
3022 * 0 - successfully issued logo
3023 * 1 - failed to issue logo
3026 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3029 struct lpfc_hba *phba = vport->phba;
3030 struct lpfc_iocbq *elsiocb;
3035 spin_lock_irq(&ndlp->lock);
3036 if (ndlp->nlp_flag & NLP_LOGO_SND) {
3037 spin_unlock_irq(&ndlp->lock);
3040 spin_unlock_irq(&ndlp->lock);
3042 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
3043 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3044 ndlp->nlp_DID, ELS_CMD_LOGO);
3048 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3049 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
3050 pcmd += sizeof(uint32_t);
3052 /* Fill in LOGO payload */
3053 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
3054 pcmd += sizeof(uint32_t);
3055 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
3057 phba->fc_stat.elsXmitLOGO++;
3058 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
3059 spin_lock_irq(&ndlp->lock);
3060 ndlp->nlp_flag |= NLP_LOGO_SND;
3061 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
3062 spin_unlock_irq(&ndlp->lock);
3063 elsiocb->context1 = lpfc_nlp_get(ndlp);
3064 if (!elsiocb->context1) {
3065 lpfc_els_free_iocb(phba, elsiocb);
3069 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3070 "Issue LOGO: did:x%x refcnt %d",
3071 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3072 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3073 if (rc == IOCB_ERROR) {
3074 lpfc_els_free_iocb(phba, elsiocb);
3079 spin_lock_irq(&ndlp->lock);
3080 ndlp->nlp_prev_state = ndlp->nlp_state;
3081 spin_unlock_irq(&ndlp->lock);
3082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3086 spin_lock_irq(&ndlp->lock);
3087 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3088 spin_unlock_irq(&ndlp->lock);
3093 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3094 * @phba: pointer to lpfc hba data structure.
3095 * @cmdiocb: pointer to lpfc command iocb data structure.
3096 * @rspiocb: pointer to lpfc response iocb data structure.
3098 * This routine is a generic completion callback function for ELS commands.
3099 * Specifically, it is the callback function which does not need to perform
3100 * any command specific operations. It is currently used by the ELS command
3101 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3102 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3103 * Other than certain debug loggings, this callback function simply invokes the
3104 * lpfc_els_chk_latt() routine to check whether link went down during the
3105 * discovery process.
3108 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3109 struct lpfc_iocbq *rspiocb)
3111 struct lpfc_vport *vport = cmdiocb->vport;
3112 struct lpfc_nodelist *free_ndlp;
3115 irsp = &rspiocb->iocb;
3117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3118 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3119 irsp->ulpStatus, irsp->un.ulpWord[4],
3120 irsp->un.elsreq64.remoteID);
3122 /* ELS cmd tag <ulpIoTag> completes */
3123 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3124 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3125 irsp->ulpIoTag, irsp->ulpStatus,
3126 irsp->un.ulpWord[4], irsp->ulpTimeout);
3128 /* Check to see if link went down during discovery */
3129 lpfc_els_chk_latt(vport);
3131 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3133 lpfc_els_free_iocb(phba, cmdiocb);
3134 lpfc_nlp_put(free_ndlp);
3138 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
3139 * @vport: pointer to lpfc_vport data structure.
3140 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
3142 * This routine registers the rpi assigned to the fabric controller
3143 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
3144 * state triggering a registration with the SCSI transport.
3146 * This routine is single out because the fabric controller node
3147 * does not receive a PLOGI. This routine is consumed by the
3148 * SCR and RDF ELS commands. Callers are expected to qualify
3152 lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp)
3155 struct lpfc_hba *phba = vport->phba;
3156 struct lpfc_nodelist *ns_ndlp;
3158 struct lpfc_dmabuf *mp;
3160 if (fc_ndlp->nlp_flag & NLP_RPI_REGISTERED)
3163 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
3167 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3168 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
3169 __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID,
3170 ns_ndlp->nlp_state);
3171 if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3174 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3176 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3177 "0936 %s: no memory for reg_login "
3178 "Data: x%x x%x x%x x%x\n", __func__,
3179 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3180 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3183 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID,
3184 (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi);
3190 fc_ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
3191 mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login;
3192 mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp);
3193 if (!mbox->ctx_ndlp) {
3198 mbox->vport = vport;
3199 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3200 if (rc == MBX_NOT_FINISHED) {
3202 lpfc_nlp_put(fc_ndlp);
3205 /* Success path. Exit. */
3206 lpfc_nlp_set_state(vport, fc_ndlp,
3207 NLP_STE_REG_LOGIN_ISSUE);
3211 fc_ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3212 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
3213 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3217 mempool_free(mbox, phba->mbox_mem_pool);
3218 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3219 "0938 %s: failed to format reg_login "
3220 "Data: x%x x%x x%x x%x\n", __func__,
3221 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3222 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3227 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3228 * @phba: pointer to lpfc hba data structure.
3229 * @cmdiocb: pointer to lpfc command iocb data structure.
3230 * @rspiocb: pointer to lpfc response iocb data structure.
3232 * This routine is a generic completion callback function for Discovery ELS cmd.
3233 * Currently used by the ELS command issuing routines for the ELS State Change
3234 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3235 * These commands will be retried once only for ELS timeout errors.
3238 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3239 struct lpfc_iocbq *rspiocb)
3241 struct lpfc_vport *vport = cmdiocb->vport;
3243 struct lpfc_els_rdf_rsp *prdf;
3244 struct lpfc_dmabuf *pcmd, *prsp;
3247 struct lpfc_nodelist *ndlp = cmdiocb->context1;
3249 irsp = &rspiocb->iocb;
3251 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3252 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3253 irsp->ulpStatus, irsp->un.ulpWord[4],
3254 irsp->un.elsreq64.remoteID);
3255 /* ELS cmd tag <ulpIoTag> completes */
3256 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3257 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3259 irsp->ulpIoTag, irsp->ulpStatus,
3260 irsp->un.ulpWord[4], irsp->ulpTimeout,
3263 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3267 pdata = (u32 *)pcmd->virt;
3272 /* Only 1 retry for ELS Timeout only */
3273 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3274 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3275 IOERR_SEQUENCE_TIMEOUT)) {
3277 if (cmdiocb->retry <= 1) {
3280 lpfc_issue_els_scr(vport, cmdiocb->retry);
3283 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3284 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3289 phba->fc_stat.elsRetryExceeded++;
3291 if (irsp->ulpStatus) {
3292 /* ELS discovery cmd completes with error */
3293 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3294 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3295 irsp->ulpStatus, irsp->un.ulpWord[4]);
3299 /* The RDF response doesn't have any impact on the running driver
3300 * but the notification descriptors are dumped here for support.
3302 if (cmd == ELS_CMD_RDF) {
3305 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3309 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3313 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3314 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3315 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3316 "4677 Fabric RDF Notification Grant Data: "
3319 prdf->reg_d1.desc_tags[i]));
3323 /* Check to see if link went down during discovery */
3324 lpfc_els_chk_latt(vport);
3325 lpfc_els_free_iocb(phba, cmdiocb);
3331 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3332 * @vport: pointer to a host virtual N_Port data structure.
3333 * @retry: retry counter for the command IOCB.
3335 * This routine issues a State Change Request (SCR) to a fabric node
3336 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3337 * first search the @vport node list to find the matching ndlp. If no such
3338 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3339 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3340 * routine is invoked to send the SCR IOCB.
3342 * Note that the ndlp reference count will be incremented by 1 for holding the
3343 * ndlp and the reference to ndlp will be stored into the context1 field of
3344 * the IOCB for the completion callback function to the SCR ELS command.
3347 * 0 - Successfully issued scr command
3348 * 1 - Failed to issue scr command
3351 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3354 struct lpfc_hba *phba = vport->phba;
3355 struct lpfc_iocbq *elsiocb;
3358 struct lpfc_nodelist *ndlp;
3360 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3362 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3364 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3367 lpfc_enqueue_node(vport, ndlp);
3370 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3371 ndlp->nlp_DID, ELS_CMD_SCR);
3375 if (phba->sli_rev == LPFC_SLI_REV4) {
3376 rc = lpfc_reg_fab_ctrl_node(vport, ndlp);
3378 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3379 "0937 %s: Failed to reg fc node, rc %d\n",
3384 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3386 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3387 pcmd += sizeof(uint32_t);
3389 /* For SCR, remainder of payload is SCR parameter page */
3390 memset(pcmd, 0, sizeof(SCR));
3391 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3393 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3394 "Issue SCR: did:x%x",
3395 ndlp->nlp_DID, 0, 0);
3397 phba->fc_stat.elsXmitSCR++;
3398 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3399 elsiocb->context1 = lpfc_nlp_get(ndlp);
3400 if (!elsiocb->context1) {
3401 lpfc_els_free_iocb(phba, elsiocb);
3405 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3406 "Issue SCR: did:x%x refcnt %d",
3407 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3409 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3410 if (rc == IOCB_ERROR) {
3411 lpfc_els_free_iocb(phba, elsiocb);
3416 /* Keep the ndlp just in case RDF is being sent */
3421 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3422 * or the other nport (pt2pt).
3423 * @vport: pointer to a host virtual N_Port data structure.
3424 * @retry: number of retries to the command IOCB.
3426 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3427 * when connected to a fabric, or to the remote port when connected
3428 * in point-to-point mode. When sent to the Fabric Controller, it will
3429 * replay the RSCN to registered recipients.
3431 * Note that the ndlp reference count will be incremented by 1 for holding the
3432 * ndlp and the reference to ndlp will be stored into the context1 field of
3433 * the IOCB for the completion callback function to the RSCN ELS command.
3436 * 0 - Successfully issued RSCN command
3437 * 1 - Failed to issue RSCN command
3440 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3443 struct lpfc_hba *phba = vport->phba;
3444 struct lpfc_iocbq *elsiocb;
3445 struct lpfc_nodelist *ndlp;
3447 struct fc_els_rscn rscn;
3448 struct fc_els_rscn_page portid;
3451 uint16_t cmdsize = sizeof(*event);
3453 /* Not supported for private loop */
3454 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3455 !(vport->fc_flag & FC_PUBLIC_LOOP))
3458 if (vport->fc_flag & FC_PT2PT) {
3459 /* find any mapped nport - that would be the other nport */
3460 ndlp = lpfc_findnode_mapped(vport);
3464 nportid = FC_FID_FCTRL;
3465 /* find the fabric controller node */
3466 ndlp = lpfc_findnode_did(vport, nportid);
3468 /* if one didn't exist, make one */
3469 ndlp = lpfc_nlp_init(vport, nportid);
3472 lpfc_enqueue_node(vport, ndlp);
3476 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3477 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3482 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3484 event->rscn.rscn_cmd = ELS_RSCN;
3485 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3486 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3488 nportid = vport->fc_myDID;
3489 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3490 event->portid.rscn_page_flags = 0;
3491 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3492 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3493 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3495 phba->fc_stat.elsXmitRSCN++;
3496 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3497 elsiocb->context1 = lpfc_nlp_get(ndlp);
3498 if (!elsiocb->context1) {
3499 lpfc_els_free_iocb(phba, elsiocb);
3503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3504 "Issue RSCN: did:x%x",
3505 ndlp->nlp_DID, 0, 0);
3507 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3508 if (rc == IOCB_ERROR) {
3509 lpfc_els_free_iocb(phba, elsiocb);
3514 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3515 * trigger the release of node.
3517 if (!(vport->fc_flag & FC_PT2PT))
3523 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3524 * @vport: pointer to a host virtual N_Port data structure.
3525 * @nportid: N_Port identifier to the remote node.
3526 * @retry: number of retries to the command IOCB.
3528 * This routine issues a Fibre Channel Address Resolution Response
3529 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3530 * is passed into the function. It first search the @vport node list to find
3531 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3532 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3533 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3535 * Note that the ndlp reference count will be incremented by 1 for holding the
3536 * ndlp and the reference to ndlp will be stored into the context1 field of
3537 * the IOCB for the completion callback function to the FARPR ELS command.
3540 * 0 - Successfully issued farpr command
3541 * 1 - Failed to issue farpr command
3544 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3547 struct lpfc_hba *phba = vport->phba;
3548 struct lpfc_iocbq *elsiocb;
3553 struct lpfc_nodelist *ondlp;
3554 struct lpfc_nodelist *ndlp;
3556 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3558 ndlp = lpfc_findnode_did(vport, nportid);
3560 ndlp = lpfc_nlp_init(vport, nportid);
3563 lpfc_enqueue_node(vport, ndlp);
3566 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3567 ndlp->nlp_DID, ELS_CMD_RNID);
3571 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3573 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3574 pcmd += sizeof(uint32_t);
3576 /* Fill in FARPR payload */
3577 fp = (FARP *) (pcmd);
3578 memset(fp, 0, sizeof(FARP));
3579 lp = (uint32_t *) pcmd;
3580 *lp++ = be32_to_cpu(nportid);
3581 *lp++ = be32_to_cpu(vport->fc_myDID);
3583 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3585 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3586 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3587 ondlp = lpfc_findnode_did(vport, nportid);
3589 memcpy(&fp->OportName, &ondlp->nlp_portname,
3590 sizeof(struct lpfc_name));
3591 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3592 sizeof(struct lpfc_name));
3595 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3596 "Issue FARPR: did:x%x",
3597 ndlp->nlp_DID, 0, 0);
3599 phba->fc_stat.elsXmitFARPR++;
3600 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3601 elsiocb->context1 = lpfc_nlp_get(ndlp);
3602 if (!elsiocb->context1) {
3603 lpfc_els_free_iocb(phba, elsiocb);
3607 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3608 if (rc == IOCB_ERROR) {
3609 /* The additional lpfc_nlp_put will cause the following
3610 * lpfc_els_free_iocb routine to trigger the release of
3613 lpfc_els_free_iocb(phba, elsiocb);
3617 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3618 * trigger the release of the node.
3620 /* Don't release reference count as RDF is likely outstanding */
3625 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3626 * @vport: pointer to a host virtual N_Port data structure.
3627 * @retry: retry counter for the command IOCB.
3629 * This routine issues an ELS RDF to the Fabric Controller to register
3630 * for diagnostic functions.
3632 * Note that the ndlp reference count will be incremented by 1 for holding the
3633 * ndlp and the reference to ndlp will be stored into the context1 field of
3634 * the IOCB for the completion callback function to the RDF ELS command.
3637 * 0 - Successfully issued rdf command
3638 * 1 - Failed to issue rdf command
3641 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3643 struct lpfc_hba *phba = vport->phba;
3644 struct lpfc_iocbq *elsiocb;
3645 struct lpfc_els_rdf_req *prdf;
3646 struct lpfc_nodelist *ndlp;
3650 cmdsize = sizeof(*prdf);
3652 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3654 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3657 lpfc_enqueue_node(vport, ndlp);
3660 /* RDF ELS is not required on an NPIV VN_Port. */
3661 if (vport->port_type == LPFC_NPIV_PORT) {
3666 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3667 ndlp->nlp_DID, ELS_CMD_RDF);
3671 if (phba->sli_rev == LPFC_SLI_REV4 &&
3672 !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
3673 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3674 "0939 %s: FC_NODE x%x RPI x%x flag x%x "
3675 "ste x%x type x%x Not registered\n",
3676 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
3677 ndlp->nlp_flag, ndlp->nlp_state,
3682 /* Configure the payload for the supported FPIN events. */
3683 prdf = (struct lpfc_els_rdf_req *)
3684 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3685 memset(prdf, 0, cmdsize);
3686 prdf->rdf.fpin_cmd = ELS_RDF;
3687 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3688 sizeof(struct fc_els_rdf));
3689 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3690 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3691 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3692 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3693 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3694 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3695 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3696 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3699 "6444 Xmit RDF to remote NPORT x%x\n",
3702 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3703 elsiocb->context1 = lpfc_nlp_get(ndlp);
3704 if (!elsiocb->context1) {
3705 lpfc_els_free_iocb(phba, elsiocb);
3709 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3710 "Issue RDF: did:x%x refcnt %d",
3711 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3713 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3714 if (rc == IOCB_ERROR) {
3715 lpfc_els_free_iocb(phba, elsiocb);
3723 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
3724 * @vport: pointer to a host virtual N_Port data structure.
3725 * @cmdiocb: pointer to lpfc command iocb data structure.
3726 * @ndlp: pointer to a node-list data structure.
3728 * A received RDF implies a possible change to fabric supported diagnostic
3729 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
3730 * RDF request to reregister for supported diagnostic functions.
3734 * -EIO - Failed to process received RDF
3737 lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3738 struct lpfc_nodelist *ndlp)
3741 if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) {
3742 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3743 "1623 Failed to RDF_ACC from x%x for x%x\n",
3744 ndlp->nlp_DID, vport->fc_myDID);
3748 /* Issue new RDF for reregistering */
3749 if (lpfc_issue_els_rdf(vport, 0)) {
3750 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3751 "2623 Failed to re register RDF for x%x\n",
3760 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3761 * @vport: pointer to a host virtual N_Port data structure.
3762 * @nlp: pointer to a node-list data structure.
3764 * This routine cancels the timer with a delayed IOCB-command retry for
3765 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3766 * removes the ELS retry event if it presents. In addition, if the
3767 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3768 * commands are sent for the @vport's nodes that require issuing discovery
3772 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3775 struct lpfc_work_evt *evtp;
3777 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3779 spin_lock_irq(&nlp->lock);
3780 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3781 spin_unlock_irq(&nlp->lock);
3782 del_timer_sync(&nlp->nlp_delayfunc);
3783 nlp->nlp_last_elscmd = 0;
3784 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3785 list_del_init(&nlp->els_retry_evt.evt_listp);
3786 /* Decrement nlp reference count held for the delayed retry */
3787 evtp = &nlp->els_retry_evt;
3788 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3790 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3791 spin_lock_irq(&nlp->lock);
3792 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3793 spin_unlock_irq(&nlp->lock);
3794 if (vport->num_disc_nodes) {
3795 if (vport->port_state < LPFC_VPORT_READY) {
3796 /* Check if there are more ADISCs to be sent */
3797 lpfc_more_adisc(vport);
3799 /* Check if there are more PLOGIs to be sent */
3800 lpfc_more_plogi(vport);
3801 if (vport->num_disc_nodes == 0) {
3802 spin_lock_irq(shost->host_lock);
3803 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3804 spin_unlock_irq(shost->host_lock);
3805 lpfc_can_disctmo(vport);
3806 lpfc_end_rscn(vport);
3815 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3816 * @t: pointer to the timer function associated data (ndlp).
3818 * This routine is invoked by the ndlp delayed-function timer to check
3819 * whether there is any pending ELS retry event(s) with the node. If not, it
3820 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3821 * adds the delayed events to the HBA work list and invokes the
3822 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3823 * event. Note that lpfc_nlp_get() is called before posting the event to
3824 * the work list to hold reference count of ndlp so that it guarantees the
3825 * reference to ndlp will still be available when the worker thread gets
3826 * to the event associated with the ndlp.
3829 lpfc_els_retry_delay(struct timer_list *t)
3831 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3832 struct lpfc_vport *vport = ndlp->vport;
3833 struct lpfc_hba *phba = vport->phba;
3834 unsigned long flags;
3835 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3837 spin_lock_irqsave(&phba->hbalock, flags);
3838 if (!list_empty(&evtp->evt_listp)) {
3839 spin_unlock_irqrestore(&phba->hbalock, flags);
3843 /* We need to hold the node by incrementing the reference
3844 * count until the queued work is done
3846 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3847 if (evtp->evt_arg1) {
3848 evtp->evt = LPFC_EVT_ELS_RETRY;
3849 list_add_tail(&evtp->evt_listp, &phba->work_list);
3850 lpfc_worker_wake_up(phba);
3852 spin_unlock_irqrestore(&phba->hbalock, flags);
3857 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3858 * @ndlp: pointer to a node-list data structure.
3860 * This routine is the worker-thread handler for processing the @ndlp delayed
3861 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3862 * the last ELS command from the associated ndlp and invokes the proper ELS
3863 * function according to the delayed ELS command to retry the command.
3866 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3868 struct lpfc_vport *vport = ndlp->vport;
3869 uint32_t cmd, retry;
3871 spin_lock_irq(&ndlp->lock);
3872 cmd = ndlp->nlp_last_elscmd;
3873 ndlp->nlp_last_elscmd = 0;
3875 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3876 spin_unlock_irq(&ndlp->lock);
3880 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3881 spin_unlock_irq(&ndlp->lock);
3883 * If a discovery event readded nlp_delayfunc after timer
3884 * firing and before processing the timer, cancel the
3887 del_timer_sync(&ndlp->nlp_delayfunc);
3888 retry = ndlp->nlp_retry;
3889 ndlp->nlp_retry = 0;
3893 lpfc_issue_els_flogi(vport, ndlp, retry);
3896 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3897 ndlp->nlp_prev_state = ndlp->nlp_state;
3898 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3902 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3903 ndlp->nlp_prev_state = ndlp->nlp_state;
3904 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3908 case ELS_CMD_NVMEPRLI:
3909 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3910 ndlp->nlp_prev_state = ndlp->nlp_state;
3911 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3915 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3916 ndlp->nlp_prev_state = ndlp->nlp_state;
3917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3921 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3922 lpfc_issue_els_fdisc(vport, ndlp, retry);
3929 * lpfc_link_reset - Issue link reset
3930 * @vport: pointer to a virtual N_Port data structure.
3932 * This routine performs link reset by sending INIT_LINK mailbox command.
3933 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3934 * INIT_LINK mailbox command.
3937 * 0 - Link reset initiated successfully
3938 * 1 - Failed to initiate link reset
3941 lpfc_link_reset(struct lpfc_vport *vport)
3943 struct lpfc_hba *phba = vport->phba;
3948 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3949 "2851 Attempt link reset\n");
3950 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3952 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3953 "2852 Failed to allocate mbox memory");
3957 /* Enable Link attention interrupts */
3958 if (phba->sli_rev <= LPFC_SLI_REV3) {
3959 spin_lock_irq(&phba->hbalock);
3960 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3961 control = readl(phba->HCregaddr);
3962 control |= HC_LAINT_ENA;
3963 writel(control, phba->HCregaddr);
3964 readl(phba->HCregaddr); /* flush */
3965 spin_unlock_irq(&phba->hbalock);
3968 lpfc_init_link(phba, mbox, phba->cfg_topology,
3969 phba->cfg_link_speed);
3970 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3971 mbox->vport = vport;
3972 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3973 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3974 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3975 "2853 Failed to issue INIT_LINK "
3976 "mbox command, rc:x%x\n", rc);
3977 mempool_free(mbox, phba->mbox_mem_pool);
3985 * lpfc_els_retry - Make retry decision on an els command iocb
3986 * @phba: pointer to lpfc hba data structure.
3987 * @cmdiocb: pointer to lpfc command iocb data structure.
3988 * @rspiocb: pointer to lpfc response iocb data structure.
3990 * This routine makes a retry decision on an ELS command IOCB, which has
3991 * failed. The following ELS IOCBs use this function for retrying the command
3992 * when previously issued command responsed with error status: FLOGI, PLOGI,
3993 * PRLI, ADISC and FDISC. Based on the ELS command type and the
3994 * returned error status, it makes the decision whether a retry shall be
3995 * issued for the command, and whether a retry shall be made immediately or
3996 * delayed. In the former case, the corresponding ELS command issuing-function
3997 * is called to retry the command. In the later case, the ELS command shall
3998 * be posted to the ndlp delayed event and delayed function timer set to the
3999 * ndlp for the delayed command issusing.
4002 * 0 - No retry of els command is made
4003 * 1 - Immediate or delayed retry of els command is made
4006 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4007 struct lpfc_iocbq *rspiocb)
4009 struct lpfc_vport *vport = cmdiocb->vport;
4010 IOCB_t *irsp = &rspiocb->iocb;
4011 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4012 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4015 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
4019 int link_reset = 0, rc;
4022 /* Note: context2 may be 0 for internal driver abort
4023 * of delays ELS command.
4026 if (pcmd && pcmd->virt) {
4027 elscmd = (uint32_t *) (pcmd->virt);
4032 did = ndlp->nlp_DID;
4034 /* We should only hit this case for retrying PLOGI */
4035 did = irsp->un.elsreq64.remoteID;
4036 ndlp = lpfc_findnode_did(vport, did);
4037 if (!ndlp && (cmd != ELS_CMD_PLOGI))
4041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4042 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
4043 *(((uint32_t *)irsp) + 7), irsp->un.ulpWord[4], did);
4045 switch (irsp->ulpStatus) {
4046 case IOSTAT_FCP_RSP_ERROR:
4048 case IOSTAT_REMOTE_STOP:
4049 if (phba->sli_rev == LPFC_SLI_REV4) {
4050 /* This IO was aborted by the target, we don't
4051 * know the rxid and because we did not send the
4052 * ABTS we cannot generate and RRQ.
4054 lpfc_set_rrq_active(phba, ndlp,
4055 cmdiocb->sli4_lxritag, 0, 0);
4058 case IOSTAT_LOCAL_REJECT:
4059 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
4060 case IOERR_LOOP_OPEN_FAILURE:
4061 if (cmd == ELS_CMD_FLOGI) {
4062 if (PCI_DEVICE_ID_HORNET ==
4063 phba->pcidev->device) {
4064 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
4065 phba->pport->fc_myDID = 0;
4066 phba->alpa_map[0] = 0;
4067 phba->alpa_map[1] = 0;
4070 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
4075 case IOERR_ILLEGAL_COMMAND:
4076 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4077 "0124 Retry illegal cmd x%x "
4078 "retry:x%x delay:x%x\n",
4079 cmd, cmdiocb->retry, delay);
4081 /* All command's retry policy */
4083 if (cmdiocb->retry > 2)
4087 case IOERR_NO_RESOURCES:
4088 logerr = 1; /* HBA out of resources */
4090 if (cmdiocb->retry > 100)
4095 case IOERR_ILLEGAL_FRAME:
4100 case IOERR_INVALID_RPI:
4101 if (cmd == ELS_CMD_PLOGI &&
4102 did == NameServer_DID) {
4103 /* Continue forever if plogi to */
4104 /* the nameserver fails */
4111 case IOERR_SEQUENCE_TIMEOUT:
4112 if (cmd == ELS_CMD_PLOGI &&
4113 did == NameServer_DID &&
4114 (cmdiocb->retry + 1) == maxretry) {
4115 /* Reset the Link */
4125 case IOSTAT_NPORT_RJT:
4126 case IOSTAT_FABRIC_RJT:
4127 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4133 case IOSTAT_NPORT_BSY:
4134 case IOSTAT_FABRIC_BSY:
4135 logerr = 1; /* Fabric / Remote NPort out of resources */
4140 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
4141 /* Added for Vendor specifc support
4142 * Just keep retrying for these Rsn / Exp codes
4144 switch (stat.un.b.lsRjtRsnCode) {
4145 case LSRJT_UNABLE_TPC:
4146 /* The driver has a VALID PLOGI but the rport has
4147 * rejected the PRLI - can't do it now. Delay
4148 * for 1 second and try again.
4150 * However, if explanation is REQ_UNSUPPORTED there's
4151 * no point to retry PRLI.
4153 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
4154 stat.un.b.lsRjtRsnCodeExp !=
4155 LSEXP_REQ_UNSUPPORTED) {
4157 maxretry = lpfc_max_els_tries + 1;
4162 /* Legacy bug fix code for targets with PLOGI delays. */
4163 if (stat.un.b.lsRjtRsnCodeExp ==
4164 LSEXP_CMD_IN_PROGRESS) {
4165 if (cmd == ELS_CMD_PLOGI) {
4172 if (stat.un.b.lsRjtRsnCodeExp ==
4173 LSEXP_CANT_GIVE_DATA) {
4174 if (cmd == ELS_CMD_PLOGI) {
4181 if (cmd == ELS_CMD_PLOGI) {
4183 maxretry = lpfc_max_els_tries + 1;
4187 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4188 (cmd == ELS_CMD_FDISC) &&
4189 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
4190 lpfc_printf_vlog(vport, KERN_ERR,
4192 "0125 FDISC Failed (x%x). "
4193 "Fabric out of resources\n",
4194 stat.un.lsRjtError);
4195 lpfc_vport_set_state(vport,
4196 FC_VPORT_NO_FABRIC_RSCS);
4200 case LSRJT_LOGICAL_BSY:
4201 if ((cmd == ELS_CMD_PLOGI) ||
4202 (cmd == ELS_CMD_PRLI) ||
4203 (cmd == ELS_CMD_NVMEPRLI)) {
4206 } else if (cmd == ELS_CMD_FDISC) {
4207 /* FDISC retry policy */
4209 if (cmdiocb->retry >= 32)
4215 case LSRJT_LOGICAL_ERR:
4216 /* There are some cases where switches return this
4217 * error when they are not ready and should be returning
4218 * Logical Busy. We should delay every time.
4220 if (cmd == ELS_CMD_FDISC &&
4221 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4225 } else if (cmd == ELS_CMD_FLOGI &&
4226 stat.un.b.lsRjtRsnCodeExp ==
4227 LSEXP_NOTHING_MORE) {
4228 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4230 lpfc_printf_vlog(vport, KERN_ERR,
4232 "0820 FLOGI Failed (x%x). "
4233 "BBCredit Not Supported\n",
4234 stat.un.lsRjtError);
4238 case LSRJT_PROTOCOL_ERR:
4239 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4240 (cmd == ELS_CMD_FDISC) &&
4241 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4242 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4244 lpfc_printf_vlog(vport, KERN_ERR,
4246 "0122 FDISC Failed (x%x). "
4247 "Fabric Detected Bad WWN\n",
4248 stat.un.lsRjtError);
4249 lpfc_vport_set_state(vport,
4250 FC_VPORT_FABRIC_REJ_WWN);
4253 case LSRJT_VENDOR_UNIQUE:
4254 if ((stat.un.b.vendorUnique == 0x45) &&
4255 (cmd == ELS_CMD_FLOGI)) {
4259 case LSRJT_CMD_UNSUPPORTED:
4260 /* lpfc nvmet returns this type of LS_RJT when it
4261 * receives an FCP PRLI because lpfc nvmet only
4262 * support NVME. ELS request is terminated for FCP4
4265 if (stat.un.b.lsRjtRsnCodeExp ==
4266 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4267 spin_lock_irq(&ndlp->lock);
4268 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4269 spin_unlock_irq(&ndlp->lock);
4277 case IOSTAT_INTERMED_RSP:
4286 rc = lpfc_link_reset(vport);
4288 /* Do not give up. Retry PLOGI one more time and attempt
4289 * link reset if PLOGI fails again.
4298 if (did == FDMI_DID)
4301 if ((cmd == ELS_CMD_FLOGI) &&
4302 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4303 !lpfc_error_lost_link(irsp)) {
4304 /* FLOGI retry policy */
4306 /* retry FLOGI forever */
4307 if (phba->link_flag != LS_LOOPBACK_MODE)
4312 if (cmdiocb->retry >= 100)
4314 else if (cmdiocb->retry >= 32)
4316 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4317 /* retry FDISCs every second up to devloss */
4319 maxretry = vport->cfg_devloss_tmo;
4324 if (maxretry && (cmdiocb->retry >= maxretry)) {
4325 phba->fc_stat.elsRetryExceeded++;
4329 if ((vport->load_flag & FC_UNLOADING) != 0)
4334 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4335 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4336 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4337 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4338 "2849 Stop retry ELS command "
4339 "x%x to remote NPORT x%x, "
4340 "Data: x%x x%x\n", cmd, did,
4341 cmdiocb->retry, delay);
4346 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4347 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4348 "0107 Retry ELS command x%x to remote "
4349 "NPORT x%x Data: x%x x%x\n",
4350 cmd, did, cmdiocb->retry, delay);
4352 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4353 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4354 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4355 IOERR_NO_RESOURCES))) {
4356 /* Don't reset timer for no resources */
4358 /* If discovery / RSCN timer is running, reset it */
4359 if (timer_pending(&vport->fc_disctmo) ||
4360 (vport->fc_flag & FC_RSCN_MODE))
4361 lpfc_set_disctmo(vport);
4364 phba->fc_stat.elsXmitRetry++;
4365 if (ndlp && delay) {
4366 phba->fc_stat.elsDelayRetry++;
4367 ndlp->nlp_retry = cmdiocb->retry;
4369 /* delay is specified in milliseconds */
4370 mod_timer(&ndlp->nlp_delayfunc,
4371 jiffies + msecs_to_jiffies(delay));
4372 spin_lock_irq(&ndlp->lock);
4373 ndlp->nlp_flag |= NLP_DELAY_TMO;
4374 spin_unlock_irq(&ndlp->lock);
4376 ndlp->nlp_prev_state = ndlp->nlp_state;
4377 if ((cmd == ELS_CMD_PRLI) ||
4378 (cmd == ELS_CMD_NVMEPRLI))
4379 lpfc_nlp_set_state(vport, ndlp,
4380 NLP_STE_PRLI_ISSUE);
4382 lpfc_nlp_set_state(vport, ndlp,
4384 ndlp->nlp_last_elscmd = cmd;
4390 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4393 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4397 ndlp->nlp_prev_state = ndlp->nlp_state;
4398 lpfc_nlp_set_state(vport, ndlp,
4399 NLP_STE_PLOGI_ISSUE);
4401 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4404 ndlp->nlp_prev_state = ndlp->nlp_state;
4405 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4406 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4409 case ELS_CMD_NVMEPRLI:
4410 ndlp->nlp_prev_state = ndlp->nlp_state;
4411 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4412 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4415 ndlp->nlp_prev_state = ndlp->nlp_state;
4416 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4417 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4421 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4423 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4424 "0137 No retry ELS command x%x to remote "
4425 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4426 cmd, did, irsp->ulpStatus,
4427 irsp->un.ulpWord[4]);
4430 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4431 "0108 No retry ELS command x%x to remote "
4432 "NPORT x%x Retried:%d Error:x%x/%x\n",
4433 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4434 irsp->un.ulpWord[4]);
4440 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4441 * @phba: pointer to lpfc hba data structure.
4442 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4444 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4445 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4446 * checks to see whether there is a lpfc DMA buffer associated with the
4447 * response of the command IOCB. If so, it will be released before releasing
4448 * the lpfc DMA buffer associated with the IOCB itself.
4451 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4454 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4456 struct lpfc_dmabuf *buf_ptr;
4458 /* Free the response before processing the command. */
4459 if (!list_empty(&buf_ptr1->list)) {
4460 list_remove_head(&buf_ptr1->list, buf_ptr,
4463 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4466 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4472 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4473 * @phba: pointer to lpfc hba data structure.
4474 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4476 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4477 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4481 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4484 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4486 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4492 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4493 * @phba: pointer to lpfc hba data structure.
4494 * @elsiocb: pointer to lpfc els command iocb data structure.
4496 * This routine frees a command IOCB and its associated resources. The
4497 * command IOCB data structure contains the reference to various associated
4498 * resources, these fields must be set to NULL if the associated reference
4500 * context1 - reference to ndlp
4501 * context2 - reference to cmd
4502 * context2->next - reference to rsp
4503 * context3 - reference to bpl
4505 * It first properly decrements the reference count held on ndlp for the
4506 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4507 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4508 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4509 * adds the DMA buffer the @phba data structure for the delayed release.
4510 * If reference to the Buffer Pointer List (BPL) is present, the
4511 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4512 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4513 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4516 * 0 - Success (currently, always return 0)
4519 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4521 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4523 /* The I/O job is complete. Clear the context1 data. */
4524 elsiocb->context1 = NULL;
4526 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4527 if (elsiocb->context2) {
4528 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4529 /* Firmware could still be in progress of DMAing
4530 * payload, so don't free data buffer till after
4533 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4534 buf_ptr = elsiocb->context2;
4535 elsiocb->context2 = NULL;
4538 spin_lock_irq(&phba->hbalock);
4539 if (!list_empty(&buf_ptr->list)) {
4540 list_remove_head(&buf_ptr->list,
4541 buf_ptr1, struct lpfc_dmabuf,
4543 INIT_LIST_HEAD(&buf_ptr1->list);
4544 list_add_tail(&buf_ptr1->list,
4548 INIT_LIST_HEAD(&buf_ptr->list);
4549 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4551 spin_unlock_irq(&phba->hbalock);
4554 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4555 lpfc_els_free_data(phba, buf_ptr1);
4556 elsiocb->context2 = NULL;
4560 if (elsiocb->context3) {
4561 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4562 lpfc_els_free_bpl(phba, buf_ptr);
4563 elsiocb->context3 = NULL;
4565 lpfc_sli_release_iocbq(phba, elsiocb);
4570 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4571 * @phba: pointer to lpfc hba data structure.
4572 * @cmdiocb: pointer to lpfc command iocb data structure.
4573 * @rspiocb: pointer to lpfc response iocb data structure.
4575 * This routine is the completion callback function to the Logout (LOGO)
4576 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4577 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4578 * release the ndlp if it has the last reference remaining (reference count
4579 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4580 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4581 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4582 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4583 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4584 * IOCB data structure.
4587 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4588 struct lpfc_iocbq *rspiocb)
4590 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4591 struct lpfc_vport *vport = cmdiocb->vport;
4594 irsp = &rspiocb->iocb;
4595 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4596 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4597 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4598 /* ACC to LOGO completes to NPort <nlp_DID> */
4599 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4600 "0109 ACC to LOGO completes to NPort x%x refcnt %d "
4601 "Data: x%x x%x x%x\n",
4602 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
4603 ndlp->nlp_state, ndlp->nlp_rpi);
4605 /* This clause allows the LOGO ACC to complete and free resources
4606 * for the Fabric Domain Controller. It does deliberately skip
4607 * the unreg_rpi and release rpi because some fabrics send RDP
4608 * requests after logging out from the initiator.
4610 if (ndlp->nlp_type & NLP_FABRIC &&
4611 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
4614 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4615 /* NPort Recovery mode or node is just allocated */
4616 if (!lpfc_nlp_not_used(ndlp)) {
4617 /* A LOGO is completing and the node is in NPR state.
4618 * If this a fabric node that cleared its transport
4619 * registration, release the rpi.
4621 spin_lock_irq(&ndlp->lock);
4622 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4623 if (phba->sli_rev == LPFC_SLI_REV4)
4624 ndlp->nlp_flag |= NLP_RELEASE_RPI;
4625 spin_unlock_irq(&ndlp->lock);
4626 lpfc_unreg_rpi(vport, ndlp);
4628 /* Indicate the node has already released, should
4629 * not reference to it from within lpfc_els_free_iocb.
4631 cmdiocb->context1 = NULL;
4636 * The driver received a LOGO from the rport and has ACK'd it.
4637 * At this point, the driver is done so release the IOCB
4639 lpfc_els_free_iocb(phba, cmdiocb);
4644 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4645 * @phba: pointer to lpfc hba data structure.
4646 * @pmb: pointer to the driver internal queue element for mailbox command.
4648 * This routine is the completion callback function for unregister default
4649 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4650 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4651 * decrements the ndlp reference count held for this completion callback
4652 * function. After that, it invokes the lpfc_nlp_not_used() to check
4653 * whether there is only one reference left on the ndlp. If so, it will
4654 * perform one more decrement and trigger the release of the ndlp.
4657 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4659 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4660 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4661 u32 mbx_flag = pmb->mbox_flag;
4662 u32 mbx_cmd = pmb->u.mb.mbxCommand;
4664 pmb->ctx_buf = NULL;
4665 pmb->ctx_ndlp = NULL;
4668 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4669 "0006 rpi x%x DID:%x flg:%x %d x%px "
4670 "mbx_cmd x%x mbx_flag x%x x%px\n",
4671 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4672 kref_read(&ndlp->kref), ndlp, mbx_cmd,
4675 /* This ends the default/temporary RPI cleanup logic for this
4676 * ndlp and the node and rpi needs to be released. Free the rpi
4677 * first on an UNREG_LOGIN and then release the final
4680 spin_lock_irq(&ndlp->lock);
4681 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4682 if (mbx_cmd == MBX_UNREG_LOGIN)
4683 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4684 spin_unlock_irq(&ndlp->lock);
4686 lpfc_drop_node(ndlp->vport, ndlp);
4689 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4691 mempool_free(pmb, phba->mbox_mem_pool);
4696 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4697 * @phba: pointer to lpfc hba data structure.
4698 * @cmdiocb: pointer to lpfc command iocb data structure.
4699 * @rspiocb: pointer to lpfc response iocb data structure.
4701 * This routine is the completion callback function for ELS Response IOCB
4702 * command. In normal case, this callback function just properly sets the
4703 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4704 * field in the command IOCB is not NULL, the referred mailbox command will
4705 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4709 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4710 struct lpfc_iocbq *rspiocb)
4712 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4713 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4714 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4716 LPFC_MBOXQ_t *mbox = NULL;
4717 struct lpfc_dmabuf *mp = NULL;
4719 irsp = &rspiocb->iocb;
4722 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4723 "3177 ELS response failed\n");
4726 if (cmdiocb->context_un.mbox)
4727 mbox = cmdiocb->context_un.mbox;
4729 /* Check to see if link went down during discovery */
4730 if (!ndlp || lpfc_els_chk_latt(vport)) {
4732 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4734 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4737 mempool_free(mbox, phba->mbox_mem_pool);
4742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4743 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4744 irsp->ulpStatus, irsp->un.ulpWord[4],
4745 cmdiocb->iocb.un.elsreq64.remoteID);
4746 /* ELS response tag <ulpIoTag> completes */
4747 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4748 "0110 ELS response tag x%x completes "
4749 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%px\n",
4750 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4751 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4752 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4753 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox);
4755 if ((rspiocb->iocb.ulpStatus == 0) &&
4756 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4757 if (!lpfc_unreg_rpi(vport, ndlp) &&
4758 (!(vport->fc_flag & FC_PT2PT))) {
4759 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
4760 lpfc_printf_vlog(vport, KERN_INFO,
4764 "Data: x%x x%x x%x\n",
4771 lpfc_mbuf_free(phba, mp->virt,
4775 mempool_free(mbox, phba->mbox_mem_pool);
4780 /* Increment reference count to ndlp to hold the
4781 * reference to ndlp for the callback function.
4783 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4784 if (!mbox->ctx_ndlp)
4787 mbox->vport = vport;
4788 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4789 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4790 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4793 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4794 ndlp->nlp_prev_state = ndlp->nlp_state;
4795 lpfc_nlp_set_state(vport, ndlp,
4796 NLP_STE_REG_LOGIN_ISSUE);
4799 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4800 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4801 != MBX_NOT_FINISHED)
4804 /* Decrement the ndlp reference count we
4805 * set for this failed mailbox command.
4808 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4810 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4811 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4812 "0138 ELS rsp: Cannot issue reg_login for x%x "
4813 "Data: x%x x%x x%x\n",
4814 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4817 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4819 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4822 mempool_free(mbox, phba->mbox_mem_pool);
4825 if (ndlp && shost) {
4826 spin_lock_irq(&ndlp->lock);
4828 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4829 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4830 spin_unlock_irq(&ndlp->lock);
4833 /* An SLI4 NPIV instance wants to drop the node at this point under
4834 * these conditions and release the RPI.
4836 if (phba->sli_rev == LPFC_SLI_REV4 &&
4837 (vport && vport->port_type == LPFC_NPIV_PORT) &&
4838 ndlp->nlp_flag & NLP_RELEASE_RPI) {
4839 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
4840 spin_lock_irq(&ndlp->lock);
4841 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
4842 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
4843 spin_unlock_irq(&ndlp->lock);
4844 lpfc_drop_node(vport, ndlp);
4847 /* Release the originating I/O reference. */
4848 lpfc_els_free_iocb(phba, cmdiocb);
4854 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4855 * @vport: pointer to a host virtual N_Port data structure.
4856 * @flag: the els command code to be accepted.
4857 * @oldiocb: pointer to the original lpfc command iocb data structure.
4858 * @ndlp: pointer to a node-list data structure.
4859 * @mbox: pointer to the driver internal queue element for mailbox command.
4861 * This routine prepares and issues an Accept (ACC) response IOCB
4862 * command. It uses the @flag to properly set up the IOCB field for the
4863 * specific ACC response command to be issued and invokes the
4864 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4865 * @mbox pointer is passed in, it will be put into the context_un.mbox
4866 * field of the IOCB for the completion callback function to issue the
4867 * mailbox command to the HBA later when callback is invoked.
4869 * Note that the ndlp reference count will be incremented by 1 for holding the
4870 * ndlp and the reference to ndlp will be stored into the context1 field of
4871 * the IOCB for the completion callback function to the corresponding
4872 * response ELS IOCB command.
4875 * 0 - Successfully issued acc response
4876 * 1 - Failed to issue acc response
4879 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4880 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4883 struct lpfc_hba *phba = vport->phba;
4886 struct lpfc_iocbq *elsiocb;
4888 struct serv_parm *sp;
4891 ELS_PKT *els_pkt_ptr;
4892 struct fc_els_rdf_resp *rdf_resp;
4894 oldcmd = &oldiocb->iocb;
4898 cmdsize = sizeof(uint32_t);
4899 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4900 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4902 spin_lock_irq(&ndlp->lock);
4903 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4904 spin_unlock_irq(&ndlp->lock);
4908 icmd = &elsiocb->iocb;
4909 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4910 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4911 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4912 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4913 pcmd += sizeof(uint32_t);
4915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4916 "Issue ACC: did:x%x flg:x%x",
4917 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4921 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4922 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4923 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4927 icmd = &elsiocb->iocb;
4928 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4929 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4930 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4933 elsiocb->context_un.mbox = mbox;
4935 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4936 pcmd += sizeof(uint32_t);
4937 sp = (struct serv_parm *)pcmd;
4939 if (flag == ELS_CMD_FLOGI) {
4940 /* Copy the received service parameters back */
4941 memcpy(sp, &phba->fc_fabparam,
4942 sizeof(struct serv_parm));
4944 /* Clear the F_Port bit */
4947 /* Mark all class service parameters as invalid */
4948 sp->cls1.classValid = 0;
4949 sp->cls2.classValid = 0;
4950 sp->cls3.classValid = 0;
4951 sp->cls4.classValid = 0;
4953 /* Copy our worldwide names */
4954 memcpy(&sp->portName, &vport->fc_sparam.portName,
4955 sizeof(struct lpfc_name));
4956 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4957 sizeof(struct lpfc_name));
4959 memcpy(pcmd, &vport->fc_sparam,
4960 sizeof(struct serv_parm));
4962 sp->cmn.valid_vendor_ver_level = 0;
4963 memset(sp->un.vendorVersion, 0,
4964 sizeof(sp->un.vendorVersion));
4965 sp->cmn.bbRcvSizeMsb &= 0xF;
4967 /* If our firmware supports this feature, convey that
4968 * info to the target using the vendor specific field.
4970 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4971 sp->cmn.valid_vendor_ver_level = 1;
4972 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4974 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4979 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4980 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4983 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4984 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4985 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4989 icmd = &elsiocb->iocb;
4990 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4991 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4992 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4994 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4995 sizeof(uint32_t) + sizeof(PRLO));
4996 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4997 els_pkt_ptr = (ELS_PKT *) pcmd;
4998 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
5000 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5001 "Issue ACC PRLO: did:x%x flg:x%x",
5002 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5005 cmdsize = sizeof(*rdf_resp);
5006 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5007 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5011 icmd = &elsiocb->iocb;
5012 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5013 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5014 pcmd = (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5015 rdf_resp = (struct fc_els_rdf_resp *)pcmd;
5016 memset(rdf_resp, 0, sizeof(*rdf_resp));
5017 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC;
5019 /* FC-LS-5 specifies desc_list_len shall be set to 12 */
5020 rdf_resp->desc_list_len = cpu_to_be32(12);
5022 /* FC-LS-5 specifies LS REQ Information descriptor */
5023 rdf_resp->lsri.desc_tag = cpu_to_be32(1);
5024 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32));
5025 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF;
5030 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
5031 spin_lock_irq(&ndlp->lock);
5032 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5033 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
5034 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5035 spin_unlock_irq(&ndlp->lock);
5036 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
5038 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5041 phba->fc_stat.elsXmitACC++;
5042 elsiocb->context1 = lpfc_nlp_get(ndlp);
5043 if (!elsiocb->context1) {
5044 lpfc_els_free_iocb(phba, elsiocb);
5048 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5049 if (rc == IOCB_ERROR) {
5050 lpfc_els_free_iocb(phba, elsiocb);
5055 /* Xmit ELS ACC response tag <ulpIoTag> */
5056 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5057 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5058 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5059 "RPI: x%x, fc_flag x%x refcnt %d\n",
5060 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5061 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5062 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref));
5067 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
5068 * @vport: pointer to a virtual N_Port data structure.
5069 * @rejectError: reject response to issue
5070 * @oldiocb: pointer to the original lpfc command iocb data structure.
5071 * @ndlp: pointer to a node-list data structure.
5072 * @mbox: pointer to the driver internal queue element for mailbox command.
5074 * This routine prepares and issue an Reject (RJT) response IOCB
5075 * command. If a @mbox pointer is passed in, it will be put into the
5076 * context_un.mbox field of the IOCB for the completion callback function
5077 * to issue to the HBA later.
5079 * Note that the ndlp reference count will be incremented by 1 for holding the
5080 * ndlp and the reference to ndlp will be stored into the context1 field of
5081 * the IOCB for the completion callback function to the reject response
5085 * 0 - Successfully issued reject response
5086 * 1 - Failed to issue reject response
5089 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
5090 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5094 struct lpfc_hba *phba = vport->phba;
5097 struct lpfc_iocbq *elsiocb;
5101 cmdsize = 2 * sizeof(uint32_t);
5102 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5103 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5107 icmd = &elsiocb->iocb;
5108 oldcmd = &oldiocb->iocb;
5109 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5110 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5111 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5113 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5114 pcmd += sizeof(uint32_t);
5115 *((uint32_t *) (pcmd)) = rejectError;
5118 elsiocb->context_un.mbox = mbox;
5120 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
5121 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5122 "0129 Xmit ELS RJT x%x response tag x%x "
5123 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5125 rejectError, elsiocb->iotag,
5126 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
5127 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
5128 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5129 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
5130 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
5132 phba->fc_stat.elsXmitLSRJT++;
5133 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5134 elsiocb->context1 = lpfc_nlp_get(ndlp);
5135 if (!elsiocb->context1) {
5136 lpfc_els_free_iocb(phba, elsiocb);
5140 /* The NPIV instance is rejecting this unsolicited ELS. Make sure the
5141 * node's assigned RPI needs to be released as this node will get
5144 if (phba->sli_rev == LPFC_SLI_REV4 &&
5145 vport->port_type == LPFC_NPIV_PORT) {
5146 spin_lock_irq(&ndlp->lock);
5147 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5148 spin_unlock_irq(&ndlp->lock);
5151 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5152 if (rc == IOCB_ERROR) {
5153 lpfc_els_free_iocb(phba, elsiocb);
5162 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
5163 * @vport: pointer to a virtual N_Port data structure.
5164 * @oldiocb: pointer to the original lpfc command iocb data structure.
5165 * @ndlp: pointer to a node-list data structure.
5167 * This routine prepares and issues an Accept (ACC) response to Address
5168 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
5169 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5171 * Note that the ndlp reference count will be incremented by 1 for holding the
5172 * ndlp and the reference to ndlp will be stored into the context1 field of
5173 * the IOCB for the completion callback function to the ADISC Accept response
5177 * 0 - Successfully issued acc adisc response
5178 * 1 - Failed to issue adisc acc response
5181 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5182 struct lpfc_nodelist *ndlp)
5184 struct lpfc_hba *phba = vport->phba;
5186 IOCB_t *icmd, *oldcmd;
5187 struct lpfc_iocbq *elsiocb;
5192 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
5193 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5194 ndlp->nlp_DID, ELS_CMD_ACC);
5198 icmd = &elsiocb->iocb;
5199 oldcmd = &oldiocb->iocb;
5200 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5201 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5203 /* Xmit ADISC ACC response tag <ulpIoTag> */
5204 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5205 "0130 Xmit ADISC ACC response iotag x%x xri: "
5206 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
5207 elsiocb->iotag, elsiocb->iocb.ulpContext,
5208 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5210 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5212 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5213 pcmd += sizeof(uint32_t);
5215 ap = (ADISC *) (pcmd);
5216 ap->hardAL_PA = phba->fc_pref_ALPA;
5217 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5218 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5219 ap->DID = be32_to_cpu(vport->fc_myDID);
5221 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5222 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5223 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5225 phba->fc_stat.elsXmitACC++;
5226 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5227 elsiocb->context1 = lpfc_nlp_get(ndlp);
5228 if (!elsiocb->context1) {
5229 lpfc_els_free_iocb(phba, elsiocb);
5233 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5234 if (rc == IOCB_ERROR) {
5235 lpfc_els_free_iocb(phba, elsiocb);
5240 /* Xmit ELS ACC response tag <ulpIoTag> */
5241 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5242 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5243 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5244 "RPI: x%x, fc_flag x%x\n",
5245 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5246 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5247 ndlp->nlp_rpi, vport->fc_flag);
5252 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5253 * @vport: pointer to a virtual N_Port data structure.
5254 * @oldiocb: pointer to the original lpfc command iocb data structure.
5255 * @ndlp: pointer to a node-list data structure.
5257 * This routine prepares and issues an Accept (ACC) response to Process
5258 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5259 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5261 * Note that the ndlp reference count will be incremented by 1 for holding the
5262 * ndlp and the reference to ndlp will be stored into the context1 field of
5263 * the IOCB for the completion callback function to the PRLI Accept response
5267 * 0 - Successfully issued acc prli response
5268 * 1 - Failed to issue acc prli response
5271 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5272 struct lpfc_nodelist *ndlp)
5274 struct lpfc_hba *phba = vport->phba;
5276 struct lpfc_nvme_prli *npr_nvme;
5280 struct lpfc_iocbq *elsiocb;
5283 uint32_t prli_fc4_req, *req_payload;
5284 struct lpfc_dmabuf *req_buf;
5288 /* Need the incoming PRLI payload to determine if the ACC is for an
5289 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5291 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5292 req_payload = (((uint32_t *)req_buf->virt) + 1);
5294 /* PRLI type payload is at byte 3 for FCP or NVME. */
5295 prli_fc4_req = be32_to_cpu(*req_payload);
5296 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5297 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5298 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5299 prli_fc4_req, *((uint32_t *)req_payload));
5301 if (prli_fc4_req == PRLI_FCP_TYPE) {
5302 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5303 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5304 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5305 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5306 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5311 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5312 ndlp->nlp_DID, elsrspcmd);
5316 icmd = &elsiocb->iocb;
5317 oldcmd = &oldiocb->iocb;
5318 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5319 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5321 /* Xmit PRLI ACC response tag <ulpIoTag> */
5322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5323 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5324 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5325 elsiocb->iotag, elsiocb->iocb.ulpContext,
5326 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5328 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5329 memset(pcmd, 0, cmdsize);
5331 *((uint32_t *)(pcmd)) = elsrspcmd;
5332 pcmd += sizeof(uint32_t);
5334 /* For PRLI, remainder of payload is PRLI parameter page */
5337 if (prli_fc4_req == PRLI_FCP_TYPE) {
5339 * If the remote port is a target and our firmware version
5340 * is 3.20 or later, set the following bits for FC-TAPE
5343 npr = (PRLI *) pcmd;
5344 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5345 (vpd->rev.feaLevelHigh >= 0x02)) {
5346 npr->ConfmComplAllowed = 1;
5348 npr->TaskRetryIdReq = 1;
5350 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5351 npr->estabImagePair = 1;
5352 npr->readXferRdyDis = 1;
5353 npr->ConfmComplAllowed = 1;
5354 npr->prliType = PRLI_FCP_TYPE;
5355 npr->initiatorFunc = 1;
5356 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5357 /* Respond with an NVME PRLI Type */
5358 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5359 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5360 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5361 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5362 if (phba->nvmet_support) {
5363 bf_set(prli_tgt, npr_nvme, 1);
5364 bf_set(prli_disc, npr_nvme, 1);
5365 if (phba->cfg_nvme_enable_fb) {
5366 bf_set(prli_fba, npr_nvme, 1);
5368 /* TBD. Target mode needs to post buffers
5369 * that support the configured first burst
5372 bf_set(prli_fb_sz, npr_nvme,
5373 phba->cfg_nvmet_fb_size);
5376 bf_set(prli_init, npr_nvme, 1);
5379 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5380 "6015 NVME issue PRLI ACC word1 x%08x "
5381 "word4 x%08x word5 x%08x flag x%x, "
5382 "fcp_info x%x nlp_type x%x\n",
5383 npr_nvme->word1, npr_nvme->word4,
5384 npr_nvme->word5, ndlp->nlp_flag,
5385 ndlp->nlp_fcp_info, ndlp->nlp_type);
5386 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5387 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5388 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5390 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5391 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5392 prli_fc4_req, ndlp->nlp_fc4_type,
5395 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5396 "Issue ACC PRLI: did:x%x flg:x%x",
5397 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5399 phba->fc_stat.elsXmitACC++;
5400 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5401 elsiocb->context1 = lpfc_nlp_get(ndlp);
5402 if (!elsiocb->context1) {
5403 lpfc_els_free_iocb(phba, elsiocb);
5407 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5408 if (rc == IOCB_ERROR) {
5409 lpfc_els_free_iocb(phba, elsiocb);
5418 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5419 * @vport: pointer to a virtual N_Port data structure.
5420 * @format: rnid command format.
5421 * @oldiocb: pointer to the original lpfc command iocb data structure.
5422 * @ndlp: pointer to a node-list data structure.
5424 * This routine issues a Request Node Identification Data (RNID) Accept
5425 * (ACC) response. It constructs the RNID ACC response command according to
5426 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5427 * issue the response.
5429 * Note that the ndlp reference count will be incremented by 1 for holding the
5430 * ndlp and the reference to ndlp will be stored into the context1 field of
5431 * the IOCB for the completion callback function.
5434 * 0 - Successfully issued acc rnid response
5435 * 1 - Failed to issue acc rnid response
5438 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5439 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5441 struct lpfc_hba *phba = vport->phba;
5443 IOCB_t *icmd, *oldcmd;
5444 struct lpfc_iocbq *elsiocb;
5449 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5450 + (2 * sizeof(struct lpfc_name));
5452 cmdsize += sizeof(RNID_TOP_DISC);
5454 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5455 ndlp->nlp_DID, ELS_CMD_ACC);
5459 icmd = &elsiocb->iocb;
5460 oldcmd = &oldiocb->iocb;
5461 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5462 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5464 /* Xmit RNID ACC response tag <ulpIoTag> */
5465 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5466 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5467 elsiocb->iotag, elsiocb->iocb.ulpContext);
5468 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5469 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5470 pcmd += sizeof(uint32_t);
5472 memset(pcmd, 0, sizeof(RNID));
5473 rn = (RNID *) (pcmd);
5474 rn->Format = format;
5475 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5476 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5477 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5480 rn->SpecificLen = 0;
5482 case RNID_TOPOLOGY_DISC:
5483 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5484 memcpy(&rn->un.topologyDisc.portName,
5485 &vport->fc_portname, sizeof(struct lpfc_name));
5486 rn->un.topologyDisc.unitType = RNID_HBA;
5487 rn->un.topologyDisc.physPort = 0;
5488 rn->un.topologyDisc.attachedNodes = 0;
5492 rn->SpecificLen = 0;
5496 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5497 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
5498 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5500 phba->fc_stat.elsXmitACC++;
5501 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5502 elsiocb->context1 = lpfc_nlp_get(ndlp);
5503 if (!elsiocb->context1) {
5504 lpfc_els_free_iocb(phba, elsiocb);
5508 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5509 if (rc == IOCB_ERROR) {
5510 lpfc_els_free_iocb(phba, elsiocb);
5519 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5520 * @vport: pointer to a virtual N_Port data structure.
5521 * @iocb: pointer to the lpfc command iocb data structure.
5522 * @ndlp: pointer to a node-list data structure.
5527 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5528 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5530 struct lpfc_hba *phba = vport->phba;
5535 struct lpfc_node_rrq *prrq;
5538 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5539 pcmd += sizeof(uint32_t);
5540 rrq = (struct RRQ *)pcmd;
5541 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5542 rxid = bf_get(rrq_rxid, rrq);
5544 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5545 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5547 be32_to_cpu(bf_get(rrq_did, rrq)),
5548 bf_get(rrq_oxid, rrq),
5550 iocb->iotag, iocb->iocb.ulpContext);
5552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5553 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5554 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5555 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5556 xri = bf_get(rrq_oxid, rrq);
5559 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5561 lpfc_clr_rrq_active(phba, xri, prrq);
5566 * lpfc_els_rsp_echo_acc - Issue echo acc response
5567 * @vport: pointer to a virtual N_Port data structure.
5568 * @data: pointer to echo data to return in the accept.
5569 * @oldiocb: pointer to the original lpfc command iocb data structure.
5570 * @ndlp: pointer to a node-list data structure.
5573 * 0 - Successfully issued acc echo response
5574 * 1 - Failed to issue acc echo response
5577 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5578 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5580 struct lpfc_hba *phba = vport->phba;
5581 struct lpfc_iocbq *elsiocb;
5586 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5588 /* The accumulated length can exceed the BPL_SIZE. For
5589 * now, use this as the limit
5591 if (cmdsize > LPFC_BPL_SIZE)
5592 cmdsize = LPFC_BPL_SIZE;
5593 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5594 ndlp->nlp_DID, ELS_CMD_ACC);
5598 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5599 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5601 /* Xmit ECHO ACC response tag <ulpIoTag> */
5602 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5603 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5604 elsiocb->iotag, elsiocb->iocb.ulpContext);
5605 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5606 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5607 pcmd += sizeof(uint32_t);
5608 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5610 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5611 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
5612 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5614 phba->fc_stat.elsXmitACC++;
5615 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5616 elsiocb->context1 = lpfc_nlp_get(ndlp);
5617 if (!elsiocb->context1) {
5618 lpfc_els_free_iocb(phba, elsiocb);
5622 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5623 if (rc == IOCB_ERROR) {
5624 lpfc_els_free_iocb(phba, elsiocb);
5633 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5634 * @vport: pointer to a host virtual N_Port data structure.
5636 * This routine issues Address Discover (ADISC) ELS commands to those
5637 * N_Ports which are in node port recovery state and ADISC has not been issued
5638 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5639 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5640 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5641 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5642 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5643 * IOCBs quit for later pick up. On the other hand, after walking through
5644 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5645 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5646 * no more ADISC need to be sent.
5649 * The number of N_Ports with adisc issued.
5652 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5654 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5655 struct lpfc_nodelist *ndlp, *next_ndlp;
5658 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5659 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5660 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5661 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5662 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5663 spin_lock_irq(&ndlp->lock);
5664 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5665 spin_unlock_irq(&ndlp->lock);
5666 ndlp->nlp_prev_state = ndlp->nlp_state;
5667 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5668 lpfc_issue_els_adisc(vport, ndlp, 0);
5670 vport->num_disc_nodes++;
5671 if (vport->num_disc_nodes >=
5672 vport->cfg_discovery_threads) {
5673 spin_lock_irq(shost->host_lock);
5674 vport->fc_flag |= FC_NLP_MORE;
5675 spin_unlock_irq(shost->host_lock);
5680 if (sentadisc == 0) {
5681 spin_lock_irq(shost->host_lock);
5682 vport->fc_flag &= ~FC_NLP_MORE;
5683 spin_unlock_irq(shost->host_lock);
5689 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5690 * @vport: pointer to a host virtual N_Port data structure.
5692 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5693 * which are in node port recovery state, with a @vport. Each time an ELS
5694 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5695 * the per @vport number of discover count (num_disc_nodes) shall be
5696 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5697 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5698 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5699 * later pick up. On the other hand, after walking through all the ndlps with
5700 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5701 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5702 * PLOGI need to be sent.
5705 * The number of N_Ports with plogi issued.
5708 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5710 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5711 struct lpfc_nodelist *ndlp, *next_ndlp;
5714 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5715 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5716 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5717 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5718 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5719 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5720 ndlp->nlp_prev_state = ndlp->nlp_state;
5721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5722 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5724 vport->num_disc_nodes++;
5725 if (vport->num_disc_nodes >=
5726 vport->cfg_discovery_threads) {
5727 spin_lock_irq(shost->host_lock);
5728 vport->fc_flag |= FC_NLP_MORE;
5729 spin_unlock_irq(shost->host_lock);
5735 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5736 "6452 Discover PLOGI %d flag x%x\n",
5737 sentplogi, vport->fc_flag);
5740 lpfc_set_disctmo(vport);
5743 spin_lock_irq(shost->host_lock);
5744 vport->fc_flag &= ~FC_NLP_MORE;
5745 spin_unlock_irq(shost->host_lock);
5751 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5755 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5756 desc->payload.els_req = word0;
5757 desc->length = cpu_to_be32(sizeof(desc->payload));
5759 return sizeof(struct fc_rdp_link_service_desc);
5763 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5764 uint8_t *page_a0, uint8_t *page_a2)
5766 uint16_t wavelength;
5767 uint16_t temperature;
5773 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5774 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5776 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5778 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5779 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5780 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5781 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5783 if ((trasn_code_byte4->fc_sw_laser) ||
5784 (trasn_code_byte5->fc_sw_laser_sl) ||
5785 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5786 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5787 } else if (trasn_code_byte4->fc_lw_laser) {
5788 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5789 page_a0[SSF_WAVELENGTH_B0];
5790 if (wavelength == SFP_WAVELENGTH_LC1310)
5791 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5792 if (wavelength == SFP_WAVELENGTH_LL1550)
5793 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5795 /* check if its SFP+ */
5796 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5797 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5798 << SFP_FLAG_CT_SHIFT;
5800 /* check if its OPTICAL */
5801 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5802 SFP_FLAG_IS_OPTICAL_PORT : 0)
5803 << SFP_FLAG_IS_OPTICAL_SHIFT;
5805 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5806 page_a2[SFF_TEMPERATURE_B0]);
5807 vcc = (page_a2[SFF_VCC_B1] << 8 |
5808 page_a2[SFF_VCC_B0]);
5809 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5810 page_a2[SFF_TXPOWER_B0]);
5811 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5812 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5813 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5814 page_a2[SFF_RXPOWER_B0]);
5815 desc->sfp_info.temperature = cpu_to_be16(temperature);
5816 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5817 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5818 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5819 desc->sfp_info.vcc = cpu_to_be16(vcc);
5821 desc->sfp_info.flags = cpu_to_be16(flag);
5822 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5824 return sizeof(struct fc_rdp_sfp_desc);
5828 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5833 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5835 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5837 desc->info.port_type = cpu_to_be32(type);
5839 desc->info.link_status.link_failure_cnt =
5840 cpu_to_be32(stat->linkFailureCnt);
5841 desc->info.link_status.loss_of_synch_cnt =
5842 cpu_to_be32(stat->lossSyncCnt);
5843 desc->info.link_status.loss_of_signal_cnt =
5844 cpu_to_be32(stat->lossSignalCnt);
5845 desc->info.link_status.primitive_seq_proto_err =
5846 cpu_to_be32(stat->primSeqErrCnt);
5847 desc->info.link_status.invalid_trans_word =
5848 cpu_to_be32(stat->invalidXmitWord);
5849 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5851 desc->length = cpu_to_be32(sizeof(desc->info));
5853 return sizeof(struct fc_rdp_link_error_status_desc);
5857 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5858 struct lpfc_vport *vport)
5862 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5864 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5865 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5866 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5867 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5868 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5869 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5870 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5872 desc->bbc_info.attached_port_bbc = 0;
5875 desc->bbc_info.rtt = 0;
5876 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5878 return sizeof(struct fc_rdp_bbc_desc);
5882 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5883 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5887 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5889 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5890 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5891 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5892 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5894 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5895 flags |= RDP_OET_HIGH_ALARM;
5896 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5897 flags |= RDP_OET_LOW_ALARM;
5898 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5899 flags |= RDP_OET_HIGH_WARNING;
5900 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5901 flags |= RDP_OET_LOW_WARNING;
5903 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5904 desc->oed_info.function_flags = cpu_to_be32(flags);
5905 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5906 return sizeof(struct fc_rdp_oed_sfp_desc);
5910 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5911 struct fc_rdp_oed_sfp_desc *desc,
5916 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5918 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5919 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5920 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5921 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5923 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5924 flags |= RDP_OET_HIGH_ALARM;
5925 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5926 flags |= RDP_OET_LOW_ALARM;
5927 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5928 flags |= RDP_OET_HIGH_WARNING;
5929 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5930 flags |= RDP_OET_LOW_WARNING;
5932 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5933 desc->oed_info.function_flags = cpu_to_be32(flags);
5934 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5935 return sizeof(struct fc_rdp_oed_sfp_desc);
5939 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5940 struct fc_rdp_oed_sfp_desc *desc,
5945 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5947 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5948 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5949 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5950 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5952 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5953 flags |= RDP_OET_HIGH_ALARM;
5954 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5955 flags |= RDP_OET_LOW_ALARM;
5956 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5957 flags |= RDP_OET_HIGH_WARNING;
5958 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5959 flags |= RDP_OET_LOW_WARNING;
5961 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5962 desc->oed_info.function_flags = cpu_to_be32(flags);
5963 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5964 return sizeof(struct fc_rdp_oed_sfp_desc);
5968 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5969 struct fc_rdp_oed_sfp_desc *desc,
5974 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5976 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5977 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5978 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5979 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5981 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5982 flags |= RDP_OET_HIGH_ALARM;
5983 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5984 flags |= RDP_OET_LOW_ALARM;
5985 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5986 flags |= RDP_OET_HIGH_WARNING;
5987 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5988 flags |= RDP_OET_LOW_WARNING;
5990 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5991 desc->oed_info.function_flags = cpu_to_be32(flags);
5992 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5993 return sizeof(struct fc_rdp_oed_sfp_desc);
5998 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5999 struct fc_rdp_oed_sfp_desc *desc,
6004 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6006 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
6007 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
6008 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
6009 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
6011 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6012 flags |= RDP_OET_HIGH_ALARM;
6013 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
6014 flags |= RDP_OET_LOW_ALARM;
6015 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6016 flags |= RDP_OET_HIGH_WARNING;
6017 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
6018 flags |= RDP_OET_LOW_WARNING;
6020 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
6021 desc->oed_info.function_flags = cpu_to_be32(flags);
6022 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6023 return sizeof(struct fc_rdp_oed_sfp_desc);
6027 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
6028 uint8_t *page_a0, struct lpfc_vport *vport)
6030 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
6031 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
6032 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
6033 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
6034 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
6035 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
6036 desc->length = cpu_to_be32(sizeof(desc->opd_info));
6037 return sizeof(struct fc_rdp_opd_sfp_desc);
6041 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
6043 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
6045 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
6047 desc->info.CorrectedBlocks =
6048 cpu_to_be32(stat->fecCorrBlkCount);
6049 desc->info.UncorrectableBlocks =
6050 cpu_to_be32(stat->fecUncorrBlkCount);
6052 desc->length = cpu_to_be32(sizeof(desc->info));
6054 return sizeof(struct fc_fec_rdp_desc);
6058 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
6060 uint16_t rdp_cap = 0;
6063 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
6065 switch (phba->fc_linkspeed) {
6066 case LPFC_LINK_SPEED_1GHZ:
6067 rdp_speed = RDP_PS_1GB;
6069 case LPFC_LINK_SPEED_2GHZ:
6070 rdp_speed = RDP_PS_2GB;
6072 case LPFC_LINK_SPEED_4GHZ:
6073 rdp_speed = RDP_PS_4GB;
6075 case LPFC_LINK_SPEED_8GHZ:
6076 rdp_speed = RDP_PS_8GB;
6078 case LPFC_LINK_SPEED_10GHZ:
6079 rdp_speed = RDP_PS_10GB;
6081 case LPFC_LINK_SPEED_16GHZ:
6082 rdp_speed = RDP_PS_16GB;
6084 case LPFC_LINK_SPEED_32GHZ:
6085 rdp_speed = RDP_PS_32GB;
6087 case LPFC_LINK_SPEED_64GHZ:
6088 rdp_speed = RDP_PS_64GB;
6091 rdp_speed = RDP_PS_UNKNOWN;
6095 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
6097 if (phba->lmt & LMT_128Gb)
6098 rdp_cap |= RDP_PS_128GB;
6099 if (phba->lmt & LMT_64Gb)
6100 rdp_cap |= RDP_PS_64GB;
6101 if (phba->lmt & LMT_32Gb)
6102 rdp_cap |= RDP_PS_32GB;
6103 if (phba->lmt & LMT_16Gb)
6104 rdp_cap |= RDP_PS_16GB;
6105 if (phba->lmt & LMT_10Gb)
6106 rdp_cap |= RDP_PS_10GB;
6107 if (phba->lmt & LMT_8Gb)
6108 rdp_cap |= RDP_PS_8GB;
6109 if (phba->lmt & LMT_4Gb)
6110 rdp_cap |= RDP_PS_4GB;
6111 if (phba->lmt & LMT_2Gb)
6112 rdp_cap |= RDP_PS_2GB;
6113 if (phba->lmt & LMT_1Gb)
6114 rdp_cap |= RDP_PS_1GB;
6117 rdp_cap = RDP_CAP_UNKNOWN;
6118 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
6119 rdp_cap |= RDP_CAP_USER_CONFIGURED;
6121 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
6122 desc->length = cpu_to_be32(sizeof(desc->info));
6123 return sizeof(struct fc_rdp_port_speed_desc);
6127 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
6128 struct lpfc_vport *vport)
6131 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6133 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
6134 sizeof(desc->port_names.wwnn));
6136 memcpy(desc->port_names.wwpn, &vport->fc_portname,
6137 sizeof(desc->port_names.wwpn));
6139 desc->length = cpu_to_be32(sizeof(desc->port_names));
6140 return sizeof(struct fc_rdp_port_name_desc);
6144 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
6145 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6148 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6149 if (vport->fc_flag & FC_FABRIC) {
6150 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
6151 sizeof(desc->port_names.wwnn));
6153 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
6154 sizeof(desc->port_names.wwpn));
6155 } else { /* Point to Point */
6156 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
6157 sizeof(desc->port_names.wwnn));
6159 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
6160 sizeof(desc->port_names.wwpn));
6163 desc->length = cpu_to_be32(sizeof(desc->port_names));
6164 return sizeof(struct fc_rdp_port_name_desc);
6168 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
6171 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
6172 struct lpfc_vport *vport = ndlp->vport;
6173 struct lpfc_iocbq *elsiocb;
6174 struct ulp_bde64 *bpl;
6177 struct ls_rjt *stat;
6178 struct fc_rdp_res_frame *rdp_res;
6179 uint32_t cmdsize, len;
6183 if (status != SUCCESS)
6186 /* This will change once we know the true size of the RDP payload */
6187 cmdsize = sizeof(struct fc_rdp_res_frame);
6189 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
6190 lpfc_max_els_tries, rdp_context->ndlp,
6191 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
6193 goto free_rdp_context;
6195 icmd = &elsiocb->iocb;
6196 icmd->ulpContext = rdp_context->rx_id;
6197 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6199 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6200 "2171 Xmit RDP response tag x%x xri x%x, "
6201 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
6202 elsiocb->iotag, elsiocb->iocb.ulpContext,
6203 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6205 rdp_res = (struct fc_rdp_res_frame *)
6206 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6207 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6208 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
6209 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6211 /* Update Alarm and Warning */
6212 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
6213 phba->sfp_alarm |= *flag_ptr;
6214 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6215 phba->sfp_warning |= *flag_ptr;
6217 /* For RDP payload */
6219 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6220 (len + pcmd), ELS_CMD_RDP);
6222 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
6223 rdp_context->page_a0, rdp_context->page_a2);
6224 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6226 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6227 (len + pcmd), &rdp_context->link_stat);
6228 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
6229 (len + pcmd), vport);
6230 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6231 (len + pcmd), vport, ndlp);
6232 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
6233 &rdp_context->link_stat);
6234 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6235 &rdp_context->link_stat, vport);
6236 len += lpfc_rdp_res_oed_temp_desc(phba,
6237 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6238 rdp_context->page_a2);
6239 len += lpfc_rdp_res_oed_voltage_desc(phba,
6240 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6241 rdp_context->page_a2);
6242 len += lpfc_rdp_res_oed_txbias_desc(phba,
6243 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6244 rdp_context->page_a2);
6245 len += lpfc_rdp_res_oed_txpower_desc(phba,
6246 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6247 rdp_context->page_a2);
6248 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6249 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6250 rdp_context->page_a2);
6251 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6252 rdp_context->page_a0, vport);
6254 rdp_res->length = cpu_to_be32(len - 8);
6255 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6257 /* Now that we know the true size of the payload, update the BPL */
6258 bpl = (struct ulp_bde64 *)
6259 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6260 bpl->tus.f.bdeSize = len;
6261 bpl->tus.f.bdeFlags = 0;
6262 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6264 phba->fc_stat.elsXmitACC++;
6265 elsiocb->context1 = lpfc_nlp_get(ndlp);
6266 if (!elsiocb->context1) {
6267 lpfc_els_free_iocb(phba, elsiocb);
6268 goto free_rdp_context;
6271 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6272 if (rc == IOCB_ERROR) {
6273 lpfc_els_free_iocb(phba, elsiocb);
6277 goto free_rdp_context;
6280 cmdsize = 2 * sizeof(uint32_t);
6281 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6282 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6284 goto free_rdp_context;
6286 icmd = &elsiocb->iocb;
6287 icmd->ulpContext = rdp_context->rx_id;
6288 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6289 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6291 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6292 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6293 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6295 phba->fc_stat.elsXmitLSRJT++;
6296 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6297 elsiocb->context1 = lpfc_nlp_get(ndlp);
6298 if (!elsiocb->context1) {
6299 lpfc_els_free_iocb(phba, elsiocb);
6300 goto free_rdp_context;
6303 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6304 if (rc == IOCB_ERROR) {
6305 lpfc_els_free_iocb(phba, elsiocb);
6310 /* This reference put is for the original unsolicited RDP. If the
6311 * iocb prep failed, there is no reference to remove.
6318 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6320 LPFC_MBOXQ_t *mbox = NULL;
6323 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6325 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6326 "7105 failed to allocate mailbox memory");
6330 if (lpfc_sli4_dump_page_a0(phba, mbox))
6331 goto prep_mbox_fail;
6332 mbox->vport = rdp_context->ndlp->vport;
6333 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6334 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6335 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6336 if (rc == MBX_NOT_FINISHED)
6337 goto issue_mbox_fail;
6343 mempool_free(mbox, phba->mbox_mem_pool);
6348 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6349 * @vport: pointer to a host virtual N_Port data structure.
6350 * @cmdiocb: pointer to lpfc command iocb data structure.
6351 * @ndlp: pointer to a node-list data structure.
6353 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6354 * IOCB. First, the payload of the unsolicited RDP is checked.
6355 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6356 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6357 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6358 * gather all data and send RDP response.
6361 * 0 - Sent the acc response
6362 * 1 - Sent the reject response.
6365 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6366 struct lpfc_nodelist *ndlp)
6368 struct lpfc_hba *phba = vport->phba;
6369 struct lpfc_dmabuf *pcmd;
6370 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6371 struct fc_rdp_req_frame *rdp_req;
6372 struct lpfc_rdp_context *rdp_context;
6376 if (phba->sli_rev < LPFC_SLI_REV4 ||
6377 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6378 LPFC_SLI_INTF_IF_TYPE_2) {
6379 rjt_err = LSRJT_UNABLE_TPC;
6380 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6384 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6385 rjt_err = LSRJT_UNABLE_TPC;
6386 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6390 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6391 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6393 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6394 "2422 ELS RDP Request "
6395 "dec len %d tag x%x port_id %d len %d\n",
6396 be32_to_cpu(rdp_req->rdp_des_length),
6397 be32_to_cpu(rdp_req->nport_id_desc.tag),
6398 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6399 be32_to_cpu(rdp_req->nport_id_desc.length));
6401 if (sizeof(struct fc_rdp_nport_desc) !=
6402 be32_to_cpu(rdp_req->rdp_des_length))
6404 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6406 if (RDP_NPORT_ID_SIZE !=
6407 be32_to_cpu(rdp_req->nport_id_desc.length))
6409 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6411 rjt_err = LSRJT_UNABLE_TPC;
6415 cmd = &cmdiocb->iocb;
6416 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6417 if (!rdp_context->ndlp) {
6419 rjt_err = LSRJT_UNABLE_TPC;
6422 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6423 rdp_context->rx_id = cmd->ulpContext;
6424 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6425 if (lpfc_get_rdp_info(phba, rdp_context)) {
6426 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6427 "2423 Unable to send mailbox");
6429 rjt_err = LSRJT_UNABLE_TPC;
6437 rjt_err = LSRJT_LOGICAL_ERR;
6440 memset(&stat, 0, sizeof(stat));
6441 stat.un.b.lsRjtRsnCode = rjt_err;
6442 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6443 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6449 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6454 struct lpfc_iocbq *elsiocb;
6455 struct lpfc_nodelist *ndlp;
6456 struct ls_rjt *stat;
6457 union lpfc_sli4_cfg_shdr *shdr;
6458 struct lpfc_lcb_context *lcb_context;
6459 struct fc_lcb_res_frame *lcb_res;
6460 uint32_t cmdsize, shdr_status, shdr_add_status;
6464 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6465 ndlp = lcb_context->ndlp;
6466 pmb->ctx_ndlp = NULL;
6467 pmb->ctx_buf = NULL;
6469 shdr = (union lpfc_sli4_cfg_shdr *)
6470 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6471 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6472 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6474 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6475 "0194 SET_BEACON_CONFIG mailbox "
6476 "completed with status x%x add_status x%x,"
6477 " mbx status x%x\n",
6478 shdr_status, shdr_add_status, mb->mbxStatus);
6480 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6481 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6482 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6483 mempool_free(pmb, phba->mbox_mem_pool);
6487 mempool_free(pmb, phba->mbox_mem_pool);
6488 cmdsize = sizeof(struct fc_lcb_res_frame);
6489 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6490 lpfc_max_els_tries, ndlp,
6491 ndlp->nlp_DID, ELS_CMD_ACC);
6493 /* Decrement the ndlp reference count from previous mbox command */
6497 goto free_lcb_context;
6499 lcb_res = (struct fc_lcb_res_frame *)
6500 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6502 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6503 icmd = &elsiocb->iocb;
6504 icmd->ulpContext = lcb_context->rx_id;
6505 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6507 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6508 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6509 lcb_res->lcb_sub_command = lcb_context->sub_command;
6510 lcb_res->lcb_type = lcb_context->type;
6511 lcb_res->capability = lcb_context->capability;
6512 lcb_res->lcb_frequency = lcb_context->frequency;
6513 lcb_res->lcb_duration = lcb_context->duration;
6514 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6515 phba->fc_stat.elsXmitACC++;
6517 elsiocb->context1 = lpfc_nlp_get(ndlp);
6518 if (!elsiocb->context1) {
6519 lpfc_els_free_iocb(phba, elsiocb);
6523 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6524 if (rc == IOCB_ERROR) {
6525 lpfc_els_free_iocb(phba, elsiocb);
6533 cmdsize = sizeof(struct fc_lcb_res_frame);
6534 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6535 lpfc_max_els_tries, ndlp,
6536 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6539 goto free_lcb_context;
6541 icmd = &elsiocb->iocb;
6542 icmd->ulpContext = lcb_context->rx_id;
6543 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6544 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6546 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6547 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6548 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6550 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6551 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6553 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6554 phba->fc_stat.elsXmitLSRJT++;
6555 elsiocb->context1 = lpfc_nlp_get(ndlp);
6556 if (!elsiocb->context1) {
6557 lpfc_els_free_iocb(phba, elsiocb);
6558 goto free_lcb_context;
6561 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6562 if (rc == IOCB_ERROR) {
6563 lpfc_els_free_iocb(phba, elsiocb);
6571 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6572 struct lpfc_lcb_context *lcb_context,
6573 uint32_t beacon_state)
6575 struct lpfc_hba *phba = vport->phba;
6576 union lpfc_sli4_cfg_shdr *cfg_shdr;
6577 LPFC_MBOXQ_t *mbox = NULL;
6581 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6585 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6586 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6587 sizeof(struct lpfc_sli4_cfg_mhdr);
6588 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6589 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6590 LPFC_SLI4_MBX_EMBED);
6591 mbox->ctx_ndlp = (void *)lcb_context;
6592 mbox->vport = phba->pport;
6593 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6594 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6595 phba->sli4_hba.physical_port);
6596 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6598 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6601 * Check bv1s bit before issuing the mailbox
6602 * if bv1s == 1, LCB V1 supported
6603 * else, LCB V0 supported
6606 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6607 /* COMMON_SET_BEACON_CONFIG_V1 */
6608 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6609 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6610 bf_set(lpfc_mbx_set_beacon_port_type,
6611 &mbox->u.mqe.un.beacon_config, 0);
6612 bf_set(lpfc_mbx_set_beacon_duration_v1,
6613 &mbox->u.mqe.un.beacon_config,
6614 be16_to_cpu(lcb_context->duration));
6616 /* COMMON_SET_BEACON_CONFIG_V0 */
6617 if (be16_to_cpu(lcb_context->duration) != 0) {
6618 mempool_free(mbox, phba->mbox_mem_pool);
6621 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6622 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6623 bf_set(lpfc_mbx_set_beacon_state,
6624 &mbox->u.mqe.un.beacon_config, beacon_state);
6625 bf_set(lpfc_mbx_set_beacon_port_type,
6626 &mbox->u.mqe.un.beacon_config, 1);
6627 bf_set(lpfc_mbx_set_beacon_duration,
6628 &mbox->u.mqe.un.beacon_config,
6629 be16_to_cpu(lcb_context->duration));
6632 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6633 if (rc == MBX_NOT_FINISHED) {
6634 mempool_free(mbox, phba->mbox_mem_pool);
6643 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6644 * @vport: pointer to a host virtual N_Port data structure.
6645 * @cmdiocb: pointer to lpfc command iocb data structure.
6646 * @ndlp: pointer to a node-list data structure.
6648 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6649 * First, the payload of the unsolicited LCB is checked.
6650 * Then based on Subcommand beacon will either turn on or off.
6653 * 0 - Sent the acc response
6654 * 1 - Sent the reject response.
6657 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6658 struct lpfc_nodelist *ndlp)
6660 struct lpfc_hba *phba = vport->phba;
6661 struct lpfc_dmabuf *pcmd;
6663 struct fc_lcb_request_frame *beacon;
6664 struct lpfc_lcb_context *lcb_context;
6665 u8 state, rjt_err = 0;
6668 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6669 lp = (uint8_t *)pcmd->virt;
6670 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6673 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6674 "type x%x frequency %x duration x%x\n",
6675 lp[0], lp[1], lp[2],
6676 beacon->lcb_command,
6677 beacon->lcb_sub_command,
6679 beacon->lcb_frequency,
6680 be16_to_cpu(beacon->lcb_duration));
6682 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6683 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6684 rjt_err = LSRJT_CMD_UNSUPPORTED;
6688 if (phba->sli_rev < LPFC_SLI_REV4 ||
6689 phba->hba_flag & HBA_FCOE_MODE ||
6690 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6691 LPFC_SLI_INTF_IF_TYPE_2)) {
6692 rjt_err = LSRJT_CMD_UNSUPPORTED;
6696 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6698 rjt_err = LSRJT_UNABLE_TPC;
6702 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6703 lcb_context->sub_command = beacon->lcb_sub_command;
6704 lcb_context->capability = 0;
6705 lcb_context->type = beacon->lcb_type;
6706 lcb_context->frequency = beacon->lcb_frequency;
6707 lcb_context->duration = beacon->lcb_duration;
6708 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6709 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6710 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6711 if (!lcb_context->ndlp) {
6712 rjt_err = LSRJT_UNABLE_TPC;
6716 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6717 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6718 "0193 failed to send mail box");
6720 rjt_err = LSRJT_UNABLE_TPC;
6728 memset(&stat, 0, sizeof(stat));
6729 stat.un.b.lsRjtRsnCode = rjt_err;
6730 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6736 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6737 * @vport: pointer to a host virtual N_Port data structure.
6739 * This routine cleans up any Registration State Change Notification
6740 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6741 * @vport together with the host_lock is used to prevent multiple thread
6742 * trying to access the RSCN array on a same @vport at the same time.
6745 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6747 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6748 struct lpfc_hba *phba = vport->phba;
6751 spin_lock_irq(shost->host_lock);
6752 if (vport->fc_rscn_flush) {
6753 /* Another thread is walking fc_rscn_id_list on this vport */
6754 spin_unlock_irq(shost->host_lock);
6757 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6758 vport->fc_rscn_flush = 1;
6759 spin_unlock_irq(shost->host_lock);
6761 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6762 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6763 vport->fc_rscn_id_list[i] = NULL;
6765 spin_lock_irq(shost->host_lock);
6766 vport->fc_rscn_id_cnt = 0;
6767 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6768 spin_unlock_irq(shost->host_lock);
6769 lpfc_can_disctmo(vport);
6770 /* Indicate we are done walking this fc_rscn_id_list */
6771 vport->fc_rscn_flush = 0;
6775 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6776 * @vport: pointer to a host virtual N_Port data structure.
6777 * @did: remote destination port identifier.
6779 * This routine checks whether there is any pending Registration State
6780 * Configuration Notification (RSCN) to a @did on @vport.
6783 * None zero - The @did matched with a pending rscn
6784 * 0 - not able to match @did with a pending rscn
6787 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6792 uint32_t payload_len, i;
6793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6795 ns_did.un.word = did;
6797 /* Never match fabric nodes for RSCNs */
6798 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6801 /* If we are doing a FULL RSCN rediscovery, match everything */
6802 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6805 spin_lock_irq(shost->host_lock);
6806 if (vport->fc_rscn_flush) {
6807 /* Another thread is walking fc_rscn_id_list on this vport */
6808 spin_unlock_irq(shost->host_lock);
6811 /* Indicate we are walking fc_rscn_id_list on this vport */
6812 vport->fc_rscn_flush = 1;
6813 spin_unlock_irq(shost->host_lock);
6814 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6815 lp = vport->fc_rscn_id_list[i]->virt;
6816 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6817 payload_len -= sizeof(uint32_t); /* take off word 0 */
6818 while (payload_len) {
6819 rscn_did.un.word = be32_to_cpu(*lp++);
6820 payload_len -= sizeof(uint32_t);
6821 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6822 case RSCN_ADDRESS_FORMAT_PORT:
6823 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6824 && (ns_did.un.b.area == rscn_did.un.b.area)
6825 && (ns_did.un.b.id == rscn_did.un.b.id))
6826 goto return_did_out;
6828 case RSCN_ADDRESS_FORMAT_AREA:
6829 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6830 && (ns_did.un.b.area == rscn_did.un.b.area))
6831 goto return_did_out;
6833 case RSCN_ADDRESS_FORMAT_DOMAIN:
6834 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6835 goto return_did_out;
6837 case RSCN_ADDRESS_FORMAT_FABRIC:
6838 goto return_did_out;
6842 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6843 vport->fc_rscn_flush = 0;
6846 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6847 vport->fc_rscn_flush = 0;
6852 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6853 * @vport: pointer to a host virtual N_Port data structure.
6855 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6856 * state machine for a @vport's nodes that are with pending RSCN (Registration
6857 * State Change Notification).
6860 * 0 - Successful (currently alway return 0)
6863 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6865 struct lpfc_nodelist *ndlp = NULL;
6867 /* Move all affected nodes by pending RSCNs to NPR state. */
6868 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6869 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6870 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6873 /* NVME Target mode does not do RSCN Recovery. */
6874 if (vport->phba->nvmet_support)
6877 /* If we are in the process of doing discovery on this
6878 * NPort, let it continue on its own.
6880 switch (ndlp->nlp_state) {
6881 case NLP_STE_PLOGI_ISSUE:
6882 case NLP_STE_ADISC_ISSUE:
6883 case NLP_STE_REG_LOGIN_ISSUE:
6884 case NLP_STE_PRLI_ISSUE:
6885 case NLP_STE_LOGO_ISSUE:
6889 /* Check to see if we need to NVME rescan this target
6892 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6893 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6894 lpfc_nvme_rescan_port(vport, ndlp);
6896 lpfc_disc_state_machine(vport, ndlp, NULL,
6897 NLP_EVT_DEVICE_RECOVERY);
6898 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6904 * lpfc_send_rscn_event - Send an RSCN event to management application
6905 * @vport: pointer to a host virtual N_Port data structure.
6906 * @cmdiocb: pointer to lpfc command iocb data structure.
6908 * lpfc_send_rscn_event sends an RSCN netlink event to management
6912 lpfc_send_rscn_event(struct lpfc_vport *vport,
6913 struct lpfc_iocbq *cmdiocb)
6915 struct lpfc_dmabuf *pcmd;
6916 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6917 uint32_t *payload_ptr;
6918 uint32_t payload_len;
6919 struct lpfc_rscn_event_header *rscn_event_data;
6921 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6922 payload_ptr = (uint32_t *) pcmd->virt;
6923 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6925 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6926 payload_len, GFP_KERNEL);
6927 if (!rscn_event_data) {
6928 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6929 "0147 Failed to allocate memory for RSCN event\n");
6932 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6933 rscn_event_data->payload_length = payload_len;
6934 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6937 fc_host_post_vendor_event(shost,
6938 fc_get_event_number(),
6939 sizeof(struct lpfc_rscn_event_header) + payload_len,
6940 (char *)rscn_event_data,
6943 kfree(rscn_event_data);
6947 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6948 * @vport: pointer to a host virtual N_Port data structure.
6949 * @cmdiocb: pointer to lpfc command iocb data structure.
6950 * @ndlp: pointer to a node-list data structure.
6952 * This routine processes an unsolicited RSCN (Registration State Change
6953 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6954 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6955 * discover state machine is about to begin discovery, it just accepts the
6956 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6957 * contains N_Port IDs for other vports on this HBA, it just accepts the
6958 * RSCN and ignore processing it. If the state machine is in the recovery
6959 * state, the fc_rscn_id_list of this @vport is walked and the
6960 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6961 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6962 * routine is invoked to handle the RSCN event.
6965 * 0 - Just sent the acc response
6966 * 1 - Sent the acc response and waited for name server completion
6969 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6970 struct lpfc_nodelist *ndlp)
6972 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6973 struct lpfc_hba *phba = vport->phba;
6974 struct lpfc_dmabuf *pcmd;
6975 uint32_t *lp, *datap;
6976 uint32_t payload_len, length, nportid, *cmd;
6978 int rscn_id = 0, hba_id = 0;
6981 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6982 lp = (uint32_t *) pcmd->virt;
6984 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6985 payload_len -= sizeof(uint32_t); /* take off word 0 */
6987 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6988 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6989 vport->fc_flag, payload_len, *lp,
6990 vport->fc_rscn_id_cnt);
6992 /* Send an RSCN event to the management application */
6993 lpfc_send_rscn_event(vport, cmdiocb);
6995 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6996 fc_host_post_event(shost, fc_get_event_number(),
6997 FCH_EVT_RSCN, lp[i]);
6999 /* Check if RSCN is coming from a direct-connected remote NPort */
7000 if (vport->fc_flag & FC_PT2PT) {
7001 /* If so, just ACC it, no other action needed for now */
7002 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7003 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
7004 *lp, vport->fc_flag, payload_len);
7005 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7007 /* Check to see if we need to NVME rescan this target
7010 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
7011 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
7012 lpfc_nvme_rescan_port(vport, ndlp);
7016 /* If we are about to begin discovery, just ACC the RSCN.
7017 * Discovery processing will satisfy it.
7019 if (vport->port_state <= LPFC_NS_QRY) {
7020 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7021 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
7022 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7024 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7028 /* If this RSCN just contains NPortIDs for other vports on this HBA,
7029 * just ACC and ignore it.
7031 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7032 !(vport->cfg_peer_port_login)) {
7037 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
7038 i -= sizeof(uint32_t);
7040 if (lpfc_find_vport_by_did(phba, nportid))
7043 if (rscn_id == hba_id) {
7044 /* ALL NPortIDs in RSCN are on HBA */
7045 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7047 "Data: x%x x%x x%x x%x\n",
7048 vport->fc_flag, payload_len,
7049 *lp, vport->fc_rscn_id_cnt);
7050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7051 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
7052 ndlp->nlp_DID, vport->port_state,
7055 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
7061 spin_lock_irq(shost->host_lock);
7062 if (vport->fc_rscn_flush) {
7063 /* Another thread is walking fc_rscn_id_list on this vport */
7064 vport->fc_flag |= FC_RSCN_DISCOVERY;
7065 spin_unlock_irq(shost->host_lock);
7067 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7070 /* Indicate we are walking fc_rscn_id_list on this vport */
7071 vport->fc_rscn_flush = 1;
7072 spin_unlock_irq(shost->host_lock);
7073 /* Get the array count after successfully have the token */
7074 rscn_cnt = vport->fc_rscn_id_cnt;
7075 /* If we are already processing an RSCN, save the received
7076 * RSCN payload buffer, cmdiocb->context2 to process later.
7078 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
7079 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7080 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
7081 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7083 spin_lock_irq(shost->host_lock);
7084 vport->fc_flag |= FC_RSCN_DEFERRED;
7086 /* Restart disctmo if its already running */
7087 if (vport->fc_flag & FC_DISC_TMO) {
7088 tmo = ((phba->fc_ratov * 3) + 3);
7089 mod_timer(&vport->fc_disctmo,
7090 jiffies + msecs_to_jiffies(1000 * tmo));
7092 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
7093 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
7094 vport->fc_flag |= FC_RSCN_MODE;
7095 spin_unlock_irq(shost->host_lock);
7097 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
7098 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
7101 (payload_len + length <= LPFC_BPL_SIZE)) {
7102 *cmd &= ELS_CMD_MASK;
7103 *cmd |= cpu_to_be32(payload_len + length);
7104 memcpy(((uint8_t *)cmd) + length, lp,
7107 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
7108 vport->fc_rscn_id_cnt++;
7109 /* If we zero, cmdiocb->context2, the calling
7110 * routine will not try to free it.
7112 cmdiocb->context2 = NULL;
7115 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7116 "0235 Deferred RSCN "
7117 "Data: x%x x%x x%x\n",
7118 vport->fc_rscn_id_cnt, vport->fc_flag,
7121 vport->fc_flag |= FC_RSCN_DISCOVERY;
7122 spin_unlock_irq(shost->host_lock);
7123 /* ReDiscovery RSCN */
7124 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7125 "0234 ReDiscovery RSCN "
7126 "Data: x%x x%x x%x\n",
7127 vport->fc_rscn_id_cnt, vport->fc_flag,
7130 /* Indicate we are done walking fc_rscn_id_list on this vport */
7131 vport->fc_rscn_flush = 0;
7133 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7134 /* send RECOVERY event for ALL nodes that match RSCN payload */
7135 lpfc_rscn_recovery_check(vport);
7138 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7139 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
7140 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
7142 spin_lock_irq(shost->host_lock);
7143 vport->fc_flag |= FC_RSCN_MODE;
7144 spin_unlock_irq(shost->host_lock);
7145 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
7146 /* Indicate we are done walking fc_rscn_id_list on this vport */
7147 vport->fc_rscn_flush = 0;
7149 * If we zero, cmdiocb->context2, the calling routine will
7150 * not try to free it.
7152 cmdiocb->context2 = NULL;
7153 lpfc_set_disctmo(vport);
7155 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7156 /* send RECOVERY event for ALL nodes that match RSCN payload */
7157 lpfc_rscn_recovery_check(vport);
7158 return lpfc_els_handle_rscn(vport);
7162 * lpfc_els_handle_rscn - Handle rscn for a vport
7163 * @vport: pointer to a host virtual N_Port data structure.
7165 * This routine handles the Registration State Configuration Notification
7166 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
7167 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
7168 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
7169 * NameServer shall be issued. If CT command to the NameServer fails to be
7170 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
7171 * RSCN activities with the @vport.
7174 * 0 - Cleaned up rscn on the @vport
7175 * 1 - Wait for plogi to name server before proceed
7178 lpfc_els_handle_rscn(struct lpfc_vport *vport)
7180 struct lpfc_nodelist *ndlp;
7181 struct lpfc_hba *phba = vport->phba;
7183 /* Ignore RSCN if the port is being torn down. */
7184 if (vport->load_flag & FC_UNLOADING) {
7185 lpfc_els_flush_rscn(vport);
7189 /* Start timer for RSCN processing */
7190 lpfc_set_disctmo(vport);
7192 /* RSCN processed */
7193 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7194 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
7195 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
7196 vport->port_state, vport->num_disc_nodes,
7199 /* To process RSCN, first compare RSCN data with NameServer */
7200 vport->fc_ns_retry = 0;
7201 vport->num_disc_nodes = 0;
7203 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7204 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
7205 /* Good ndlp, issue CT Request to NameServer. Need to
7206 * know how many gidfts were issued. If none, then just
7207 * flush the RSCN. Otherwise, the outstanding requests
7210 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
7211 if (lpfc_issue_gidft(vport) > 0)
7213 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
7214 if (lpfc_issue_gidpt(vport) > 0)
7220 /* Nameserver login in question. Revalidate. */
7222 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
7223 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7225 ndlp = lpfc_nlp_init(vport, NameServer_DID);
7227 lpfc_els_flush_rscn(vport);
7230 ndlp->nlp_prev_state = ndlp->nlp_state;
7231 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7233 ndlp->nlp_type |= NLP_FABRIC;
7234 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
7235 /* Wait for NameServer login cmpl before we can
7241 lpfc_els_flush_rscn(vport);
7246 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
7247 * @vport: pointer to a host virtual N_Port data structure.
7248 * @cmdiocb: pointer to lpfc command iocb data structure.
7249 * @ndlp: pointer to a node-list data structure.
7251 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
7252 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
7253 * point topology. As an unsolicited FLOGI should not be received in a loop
7254 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7255 * lpfc_check_sparm() routine is invoked to check the parameters in the
7256 * unsolicited FLOGI. If parameters validation failed, the routine
7257 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7258 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7259 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7260 * will initiate PLOGI. The higher lexicographical value party shall has
7261 * higher priority (as the winning port) and will initiate PLOGI and
7262 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7263 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7264 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7267 * 0 - Successfully processed the unsolicited flogi
7268 * 1 - Failed to process the unsolicited flogi
7271 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7272 struct lpfc_nodelist *ndlp)
7274 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7275 struct lpfc_hba *phba = vport->phba;
7276 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7277 uint32_t *lp = (uint32_t *) pcmd->virt;
7278 IOCB_t *icmd = &cmdiocb->iocb;
7279 struct serv_parm *sp;
7283 uint32_t fc_flag = 0;
7284 uint32_t port_state = 0;
7287 sp = (struct serv_parm *) lp;
7289 /* FLOGI received */
7291 lpfc_set_disctmo(vport);
7293 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7294 /* We should never receive a FLOGI in loop mode, ignore it */
7295 did = icmd->un.elsreq64.remoteID;
7297 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7299 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7300 "0113 An FLOGI ELS command x%x was "
7301 "received from DID x%x in Loop Mode\n",
7306 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7309 * If our portname is greater than the remote portname,
7310 * then we initiate Nport login.
7313 rc = memcmp(&vport->fc_portname, &sp->portName,
7314 sizeof(struct lpfc_name));
7317 if (phba->sli_rev < LPFC_SLI_REV4) {
7318 mbox = mempool_alloc(phba->mbox_mem_pool,
7322 lpfc_linkdown(phba);
7323 lpfc_init_link(phba, mbox,
7325 phba->cfg_link_speed);
7326 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7327 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7328 mbox->vport = vport;
7329 rc = lpfc_sli_issue_mbox(phba, mbox,
7331 lpfc_set_loopback_flag(phba);
7332 if (rc == MBX_NOT_FINISHED)
7333 mempool_free(mbox, phba->mbox_mem_pool);
7337 /* abort the flogi coming back to ourselves
7338 * due to external loopback on the port.
7340 lpfc_els_abort_flogi(phba);
7343 } else if (rc > 0) { /* greater than */
7344 spin_lock_irq(shost->host_lock);
7345 vport->fc_flag |= FC_PT2PT_PLOGI;
7346 spin_unlock_irq(shost->host_lock);
7348 /* If we have the high WWPN we can assign our own
7349 * myDID; otherwise, we have to WAIT for a PLOGI
7350 * from the remote NPort to find out what it
7353 vport->fc_myDID = PT2PT_LocalID;
7355 vport->fc_myDID = PT2PT_RemoteID;
7359 * The vport state should go to LPFC_FLOGI only
7360 * AFTER we issue a FLOGI, not receive one.
7362 spin_lock_irq(shost->host_lock);
7363 fc_flag = vport->fc_flag;
7364 port_state = vport->port_state;
7365 vport->fc_flag |= FC_PT2PT;
7366 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7368 /* Acking an unsol FLOGI. Count 1 for link bounce
7371 vport->rcv_flogi_cnt++;
7372 spin_unlock_irq(shost->host_lock);
7373 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7374 "3311 Rcv Flogi PS x%x new PS x%x "
7375 "fc_flag x%x new fc_flag x%x\n",
7376 port_state, vport->port_state,
7377 fc_flag, vport->fc_flag);
7380 * We temporarily set fc_myDID to make it look like we are
7381 * a Fabric. This is done just so we end up with the right
7382 * did / sid on the FLOGI ACC rsp.
7384 did = vport->fc_myDID;
7385 vport->fc_myDID = Fabric_DID;
7387 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7389 /* Defer ACC response until AFTER we issue a FLOGI */
7390 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7391 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7392 phba->defer_flogi_acc_ox_id =
7393 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7395 vport->fc_myDID = did;
7397 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7398 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7399 " ox_id: x%x, hba_flag x%x\n",
7400 phba->defer_flogi_acc_rx_id,
7401 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7403 phba->defer_flogi_acc_flag = true;
7409 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7411 /* Now lets put fc_myDID back to what its supposed to be */
7412 vport->fc_myDID = did;
7418 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7419 * @vport: pointer to a host virtual N_Port data structure.
7420 * @cmdiocb: pointer to lpfc command iocb data structure.
7421 * @ndlp: pointer to a node-list data structure.
7423 * This routine processes Request Node Identification Data (RNID) IOCB
7424 * received as an ELS unsolicited event. Only when the RNID specified format
7425 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7426 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7427 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7428 * rejected by invoking the lpfc_els_rsp_reject() routine.
7431 * 0 - Successfully processed rnid iocb (currently always return 0)
7434 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7435 struct lpfc_nodelist *ndlp)
7437 struct lpfc_dmabuf *pcmd;
7442 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7443 lp = (uint32_t *) pcmd->virt;
7450 switch (rn->Format) {
7452 case RNID_TOPOLOGY_DISC:
7454 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7457 /* Reject this request because format not supported */
7458 stat.un.b.lsRjtRsvd0 = 0;
7459 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7460 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7461 stat.un.b.vendorUnique = 0;
7462 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7469 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7470 * @vport: pointer to a host virtual N_Port data structure.
7471 * @cmdiocb: pointer to lpfc command iocb data structure.
7472 * @ndlp: pointer to a node-list data structure.
7475 * 0 - Successfully processed echo iocb (currently always return 0)
7478 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7479 struct lpfc_nodelist *ndlp)
7483 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7485 /* skip over first word of echo command to find echo data */
7486 pcmd += sizeof(uint32_t);
7488 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7493 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7494 * @vport: pointer to a host virtual N_Port data structure.
7495 * @cmdiocb: pointer to lpfc command iocb data structure.
7496 * @ndlp: pointer to a node-list data structure.
7498 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7499 * received as an ELS unsolicited event. Currently, this function just invokes
7500 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7503 * 0 - Successfully processed lirr iocb (currently always return 0)
7506 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7507 struct lpfc_nodelist *ndlp)
7511 /* For now, unconditionally reject this command */
7512 stat.un.b.lsRjtRsvd0 = 0;
7513 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7514 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7515 stat.un.b.vendorUnique = 0;
7516 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7521 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7522 * @vport: pointer to a host virtual N_Port data structure.
7523 * @cmdiocb: pointer to lpfc command iocb data structure.
7524 * @ndlp: pointer to a node-list data structure.
7526 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7527 * received as an ELS unsolicited event. A request to RRQ shall only
7528 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7529 * Nx_Port N_Port_ID of the target Exchange is the same as the
7530 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7531 * not accepted, an LS_RJT with reason code "Unable to perform
7532 * command request" and reason code explanation "Invalid Originator
7533 * S_ID" shall be returned. For now, we just unconditionally accept
7534 * RRQ from the target.
7537 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7538 struct lpfc_nodelist *ndlp)
7540 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7541 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7542 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7546 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7547 * @phba: pointer to lpfc hba data structure.
7548 * @pmb: pointer to the driver internal queue element for mailbox command.
7550 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7551 * mailbox command. This callback function is to actually send the Accept
7552 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
7553 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7554 * mailbox command, constructs the RLS response with the link statistics
7555 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7556 * response to the RLS.
7558 * Note that the ndlp reference count will be incremented by 1 for holding the
7559 * ndlp and the reference to ndlp will be stored into the context1 field of
7560 * the IOCB for the completion callback function to the RLS Accept Response
7565 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7570 struct RLS_RSP *rls_rsp;
7572 struct lpfc_iocbq *elsiocb;
7573 struct lpfc_nodelist *ndlp;
7580 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7581 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7582 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7583 pmb->ctx_buf = NULL;
7584 pmb->ctx_ndlp = NULL;
7586 if (mb->mbxStatus) {
7587 mempool_free(pmb, phba->mbox_mem_pool);
7591 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7592 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7593 lpfc_max_els_tries, ndlp,
7594 ndlp->nlp_DID, ELS_CMD_ACC);
7596 /* Decrement the ndlp reference count from previous mbox command */
7600 mempool_free(pmb, phba->mbox_mem_pool);
7604 icmd = &elsiocb->iocb;
7605 icmd->ulpContext = rxid;
7606 icmd->unsli3.rcvsli3.ox_id = oxid;
7608 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7609 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7610 pcmd += sizeof(uint32_t); /* Skip past command */
7611 rls_rsp = (struct RLS_RSP *)pcmd;
7613 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7614 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7615 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7616 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7617 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7618 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7619 mempool_free(pmb, phba->mbox_mem_pool);
7620 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7621 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7622 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7623 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7624 elsiocb->iotag, elsiocb->iocb.ulpContext,
7625 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7627 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7628 phba->fc_stat.elsXmitACC++;
7629 elsiocb->context1 = lpfc_nlp_get(ndlp);
7630 if (!elsiocb->context1) {
7631 lpfc_els_free_iocb(phba, elsiocb);
7635 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7636 if (rc == IOCB_ERROR) {
7637 lpfc_els_free_iocb(phba, elsiocb);
7644 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7645 * @vport: pointer to a host virtual N_Port data structure.
7646 * @cmdiocb: pointer to lpfc command iocb data structure.
7647 * @ndlp: pointer to a node-list data structure.
7649 * This routine processes Read Link Status (RLS) IOCB received as an
7650 * ELS unsolicited event. It first checks the remote port state. If the
7651 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7652 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7653 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7654 * for reading the HBA link statistics. It is for the callback function,
7655 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7656 * to actually sending out RPL Accept (ACC) response.
7659 * 0 - Successfully processed rls iocb (currently always return 0)
7662 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7663 struct lpfc_nodelist *ndlp)
7665 struct lpfc_hba *phba = vport->phba;
7669 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7670 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7671 /* reject the unsolicited RLS request and done with it */
7674 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7676 lpfc_read_lnk_stat(phba, mbox);
7677 mbox->ctx_buf = (void *)((unsigned long)
7678 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7679 cmdiocb->iocb.ulpContext)); /* rx_id */
7680 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7681 if (!mbox->ctx_ndlp)
7683 mbox->vport = vport;
7684 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7685 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7686 != MBX_NOT_FINISHED)
7687 /* Mbox completion will send ELS Response */
7689 /* Decrement reference count used for the failed mbox
7694 mempool_free(mbox, phba->mbox_mem_pool);
7697 /* issue rejection response */
7698 stat.un.b.lsRjtRsvd0 = 0;
7699 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7700 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7701 stat.un.b.vendorUnique = 0;
7702 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7707 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7708 * @vport: pointer to a host virtual N_Port data structure.
7709 * @cmdiocb: pointer to lpfc command iocb data structure.
7710 * @ndlp: pointer to a node-list data structure.
7712 * This routine processes Read Timout Value (RTV) IOCB received as an
7713 * ELS unsolicited event. It first checks the remote port state. If the
7714 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7715 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7716 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7717 * Value (RTV) unsolicited IOCB event.
7719 * Note that the ndlp reference count will be incremented by 1 for holding the
7720 * ndlp and the reference to ndlp will be stored into the context1 field of
7721 * the IOCB for the completion callback function to the RTV Accept Response
7725 * 0 - Successfully processed rtv iocb (currently always return 0)
7728 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7729 struct lpfc_nodelist *ndlp)
7732 struct lpfc_hba *phba = vport->phba;
7734 struct RTV_RSP *rtv_rsp;
7736 struct lpfc_iocbq *elsiocb;
7740 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7741 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7742 /* reject the unsolicited RTV request and done with it */
7745 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7746 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7747 lpfc_max_els_tries, ndlp,
7748 ndlp->nlp_DID, ELS_CMD_ACC);
7753 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7754 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7755 pcmd += sizeof(uint32_t); /* Skip past command */
7757 /* use the command's xri in the response */
7758 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7759 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7761 rtv_rsp = (struct RTV_RSP *)pcmd;
7763 /* populate RTV payload */
7764 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7765 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7766 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7767 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7768 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7770 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7771 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7772 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7773 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7774 "Data: x%x x%x x%x\n",
7775 elsiocb->iotag, elsiocb->iocb.ulpContext,
7776 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7778 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7779 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7780 phba->fc_stat.elsXmitACC++;
7781 elsiocb->context1 = lpfc_nlp_get(ndlp);
7782 if (!elsiocb->context1) {
7783 lpfc_els_free_iocb(phba, elsiocb);
7787 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7788 if (rc == IOCB_ERROR) {
7789 lpfc_els_free_iocb(phba, elsiocb);
7795 /* issue rejection response */
7796 stat.un.b.lsRjtRsvd0 = 0;
7797 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7798 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7799 stat.un.b.vendorUnique = 0;
7800 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7804 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7805 * @vport: pointer to a host virtual N_Port data structure.
7806 * @ndlp: pointer to a node-list data structure.
7807 * @did: DID of the target.
7808 * @rrq: Pointer to the rrq struct.
7810 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7811 * Successful the the completion handler will clear the RRQ.
7814 * 0 - Successfully sent rrq els iocb.
7815 * 1 - Failed to send rrq els iocb.
7818 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7819 uint32_t did, struct lpfc_node_rrq *rrq)
7821 struct lpfc_hba *phba = vport->phba;
7822 struct RRQ *els_rrq;
7823 struct lpfc_iocbq *elsiocb;
7831 /* If ndlp is not NULL, we will bump the reference count on it */
7832 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7833 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7838 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7840 /* For RRQ request, remainder of payload is Exchange IDs */
7841 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7842 pcmd += sizeof(uint32_t);
7843 els_rrq = (struct RRQ *) pcmd;
7845 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7846 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7847 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7848 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7849 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7852 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7853 "Issue RRQ: did:x%x",
7854 did, rrq->xritag, rrq->rxid);
7855 elsiocb->context_un.rrq = rrq;
7856 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7859 elsiocb->context1 = ndlp;
7861 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7862 if (ret == IOCB_ERROR)
7867 lpfc_els_free_iocb(phba, elsiocb);
7873 * lpfc_send_rrq - Sends ELS RRQ if needed.
7874 * @phba: pointer to lpfc hba data structure.
7875 * @rrq: pointer to the active rrq.
7877 * This routine will call the lpfc_issue_els_rrq if the rrq is
7878 * still active for the xri. If this function returns a failure then
7879 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7881 * Returns 0 Success.
7885 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7887 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7892 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7893 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7900 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7901 * @vport: pointer to a host virtual N_Port data structure.
7902 * @cmdsize: size of the ELS command.
7903 * @oldiocb: pointer to the original lpfc command iocb data structure.
7904 * @ndlp: pointer to a node-list data structure.
7906 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7907 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7909 * Note that the ndlp reference count will be incremented by 1 for holding the
7910 * ndlp and the reference to ndlp will be stored into the context1 field of
7911 * the IOCB for the completion callback function to the RPL Accept Response
7915 * 0 - Successfully issued ACC RPL ELS command
7916 * 1 - Failed to issue ACC RPL ELS command
7919 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7920 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7923 struct lpfc_hba *phba = vport->phba;
7924 IOCB_t *icmd, *oldcmd;
7926 struct lpfc_iocbq *elsiocb;
7929 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7930 ndlp->nlp_DID, ELS_CMD_ACC);
7935 icmd = &elsiocb->iocb;
7936 oldcmd = &oldiocb->iocb;
7937 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7938 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7940 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7941 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7942 pcmd += sizeof(uint16_t);
7943 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7944 pcmd += sizeof(uint16_t);
7946 /* Setup the RPL ACC payload */
7947 rpl_rsp.listLen = be32_to_cpu(1);
7949 rpl_rsp.port_num_blk.portNum = 0;
7950 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7951 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7952 sizeof(struct lpfc_name));
7953 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7954 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7955 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7956 "0120 Xmit ELS RPL ACC response tag x%x "
7957 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7959 elsiocb->iotag, elsiocb->iocb.ulpContext,
7960 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7962 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7963 phba->fc_stat.elsXmitACC++;
7964 elsiocb->context1 = lpfc_nlp_get(ndlp);
7965 if (!elsiocb->context1) {
7966 lpfc_els_free_iocb(phba, elsiocb);
7970 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7971 if (rc == IOCB_ERROR) {
7972 lpfc_els_free_iocb(phba, elsiocb);
7981 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7982 * @vport: pointer to a host virtual N_Port data structure.
7983 * @cmdiocb: pointer to lpfc command iocb data structure.
7984 * @ndlp: pointer to a node-list data structure.
7986 * This routine processes Read Port List (RPL) IOCB received as an ELS
7987 * unsolicited event. It first checks the remote port state. If the remote
7988 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7989 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7990 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7991 * to accept the RPL.
7994 * 0 - Successfully processed rpl iocb (currently always return 0)
7997 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7998 struct lpfc_nodelist *ndlp)
8000 struct lpfc_dmabuf *pcmd;
8007 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8008 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
8009 /* issue rejection response */
8010 stat.un.b.lsRjtRsvd0 = 0;
8011 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8012 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8013 stat.un.b.vendorUnique = 0;
8014 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8016 /* rejected the unsolicited RPL request and done with it */
8020 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8021 lp = (uint32_t *) pcmd->virt;
8022 rpl = (RPL *) (lp + 1);
8023 maxsize = be32_to_cpu(rpl->maxsize);
8025 /* We support only one port */
8026 if ((rpl->index == 0) &&
8028 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
8029 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
8031 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
8033 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
8039 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
8040 * @vport: pointer to a virtual N_Port data structure.
8041 * @cmdiocb: pointer to lpfc command iocb data structure.
8042 * @ndlp: pointer to a node-list data structure.
8044 * This routine processes Fibre Channel Address Resolution Protocol
8045 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
8046 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
8047 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
8048 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
8049 * remote PortName is compared against the FC PortName stored in the @vport
8050 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
8051 * compared against the FC NodeName stored in the @vport data structure.
8052 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
8053 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
8054 * invoked to send out FARP Response to the remote node. Before sending the
8055 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
8056 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
8057 * routine is invoked to log into the remote port first.
8060 * 0 - Either the FARP Match Mode not supported or successfully processed
8063 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8064 struct lpfc_nodelist *ndlp)
8066 struct lpfc_dmabuf *pcmd;
8072 icmd = &cmdiocb->iocb;
8073 did = icmd->un.elsreq64.remoteID;
8074 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8075 lp = (uint32_t *) pcmd->virt;
8079 /* FARP-REQ received from DID <did> */
8080 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8081 "0601 FARP-REQ received from DID x%x\n", did);
8082 /* We will only support match on WWPN or WWNN */
8083 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
8088 /* If this FARP command is searching for my portname */
8089 if (fp->Mflags & FARP_MATCH_PORT) {
8090 if (memcmp(&fp->RportName, &vport->fc_portname,
8091 sizeof(struct lpfc_name)) == 0)
8095 /* If this FARP command is searching for my nodename */
8096 if (fp->Mflags & FARP_MATCH_NODE) {
8097 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
8098 sizeof(struct lpfc_name)) == 0)
8103 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
8104 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
8105 /* Log back into the node before sending the FARP. */
8106 if (fp->Rflags & FARP_REQUEST_PLOGI) {
8107 ndlp->nlp_prev_state = ndlp->nlp_state;
8108 lpfc_nlp_set_state(vport, ndlp,
8109 NLP_STE_PLOGI_ISSUE);
8110 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8113 /* Send a FARP response to that node */
8114 if (fp->Rflags & FARP_REQUEST_FARPR)
8115 lpfc_issue_els_farpr(vport, did, 0);
8122 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
8123 * @vport: pointer to a host virtual N_Port data structure.
8124 * @cmdiocb: pointer to lpfc command iocb data structure.
8125 * @ndlp: pointer to a node-list data structure.
8127 * This routine processes Fibre Channel Address Resolution Protocol
8128 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
8129 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
8130 * the FARP response request.
8133 * 0 - Successfully processed FARPR IOCB (currently always return 0)
8136 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8137 struct lpfc_nodelist *ndlp)
8139 struct lpfc_dmabuf *pcmd;
8144 icmd = &cmdiocb->iocb;
8145 did = icmd->un.elsreq64.remoteID;
8146 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
8147 lp = (uint32_t *) pcmd->virt;
8150 /* FARP-RSP received from DID <did> */
8151 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8152 "0600 FARP-RSP received from DID x%x\n", did);
8153 /* ACCEPT the Farp resp request */
8154 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8160 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
8161 * @vport: pointer to a host virtual N_Port data structure.
8162 * @cmdiocb: pointer to lpfc command iocb data structure.
8163 * @fan_ndlp: pointer to a node-list data structure.
8165 * This routine processes a Fabric Address Notification (FAN) IOCB
8166 * command received as an ELS unsolicited event. The FAN ELS command will
8167 * only be processed on a physical port (i.e., the @vport represents the
8168 * physical port). The fabric NodeName and PortName from the FAN IOCB are
8169 * compared against those in the phba data structure. If any of those is
8170 * different, the lpfc_initial_flogi() routine is invoked to initialize
8171 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
8172 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
8173 * is invoked to register login to the fabric.
8176 * 0 - Successfully processed fan iocb (currently always return 0).
8179 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8180 struct lpfc_nodelist *fan_ndlp)
8182 struct lpfc_hba *phba = vport->phba;
8186 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
8187 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
8189 /* FAN received; Fan does not have a reply sequence */
8190 if ((vport == phba->pport) &&
8191 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
8192 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
8193 sizeof(struct lpfc_name))) ||
8194 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
8195 sizeof(struct lpfc_name)))) {
8196 /* This port has switched fabrics. FLOGI is required */
8197 lpfc_issue_init_vfi(vport);
8199 /* FAN verified - skip FLOGI */
8200 vport->fc_myDID = vport->fc_prevDID;
8201 if (phba->sli_rev < LPFC_SLI_REV4)
8202 lpfc_issue_fabric_reglogin(vport);
8204 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8205 "3138 Need register VFI: (x%x/%x)\n",
8206 vport->fc_prevDID, vport->fc_myDID);
8207 lpfc_issue_reg_vfi(vport);
8215 * lpfc_els_timeout - Handler funciton to the els timer
8216 * @t: timer context used to obtain the vport.
8218 * This routine is invoked by the ELS timer after timeout. It posts the ELS
8219 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
8220 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
8221 * up the worker thread. It is for the worker thread to invoke the routine
8222 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
8225 lpfc_els_timeout(struct timer_list *t)
8227 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
8228 struct lpfc_hba *phba = vport->phba;
8229 uint32_t tmo_posted;
8230 unsigned long iflag;
8232 spin_lock_irqsave(&vport->work_port_lock, iflag);
8233 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
8234 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8235 vport->work_port_events |= WORKER_ELS_TMO;
8236 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
8238 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8239 lpfc_worker_wake_up(phba);
8245 * lpfc_els_timeout_handler - Process an els timeout event
8246 * @vport: pointer to a virtual N_Port data structure.
8248 * This routine is the actual handler function that processes an ELS timeout
8249 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8250 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8251 * invoking the lpfc_sli_issue_abort_iotag() routine.
8254 lpfc_els_timeout_handler(struct lpfc_vport *vport)
8256 struct lpfc_hba *phba = vport->phba;
8257 struct lpfc_sli_ring *pring;
8258 struct lpfc_iocbq *tmp_iocb, *piocb;
8260 struct lpfc_dmabuf *pcmd;
8261 uint32_t els_command = 0;
8263 uint32_t remote_ID = 0xffffffff;
8264 LIST_HEAD(abort_list);
8267 timeout = (uint32_t)(phba->fc_ratov << 1);
8269 pring = lpfc_phba_elsring(phba);
8270 if (unlikely(!pring))
8273 if (phba->pport->load_flag & FC_UNLOADING)
8276 spin_lock_irq(&phba->hbalock);
8277 if (phba->sli_rev == LPFC_SLI_REV4)
8278 spin_lock(&pring->ring_lock);
8280 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8283 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8284 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8285 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
8288 if (piocb->vport != vport)
8291 pcmd = (struct lpfc_dmabuf *) piocb->context2;
8293 els_command = *(uint32_t *) (pcmd->virt);
8295 if (els_command == ELS_CMD_FARP ||
8296 els_command == ELS_CMD_FARPR ||
8297 els_command == ELS_CMD_FDISC)
8300 if (piocb->drvrTimeout > 0) {
8301 if (piocb->drvrTimeout >= timeout)
8302 piocb->drvrTimeout -= timeout;
8304 piocb->drvrTimeout = 0;
8308 remote_ID = 0xffffffff;
8309 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
8310 remote_ID = cmd->un.elsreq64.remoteID;
8312 struct lpfc_nodelist *ndlp;
8313 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
8315 remote_ID = ndlp->nlp_DID;
8317 list_add_tail(&piocb->dlist, &abort_list);
8319 if (phba->sli_rev == LPFC_SLI_REV4)
8320 spin_unlock(&pring->ring_lock);
8321 spin_unlock_irq(&phba->hbalock);
8323 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8325 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8326 "0127 ELS timeout Data: x%x x%x x%x "
8327 "x%x\n", els_command,
8328 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8329 spin_lock_irq(&phba->hbalock);
8330 list_del_init(&piocb->dlist);
8331 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
8332 spin_unlock_irq(&phba->hbalock);
8335 /* Make sure HBA is alive */
8336 lpfc_issue_hb_tmo(phba);
8338 if (!list_empty(&pring->txcmplq))
8339 if (!(phba->pport->load_flag & FC_UNLOADING))
8340 mod_timer(&vport->els_tmofunc,
8341 jiffies + msecs_to_jiffies(1000 * timeout));
8345 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8346 * @vport: pointer to a host virtual N_Port data structure.
8348 * This routine is used to clean up all the outstanding ELS commands on a
8349 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8350 * routine. After that, it walks the ELS transmit queue to remove all the
8351 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8352 * the IOCBs with a non-NULL completion callback function, the callback
8353 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8354 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8355 * callback function, the IOCB will simply be released. Finally, it walks
8356 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8357 * completion queue IOCB that is associated with the @vport and is not
8358 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8359 * part of the discovery state machine) out to HBA by invoking the
8360 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8361 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8362 * the IOCBs are aborted when this function returns.
8365 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8367 LIST_HEAD(abort_list);
8368 struct lpfc_hba *phba = vport->phba;
8369 struct lpfc_sli_ring *pring;
8370 struct lpfc_iocbq *tmp_iocb, *piocb;
8372 unsigned long iflags = 0;
8374 lpfc_fabric_abort_vport(vport);
8377 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8378 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8379 * ultimately grabs the ring_lock, the driver must splice the list into
8380 * a working list and release the locks before calling the abort.
8382 spin_lock_irqsave(&phba->hbalock, iflags);
8383 pring = lpfc_phba_elsring(phba);
8385 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8386 if (unlikely(!pring)) {
8387 spin_unlock_irqrestore(&phba->hbalock, iflags);
8391 if (phba->sli_rev == LPFC_SLI_REV4)
8392 spin_lock(&pring->ring_lock);
8394 /* First we need to issue aborts to outstanding cmds on txcmpl */
8395 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8396 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8399 if (piocb->vport != vport)
8402 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8405 /* On the ELS ring we can have ELS_REQUESTs or
8406 * GEN_REQUESTs waiting for a response.
8409 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8410 list_add_tail(&piocb->dlist, &abort_list);
8412 /* If the link is down when flushing ELS commands
8413 * the firmware will not complete them till after
8414 * the link comes back up. This may confuse
8415 * discovery for the new link up, so we need to
8416 * change the compl routine to just clean up the iocb
8417 * and avoid any retry logic.
8419 if (phba->link_state == LPFC_LINK_DOWN)
8420 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8422 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8423 list_add_tail(&piocb->dlist, &abort_list);
8426 if (phba->sli_rev == LPFC_SLI_REV4)
8427 spin_unlock(&pring->ring_lock);
8428 spin_unlock_irqrestore(&phba->hbalock, iflags);
8430 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8431 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8432 spin_lock_irqsave(&phba->hbalock, iflags);
8433 list_del_init(&piocb->dlist);
8434 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
8435 spin_unlock_irqrestore(&phba->hbalock, iflags);
8437 /* Make sure HBA is alive */
8438 lpfc_issue_hb_tmo(phba);
8440 if (!list_empty(&abort_list))
8441 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8442 "3387 abort list for txq not empty\n");
8443 INIT_LIST_HEAD(&abort_list);
8445 spin_lock_irqsave(&phba->hbalock, iflags);
8446 if (phba->sli_rev == LPFC_SLI_REV4)
8447 spin_lock(&pring->ring_lock);
8449 /* No need to abort the txq list,
8450 * just queue them up for lpfc_sli_cancel_iocbs
8452 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8455 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8459 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8460 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8461 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8462 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8463 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8466 if (piocb->vport != vport)
8469 list_del_init(&piocb->list);
8470 list_add_tail(&piocb->list, &abort_list);
8473 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8474 if (vport == phba->pport) {
8475 list_for_each_entry_safe(piocb, tmp_iocb,
8476 &phba->fabric_iocb_list, list) {
8478 list_del_init(&piocb->list);
8479 list_add_tail(&piocb->list, &abort_list);
8483 if (phba->sli_rev == LPFC_SLI_REV4)
8484 spin_unlock(&pring->ring_lock);
8485 spin_unlock_irqrestore(&phba->hbalock, iflags);
8487 /* Cancel all the IOCBs from the completions list */
8488 lpfc_sli_cancel_iocbs(phba, &abort_list,
8489 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8495 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8496 * @phba: pointer to lpfc hba data structure.
8498 * This routine is used to clean up all the outstanding ELS commands on a
8499 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8500 * routine. After that, it walks the ELS transmit queue to remove all the
8501 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8502 * the IOCBs with the completion callback function associated, the callback
8503 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8504 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8505 * callback function associated, the IOCB will simply be released. Finally,
8506 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8507 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8508 * management plane IOCBs that are not part of the discovery state machine)
8509 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8512 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8514 struct lpfc_vport *vport;
8516 spin_lock_irq(&phba->port_list_lock);
8517 list_for_each_entry(vport, &phba->port_list, listentry)
8518 lpfc_els_flush_cmd(vport);
8519 spin_unlock_irq(&phba->port_list_lock);
8525 * lpfc_send_els_failure_event - Posts an ELS command failure event
8526 * @phba: Pointer to hba context object.
8527 * @cmdiocbp: Pointer to command iocb which reported error.
8528 * @rspiocbp: Pointer to response iocb which reported error.
8530 * This function sends an event when there is an ELS command
8534 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8535 struct lpfc_iocbq *cmdiocbp,
8536 struct lpfc_iocbq *rspiocbp)
8538 struct lpfc_vport *vport = cmdiocbp->vport;
8539 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8540 struct lpfc_lsrjt_event lsrjt_event;
8541 struct lpfc_fabric_event_header fabric_event;
8543 struct lpfc_nodelist *ndlp;
8546 ndlp = cmdiocbp->context1;
8550 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8551 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8552 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8553 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8554 sizeof(struct lpfc_name));
8555 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8556 sizeof(struct lpfc_name));
8557 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8558 cmdiocbp->context2)->virt);
8559 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8560 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8561 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8562 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8563 fc_host_post_vendor_event(shost,
8564 fc_get_event_number(),
8565 sizeof(lsrjt_event),
8566 (char *)&lsrjt_event,
8570 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8571 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8572 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8573 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8574 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8576 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8577 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8578 sizeof(struct lpfc_name));
8579 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8580 sizeof(struct lpfc_name));
8581 fc_host_post_vendor_event(shost,
8582 fc_get_event_number(),
8583 sizeof(fabric_event),
8584 (char *)&fabric_event,
8592 * lpfc_send_els_event - Posts unsolicited els event
8593 * @vport: Pointer to vport object.
8594 * @ndlp: Pointer FC node object.
8595 * @payload: ELS command code type.
8597 * This function posts an event when there is an incoming
8598 * unsolicited ELS command.
8601 lpfc_send_els_event(struct lpfc_vport *vport,
8602 struct lpfc_nodelist *ndlp,
8605 struct lpfc_els_event_header *els_data = NULL;
8606 struct lpfc_logo_event *logo_data = NULL;
8607 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8609 if (*payload == ELS_CMD_LOGO) {
8610 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8612 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8613 "0148 Failed to allocate memory "
8614 "for LOGO event\n");
8617 els_data = &logo_data->header;
8619 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8622 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8623 "0149 Failed to allocate memory "
8628 els_data->event_type = FC_REG_ELS_EVENT;
8631 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8634 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8637 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8640 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8641 /* Copy the WWPN in the LOGO payload */
8642 memcpy(logo_data->logo_wwpn, &payload[2],
8643 sizeof(struct lpfc_name));
8649 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8650 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8651 if (*payload == ELS_CMD_LOGO) {
8652 fc_host_post_vendor_event(shost,
8653 fc_get_event_number(),
8654 sizeof(struct lpfc_logo_event),
8659 fc_host_post_vendor_event(shost,
8660 fc_get_event_number(),
8661 sizeof(struct lpfc_els_event_header),
8671 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8672 FC_LS_TLV_DTAG_INIT);
8674 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8675 FC_FPIN_LI_EVT_TYPES_INIT);
8678 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8679 * @vport: Pointer to vport object.
8680 * @tlv: Pointer to the Link Integrity Notification Descriptor.
8682 * This function processes a link integrity FPIN event by
8686 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8688 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8689 const char *li_evt_str;
8692 li_evt = be16_to_cpu(li->event_type);
8693 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8695 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8696 "4680 FPIN Link Integrity %s (x%x) "
8697 "Detecting PN x%016llx Attached PN x%016llx "
8698 "Duration %d mSecs Count %d Port Cnt %d\n",
8700 be64_to_cpu(li->detecting_wwpn),
8701 be64_to_cpu(li->attached_wwpn),
8702 be32_to_cpu(li->event_threshold),
8703 be32_to_cpu(li->event_count),
8704 be32_to_cpu(li->pname_count));
8708 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8711 struct fc_tlv_desc *tlv;
8712 const char *dtag_nm;
8713 uint32_t desc_cnt = 0, bytes_remain;
8716 /* FPINs handled only if we are in the right discovery state */
8717 if (vport->port_state < LPFC_DISC_AUTH)
8720 /* make sure there is the full fpin header */
8721 if (fpin_length < sizeof(struct fc_els_fpin))
8724 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8725 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8726 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8728 /* process each descriptor */
8729 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8730 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8732 dtag = be32_to_cpu(tlv->desc_tag);
8734 case ELS_DTAG_LNK_INTEGRITY:
8735 lpfc_els_rcv_fpin_li(vport, tlv);
8738 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8739 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8740 "4678 skipped FPIN descriptor[%d]: "
8742 desc_cnt, dtag, dtag_nm);
8747 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8748 tlv = fc_tlv_next_desc(tlv);
8751 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8756 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8757 * @phba: pointer to lpfc hba data structure.
8758 * @pring: pointer to a SLI ring.
8759 * @vport: pointer to a host virtual N_Port data structure.
8760 * @elsiocb: pointer to lpfc els command iocb data structure.
8762 * This routine is used for processing the IOCB associated with a unsolicited
8763 * event. It first determines whether there is an existing ndlp that matches
8764 * the DID from the unsolicited IOCB. If not, it will create a new one with
8765 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8766 * IOCB is then used to invoke the proper routine and to set up proper state
8767 * of the discovery state machine.
8770 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8771 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8773 struct lpfc_nodelist *ndlp;
8775 uint32_t *payload, payload_len;
8776 uint32_t cmd, did, newnode;
8777 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8778 IOCB_t *icmd = &elsiocb->iocb;
8781 if (!vport || !(elsiocb->context2))
8785 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8786 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8788 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8789 lpfc_post_buffer(phba, pring, 1);
8791 did = icmd->un.rcvels.remoteID;
8792 if (icmd->ulpStatus) {
8793 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8794 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8795 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8799 /* Check to see if link went down during discovery */
8800 if (lpfc_els_chk_latt(vport))
8803 /* Ignore traffic received during vport shutdown. */
8804 if (vport->load_flag & FC_UNLOADING)
8807 /* If NPort discovery is delayed drop incoming ELS */
8808 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8809 (cmd != ELS_CMD_PLOGI))
8812 ndlp = lpfc_findnode_did(vport, did);
8814 /* Cannot find existing Fabric ndlp, so allocate a new one */
8815 ndlp = lpfc_nlp_init(vport, did);
8818 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8820 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8821 ndlp->nlp_type |= NLP_FABRIC;
8822 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8823 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8827 phba->fc_stat.elsRcvFrame++;
8830 * Do not process any unsolicited ELS commands
8831 * if the ndlp is in DEV_LOSS
8833 spin_lock_irq(&ndlp->lock);
8834 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8835 spin_unlock_irq(&ndlp->lock);
8840 spin_unlock_irq(&ndlp->lock);
8842 elsiocb->context1 = lpfc_nlp_get(ndlp);
8843 if (!elsiocb->context1)
8845 elsiocb->vport = vport;
8847 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8848 cmd &= ELS_CMD_MASK;
8850 /* ELS command <elsCmd> received from NPORT <did> */
8851 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8852 "0112 ELS command x%x received from NPORT x%x "
8853 "refcnt %d Data: x%x x%x x%x x%x\n",
8854 cmd, did, kref_read(&ndlp->kref), vport->port_state,
8855 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
8857 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8858 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8859 (cmd != ELS_CMD_FLOGI) &&
8860 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8861 rjt_err = LSRJT_LOGICAL_BSY;
8862 rjt_exp = LSEXP_NOTHING_MORE;
8868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8869 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8870 did, vport->port_state, ndlp->nlp_flag);
8872 phba->fc_stat.elsRcvPLOGI++;
8873 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8874 if (phba->sli_rev == LPFC_SLI_REV4 &&
8875 (phba->pport->fc_flag & FC_PT2PT)) {
8876 vport->fc_prevDID = vport->fc_myDID;
8877 /* Our DID needs to be updated before registering
8878 * the vfi. This is done in lpfc_rcv_plogi but
8879 * that is called after the reg_vfi.
8881 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8882 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8883 "3312 Remote port assigned DID x%x "
8884 "%x\n", vport->fc_myDID,
8888 lpfc_send_els_event(vport, ndlp, payload);
8890 /* If Nport discovery is delayed, reject PLOGIs */
8891 if (vport->fc_flag & FC_DISC_DELAYED) {
8892 rjt_err = LSRJT_UNABLE_TPC;
8893 rjt_exp = LSEXP_NOTHING_MORE;
8897 if (vport->port_state < LPFC_DISC_AUTH) {
8898 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8899 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8900 rjt_err = LSRJT_UNABLE_TPC;
8901 rjt_exp = LSEXP_NOTHING_MORE;
8906 spin_lock_irq(&ndlp->lock);
8907 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8908 spin_unlock_irq(&ndlp->lock);
8910 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8916 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8917 did, vport->port_state, ndlp->nlp_flag);
8919 phba->fc_stat.elsRcvFLOGI++;
8921 /* If the driver believes fabric discovery is done and is ready,
8922 * bounce the link. There is some descrepancy.
8924 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8925 vport->fc_flag & FC_PT2PT &&
8926 vport->rcv_flogi_cnt >= 1) {
8927 rjt_err = LSRJT_LOGICAL_BSY;
8928 rjt_exp = LSEXP_NOTHING_MORE;
8933 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8935 lpfc_disc_state_machine(vport, ndlp, NULL,
8939 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8940 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8941 did, vport->port_state, ndlp->nlp_flag);
8943 phba->fc_stat.elsRcvLOGO++;
8944 lpfc_send_els_event(vport, ndlp, payload);
8945 if (vport->port_state < LPFC_DISC_AUTH) {
8946 rjt_err = LSRJT_UNABLE_TPC;
8947 rjt_exp = LSEXP_NOTHING_MORE;
8950 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8953 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8954 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8955 did, vport->port_state, ndlp->nlp_flag);
8957 phba->fc_stat.elsRcvPRLO++;
8958 lpfc_send_els_event(vport, ndlp, payload);
8959 if (vport->port_state < LPFC_DISC_AUTH) {
8960 rjt_err = LSRJT_UNABLE_TPC;
8961 rjt_exp = LSEXP_NOTHING_MORE;
8964 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8967 phba->fc_stat.elsRcvLCB++;
8968 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8971 phba->fc_stat.elsRcvRDP++;
8972 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8975 phba->fc_stat.elsRcvRSCN++;
8976 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8978 lpfc_disc_state_machine(vport, ndlp, NULL,
8982 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8983 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8984 did, vport->port_state, ndlp->nlp_flag);
8986 lpfc_send_els_event(vport, ndlp, payload);
8987 phba->fc_stat.elsRcvADISC++;
8988 if (vport->port_state < LPFC_DISC_AUTH) {
8989 rjt_err = LSRJT_UNABLE_TPC;
8990 rjt_exp = LSEXP_NOTHING_MORE;
8993 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8998 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8999 did, vport->port_state, ndlp->nlp_flag);
9001 phba->fc_stat.elsRcvPDISC++;
9002 if (vport->port_state < LPFC_DISC_AUTH) {
9003 rjt_err = LSRJT_UNABLE_TPC;
9004 rjt_exp = LSEXP_NOTHING_MORE;
9007 lpfc_disc_state_machine(vport, ndlp, elsiocb,
9011 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9012 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
9013 did, vport->port_state, ndlp->nlp_flag);
9015 phba->fc_stat.elsRcvFARPR++;
9016 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
9019 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9020 "RCV FARP: did:x%x/ste:x%x flg:x%x",
9021 did, vport->port_state, ndlp->nlp_flag);
9023 phba->fc_stat.elsRcvFARP++;
9024 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
9027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9028 "RCV FAN: did:x%x/ste:x%x flg:x%x",
9029 did, vport->port_state, ndlp->nlp_flag);
9031 phba->fc_stat.elsRcvFAN++;
9032 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
9035 case ELS_CMD_NVMEPRLI:
9036 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9037 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
9038 did, vport->port_state, ndlp->nlp_flag);
9040 phba->fc_stat.elsRcvPRLI++;
9041 if ((vport->port_state < LPFC_DISC_AUTH) &&
9042 (vport->fc_flag & FC_FABRIC)) {
9043 rjt_err = LSRJT_UNABLE_TPC;
9044 rjt_exp = LSEXP_NOTHING_MORE;
9047 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
9050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9051 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
9052 did, vport->port_state, ndlp->nlp_flag);
9054 phba->fc_stat.elsRcvLIRR++;
9055 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
9057 lpfc_disc_state_machine(vport, ndlp, NULL,
9061 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9062 "RCV RLS: did:x%x/ste:x%x flg:x%x",
9063 did, vport->port_state, ndlp->nlp_flag);
9065 phba->fc_stat.elsRcvRLS++;
9066 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
9068 lpfc_disc_state_machine(vport, ndlp, NULL,
9072 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9073 "RCV RPL: did:x%x/ste:x%x flg:x%x",
9074 did, vport->port_state, ndlp->nlp_flag);
9076 phba->fc_stat.elsRcvRPL++;
9077 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
9079 lpfc_disc_state_machine(vport, ndlp, NULL,
9083 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9084 "RCV RNID: did:x%x/ste:x%x flg:x%x",
9085 did, vport->port_state, ndlp->nlp_flag);
9087 phba->fc_stat.elsRcvRNID++;
9088 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
9090 lpfc_disc_state_machine(vport, ndlp, NULL,
9094 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9095 "RCV RTV: did:x%x/ste:x%x flg:x%x",
9096 did, vport->port_state, ndlp->nlp_flag);
9097 phba->fc_stat.elsRcvRTV++;
9098 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
9100 lpfc_disc_state_machine(vport, ndlp, NULL,
9104 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9105 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
9106 did, vport->port_state, ndlp->nlp_flag);
9108 phba->fc_stat.elsRcvRRQ++;
9109 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
9111 lpfc_disc_state_machine(vport, ndlp, NULL,
9115 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9116 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
9117 did, vport->port_state, ndlp->nlp_flag);
9119 phba->fc_stat.elsRcvECHO++;
9120 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
9122 lpfc_disc_state_machine(vport, ndlp, NULL,
9126 /* receive this due to exchange closed */
9127 rjt_err = LSRJT_UNABLE_TPC;
9128 rjt_exp = LSEXP_INVALID_OX_RX;
9131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9132 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
9133 did, vport->port_state, ndlp->nlp_flag);
9135 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
9138 /* There are no replies, so no rjt codes */
9141 phba->fc_stat.elsRcvRDF++;
9142 /* Accept RDF only from fabric controller */
9143 if (did != Fabric_Cntl_DID) {
9144 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
9145 "1115 Received RDF from invalid DID "
9147 rjt_err = LSRJT_PROTOCOL_ERR;
9148 rjt_exp = LSEXP_NOTHING_MORE;
9152 lpfc_els_rcv_rdf(vport, elsiocb, ndlp);
9155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
9156 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
9157 cmd, did, vport->port_state);
9159 /* Unsupported ELS command, reject */
9160 rjt_err = LSRJT_CMD_UNSUPPORTED;
9161 rjt_exp = LSEXP_NOTHING_MORE;
9163 /* Unknown ELS command <elsCmd> received from NPORT <did> */
9164 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9165 "0115 Unknown ELS command x%x "
9166 "received from NPORT x%x\n", cmd, did);
9168 lpfc_disc_state_machine(vport, ndlp, NULL,
9174 /* check if need to LS_RJT received ELS cmd */
9176 memset(&stat, 0, sizeof(stat));
9177 stat.un.b.lsRjtRsnCode = rjt_err;
9178 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
9179 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
9181 /* Remove the reference from above for new nodes. */
9183 lpfc_disc_state_machine(vport, ndlp, NULL,
9187 /* Release the reference on this elsiocb, not the ndlp. */
9188 lpfc_nlp_put(elsiocb->context1);
9189 elsiocb->context1 = NULL;
9191 /* Special case. Driver received an unsolicited command that
9192 * unsupportable given the driver's current state. Reset the
9193 * link and start over.
9196 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9199 lpfc_linkdown(phba);
9200 lpfc_init_link(phba, mbox,
9202 phba->cfg_link_speed);
9203 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
9204 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9205 mbox->vport = vport;
9206 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
9208 mempool_free(mbox, phba->mbox_mem_pool);
9214 if (vport && !(vport->load_flag & FC_UNLOADING))
9215 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9216 "0111 Dropping received ELS cmd "
9217 "Data: x%x x%x x%x\n",
9218 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
9219 phba->fc_stat.elsRcvDrop++;
9223 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
9224 * @phba: pointer to lpfc hba data structure.
9225 * @pring: pointer to a SLI ring.
9226 * @elsiocb: pointer to lpfc els iocb data structure.
9228 * This routine is used to process an unsolicited event received from a SLI
9229 * (Service Level Interface) ring. The actual processing of the data buffer
9230 * associated with the unsolicited event is done by invoking the routine
9231 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
9232 * SLI ring on which the unsolicited event was received.
9235 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9236 struct lpfc_iocbq *elsiocb)
9238 struct lpfc_vport *vport = phba->pport;
9239 IOCB_t *icmd = &elsiocb->iocb;
9241 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
9242 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
9244 elsiocb->context1 = NULL;
9245 elsiocb->context2 = NULL;
9246 elsiocb->context3 = NULL;
9248 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
9249 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
9250 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
9251 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
9252 IOERR_RCV_BUFFER_WAITING) {
9253 phba->fc_stat.NoRcvBuf++;
9254 /* Not enough posted buffers; Try posting more buffers */
9255 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
9256 lpfc_post_buffer(phba, pring, 0);
9260 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
9261 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
9262 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
9263 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
9264 vport = phba->pport;
9266 vport = lpfc_find_vport_by_vpid(phba,
9267 icmd->unsli3.rcvsli3.vpi);
9270 /* If there are no BDEs associated
9271 * with this IOCB, there is nothing to do.
9273 if (icmd->ulpBdeCount == 0)
9276 /* type of ELS cmd is first 32bit word
9279 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9280 elsiocb->context2 = bdeBuf1;
9282 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
9283 icmd->un.cont64[0].addrLow);
9284 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
9288 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9290 * The different unsolicited event handlers would tell us
9291 * if they are done with "mp" by setting context2 to NULL.
9293 if (elsiocb->context2) {
9294 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
9295 elsiocb->context2 = NULL;
9298 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
9299 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
9300 icmd->ulpBdeCount == 2) {
9301 elsiocb->context2 = bdeBuf2;
9302 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9303 /* free mp if we are done with it */
9304 if (elsiocb->context2) {
9305 lpfc_in_buf_free(phba, elsiocb->context2);
9306 elsiocb->context2 = NULL;
9312 lpfc_start_fdmi(struct lpfc_vport *vport)
9314 struct lpfc_nodelist *ndlp;
9316 /* If this is the first time, allocate an ndlp and initialize
9317 * it. Otherwise, make sure the node is enabled and then do the
9320 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9322 ndlp = lpfc_nlp_init(vport, FDMI_DID);
9324 ndlp->nlp_type |= NLP_FABRIC;
9330 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9331 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9335 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
9336 * @phba: pointer to lpfc hba data structure.
9337 * @vport: pointer to a virtual N_Port data structure.
9339 * This routine issues a Port Login (PLOGI) to the Name Server with
9340 * State Change Request (SCR) for a @vport. This routine will create an
9341 * ndlp for the Name Server associated to the @vport if such node does
9342 * not already exist. The PLOGI to Name Server is issued by invoking the
9343 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9344 * (FDMI) is configured to the @vport, a FDMI node will be created and
9345 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9348 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9350 struct lpfc_nodelist *ndlp;
9351 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9354 * If lpfc_delay_discovery parameter is set and the clean address
9355 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9358 spin_lock_irq(shost->host_lock);
9359 if (vport->fc_flag & FC_DISC_DELAYED) {
9360 spin_unlock_irq(shost->host_lock);
9361 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9362 "3334 Delay fc port discovery for %d secs\n",
9364 mod_timer(&vport->delayed_disc_tmo,
9365 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9368 spin_unlock_irq(shost->host_lock);
9370 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9372 ndlp = lpfc_nlp_init(vport, NameServer_DID);
9374 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9375 lpfc_disc_start(vport);
9378 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9379 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9380 "0251 NameServer login: no memory\n");
9385 ndlp->nlp_type |= NLP_FABRIC;
9387 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9389 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9390 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9391 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9392 "0252 Cannot issue NameServer login\n");
9396 if ((phba->cfg_enable_SmartSAN ||
9397 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9398 (vport->load_flag & FC_ALLOW_FDMI))
9399 lpfc_start_fdmi(vport);
9403 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9404 * @phba: pointer to lpfc hba data structure.
9405 * @pmb: pointer to the driver internal queue element for mailbox command.
9407 * This routine is the completion callback function to register new vport
9408 * mailbox command. If the new vport mailbox command completes successfully,
9409 * the fabric registration login shall be performed on physical port (the
9410 * new vport created is actually a physical port, with VPI 0) or the port
9411 * login to Name Server for State Change Request (SCR) will be performed
9412 * on virtual port (real virtual port, with VPI greater than 0).
9415 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9417 struct lpfc_vport *vport = pmb->vport;
9418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9419 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9420 MAILBOX_t *mb = &pmb->u.mb;
9423 spin_lock_irq(shost->host_lock);
9424 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9425 spin_unlock_irq(shost->host_lock);
9427 if (mb->mbxStatus) {
9428 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9429 "0915 Register VPI failed : Status: x%x"
9430 " upd bit: x%x \n", mb->mbxStatus,
9431 mb->un.varRegVpi.upd);
9432 if (phba->sli_rev == LPFC_SLI_REV4 &&
9433 mb->un.varRegVpi.upd)
9434 goto mbox_err_exit ;
9436 switch (mb->mbxStatus) {
9437 case 0x11: /* unsupported feature */
9438 case 0x9603: /* max_vpi exceeded */
9439 case 0x9602: /* Link event since CLEAR_LA */
9440 /* giving up on vport registration */
9441 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9442 spin_lock_irq(shost->host_lock);
9443 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9444 spin_unlock_irq(shost->host_lock);
9445 lpfc_can_disctmo(vport);
9447 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9449 spin_lock_irq(shost->host_lock);
9450 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9451 spin_unlock_irq(shost->host_lock);
9452 lpfc_init_vpi(phba, pmb, vport->vpi);
9454 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9455 rc = lpfc_sli_issue_mbox(phba, pmb,
9457 if (rc == MBX_NOT_FINISHED) {
9458 lpfc_printf_vlog(vport, KERN_ERR,
9460 "2732 Failed to issue INIT_VPI"
9461 " mailbox command\n");
9468 /* Try to recover from this error */
9469 if (phba->sli_rev == LPFC_SLI_REV4)
9470 lpfc_sli4_unreg_all_rpis(vport);
9471 lpfc_mbx_unreg_vpi(vport);
9472 spin_lock_irq(shost->host_lock);
9473 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9474 spin_unlock_irq(shost->host_lock);
9475 if (mb->mbxStatus == MBX_NOT_FINISHED)
9477 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9478 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9479 if (phba->sli_rev == LPFC_SLI_REV4)
9480 lpfc_issue_init_vfi(vport);
9482 lpfc_initial_flogi(vport);
9484 lpfc_initial_fdisc(vport);
9489 spin_lock_irq(shost->host_lock);
9490 vport->vpi_state |= LPFC_VPI_REGISTERED;
9491 spin_unlock_irq(shost->host_lock);
9492 if (vport == phba->pport) {
9493 if (phba->sli_rev < LPFC_SLI_REV4)
9494 lpfc_issue_fabric_reglogin(vport);
9497 * If the physical port is instantiated using
9498 * FDISC, do not start vport discovery.
9500 if (vport->port_state != LPFC_FDISC)
9501 lpfc_start_fdiscs(phba);
9502 lpfc_do_scr_ns_plogi(phba, vport);
9505 lpfc_do_scr_ns_plogi(phba, vport);
9509 /* Now, we decrement the ndlp reference count held for this
9514 mempool_free(pmb, phba->mbox_mem_pool);
9519 * lpfc_register_new_vport - Register a new vport with a HBA
9520 * @phba: pointer to lpfc hba data structure.
9521 * @vport: pointer to a host virtual N_Port data structure.
9522 * @ndlp: pointer to a node-list data structure.
9524 * This routine registers the @vport as a new virtual port with a HBA.
9525 * It is done through a registering vpi mailbox command.
9528 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9529 struct lpfc_nodelist *ndlp)
9531 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9534 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9536 lpfc_reg_vpi(vport, mbox);
9537 mbox->vport = vport;
9538 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9539 if (!mbox->ctx_ndlp) {
9540 mempool_free(mbox, phba->mbox_mem_pool);
9544 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9545 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9546 == MBX_NOT_FINISHED) {
9547 /* mailbox command not success, decrement ndlp
9548 * reference count for this command
9551 mempool_free(mbox, phba->mbox_mem_pool);
9553 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9554 "0253 Register VPI: Can't send mbox\n");
9558 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9559 "0254 Register VPI: no memory\n");
9565 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9566 spin_lock_irq(shost->host_lock);
9567 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9568 spin_unlock_irq(shost->host_lock);
9573 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9574 * @phba: pointer to lpfc hba data structure.
9576 * This routine cancels the retry delay timers to all the vports.
9579 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9581 struct lpfc_vport **vports;
9582 struct lpfc_nodelist *ndlp;
9583 uint32_t link_state;
9586 /* Treat this failure as linkdown for all vports */
9587 link_state = phba->link_state;
9588 lpfc_linkdown(phba);
9589 phba->link_state = link_state;
9591 vports = lpfc_create_vport_work_array(phba);
9594 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9595 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9597 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9598 lpfc_els_flush_cmd(vports[i]);
9600 lpfc_destroy_vport_work_array(phba, vports);
9605 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9606 * @phba: pointer to lpfc hba data structure.
9608 * This routine abort all pending discovery commands and
9609 * start a timer to retry FLOGI for the physical port
9613 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9615 struct lpfc_nodelist *ndlp;
9617 /* Cancel the all vports retry delay retry timers */
9618 lpfc_cancel_all_vport_retry_delay_timer(phba);
9620 /* If fabric require FLOGI, then re-instantiate physical login */
9621 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9625 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9626 spin_lock_irq(&ndlp->lock);
9627 ndlp->nlp_flag |= NLP_DELAY_TMO;
9628 spin_unlock_irq(&ndlp->lock);
9629 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9630 phba->pport->port_state = LPFC_FLOGI;
9635 * lpfc_fabric_login_reqd - Check if FLOGI required.
9636 * @phba: pointer to lpfc hba data structure.
9637 * @cmdiocb: pointer to FDISC command iocb.
9638 * @rspiocb: pointer to FDISC response iocb.
9640 * This routine checks if a FLOGI is reguired for FDISC
9644 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9645 struct lpfc_iocbq *cmdiocb,
9646 struct lpfc_iocbq *rspiocb)
9649 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9650 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9657 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9658 * @phba: pointer to lpfc hba data structure.
9659 * @cmdiocb: pointer to lpfc command iocb data structure.
9660 * @rspiocb: pointer to lpfc response iocb data structure.
9662 * This routine is the completion callback function to a Fabric Discover
9663 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9664 * single threaded, each FDISC completion callback function will reset
9665 * the discovery timer for all vports such that the timers will not get
9666 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9667 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9668 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9669 * assigned to the vport has been changed with the completion of the FDISC
9670 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9671 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9672 * routine is invoked to register new vport with the HBA. Otherwise, the
9673 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9674 * Server for State Change Request (SCR).
9677 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9678 struct lpfc_iocbq *rspiocb)
9680 struct lpfc_vport *vport = cmdiocb->vport;
9681 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9682 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9683 struct lpfc_nodelist *np;
9684 struct lpfc_nodelist *next_np;
9685 IOCB_t *irsp = &rspiocb->iocb;
9686 struct lpfc_iocbq *piocb;
9687 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9688 struct serv_parm *sp;
9689 uint8_t fabric_param_changed;
9691 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9692 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9693 irsp->ulpStatus, irsp->un.ulpWord[4],
9695 /* Since all FDISCs are being single threaded, we
9696 * must reset the discovery timer for ALL vports
9697 * waiting to send FDISC when one completes.
9699 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9700 lpfc_set_disctmo(piocb->vport);
9703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9704 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9705 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9707 if (irsp->ulpStatus) {
9709 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9710 lpfc_retry_pport_discovery(phba);
9714 /* Check for retry */
9715 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9718 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9719 "0126 FDISC failed. (x%x/x%x)\n",
9720 irsp->ulpStatus, irsp->un.ulpWord[4]);
9723 spin_lock_irq(shost->host_lock);
9724 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9725 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9726 vport->fc_flag |= FC_FABRIC;
9727 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9728 vport->fc_flag |= FC_PUBLIC_LOOP;
9729 spin_unlock_irq(shost->host_lock);
9731 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9732 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9733 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9736 sp = prsp->virt + sizeof(uint32_t);
9737 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9738 memcpy(&vport->fabric_portname, &sp->portName,
9739 sizeof(struct lpfc_name));
9740 memcpy(&vport->fabric_nodename, &sp->nodeName,
9741 sizeof(struct lpfc_name));
9742 if (fabric_param_changed &&
9743 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9744 /* If our NportID changed, we need to ensure all
9745 * remaining NPORTs get unreg_login'ed so we can
9748 list_for_each_entry_safe(np, next_np,
9749 &vport->fc_nodes, nlp_listp) {
9750 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
9751 !(np->nlp_flag & NLP_NPR_ADISC))
9753 spin_lock_irq(&ndlp->lock);
9754 np->nlp_flag &= ~NLP_NPR_ADISC;
9755 spin_unlock_irq(&ndlp->lock);
9756 lpfc_unreg_rpi(vport, np);
9758 lpfc_cleanup_pending_mbox(vport);
9760 if (phba->sli_rev == LPFC_SLI_REV4)
9761 lpfc_sli4_unreg_all_rpis(vport);
9763 lpfc_mbx_unreg_vpi(vport);
9764 spin_lock_irq(shost->host_lock);
9765 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9766 if (phba->sli_rev == LPFC_SLI_REV4)
9767 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9769 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9770 spin_unlock_irq(shost->host_lock);
9771 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9772 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9774 * Driver needs to re-reg VPI in order for f/w
9775 * to update the MAC address.
9777 lpfc_register_new_vport(phba, vport, ndlp);
9778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9782 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9783 lpfc_issue_init_vpi(vport);
9784 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9785 lpfc_register_new_vport(phba, vport, ndlp);
9787 lpfc_do_scr_ns_plogi(phba, vport);
9789 /* The FDISC completed successfully. Move the fabric ndlp to
9790 * UNMAPPED state and register with the transport.
9792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9796 if (vport->fc_vport &&
9797 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9798 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9799 /* Cancel discovery timer */
9800 lpfc_can_disctmo(vport);
9802 lpfc_els_free_iocb(phba, cmdiocb);
9807 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9808 * @vport: pointer to a virtual N_Port data structure.
9809 * @ndlp: pointer to a node-list data structure.
9810 * @retry: number of retries to the command IOCB.
9812 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9813 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9814 * routine to issue the IOCB, which makes sure only one outstanding fabric
9815 * IOCB will be sent off HBA at any given time.
9817 * Note that the ndlp reference count will be incremented by 1 for holding the
9818 * ndlp and the reference to ndlp will be stored into the context1 field of
9819 * the IOCB for the completion callback function to the FDISC ELS command.
9822 * 0 - Successfully issued fdisc iocb command
9823 * 1 - Failed to issue fdisc iocb command
9826 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9829 struct lpfc_hba *phba = vport->phba;
9831 struct lpfc_iocbq *elsiocb;
9832 struct serv_parm *sp;
9835 int did = ndlp->nlp_DID;
9838 vport->port_state = LPFC_FDISC;
9839 vport->fc_myDID = 0;
9840 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9841 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9844 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9845 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9846 "0255 Issue FDISC: no IOCB\n");
9850 icmd = &elsiocb->iocb;
9851 icmd->un.elsreq64.myID = 0;
9852 icmd->un.elsreq64.fl = 1;
9855 * SLI3 ports require a different context type value than SLI4.
9856 * Catch SLI3 ports here and override the prep.
9858 if (phba->sli_rev == LPFC_SLI_REV3) {
9863 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9864 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9865 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9866 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9867 sp = (struct serv_parm *) pcmd;
9868 /* Setup CSPs accordingly for Fabric */
9869 sp->cmn.e_d_tov = 0;
9870 sp->cmn.w2.r_a_tov = 0;
9871 sp->cmn.virtual_fabric_support = 0;
9872 sp->cls1.classValid = 0;
9873 sp->cls2.seqDelivery = 1;
9874 sp->cls3.seqDelivery = 1;
9876 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9877 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9878 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9879 pcmd += sizeof(uint32_t); /* Port Name */
9880 memcpy(pcmd, &vport->fc_portname, 8);
9881 pcmd += sizeof(uint32_t); /* Node Name */
9882 pcmd += sizeof(uint32_t); /* Node Name */
9883 memcpy(pcmd, &vport->fc_nodename, 8);
9884 sp->cmn.valid_vendor_ver_level = 0;
9885 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9886 lpfc_set_disctmo(vport);
9888 phba->fc_stat.elsXmitFDISC++;
9889 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9892 "Issue FDISC: did:x%x",
9895 elsiocb->context1 = lpfc_nlp_get(ndlp);
9896 if (!elsiocb->context1) {
9897 lpfc_els_free_iocb(phba, elsiocb);
9901 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9902 if (rc == IOCB_ERROR) {
9903 lpfc_els_free_iocb(phba, elsiocb);
9908 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9912 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9913 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9914 "0256 Issue FDISC: Cannot send IOCB\n");
9919 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9920 * @phba: pointer to lpfc hba data structure.
9921 * @cmdiocb: pointer to lpfc command iocb data structure.
9922 * @rspiocb: pointer to lpfc response iocb data structure.
9924 * This routine is the completion callback function to the issuing of a LOGO
9925 * ELS command off a vport. It frees the command IOCB and then decrement the
9926 * reference count held on ndlp for this completion function, indicating that
9927 * the reference to the ndlp is no long needed. Note that the
9928 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9929 * callback function and an additional explicit ndlp reference decrementation
9930 * will trigger the actual release of the ndlp.
9933 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9934 struct lpfc_iocbq *rspiocb)
9936 struct lpfc_vport *vport = cmdiocb->vport;
9938 struct lpfc_nodelist *ndlp;
9939 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9941 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9942 irsp = &rspiocb->iocb;
9943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9944 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9945 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9947 /* NPIV LOGO completes to NPort <nlp_DID> */
9948 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9949 "2928 NPIV LOGO completes to NPort x%x "
9950 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
9951 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9952 irsp->ulpTimeout, vport->num_disc_nodes,
9953 kref_read(&ndlp->kref), ndlp->nlp_flag,
9954 ndlp->fc4_xpt_flags);
9956 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9957 spin_lock_irq(shost->host_lock);
9958 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9959 vport->fc_flag &= ~FC_FABRIC;
9960 spin_unlock_irq(shost->host_lock);
9961 lpfc_can_disctmo(vport);
9964 /* Safe to release resources now. */
9965 lpfc_els_free_iocb(phba, cmdiocb);
9967 vport->unreg_vpi_cmpl = VPORT_ERROR;
9971 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9972 * @vport: pointer to a virtual N_Port data structure.
9973 * @ndlp: pointer to a node-list data structure.
9975 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9977 * Note that the ndlp reference count will be incremented by 1 for holding the
9978 * ndlp and the reference to ndlp will be stored into the context1 field of
9979 * the IOCB for the completion callback function to the LOGO ELS command.
9982 * 0 - Successfully issued logo off the @vport
9983 * 1 - Failed to issue logo off the @vport
9986 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9989 struct lpfc_hba *phba = vport->phba;
9990 struct lpfc_iocbq *elsiocb;
9994 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9995 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
10000 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
10001 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
10002 pcmd += sizeof(uint32_t);
10004 /* Fill in LOGO payload */
10005 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
10006 pcmd += sizeof(uint32_t);
10007 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
10009 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
10010 "Issue LOGO npiv did:x%x flg:x%x",
10011 ndlp->nlp_DID, ndlp->nlp_flag, 0);
10013 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
10014 spin_lock_irq(&ndlp->lock);
10015 ndlp->nlp_flag |= NLP_LOGO_SND;
10016 spin_unlock_irq(&ndlp->lock);
10017 elsiocb->context1 = lpfc_nlp_get(ndlp);
10018 if (!elsiocb->context1) {
10019 lpfc_els_free_iocb(phba, elsiocb);
10023 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
10024 if (rc == IOCB_ERROR) {
10025 lpfc_els_free_iocb(phba, elsiocb);
10026 lpfc_nlp_put(ndlp);
10032 spin_lock_irq(&ndlp->lock);
10033 ndlp->nlp_flag &= ~NLP_LOGO_SND;
10034 spin_unlock_irq(&ndlp->lock);
10039 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
10040 * @t: timer context used to obtain the lpfc hba.
10042 * This routine is invoked by the fabric iocb block timer after
10043 * timeout. It posts the fabric iocb block timeout event by setting the
10044 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
10045 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
10046 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
10047 * posted event WORKER_FABRIC_BLOCK_TMO.
10050 lpfc_fabric_block_timeout(struct timer_list *t)
10052 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
10053 unsigned long iflags;
10054 uint32_t tmo_posted;
10056 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
10057 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
10059 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
10060 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
10063 lpfc_worker_wake_up(phba);
10068 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
10069 * @phba: pointer to lpfc hba data structure.
10071 * This routine issues one fabric iocb from the driver internal list to
10072 * the HBA. It first checks whether it's ready to issue one fabric iocb to
10073 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
10074 * remove one pending fabric iocb from the driver internal list and invokes
10075 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
10078 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
10080 struct lpfc_iocbq *iocb;
10081 unsigned long iflags;
10087 spin_lock_irqsave(&phba->hbalock, iflags);
10088 /* Post any pending iocb to the SLI layer */
10089 if (atomic_read(&phba->fabric_iocb_count) == 0) {
10090 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
10093 /* Increment fabric iocb count to hold the position */
10094 atomic_inc(&phba->fabric_iocb_count);
10096 spin_unlock_irqrestore(&phba->hbalock, iflags);
10098 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
10099 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
10100 iocb->iocb_flag |= LPFC_IO_FABRIC;
10102 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
10103 "Fabric sched1: ste:x%x",
10104 iocb->vport->port_state, 0, 0);
10106 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
10108 if (ret == IOCB_ERROR) {
10109 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
10110 iocb->fabric_iocb_cmpl = NULL;
10111 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
10113 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
10114 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
10115 iocb->iocb_cmpl(phba, iocb, iocb);
10117 atomic_dec(&phba->fabric_iocb_count);
10124 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
10125 * @phba: pointer to lpfc hba data structure.
10127 * This routine unblocks the issuing fabric iocb command. The function
10128 * will clear the fabric iocb block bit and then invoke the routine
10129 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
10130 * from the driver internal fabric iocb list.
10133 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
10135 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10137 lpfc_resume_fabric_iocbs(phba);
10142 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
10143 * @phba: pointer to lpfc hba data structure.
10145 * This routine blocks the issuing fabric iocb for a specified amount of
10146 * time (currently 100 ms). This is done by set the fabric iocb block bit
10147 * and set up a timeout timer for 100ms. When the block bit is set, no more
10148 * fabric iocb will be issued out of the HBA.
10151 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
10155 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10156 /* Start a timer to unblock fabric iocbs after 100ms */
10158 mod_timer(&phba->fabric_block_timer,
10159 jiffies + msecs_to_jiffies(100));
10165 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
10166 * @phba: pointer to lpfc hba data structure.
10167 * @cmdiocb: pointer to lpfc command iocb data structure.
10168 * @rspiocb: pointer to lpfc response iocb data structure.
10170 * This routine is the callback function that is put to the fabric iocb's
10171 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
10172 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
10173 * function first restores and invokes the original iocb's callback function
10174 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
10175 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
10178 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10179 struct lpfc_iocbq *rspiocb)
10181 struct ls_rjt stat;
10183 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
10185 switch (rspiocb->iocb.ulpStatus) {
10186 case IOSTAT_NPORT_RJT:
10187 case IOSTAT_FABRIC_RJT:
10188 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
10189 lpfc_block_fabric_iocbs(phba);
10193 case IOSTAT_NPORT_BSY:
10194 case IOSTAT_FABRIC_BSY:
10195 lpfc_block_fabric_iocbs(phba);
10198 case IOSTAT_LS_RJT:
10199 stat.un.lsRjtError =
10200 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
10201 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
10202 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
10203 lpfc_block_fabric_iocbs(phba);
10207 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
10209 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
10210 cmdiocb->fabric_iocb_cmpl = NULL;
10211 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
10212 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
10214 atomic_dec(&phba->fabric_iocb_count);
10215 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
10216 /* Post any pending iocbs to HBA */
10217 lpfc_resume_fabric_iocbs(phba);
10222 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
10223 * @phba: pointer to lpfc hba data structure.
10224 * @iocb: pointer to lpfc command iocb data structure.
10226 * This routine is used as the top-level API for issuing a fabric iocb command
10227 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
10228 * function makes sure that only one fabric bound iocb will be outstanding at
10229 * any given time. As such, this function will first check to see whether there
10230 * is already an outstanding fabric iocb on the wire. If so, it will put the
10231 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
10232 * issued later. Otherwise, it will issue the iocb on the wire and update the
10233 * fabric iocb count it indicate that there is one fabric iocb on the wire.
10235 * Note, this implementation has a potential sending out fabric IOCBs out of
10236 * order. The problem is caused by the construction of the "ready" boolen does
10237 * not include the condition that the internal fabric IOCB list is empty. As
10238 * such, it is possible a fabric IOCB issued by this routine might be "jump"
10239 * ahead of the fabric IOCBs in the internal list.
10242 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
10243 * IOCB_ERROR - failed to issue fabric iocb
10246 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
10248 unsigned long iflags;
10252 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
10254 spin_lock_irqsave(&phba->hbalock, iflags);
10255 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
10256 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10259 /* Increment fabric iocb count to hold the position */
10260 atomic_inc(&phba->fabric_iocb_count);
10261 spin_unlock_irqrestore(&phba->hbalock, iflags);
10263 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
10264 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
10265 iocb->iocb_flag |= LPFC_IO_FABRIC;
10267 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
10268 "Fabric sched2: ste:x%x",
10269 iocb->vport->port_state, 0, 0);
10271 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
10273 if (ret == IOCB_ERROR) {
10274 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
10275 iocb->fabric_iocb_cmpl = NULL;
10276 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
10277 atomic_dec(&phba->fabric_iocb_count);
10280 spin_lock_irqsave(&phba->hbalock, iflags);
10281 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
10282 spin_unlock_irqrestore(&phba->hbalock, iflags);
10283 ret = IOCB_SUCCESS;
10289 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
10290 * @vport: pointer to a virtual N_Port data structure.
10292 * This routine aborts all the IOCBs associated with a @vport from the
10293 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10294 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10295 * list, removes each IOCB associated with the @vport off the list, set the
10296 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
10297 * associated with the IOCB.
10299 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
10301 LIST_HEAD(completions);
10302 struct lpfc_hba *phba = vport->phba;
10303 struct lpfc_iocbq *tmp_iocb, *piocb;
10305 spin_lock_irq(&phba->hbalock);
10306 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10309 if (piocb->vport != vport)
10312 list_move_tail(&piocb->list, &completions);
10314 spin_unlock_irq(&phba->hbalock);
10316 /* Cancel all the IOCBs from the completions list */
10317 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10318 IOERR_SLI_ABORTED);
10322 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
10323 * @ndlp: pointer to a node-list data structure.
10325 * This routine aborts all the IOCBs associated with an @ndlp from the
10326 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10327 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10328 * list, removes each IOCB associated with the @ndlp off the list, set the
10329 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
10330 * associated with the IOCB.
10332 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10334 LIST_HEAD(completions);
10335 struct lpfc_hba *phba = ndlp->phba;
10336 struct lpfc_iocbq *tmp_iocb, *piocb;
10337 struct lpfc_sli_ring *pring;
10339 pring = lpfc_phba_elsring(phba);
10341 if (unlikely(!pring))
10344 spin_lock_irq(&phba->hbalock);
10345 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10347 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10349 list_move_tail(&piocb->list, &completions);
10352 spin_unlock_irq(&phba->hbalock);
10354 /* Cancel all the IOCBs from the completions list */
10355 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10356 IOERR_SLI_ABORTED);
10360 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
10361 * @phba: pointer to lpfc hba data structure.
10363 * This routine aborts all the IOCBs currently on the driver internal
10364 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10365 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10366 * list, removes IOCBs off the list, set the status field to
10367 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10370 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10372 LIST_HEAD(completions);
10374 spin_lock_irq(&phba->hbalock);
10375 list_splice_init(&phba->fabric_iocb_list, &completions);
10376 spin_unlock_irq(&phba->hbalock);
10378 /* Cancel all the IOCBs from the completions list */
10379 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10380 IOERR_SLI_ABORTED);
10384 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10385 * @vport: pointer to lpfc vport data structure.
10387 * This routine is invoked by the vport cleanup for deletions and the cleanup
10388 * for an ndlp on removal.
10391 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10393 struct lpfc_hba *phba = vport->phba;
10394 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10395 unsigned long iflag = 0;
10397 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
10398 list_for_each_entry_safe(sglq_entry, sglq_next,
10399 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10400 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
10401 lpfc_nlp_put(sglq_entry->ndlp);
10402 sglq_entry->ndlp = NULL;
10405 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
10410 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10411 * @phba: pointer to lpfc hba data structure.
10412 * @axri: pointer to the els xri abort wcqe structure.
10414 * This routine is invoked by the worker thread to process a SLI4 slow-path
10418 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10419 struct sli4_wcqe_xri_aborted *axri)
10421 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10422 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10425 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10426 unsigned long iflag = 0;
10427 struct lpfc_nodelist *ndlp;
10428 struct lpfc_sli_ring *pring;
10430 pring = lpfc_phba_elsring(phba);
10432 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
10433 list_for_each_entry_safe(sglq_entry, sglq_next,
10434 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10435 if (sglq_entry->sli4_xritag == xri) {
10436 list_del(&sglq_entry->list);
10437 ndlp = sglq_entry->ndlp;
10438 sglq_entry->ndlp = NULL;
10439 list_add_tail(&sglq_entry->list,
10440 &phba->sli4_hba.lpfc_els_sgl_list);
10441 sglq_entry->state = SGL_FREED;
10442 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
10446 lpfc_set_rrq_active(phba, ndlp,
10447 sglq_entry->sli4_lxritag,
10449 lpfc_nlp_put(ndlp);
10452 /* Check if TXQ queue needs to be serviced */
10453 if (pring && !list_empty(&pring->txq))
10454 lpfc_worker_wake_up(phba);
10458 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
10459 lxri = lpfc_sli4_xri_inrange(phba, xri);
10460 if (lxri == NO_XRI)
10463 spin_lock_irqsave(&phba->hbalock, iflag);
10464 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10465 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10466 spin_unlock_irqrestore(&phba->hbalock, iflag);
10469 sglq_entry->state = SGL_XRI_ABORTED;
10470 spin_unlock_irqrestore(&phba->hbalock, iflag);
10474 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10475 * @vport: pointer to virtual port object.
10476 * @ndlp: nodelist pointer for the impacted node.
10478 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10479 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10480 * the driver is required to send a LOGO to the remote node before it
10481 * attempts to recover its login to the remote node.
10484 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10485 struct lpfc_nodelist *ndlp)
10487 struct Scsi_Host *shost;
10488 struct lpfc_hba *phba;
10489 unsigned long flags = 0;
10491 shost = lpfc_shost_from_vport(vport);
10492 phba = vport->phba;
10493 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10494 lpfc_printf_log(phba, KERN_INFO,
10495 LOG_SLI, "3093 No rport recovery needed. "
10496 "rport in state 0x%x\n", ndlp->nlp_state);
10499 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10500 "3094 Start rport recovery on shost id 0x%x "
10501 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10503 shost->host_no, ndlp->nlp_DID,
10504 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10507 * The rport is not responding. Remove the FCP-2 flag to prevent
10508 * an ADISC in the follow-up recovery code.
10510 spin_lock_irqsave(&ndlp->lock, flags);
10511 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10512 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10513 spin_unlock_irqrestore(&ndlp->lock, flags);
10514 lpfc_unreg_rpi(vport, ndlp);
10517 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport)
10519 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE);
10523 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max)
10527 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE))
10530 for (i = min; i <= max; i++)
10531 set_bit(i, vport->vmid_priority_range);
10534 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid)
10536 set_bit(ctcl_vmid, vport->vmid_priority_range);
10539 u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport)
10543 i = find_first_bit(vport->vmid_priority_range,
10544 LPFC_VMID_MAX_PRIORITY_RANGE);
10546 if (i == LPFC_VMID_MAX_PRIORITY_RANGE)
10549 clear_bit(i, vport->vmid_priority_range);
10553 #define MAX_PRIORITY_DESC 255
10556 lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10557 struct lpfc_iocbq *rspiocb)
10559 struct lpfc_vport *vport = cmdiocb->vport;
10560 struct priority_range_desc *desc;
10561 struct lpfc_dmabuf *prsp = NULL;
10562 struct lpfc_vmid_priority_range *vmid_range = NULL;
10564 struct lpfc_dmabuf *dmabuf = cmdiocb->context2;
10565 IOCB_t *irsp = &rspiocb->iocb;
10566 u8 *pcmd, max_desc;
10568 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
10570 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
10575 data = (u32 *)pcmd;
10576 if (data[0] == ELS_CMD_LS_RJT) {
10577 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
10578 "3277 QFPA LS_RJT x%x x%x\n",
10582 if (irsp->ulpStatus) {
10583 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
10584 "6529 QFPA failed with status x%x x%x\n",
10585 irsp->ulpStatus, irsp->un.ulpWord[4]);
10589 if (!vport->qfpa_res) {
10590 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res);
10591 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res),
10593 if (!vport->qfpa_res)
10597 len = *((u32 *)(pcmd + 4));
10598 len = be32_to_cpu(len);
10599 memcpy(vport->qfpa_res, pcmd, len + 8);
10600 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE;
10602 desc = (struct priority_range_desc *)(pcmd + 8);
10603 vmid_range = vport->vmid_priority.vmid_range;
10605 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range),
10608 kfree(vport->qfpa_res);
10611 vport->vmid_priority.vmid_range = vmid_range;
10613 vport->vmid_priority.num_descriptors = len;
10615 for (i = 0; i < len; i++, vmid_range++, desc++) {
10616 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
10617 "6539 vmid values low=%d, high=%d, qos=%d, "
10618 "local ve id=%d\n", desc->lo_range,
10619 desc->hi_range, desc->qos_priority,
10620 desc->local_ve_id);
10622 vmid_range->low = desc->lo_range << 1;
10623 if (desc->local_ve_id == QFPA_ODD_ONLY)
10625 if (desc->qos_priority)
10626 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED;
10627 vmid_range->qos = desc->qos_priority;
10629 vmid_range->high = desc->hi_range << 1;
10630 if ((desc->local_ve_id == QFPA_ODD_ONLY) ||
10631 (desc->local_ve_id == QFPA_EVEN_ODD))
10632 vmid_range->high++;
10634 lpfc_init_cs_ctl_bitmap(vport);
10635 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) {
10636 lpfc_vmid_set_cs_ctl_range(vport,
10637 vport->vmid_priority.vmid_range[i].low,
10638 vport->vmid_priority.vmid_range[i].high);
10641 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL;
10643 lpfc_els_free_iocb(phba, cmdiocb);
10644 lpfc_nlp_put(ndlp);
10647 int lpfc_issue_els_qfpa(struct lpfc_vport *vport)
10649 struct lpfc_hba *phba = vport->phba;
10650 struct lpfc_nodelist *ndlp;
10651 struct lpfc_iocbq *elsiocb;
10655 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
10656 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
10659 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp,
10660 ndlp->nlp_DID, ELS_CMD_QFPA);
10664 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
10666 *((u32 *)(pcmd)) = ELS_CMD_QFPA;
10669 elsiocb->iocb_cmpl = lpfc_cmpl_els_qfpa;
10671 elsiocb->context1 = lpfc_nlp_get(ndlp);
10672 if (!elsiocb->context1) {
10673 lpfc_els_free_iocb(vport->phba, elsiocb);
10677 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2);
10678 if (ret != IOCB_SUCCESS) {
10679 lpfc_els_free_iocb(phba, elsiocb);
10680 lpfc_nlp_put(ndlp);
10683 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED;
10688 lpfc_vmid_uvem(struct lpfc_vport *vport,
10689 struct lpfc_vmid *vmid, bool instantiated)
10691 struct lpfc_vem_id_desc *vem_id_desc;
10692 struct lpfc_nodelist *ndlp;
10693 struct lpfc_iocbq *elsiocb;
10694 struct instantiated_ve_desc *inst_desc;
10695 struct lpfc_vmid_context *vmid_context;
10700 ndlp = lpfc_findnode_did(vport, Fabric_DID);
10701 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
10704 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL);
10707 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2,
10708 ndlp, Fabric_DID, ELS_CMD_UVEM);
10712 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
10713 "3427 Host vmid %s %d\n",
10714 vmid->host_vmid, instantiated);
10715 vmid_context->vmp = vmid;
10716 vmid_context->nlp = ndlp;
10717 vmid_context->instantiated = instantiated;
10718 elsiocb->vmid_tag.vmid_context = vmid_context;
10719 pcmd = (u8 *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
10721 if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid))
10722 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid,
10723 LPFC_COMPRESS_VMID_SIZE);
10725 *((u32 *)(pcmd)) = ELS_CMD_UVEM;
10726 len = (u32 *)(pcmd + 4);
10727 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8);
10729 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8);
10730 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG);
10731 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE);
10732 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid,
10733 LPFC_COMPRESS_VMID_SIZE);
10735 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32);
10736 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
10737 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE);
10738 memcpy(inst_desc->global_vem_id, vmid->host_vmid,
10739 LPFC_COMPRESS_VMID_SIZE);
10741 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID);
10742 bf_set(lpfc_instantiated_local_id, inst_desc,
10743 vmid->un.cs_ctl_vmid);
10744 if (instantiated) {
10745 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
10747 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG);
10748 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid);
10750 inst_desc->word6 = cpu_to_be32(inst_desc->word6);
10752 elsiocb->iocb_cmpl = lpfc_cmpl_els_uvem;
10754 elsiocb->context1 = lpfc_nlp_get(ndlp);
10755 if (!elsiocb->context1) {
10756 lpfc_els_free_iocb(vport->phba, elsiocb);
10760 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0);
10761 if (ret != IOCB_SUCCESS) {
10762 lpfc_els_free_iocb(vport->phba, elsiocb);
10763 lpfc_nlp_put(ndlp);
10769 kfree(vmid_context);
10774 lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb,
10775 struct lpfc_iocbq *rspiocb)
10777 struct lpfc_vport *vport = icmdiocb->vport;
10778 struct lpfc_dmabuf *prsp = NULL;
10779 struct lpfc_vmid_context *vmid_context =
10780 icmdiocb->vmid_tag.vmid_context;
10781 struct lpfc_nodelist *ndlp = icmdiocb->context1;
10784 IOCB_t *irsp = &rspiocb->iocb;
10785 struct lpfc_dmabuf *dmabuf = icmdiocb->context2;
10786 struct lpfc_vmid *vmid;
10788 vmid = vmid_context->vmp;
10789 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
10792 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
10796 data = (u32 *)pcmd;
10797 if (data[0] == ELS_CMD_LS_RJT) {
10798 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
10799 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]);
10802 if (irsp->ulpStatus) {
10803 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
10804 "4533 UVEM error status %x: %x\n",
10805 irsp->ulpStatus, irsp->un.ulpWord[4]);
10808 spin_lock(&phba->hbalock);
10809 /* Set IN USE flag */
10810 vport->vmid_flag |= LPFC_VMID_IN_USE;
10811 phba->pport->vmid_flag |= LPFC_VMID_IN_USE;
10812 spin_unlock(&phba->hbalock);
10814 if (vmid_context->instantiated) {
10815 write_lock(&vport->vmid_lock);
10816 vmid->flag |= LPFC_VMID_REGISTERED;
10817 vmid->flag &= ~LPFC_VMID_REQ_REGISTER;
10818 write_unlock(&vport->vmid_lock);
10822 kfree(vmid_context);
10823 lpfc_els_free_iocb(phba, icmdiocb);
10824 lpfc_nlp_put(ndlp);