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>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <uapi/scsi/fc/fc_fs.h>
34 #include <uapi/scsi/fc/fc_els.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_debugfs.h"
49 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
51 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
53 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
54 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp, uint8_t retry);
56 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
57 struct lpfc_iocbq *iocb);
59 static int lpfc_max_els_tries = 3;
62 * lpfc_els_chk_latt - Check host link attention event for a vport
63 * @vport: pointer to a host virtual N_Port data structure.
65 * This routine checks whether there is an outstanding host link
66 * attention event during the discovery process with the @vport. It is done
67 * by reading the HBA's Host Attention (HA) register. If there is any host
68 * link attention events during this @vport's discovery process, the @vport
69 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
70 * be issued if the link state is not already in host link cleared state,
71 * and a return code shall indicate whether the host link attention event
74 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
75 * state in LPFC_VPORT_READY, the request for checking host link attention
76 * event will be ignored and a return code shall indicate no host link
77 * attention event had happened.
80 * 0 - no host link attention event happened
81 * 1 - host link attention event happened
84 lpfc_els_chk_latt(struct lpfc_vport *vport)
86 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
87 struct lpfc_hba *phba = vport->phba;
90 if (vport->port_state >= LPFC_VPORT_READY ||
91 phba->link_state == LPFC_LINK_DOWN ||
92 phba->sli_rev > LPFC_SLI_REV3)
95 /* Read the HBA Host Attention Register */
96 if (lpfc_readl(phba->HAregaddr, &ha_copy))
99 if (!(ha_copy & HA_LATT))
102 /* Pending Link Event during Discovery */
103 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
104 "0237 Pending Link Event during "
105 "Discovery: State x%x\n",
106 phba->pport->port_state);
108 /* CLEAR_LA should re-enable link attention events and
109 * we should then immediately take a LATT event. The
110 * LATT processing should call lpfc_linkdown() which
111 * will cleanup any left over in-progress discovery
114 spin_lock_irq(shost->host_lock);
115 vport->fc_flag |= FC_ABORT_DISCOVERY;
116 spin_unlock_irq(shost->host_lock);
118 if (phba->link_state != LPFC_CLEAR_LA)
119 lpfc_issue_clear_la(phba, vport);
125 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
126 * @vport: pointer to a host virtual N_Port data structure.
127 * @expectRsp: flag indicating whether response is expected.
128 * @cmdSize: size of the ELS command.
129 * @retry: number of retries to the command IOCB when it fails.
130 * @ndlp: pointer to a node-list data structure.
131 * @did: destination identifier.
132 * @elscmd: the ELS command code.
134 * This routine is used for allocating a lpfc-IOCB data structure from
135 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
136 * passed into the routine for discovery state machine to issue an Extended
137 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
138 * and preparation routine that is used by all the discovery state machine
139 * routines and the ELS command-specific fields will be later set up by
140 * the individual discovery machine routines after calling this routine
141 * allocating and preparing a generic IOCB data structure. It fills in the
142 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
143 * payload and response payload (if expected). The reference count on the
144 * ndlp is incremented by 1 and the reference to the ndlp is put into
145 * context1 of the IOCB data structure for this IOCB to hold the ndlp
146 * reference for the command's callback function to access later.
149 * Pointer to the newly allocated/prepared els iocb data structure
150 * NULL - when els iocb data structure allocation/preparation failed
153 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
154 uint16_t cmdSize, uint8_t retry,
155 struct lpfc_nodelist *ndlp, uint32_t did,
158 struct lpfc_hba *phba = vport->phba;
159 struct lpfc_iocbq *elsiocb;
160 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
161 struct ulp_bde64 *bpl;
165 if (!lpfc_is_link_up(phba))
168 /* Allocate buffer for command iocb */
169 elsiocb = lpfc_sli_get_iocbq(phba);
175 * If this command is for fabric controller and HBA running
176 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
178 if ((did == Fabric_DID) &&
179 (phba->hba_flag & HBA_FIP_SUPPORT) &&
180 ((elscmd == ELS_CMD_FLOGI) ||
181 (elscmd == ELS_CMD_FDISC) ||
182 (elscmd == ELS_CMD_LOGO)))
185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
187 & LPFC_FIP_ELS_ID_MASK);
190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
192 & LPFC_FIP_ELS_ID_MASK);
195 elsiocb->iocb_flag |=
196 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
197 & LPFC_FIP_ELS_ID_MASK);
201 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
203 icmd = &elsiocb->iocb;
205 /* fill in BDEs for command */
206 /* Allocate buffer for command payload */
207 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
209 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
210 if (!pcmd || !pcmd->virt)
211 goto els_iocb_free_pcmb_exit;
213 INIT_LIST_HEAD(&pcmd->list);
215 /* Allocate buffer for response payload */
217 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
219 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
221 if (!prsp || !prsp->virt)
222 goto els_iocb_free_prsp_exit;
223 INIT_LIST_HEAD(&prsp->list);
227 /* Allocate buffer for Buffer ptr list */
228 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
230 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
232 if (!pbuflist || !pbuflist->virt)
233 goto els_iocb_free_pbuf_exit;
235 INIT_LIST_HEAD(&pbuflist->list);
238 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
239 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
240 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
241 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
243 icmd->un.elsreq64.remoteID = did; /* DID */
244 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
245 if (elscmd == ELS_CMD_FLOGI)
246 icmd->ulpTimeout = FF_DEF_RATOV * 2;
247 else if (elscmd == ELS_CMD_LOGO)
248 icmd->ulpTimeout = phba->fc_ratov;
250 icmd->ulpTimeout = phba->fc_ratov * 2;
252 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
253 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
254 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
255 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
256 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
257 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
259 icmd->ulpBdeCount = 1;
261 icmd->ulpClass = CLASS3;
264 * If we have NPIV enabled, we want to send ELS traffic by VPI.
265 * For SLI4, since the driver controls VPIs we also want to include
266 * all ELS pt2pt protocol traffic as well.
268 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
269 ((phba->sli_rev == LPFC_SLI_REV4) &&
270 (vport->fc_flag & FC_PT2PT))) {
273 icmd->un.elsreq64.myID = vport->fc_myDID;
275 /* For ELS_REQUEST64_CR, use the VPI by default */
276 icmd->ulpContext = phba->vpi_ids[vport->vpi];
280 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
281 if (elscmd == ELS_CMD_ECHO)
282 icmd->ulpCt_l = 0; /* context = invalid RPI */
284 icmd->ulpCt_l = 1; /* context = VPI */
287 bpl = (struct ulp_bde64 *) pbuflist->virt;
288 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
289 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
290 bpl->tus.f.bdeSize = cmdSize;
291 bpl->tus.f.bdeFlags = 0;
292 bpl->tus.w = le32_to_cpu(bpl->tus.w);
296 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
297 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
298 bpl->tus.f.bdeSize = FCELSSIZE;
299 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
300 bpl->tus.w = le32_to_cpu(bpl->tus.w);
303 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
305 elsiocb->retry = retry;
306 elsiocb->vport = vport;
307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
310 list_add(&prsp->list, &pcmd->list);
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
316 "NPORT x%x I/O tag: x%x, port state:x%x "
317 "rpi x%x fc_flag:x%x\n",
318 elscmd, did, elsiocb->iotag,
319 vport->port_state, ndlp->nlp_rpi,
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
325 "NPORT x%x I/O tag: x%x, size: x%x "
326 "port_state x%x rpi x%x fc_flag x%x\n",
327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
328 cmdSize, vport->port_state,
329 ndlp->nlp_rpi, vport->fc_flag);
333 els_iocb_free_pbuf_exit:
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
338 els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
342 els_iocb_free_pcmb_exit:
344 lpfc_sli_release_iocbq(phba, elsiocb);
349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
350 * @vport: pointer to a host virtual N_Port data structure.
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
365 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
367 struct lpfc_hba *phba = vport->phba;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
394 if (rc == MBX_NOT_FINISHED) {
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
416 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
417 if (!mbox->ctx_ndlp) {
422 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
423 if (rc == MBX_NOT_FINISHED) {
425 goto fail_issue_reg_login;
430 fail_issue_reg_login:
431 /* decrement the reference count on ndlp just incremented
432 * for the failed mbox command.
436 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
437 lpfc_mbuf_free(phba, mp->virt, mp->phys);
440 mempool_free(mbox, phba->mbox_mem_pool);
443 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
444 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
445 "0249 Cannot issue Register Fabric login: Err %d\n",
451 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
452 * @vport: pointer to a host virtual N_Port data structure.
454 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
455 * the @vport. This mailbox command is necessary for SLI4 port only.
458 * 0 - successfully issued REG_VFI for @vport
459 * A failure code otherwise.
462 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
464 struct lpfc_hba *phba = vport->phba;
465 LPFC_MBOXQ_t *mboxq = NULL;
466 struct lpfc_nodelist *ndlp;
467 struct lpfc_dmabuf *dmabuf = NULL;
470 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
471 if ((phba->sli_rev == LPFC_SLI_REV4) &&
472 !(phba->link_flag & LS_LOOPBACK_MODE) &&
473 !(vport->fc_flag & FC_PT2PT)) {
474 ndlp = lpfc_findnode_did(vport, Fabric_DID);
481 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
487 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
488 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
489 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
494 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
499 memcpy(dmabuf->virt, &phba->fc_fabparam,
500 sizeof(struct serv_parm));
503 vport->port_state = LPFC_FABRIC_CFG_LINK;
505 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
507 lpfc_reg_vfi(mboxq, vport, 0);
509 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
510 mboxq->vport = vport;
511 mboxq->ctx_buf = dmabuf;
512 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
513 if (rc == MBX_NOT_FINISHED) {
521 mempool_free(mboxq, phba->mbox_mem_pool);
524 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
528 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
529 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
530 "0289 Issue Register VFI failed: Err %d\n", rc);
535 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
536 * @vport: pointer to a host virtual N_Port data structure.
538 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
539 * the @vport. This mailbox command is necessary for SLI4 port only.
542 * 0 - successfully issued REG_VFI for @vport
543 * A failure code otherwise.
546 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
548 struct lpfc_hba *phba = vport->phba;
549 struct Scsi_Host *shost;
553 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
555 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
556 "2556 UNREG_VFI mbox allocation failed"
557 "HBA state x%x\n", phba->pport->port_state);
561 lpfc_unreg_vfi(mboxq, vport);
562 mboxq->vport = vport;
563 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
565 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
566 if (rc == MBX_NOT_FINISHED) {
567 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
568 "2557 UNREG_VFI issue mbox failed rc x%x "
570 rc, phba->pport->port_state);
571 mempool_free(mboxq, phba->mbox_mem_pool);
575 shost = lpfc_shost_from_vport(vport);
576 spin_lock_irq(shost->host_lock);
577 vport->fc_flag &= ~FC_VFI_REGISTERED;
578 spin_unlock_irq(shost->host_lock);
583 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
584 * @vport: pointer to a host virtual N_Port data structure.
585 * @sp: pointer to service parameter data structure.
587 * This routine is called from FLOGI/FDISC completion handler functions.
588 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter else return
590 * 0. This function also set flag in the vport data structure to delay
591 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
592 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
593 * node nodename is changed in the completion service parameter.
596 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
597 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
601 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
602 struct serv_parm *sp)
604 struct lpfc_hba *phba = vport->phba;
605 uint8_t fabric_param_changed = 0;
606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
608 if ((vport->fc_prevDID != vport->fc_myDID) ||
609 memcmp(&vport->fabric_portname, &sp->portName,
610 sizeof(struct lpfc_name)) ||
611 memcmp(&vport->fabric_nodename, &sp->nodeName,
612 sizeof(struct lpfc_name)) ||
613 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
614 fabric_param_changed = 1;
615 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
618 * Word 1 Bit 31 in common service parameter is overloaded.
619 * Word 1 Bit 31 in FLOGI request is multiple NPort request
620 * Word 1 Bit 31 in FLOGI response is clean address bit
622 * If fabric parameter is changed and clean address bit is
623 * cleared delay nport discovery if
624 * - vport->fc_prevDID != 0 (not initial discovery) OR
625 * - lpfc_delay_discovery module parameter is set.
627 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
628 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
629 spin_lock_irq(shost->host_lock);
630 vport->fc_flag |= FC_DISC_DELAYED;
631 spin_unlock_irq(shost->host_lock);
634 return fabric_param_changed;
639 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
640 * @vport: pointer to a host virtual N_Port data structure.
641 * @ndlp: pointer to a node-list data structure.
642 * @sp: pointer to service parameter data structure.
643 * @irsp: pointer to the IOCB within the lpfc response IOCB.
645 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
646 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
647 * port in a fabric topology. It properly sets up the parameters to the @ndlp
648 * from the IOCB response. It also check the newly assigned N_Port ID to the
649 * @vport against the previously assigned N_Port ID. If it is different from
650 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
651 * is invoked on all the remaining nodes with the @vport to unregister the
652 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
653 * is invoked to register login to the fabric.
656 * 0 - Success (currently, always return 0)
659 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
660 struct serv_parm *sp, IOCB_t *irsp)
662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
663 struct lpfc_hba *phba = vport->phba;
664 struct lpfc_nodelist *np;
665 struct lpfc_nodelist *next_np;
666 uint8_t fabric_param_changed;
668 spin_lock_irq(shost->host_lock);
669 vport->fc_flag |= FC_FABRIC;
670 spin_unlock_irq(shost->host_lock);
672 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
673 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
674 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
676 phba->fc_edtovResol = sp->cmn.edtovResolution;
677 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
679 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
680 spin_lock_irq(shost->host_lock);
681 vport->fc_flag |= FC_PUBLIC_LOOP;
682 spin_unlock_irq(shost->host_lock);
685 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
686 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
687 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
688 ndlp->nlp_class_sup = 0;
689 if (sp->cls1.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS1;
691 if (sp->cls2.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS2;
693 if (sp->cls3.classValid)
694 ndlp->nlp_class_sup |= FC_COS_CLASS3;
695 if (sp->cls4.classValid)
696 ndlp->nlp_class_sup |= FC_COS_CLASS4;
697 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
698 sp->cmn.bbRcvSizeLsb;
700 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
701 if (fabric_param_changed) {
702 /* Reset FDMI attribute masks based on config parameter */
703 if (phba->cfg_enable_SmartSAN ||
704 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
705 /* Setup appropriate attribute masks */
706 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
707 if (phba->cfg_enable_SmartSAN)
708 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
710 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
712 vport->fdmi_hba_mask = 0;
713 vport->fdmi_port_mask = 0;
717 memcpy(&vport->fabric_portname, &sp->portName,
718 sizeof(struct lpfc_name));
719 memcpy(&vport->fabric_nodename, &sp->nodeName,
720 sizeof(struct lpfc_name));
721 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
723 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
724 if (sp->cmn.response_multiple_NPort) {
725 lpfc_printf_vlog(vport, KERN_WARNING,
727 "1816 FLOGI NPIV supported, "
728 "response data 0x%x\n",
729 sp->cmn.response_multiple_NPort);
730 spin_lock_irq(&phba->hbalock);
731 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
732 spin_unlock_irq(&phba->hbalock);
734 /* Because we asked f/w for NPIV it still expects us
735 to call reg_vnpid at least for the physical host */
736 lpfc_printf_vlog(vport, KERN_WARNING,
738 "1817 Fabric does not support NPIV "
739 "- configuring single port mode.\n");
740 spin_lock_irq(&phba->hbalock);
741 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
742 spin_unlock_irq(&phba->hbalock);
747 * For FC we need to do some special processing because of the SLI
748 * Port's default settings of the Common Service Parameters.
750 if ((phba->sli_rev == LPFC_SLI_REV4) &&
751 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
752 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
753 if (fabric_param_changed)
754 lpfc_unregister_fcf_prep(phba);
756 /* This should just update the VFI CSPs*/
757 if (vport->fc_flag & FC_VFI_REGISTERED)
758 lpfc_issue_reg_vfi(vport);
761 if (fabric_param_changed &&
762 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
764 /* If our NportID changed, we need to ensure all
765 * remaining NPORTs get unreg_login'ed.
767 list_for_each_entry_safe(np, next_np,
768 &vport->fc_nodes, nlp_listp) {
769 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
770 !(np->nlp_flag & NLP_NPR_ADISC))
772 spin_lock_irq(&np->lock);
773 np->nlp_flag &= ~NLP_NPR_ADISC;
774 spin_unlock_irq(&np->lock);
775 lpfc_unreg_rpi(vport, np);
777 lpfc_cleanup_pending_mbox(vport);
779 if (phba->sli_rev == LPFC_SLI_REV4) {
780 lpfc_sli4_unreg_all_rpis(vport);
781 lpfc_mbx_unreg_vpi(vport);
782 spin_lock_irq(shost->host_lock);
783 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
784 spin_unlock_irq(shost->host_lock);
788 * For SLI3 and SLI4, the VPI needs to be reregistered in
789 * response to this fabric parameter change event.
791 spin_lock_irq(shost->host_lock);
792 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
793 spin_unlock_irq(shost->host_lock);
794 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
795 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
797 * Driver needs to re-reg VPI in order for f/w
798 * to update the MAC address.
800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
801 lpfc_register_new_vport(phba, vport, ndlp);
805 if (phba->sli_rev < LPFC_SLI_REV4) {
806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
807 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
808 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
809 lpfc_register_new_vport(phba, vport, ndlp);
811 lpfc_issue_fabric_reglogin(vport);
813 ndlp->nlp_type |= NLP_FABRIC;
814 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
815 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
816 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
817 lpfc_start_fdiscs(phba);
818 lpfc_do_scr_ns_plogi(phba, vport);
819 } else if (vport->fc_flag & FC_VFI_REGISTERED)
820 lpfc_issue_init_vpi(vport);
822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
823 "3135 Need register VFI: (x%x/%x)\n",
824 vport->fc_prevDID, vport->fc_myDID);
825 lpfc_issue_reg_vfi(vport);
832 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
833 * @vport: pointer to a host virtual N_Port data structure.
834 * @ndlp: pointer to a node-list data structure.
835 * @sp: pointer to service parameter data structure.
837 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
838 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
839 * in a point-to-point topology. First, the @vport's N_Port Name is compared
840 * with the received N_Port Name: if the @vport's N_Port Name is greater than
841 * the received N_Port Name lexicographically, this node shall assign local
842 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
843 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
844 * this node shall just wait for the remote node to issue PLOGI and assign
852 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 struct serv_parm *sp)
855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
856 struct lpfc_hba *phba = vport->phba;
860 spin_lock_irq(shost->host_lock);
861 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
862 vport->fc_flag |= FC_PT2PT;
863 spin_unlock_irq(shost->host_lock);
865 /* If we are pt2pt with another NPort, force NPIV off! */
866 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
868 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
869 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
870 lpfc_unregister_fcf_prep(phba);
872 spin_lock_irq(shost->host_lock);
873 vport->fc_flag &= ~FC_VFI_REGISTERED;
874 spin_unlock_irq(shost->host_lock);
875 phba->fc_topology_changed = 0;
878 rc = memcmp(&vport->fc_portname, &sp->portName,
879 sizeof(vport->fc_portname));
882 /* This side will initiate the PLOGI */
883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag |= FC_PT2PT_PLOGI;
885 spin_unlock_irq(shost->host_lock);
888 * N_Port ID cannot be 0, set our Id to LocalID
889 * the other side will be RemoteID.
894 vport->fc_myDID = PT2PT_LocalID;
896 /* Decrement ndlp reference count indicating that ndlp can be
897 * safely released when other references to it are done.
901 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
904 * Cannot find existing Fabric ndlp, so allocate a
907 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
912 memcpy(&ndlp->nlp_portname, &sp->portName,
913 sizeof(struct lpfc_name));
914 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
915 sizeof(struct lpfc_name));
916 /* Set state will put ndlp onto node list if not already done */
917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
918 spin_lock_irq(&ndlp->lock);
919 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
920 spin_unlock_irq(&ndlp->lock);
922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
926 lpfc_config_link(phba, mbox);
928 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
930 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
931 if (rc == MBX_NOT_FINISHED) {
932 mempool_free(mbox, phba->mbox_mem_pool);
936 /* This side will wait for the PLOGI, decrement ndlp reference
937 * count indicating that ndlp can be released when other
938 * references to it are done.
942 /* Start discovery - this should just do CLEAR_LA */
943 lpfc_disc_start(vport);
952 * lpfc_cmpl_els_flogi - Completion callback function for flogi
953 * @phba: pointer to lpfc hba data structure.
954 * @cmdiocb: pointer to lpfc command iocb data structure.
955 * @rspiocb: pointer to lpfc response iocb data structure.
957 * This routine is the top-level completion callback function for issuing
958 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
959 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
960 * retry has been made (either immediately or delayed with lpfc_els_retry()
961 * returning 1), the command IOCB will be released and function returned.
962 * If the retry attempt has been given up (possibly reach the maximum
963 * number of retries), one additional decrement of ndlp reference shall be
964 * invoked before going out after releasing the command IOCB. This will
965 * actually release the remote node (Note, lpfc_els_free_iocb() will also
966 * invoke one decrement of ndlp reference count). If no error reported in
967 * the IOCB status, the command Port ID field is used to determine whether
968 * this is a point-to-point topology or a fabric topology: if the Port ID
969 * field is assigned, it is a fabric topology; otherwise, it is a
970 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
971 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
972 * specific topology completion conditions.
975 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
976 struct lpfc_iocbq *rspiocb)
978 struct lpfc_vport *vport = cmdiocb->vport;
979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
980 IOCB_t *irsp = &rspiocb->iocb;
981 struct lpfc_nodelist *ndlp = cmdiocb->context1;
982 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
983 struct serv_parm *sp;
987 /* Check to see if link went down during discovery */
988 if (lpfc_els_chk_latt(vport)) {
989 /* One additional decrement on node reference count to
990 * trigger the release of the node
996 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
997 "FLOGI cmpl: status:x%x/x%x state:x%x",
998 irsp->ulpStatus, irsp->un.ulpWord[4],
1001 if (irsp->ulpStatus) {
1003 * In case of FIP mode, perform roundrobin FCF failover
1004 * due to new FCF discovery
1006 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1007 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1008 if (phba->link_state < LPFC_LINK_UP)
1009 goto stop_rr_fcf_flogi;
1010 if ((phba->fcoe_cvl_eventtag_attn ==
1011 phba->fcoe_cvl_eventtag) &&
1012 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1013 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1015 goto stop_rr_fcf_flogi;
1017 phba->fcoe_cvl_eventtag_attn =
1018 phba->fcoe_cvl_eventtag;
1019 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1020 "2611 FLOGI failed on FCF (x%x), "
1021 "status:x%x/x%x, tmo:x%x, perform "
1022 "roundrobin FCF failover\n",
1023 phba->fcf.current_rec.fcf_indx,
1024 irsp->ulpStatus, irsp->un.ulpWord[4],
1026 lpfc_sli4_set_fcf_flogi_fail(phba,
1027 phba->fcf.current_rec.fcf_indx);
1028 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1029 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1036 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1037 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1038 IOERR_LOOP_OPEN_FAILURE)))
1039 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1040 "2858 FLOGI failure Status:x%x/x%x TMO"
1041 ":x%x Data x%x x%x\n",
1042 irsp->ulpStatus, irsp->un.ulpWord[4],
1043 irsp->ulpTimeout, phba->hba_flag,
1044 phba->fcf.fcf_flag);
1046 /* Check for retry */
1047 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1050 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1051 "0150 FLOGI failure Status:x%x/x%x "
1052 "xri x%x TMO:x%x\n",
1053 irsp->ulpStatus, irsp->un.ulpWord[4],
1054 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1056 /* If this is not a loop open failure, bail out */
1057 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1058 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1059 IOERR_LOOP_OPEN_FAILURE)))
1062 /* FLOGI failed, so there is no fabric */
1063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1065 spin_unlock_irq(shost->host_lock);
1067 /* If private loop, then allow max outstanding els to be
1068 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1069 * alpa map would take too long otherwise.
1071 if (phba->alpa_map[0] == 0)
1072 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1073 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1074 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1075 (vport->fc_prevDID != vport->fc_myDID) ||
1076 phba->fc_topology_changed)) {
1077 if (vport->fc_flag & FC_VFI_REGISTERED) {
1078 if (phba->fc_topology_changed) {
1079 lpfc_unregister_fcf_prep(phba);
1080 spin_lock_irq(shost->host_lock);
1081 vport->fc_flag &= ~FC_VFI_REGISTERED;
1082 spin_unlock_irq(shost->host_lock);
1083 phba->fc_topology_changed = 0;
1085 lpfc_sli4_unreg_all_rpis(vport);
1089 /* Do not register VFI if the driver aborted FLOGI */
1090 if (!lpfc_error_lost_link(irsp))
1091 lpfc_issue_reg_vfi(vport);
1098 spin_lock_irq(shost->host_lock);
1099 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1100 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1101 spin_unlock_irq(shost->host_lock);
1104 * The FLogI succeeded. Sync the data for the CPU before
1107 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1110 sp = prsp->virt + sizeof(uint32_t);
1112 /* FLOGI completes successfully */
1113 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1114 "0101 FLOGI completes successfully, I/O tag:x%x, "
1115 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1116 cmdiocb->iotag, cmdiocb->sli4_xritag,
1117 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1118 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1119 vport->port_state, vport->fc_flag);
1121 if (vport->port_state == LPFC_FLOGI) {
1123 * If Common Service Parameters indicate Nport
1124 * we are point to point, if Fport we are Fabric.
1127 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1128 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1129 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1131 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1132 "2831 FLOGI response with cleared Fabric "
1133 "bit fcf_index 0x%x "
1134 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1136 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1137 phba->fcf.current_rec.fcf_indx,
1138 phba->fcf.current_rec.switch_name[0],
1139 phba->fcf.current_rec.switch_name[1],
1140 phba->fcf.current_rec.switch_name[2],
1141 phba->fcf.current_rec.switch_name[3],
1142 phba->fcf.current_rec.switch_name[4],
1143 phba->fcf.current_rec.switch_name[5],
1144 phba->fcf.current_rec.switch_name[6],
1145 phba->fcf.current_rec.switch_name[7],
1146 phba->fcf.current_rec.fabric_name[0],
1147 phba->fcf.current_rec.fabric_name[1],
1148 phba->fcf.current_rec.fabric_name[2],
1149 phba->fcf.current_rec.fabric_name[3],
1150 phba->fcf.current_rec.fabric_name[4],
1151 phba->fcf.current_rec.fabric_name[5],
1152 phba->fcf.current_rec.fabric_name[6],
1153 phba->fcf.current_rec.fabric_name[7]);
1156 spin_lock_irq(&phba->hbalock);
1157 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1158 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1159 spin_unlock_irq(&phba->hbalock);
1160 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1164 /* Mark the FCF discovery process done */
1165 if (phba->hba_flag & HBA_FIP_SUPPORT)
1166 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1168 "2769 FLOGI to FCF (x%x) "
1169 "completed successfully\n",
1170 phba->fcf.current_rec.fcf_indx);
1171 spin_lock_irq(&phba->hbalock);
1172 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1173 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1174 spin_unlock_irq(&phba->hbalock);
1175 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1181 spin_lock_irq(&phba->hbalock);
1182 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1183 spin_unlock_irq(&phba->hbalock);
1185 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
1187 if (!lpfc_error_lost_link(irsp)) {
1188 /* FLOGI failed, so just use loop map to make discovery list */
1189 lpfc_disc_list_loopmap(vport);
1191 /* Start discovery */
1192 lpfc_disc_start(vport);
1193 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1194 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1195 IOERR_SLI_ABORTED) &&
1196 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1197 IOERR_SLI_DOWN))) &&
1198 (phba->link_state != LPFC_CLEAR_LA)) {
1199 /* If FLOGI failed enable link interrupt. */
1200 lpfc_issue_clear_la(phba, vport);
1203 phba->hba_flag &= ~HBA_FLOGI_OUTSTANDING;
1204 lpfc_els_free_iocb(phba, cmdiocb);
1209 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1210 * aborted during a link down
1211 * @phba: pointer to lpfc hba data structure.
1212 * @cmdiocb: pointer to lpfc command iocb data structure.
1213 * @rspiocb: pointer to lpfc response iocb data structure.
1217 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1218 struct lpfc_iocbq *rspiocb)
1224 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1226 irsp = &rspiocb->iocb;
1228 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1229 "6445 ELS completes after LINK_DOWN: "
1230 " Status %x/%x cmd x%x flg x%x\n",
1231 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1232 cmdiocb->iocb_flag);
1234 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1235 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1236 atomic_dec(&phba->fabric_iocb_count);
1238 lpfc_els_free_iocb(phba, cmdiocb);
1242 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1243 * @vport: pointer to a host virtual N_Port data structure.
1244 * @ndlp: pointer to a node-list data structure.
1245 * @retry: number of retries to the command IOCB.
1247 * This routine issues a Fabric Login (FLOGI) Request ELS command
1248 * for a @vport. The initiator service parameters are put into the payload
1249 * of the FLOGI Request IOCB and the top-level callback function pointer
1250 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1251 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1252 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1254 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1255 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1256 * will be stored into the context1 field of the IOCB for the completion
1257 * callback function to the FLOGI ELS command.
1260 * 0 - successfully issued flogi iocb for @vport
1261 * 1 - failed to issue flogi iocb for @vport
1264 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1267 struct lpfc_hba *phba = vport->phba;
1268 struct serv_parm *sp;
1270 struct lpfc_iocbq *elsiocb;
1271 struct lpfc_iocbq defer_flogi_acc;
1277 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1278 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1279 ndlp->nlp_DID, ELS_CMD_FLOGI);
1284 icmd = &elsiocb->iocb;
1285 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1287 /* For FLOGI request, remainder of payload is service parameters */
1288 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1289 pcmd += sizeof(uint32_t);
1290 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1291 sp = (struct serv_parm *) pcmd;
1293 /* Setup CSPs accordingly for Fabric */
1294 sp->cmn.e_d_tov = 0;
1295 sp->cmn.w2.r_a_tov = 0;
1296 sp->cmn.virtual_fabric_support = 0;
1297 sp->cls1.classValid = 0;
1298 if (sp->cmn.fcphLow < FC_PH3)
1299 sp->cmn.fcphLow = FC_PH3;
1300 if (sp->cmn.fcphHigh < FC_PH3)
1301 sp->cmn.fcphHigh = FC_PH3;
1303 if (phba->sli_rev == LPFC_SLI_REV4) {
1304 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1305 LPFC_SLI_INTF_IF_TYPE_0) {
1306 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1307 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1308 /* FLOGI needs to be 3 for WQE FCFI */
1309 /* Set the fcfi to the fcfi we registered with */
1310 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1312 /* Can't do SLI4 class2 without support sequence coalescing */
1313 sp->cls2.classValid = 0;
1314 sp->cls2.seqDelivery = 0;
1316 /* Historical, setting sequential-delivery bit for SLI3 */
1317 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1318 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1319 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1320 sp->cmn.request_multiple_Nport = 1;
1321 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1325 sp->cmn.request_multiple_Nport = 0;
1328 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1329 icmd->un.elsreq64.myID = 0;
1330 icmd->un.elsreq64.fl = 1;
1333 tmo = phba->fc_ratov;
1334 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1335 lpfc_set_disctmo(vport);
1336 phba->fc_ratov = tmo;
1338 phba->fc_stat.elsXmitFLOGI++;
1339 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1341 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1342 "Issue FLOGI: opt:x%x",
1343 phba->sli3_options, 0, 0);
1345 elsiocb->context1 = lpfc_nlp_get(ndlp);
1346 if (!elsiocb->context1) {
1347 lpfc_els_free_iocb(phba, elsiocb);
1351 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1352 if (rc == IOCB_ERROR) {
1353 lpfc_els_free_iocb(phba, elsiocb);
1358 phba->hba_flag |= (HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
1360 /* Check for a deferred FLOGI ACC condition */
1361 if (phba->defer_flogi_acc_flag) {
1362 did = vport->fc_myDID;
1363 vport->fc_myDID = Fabric_DID;
1365 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1367 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1368 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1369 phba->defer_flogi_acc_ox_id;
1371 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1372 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1373 " ox_id: x%x, hba_flag x%x\n",
1374 phba->defer_flogi_acc_rx_id,
1375 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1377 /* Send deferred FLOGI ACC */
1378 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1381 phba->defer_flogi_acc_flag = false;
1383 vport->fc_myDID = did;
1390 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1391 * @phba: pointer to lpfc hba data structure.
1393 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1394 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1395 * list and issues an abort IOCB commond on each outstanding IOCB that
1396 * contains a active Fabric_DID ndlp. Note that this function is to issue
1397 * the abort IOCB command on all the outstanding IOCBs, thus when this
1398 * function returns, it does not guarantee all the IOCBs are actually aborted.
1401 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1404 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1406 struct lpfc_sli_ring *pring;
1407 struct lpfc_iocbq *iocb, *next_iocb;
1408 struct lpfc_nodelist *ndlp;
1411 /* Abort outstanding I/O on NPort <nlp_DID> */
1412 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1413 "0201 Abort outstanding I/O on NPort x%x\n",
1416 pring = lpfc_phba_elsring(phba);
1417 if (unlikely(!pring))
1421 * Check the txcmplq for an iocb that matches the nport the driver is
1424 spin_lock_irq(&phba->hbalock);
1425 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1427 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1428 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1429 if (ndlp && ndlp->nlp_DID == Fabric_DID) {
1430 if ((phba->pport->fc_flag & FC_PT2PT) &&
1431 !(phba->pport->fc_flag & FC_PT2PT_PLOGI))
1432 iocb->fabric_iocb_cmpl =
1433 lpfc_ignore_els_cmpl;
1434 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1439 /* Make sure HBA is alive */
1440 lpfc_issue_hb_tmo(phba);
1442 spin_unlock_irq(&phba->hbalock);
1448 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1449 * @vport: pointer to a host virtual N_Port data structure.
1451 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1452 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1453 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1454 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1455 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1456 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1460 * 0 - failed to issue initial flogi for @vport
1461 * 1 - successfully issued initial flogi for @vport
1464 lpfc_initial_flogi(struct lpfc_vport *vport)
1466 struct lpfc_nodelist *ndlp;
1468 vport->port_state = LPFC_FLOGI;
1469 lpfc_set_disctmo(vport);
1471 /* First look for the Fabric ndlp */
1472 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1474 /* Cannot find existing Fabric ndlp, so allocate a new one */
1475 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1478 /* Set the node type */
1479 ndlp->nlp_type |= NLP_FABRIC;
1481 /* Put ndlp onto node list */
1482 lpfc_enqueue_node(vport, ndlp);
1485 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1486 /* This decrement of reference count to node shall kick off
1487 * the release of the node.
1496 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1497 * @vport: pointer to a host virtual N_Port data structure.
1499 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1500 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1501 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1502 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1503 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1504 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1508 * 0 - failed to issue initial fdisc for @vport
1509 * 1 - successfully issued initial fdisc for @vport
1512 lpfc_initial_fdisc(struct lpfc_vport *vport)
1514 struct lpfc_nodelist *ndlp;
1516 /* First look for the Fabric ndlp */
1517 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1519 /* Cannot find existing Fabric ndlp, so allocate a new one */
1520 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1524 /* NPIV is only supported in Fabrics. */
1525 ndlp->nlp_type |= NLP_FABRIC;
1527 /* Put ndlp onto node list */
1528 lpfc_enqueue_node(vport, ndlp);
1531 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1532 /* decrement node reference count to trigger the release of
1542 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1543 * @vport: pointer to a host virtual N_Port data structure.
1545 * This routine checks whether there are more remaining Port Logins
1546 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1547 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1548 * to issue ELS PLOGIs up to the configured discover threads with the
1549 * @vport (@vport->cfg_discovery_threads). The function also decrement
1550 * the @vport's num_disc_node by 1 if it is not already 0.
1553 lpfc_more_plogi(struct lpfc_vport *vport)
1555 if (vport->num_disc_nodes)
1556 vport->num_disc_nodes--;
1558 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1559 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1560 "0232 Continue discovery with %d PLOGIs to go "
1561 "Data: x%x x%x x%x\n",
1562 vport->num_disc_nodes, vport->fc_plogi_cnt,
1563 vport->fc_flag, vport->port_state);
1564 /* Check to see if there are more PLOGIs to be sent */
1565 if (vport->fc_flag & FC_NLP_MORE)
1566 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1567 lpfc_els_disc_plogi(vport);
1573 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1574 * @phba: pointer to lpfc hba data structure.
1575 * @prsp: pointer to response IOCB payload.
1576 * @ndlp: pointer to a node-list data structure.
1578 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1579 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1580 * The following cases are considered N_Port confirmed:
1581 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1582 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1583 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1584 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1585 * 1) if there is a node on vport list other than the @ndlp with the same
1586 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1587 * on that node to release the RPI associated with the node; 2) if there is
1588 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1589 * into, a new node shall be allocated (or activated). In either case, the
1590 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1591 * be released and the new_ndlp shall be put on to the vport node list and
1592 * its pointer returned as the confirmed node.
1594 * Note that before the @ndlp got "released", the keepDID from not-matching
1595 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1596 * of the @ndlp. This is because the release of @ndlp is actually to put it
1597 * into an inactive state on the vport node list and the vport node list
1598 * management algorithm does not allow two node with a same DID.
1601 * pointer to the PLOGI N_Port @ndlp
1603 static struct lpfc_nodelist *
1604 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1605 struct lpfc_nodelist *ndlp)
1607 struct lpfc_vport *vport = ndlp->vport;
1608 struct lpfc_nodelist *new_ndlp;
1609 struct serv_parm *sp;
1610 uint8_t name[sizeof(struct lpfc_name)];
1611 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1612 uint32_t keep_new_nlp_flag = 0;
1613 uint16_t keep_nlp_state;
1614 u32 keep_nlp_fc4_type = 0;
1615 struct lpfc_nvme_rport *keep_nrport = NULL;
1616 unsigned long *active_rrqs_xri_bitmap = NULL;
1618 /* Fabric nodes can have the same WWPN so we don't bother searching
1619 * by WWPN. Just return the ndlp that was given to us.
1621 if (ndlp->nlp_type & NLP_FABRIC)
1624 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1625 memset(name, 0, sizeof(struct lpfc_name));
1627 /* Now we find out if the NPort we are logging into, matches the WWPN
1628 * we have for that ndlp. If not, we have some work to do.
1630 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1632 /* return immediately if the WWPN matches ndlp */
1633 if (new_ndlp == ndlp)
1636 if (phba->sli_rev == LPFC_SLI_REV4) {
1637 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1639 if (active_rrqs_xri_bitmap)
1640 memset(active_rrqs_xri_bitmap, 0,
1641 phba->cfg_rrq_xri_bitmap_sz);
1644 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1645 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1646 "new_ndlp x%x x%x x%x\n",
1647 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1648 (new_ndlp ? new_ndlp->nlp_DID : 0),
1649 (new_ndlp ? new_ndlp->nlp_flag : 0),
1650 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1653 rc = memcmp(&ndlp->nlp_portname, name,
1654 sizeof(struct lpfc_name));
1656 if (active_rrqs_xri_bitmap)
1657 mempool_free(active_rrqs_xri_bitmap,
1658 phba->active_rrq_pool);
1661 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1663 if (active_rrqs_xri_bitmap)
1664 mempool_free(active_rrqs_xri_bitmap,
1665 phba->active_rrq_pool);
1669 keepDID = new_ndlp->nlp_DID;
1670 if (phba->sli_rev == LPFC_SLI_REV4 &&
1671 active_rrqs_xri_bitmap)
1672 memcpy(active_rrqs_xri_bitmap,
1673 new_ndlp->active_rrqs_xri_bitmap,
1674 phba->cfg_rrq_xri_bitmap_sz);
1677 /* At this point in this routine, we know new_ndlp will be
1678 * returned. however, any previous GID_FTs that were done
1679 * would have updated nlp_fc4_type in ndlp, so we must ensure
1680 * new_ndlp has the right value.
1682 if (vport->fc_flag & FC_FABRIC) {
1683 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1684 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1687 lpfc_unreg_rpi(vport, new_ndlp);
1688 new_ndlp->nlp_DID = ndlp->nlp_DID;
1689 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1690 if (phba->sli_rev == LPFC_SLI_REV4)
1691 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1692 ndlp->active_rrqs_xri_bitmap,
1693 phba->cfg_rrq_xri_bitmap_sz);
1695 /* Lock both ndlps */
1696 spin_lock_irq(&ndlp->lock);
1697 spin_lock_irq(&new_ndlp->lock);
1698 keep_new_nlp_flag = new_ndlp->nlp_flag;
1699 keep_nlp_flag = ndlp->nlp_flag;
1700 new_ndlp->nlp_flag = ndlp->nlp_flag;
1702 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1703 if (keep_new_nlp_flag & NLP_UNREG_INP)
1704 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1706 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1708 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1709 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1710 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1712 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1714 ndlp->nlp_flag = keep_new_nlp_flag;
1716 /* if ndlp had NLP_UNREG_INP set, keep it */
1717 if (keep_nlp_flag & NLP_UNREG_INP)
1718 ndlp->nlp_flag |= NLP_UNREG_INP;
1720 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1722 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1723 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1724 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1726 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1728 spin_unlock_irq(&new_ndlp->lock);
1729 spin_unlock_irq(&ndlp->lock);
1731 /* Set nlp_states accordingly */
1732 keep_nlp_state = new_ndlp->nlp_state;
1733 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1735 /* interchange the nvme remoteport structs */
1736 keep_nrport = new_ndlp->nrport;
1737 new_ndlp->nrport = ndlp->nrport;
1739 /* Move this back to NPR state */
1740 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1741 /* The new_ndlp is replacing ndlp totally, so we need
1742 * to put ndlp on UNUSED list and try to free it.
1744 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1745 "3179 PLOGI confirm NEW: %x %x\n",
1746 new_ndlp->nlp_DID, keepDID);
1748 /* Two ndlps cannot have the same did on the nodelist.
1749 * Note: for this case, ndlp has a NULL WWPN so setting
1750 * the nlp_fc4_type isn't required.
1752 ndlp->nlp_DID = keepDID;
1753 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1754 if (phba->sli_rev == LPFC_SLI_REV4 &&
1755 active_rrqs_xri_bitmap)
1756 memcpy(ndlp->active_rrqs_xri_bitmap,
1757 active_rrqs_xri_bitmap,
1758 phba->cfg_rrq_xri_bitmap_sz);
1761 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1762 "3180 PLOGI confirm SWAP: %x %x\n",
1763 new_ndlp->nlp_DID, keepDID);
1765 lpfc_unreg_rpi(vport, ndlp);
1767 /* Two ndlps cannot have the same did and the fc4
1768 * type must be transferred because the ndlp is in
1771 ndlp->nlp_DID = keepDID;
1772 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1774 if (phba->sli_rev == LPFC_SLI_REV4 &&
1775 active_rrqs_xri_bitmap)
1776 memcpy(ndlp->active_rrqs_xri_bitmap,
1777 active_rrqs_xri_bitmap,
1778 phba->cfg_rrq_xri_bitmap_sz);
1780 /* Since we are switching over to the new_ndlp,
1781 * reset the old ndlp state
1783 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1784 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1785 keep_nlp_state = NLP_STE_NPR_NODE;
1786 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1787 ndlp->nrport = keep_nrport;
1791 * If ndlp is not associated with any rport we can drop it here else
1792 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1794 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1795 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1797 if (phba->sli_rev == LPFC_SLI_REV4 &&
1798 active_rrqs_xri_bitmap)
1799 mempool_free(active_rrqs_xri_bitmap,
1800 phba->active_rrq_pool);
1802 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1803 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1804 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1805 new_ndlp->nlp_fc4_type);
1811 * lpfc_end_rscn - Check and handle more rscn for a vport
1812 * @vport: pointer to a host virtual N_Port data structure.
1814 * This routine checks whether more Registration State Change
1815 * Notifications (RSCNs) came in while the discovery state machine was in
1816 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1817 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1818 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1819 * handling the RSCNs.
1822 lpfc_end_rscn(struct lpfc_vport *vport)
1824 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1826 if (vport->fc_flag & FC_RSCN_MODE) {
1828 * Check to see if more RSCNs came in while we were
1829 * processing this one.
1831 if (vport->fc_rscn_id_cnt ||
1832 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1833 lpfc_els_handle_rscn(vport);
1835 spin_lock_irq(shost->host_lock);
1836 vport->fc_flag &= ~FC_RSCN_MODE;
1837 spin_unlock_irq(shost->host_lock);
1843 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1844 * @phba: pointer to lpfc hba data structure.
1845 * @cmdiocb: pointer to lpfc command iocb data structure.
1846 * @rspiocb: pointer to lpfc response iocb data structure.
1848 * This routine will call the clear rrq function to free the rrq and
1849 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1850 * exist then the clear_rrq is still called because the rrq needs to
1855 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1856 struct lpfc_iocbq *rspiocb)
1858 struct lpfc_vport *vport = cmdiocb->vport;
1860 struct lpfc_nodelist *ndlp = cmdiocb->context1;
1861 struct lpfc_node_rrq *rrq;
1863 /* we pass cmdiocb to state machine which needs rspiocb as well */
1864 rrq = cmdiocb->context_un.rrq;
1865 cmdiocb->context_un.rsp_iocb = rspiocb;
1867 irsp = &rspiocb->iocb;
1868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1869 "RRQ cmpl: status:x%x/x%x did:x%x",
1870 irsp->ulpStatus, irsp->un.ulpWord[4],
1871 irsp->un.elsreq64.remoteID);
1873 /* rrq completes to NPort <nlp_DID> */
1874 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1875 "2880 RRQ completes to DID x%x "
1876 "Data: x%x x%x x%x x%x x%x\n",
1877 irsp->un.elsreq64.remoteID,
1878 irsp->ulpStatus, irsp->un.ulpWord[4],
1879 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1881 if (irsp->ulpStatus) {
1882 /* Check for retry */
1883 /* RRQ failed Don't print the vport to vport rjts */
1884 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1885 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1886 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1887 (phba)->pport->cfg_log_verbose & LOG_ELS)
1888 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1889 "2881 RRQ failure DID:%06X Status:"
1891 ndlp->nlp_DID, irsp->ulpStatus,
1892 irsp->un.ulpWord[4]);
1895 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1896 lpfc_els_free_iocb(phba, cmdiocb);
1901 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1902 * @phba: pointer to lpfc hba data structure.
1903 * @cmdiocb: pointer to lpfc command iocb data structure.
1904 * @rspiocb: pointer to lpfc response iocb data structure.
1906 * This routine is the completion callback function for issuing the Port
1907 * Login (PLOGI) command. For PLOGI completion, there must be an active
1908 * ndlp on the vport node list that matches the remote node ID from the
1909 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1910 * ignored and command IOCB released. The PLOGI response IOCB status is
1911 * checked for error conditons. If there is error status reported, PLOGI
1912 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1913 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1914 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1915 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1916 * there are additional N_Port nodes with the vport that need to perform
1917 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1921 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1922 struct lpfc_iocbq *rspiocb)
1924 struct lpfc_vport *vport = cmdiocb->vport;
1925 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1927 struct lpfc_nodelist *ndlp, *free_ndlp;
1928 struct lpfc_dmabuf *prsp;
1931 /* we pass cmdiocb to state machine which needs rspiocb as well */
1932 cmdiocb->context_un.rsp_iocb = rspiocb;
1934 irsp = &rspiocb->iocb;
1935 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1936 "PLOGI cmpl: status:x%x/x%x did:x%x",
1937 irsp->ulpStatus, irsp->un.ulpWord[4],
1938 irsp->un.elsreq64.remoteID);
1940 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1942 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1943 "0136 PLOGI completes to NPort x%x "
1944 "with no ndlp. Data: x%x x%x x%x\n",
1945 irsp->un.elsreq64.remoteID,
1946 irsp->ulpStatus, irsp->un.ulpWord[4],
1951 /* Since ndlp can be freed in the disc state machine, note if this node
1952 * is being used during discovery.
1954 spin_lock_irq(&ndlp->lock);
1955 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1956 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1957 spin_unlock_irq(&ndlp->lock);
1959 /* PLOGI completes to NPort <nlp_DID> */
1960 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1961 "0102 PLOGI completes to NPort x%06x "
1962 "Data: x%x x%x x%x x%x x%x\n",
1963 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1964 irsp->ulpStatus, irsp->un.ulpWord[4],
1965 disc, vport->num_disc_nodes);
1967 /* Check to see if link went down during discovery */
1968 if (lpfc_els_chk_latt(vport)) {
1969 spin_lock_irq(&ndlp->lock);
1970 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1971 spin_unlock_irq(&ndlp->lock);
1975 if (irsp->ulpStatus) {
1976 /* Check for retry */
1977 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1978 /* ELS command is being retried */
1980 spin_lock_irq(&ndlp->lock);
1981 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1982 spin_unlock_irq(&ndlp->lock);
1986 /* PLOGI failed Don't print the vport to vport rjts */
1987 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1988 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1989 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1990 (phba)->pport->cfg_log_verbose & LOG_ELS)
1991 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1992 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1993 ndlp->nlp_DID, irsp->ulpStatus,
1994 irsp->un.ulpWord[4]);
1996 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1997 if (lpfc_error_lost_link(irsp))
2000 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2001 NLP_EVT_CMPL_PLOGI);
2003 /* As long as this node is not registered with the scsi or nvme
2004 * transport, it is no longer an active node. Otherwise
2005 * devloss handles the final cleanup.
2007 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2008 spin_lock_irq(&ndlp->lock);
2009 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2010 spin_unlock_irq(&ndlp->lock);
2011 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2015 /* Good status, call state machine */
2016 prsp = list_entry(((struct lpfc_dmabuf *)
2017 cmdiocb->context2)->list.next,
2018 struct lpfc_dmabuf, list);
2019 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2020 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2021 NLP_EVT_CMPL_PLOGI);
2025 if (disc && vport->num_disc_nodes) {
2026 /* Check to see if there are more PLOGIs to be sent */
2027 lpfc_more_plogi(vport);
2029 if (vport->num_disc_nodes == 0) {
2030 spin_lock_irq(shost->host_lock);
2031 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2032 spin_unlock_irq(shost->host_lock);
2034 lpfc_can_disctmo(vport);
2035 lpfc_end_rscn(vport);
2040 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2041 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2042 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2045 /* Release the reference on the original I/O request. */
2046 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2048 lpfc_els_free_iocb(phba, cmdiocb);
2049 lpfc_nlp_put(free_ndlp);
2054 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2055 * @vport: pointer to a host virtual N_Port data structure.
2056 * @did: destination port identifier.
2057 * @retry: number of retries to the command IOCB.
2059 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2060 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2061 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2062 * This routine constructs the proper fields of the PLOGI IOCB and invokes
2063 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2065 * Note that the ndlp reference count will be incremented by 1 for holding
2066 * the ndlp and the reference to ndlp will be stored into the context1 field
2067 * of the IOCB for the completion callback function to the PLOGI ELS command.
2070 * 0 - Successfully issued a plogi for @vport
2071 * 1 - failed to issue a plogi for @vport
2074 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2076 struct lpfc_hba *phba = vport->phba;
2077 struct serv_parm *sp;
2078 struct lpfc_nodelist *ndlp;
2079 struct lpfc_iocbq *elsiocb;
2084 ndlp = lpfc_findnode_did(vport, did);
2088 /* Defer the processing of the issue PLOGI until after the
2089 * outstanding UNREG_RPI mbox command completes, unless we
2090 * are going offline. This logic does not apply for Fabric DIDs
2092 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2093 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2094 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2095 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2096 "4110 Issue PLOGI x%x deferred "
2097 "on NPort x%x rpi x%x Data: x%px\n",
2098 ndlp->nlp_defer_did, ndlp->nlp_DID,
2099 ndlp->nlp_rpi, ndlp);
2101 /* We can only defer 1st PLOGI */
2102 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2103 ndlp->nlp_defer_did = did;
2107 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2108 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2113 spin_lock_irq(&ndlp->lock);
2114 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2115 spin_unlock_irq(&ndlp->lock);
2117 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2119 /* For PLOGI request, remainder of payload is service parameters */
2120 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2121 pcmd += sizeof(uint32_t);
2122 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2123 sp = (struct serv_parm *) pcmd;
2126 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2127 * to device on remote loops work.
2129 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2130 sp->cmn.altBbCredit = 1;
2132 if (sp->cmn.fcphLow < FC_PH_4_3)
2133 sp->cmn.fcphLow = FC_PH_4_3;
2135 if (sp->cmn.fcphHigh < FC_PH3)
2136 sp->cmn.fcphHigh = FC_PH3;
2138 sp->cmn.valid_vendor_ver_level = 0;
2139 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2140 sp->cmn.bbRcvSizeMsb &= 0xF;
2142 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2143 "Issue PLOGI: did:x%x",
2146 /* If our firmware supports this feature, convey that
2147 * information to the target using the vendor specific field.
2149 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2150 sp->cmn.valid_vendor_ver_level = 1;
2151 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2152 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2155 phba->fc_stat.elsXmitPLOGI++;
2156 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2158 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2159 "Issue PLOGI: did:x%x refcnt %d",
2160 did, kref_read(&ndlp->kref), 0);
2161 elsiocb->context1 = lpfc_nlp_get(ndlp);
2162 if (!elsiocb->context1) {
2163 lpfc_els_free_iocb(phba, elsiocb);
2167 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2169 lpfc_els_free_iocb(phba, elsiocb);
2178 * lpfc_cmpl_els_prli - Completion callback function for prli
2179 * @phba: pointer to lpfc hba data structure.
2180 * @cmdiocb: pointer to lpfc command iocb data structure.
2181 * @rspiocb: pointer to lpfc response iocb data structure.
2183 * This routine is the completion callback function for a Process Login
2184 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2185 * status. If there is error status reported, PRLI retry shall be attempted
2186 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2187 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2188 * ndlp to mark the PRLI completion.
2191 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2192 struct lpfc_iocbq *rspiocb)
2194 struct lpfc_vport *vport = cmdiocb->vport;
2196 struct lpfc_nodelist *ndlp;
2200 /* we pass cmdiocb to state machine which needs rspiocb as well */
2201 cmdiocb->context_un.rsp_iocb = rspiocb;
2203 irsp = &(rspiocb->iocb);
2204 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2205 spin_lock_irq(&ndlp->lock);
2206 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2208 /* Driver supports multiple FC4 types. Counters matter. */
2209 vport->fc_prli_sent--;
2210 ndlp->fc4_prli_sent--;
2211 spin_unlock_irq(&ndlp->lock);
2213 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2214 "PRLI cmpl: status:x%x/x%x did:x%x",
2215 irsp->ulpStatus, irsp->un.ulpWord[4],
2218 /* PRLI completes to NPort <nlp_DID> */
2219 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2220 "0103 PRLI completes to NPort x%06x "
2221 "Data: x%x x%x x%x x%x\n",
2222 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2223 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2225 /* Check to see if link went down during discovery */
2226 if (lpfc_els_chk_latt(vport))
2229 if (irsp->ulpStatus) {
2230 /* Check for retry */
2231 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2232 /* ELS command is being retried */
2236 /* If we don't send GFT_ID to Fabric, a PRLI error
2237 * could be expected.
2239 if ((vport->fc_flag & FC_FABRIC) ||
2240 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2242 loglevel = LOG_TRACE_EVENT;
2249 lpfc_printf_vlog(vport, mode, loglevel,
2250 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2252 ndlp->nlp_DID, irsp->ulpStatus,
2253 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2255 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2256 if (lpfc_error_lost_link(irsp))
2259 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2262 /* As long as this node is not registered with the SCSI
2263 * or NVMe transport and no other PRLIs are outstanding,
2264 * it is no longer an active node. Otherwise devloss
2265 * handles the final cleanup.
2267 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2268 !ndlp->fc4_prli_sent) {
2269 spin_lock_irq(&ndlp->lock);
2270 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2271 spin_unlock_irq(&ndlp->lock);
2272 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2276 /* Good status, call state machine. However, if another
2277 * PRLI is outstanding, don't call the state machine
2278 * because final disposition to Mapped or Unmapped is
2281 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2286 lpfc_els_free_iocb(phba, cmdiocb);
2292 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2293 * @vport: pointer to a host virtual N_Port data structure.
2294 * @ndlp: pointer to a node-list data structure.
2295 * @retry: number of retries to the command IOCB.
2297 * This routine issues a Process Login (PRLI) ELS command for the
2298 * @vport. The PRLI service parameters are set up in the payload of the
2299 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2300 * is put to the IOCB completion callback func field before invoking the
2301 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2303 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2304 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2305 * will be stored into the context1 field of the IOCB for the completion
2306 * callback function to the PRLI ELS command.
2309 * 0 - successfully issued prli iocb command for @vport
2310 * 1 - failed to issue prli iocb command for @vport
2313 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2317 struct lpfc_hba *phba = vport->phba;
2319 struct lpfc_nvme_prli *npr_nvme;
2320 struct lpfc_iocbq *elsiocb;
2323 u32 local_nlp_type, elscmd;
2326 * If we are in RSCN mode, the FC4 types supported from a
2327 * previous GFT_ID command may not be accurate. So, if we
2328 * are a NVME Initiator, always look for the possibility of
2329 * the remote NPort beng a NVME Target.
2331 if (phba->sli_rev == LPFC_SLI_REV4 &&
2332 vport->fc_flag & FC_RSCN_MODE &&
2333 vport->nvmei_support)
2334 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2335 local_nlp_type = ndlp->nlp_fc4_type;
2337 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2338 * fields here before any of them can complete.
2340 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2341 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2342 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2343 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2344 ndlp->nvme_fb_size = 0;
2347 if (local_nlp_type & NLP_FC4_FCP) {
2348 /* Payload is 4 + 16 = 20 x14 bytes. */
2349 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2350 elscmd = ELS_CMD_PRLI;
2351 } else if (local_nlp_type & NLP_FC4_NVME) {
2352 /* Payload is 4 + 20 = 24 x18 bytes. */
2353 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2354 elscmd = ELS_CMD_NVMEPRLI;
2356 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2357 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2358 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2362 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2363 * FC4 type, implicitly LOGO.
2365 if (phba->sli_rev == LPFC_SLI_REV3 &&
2366 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2367 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2368 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2370 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2374 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2375 ndlp->nlp_DID, elscmd);
2379 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2381 /* For PRLI request, remainder of payload is service parameters */
2382 memset(pcmd, 0, cmdsize);
2384 if (local_nlp_type & NLP_FC4_FCP) {
2385 /* Remainder of payload is FCP PRLI parameter page.
2386 * Note: this data structure is defined as
2387 * BE/LE in the structure definition so no
2388 * byte swap call is made.
2390 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2391 pcmd += sizeof(uint32_t);
2395 * If our firmware version is 3.20 or later,
2396 * set the following bits for FC-TAPE support.
2398 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2399 npr->ConfmComplAllowed = 1;
2401 npr->TaskRetryIdReq = 1;
2403 npr->estabImagePair = 1;
2404 npr->readXferRdyDis = 1;
2405 if (vport->cfg_first_burst_size)
2406 npr->writeXferRdyDis = 1;
2408 /* For FCP support */
2409 npr->prliType = PRLI_FCP_TYPE;
2410 npr->initiatorFunc = 1;
2411 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2413 /* Remove FCP type - processed. */
2414 local_nlp_type &= ~NLP_FC4_FCP;
2415 } else if (local_nlp_type & NLP_FC4_NVME) {
2416 /* Remainder of payload is NVME PRLI parameter page.
2417 * This data structure is the newer definition that
2418 * uses bf macros so a byte swap is required.
2420 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2421 pcmd += sizeof(uint32_t);
2422 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2423 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2424 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2426 bf_set(prli_nsler, npr_nvme, 1);
2427 bf_set(prli_conf, npr_nvme, 1);
2430 /* Only initiators request first burst. */
2431 if ((phba->cfg_nvme_enable_fb) &&
2432 !phba->nvmet_support)
2433 bf_set(prli_fba, npr_nvme, 1);
2435 if (phba->nvmet_support) {
2436 bf_set(prli_tgt, npr_nvme, 1);
2437 bf_set(prli_disc, npr_nvme, 1);
2439 bf_set(prli_init, npr_nvme, 1);
2440 bf_set(prli_conf, npr_nvme, 1);
2443 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2444 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2445 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2447 /* Remove NVME type - processed. */
2448 local_nlp_type &= ~NLP_FC4_NVME;
2451 phba->fc_stat.elsXmitPRLI++;
2452 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2453 spin_lock_irq(&ndlp->lock);
2454 ndlp->nlp_flag |= NLP_PRLI_SND;
2456 /* The vport counters are used for lpfc_scan_finished, but
2457 * the ndlp is used to track outstanding PRLIs for different
2460 vport->fc_prli_sent++;
2461 ndlp->fc4_prli_sent++;
2462 spin_unlock_irq(&ndlp->lock);
2464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2465 "Issue PRLI: did:x%x refcnt %d",
2466 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2467 elsiocb->context1 = lpfc_nlp_get(ndlp);
2468 if (!elsiocb->context1) {
2469 lpfc_els_free_iocb(phba, elsiocb);
2473 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2474 if (rc == IOCB_ERROR) {
2475 lpfc_els_free_iocb(phba, elsiocb);
2481 /* The driver supports 2 FC4 types. Make sure
2482 * a PRLI is issued for all types before exiting.
2484 if (phba->sli_rev == LPFC_SLI_REV4 &&
2485 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2486 goto send_next_prli;
2491 spin_lock_irq(&ndlp->lock);
2492 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2493 spin_unlock_irq(&ndlp->lock);
2498 * lpfc_rscn_disc - Perform rscn discovery for a vport
2499 * @vport: pointer to a host virtual N_Port data structure.
2501 * This routine performs Registration State Change Notification (RSCN)
2502 * discovery for a @vport. If the @vport's node port recovery count is not
2503 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2504 * the nodes that need recovery. If none of the PLOGI were needed through
2505 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2506 * invoked to check and handle possible more RSCN came in during the period
2507 * of processing the current ones.
2510 lpfc_rscn_disc(struct lpfc_vport *vport)
2512 lpfc_can_disctmo(vport);
2514 /* RSCN discovery */
2515 /* go thru NPR nodes and issue ELS PLOGIs */
2516 if (vport->fc_npr_cnt)
2517 if (lpfc_els_disc_plogi(vport))
2520 lpfc_end_rscn(vport);
2524 * lpfc_adisc_done - Complete the adisc phase of discovery
2525 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2527 * This function is called when the final ADISC is completed during discovery.
2528 * This function handles clearing link attention or issuing reg_vpi depending
2529 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2531 * This function is called with no locks held.
2534 lpfc_adisc_done(struct lpfc_vport *vport)
2536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2537 struct lpfc_hba *phba = vport->phba;
2540 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2541 * and continue discovery.
2543 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2544 !(vport->fc_flag & FC_RSCN_MODE) &&
2545 (phba->sli_rev < LPFC_SLI_REV4)) {
2546 /* The ADISCs are complete. Doesn't matter if they
2547 * succeeded or failed because the ADISC completion
2548 * routine guarantees to call the state machine and
2549 * the RPI is either unregistered (failed ADISC response)
2550 * or the RPI is still valid and the node is marked
2551 * mapped for a target. The exchanges should be in the
2552 * correct state. This code is specific to SLI3.
2554 lpfc_issue_clear_la(phba, vport);
2555 lpfc_issue_reg_vpi(phba, vport);
2559 * For SLI2, we need to set port_state to READY
2560 * and continue discovery.
2562 if (vport->port_state < LPFC_VPORT_READY) {
2563 /* If we get here, there is nothing to ADISC */
2564 lpfc_issue_clear_la(phba, vport);
2565 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2566 vport->num_disc_nodes = 0;
2567 /* go thru NPR list, issue ELS PLOGIs */
2568 if (vport->fc_npr_cnt)
2569 lpfc_els_disc_plogi(vport);
2570 if (!vport->num_disc_nodes) {
2571 spin_lock_irq(shost->host_lock);
2572 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2573 spin_unlock_irq(shost->host_lock);
2574 lpfc_can_disctmo(vport);
2575 lpfc_end_rscn(vport);
2578 vport->port_state = LPFC_VPORT_READY;
2580 lpfc_rscn_disc(vport);
2584 * lpfc_more_adisc - Issue more adisc as needed
2585 * @vport: pointer to a host virtual N_Port data structure.
2587 * This routine determines whether there are more ndlps on a @vport
2588 * node list need to have Address Discover (ADISC) issued. If so, it will
2589 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2590 * remaining nodes which need to have ADISC sent.
2593 lpfc_more_adisc(struct lpfc_vport *vport)
2595 if (vport->num_disc_nodes)
2596 vport->num_disc_nodes--;
2597 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2598 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2599 "0210 Continue discovery with %d ADISCs to go "
2600 "Data: x%x x%x x%x\n",
2601 vport->num_disc_nodes, vport->fc_adisc_cnt,
2602 vport->fc_flag, vport->port_state);
2603 /* Check to see if there are more ADISCs to be sent */
2604 if (vport->fc_flag & FC_NLP_MORE) {
2605 lpfc_set_disctmo(vport);
2606 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2607 lpfc_els_disc_adisc(vport);
2609 if (!vport->num_disc_nodes)
2610 lpfc_adisc_done(vport);
2615 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2616 * @phba: pointer to lpfc hba data structure.
2617 * @cmdiocb: pointer to lpfc command iocb data structure.
2618 * @rspiocb: pointer to lpfc response iocb data structure.
2620 * This routine is the completion function for issuing the Address Discover
2621 * (ADISC) command. It first checks to see whether link went down during
2622 * the discovery process. If so, the node will be marked as node port
2623 * recovery for issuing discover IOCB by the link attention handler and
2624 * exit. Otherwise, the response status is checked. If error was reported
2625 * in the response status, the ADISC command shall be retried by invoking
2626 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2627 * the response status, the state machine is invoked to set transition
2628 * with respect to NLP_EVT_CMPL_ADISC event.
2631 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2632 struct lpfc_iocbq *rspiocb)
2634 struct lpfc_vport *vport = cmdiocb->vport;
2636 struct lpfc_nodelist *ndlp;
2639 /* we pass cmdiocb to state machine which needs rspiocb as well */
2640 cmdiocb->context_un.rsp_iocb = rspiocb;
2642 irsp = &(rspiocb->iocb);
2643 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2646 "ADISC cmpl: status:x%x/x%x did:x%x",
2647 irsp->ulpStatus, irsp->un.ulpWord[4],
2650 /* Since ndlp can be freed in the disc state machine, note if this node
2651 * is being used during discovery.
2653 spin_lock_irq(&ndlp->lock);
2654 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2655 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2656 spin_unlock_irq(&ndlp->lock);
2657 /* ADISC completes to NPort <nlp_DID> */
2658 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2659 "0104 ADISC completes to NPort x%x "
2660 "Data: x%x x%x x%x x%x x%x\n",
2661 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2662 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2663 /* Check to see if link went down during discovery */
2664 if (lpfc_els_chk_latt(vport)) {
2665 spin_lock_irq(&ndlp->lock);
2666 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2667 spin_unlock_irq(&ndlp->lock);
2671 if (irsp->ulpStatus) {
2672 /* Check for retry */
2673 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2674 /* ELS command is being retried */
2676 spin_lock_irq(&ndlp->lock);
2677 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2678 spin_unlock_irq(&ndlp->lock);
2679 lpfc_set_disctmo(vport);
2684 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2685 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2686 ndlp->nlp_DID, irsp->ulpStatus,
2687 irsp->un.ulpWord[4]);
2688 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2689 if (lpfc_error_lost_link(irsp))
2692 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2693 NLP_EVT_CMPL_ADISC);
2695 /* As long as this node is not registered with the SCSI or NVMe
2696 * transport, it is no longer an active node. Otherwise
2697 * devloss handles the final cleanup.
2699 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2700 spin_lock_irq(&ndlp->lock);
2701 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2702 spin_unlock_irq(&ndlp->lock);
2703 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2707 /* Good status, call state machine */
2708 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2709 NLP_EVT_CMPL_ADISC);
2712 /* Check to see if there are more ADISCs to be sent */
2713 if (disc && vport->num_disc_nodes)
2714 lpfc_more_adisc(vport);
2716 lpfc_els_free_iocb(phba, cmdiocb);
2722 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2723 * @vport: pointer to a virtual N_Port data structure.
2724 * @ndlp: pointer to a node-list data structure.
2725 * @retry: number of retries to the command IOCB.
2727 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2728 * @vport. It prepares the payload of the ADISC ELS command, updates the
2729 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2730 * to issue the ADISC ELS command.
2732 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2733 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2734 * will be stored into the context1 field of the IOCB for the completion
2735 * callback function to the ADISC ELS command.
2738 * 0 - successfully issued adisc
2739 * 1 - failed to issue adisc
2742 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2746 struct lpfc_hba *phba = vport->phba;
2748 struct lpfc_iocbq *elsiocb;
2752 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2753 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2754 ndlp->nlp_DID, ELS_CMD_ADISC);
2758 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2760 /* For ADISC request, remainder of payload is service parameters */
2761 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2762 pcmd += sizeof(uint32_t);
2764 /* Fill in ADISC payload */
2765 ap = (ADISC *) pcmd;
2766 ap->hardAL_PA = phba->fc_pref_ALPA;
2767 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2768 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2769 ap->DID = be32_to_cpu(vport->fc_myDID);
2771 phba->fc_stat.elsXmitADISC++;
2772 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2773 spin_lock_irq(&ndlp->lock);
2774 ndlp->nlp_flag |= NLP_ADISC_SND;
2775 spin_unlock_irq(&ndlp->lock);
2776 elsiocb->context1 = lpfc_nlp_get(ndlp);
2777 if (!elsiocb->context1) {
2778 lpfc_els_free_iocb(phba, elsiocb);
2782 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2783 "Issue ADISC: did:x%x refcnt %d",
2784 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2785 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2786 if (rc == IOCB_ERROR) {
2787 lpfc_els_free_iocb(phba, elsiocb);
2795 spin_lock_irq(&ndlp->lock);
2796 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2797 spin_unlock_irq(&ndlp->lock);
2802 * lpfc_cmpl_els_logo - Completion callback function for logo
2803 * @phba: pointer to lpfc hba data structure.
2804 * @cmdiocb: pointer to lpfc command iocb data structure.
2805 * @rspiocb: pointer to lpfc response iocb data structure.
2807 * This routine is the completion function for issuing the ELS Logout (LOGO)
2808 * command. If no error status was reported from the LOGO response, the
2809 * state machine of the associated ndlp shall be invoked for transition with
2810 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2811 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2814 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2815 struct lpfc_iocbq *rspiocb)
2817 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2818 struct lpfc_vport *vport = ndlp->vport;
2820 unsigned long flags;
2821 uint32_t skip_recovery = 0;
2822 int wake_up_waiter = 0;
2824 /* we pass cmdiocb to state machine which needs rspiocb as well */
2825 cmdiocb->context_un.rsp_iocb = rspiocb;
2827 irsp = &(rspiocb->iocb);
2828 spin_lock_irq(&ndlp->lock);
2829 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2830 if (ndlp->upcall_flags & NLP_WAIT_FOR_LOGO) {
2832 ndlp->upcall_flags &= ~NLP_WAIT_FOR_LOGO;
2834 spin_unlock_irq(&ndlp->lock);
2836 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2837 "LOGO cmpl: status:x%x/x%x did:x%x",
2838 irsp->ulpStatus, irsp->un.ulpWord[4],
2841 /* LOGO completes to NPort <nlp_DID> */
2842 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2843 "0105 LOGO completes to NPort x%x "
2844 "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
2845 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
2846 irsp->ulpStatus, irsp->un.ulpWord[4],
2847 irsp->ulpTimeout, vport->num_disc_nodes);
2849 if (lpfc_els_chk_latt(vport)) {
2854 /* The LOGO will not be retried on failure. A LOGO was
2855 * issued to the remote rport and a ACC or RJT or no Answer are
2856 * all acceptable. Note the failure and move forward with
2857 * discovery. The PLOGI will retry.
2859 if (irsp->ulpStatus) {
2861 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2862 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2863 ndlp->nlp_DID, irsp->ulpStatus,
2864 irsp->un.ulpWord[4]);
2865 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2866 if (lpfc_error_lost_link(irsp)) {
2872 /* Call state machine. This will unregister the rpi if needed. */
2873 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2875 /* The driver sets this flag for an NPIV instance that doesn't want to
2876 * log into the remote port.
2878 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2879 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2881 lpfc_els_free_iocb(phba, cmdiocb);
2884 /* Presume the node was released. */
2889 /* Driver is done with the IO. */
2890 lpfc_els_free_iocb(phba, cmdiocb);
2893 /* At this point, the LOGO processing is complete. NOTE: For a
2894 * pt2pt topology, we are assuming the NPortID will only change
2895 * on link up processing. For a LOGO / PLOGI initiated by the
2896 * Initiator, we are assuming the NPortID is not going to change.
2899 if (wake_up_waiter && ndlp->logo_waitq)
2900 wake_up(ndlp->logo_waitq);
2902 * If the node is a target, the handling attempts to recover the port.
2903 * For any other port type, the rpi is unregistered as an implicit
2906 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2907 skip_recovery == 0) {
2908 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2909 spin_lock_irqsave(&ndlp->lock, flags);
2910 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2911 spin_unlock_irqrestore(&ndlp->lock, flags);
2913 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2914 "3187 LOGO completes to NPort x%x: Start "
2915 "Recovery Data: x%x x%x x%x x%x\n",
2916 ndlp->nlp_DID, irsp->ulpStatus,
2917 irsp->un.ulpWord[4], irsp->ulpTimeout,
2918 vport->num_disc_nodes);
2919 lpfc_disc_start(vport);
2923 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
2924 * driver sends a LOGO to the rport to cleanup. For fabric and
2925 * initiator ports cleanup the node as long as it the node is not
2926 * register with the transport.
2928 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2929 spin_lock_irq(&ndlp->lock);
2930 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2931 spin_unlock_irq(&ndlp->lock);
2932 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2938 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2939 * @vport: pointer to a virtual N_Port data structure.
2940 * @ndlp: pointer to a node-list data structure.
2941 * @retry: number of retries to the command IOCB.
2943 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2944 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2945 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2946 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2948 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2949 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2950 * will be stored into the context1 field of the IOCB for the completion
2951 * callback function to the LOGO ELS command.
2953 * Callers of this routine are expected to unregister the RPI first
2956 * 0 - successfully issued logo
2957 * 1 - failed to issue logo
2960 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2963 struct lpfc_hba *phba = vport->phba;
2964 struct lpfc_iocbq *elsiocb;
2969 spin_lock_irq(&ndlp->lock);
2970 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2971 spin_unlock_irq(&ndlp->lock);
2974 spin_unlock_irq(&ndlp->lock);
2976 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2977 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2978 ndlp->nlp_DID, ELS_CMD_LOGO);
2982 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2983 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2984 pcmd += sizeof(uint32_t);
2986 /* Fill in LOGO payload */
2987 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2988 pcmd += sizeof(uint32_t);
2989 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2991 phba->fc_stat.elsXmitLOGO++;
2992 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2993 spin_lock_irq(&ndlp->lock);
2994 ndlp->nlp_flag |= NLP_LOGO_SND;
2995 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2996 spin_unlock_irq(&ndlp->lock);
2997 elsiocb->context1 = lpfc_nlp_get(ndlp);
2998 if (!elsiocb->context1) {
2999 lpfc_els_free_iocb(phba, elsiocb);
3003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3004 "Issue LOGO: did:x%x refcnt %d",
3005 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3006 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3007 if (rc == IOCB_ERROR) {
3008 lpfc_els_free_iocb(phba, elsiocb);
3013 spin_lock_irq(&ndlp->lock);
3014 ndlp->nlp_prev_state = ndlp->nlp_state;
3015 spin_unlock_irq(&ndlp->lock);
3016 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3020 spin_lock_irq(&ndlp->lock);
3021 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3022 spin_unlock_irq(&ndlp->lock);
3027 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3028 * @phba: pointer to lpfc hba data structure.
3029 * @cmdiocb: pointer to lpfc command iocb data structure.
3030 * @rspiocb: pointer to lpfc response iocb data structure.
3032 * This routine is a generic completion callback function for ELS commands.
3033 * Specifically, it is the callback function which does not need to perform
3034 * any command specific operations. It is currently used by the ELS command
3035 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3036 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3037 * Other than certain debug loggings, this callback function simply invokes the
3038 * lpfc_els_chk_latt() routine to check whether link went down during the
3039 * discovery process.
3042 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3043 struct lpfc_iocbq *rspiocb)
3045 struct lpfc_vport *vport = cmdiocb->vport;
3046 struct lpfc_nodelist *free_ndlp;
3049 irsp = &rspiocb->iocb;
3051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3052 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3053 irsp->ulpStatus, irsp->un.ulpWord[4],
3054 irsp->un.elsreq64.remoteID);
3056 /* ELS cmd tag <ulpIoTag> completes */
3057 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3058 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3059 irsp->ulpIoTag, irsp->ulpStatus,
3060 irsp->un.ulpWord[4], irsp->ulpTimeout);
3062 /* Check to see if link went down during discovery */
3063 lpfc_els_chk_latt(vport);
3065 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3067 lpfc_els_free_iocb(phba, cmdiocb);
3068 lpfc_nlp_put(free_ndlp);
3072 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3073 * @phba: pointer to lpfc hba data structure.
3074 * @cmdiocb: pointer to lpfc command iocb data structure.
3075 * @rspiocb: pointer to lpfc response iocb data structure.
3077 * This routine is a generic completion callback function for Discovery ELS cmd.
3078 * Currently used by the ELS command issuing routines for the ELS State Change
3079 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3080 * These commands will be retried once only for ELS timeout errors.
3083 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3084 struct lpfc_iocbq *rspiocb)
3086 struct lpfc_vport *vport = cmdiocb->vport;
3088 struct lpfc_els_rdf_rsp *prdf;
3089 struct lpfc_dmabuf *pcmd, *prsp;
3092 struct lpfc_nodelist *ndlp = cmdiocb->context1;
3094 irsp = &rspiocb->iocb;
3096 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3097 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3098 irsp->ulpStatus, irsp->un.ulpWord[4],
3099 irsp->un.elsreq64.remoteID);
3100 /* ELS cmd tag <ulpIoTag> completes */
3101 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3102 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3104 irsp->ulpIoTag, irsp->ulpStatus,
3105 irsp->un.ulpWord[4], irsp->ulpTimeout,
3108 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3112 pdata = (u32 *)pcmd->virt;
3117 /* Only 1 retry for ELS Timeout only */
3118 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3119 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3120 IOERR_SEQUENCE_TIMEOUT)) {
3122 if (cmdiocb->retry <= 1) {
3125 lpfc_issue_els_scr(vport, cmdiocb->retry);
3128 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3129 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3134 phba->fc_stat.elsRetryExceeded++;
3136 if (irsp->ulpStatus) {
3137 /* ELS discovery cmd completes with error */
3138 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3139 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3140 irsp->ulpStatus, irsp->un.ulpWord[4]);
3144 /* The RDF response doesn't have any impact on the running driver
3145 * but the notification descriptors are dumped here for support.
3147 if (cmd == ELS_CMD_RDF) {
3150 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3154 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3158 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3159 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3160 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3161 "4677 Fabric RDF Notification Grant Data: "
3164 prdf->reg_d1.desc_tags[i]));
3168 /* Check to see if link went down during discovery */
3169 lpfc_els_chk_latt(vport);
3170 lpfc_els_free_iocb(phba, cmdiocb);
3176 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3177 * @vport: pointer to a host virtual N_Port data structure.
3178 * @retry: retry counter for the command IOCB.
3180 * This routine issues a State Change Request (SCR) to a fabric node
3181 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3182 * first search the @vport node list to find the matching ndlp. If no such
3183 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3184 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3185 * routine is invoked to send the SCR IOCB.
3187 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3188 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3189 * will be stored into the context1 field of the IOCB for the completion
3190 * callback function to the SCR ELS command.
3193 * 0 - Successfully issued scr command
3194 * 1 - Failed to issue scr command
3197 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3200 struct lpfc_hba *phba = vport->phba;
3201 struct lpfc_iocbq *elsiocb;
3204 struct lpfc_nodelist *ndlp;
3206 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3208 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3210 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3213 lpfc_enqueue_node(vport, ndlp);
3216 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3217 ndlp->nlp_DID, ELS_CMD_SCR);
3222 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3224 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3225 pcmd += sizeof(uint32_t);
3227 /* For SCR, remainder of payload is SCR parameter page */
3228 memset(pcmd, 0, sizeof(SCR));
3229 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3232 "Issue SCR: did:x%x",
3233 ndlp->nlp_DID, 0, 0);
3235 phba->fc_stat.elsXmitSCR++;
3236 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3237 elsiocb->context1 = lpfc_nlp_get(ndlp);
3238 if (!elsiocb->context1) {
3239 lpfc_els_free_iocb(phba, elsiocb);
3243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3244 "Issue SCR: did:x%x refcnt %d",
3245 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3247 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3248 if (rc == IOCB_ERROR) {
3249 lpfc_els_free_iocb(phba, elsiocb);
3254 /* Keep the ndlp just in case RDF is being sent */
3259 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3260 * or the other nport (pt2pt).
3261 * @vport: pointer to a host virtual N_Port data structure.
3262 * @retry: number of retries to the command IOCB.
3264 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3265 * when connected to a fabric, or to the remote port when connected
3266 * in point-to-point mode. When sent to the Fabric Controller, it will
3267 * replay the RSCN to registered recipients.
3269 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3270 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3271 * will be stored into the context1 field of the IOCB for the completion
3272 * callback function to the RSCN ELS command.
3275 * 0 - Successfully issued RSCN command
3276 * 1 - Failed to issue RSCN command
3279 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3282 struct lpfc_hba *phba = vport->phba;
3283 struct lpfc_iocbq *elsiocb;
3284 struct lpfc_nodelist *ndlp;
3286 struct fc_els_rscn rscn;
3287 struct fc_els_rscn_page portid;
3290 uint16_t cmdsize = sizeof(*event);
3292 /* Not supported for private loop */
3293 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3294 !(vport->fc_flag & FC_PUBLIC_LOOP))
3297 if (vport->fc_flag & FC_PT2PT) {
3298 /* find any mapped nport - that would be the other nport */
3299 ndlp = lpfc_findnode_mapped(vport);
3303 nportid = FC_FID_FCTRL;
3304 /* find the fabric controller node */
3305 ndlp = lpfc_findnode_did(vport, nportid);
3307 /* if one didn't exist, make one */
3308 ndlp = lpfc_nlp_init(vport, nportid);
3311 lpfc_enqueue_node(vport, ndlp);
3315 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3316 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3321 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3323 event->rscn.rscn_cmd = ELS_RSCN;
3324 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3325 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3327 nportid = vport->fc_myDID;
3328 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3329 event->portid.rscn_page_flags = 0;
3330 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3331 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3332 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3334 phba->fc_stat.elsXmitRSCN++;
3335 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3336 elsiocb->context1 = lpfc_nlp_get(ndlp);
3337 if (!elsiocb->context1) {
3338 lpfc_els_free_iocb(phba, elsiocb);
3342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3343 "Issue RSCN: did:x%x",
3344 ndlp->nlp_DID, 0, 0);
3346 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3347 if (rc == IOCB_ERROR) {
3348 lpfc_els_free_iocb(phba, elsiocb);
3353 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3354 * trigger the release of node.
3356 if (!(vport->fc_flag & FC_PT2PT))
3362 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3363 * @vport: pointer to a host virtual N_Port data structure.
3364 * @nportid: N_Port identifier to the remote node.
3365 * @retry: number of retries to the command IOCB.
3367 * This routine issues a Fibre Channel Address Resolution Response
3368 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3369 * is passed into the function. It first search the @vport node list to find
3370 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3371 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3372 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3374 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3375 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3376 * will be stored into the context1 field of the IOCB for the completion
3377 * callback function to the PARPR ELS command.
3380 * 0 - Successfully issued farpr command
3381 * 1 - Failed to issue farpr command
3384 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3387 struct lpfc_hba *phba = vport->phba;
3388 struct lpfc_iocbq *elsiocb;
3393 struct lpfc_nodelist *ondlp;
3394 struct lpfc_nodelist *ndlp;
3396 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3398 ndlp = lpfc_findnode_did(vport, nportid);
3400 ndlp = lpfc_nlp_init(vport, nportid);
3403 lpfc_enqueue_node(vport, ndlp);
3406 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3407 ndlp->nlp_DID, ELS_CMD_RNID);
3411 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3413 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3414 pcmd += sizeof(uint32_t);
3416 /* Fill in FARPR payload */
3417 fp = (FARP *) (pcmd);
3418 memset(fp, 0, sizeof(FARP));
3419 lp = (uint32_t *) pcmd;
3420 *lp++ = be32_to_cpu(nportid);
3421 *lp++ = be32_to_cpu(vport->fc_myDID);
3423 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3425 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3426 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3427 ondlp = lpfc_findnode_did(vport, nportid);
3429 memcpy(&fp->OportName, &ondlp->nlp_portname,
3430 sizeof(struct lpfc_name));
3431 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3432 sizeof(struct lpfc_name));
3435 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3436 "Issue FARPR: did:x%x",
3437 ndlp->nlp_DID, 0, 0);
3439 phba->fc_stat.elsXmitFARPR++;
3440 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3441 elsiocb->context1 = lpfc_nlp_get(ndlp);
3442 if (!elsiocb->context1) {
3443 lpfc_els_free_iocb(phba, elsiocb);
3447 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3448 if (rc == IOCB_ERROR) {
3449 /* The additional lpfc_nlp_put will cause the following
3450 * lpfc_els_free_iocb routine to trigger the release of
3453 lpfc_els_free_iocb(phba, elsiocb);
3457 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3458 * trigger the release of the node.
3460 /* Don't release reference count as RDF is likely outstanding */
3465 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3466 * @vport: pointer to a host virtual N_Port data structure.
3467 * @retry: retry counter for the command IOCB.
3469 * This routine issues an ELS RDF to the Fabric Controller to register
3470 * for diagnostic functions.
3472 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3473 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3474 * will be stored into the context1 field of the IOCB for the completion
3475 * callback function to the RDF ELS command.
3478 * 0 - Successfully issued rdf command
3479 * 1 - Failed to issue rdf command
3482 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3484 struct lpfc_hba *phba = vport->phba;
3485 struct lpfc_iocbq *elsiocb;
3486 struct lpfc_els_rdf_req *prdf;
3487 struct lpfc_nodelist *ndlp;
3491 cmdsize = sizeof(*prdf);
3493 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3495 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3498 lpfc_enqueue_node(vport, ndlp);
3501 /* RDF ELS is not required on an NPIV VN_Port. */
3502 if (vport->port_type == LPFC_NPIV_PORT) {
3507 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3508 ndlp->nlp_DID, ELS_CMD_RDF);
3512 /* Configure the payload for the supported FPIN events. */
3513 prdf = (struct lpfc_els_rdf_req *)
3514 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3515 memset(prdf, 0, cmdsize);
3516 prdf->rdf.fpin_cmd = ELS_RDF;
3517 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3518 sizeof(struct fc_els_rdf));
3519 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3520 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3521 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3522 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3523 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3524 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3525 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3526 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3528 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3529 "6444 Xmit RDF to remote NPORT x%x\n",
3532 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3533 elsiocb->context1 = lpfc_nlp_get(ndlp);
3534 if (!elsiocb->context1) {
3535 lpfc_els_free_iocb(phba, elsiocb);
3539 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3540 "Issue RDF: did:x%x refcnt %d",
3541 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3543 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3544 if (rc == IOCB_ERROR) {
3545 lpfc_els_free_iocb(phba, elsiocb);
3553 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3554 * @vport: pointer to a host virtual N_Port data structure.
3555 * @nlp: pointer to a node-list data structure.
3557 * This routine cancels the timer with a delayed IOCB-command retry for
3558 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3559 * removes the ELS retry event if it presents. In addition, if the
3560 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3561 * commands are sent for the @vport's nodes that require issuing discovery
3565 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3567 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3568 struct lpfc_work_evt *evtp;
3570 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3572 spin_lock_irq(&nlp->lock);
3573 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3574 spin_unlock_irq(&nlp->lock);
3575 del_timer_sync(&nlp->nlp_delayfunc);
3576 nlp->nlp_last_elscmd = 0;
3577 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3578 list_del_init(&nlp->els_retry_evt.evt_listp);
3579 /* Decrement nlp reference count held for the delayed retry */
3580 evtp = &nlp->els_retry_evt;
3581 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3583 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3584 spin_lock_irq(&nlp->lock);
3585 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3586 spin_unlock_irq(&nlp->lock);
3587 if (vport->num_disc_nodes) {
3588 if (vport->port_state < LPFC_VPORT_READY) {
3589 /* Check if there are more ADISCs to be sent */
3590 lpfc_more_adisc(vport);
3592 /* Check if there are more PLOGIs to be sent */
3593 lpfc_more_plogi(vport);
3594 if (vport->num_disc_nodes == 0) {
3595 spin_lock_irq(shost->host_lock);
3596 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3597 spin_unlock_irq(shost->host_lock);
3598 lpfc_can_disctmo(vport);
3599 lpfc_end_rscn(vport);
3608 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3609 * @t: pointer to the timer function associated data (ndlp).
3611 * This routine is invoked by the ndlp delayed-function timer to check
3612 * whether there is any pending ELS retry event(s) with the node. If not, it
3613 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3614 * adds the delayed events to the HBA work list and invokes the
3615 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3616 * event. Note that lpfc_nlp_get() is called before posting the event to
3617 * the work list to hold reference count of ndlp so that it guarantees the
3618 * reference to ndlp will still be available when the worker thread gets
3619 * to the event associated with the ndlp.
3622 lpfc_els_retry_delay(struct timer_list *t)
3624 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3625 struct lpfc_vport *vport = ndlp->vport;
3626 struct lpfc_hba *phba = vport->phba;
3627 unsigned long flags;
3628 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3630 spin_lock_irqsave(&phba->hbalock, flags);
3631 if (!list_empty(&evtp->evt_listp)) {
3632 spin_unlock_irqrestore(&phba->hbalock, flags);
3636 /* We need to hold the node by incrementing the reference
3637 * count until the queued work is done
3639 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3640 if (evtp->evt_arg1) {
3641 evtp->evt = LPFC_EVT_ELS_RETRY;
3642 list_add_tail(&evtp->evt_listp, &phba->work_list);
3643 lpfc_worker_wake_up(phba);
3645 spin_unlock_irqrestore(&phba->hbalock, flags);
3650 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3651 * @ndlp: pointer to a node-list data structure.
3653 * This routine is the worker-thread handler for processing the @ndlp delayed
3654 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3655 * the last ELS command from the associated ndlp and invokes the proper ELS
3656 * function according to the delayed ELS command to retry the command.
3659 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3661 struct lpfc_vport *vport = ndlp->vport;
3662 uint32_t cmd, retry;
3664 spin_lock_irq(&ndlp->lock);
3665 cmd = ndlp->nlp_last_elscmd;
3666 ndlp->nlp_last_elscmd = 0;
3668 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3669 spin_unlock_irq(&ndlp->lock);
3673 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3674 spin_unlock_irq(&ndlp->lock);
3676 * If a discovery event readded nlp_delayfunc after timer
3677 * firing and before processing the timer, cancel the
3680 del_timer_sync(&ndlp->nlp_delayfunc);
3681 retry = ndlp->nlp_retry;
3682 ndlp->nlp_retry = 0;
3686 lpfc_issue_els_flogi(vport, ndlp, retry);
3689 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3690 ndlp->nlp_prev_state = ndlp->nlp_state;
3691 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3695 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3696 ndlp->nlp_prev_state = ndlp->nlp_state;
3697 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3701 case ELS_CMD_NVMEPRLI:
3702 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3703 ndlp->nlp_prev_state = ndlp->nlp_state;
3704 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3708 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3709 ndlp->nlp_prev_state = ndlp->nlp_state;
3710 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3714 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3715 lpfc_issue_els_fdisc(vport, ndlp, retry);
3722 * lpfc_link_reset - Issue link reset
3723 * @vport: pointer to a virtual N_Port data structure.
3725 * This routine performs link reset by sending INIT_LINK mailbox command.
3726 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3727 * INIT_LINK mailbox command.
3730 * 0 - Link reset initiated successfully
3731 * 1 - Failed to initiate link reset
3734 lpfc_link_reset(struct lpfc_vport *vport)
3736 struct lpfc_hba *phba = vport->phba;
3741 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3742 "2851 Attempt link reset\n");
3743 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3745 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3746 "2852 Failed to allocate mbox memory");
3750 /* Enable Link attention interrupts */
3751 if (phba->sli_rev <= LPFC_SLI_REV3) {
3752 spin_lock_irq(&phba->hbalock);
3753 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3754 control = readl(phba->HCregaddr);
3755 control |= HC_LAINT_ENA;
3756 writel(control, phba->HCregaddr);
3757 readl(phba->HCregaddr); /* flush */
3758 spin_unlock_irq(&phba->hbalock);
3761 lpfc_init_link(phba, mbox, phba->cfg_topology,
3762 phba->cfg_link_speed);
3763 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3764 mbox->vport = vport;
3765 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3766 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3767 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3768 "2853 Failed to issue INIT_LINK "
3769 "mbox command, rc:x%x\n", rc);
3770 mempool_free(mbox, phba->mbox_mem_pool);
3778 * lpfc_els_retry - Make retry decision on an els command iocb
3779 * @phba: pointer to lpfc hba data structure.
3780 * @cmdiocb: pointer to lpfc command iocb data structure.
3781 * @rspiocb: pointer to lpfc response iocb data structure.
3783 * This routine makes a retry decision on an ELS command IOCB, which has
3784 * failed. The following ELS IOCBs use this function for retrying the command
3785 * when previously issued command responsed with error status: FLOGI, PLOGI,
3786 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3787 * returned error status, it makes the decision whether a retry shall be
3788 * issued for the command, and whether a retry shall be made immediately or
3789 * delayed. In the former case, the corresponding ELS command issuing-function
3790 * is called to retry the command. In the later case, the ELS command shall
3791 * be posted to the ndlp delayed event and delayed function timer set to the
3792 * ndlp for the delayed command issusing.
3795 * 0 - No retry of els command is made
3796 * 1 - Immediate or delayed retry of els command is made
3799 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3800 struct lpfc_iocbq *rspiocb)
3802 struct lpfc_vport *vport = cmdiocb->vport;
3803 IOCB_t *irsp = &rspiocb->iocb;
3804 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3805 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3808 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3812 int link_reset = 0, rc;
3815 /* Note: context2 may be 0 for internal driver abort
3816 * of delays ELS command.
3819 if (pcmd && pcmd->virt) {
3820 elscmd = (uint32_t *) (pcmd->virt);
3825 did = ndlp->nlp_DID;
3827 /* We should only hit this case for retrying PLOGI */
3828 did = irsp->un.elsreq64.remoteID;
3829 ndlp = lpfc_findnode_did(vport, did);
3830 if (!ndlp && (cmd != ELS_CMD_PLOGI))
3834 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3835 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3836 *(((uint32_t *)irsp) + 7), irsp->un.ulpWord[4], did);
3838 switch (irsp->ulpStatus) {
3839 case IOSTAT_FCP_RSP_ERROR:
3841 case IOSTAT_REMOTE_STOP:
3842 if (phba->sli_rev == LPFC_SLI_REV4) {
3843 /* This IO was aborted by the target, we don't
3844 * know the rxid and because we did not send the
3845 * ABTS we cannot generate and RRQ.
3847 lpfc_set_rrq_active(phba, ndlp,
3848 cmdiocb->sli4_lxritag, 0, 0);
3851 case IOSTAT_LOCAL_REJECT:
3852 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3853 case IOERR_LOOP_OPEN_FAILURE:
3854 if (cmd == ELS_CMD_FLOGI) {
3855 if (PCI_DEVICE_ID_HORNET ==
3856 phba->pcidev->device) {
3857 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3858 phba->pport->fc_myDID = 0;
3859 phba->alpa_map[0] = 0;
3860 phba->alpa_map[1] = 0;
3863 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3868 case IOERR_ILLEGAL_COMMAND:
3869 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3870 "0124 Retry illegal cmd x%x "
3871 "retry:x%x delay:x%x\n",
3872 cmd, cmdiocb->retry, delay);
3874 /* All command's retry policy */
3876 if (cmdiocb->retry > 2)
3880 case IOERR_NO_RESOURCES:
3881 logerr = 1; /* HBA out of resources */
3883 if (cmdiocb->retry > 100)
3888 case IOERR_ILLEGAL_FRAME:
3893 case IOERR_INVALID_RPI:
3894 if (cmd == ELS_CMD_PLOGI &&
3895 did == NameServer_DID) {
3896 /* Continue forever if plogi to */
3897 /* the nameserver fails */
3904 case IOERR_SEQUENCE_TIMEOUT:
3905 if (cmd == ELS_CMD_PLOGI &&
3906 did == NameServer_DID &&
3907 (cmdiocb->retry + 1) == maxretry) {
3908 /* Reset the Link */
3918 case IOSTAT_NPORT_RJT:
3919 case IOSTAT_FABRIC_RJT:
3920 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3926 case IOSTAT_NPORT_BSY:
3927 case IOSTAT_FABRIC_BSY:
3928 logerr = 1; /* Fabric / Remote NPort out of resources */
3933 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3934 /* Added for Vendor specifc support
3935 * Just keep retrying for these Rsn / Exp codes
3937 switch (stat.un.b.lsRjtRsnCode) {
3938 case LSRJT_UNABLE_TPC:
3939 /* The driver has a VALID PLOGI but the rport has
3940 * rejected the PRLI - can't do it now. Delay
3941 * for 1 second and try again.
3943 * However, if explanation is REQ_UNSUPPORTED there's
3944 * no point to retry PRLI.
3946 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3947 stat.un.b.lsRjtRsnCodeExp !=
3948 LSEXP_REQ_UNSUPPORTED) {
3950 maxretry = lpfc_max_els_tries + 1;
3955 /* Legacy bug fix code for targets with PLOGI delays. */
3956 if (stat.un.b.lsRjtRsnCodeExp ==
3957 LSEXP_CMD_IN_PROGRESS) {
3958 if (cmd == ELS_CMD_PLOGI) {
3965 if (stat.un.b.lsRjtRsnCodeExp ==
3966 LSEXP_CANT_GIVE_DATA) {
3967 if (cmd == ELS_CMD_PLOGI) {
3974 if (cmd == ELS_CMD_PLOGI) {
3976 maxretry = lpfc_max_els_tries + 1;
3980 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3981 (cmd == ELS_CMD_FDISC) &&
3982 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3983 lpfc_printf_vlog(vport, KERN_ERR,
3985 "0125 FDISC Failed (x%x). "
3986 "Fabric out of resources\n",
3987 stat.un.lsRjtError);
3988 lpfc_vport_set_state(vport,
3989 FC_VPORT_NO_FABRIC_RSCS);
3993 case LSRJT_LOGICAL_BSY:
3994 if ((cmd == ELS_CMD_PLOGI) ||
3995 (cmd == ELS_CMD_PRLI) ||
3996 (cmd == ELS_CMD_NVMEPRLI)) {
3999 } else if (cmd == ELS_CMD_FDISC) {
4000 /* FDISC retry policy */
4002 if (cmdiocb->retry >= 32)
4008 case LSRJT_LOGICAL_ERR:
4009 /* There are some cases where switches return this
4010 * error when they are not ready and should be returning
4011 * Logical Busy. We should delay every time.
4013 if (cmd == ELS_CMD_FDISC &&
4014 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4018 } else if (cmd == ELS_CMD_FLOGI &&
4019 stat.un.b.lsRjtRsnCodeExp ==
4020 LSEXP_NOTHING_MORE) {
4021 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4023 lpfc_printf_vlog(vport, KERN_ERR,
4025 "0820 FLOGI Failed (x%x). "
4026 "BBCredit Not Supported\n",
4027 stat.un.lsRjtError);
4031 case LSRJT_PROTOCOL_ERR:
4032 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4033 (cmd == ELS_CMD_FDISC) &&
4034 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4035 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4037 lpfc_printf_vlog(vport, KERN_ERR,
4039 "0122 FDISC Failed (x%x). "
4040 "Fabric Detected Bad WWN\n",
4041 stat.un.lsRjtError);
4042 lpfc_vport_set_state(vport,
4043 FC_VPORT_FABRIC_REJ_WWN);
4046 case LSRJT_VENDOR_UNIQUE:
4047 if ((stat.un.b.vendorUnique == 0x45) &&
4048 (cmd == ELS_CMD_FLOGI)) {
4052 case LSRJT_CMD_UNSUPPORTED:
4053 /* lpfc nvmet returns this type of LS_RJT when it
4054 * receives an FCP PRLI because lpfc nvmet only
4055 * support NVME. ELS request is terminated for FCP4
4058 if (stat.un.b.lsRjtRsnCodeExp ==
4059 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4060 spin_lock_irq(&ndlp->lock);
4061 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4062 spin_unlock_irq(&ndlp->lock);
4070 case IOSTAT_INTERMED_RSP:
4079 rc = lpfc_link_reset(vport);
4081 /* Do not give up. Retry PLOGI one more time and attempt
4082 * link reset if PLOGI fails again.
4091 if (did == FDMI_DID)
4094 if ((cmd == ELS_CMD_FLOGI) &&
4095 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4096 !lpfc_error_lost_link(irsp)) {
4097 /* FLOGI retry policy */
4099 /* retry FLOGI forever */
4100 if (phba->link_flag != LS_LOOPBACK_MODE)
4105 if (cmdiocb->retry >= 100)
4107 else if (cmdiocb->retry >= 32)
4109 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4110 /* retry FDISCs every second up to devloss */
4112 maxretry = vport->cfg_devloss_tmo;
4117 if (maxretry && (cmdiocb->retry >= maxretry)) {
4118 phba->fc_stat.elsRetryExceeded++;
4122 if ((vport->load_flag & FC_UNLOADING) != 0)
4127 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4128 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4129 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4131 "2849 Stop retry ELS command "
4132 "x%x to remote NPORT x%x, "
4133 "Data: x%x x%x\n", cmd, did,
4134 cmdiocb->retry, delay);
4139 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4140 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4141 "0107 Retry ELS command x%x to remote "
4142 "NPORT x%x Data: x%x x%x\n",
4143 cmd, did, cmdiocb->retry, delay);
4145 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4146 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4147 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4148 IOERR_NO_RESOURCES))) {
4149 /* Don't reset timer for no resources */
4151 /* If discovery / RSCN timer is running, reset it */
4152 if (timer_pending(&vport->fc_disctmo) ||
4153 (vport->fc_flag & FC_RSCN_MODE))
4154 lpfc_set_disctmo(vport);
4157 phba->fc_stat.elsXmitRetry++;
4158 if (ndlp && delay) {
4159 phba->fc_stat.elsDelayRetry++;
4160 ndlp->nlp_retry = cmdiocb->retry;
4162 /* delay is specified in milliseconds */
4163 mod_timer(&ndlp->nlp_delayfunc,
4164 jiffies + msecs_to_jiffies(delay));
4165 spin_lock_irq(&ndlp->lock);
4166 ndlp->nlp_flag |= NLP_DELAY_TMO;
4167 spin_unlock_irq(&ndlp->lock);
4169 ndlp->nlp_prev_state = ndlp->nlp_state;
4170 if ((cmd == ELS_CMD_PRLI) ||
4171 (cmd == ELS_CMD_NVMEPRLI))
4172 lpfc_nlp_set_state(vport, ndlp,
4173 NLP_STE_PRLI_ISSUE);
4175 lpfc_nlp_set_state(vport, ndlp,
4177 ndlp->nlp_last_elscmd = cmd;
4183 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4186 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4190 ndlp->nlp_prev_state = ndlp->nlp_state;
4191 lpfc_nlp_set_state(vport, ndlp,
4192 NLP_STE_PLOGI_ISSUE);
4194 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4197 ndlp->nlp_prev_state = ndlp->nlp_state;
4198 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4199 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4202 case ELS_CMD_NVMEPRLI:
4203 ndlp->nlp_prev_state = ndlp->nlp_state;
4204 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4205 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4208 ndlp->nlp_prev_state = ndlp->nlp_state;
4209 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4210 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4214 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4216 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4217 "0137 No retry ELS command x%x to remote "
4218 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4219 cmd, did, irsp->ulpStatus,
4220 irsp->un.ulpWord[4]);
4223 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4224 "0108 No retry ELS command x%x to remote "
4225 "NPORT x%x Retried:%d Error:x%x/%x\n",
4226 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4227 irsp->un.ulpWord[4]);
4233 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4234 * @phba: pointer to lpfc hba data structure.
4235 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4237 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4238 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4239 * checks to see whether there is a lpfc DMA buffer associated with the
4240 * response of the command IOCB. If so, it will be released before releasing
4241 * the lpfc DMA buffer associated with the IOCB itself.
4244 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4247 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4249 struct lpfc_dmabuf *buf_ptr;
4251 /* Free the response before processing the command. */
4252 if (!list_empty(&buf_ptr1->list)) {
4253 list_remove_head(&buf_ptr1->list, buf_ptr,
4256 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4259 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4265 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4266 * @phba: pointer to lpfc hba data structure.
4267 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4269 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4270 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4274 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4277 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4279 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4285 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4286 * @phba: pointer to lpfc hba data structure.
4287 * @elsiocb: pointer to lpfc els command iocb data structure.
4289 * This routine frees a command IOCB and its associated resources. The
4290 * command IOCB data structure contains the reference to various associated
4291 * resources, these fields must be set to NULL if the associated reference
4293 * context1 - reference to ndlp
4294 * context2 - reference to cmd
4295 * context2->next - reference to rsp
4296 * context3 - reference to bpl
4298 * It first properly decrements the reference count held on ndlp for the
4299 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4300 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4301 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4302 * adds the DMA buffer the @phba data structure for the delayed release.
4303 * If reference to the Buffer Pointer List (BPL) is present, the
4304 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4305 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4306 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4309 * 0 - Success (currently, always return 0)
4312 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4314 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4316 /* The I/O job is complete. Clear the context1 data. */
4317 elsiocb->context1 = NULL;
4319 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4320 if (elsiocb->context2) {
4321 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4322 /* Firmware could still be in progress of DMAing
4323 * payload, so don't free data buffer till after
4326 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4327 buf_ptr = elsiocb->context2;
4328 elsiocb->context2 = NULL;
4331 spin_lock_irq(&phba->hbalock);
4332 if (!list_empty(&buf_ptr->list)) {
4333 list_remove_head(&buf_ptr->list,
4334 buf_ptr1, struct lpfc_dmabuf,
4336 INIT_LIST_HEAD(&buf_ptr1->list);
4337 list_add_tail(&buf_ptr1->list,
4341 INIT_LIST_HEAD(&buf_ptr->list);
4342 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4344 spin_unlock_irq(&phba->hbalock);
4347 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4348 lpfc_els_free_data(phba, buf_ptr1);
4349 elsiocb->context2 = NULL;
4353 if (elsiocb->context3) {
4354 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4355 lpfc_els_free_bpl(phba, buf_ptr);
4356 elsiocb->context3 = NULL;
4358 lpfc_sli_release_iocbq(phba, elsiocb);
4363 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4364 * @phba: pointer to lpfc hba data structure.
4365 * @cmdiocb: pointer to lpfc command iocb data structure.
4366 * @rspiocb: pointer to lpfc response iocb data structure.
4368 * This routine is the completion callback function to the Logout (LOGO)
4369 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4370 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4371 * release the ndlp if it has the last reference remaining (reference count
4372 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4373 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4374 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4375 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4376 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4377 * IOCB data structure.
4380 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4381 struct lpfc_iocbq *rspiocb)
4383 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4384 struct lpfc_vport *vport = cmdiocb->vport;
4387 irsp = &rspiocb->iocb;
4388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4389 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4390 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4391 /* ACC to LOGO completes to NPort <nlp_DID> */
4392 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4393 "0109 ACC to LOGO completes to NPort x%x refcnt %d"
4394 "Data: x%x x%x x%x\n",
4395 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
4396 ndlp->nlp_state, ndlp->nlp_rpi);
4398 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4399 /* NPort Recovery mode or node is just allocated */
4400 if (!lpfc_nlp_not_used(ndlp)) {
4401 /* If the ndlp is being used by another discovery
4402 * thread, just unregister the RPI.
4404 lpfc_unreg_rpi(vport, ndlp);
4406 /* Indicate the node has already released, should
4407 * not reference to it from within lpfc_els_free_iocb.
4409 cmdiocb->context1 = NULL;
4414 * The driver received a LOGO from the rport and has ACK'd it.
4415 * At this point, the driver is done so release the IOCB
4417 lpfc_els_free_iocb(phba, cmdiocb);
4422 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4423 * @phba: pointer to lpfc hba data structure.
4424 * @pmb: pointer to the driver internal queue element for mailbox command.
4426 * This routine is the completion callback function for unregister default
4427 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4428 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4429 * decrements the ndlp reference count held for this completion callback
4430 * function. After that, it invokes the lpfc_nlp_not_used() to check
4431 * whether there is only one reference left on the ndlp. If so, it will
4432 * perform one more decrement and trigger the release of the ndlp.
4435 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4437 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4438 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4440 pmb->ctx_buf = NULL;
4441 pmb->ctx_ndlp = NULL;
4443 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4445 mempool_free(pmb, phba->mbox_mem_pool);
4447 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4448 "0006 rpi x%x DID:%x flg:%x %d x%px\n",
4449 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4450 kref_read(&ndlp->kref),
4452 /* This is the end of the default RPI cleanup logic for
4453 * this ndlp and it could get released. Clear the nlp_flags to
4454 * prevent any further processing.
4456 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4458 lpfc_nlp_not_used(ndlp);
4465 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4466 * @phba: pointer to lpfc hba data structure.
4467 * @cmdiocb: pointer to lpfc command iocb data structure.
4468 * @rspiocb: pointer to lpfc response iocb data structure.
4470 * This routine is the completion callback function for ELS Response IOCB
4471 * command. In normal case, this callback function just properly sets the
4472 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4473 * field in the command IOCB is not NULL, the referred mailbox command will
4474 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4475 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4476 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4477 * routine shall be invoked trying to release the ndlp if no other threads
4478 * are currently referring it.
4481 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4482 struct lpfc_iocbq *rspiocb)
4484 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4485 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4486 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4489 LPFC_MBOXQ_t *mbox = NULL;
4490 struct lpfc_dmabuf *mp = NULL;
4491 uint32_t ls_rjt = 0;
4493 irsp = &rspiocb->iocb;
4496 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4497 "3177 ELS response failed\n");
4500 if (cmdiocb->context_un.mbox)
4501 mbox = cmdiocb->context_un.mbox;
4503 /* First determine if this is a LS_RJT cmpl. Note, this callback
4504 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4506 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4507 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4508 /* A LS_RJT associated with Default RPI cleanup has its own
4509 * separate code path.
4511 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4515 /* Check to see if link went down during discovery */
4516 if (!ndlp || lpfc_els_chk_latt(vport)) {
4518 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4520 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4523 mempool_free(mbox, phba->mbox_mem_pool);
4525 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4526 if (lpfc_nlp_not_used(ndlp)) {
4528 /* Indicate the node has already released,
4529 * should not reference to it from within
4530 * the routine lpfc_els_free_iocb.
4532 cmdiocb->context1 = NULL;
4537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4538 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4539 irsp->ulpStatus, irsp->un.ulpWord[4],
4540 cmdiocb->iocb.un.elsreq64.remoteID);
4541 /* ELS response tag <ulpIoTag> completes */
4542 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4543 "0110 ELS response tag x%x completes "
4544 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4545 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4546 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4547 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4550 if ((rspiocb->iocb.ulpStatus == 0) &&
4551 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4552 if (!lpfc_unreg_rpi(vport, ndlp) &&
4553 (!(vport->fc_flag & FC_PT2PT))) {
4554 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
4555 lpfc_printf_vlog(vport, KERN_INFO,
4559 "Data: x%x x%x x%x\n",
4566 lpfc_mbuf_free(phba, mp->virt,
4570 mempool_free(mbox, phba->mbox_mem_pool);
4575 /* Increment reference count to ndlp to hold the
4576 * reference to ndlp for the callback function.
4578 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4579 if (!mbox->ctx_ndlp)
4582 mbox->vport = vport;
4583 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4584 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4585 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4588 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4589 ndlp->nlp_prev_state = ndlp->nlp_state;
4590 lpfc_nlp_set_state(vport, ndlp,
4591 NLP_STE_REG_LOGIN_ISSUE);
4594 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4595 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4596 != MBX_NOT_FINISHED)
4599 /* Decrement the ndlp reference count we
4600 * set for this failed mailbox command.
4603 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4605 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4606 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4607 "0138 ELS rsp: Cannot issue reg_login for x%x "
4608 "Data: x%x x%x x%x\n",
4609 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4612 if (lpfc_nlp_not_used(ndlp)) {
4614 /* Indicate node has already been released,
4615 * should not reference to it from within
4616 * the routine lpfc_els_free_iocb.
4618 cmdiocb->context1 = NULL;
4621 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4622 if (!lpfc_error_lost_link(irsp) &&
4623 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4624 if (lpfc_nlp_not_used(ndlp)) {
4626 /* Indicate node has already been
4627 * released, should not reference
4628 * to it from within the routine
4629 * lpfc_els_free_iocb.
4631 cmdiocb->context1 = NULL;
4635 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4637 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4640 mempool_free(mbox, phba->mbox_mem_pool);
4643 if (ndlp && shost) {
4644 spin_lock_irq(&ndlp->lock);
4646 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4647 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4648 spin_unlock_irq(&ndlp->lock);
4650 /* If the node is not being used by another discovery thread,
4651 * and we are sending a reject, we are done with it.
4652 * Release driver reference count here and free associated
4656 if (lpfc_nlp_not_used(ndlp))
4657 /* Indicate node has already been released,
4658 * should not reference to it from within
4659 * the routine lpfc_els_free_iocb.
4661 cmdiocb->context1 = NULL;
4664 /* Release the originating I/O reference. */
4665 lpfc_els_free_iocb(phba, cmdiocb);
4671 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4672 * @vport: pointer to a host virtual N_Port data structure.
4673 * @flag: the els command code to be accepted.
4674 * @oldiocb: pointer to the original lpfc command iocb data structure.
4675 * @ndlp: pointer to a node-list data structure.
4676 * @mbox: pointer to the driver internal queue element for mailbox command.
4678 * This routine prepares and issues an Accept (ACC) response IOCB
4679 * command. It uses the @flag to properly set up the IOCB field for the
4680 * specific ACC response command to be issued and invokes the
4681 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4682 * @mbox pointer is passed in, it will be put into the context_un.mbox
4683 * field of the IOCB for the completion callback function to issue the
4684 * mailbox command to the HBA later when callback is invoked.
4686 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4687 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4688 * will be stored into the context1 field of the IOCB for the completion
4689 * callback function to the corresponding response ELS IOCB command.
4692 * 0 - Successfully issued acc response
4693 * 1 - Failed to issue acc response
4696 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4697 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4700 struct lpfc_hba *phba = vport->phba;
4703 struct lpfc_iocbq *elsiocb;
4705 struct serv_parm *sp;
4708 ELS_PKT *els_pkt_ptr;
4710 oldcmd = &oldiocb->iocb;
4714 cmdsize = sizeof(uint32_t);
4715 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4716 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4718 spin_lock_irq(&ndlp->lock);
4719 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4720 spin_unlock_irq(&ndlp->lock);
4724 icmd = &elsiocb->iocb;
4725 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4726 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4727 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4728 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4729 pcmd += sizeof(uint32_t);
4731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4732 "Issue ACC: did:x%x flg:x%x",
4733 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4737 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4738 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4739 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4743 icmd = &elsiocb->iocb;
4744 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4745 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4746 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4749 elsiocb->context_un.mbox = mbox;
4751 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4752 pcmd += sizeof(uint32_t);
4753 sp = (struct serv_parm *)pcmd;
4755 if (flag == ELS_CMD_FLOGI) {
4756 /* Copy the received service parameters back */
4757 memcpy(sp, &phba->fc_fabparam,
4758 sizeof(struct serv_parm));
4760 /* Clear the F_Port bit */
4763 /* Mark all class service parameters as invalid */
4764 sp->cls1.classValid = 0;
4765 sp->cls2.classValid = 0;
4766 sp->cls3.classValid = 0;
4767 sp->cls4.classValid = 0;
4769 /* Copy our worldwide names */
4770 memcpy(&sp->portName, &vport->fc_sparam.portName,
4771 sizeof(struct lpfc_name));
4772 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4773 sizeof(struct lpfc_name));
4775 memcpy(pcmd, &vport->fc_sparam,
4776 sizeof(struct serv_parm));
4778 sp->cmn.valid_vendor_ver_level = 0;
4779 memset(sp->un.vendorVersion, 0,
4780 sizeof(sp->un.vendorVersion));
4781 sp->cmn.bbRcvSizeMsb &= 0xF;
4783 /* If our firmware supports this feature, convey that
4784 * info to the target using the vendor specific field.
4786 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4787 sp->cmn.valid_vendor_ver_level = 1;
4788 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4790 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4795 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4796 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4799 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4800 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4801 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4805 icmd = &elsiocb->iocb;
4806 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4807 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4808 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4810 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4811 sizeof(uint32_t) + sizeof(PRLO));
4812 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4813 els_pkt_ptr = (ELS_PKT *) pcmd;
4814 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4817 "Issue ACC PRLO: did:x%x flg:x%x",
4818 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4823 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4824 spin_lock_irq(&ndlp->lock);
4825 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4826 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4827 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4828 spin_unlock_irq(&ndlp->lock);
4829 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4831 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4834 phba->fc_stat.elsXmitACC++;
4835 elsiocb->context1 = lpfc_nlp_get(ndlp);
4836 if (!elsiocb->context1) {
4837 lpfc_els_free_iocb(phba, elsiocb);
4841 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4842 if (rc == IOCB_ERROR) {
4843 lpfc_els_free_iocb(phba, elsiocb);
4848 /* Xmit ELS ACC response tag <ulpIoTag> */
4849 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4850 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4851 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4852 "RPI: x%x, fc_flag x%x\n",
4853 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4854 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4855 ndlp->nlp_rpi, vport->fc_flag);
4860 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4861 * @vport: pointer to a virtual N_Port data structure.
4862 * @rejectError: reject response to issue
4863 * @oldiocb: pointer to the original lpfc command iocb data structure.
4864 * @ndlp: pointer to a node-list data structure.
4865 * @mbox: pointer to the driver internal queue element for mailbox command.
4867 * This routine prepares and issue an Reject (RJT) response IOCB
4868 * command. If a @mbox pointer is passed in, it will be put into the
4869 * context_un.mbox field of the IOCB for the completion callback function
4870 * to issue to the HBA later.
4872 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4873 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4874 * will be stored into the context1 field of the IOCB for the completion
4875 * callback function to the reject response ELS IOCB command.
4878 * 0 - Successfully issued reject response
4879 * 1 - Failed to issue reject response
4882 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4883 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4887 struct lpfc_hba *phba = vport->phba;
4890 struct lpfc_iocbq *elsiocb;
4894 cmdsize = 2 * sizeof(uint32_t);
4895 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4896 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4900 icmd = &elsiocb->iocb;
4901 oldcmd = &oldiocb->iocb;
4902 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4903 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4904 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4906 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4907 pcmd += sizeof(uint32_t);
4908 *((uint32_t *) (pcmd)) = rejectError;
4911 elsiocb->context_un.mbox = mbox;
4913 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4914 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4915 "0129 Xmit ELS RJT x%x response tag x%x "
4916 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4918 rejectError, elsiocb->iotag,
4919 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4920 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4921 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4922 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4923 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4925 phba->fc_stat.elsXmitLSRJT++;
4926 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4927 elsiocb->context1 = lpfc_nlp_get(ndlp);
4928 if (!elsiocb->context1) {
4929 lpfc_els_free_iocb(phba, elsiocb);
4933 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4934 if (rc == IOCB_ERROR) {
4935 lpfc_els_free_iocb(phba, elsiocb);
4944 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4945 * @vport: pointer to a virtual N_Port data structure.
4946 * @oldiocb: pointer to the original lpfc command iocb data structure.
4947 * @ndlp: pointer to a node-list data structure.
4949 * This routine prepares and issues an Accept (ACC) response to Address
4950 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4951 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4953 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4954 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4955 * will be stored into the context1 field of the IOCB for the completion
4956 * callback function to the ADISC Accept response ELS IOCB command.
4959 * 0 - Successfully issued acc adisc response
4960 * 1 - Failed to issue adisc acc response
4963 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4964 struct lpfc_nodelist *ndlp)
4966 struct lpfc_hba *phba = vport->phba;
4968 IOCB_t *icmd, *oldcmd;
4969 struct lpfc_iocbq *elsiocb;
4974 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4975 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4976 ndlp->nlp_DID, ELS_CMD_ACC);
4980 icmd = &elsiocb->iocb;
4981 oldcmd = &oldiocb->iocb;
4982 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4983 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4985 /* Xmit ADISC ACC response tag <ulpIoTag> */
4986 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4987 "0130 Xmit ADISC ACC response iotag x%x xri: "
4988 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4989 elsiocb->iotag, elsiocb->iocb.ulpContext,
4990 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4992 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4994 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4995 pcmd += sizeof(uint32_t);
4997 ap = (ADISC *) (pcmd);
4998 ap->hardAL_PA = phba->fc_pref_ALPA;
4999 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5000 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5001 ap->DID = be32_to_cpu(vport->fc_myDID);
5003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5004 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
5005 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5007 phba->fc_stat.elsXmitACC++;
5008 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5009 elsiocb->context1 = lpfc_nlp_get(ndlp);
5010 if (!elsiocb->context1) {
5011 lpfc_els_free_iocb(phba, elsiocb);
5015 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5016 if (rc == IOCB_ERROR) {
5017 lpfc_els_free_iocb(phba, elsiocb);
5022 /* Xmit ELS ACC response tag <ulpIoTag> */
5023 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5024 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5025 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5026 "RPI: x%x, fc_flag x%x\n",
5027 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5028 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5029 ndlp->nlp_rpi, vport->fc_flag);
5034 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5035 * @vport: pointer to a virtual N_Port data structure.
5036 * @oldiocb: pointer to the original lpfc command iocb data structure.
5037 * @ndlp: pointer to a node-list data structure.
5039 * This routine prepares and issues an Accept (ACC) response to Process
5040 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5041 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5043 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5044 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5045 * will be stored into the context1 field of the IOCB for the completion
5046 * callback function to the PRLI Accept response ELS IOCB command.
5049 * 0 - Successfully issued acc prli response
5050 * 1 - Failed to issue acc prli response
5053 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5054 struct lpfc_nodelist *ndlp)
5056 struct lpfc_hba *phba = vport->phba;
5058 struct lpfc_nvme_prli *npr_nvme;
5062 struct lpfc_iocbq *elsiocb;
5065 uint32_t prli_fc4_req, *req_payload;
5066 struct lpfc_dmabuf *req_buf;
5070 /* Need the incoming PRLI payload to determine if the ACC is for an
5071 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5073 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5074 req_payload = (((uint32_t *)req_buf->virt) + 1);
5076 /* PRLI type payload is at byte 3 for FCP or NVME. */
5077 prli_fc4_req = be32_to_cpu(*req_payload);
5078 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5079 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5080 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5081 prli_fc4_req, *((uint32_t *)req_payload));
5083 if (prli_fc4_req == PRLI_FCP_TYPE) {
5084 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5085 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5086 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5087 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5088 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5093 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5094 ndlp->nlp_DID, elsrspcmd);
5098 icmd = &elsiocb->iocb;
5099 oldcmd = &oldiocb->iocb;
5100 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5101 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5103 /* Xmit PRLI ACC response tag <ulpIoTag> */
5104 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5105 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5106 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5107 elsiocb->iotag, elsiocb->iocb.ulpContext,
5108 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5110 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5111 memset(pcmd, 0, cmdsize);
5113 *((uint32_t *)(pcmd)) = elsrspcmd;
5114 pcmd += sizeof(uint32_t);
5116 /* For PRLI, remainder of payload is PRLI parameter page */
5119 if (prli_fc4_req == PRLI_FCP_TYPE) {
5121 * If the remote port is a target and our firmware version
5122 * is 3.20 or later, set the following bits for FC-TAPE
5125 npr = (PRLI *) pcmd;
5126 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5127 (vpd->rev.feaLevelHigh >= 0x02)) {
5128 npr->ConfmComplAllowed = 1;
5130 npr->TaskRetryIdReq = 1;
5132 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5133 npr->estabImagePair = 1;
5134 npr->readXferRdyDis = 1;
5135 npr->ConfmComplAllowed = 1;
5136 npr->prliType = PRLI_FCP_TYPE;
5137 npr->initiatorFunc = 1;
5138 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5139 /* Respond with an NVME PRLI Type */
5140 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5141 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5142 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5143 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5144 if (phba->nvmet_support) {
5145 bf_set(prli_tgt, npr_nvme, 1);
5146 bf_set(prli_disc, npr_nvme, 1);
5147 if (phba->cfg_nvme_enable_fb) {
5148 bf_set(prli_fba, npr_nvme, 1);
5150 /* TBD. Target mode needs to post buffers
5151 * that support the configured first burst
5154 bf_set(prli_fb_sz, npr_nvme,
5155 phba->cfg_nvmet_fb_size);
5158 bf_set(prli_init, npr_nvme, 1);
5161 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5162 "6015 NVME issue PRLI ACC word1 x%08x "
5163 "word4 x%08x word5 x%08x flag x%x, "
5164 "fcp_info x%x nlp_type x%x\n",
5165 npr_nvme->word1, npr_nvme->word4,
5166 npr_nvme->word5, ndlp->nlp_flag,
5167 ndlp->nlp_fcp_info, ndlp->nlp_type);
5168 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5169 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5170 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5172 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5173 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5174 prli_fc4_req, ndlp->nlp_fc4_type,
5177 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5178 "Issue ACC PRLI: did:x%x flg:x%x",
5179 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5181 phba->fc_stat.elsXmitACC++;
5182 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5183 elsiocb->context1 = lpfc_nlp_get(ndlp);
5184 if (!elsiocb->context1) {
5185 lpfc_els_free_iocb(phba, elsiocb);
5189 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5190 if (rc == IOCB_ERROR) {
5191 lpfc_els_free_iocb(phba, elsiocb);
5200 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5201 * @vport: pointer to a virtual N_Port data structure.
5202 * @format: rnid command format.
5203 * @oldiocb: pointer to the original lpfc command iocb data structure.
5204 * @ndlp: pointer to a node-list data structure.
5206 * This routine issues a Request Node Identification Data (RNID) Accept
5207 * (ACC) response. It constructs the RNID ACC response command according to
5208 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5209 * issue the response. Note that this command does not need to hold the ndlp
5210 * reference count for the callback. So, the ndlp reference count taken by
5211 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5212 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5213 * there is no ndlp reference available.
5215 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5216 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5217 * will be stored into the context1 field of the IOCB for the completion
5218 * callback function. However, for the RNID Accept Response ELS command,
5219 * this is undone later by this routine after the IOCB is allocated.
5222 * 0 - Successfully issued acc rnid response
5223 * 1 - Failed to issue acc rnid response
5226 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5227 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5229 struct lpfc_hba *phba = vport->phba;
5231 IOCB_t *icmd, *oldcmd;
5232 struct lpfc_iocbq *elsiocb;
5237 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5238 + (2 * sizeof(struct lpfc_name));
5240 cmdsize += sizeof(RNID_TOP_DISC);
5242 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5243 ndlp->nlp_DID, ELS_CMD_ACC);
5247 icmd = &elsiocb->iocb;
5248 oldcmd = &oldiocb->iocb;
5249 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5250 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5252 /* Xmit RNID ACC response tag <ulpIoTag> */
5253 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5254 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5255 elsiocb->iotag, elsiocb->iocb.ulpContext);
5256 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5257 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5258 pcmd += sizeof(uint32_t);
5260 memset(pcmd, 0, sizeof(RNID));
5261 rn = (RNID *) (pcmd);
5262 rn->Format = format;
5263 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5264 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5265 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5268 rn->SpecificLen = 0;
5270 case RNID_TOPOLOGY_DISC:
5271 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5272 memcpy(&rn->un.topologyDisc.portName,
5273 &vport->fc_portname, sizeof(struct lpfc_name));
5274 rn->un.topologyDisc.unitType = RNID_HBA;
5275 rn->un.topologyDisc.physPort = 0;
5276 rn->un.topologyDisc.attachedNodes = 0;
5280 rn->SpecificLen = 0;
5284 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5285 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
5286 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5288 phba->fc_stat.elsXmitACC++;
5289 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5290 elsiocb->context1 = lpfc_nlp_get(ndlp);
5291 if (!elsiocb->context1) {
5292 lpfc_els_free_iocb(phba, elsiocb);
5296 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5297 if (rc == IOCB_ERROR) {
5298 lpfc_els_free_iocb(phba, elsiocb);
5307 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5308 * @vport: pointer to a virtual N_Port data structure.
5309 * @iocb: pointer to the lpfc command iocb data structure.
5310 * @ndlp: pointer to a node-list data structure.
5315 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5316 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5318 struct lpfc_hba *phba = vport->phba;
5323 struct lpfc_node_rrq *prrq;
5326 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5327 pcmd += sizeof(uint32_t);
5328 rrq = (struct RRQ *)pcmd;
5329 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5330 rxid = bf_get(rrq_rxid, rrq);
5332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5333 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5335 be32_to_cpu(bf_get(rrq_did, rrq)),
5336 bf_get(rrq_oxid, rrq),
5338 iocb->iotag, iocb->iocb.ulpContext);
5340 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5341 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5342 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5343 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5344 xri = bf_get(rrq_oxid, rrq);
5347 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5349 lpfc_clr_rrq_active(phba, xri, prrq);
5354 * lpfc_els_rsp_echo_acc - Issue echo acc response
5355 * @vport: pointer to a virtual N_Port data structure.
5356 * @data: pointer to echo data to return in the accept.
5357 * @oldiocb: pointer to the original lpfc command iocb data structure.
5358 * @ndlp: pointer to a node-list data structure.
5361 * 0 - Successfully issued acc echo response
5362 * 1 - Failed to issue acc echo response
5365 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5366 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5368 struct lpfc_hba *phba = vport->phba;
5369 struct lpfc_iocbq *elsiocb;
5374 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5376 /* The accumulated length can exceed the BPL_SIZE. For
5377 * now, use this as the limit
5379 if (cmdsize > LPFC_BPL_SIZE)
5380 cmdsize = LPFC_BPL_SIZE;
5381 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5382 ndlp->nlp_DID, ELS_CMD_ACC);
5386 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5387 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5389 /* Xmit ECHO ACC response tag <ulpIoTag> */
5390 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5391 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5392 elsiocb->iotag, elsiocb->iocb.ulpContext);
5393 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5394 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5395 pcmd += sizeof(uint32_t);
5396 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5398 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5399 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
5400 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5402 phba->fc_stat.elsXmitACC++;
5403 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5404 elsiocb->context1 = lpfc_nlp_get(ndlp);
5405 if (!elsiocb->context1) {
5406 lpfc_els_free_iocb(phba, elsiocb);
5410 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5411 if (rc == IOCB_ERROR) {
5412 lpfc_els_free_iocb(phba, elsiocb);
5421 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5422 * @vport: pointer to a host virtual N_Port data structure.
5424 * This routine issues Address Discover (ADISC) ELS commands to those
5425 * N_Ports which are in node port recovery state and ADISC has not been issued
5426 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5427 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5428 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5429 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5430 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5431 * IOCBs quit for later pick up. On the other hand, after walking through
5432 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5433 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5434 * no more ADISC need to be sent.
5437 * The number of N_Ports with adisc issued.
5440 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5443 struct lpfc_nodelist *ndlp, *next_ndlp;
5446 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5447 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5448 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5449 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5450 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5451 spin_lock_irq(&ndlp->lock);
5452 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5453 spin_unlock_irq(&ndlp->lock);
5454 ndlp->nlp_prev_state = ndlp->nlp_state;
5455 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5456 lpfc_issue_els_adisc(vport, ndlp, 0);
5458 vport->num_disc_nodes++;
5459 if (vport->num_disc_nodes >=
5460 vport->cfg_discovery_threads) {
5461 spin_lock_irq(shost->host_lock);
5462 vport->fc_flag |= FC_NLP_MORE;
5463 spin_unlock_irq(shost->host_lock);
5468 if (sentadisc == 0) {
5469 spin_lock_irq(shost->host_lock);
5470 vport->fc_flag &= ~FC_NLP_MORE;
5471 spin_unlock_irq(shost->host_lock);
5477 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5478 * @vport: pointer to a host virtual N_Port data structure.
5480 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5481 * which are in node port recovery state, with a @vport. Each time an ELS
5482 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5483 * the per @vport number of discover count (num_disc_nodes) shall be
5484 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5485 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5486 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5487 * later pick up. On the other hand, after walking through all the ndlps with
5488 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5489 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5490 * PLOGI need to be sent.
5493 * The number of N_Ports with plogi issued.
5496 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5498 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5499 struct lpfc_nodelist *ndlp, *next_ndlp;
5502 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5503 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5504 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5505 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5506 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5507 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5508 ndlp->nlp_prev_state = ndlp->nlp_state;
5509 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5510 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5512 vport->num_disc_nodes++;
5513 if (vport->num_disc_nodes >=
5514 vport->cfg_discovery_threads) {
5515 spin_lock_irq(shost->host_lock);
5516 vport->fc_flag |= FC_NLP_MORE;
5517 spin_unlock_irq(shost->host_lock);
5523 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5524 "6452 Discover PLOGI %d flag x%x\n",
5525 sentplogi, vport->fc_flag);
5528 lpfc_set_disctmo(vport);
5531 spin_lock_irq(shost->host_lock);
5532 vport->fc_flag &= ~FC_NLP_MORE;
5533 spin_unlock_irq(shost->host_lock);
5539 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5543 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5544 desc->payload.els_req = word0;
5545 desc->length = cpu_to_be32(sizeof(desc->payload));
5547 return sizeof(struct fc_rdp_link_service_desc);
5551 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5552 uint8_t *page_a0, uint8_t *page_a2)
5554 uint16_t wavelength;
5555 uint16_t temperature;
5561 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5562 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5564 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5566 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5567 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5568 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5569 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5571 if ((trasn_code_byte4->fc_sw_laser) ||
5572 (trasn_code_byte5->fc_sw_laser_sl) ||
5573 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5574 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5575 } else if (trasn_code_byte4->fc_lw_laser) {
5576 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5577 page_a0[SSF_WAVELENGTH_B0];
5578 if (wavelength == SFP_WAVELENGTH_LC1310)
5579 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5580 if (wavelength == SFP_WAVELENGTH_LL1550)
5581 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5583 /* check if its SFP+ */
5584 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5585 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5586 << SFP_FLAG_CT_SHIFT;
5588 /* check if its OPTICAL */
5589 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5590 SFP_FLAG_IS_OPTICAL_PORT : 0)
5591 << SFP_FLAG_IS_OPTICAL_SHIFT;
5593 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5594 page_a2[SFF_TEMPERATURE_B0]);
5595 vcc = (page_a2[SFF_VCC_B1] << 8 |
5596 page_a2[SFF_VCC_B0]);
5597 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5598 page_a2[SFF_TXPOWER_B0]);
5599 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5600 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5601 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5602 page_a2[SFF_RXPOWER_B0]);
5603 desc->sfp_info.temperature = cpu_to_be16(temperature);
5604 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5605 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5606 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5607 desc->sfp_info.vcc = cpu_to_be16(vcc);
5609 desc->sfp_info.flags = cpu_to_be16(flag);
5610 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5612 return sizeof(struct fc_rdp_sfp_desc);
5616 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5621 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5623 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5625 desc->info.port_type = cpu_to_be32(type);
5627 desc->info.link_status.link_failure_cnt =
5628 cpu_to_be32(stat->linkFailureCnt);
5629 desc->info.link_status.loss_of_synch_cnt =
5630 cpu_to_be32(stat->lossSyncCnt);
5631 desc->info.link_status.loss_of_signal_cnt =
5632 cpu_to_be32(stat->lossSignalCnt);
5633 desc->info.link_status.primitive_seq_proto_err =
5634 cpu_to_be32(stat->primSeqErrCnt);
5635 desc->info.link_status.invalid_trans_word =
5636 cpu_to_be32(stat->invalidXmitWord);
5637 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5639 desc->length = cpu_to_be32(sizeof(desc->info));
5641 return sizeof(struct fc_rdp_link_error_status_desc);
5645 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5646 struct lpfc_vport *vport)
5650 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5652 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5653 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5654 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5655 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5656 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5657 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5658 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5660 desc->bbc_info.attached_port_bbc = 0;
5663 desc->bbc_info.rtt = 0;
5664 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5666 return sizeof(struct fc_rdp_bbc_desc);
5670 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5671 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5675 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5677 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5678 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5679 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5680 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5682 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5683 flags |= RDP_OET_HIGH_ALARM;
5684 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5685 flags |= RDP_OET_LOW_ALARM;
5686 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5687 flags |= RDP_OET_HIGH_WARNING;
5688 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5689 flags |= RDP_OET_LOW_WARNING;
5691 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5692 desc->oed_info.function_flags = cpu_to_be32(flags);
5693 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5694 return sizeof(struct fc_rdp_oed_sfp_desc);
5698 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5699 struct fc_rdp_oed_sfp_desc *desc,
5704 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5706 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5707 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5708 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5709 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5711 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5712 flags |= RDP_OET_HIGH_ALARM;
5713 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5714 flags |= RDP_OET_LOW_ALARM;
5715 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5716 flags |= RDP_OET_HIGH_WARNING;
5717 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5718 flags |= RDP_OET_LOW_WARNING;
5720 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5721 desc->oed_info.function_flags = cpu_to_be32(flags);
5722 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5723 return sizeof(struct fc_rdp_oed_sfp_desc);
5727 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5728 struct fc_rdp_oed_sfp_desc *desc,
5733 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5735 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5736 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5737 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5738 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5740 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5741 flags |= RDP_OET_HIGH_ALARM;
5742 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5743 flags |= RDP_OET_LOW_ALARM;
5744 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5745 flags |= RDP_OET_HIGH_WARNING;
5746 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5747 flags |= RDP_OET_LOW_WARNING;
5749 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5750 desc->oed_info.function_flags = cpu_to_be32(flags);
5751 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5752 return sizeof(struct fc_rdp_oed_sfp_desc);
5756 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5757 struct fc_rdp_oed_sfp_desc *desc,
5762 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5764 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5765 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5766 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5767 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5769 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5770 flags |= RDP_OET_HIGH_ALARM;
5771 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5772 flags |= RDP_OET_LOW_ALARM;
5773 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5774 flags |= RDP_OET_HIGH_WARNING;
5775 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5776 flags |= RDP_OET_LOW_WARNING;
5778 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5779 desc->oed_info.function_flags = cpu_to_be32(flags);
5780 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5781 return sizeof(struct fc_rdp_oed_sfp_desc);
5786 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5787 struct fc_rdp_oed_sfp_desc *desc,
5792 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5794 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5795 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5796 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5797 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5799 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5800 flags |= RDP_OET_HIGH_ALARM;
5801 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5802 flags |= RDP_OET_LOW_ALARM;
5803 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5804 flags |= RDP_OET_HIGH_WARNING;
5805 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5806 flags |= RDP_OET_LOW_WARNING;
5808 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5809 desc->oed_info.function_flags = cpu_to_be32(flags);
5810 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5811 return sizeof(struct fc_rdp_oed_sfp_desc);
5815 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5816 uint8_t *page_a0, struct lpfc_vport *vport)
5818 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5819 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5820 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5821 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5822 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5823 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5824 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5825 return sizeof(struct fc_rdp_opd_sfp_desc);
5829 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5831 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5833 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5835 desc->info.CorrectedBlocks =
5836 cpu_to_be32(stat->fecCorrBlkCount);
5837 desc->info.UncorrectableBlocks =
5838 cpu_to_be32(stat->fecUncorrBlkCount);
5840 desc->length = cpu_to_be32(sizeof(desc->info));
5842 return sizeof(struct fc_fec_rdp_desc);
5846 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5848 uint16_t rdp_cap = 0;
5851 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5853 switch (phba->fc_linkspeed) {
5854 case LPFC_LINK_SPEED_1GHZ:
5855 rdp_speed = RDP_PS_1GB;
5857 case LPFC_LINK_SPEED_2GHZ:
5858 rdp_speed = RDP_PS_2GB;
5860 case LPFC_LINK_SPEED_4GHZ:
5861 rdp_speed = RDP_PS_4GB;
5863 case LPFC_LINK_SPEED_8GHZ:
5864 rdp_speed = RDP_PS_8GB;
5866 case LPFC_LINK_SPEED_10GHZ:
5867 rdp_speed = RDP_PS_10GB;
5869 case LPFC_LINK_SPEED_16GHZ:
5870 rdp_speed = RDP_PS_16GB;
5872 case LPFC_LINK_SPEED_32GHZ:
5873 rdp_speed = RDP_PS_32GB;
5875 case LPFC_LINK_SPEED_64GHZ:
5876 rdp_speed = RDP_PS_64GB;
5879 rdp_speed = RDP_PS_UNKNOWN;
5883 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5885 if (phba->lmt & LMT_128Gb)
5886 rdp_cap |= RDP_PS_128GB;
5887 if (phba->lmt & LMT_64Gb)
5888 rdp_cap |= RDP_PS_64GB;
5889 if (phba->lmt & LMT_32Gb)
5890 rdp_cap |= RDP_PS_32GB;
5891 if (phba->lmt & LMT_16Gb)
5892 rdp_cap |= RDP_PS_16GB;
5893 if (phba->lmt & LMT_10Gb)
5894 rdp_cap |= RDP_PS_10GB;
5895 if (phba->lmt & LMT_8Gb)
5896 rdp_cap |= RDP_PS_8GB;
5897 if (phba->lmt & LMT_4Gb)
5898 rdp_cap |= RDP_PS_4GB;
5899 if (phba->lmt & LMT_2Gb)
5900 rdp_cap |= RDP_PS_2GB;
5901 if (phba->lmt & LMT_1Gb)
5902 rdp_cap |= RDP_PS_1GB;
5905 rdp_cap = RDP_CAP_UNKNOWN;
5906 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5907 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5909 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5910 desc->length = cpu_to_be32(sizeof(desc->info));
5911 return sizeof(struct fc_rdp_port_speed_desc);
5915 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5916 struct lpfc_vport *vport)
5919 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5921 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5922 sizeof(desc->port_names.wwnn));
5924 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5925 sizeof(desc->port_names.wwpn));
5927 desc->length = cpu_to_be32(sizeof(desc->port_names));
5928 return sizeof(struct fc_rdp_port_name_desc);
5932 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5933 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5936 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5937 if (vport->fc_flag & FC_FABRIC) {
5938 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5939 sizeof(desc->port_names.wwnn));
5941 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5942 sizeof(desc->port_names.wwpn));
5943 } else { /* Point to Point */
5944 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5945 sizeof(desc->port_names.wwnn));
5947 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5948 sizeof(desc->port_names.wwpn));
5951 desc->length = cpu_to_be32(sizeof(desc->port_names));
5952 return sizeof(struct fc_rdp_port_name_desc);
5956 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5959 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5960 struct lpfc_vport *vport = ndlp->vport;
5961 struct lpfc_iocbq *elsiocb;
5962 struct ulp_bde64 *bpl;
5965 struct ls_rjt *stat;
5966 struct fc_rdp_res_frame *rdp_res;
5967 uint32_t cmdsize, len;
5971 if (status != SUCCESS)
5974 /* This will change once we know the true size of the RDP payload */
5975 cmdsize = sizeof(struct fc_rdp_res_frame);
5977 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5978 lpfc_max_els_tries, rdp_context->ndlp,
5979 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5981 goto free_rdp_context;
5983 icmd = &elsiocb->iocb;
5984 icmd->ulpContext = rdp_context->rx_id;
5985 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5987 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5988 "2171 Xmit RDP response tag x%x xri x%x, "
5989 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5990 elsiocb->iotag, elsiocb->iocb.ulpContext,
5991 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5993 rdp_res = (struct fc_rdp_res_frame *)
5994 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5995 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5996 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5997 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5999 /* Update Alarm and Warning */
6000 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
6001 phba->sfp_alarm |= *flag_ptr;
6002 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6003 phba->sfp_warning |= *flag_ptr;
6005 /* For RDP payload */
6007 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6008 (len + pcmd), ELS_CMD_RDP);
6010 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
6011 rdp_context->page_a0, rdp_context->page_a2);
6012 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6014 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6015 (len + pcmd), &rdp_context->link_stat);
6016 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
6017 (len + pcmd), vport);
6018 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6019 (len + pcmd), vport, ndlp);
6020 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
6021 &rdp_context->link_stat);
6022 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6023 &rdp_context->link_stat, vport);
6024 len += lpfc_rdp_res_oed_temp_desc(phba,
6025 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6026 rdp_context->page_a2);
6027 len += lpfc_rdp_res_oed_voltage_desc(phba,
6028 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6029 rdp_context->page_a2);
6030 len += lpfc_rdp_res_oed_txbias_desc(phba,
6031 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6032 rdp_context->page_a2);
6033 len += lpfc_rdp_res_oed_txpower_desc(phba,
6034 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6035 rdp_context->page_a2);
6036 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6037 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6038 rdp_context->page_a2);
6039 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6040 rdp_context->page_a0, vport);
6042 rdp_res->length = cpu_to_be32(len - 8);
6043 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6045 /* Now that we know the true size of the payload, update the BPL */
6046 bpl = (struct ulp_bde64 *)
6047 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6048 bpl->tus.f.bdeSize = len;
6049 bpl->tus.f.bdeFlags = 0;
6050 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6052 phba->fc_stat.elsXmitACC++;
6053 elsiocb->context1 = lpfc_nlp_get(ndlp);
6054 if (!elsiocb->context1) {
6055 lpfc_els_free_iocb(phba, elsiocb);
6056 goto free_rdp_context;
6059 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6060 if (rc == IOCB_ERROR) {
6061 lpfc_els_free_iocb(phba, elsiocb);
6065 goto free_rdp_context;
6068 cmdsize = 2 * sizeof(uint32_t);
6069 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6070 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6072 goto free_rdp_context;
6074 icmd = &elsiocb->iocb;
6075 icmd->ulpContext = rdp_context->rx_id;
6076 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6077 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6079 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6080 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6081 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6083 phba->fc_stat.elsXmitLSRJT++;
6084 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6085 elsiocb->context1 = lpfc_nlp_get(ndlp);
6086 if (!elsiocb->context1) {
6087 lpfc_els_free_iocb(phba, elsiocb);
6088 goto free_rdp_context;
6091 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6092 if (rc == IOCB_ERROR) {
6093 lpfc_els_free_iocb(phba, elsiocb);
6098 /* This reference put is for the original unsolicited RDP. If the
6099 * iocb prep failed, there is no reference to remove.
6106 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6108 LPFC_MBOXQ_t *mbox = NULL;
6111 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6113 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6114 "7105 failed to allocate mailbox memory");
6118 if (lpfc_sli4_dump_page_a0(phba, mbox))
6119 goto prep_mbox_fail;
6120 mbox->vport = rdp_context->ndlp->vport;
6121 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6122 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6123 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6124 if (rc == MBX_NOT_FINISHED)
6125 goto issue_mbox_fail;
6131 mempool_free(mbox, phba->mbox_mem_pool);
6136 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6137 * @vport: pointer to a host virtual N_Port data structure.
6138 * @cmdiocb: pointer to lpfc command iocb data structure.
6139 * @ndlp: pointer to a node-list data structure.
6141 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6142 * IOCB. First, the payload of the unsolicited RDP is checked.
6143 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6144 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6145 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6146 * gather all data and send RDP response.
6149 * 0 - Sent the acc response
6150 * 1 - Sent the reject response.
6153 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6154 struct lpfc_nodelist *ndlp)
6156 struct lpfc_hba *phba = vport->phba;
6157 struct lpfc_dmabuf *pcmd;
6158 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6159 struct fc_rdp_req_frame *rdp_req;
6160 struct lpfc_rdp_context *rdp_context;
6164 if (phba->sli_rev < LPFC_SLI_REV4 ||
6165 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6166 LPFC_SLI_INTF_IF_TYPE_2) {
6167 rjt_err = LSRJT_UNABLE_TPC;
6168 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6172 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6173 rjt_err = LSRJT_UNABLE_TPC;
6174 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6178 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6179 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6181 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6182 "2422 ELS RDP Request "
6183 "dec len %d tag x%x port_id %d len %d\n",
6184 be32_to_cpu(rdp_req->rdp_des_length),
6185 be32_to_cpu(rdp_req->nport_id_desc.tag),
6186 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6187 be32_to_cpu(rdp_req->nport_id_desc.length));
6189 if (sizeof(struct fc_rdp_nport_desc) !=
6190 be32_to_cpu(rdp_req->rdp_des_length))
6192 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6194 if (RDP_NPORT_ID_SIZE !=
6195 be32_to_cpu(rdp_req->nport_id_desc.length))
6197 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6199 rjt_err = LSRJT_UNABLE_TPC;
6203 cmd = &cmdiocb->iocb;
6204 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6205 if (!rdp_context->ndlp) {
6207 rjt_err = LSRJT_UNABLE_TPC;
6210 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6211 rdp_context->rx_id = cmd->ulpContext;
6212 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6213 if (lpfc_get_rdp_info(phba, rdp_context)) {
6214 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6215 "2423 Unable to send mailbox");
6217 rjt_err = LSRJT_UNABLE_TPC;
6225 rjt_err = LSRJT_LOGICAL_ERR;
6228 memset(&stat, 0, sizeof(stat));
6229 stat.un.b.lsRjtRsnCode = rjt_err;
6230 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6231 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6237 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6242 struct lpfc_iocbq *elsiocb;
6243 struct lpfc_nodelist *ndlp;
6244 struct ls_rjt *stat;
6245 union lpfc_sli4_cfg_shdr *shdr;
6246 struct lpfc_lcb_context *lcb_context;
6247 struct fc_lcb_res_frame *lcb_res;
6248 uint32_t cmdsize, shdr_status, shdr_add_status;
6252 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6253 ndlp = lcb_context->ndlp;
6254 pmb->ctx_ndlp = NULL;
6255 pmb->ctx_buf = NULL;
6257 shdr = (union lpfc_sli4_cfg_shdr *)
6258 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6259 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6260 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6262 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6263 "0194 SET_BEACON_CONFIG mailbox "
6264 "completed with status x%x add_status x%x,"
6265 " mbx status x%x\n",
6266 shdr_status, shdr_add_status, mb->mbxStatus);
6268 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6269 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6270 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6271 mempool_free(pmb, phba->mbox_mem_pool);
6275 mempool_free(pmb, phba->mbox_mem_pool);
6276 cmdsize = sizeof(struct fc_lcb_res_frame);
6277 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6278 lpfc_max_els_tries, ndlp,
6279 ndlp->nlp_DID, ELS_CMD_ACC);
6281 /* Decrement the ndlp reference count from previous mbox command */
6285 goto free_lcb_context;
6287 lcb_res = (struct fc_lcb_res_frame *)
6288 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6290 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6291 icmd = &elsiocb->iocb;
6292 icmd->ulpContext = lcb_context->rx_id;
6293 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6295 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6296 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6297 lcb_res->lcb_sub_command = lcb_context->sub_command;
6298 lcb_res->lcb_type = lcb_context->type;
6299 lcb_res->capability = lcb_context->capability;
6300 lcb_res->lcb_frequency = lcb_context->frequency;
6301 lcb_res->lcb_duration = lcb_context->duration;
6302 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6303 phba->fc_stat.elsXmitACC++;
6305 elsiocb->context1 = lpfc_nlp_get(ndlp);
6306 if (!elsiocb->context1) {
6307 lpfc_els_free_iocb(phba, elsiocb);
6311 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6312 if (rc == IOCB_ERROR) {
6313 lpfc_els_free_iocb(phba, elsiocb);
6321 cmdsize = sizeof(struct fc_lcb_res_frame);
6322 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6323 lpfc_max_els_tries, ndlp,
6324 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6327 goto free_lcb_context;
6329 icmd = &elsiocb->iocb;
6330 icmd->ulpContext = lcb_context->rx_id;
6331 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6332 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6334 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6335 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6336 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6338 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6339 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6341 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6342 phba->fc_stat.elsXmitLSRJT++;
6343 elsiocb->context1 = lpfc_nlp_get(ndlp);
6344 if (!elsiocb->context1) {
6345 lpfc_els_free_iocb(phba, elsiocb);
6346 goto free_lcb_context;
6349 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6350 if (rc == IOCB_ERROR) {
6351 lpfc_els_free_iocb(phba, elsiocb);
6359 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6360 struct lpfc_lcb_context *lcb_context,
6361 uint32_t beacon_state)
6363 struct lpfc_hba *phba = vport->phba;
6364 union lpfc_sli4_cfg_shdr *cfg_shdr;
6365 LPFC_MBOXQ_t *mbox = NULL;
6369 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6373 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6374 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6375 sizeof(struct lpfc_sli4_cfg_mhdr);
6376 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6377 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6378 LPFC_SLI4_MBX_EMBED);
6379 mbox->ctx_ndlp = (void *)lcb_context;
6380 mbox->vport = phba->pport;
6381 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6382 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6383 phba->sli4_hba.physical_port);
6384 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6386 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6389 * Check bv1s bit before issuing the mailbox
6390 * if bv1s == 1, LCB V1 supported
6391 * else, LCB V0 supported
6394 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6395 /* COMMON_SET_BEACON_CONFIG_V1 */
6396 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6397 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6398 bf_set(lpfc_mbx_set_beacon_port_type,
6399 &mbox->u.mqe.un.beacon_config, 0);
6400 bf_set(lpfc_mbx_set_beacon_duration_v1,
6401 &mbox->u.mqe.un.beacon_config,
6402 be16_to_cpu(lcb_context->duration));
6404 /* COMMON_SET_BEACON_CONFIG_V0 */
6405 if (be16_to_cpu(lcb_context->duration) != 0) {
6406 mempool_free(mbox, phba->mbox_mem_pool);
6409 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6410 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6411 bf_set(lpfc_mbx_set_beacon_state,
6412 &mbox->u.mqe.un.beacon_config, beacon_state);
6413 bf_set(lpfc_mbx_set_beacon_port_type,
6414 &mbox->u.mqe.un.beacon_config, 1);
6415 bf_set(lpfc_mbx_set_beacon_duration,
6416 &mbox->u.mqe.un.beacon_config,
6417 be16_to_cpu(lcb_context->duration));
6420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6421 if (rc == MBX_NOT_FINISHED) {
6422 mempool_free(mbox, phba->mbox_mem_pool);
6431 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6432 * @vport: pointer to a host virtual N_Port data structure.
6433 * @cmdiocb: pointer to lpfc command iocb data structure.
6434 * @ndlp: pointer to a node-list data structure.
6436 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6437 * First, the payload of the unsolicited LCB is checked.
6438 * Then based on Subcommand beacon will either turn on or off.
6441 * 0 - Sent the acc response
6442 * 1 - Sent the reject response.
6445 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6446 struct lpfc_nodelist *ndlp)
6448 struct lpfc_hba *phba = vport->phba;
6449 struct lpfc_dmabuf *pcmd;
6451 struct fc_lcb_request_frame *beacon;
6452 struct lpfc_lcb_context *lcb_context;
6453 u8 state, rjt_err = 0;
6456 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6457 lp = (uint8_t *)pcmd->virt;
6458 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6460 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6461 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6462 "type x%x frequency %x duration x%x\n",
6463 lp[0], lp[1], lp[2],
6464 beacon->lcb_command,
6465 beacon->lcb_sub_command,
6467 beacon->lcb_frequency,
6468 be16_to_cpu(beacon->lcb_duration));
6470 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6471 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6472 rjt_err = LSRJT_CMD_UNSUPPORTED;
6476 if (phba->sli_rev < LPFC_SLI_REV4 ||
6477 phba->hba_flag & HBA_FCOE_MODE ||
6478 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6479 LPFC_SLI_INTF_IF_TYPE_2)) {
6480 rjt_err = LSRJT_CMD_UNSUPPORTED;
6484 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6486 rjt_err = LSRJT_UNABLE_TPC;
6490 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6491 lcb_context->sub_command = beacon->lcb_sub_command;
6492 lcb_context->capability = 0;
6493 lcb_context->type = beacon->lcb_type;
6494 lcb_context->frequency = beacon->lcb_frequency;
6495 lcb_context->duration = beacon->lcb_duration;
6496 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6497 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6498 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6499 if (!lcb_context->ndlp) {
6500 rjt_err = LSRJT_UNABLE_TPC;
6504 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6505 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6506 "0193 failed to send mail box");
6508 rjt_err = LSRJT_UNABLE_TPC;
6516 memset(&stat, 0, sizeof(stat));
6517 stat.un.b.lsRjtRsnCode = rjt_err;
6518 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6524 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6525 * @vport: pointer to a host virtual N_Port data structure.
6527 * This routine cleans up any Registration State Change Notification
6528 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6529 * @vport together with the host_lock is used to prevent multiple thread
6530 * trying to access the RSCN array on a same @vport at the same time.
6533 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6535 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6536 struct lpfc_hba *phba = vport->phba;
6539 spin_lock_irq(shost->host_lock);
6540 if (vport->fc_rscn_flush) {
6541 /* Another thread is walking fc_rscn_id_list on this vport */
6542 spin_unlock_irq(shost->host_lock);
6545 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6546 vport->fc_rscn_flush = 1;
6547 spin_unlock_irq(shost->host_lock);
6549 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6550 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6551 vport->fc_rscn_id_list[i] = NULL;
6553 spin_lock_irq(shost->host_lock);
6554 vport->fc_rscn_id_cnt = 0;
6555 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6556 spin_unlock_irq(shost->host_lock);
6557 lpfc_can_disctmo(vport);
6558 /* Indicate we are done walking this fc_rscn_id_list */
6559 vport->fc_rscn_flush = 0;
6563 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6564 * @vport: pointer to a host virtual N_Port data structure.
6565 * @did: remote destination port identifier.
6567 * This routine checks whether there is any pending Registration State
6568 * Configuration Notification (RSCN) to a @did on @vport.
6571 * None zero - The @did matched with a pending rscn
6572 * 0 - not able to match @did with a pending rscn
6575 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6580 uint32_t payload_len, i;
6581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6583 ns_did.un.word = did;
6585 /* Never match fabric nodes for RSCNs */
6586 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6589 /* If we are doing a FULL RSCN rediscovery, match everything */
6590 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6593 spin_lock_irq(shost->host_lock);
6594 if (vport->fc_rscn_flush) {
6595 /* Another thread is walking fc_rscn_id_list on this vport */
6596 spin_unlock_irq(shost->host_lock);
6599 /* Indicate we are walking fc_rscn_id_list on this vport */
6600 vport->fc_rscn_flush = 1;
6601 spin_unlock_irq(shost->host_lock);
6602 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6603 lp = vport->fc_rscn_id_list[i]->virt;
6604 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6605 payload_len -= sizeof(uint32_t); /* take off word 0 */
6606 while (payload_len) {
6607 rscn_did.un.word = be32_to_cpu(*lp++);
6608 payload_len -= sizeof(uint32_t);
6609 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6610 case RSCN_ADDRESS_FORMAT_PORT:
6611 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6612 && (ns_did.un.b.area == rscn_did.un.b.area)
6613 && (ns_did.un.b.id == rscn_did.un.b.id))
6614 goto return_did_out;
6616 case RSCN_ADDRESS_FORMAT_AREA:
6617 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6618 && (ns_did.un.b.area == rscn_did.un.b.area))
6619 goto return_did_out;
6621 case RSCN_ADDRESS_FORMAT_DOMAIN:
6622 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6623 goto return_did_out;
6625 case RSCN_ADDRESS_FORMAT_FABRIC:
6626 goto return_did_out;
6630 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6631 vport->fc_rscn_flush = 0;
6634 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6635 vport->fc_rscn_flush = 0;
6640 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6641 * @vport: pointer to a host virtual N_Port data structure.
6643 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6644 * state machine for a @vport's nodes that are with pending RSCN (Registration
6645 * State Change Notification).
6648 * 0 - Successful (currently alway return 0)
6651 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6653 struct lpfc_nodelist *ndlp = NULL;
6655 /* Move all affected nodes by pending RSCNs to NPR state. */
6656 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6657 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6658 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6661 /* NVME Target mode does not do RSCN Recovery. */
6662 if (vport->phba->nvmet_support)
6665 /* If we are in the process of doing discovery on this
6666 * NPort, let it continue on its own.
6668 switch (ndlp->nlp_state) {
6669 case NLP_STE_PLOGI_ISSUE:
6670 case NLP_STE_ADISC_ISSUE:
6671 case NLP_STE_REG_LOGIN_ISSUE:
6672 case NLP_STE_PRLI_ISSUE:
6673 case NLP_STE_LOGO_ISSUE:
6677 /* Check to see if we need to NVME rescan this target
6680 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6681 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6682 lpfc_nvme_rescan_port(vport, ndlp);
6684 lpfc_disc_state_machine(vport, ndlp, NULL,
6685 NLP_EVT_DEVICE_RECOVERY);
6686 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6692 * lpfc_send_rscn_event - Send an RSCN event to management application
6693 * @vport: pointer to a host virtual N_Port data structure.
6694 * @cmdiocb: pointer to lpfc command iocb data structure.
6696 * lpfc_send_rscn_event sends an RSCN netlink event to management
6700 lpfc_send_rscn_event(struct lpfc_vport *vport,
6701 struct lpfc_iocbq *cmdiocb)
6703 struct lpfc_dmabuf *pcmd;
6704 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6705 uint32_t *payload_ptr;
6706 uint32_t payload_len;
6707 struct lpfc_rscn_event_header *rscn_event_data;
6709 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6710 payload_ptr = (uint32_t *) pcmd->virt;
6711 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6713 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6714 payload_len, GFP_KERNEL);
6715 if (!rscn_event_data) {
6716 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6717 "0147 Failed to allocate memory for RSCN event\n");
6720 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6721 rscn_event_data->payload_length = payload_len;
6722 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6725 fc_host_post_vendor_event(shost,
6726 fc_get_event_number(),
6727 sizeof(struct lpfc_rscn_event_header) + payload_len,
6728 (char *)rscn_event_data,
6731 kfree(rscn_event_data);
6735 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6736 * @vport: pointer to a host virtual N_Port data structure.
6737 * @cmdiocb: pointer to lpfc command iocb data structure.
6738 * @ndlp: pointer to a node-list data structure.
6740 * This routine processes an unsolicited RSCN (Registration State Change
6741 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6742 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6743 * discover state machine is about to begin discovery, it just accepts the
6744 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6745 * contains N_Port IDs for other vports on this HBA, it just accepts the
6746 * RSCN and ignore processing it. If the state machine is in the recovery
6747 * state, the fc_rscn_id_list of this @vport is walked and the
6748 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6749 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6750 * routine is invoked to handle the RSCN event.
6753 * 0 - Just sent the acc response
6754 * 1 - Sent the acc response and waited for name server completion
6757 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6758 struct lpfc_nodelist *ndlp)
6760 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6761 struct lpfc_hba *phba = vport->phba;
6762 struct lpfc_dmabuf *pcmd;
6763 uint32_t *lp, *datap;
6764 uint32_t payload_len, length, nportid, *cmd;
6766 int rscn_id = 0, hba_id = 0;
6769 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6770 lp = (uint32_t *) pcmd->virt;
6772 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6773 payload_len -= sizeof(uint32_t); /* take off word 0 */
6775 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6776 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6777 vport->fc_flag, payload_len, *lp,
6778 vport->fc_rscn_id_cnt);
6780 /* Send an RSCN event to the management application */
6781 lpfc_send_rscn_event(vport, cmdiocb);
6783 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6784 fc_host_post_event(shost, fc_get_event_number(),
6785 FCH_EVT_RSCN, lp[i]);
6787 /* Check if RSCN is coming from a direct-connected remote NPort */
6788 if (vport->fc_flag & FC_PT2PT) {
6789 /* If so, just ACC it, no other action needed for now */
6790 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6791 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6792 *lp, vport->fc_flag, payload_len);
6793 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6795 /* Check to see if we need to NVME rescan this target
6798 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6799 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6800 lpfc_nvme_rescan_port(vport, ndlp);
6804 /* If we are about to begin discovery, just ACC the RSCN.
6805 * Discovery processing will satisfy it.
6807 if (vport->port_state <= LPFC_NS_QRY) {
6808 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6809 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6810 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6812 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6816 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6817 * just ACC and ignore it.
6819 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6820 !(vport->cfg_peer_port_login)) {
6825 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6826 i -= sizeof(uint32_t);
6828 if (lpfc_find_vport_by_did(phba, nportid))
6831 if (rscn_id == hba_id) {
6832 /* ALL NPortIDs in RSCN are on HBA */
6833 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6835 "Data: x%x x%x x%x x%x\n",
6836 vport->fc_flag, payload_len,
6837 *lp, vport->fc_rscn_id_cnt);
6838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6839 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6840 ndlp->nlp_DID, vport->port_state,
6843 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6849 spin_lock_irq(shost->host_lock);
6850 if (vport->fc_rscn_flush) {
6851 /* Another thread is walking fc_rscn_id_list on this vport */
6852 vport->fc_flag |= FC_RSCN_DISCOVERY;
6853 spin_unlock_irq(shost->host_lock);
6855 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6858 /* Indicate we are walking fc_rscn_id_list on this vport */
6859 vport->fc_rscn_flush = 1;
6860 spin_unlock_irq(shost->host_lock);
6861 /* Get the array count after successfully have the token */
6862 rscn_cnt = vport->fc_rscn_id_cnt;
6863 /* If we are already processing an RSCN, save the received
6864 * RSCN payload buffer, cmdiocb->context2 to process later.
6866 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6868 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6869 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6871 spin_lock_irq(shost->host_lock);
6872 vport->fc_flag |= FC_RSCN_DEFERRED;
6874 /* Restart disctmo if its already running */
6875 if (vport->fc_flag & FC_DISC_TMO) {
6876 tmo = ((phba->fc_ratov * 3) + 3);
6877 mod_timer(&vport->fc_disctmo,
6878 jiffies + msecs_to_jiffies(1000 * tmo));
6880 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6881 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6882 vport->fc_flag |= FC_RSCN_MODE;
6883 spin_unlock_irq(shost->host_lock);
6885 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6886 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6889 (payload_len + length <= LPFC_BPL_SIZE)) {
6890 *cmd &= ELS_CMD_MASK;
6891 *cmd |= cpu_to_be32(payload_len + length);
6892 memcpy(((uint8_t *)cmd) + length, lp,
6895 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6896 vport->fc_rscn_id_cnt++;
6897 /* If we zero, cmdiocb->context2, the calling
6898 * routine will not try to free it.
6900 cmdiocb->context2 = NULL;
6903 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6904 "0235 Deferred RSCN "
6905 "Data: x%x x%x x%x\n",
6906 vport->fc_rscn_id_cnt, vport->fc_flag,
6909 vport->fc_flag |= FC_RSCN_DISCOVERY;
6910 spin_unlock_irq(shost->host_lock);
6911 /* ReDiscovery RSCN */
6912 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6913 "0234 ReDiscovery RSCN "
6914 "Data: x%x x%x x%x\n",
6915 vport->fc_rscn_id_cnt, vport->fc_flag,
6918 /* Indicate we are done walking fc_rscn_id_list on this vport */
6919 vport->fc_rscn_flush = 0;
6921 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6922 /* send RECOVERY event for ALL nodes that match RSCN payload */
6923 lpfc_rscn_recovery_check(vport);
6926 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6927 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6928 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6930 spin_lock_irq(shost->host_lock);
6931 vport->fc_flag |= FC_RSCN_MODE;
6932 spin_unlock_irq(shost->host_lock);
6933 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6934 /* Indicate we are done walking fc_rscn_id_list on this vport */
6935 vport->fc_rscn_flush = 0;
6937 * If we zero, cmdiocb->context2, the calling routine will
6938 * not try to free it.
6940 cmdiocb->context2 = NULL;
6941 lpfc_set_disctmo(vport);
6943 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6944 /* send RECOVERY event for ALL nodes that match RSCN payload */
6945 lpfc_rscn_recovery_check(vport);
6946 return lpfc_els_handle_rscn(vport);
6950 * lpfc_els_handle_rscn - Handle rscn for a vport
6951 * @vport: pointer to a host virtual N_Port data structure.
6953 * This routine handles the Registration State Configuration Notification
6954 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6955 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6956 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6957 * NameServer shall be issued. If CT command to the NameServer fails to be
6958 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6959 * RSCN activities with the @vport.
6962 * 0 - Cleaned up rscn on the @vport
6963 * 1 - Wait for plogi to name server before proceed
6966 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6968 struct lpfc_nodelist *ndlp;
6969 struct lpfc_hba *phba = vport->phba;
6971 /* Ignore RSCN if the port is being torn down. */
6972 if (vport->load_flag & FC_UNLOADING) {
6973 lpfc_els_flush_rscn(vport);
6977 /* Start timer for RSCN processing */
6978 lpfc_set_disctmo(vport);
6980 /* RSCN processed */
6981 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6982 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
6983 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6984 vport->port_state, vport->num_disc_nodes,
6987 /* To process RSCN, first compare RSCN data with NameServer */
6988 vport->fc_ns_retry = 0;
6989 vport->num_disc_nodes = 0;
6991 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6992 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6993 /* Good ndlp, issue CT Request to NameServer. Need to
6994 * know how many gidfts were issued. If none, then just
6995 * flush the RSCN. Otherwise, the outstanding requests
6998 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6999 if (lpfc_issue_gidft(vport) > 0)
7001 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
7002 if (lpfc_issue_gidpt(vport) > 0)
7008 /* Nameserver login in question. Revalidate. */
7010 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
7011 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7013 ndlp = lpfc_nlp_init(vport, NameServer_DID);
7015 lpfc_els_flush_rscn(vport);
7018 ndlp->nlp_prev_state = ndlp->nlp_state;
7019 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7021 ndlp->nlp_type |= NLP_FABRIC;
7022 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
7023 /* Wait for NameServer login cmpl before we can
7029 lpfc_els_flush_rscn(vport);
7034 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
7035 * @vport: pointer to a host virtual N_Port data structure.
7036 * @cmdiocb: pointer to lpfc command iocb data structure.
7037 * @ndlp: pointer to a node-list data structure.
7039 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
7040 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
7041 * point topology. As an unsolicited FLOGI should not be received in a loop
7042 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7043 * lpfc_check_sparm() routine is invoked to check the parameters in the
7044 * unsolicited FLOGI. If parameters validation failed, the routine
7045 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7046 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7047 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7048 * will initiate PLOGI. The higher lexicographical value party shall has
7049 * higher priority (as the winning port) and will initiate PLOGI and
7050 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7051 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7052 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7055 * 0 - Successfully processed the unsolicited flogi
7056 * 1 - Failed to process the unsolicited flogi
7059 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7060 struct lpfc_nodelist *ndlp)
7062 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7063 struct lpfc_hba *phba = vport->phba;
7064 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7065 uint32_t *lp = (uint32_t *) pcmd->virt;
7066 IOCB_t *icmd = &cmdiocb->iocb;
7067 struct serv_parm *sp;
7071 uint32_t fc_flag = 0;
7072 uint32_t port_state = 0;
7075 sp = (struct serv_parm *) lp;
7077 /* FLOGI received */
7079 lpfc_set_disctmo(vport);
7081 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7082 /* We should never receive a FLOGI in loop mode, ignore it */
7083 did = icmd->un.elsreq64.remoteID;
7085 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7087 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7088 "0113 An FLOGI ELS command x%x was "
7089 "received from DID x%x in Loop Mode\n",
7094 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7097 * If our portname is greater than the remote portname,
7098 * then we initiate Nport login.
7101 rc = memcmp(&vport->fc_portname, &sp->portName,
7102 sizeof(struct lpfc_name));
7105 if (phba->sli_rev < LPFC_SLI_REV4) {
7106 mbox = mempool_alloc(phba->mbox_mem_pool,
7110 lpfc_linkdown(phba);
7111 lpfc_init_link(phba, mbox,
7113 phba->cfg_link_speed);
7114 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7115 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7116 mbox->vport = vport;
7117 rc = lpfc_sli_issue_mbox(phba, mbox,
7119 lpfc_set_loopback_flag(phba);
7120 if (rc == MBX_NOT_FINISHED)
7121 mempool_free(mbox, phba->mbox_mem_pool);
7125 /* abort the flogi coming back to ourselves
7126 * due to external loopback on the port.
7128 lpfc_els_abort_flogi(phba);
7131 } else if (rc > 0) { /* greater than */
7132 spin_lock_irq(shost->host_lock);
7133 vport->fc_flag |= FC_PT2PT_PLOGI;
7134 spin_unlock_irq(shost->host_lock);
7136 /* If we have the high WWPN we can assign our own
7137 * myDID; otherwise, we have to WAIT for a PLOGI
7138 * from the remote NPort to find out what it
7141 vport->fc_myDID = PT2PT_LocalID;
7143 vport->fc_myDID = PT2PT_RemoteID;
7147 * The vport state should go to LPFC_FLOGI only
7148 * AFTER we issue a FLOGI, not receive one.
7150 spin_lock_irq(shost->host_lock);
7151 fc_flag = vport->fc_flag;
7152 port_state = vport->port_state;
7153 vport->fc_flag |= FC_PT2PT;
7154 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7156 /* Acking an unsol FLOGI. Count 1 for link bounce
7159 vport->rcv_flogi_cnt++;
7160 spin_unlock_irq(shost->host_lock);
7161 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7162 "3311 Rcv Flogi PS x%x new PS x%x "
7163 "fc_flag x%x new fc_flag x%x\n",
7164 port_state, vport->port_state,
7165 fc_flag, vport->fc_flag);
7168 * We temporarily set fc_myDID to make it look like we are
7169 * a Fabric. This is done just so we end up with the right
7170 * did / sid on the FLOGI ACC rsp.
7172 did = vport->fc_myDID;
7173 vport->fc_myDID = Fabric_DID;
7175 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7177 /* Defer ACC response until AFTER we issue a FLOGI */
7178 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7179 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7180 phba->defer_flogi_acc_ox_id =
7181 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7183 vport->fc_myDID = did;
7185 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7186 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7187 " ox_id: x%x, hba_flag x%x\n",
7188 phba->defer_flogi_acc_rx_id,
7189 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7191 phba->defer_flogi_acc_flag = true;
7197 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7199 /* Now lets put fc_myDID back to what its supposed to be */
7200 vport->fc_myDID = did;
7206 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7207 * @vport: pointer to a host virtual N_Port data structure.
7208 * @cmdiocb: pointer to lpfc command iocb data structure.
7209 * @ndlp: pointer to a node-list data structure.
7211 * This routine processes Request Node Identification Data (RNID) IOCB
7212 * received as an ELS unsolicited event. Only when the RNID specified format
7213 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7214 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7215 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7216 * rejected by invoking the lpfc_els_rsp_reject() routine.
7219 * 0 - Successfully processed rnid iocb (currently always return 0)
7222 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7223 struct lpfc_nodelist *ndlp)
7225 struct lpfc_dmabuf *pcmd;
7230 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7231 lp = (uint32_t *) pcmd->virt;
7238 switch (rn->Format) {
7240 case RNID_TOPOLOGY_DISC:
7242 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7245 /* Reject this request because format not supported */
7246 stat.un.b.lsRjtRsvd0 = 0;
7247 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7248 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7249 stat.un.b.vendorUnique = 0;
7250 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7257 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7258 * @vport: pointer to a host virtual N_Port data structure.
7259 * @cmdiocb: pointer to lpfc command iocb data structure.
7260 * @ndlp: pointer to a node-list data structure.
7263 * 0 - Successfully processed echo iocb (currently always return 0)
7266 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7267 struct lpfc_nodelist *ndlp)
7271 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7273 /* skip over first word of echo command to find echo data */
7274 pcmd += sizeof(uint32_t);
7276 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7281 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7282 * @vport: pointer to a host virtual N_Port data structure.
7283 * @cmdiocb: pointer to lpfc command iocb data structure.
7284 * @ndlp: pointer to a node-list data structure.
7286 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7287 * received as an ELS unsolicited event. Currently, this function just invokes
7288 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7291 * 0 - Successfully processed lirr iocb (currently always return 0)
7294 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7295 struct lpfc_nodelist *ndlp)
7299 /* For now, unconditionally reject this command */
7300 stat.un.b.lsRjtRsvd0 = 0;
7301 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7302 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7303 stat.un.b.vendorUnique = 0;
7304 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7309 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7310 * @vport: pointer to a host virtual N_Port data structure.
7311 * @cmdiocb: pointer to lpfc command iocb data structure.
7312 * @ndlp: pointer to a node-list data structure.
7314 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7315 * received as an ELS unsolicited event. A request to RRQ shall only
7316 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7317 * Nx_Port N_Port_ID of the target Exchange is the same as the
7318 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7319 * not accepted, an LS_RJT with reason code "Unable to perform
7320 * command request" and reason code explanation "Invalid Originator
7321 * S_ID" shall be returned. For now, we just unconditionally accept
7322 * RRQ from the target.
7325 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7326 struct lpfc_nodelist *ndlp)
7328 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7329 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7330 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7334 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7335 * @phba: pointer to lpfc hba data structure.
7336 * @pmb: pointer to the driver internal queue element for mailbox command.
7338 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7339 * mailbox command. This callback function is to actually send the Accept
7340 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7341 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7342 * mailbox command, constructs the RPS response with the link statistics
7343 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7344 * response to the RPS.
7346 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7347 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7348 * will be stored into the context1 field of the IOCB for the completion
7349 * callback function to the RPS Accept Response ELS IOCB command.
7353 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7358 struct RLS_RSP *rls_rsp;
7360 struct lpfc_iocbq *elsiocb;
7361 struct lpfc_nodelist *ndlp;
7368 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7369 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7370 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7371 pmb->ctx_buf = NULL;
7372 pmb->ctx_ndlp = NULL;
7374 if (mb->mbxStatus) {
7375 mempool_free(pmb, phba->mbox_mem_pool);
7379 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7380 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7381 lpfc_max_els_tries, ndlp,
7382 ndlp->nlp_DID, ELS_CMD_ACC);
7384 /* Decrement the ndlp reference count from previous mbox command */
7388 mempool_free(pmb, phba->mbox_mem_pool);
7392 icmd = &elsiocb->iocb;
7393 icmd->ulpContext = rxid;
7394 icmd->unsli3.rcvsli3.ox_id = oxid;
7396 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7397 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7398 pcmd += sizeof(uint32_t); /* Skip past command */
7399 rls_rsp = (struct RLS_RSP *)pcmd;
7401 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7402 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7403 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7404 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7405 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7406 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7407 mempool_free(pmb, phba->mbox_mem_pool);
7408 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7409 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7410 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7411 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7412 elsiocb->iotag, elsiocb->iocb.ulpContext,
7413 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7415 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7416 phba->fc_stat.elsXmitACC++;
7417 elsiocb->context1 = lpfc_nlp_get(ndlp);
7418 if (!elsiocb->context1) {
7419 lpfc_els_free_iocb(phba, elsiocb);
7423 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7424 if (rc == IOCB_ERROR) {
7425 lpfc_els_free_iocb(phba, elsiocb);
7432 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7433 * @vport: pointer to a host virtual N_Port data structure.
7434 * @cmdiocb: pointer to lpfc command iocb data structure.
7435 * @ndlp: pointer to a node-list data structure.
7437 * This routine processes Read Link Status (RLS) IOCB received as an
7438 * ELS unsolicited event. It first checks the remote port state. If the
7439 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7440 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7441 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7442 * for reading the HBA link statistics. It is for the callback function,
7443 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7444 * to actually sending out RPL Accept (ACC) response.
7447 * 0 - Successfully processed rls iocb (currently always return 0)
7450 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7451 struct lpfc_nodelist *ndlp)
7453 struct lpfc_hba *phba = vport->phba;
7457 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7458 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7459 /* reject the unsolicited RLS request and done with it */
7462 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7464 lpfc_read_lnk_stat(phba, mbox);
7465 mbox->ctx_buf = (void *)((unsigned long)
7466 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7467 cmdiocb->iocb.ulpContext)); /* rx_id */
7468 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7469 if (!mbox->ctx_ndlp)
7471 mbox->vport = vport;
7472 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7473 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7474 != MBX_NOT_FINISHED)
7475 /* Mbox completion will send ELS Response */
7477 /* Decrement reference count used for the failed mbox
7482 mempool_free(mbox, phba->mbox_mem_pool);
7485 /* issue rejection response */
7486 stat.un.b.lsRjtRsvd0 = 0;
7487 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7488 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7489 stat.un.b.vendorUnique = 0;
7490 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7495 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7496 * @vport: pointer to a host virtual N_Port data structure.
7497 * @cmdiocb: pointer to lpfc command iocb data structure.
7498 * @ndlp: pointer to a node-list data structure.
7500 * This routine processes Read Timout Value (RTV) IOCB received as an
7501 * ELS unsolicited event. It first checks the remote port state. If the
7502 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7503 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7504 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7505 * Value (RTV) unsolicited IOCB event.
7507 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7508 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7509 * will be stored into the context1 field of the IOCB for the completion
7510 * callback function to the RTV Accept Response ELS IOCB command.
7513 * 0 - Successfully processed rtv iocb (currently always return 0)
7516 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7517 struct lpfc_nodelist *ndlp)
7520 struct lpfc_hba *phba = vport->phba;
7522 struct RTV_RSP *rtv_rsp;
7524 struct lpfc_iocbq *elsiocb;
7528 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7529 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7530 /* reject the unsolicited RTV request and done with it */
7533 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7534 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7535 lpfc_max_els_tries, ndlp,
7536 ndlp->nlp_DID, ELS_CMD_ACC);
7541 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7542 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7543 pcmd += sizeof(uint32_t); /* Skip past command */
7545 /* use the command's xri in the response */
7546 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7547 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7549 rtv_rsp = (struct RTV_RSP *)pcmd;
7551 /* populate RTV payload */
7552 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7553 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7554 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7555 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7556 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7558 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7559 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7560 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7561 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7562 "Data: x%x x%x x%x\n",
7563 elsiocb->iotag, elsiocb->iocb.ulpContext,
7564 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7566 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7567 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7568 phba->fc_stat.elsXmitACC++;
7569 elsiocb->context1 = lpfc_nlp_get(ndlp);
7570 if (!elsiocb->context1) {
7571 lpfc_els_free_iocb(phba, elsiocb);
7575 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7576 if (rc == IOCB_ERROR) {
7577 lpfc_els_free_iocb(phba, elsiocb);
7583 /* issue rejection response */
7584 stat.un.b.lsRjtRsvd0 = 0;
7585 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7586 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7587 stat.un.b.vendorUnique = 0;
7588 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7592 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7593 * @vport: pointer to a host virtual N_Port data structure.
7594 * @ndlp: pointer to a node-list data structure.
7595 * @did: DID of the target.
7596 * @rrq: Pointer to the rrq struct.
7598 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7599 * Successful the the completion handler will clear the RRQ.
7602 * 0 - Successfully sent rrq els iocb.
7603 * 1 - Failed to send rrq els iocb.
7606 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7607 uint32_t did, struct lpfc_node_rrq *rrq)
7609 struct lpfc_hba *phba = vport->phba;
7610 struct RRQ *els_rrq;
7611 struct lpfc_iocbq *elsiocb;
7619 /* If ndlp is not NULL, we will bump the reference count on it */
7620 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7621 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7626 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7628 /* For RRQ request, remainder of payload is Exchange IDs */
7629 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7630 pcmd += sizeof(uint32_t);
7631 els_rrq = (struct RRQ *) pcmd;
7633 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7634 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7635 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7636 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7637 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7641 "Issue RRQ: did:x%x",
7642 did, rrq->xritag, rrq->rxid);
7643 elsiocb->context_un.rrq = rrq;
7644 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7647 elsiocb->context1 = ndlp;
7649 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7650 if (ret == IOCB_ERROR)
7655 lpfc_els_free_iocb(phba, elsiocb);
7661 * lpfc_send_rrq - Sends ELS RRQ if needed.
7662 * @phba: pointer to lpfc hba data structure.
7663 * @rrq: pointer to the active rrq.
7665 * This routine will call the lpfc_issue_els_rrq if the rrq is
7666 * still active for the xri. If this function returns a failure then
7667 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7669 * Returns 0 Success.
7673 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7675 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7680 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7681 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7688 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7689 * @vport: pointer to a host virtual N_Port data structure.
7690 * @cmdsize: size of the ELS command.
7691 * @oldiocb: pointer to the original lpfc command iocb data structure.
7692 * @ndlp: pointer to a node-list data structure.
7694 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7695 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7697 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7698 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7699 * will be stored into the context1 field of the IOCB for the completion
7700 * callback function to the RPL Accept Response ELS command.
7703 * 0 - Successfully issued ACC RPL ELS command
7704 * 1 - Failed to issue ACC RPL ELS command
7707 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7708 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7711 struct lpfc_hba *phba = vport->phba;
7712 IOCB_t *icmd, *oldcmd;
7714 struct lpfc_iocbq *elsiocb;
7717 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7718 ndlp->nlp_DID, ELS_CMD_ACC);
7723 icmd = &elsiocb->iocb;
7724 oldcmd = &oldiocb->iocb;
7725 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7726 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7728 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7729 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7730 pcmd += sizeof(uint16_t);
7731 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7732 pcmd += sizeof(uint16_t);
7734 /* Setup the RPL ACC payload */
7735 rpl_rsp.listLen = be32_to_cpu(1);
7737 rpl_rsp.port_num_blk.portNum = 0;
7738 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7739 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7740 sizeof(struct lpfc_name));
7741 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7742 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7743 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7744 "0120 Xmit ELS RPL ACC response tag x%x "
7745 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7747 elsiocb->iotag, elsiocb->iocb.ulpContext,
7748 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7750 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7751 phba->fc_stat.elsXmitACC++;
7752 elsiocb->context1 = lpfc_nlp_get(ndlp);
7753 if (!elsiocb->context1) {
7754 lpfc_els_free_iocb(phba, elsiocb);
7758 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7759 if (rc == IOCB_ERROR) {
7760 lpfc_els_free_iocb(phba, elsiocb);
7769 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7770 * @vport: pointer to a host virtual N_Port data structure.
7771 * @cmdiocb: pointer to lpfc command iocb data structure.
7772 * @ndlp: pointer to a node-list data structure.
7774 * This routine processes Read Port List (RPL) IOCB received as an ELS
7775 * unsolicited event. It first checks the remote port state. If the remote
7776 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7777 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7778 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7779 * to accept the RPL.
7782 * 0 - Successfully processed rpl iocb (currently always return 0)
7785 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7786 struct lpfc_nodelist *ndlp)
7788 struct lpfc_dmabuf *pcmd;
7795 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7796 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7797 /* issue rejection response */
7798 stat.un.b.lsRjtRsvd0 = 0;
7799 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7800 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7801 stat.un.b.vendorUnique = 0;
7802 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7804 /* rejected the unsolicited RPL request and done with it */
7808 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7809 lp = (uint32_t *) pcmd->virt;
7810 rpl = (RPL *) (lp + 1);
7811 maxsize = be32_to_cpu(rpl->maxsize);
7813 /* We support only one port */
7814 if ((rpl->index == 0) &&
7816 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7817 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7819 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7821 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7827 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7828 * @vport: pointer to a virtual N_Port data structure.
7829 * @cmdiocb: pointer to lpfc command iocb data structure.
7830 * @ndlp: pointer to a node-list data structure.
7832 * This routine processes Fibre Channel Address Resolution Protocol
7833 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7834 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7835 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7836 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7837 * remote PortName is compared against the FC PortName stored in the @vport
7838 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7839 * compared against the FC NodeName stored in the @vport data structure.
7840 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7841 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7842 * invoked to send out FARP Response to the remote node. Before sending the
7843 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7844 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7845 * routine is invoked to log into the remote port first.
7848 * 0 - Either the FARP Match Mode not supported or successfully processed
7851 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7852 struct lpfc_nodelist *ndlp)
7854 struct lpfc_dmabuf *pcmd;
7860 icmd = &cmdiocb->iocb;
7861 did = icmd->un.elsreq64.remoteID;
7862 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7863 lp = (uint32_t *) pcmd->virt;
7867 /* FARP-REQ received from DID <did> */
7868 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7869 "0601 FARP-REQ received from DID x%x\n", did);
7870 /* We will only support match on WWPN or WWNN */
7871 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7876 /* If this FARP command is searching for my portname */
7877 if (fp->Mflags & FARP_MATCH_PORT) {
7878 if (memcmp(&fp->RportName, &vport->fc_portname,
7879 sizeof(struct lpfc_name)) == 0)
7883 /* If this FARP command is searching for my nodename */
7884 if (fp->Mflags & FARP_MATCH_NODE) {
7885 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7886 sizeof(struct lpfc_name)) == 0)
7891 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7892 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7893 /* Log back into the node before sending the FARP. */
7894 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7895 ndlp->nlp_prev_state = ndlp->nlp_state;
7896 lpfc_nlp_set_state(vport, ndlp,
7897 NLP_STE_PLOGI_ISSUE);
7898 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7901 /* Send a FARP response to that node */
7902 if (fp->Rflags & FARP_REQUEST_FARPR)
7903 lpfc_issue_els_farpr(vport, did, 0);
7910 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7911 * @vport: pointer to a host virtual N_Port data structure.
7912 * @cmdiocb: pointer to lpfc command iocb data structure.
7913 * @ndlp: pointer to a node-list data structure.
7915 * This routine processes Fibre Channel Address Resolution Protocol
7916 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7917 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7918 * the FARP response request.
7921 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7924 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7925 struct lpfc_nodelist *ndlp)
7927 struct lpfc_dmabuf *pcmd;
7932 icmd = &cmdiocb->iocb;
7933 did = icmd->un.elsreq64.remoteID;
7934 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7935 lp = (uint32_t *) pcmd->virt;
7938 /* FARP-RSP received from DID <did> */
7939 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7940 "0600 FARP-RSP received from DID x%x\n", did);
7941 /* ACCEPT the Farp resp request */
7942 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7948 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7949 * @vport: pointer to a host virtual N_Port data structure.
7950 * @cmdiocb: pointer to lpfc command iocb data structure.
7951 * @fan_ndlp: pointer to a node-list data structure.
7953 * This routine processes a Fabric Address Notification (FAN) IOCB
7954 * command received as an ELS unsolicited event. The FAN ELS command will
7955 * only be processed on a physical port (i.e., the @vport represents the
7956 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7957 * compared against those in the phba data structure. If any of those is
7958 * different, the lpfc_initial_flogi() routine is invoked to initialize
7959 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7960 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7961 * is invoked to register login to the fabric.
7964 * 0 - Successfully processed fan iocb (currently always return 0).
7967 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7968 struct lpfc_nodelist *fan_ndlp)
7970 struct lpfc_hba *phba = vport->phba;
7974 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7975 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7977 /* FAN received; Fan does not have a reply sequence */
7978 if ((vport == phba->pport) &&
7979 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7980 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7981 sizeof(struct lpfc_name))) ||
7982 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7983 sizeof(struct lpfc_name)))) {
7984 /* This port has switched fabrics. FLOGI is required */
7985 lpfc_issue_init_vfi(vport);
7987 /* FAN verified - skip FLOGI */
7988 vport->fc_myDID = vport->fc_prevDID;
7989 if (phba->sli_rev < LPFC_SLI_REV4)
7990 lpfc_issue_fabric_reglogin(vport);
7992 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7993 "3138 Need register VFI: (x%x/%x)\n",
7994 vport->fc_prevDID, vport->fc_myDID);
7995 lpfc_issue_reg_vfi(vport);
8003 * lpfc_els_timeout - Handler funciton to the els timer
8004 * @t: timer context used to obtain the vport.
8006 * This routine is invoked by the ELS timer after timeout. It posts the ELS
8007 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
8008 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
8009 * up the worker thread. It is for the worker thread to invoke the routine
8010 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
8013 lpfc_els_timeout(struct timer_list *t)
8015 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
8016 struct lpfc_hba *phba = vport->phba;
8017 uint32_t tmo_posted;
8018 unsigned long iflag;
8020 spin_lock_irqsave(&vport->work_port_lock, iflag);
8021 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
8022 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8023 vport->work_port_events |= WORKER_ELS_TMO;
8024 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
8026 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
8027 lpfc_worker_wake_up(phba);
8033 * lpfc_els_timeout_handler - Process an els timeout event
8034 * @vport: pointer to a virtual N_Port data structure.
8036 * This routine is the actual handler function that processes an ELS timeout
8037 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8038 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8039 * invoking the lpfc_sli_issue_abort_iotag() routine.
8042 lpfc_els_timeout_handler(struct lpfc_vport *vport)
8044 struct lpfc_hba *phba = vport->phba;
8045 struct lpfc_sli_ring *pring;
8046 struct lpfc_iocbq *tmp_iocb, *piocb;
8048 struct lpfc_dmabuf *pcmd;
8049 uint32_t els_command = 0;
8051 uint32_t remote_ID = 0xffffffff;
8052 LIST_HEAD(abort_list);
8055 timeout = (uint32_t)(phba->fc_ratov << 1);
8057 pring = lpfc_phba_elsring(phba);
8058 if (unlikely(!pring))
8061 if (phba->pport->load_flag & FC_UNLOADING)
8064 spin_lock_irq(&phba->hbalock);
8065 if (phba->sli_rev == LPFC_SLI_REV4)
8066 spin_lock(&pring->ring_lock);
8068 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8071 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8072 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8073 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
8076 if (piocb->vport != vport)
8079 pcmd = (struct lpfc_dmabuf *) piocb->context2;
8081 els_command = *(uint32_t *) (pcmd->virt);
8083 if (els_command == ELS_CMD_FARP ||
8084 els_command == ELS_CMD_FARPR ||
8085 els_command == ELS_CMD_FDISC)
8088 if (piocb->drvrTimeout > 0) {
8089 if (piocb->drvrTimeout >= timeout)
8090 piocb->drvrTimeout -= timeout;
8092 piocb->drvrTimeout = 0;
8096 remote_ID = 0xffffffff;
8097 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
8098 remote_ID = cmd->un.elsreq64.remoteID;
8100 struct lpfc_nodelist *ndlp;
8101 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
8103 remote_ID = ndlp->nlp_DID;
8105 list_add_tail(&piocb->dlist, &abort_list);
8107 if (phba->sli_rev == LPFC_SLI_REV4)
8108 spin_unlock(&pring->ring_lock);
8109 spin_unlock_irq(&phba->hbalock);
8111 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8113 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8114 "0127 ELS timeout Data: x%x x%x x%x "
8115 "x%x\n", els_command,
8116 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8117 spin_lock_irq(&phba->hbalock);
8118 list_del_init(&piocb->dlist);
8119 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
8120 spin_unlock_irq(&phba->hbalock);
8123 /* Make sure HBA is alive */
8124 lpfc_issue_hb_tmo(phba);
8126 if (!list_empty(&pring->txcmplq))
8127 if (!(phba->pport->load_flag & FC_UNLOADING))
8128 mod_timer(&vport->els_tmofunc,
8129 jiffies + msecs_to_jiffies(1000 * timeout));
8133 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8134 * @vport: pointer to a host virtual N_Port data structure.
8136 * This routine is used to clean up all the outstanding ELS commands on a
8137 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8138 * routine. After that, it walks the ELS transmit queue to remove all the
8139 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8140 * the IOCBs with a non-NULL completion callback function, the callback
8141 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8142 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8143 * callback function, the IOCB will simply be released. Finally, it walks
8144 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8145 * completion queue IOCB that is associated with the @vport and is not
8146 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8147 * part of the discovery state machine) out to HBA by invoking the
8148 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8149 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8150 * the IOCBs are aborted when this function returns.
8153 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8155 LIST_HEAD(abort_list);
8156 struct lpfc_hba *phba = vport->phba;
8157 struct lpfc_sli_ring *pring;
8158 struct lpfc_iocbq *tmp_iocb, *piocb;
8160 unsigned long iflags = 0;
8162 lpfc_fabric_abort_vport(vport);
8165 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8166 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8167 * ultimately grabs the ring_lock, the driver must splice the list into
8168 * a working list and release the locks before calling the abort.
8170 spin_lock_irqsave(&phba->hbalock, iflags);
8171 pring = lpfc_phba_elsring(phba);
8173 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8174 if (unlikely(!pring)) {
8175 spin_unlock_irqrestore(&phba->hbalock, iflags);
8179 if (phba->sli_rev == LPFC_SLI_REV4)
8180 spin_lock(&pring->ring_lock);
8182 /* First we need to issue aborts to outstanding cmds on txcmpl */
8183 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8184 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8187 if (piocb->vport != vport)
8190 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8193 /* On the ELS ring we can have ELS_REQUESTs or
8194 * GEN_REQUESTs waiting for a response.
8197 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8198 list_add_tail(&piocb->dlist, &abort_list);
8200 /* If the link is down when flushing ELS commands
8201 * the firmware will not complete them till after
8202 * the link comes back up. This may confuse
8203 * discovery for the new link up, so we need to
8204 * change the compl routine to just clean up the iocb
8205 * and avoid any retry logic.
8207 if (phba->link_state == LPFC_LINK_DOWN)
8208 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8210 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8211 list_add_tail(&piocb->dlist, &abort_list);
8214 if (phba->sli_rev == LPFC_SLI_REV4)
8215 spin_unlock(&pring->ring_lock);
8216 spin_unlock_irqrestore(&phba->hbalock, iflags);
8218 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8219 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8220 spin_lock_irqsave(&phba->hbalock, iflags);
8221 list_del_init(&piocb->dlist);
8222 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
8223 spin_unlock_irqrestore(&phba->hbalock, iflags);
8225 /* Make sure HBA is alive */
8226 lpfc_issue_hb_tmo(phba);
8228 if (!list_empty(&abort_list))
8229 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8230 "3387 abort list for txq not empty\n");
8231 INIT_LIST_HEAD(&abort_list);
8233 spin_lock_irqsave(&phba->hbalock, iflags);
8234 if (phba->sli_rev == LPFC_SLI_REV4)
8235 spin_lock(&pring->ring_lock);
8237 /* No need to abort the txq list,
8238 * just queue them up for lpfc_sli_cancel_iocbs
8240 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8243 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8247 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8248 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8249 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8250 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8251 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8254 if (piocb->vport != vport)
8257 list_del_init(&piocb->list);
8258 list_add_tail(&piocb->list, &abort_list);
8261 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8262 if (vport == phba->pport) {
8263 list_for_each_entry_safe(piocb, tmp_iocb,
8264 &phba->fabric_iocb_list, list) {
8266 list_del_init(&piocb->list);
8267 list_add_tail(&piocb->list, &abort_list);
8271 if (phba->sli_rev == LPFC_SLI_REV4)
8272 spin_unlock(&pring->ring_lock);
8273 spin_unlock_irqrestore(&phba->hbalock, iflags);
8275 /* Cancel all the IOCBs from the completions list */
8276 lpfc_sli_cancel_iocbs(phba, &abort_list,
8277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8283 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8284 * @phba: pointer to lpfc hba data structure.
8286 * This routine is used to clean up all the outstanding ELS commands on a
8287 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8288 * routine. After that, it walks the ELS transmit queue to remove all the
8289 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8290 * the IOCBs with the completion callback function associated, the callback
8291 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8292 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8293 * callback function associated, the IOCB will simply be released. Finally,
8294 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8295 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8296 * management plane IOCBs that are not part of the discovery state machine)
8297 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8300 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8302 struct lpfc_vport *vport;
8304 spin_lock_irq(&phba->port_list_lock);
8305 list_for_each_entry(vport, &phba->port_list, listentry)
8306 lpfc_els_flush_cmd(vport);
8307 spin_unlock_irq(&phba->port_list_lock);
8313 * lpfc_send_els_failure_event - Posts an ELS command failure event
8314 * @phba: Pointer to hba context object.
8315 * @cmdiocbp: Pointer to command iocb which reported error.
8316 * @rspiocbp: Pointer to response iocb which reported error.
8318 * This function sends an event when there is an ELS command
8322 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8323 struct lpfc_iocbq *cmdiocbp,
8324 struct lpfc_iocbq *rspiocbp)
8326 struct lpfc_vport *vport = cmdiocbp->vport;
8327 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8328 struct lpfc_lsrjt_event lsrjt_event;
8329 struct lpfc_fabric_event_header fabric_event;
8331 struct lpfc_nodelist *ndlp;
8334 ndlp = cmdiocbp->context1;
8338 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8339 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8340 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8341 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8342 sizeof(struct lpfc_name));
8343 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8344 sizeof(struct lpfc_name));
8345 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8346 cmdiocbp->context2)->virt);
8347 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8348 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8349 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8350 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8351 fc_host_post_vendor_event(shost,
8352 fc_get_event_number(),
8353 sizeof(lsrjt_event),
8354 (char *)&lsrjt_event,
8358 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8359 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8360 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8361 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8362 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8364 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8365 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8366 sizeof(struct lpfc_name));
8367 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8368 sizeof(struct lpfc_name));
8369 fc_host_post_vendor_event(shost,
8370 fc_get_event_number(),
8371 sizeof(fabric_event),
8372 (char *)&fabric_event,
8380 * lpfc_send_els_event - Posts unsolicited els event
8381 * @vport: Pointer to vport object.
8382 * @ndlp: Pointer FC node object.
8383 * @payload: ELS command code type.
8385 * This function posts an event when there is an incoming
8386 * unsolicited ELS command.
8389 lpfc_send_els_event(struct lpfc_vport *vport,
8390 struct lpfc_nodelist *ndlp,
8393 struct lpfc_els_event_header *els_data = NULL;
8394 struct lpfc_logo_event *logo_data = NULL;
8395 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8397 if (*payload == ELS_CMD_LOGO) {
8398 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8400 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8401 "0148 Failed to allocate memory "
8402 "for LOGO event\n");
8405 els_data = &logo_data->header;
8407 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8410 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8411 "0149 Failed to allocate memory "
8416 els_data->event_type = FC_REG_ELS_EVENT;
8419 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8422 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8425 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8428 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8429 /* Copy the WWPN in the LOGO payload */
8430 memcpy(logo_data->logo_wwpn, &payload[2],
8431 sizeof(struct lpfc_name));
8437 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8438 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8439 if (*payload == ELS_CMD_LOGO) {
8440 fc_host_post_vendor_event(shost,
8441 fc_get_event_number(),
8442 sizeof(struct lpfc_logo_event),
8447 fc_host_post_vendor_event(shost,
8448 fc_get_event_number(),
8449 sizeof(struct lpfc_els_event_header),
8459 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8460 FC_LS_TLV_DTAG_INIT);
8462 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8463 FC_FPIN_LI_EVT_TYPES_INIT);
8466 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8467 * @vport: Pointer to vport object.
8468 * @tlv: Pointer to the Link Integrity Notification Descriptor.
8470 * This function processes a link integrity FPIN event by
8474 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8476 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8477 const char *li_evt_str;
8480 li_evt = be16_to_cpu(li->event_type);
8481 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8484 "4680 FPIN Link Integrity %s (x%x) "
8485 "Detecting PN x%016llx Attached PN x%016llx "
8486 "Duration %d mSecs Count %d Port Cnt %d\n",
8488 be64_to_cpu(li->detecting_wwpn),
8489 be64_to_cpu(li->attached_wwpn),
8490 be32_to_cpu(li->event_threshold),
8491 be32_to_cpu(li->event_count),
8492 be32_to_cpu(li->pname_count));
8496 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8499 struct fc_tlv_desc *tlv;
8500 const char *dtag_nm;
8501 uint32_t desc_cnt = 0, bytes_remain;
8504 /* FPINs handled only if we are in the right discovery state */
8505 if (vport->port_state < LPFC_DISC_AUTH)
8508 /* make sure there is the full fpin header */
8509 if (fpin_length < sizeof(struct fc_els_fpin))
8512 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8513 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8514 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8516 /* process each descriptor */
8517 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8518 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8520 dtag = be32_to_cpu(tlv->desc_tag);
8522 case ELS_DTAG_LNK_INTEGRITY:
8523 lpfc_els_rcv_fpin_li(vport, tlv);
8526 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8527 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8528 "4678 skipped FPIN descriptor[%d]: "
8530 desc_cnt, dtag, dtag_nm);
8535 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8536 tlv = fc_tlv_next_desc(tlv);
8539 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8544 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8545 * @phba: pointer to lpfc hba data structure.
8546 * @pring: pointer to a SLI ring.
8547 * @vport: pointer to a host virtual N_Port data structure.
8548 * @elsiocb: pointer to lpfc els command iocb data structure.
8550 * This routine is used for processing the IOCB associated with a unsolicited
8551 * event. It first determines whether there is an existing ndlp that matches
8552 * the DID from the unsolicited IOCB. If not, it will create a new one with
8553 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8554 * IOCB is then used to invoke the proper routine and to set up proper state
8555 * of the discovery state machine.
8558 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8559 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8561 struct lpfc_nodelist *ndlp;
8563 uint32_t *payload, payload_len;
8564 uint32_t cmd, did, newnode;
8565 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8566 IOCB_t *icmd = &elsiocb->iocb;
8569 if (!vport || !(elsiocb->context2))
8573 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8574 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8576 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8577 lpfc_post_buffer(phba, pring, 1);
8579 did = icmd->un.rcvels.remoteID;
8580 if (icmd->ulpStatus) {
8581 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8582 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8583 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8587 /* Check to see if link went down during discovery */
8588 if (lpfc_els_chk_latt(vport))
8591 /* Ignore traffic received during vport shutdown. */
8592 if (vport->load_flag & FC_UNLOADING)
8595 /* If NPort discovery is delayed drop incoming ELS */
8596 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8597 (cmd != ELS_CMD_PLOGI))
8600 ndlp = lpfc_findnode_did(vport, did);
8602 /* Cannot find existing Fabric ndlp, so allocate a new one */
8603 ndlp = lpfc_nlp_init(vport, did);
8606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8608 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8609 ndlp->nlp_type |= NLP_FABRIC;
8610 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8615 phba->fc_stat.elsRcvFrame++;
8618 * Do not process any unsolicited ELS commands
8619 * if the ndlp is in DEV_LOSS
8621 spin_lock_irq(&ndlp->lock);
8622 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8623 spin_unlock_irq(&ndlp->lock);
8628 spin_unlock_irq(&ndlp->lock);
8630 elsiocb->context1 = lpfc_nlp_get(ndlp);
8631 if (!elsiocb->context1)
8633 elsiocb->vport = vport;
8635 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8636 cmd &= ELS_CMD_MASK;
8638 /* ELS command <elsCmd> received from NPORT <did> */
8639 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8640 "0112 ELS command x%x received from NPORT x%x "
8641 "refcnt %d Data: x%x x%x x%x x%x\n",
8642 cmd, did, kref_read(&ndlp->kref), vport->port_state,
8643 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
8645 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8646 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8647 (cmd != ELS_CMD_FLOGI) &&
8648 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8649 rjt_err = LSRJT_LOGICAL_BSY;
8650 rjt_exp = LSEXP_NOTHING_MORE;
8656 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8657 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8658 did, vport->port_state, ndlp->nlp_flag);
8660 phba->fc_stat.elsRcvPLOGI++;
8661 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8662 if (phba->sli_rev == LPFC_SLI_REV4 &&
8663 (phba->pport->fc_flag & FC_PT2PT)) {
8664 vport->fc_prevDID = vport->fc_myDID;
8665 /* Our DID needs to be updated before registering
8666 * the vfi. This is done in lpfc_rcv_plogi but
8667 * that is called after the reg_vfi.
8669 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8670 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8671 "3312 Remote port assigned DID x%x "
8672 "%x\n", vport->fc_myDID,
8676 lpfc_send_els_event(vport, ndlp, payload);
8678 /* If Nport discovery is delayed, reject PLOGIs */
8679 if (vport->fc_flag & FC_DISC_DELAYED) {
8680 rjt_err = LSRJT_UNABLE_TPC;
8681 rjt_exp = LSEXP_NOTHING_MORE;
8685 if (vport->port_state < LPFC_DISC_AUTH) {
8686 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8687 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8688 rjt_err = LSRJT_UNABLE_TPC;
8689 rjt_exp = LSEXP_NOTHING_MORE;
8694 spin_lock_irq(&ndlp->lock);
8695 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8696 spin_unlock_irq(&ndlp->lock);
8698 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8704 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8705 did, vport->port_state, ndlp->nlp_flag);
8707 phba->fc_stat.elsRcvFLOGI++;
8709 /* If the driver believes fabric discovery is done and is ready,
8710 * bounce the link. There is some descrepancy.
8712 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8713 vport->fc_flag & FC_PT2PT &&
8714 vport->rcv_flogi_cnt >= 1) {
8715 rjt_err = LSRJT_LOGICAL_BSY;
8716 rjt_exp = LSEXP_NOTHING_MORE;
8721 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8723 lpfc_disc_state_machine(vport, ndlp, NULL,
8727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8728 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8729 did, vport->port_state, ndlp->nlp_flag);
8731 phba->fc_stat.elsRcvLOGO++;
8732 lpfc_send_els_event(vport, ndlp, payload);
8733 if (vport->port_state < LPFC_DISC_AUTH) {
8734 rjt_err = LSRJT_UNABLE_TPC;
8735 rjt_exp = LSEXP_NOTHING_MORE;
8738 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8741 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8742 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8743 did, vport->port_state, ndlp->nlp_flag);
8745 phba->fc_stat.elsRcvPRLO++;
8746 lpfc_send_els_event(vport, ndlp, payload);
8747 if (vport->port_state < LPFC_DISC_AUTH) {
8748 rjt_err = LSRJT_UNABLE_TPC;
8749 rjt_exp = LSEXP_NOTHING_MORE;
8752 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8755 phba->fc_stat.elsRcvLCB++;
8756 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8759 phba->fc_stat.elsRcvRDP++;
8760 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8763 phba->fc_stat.elsRcvRSCN++;
8764 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8766 lpfc_disc_state_machine(vport, ndlp, NULL,
8770 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8771 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8772 did, vport->port_state, ndlp->nlp_flag);
8774 lpfc_send_els_event(vport, ndlp, payload);
8775 phba->fc_stat.elsRcvADISC++;
8776 if (vport->port_state < LPFC_DISC_AUTH) {
8777 rjt_err = LSRJT_UNABLE_TPC;
8778 rjt_exp = LSEXP_NOTHING_MORE;
8781 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8786 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8787 did, vport->port_state, ndlp->nlp_flag);
8789 phba->fc_stat.elsRcvPDISC++;
8790 if (vport->port_state < LPFC_DISC_AUTH) {
8791 rjt_err = LSRJT_UNABLE_TPC;
8792 rjt_exp = LSEXP_NOTHING_MORE;
8795 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8800 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8801 did, vport->port_state, ndlp->nlp_flag);
8803 phba->fc_stat.elsRcvFARPR++;
8804 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8808 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8809 did, vport->port_state, ndlp->nlp_flag);
8811 phba->fc_stat.elsRcvFARP++;
8812 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8815 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8816 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8817 did, vport->port_state, ndlp->nlp_flag);
8819 phba->fc_stat.elsRcvFAN++;
8820 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8823 case ELS_CMD_NVMEPRLI:
8824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8825 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8826 did, vport->port_state, ndlp->nlp_flag);
8828 phba->fc_stat.elsRcvPRLI++;
8829 if ((vport->port_state < LPFC_DISC_AUTH) &&
8830 (vport->fc_flag & FC_FABRIC)) {
8831 rjt_err = LSRJT_UNABLE_TPC;
8832 rjt_exp = LSEXP_NOTHING_MORE;
8835 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8839 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8840 did, vport->port_state, ndlp->nlp_flag);
8842 phba->fc_stat.elsRcvLIRR++;
8843 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8845 lpfc_disc_state_machine(vport, ndlp, NULL,
8849 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8850 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8851 did, vport->port_state, ndlp->nlp_flag);
8853 phba->fc_stat.elsRcvRLS++;
8854 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8856 lpfc_disc_state_machine(vport, ndlp, NULL,
8860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8861 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8862 did, vport->port_state, ndlp->nlp_flag);
8864 phba->fc_stat.elsRcvRPL++;
8865 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8867 lpfc_disc_state_machine(vport, ndlp, NULL,
8871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8872 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8873 did, vport->port_state, ndlp->nlp_flag);
8875 phba->fc_stat.elsRcvRNID++;
8876 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8878 lpfc_disc_state_machine(vport, ndlp, NULL,
8882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8883 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8884 did, vport->port_state, ndlp->nlp_flag);
8885 phba->fc_stat.elsRcvRTV++;
8886 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8888 lpfc_disc_state_machine(vport, ndlp, NULL,
8892 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8893 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8894 did, vport->port_state, ndlp->nlp_flag);
8896 phba->fc_stat.elsRcvRRQ++;
8897 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8899 lpfc_disc_state_machine(vport, ndlp, NULL,
8903 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8904 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8905 did, vport->port_state, ndlp->nlp_flag);
8907 phba->fc_stat.elsRcvECHO++;
8908 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8910 lpfc_disc_state_machine(vport, ndlp, NULL,
8914 /* receive this due to exchange closed */
8915 rjt_err = LSRJT_UNABLE_TPC;
8916 rjt_exp = LSEXP_INVALID_OX_RX;
8919 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8920 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8921 did, vport->port_state, ndlp->nlp_flag);
8923 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8926 /* There are no replies, so no rjt codes */
8929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8930 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8931 cmd, did, vport->port_state);
8933 /* Unsupported ELS command, reject */
8934 rjt_err = LSRJT_CMD_UNSUPPORTED;
8935 rjt_exp = LSEXP_NOTHING_MORE;
8937 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8938 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8939 "0115 Unknown ELS command x%x "
8940 "received from NPORT x%x\n", cmd, did);
8942 lpfc_disc_state_machine(vport, ndlp, NULL,
8948 /* check if need to LS_RJT received ELS cmd */
8950 memset(&stat, 0, sizeof(stat));
8951 stat.un.b.lsRjtRsnCode = rjt_err;
8952 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8953 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8955 /* Remove the reference from above for new nodes. */
8957 lpfc_disc_state_machine(vport, ndlp, NULL,
8961 /* Release the reference on this elsiocb, not the ndlp. */
8962 lpfc_nlp_put(elsiocb->context1);
8963 elsiocb->context1 = NULL;
8965 /* Special case. Driver received an unsolicited command that
8966 * unsupportable given the driver's current state. Reset the
8967 * link and start over.
8970 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8973 lpfc_linkdown(phba);
8974 lpfc_init_link(phba, mbox,
8976 phba->cfg_link_speed);
8977 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8978 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8979 mbox->vport = vport;
8980 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8982 mempool_free(mbox, phba->mbox_mem_pool);
8988 if (vport && !(vport->load_flag & FC_UNLOADING))
8989 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8990 "0111 Dropping received ELS cmd "
8991 "Data: x%x x%x x%x\n",
8992 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8993 phba->fc_stat.elsRcvDrop++;
8997 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8998 * @phba: pointer to lpfc hba data structure.
8999 * @pring: pointer to a SLI ring.
9000 * @elsiocb: pointer to lpfc els iocb data structure.
9002 * This routine is used to process an unsolicited event received from a SLI
9003 * (Service Level Interface) ring. The actual processing of the data buffer
9004 * associated with the unsolicited event is done by invoking the routine
9005 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
9006 * SLI ring on which the unsolicited event was received.
9009 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9010 struct lpfc_iocbq *elsiocb)
9012 struct lpfc_vport *vport = phba->pport;
9013 IOCB_t *icmd = &elsiocb->iocb;
9015 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
9016 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
9018 elsiocb->context1 = NULL;
9019 elsiocb->context2 = NULL;
9020 elsiocb->context3 = NULL;
9022 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
9023 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
9024 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
9025 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
9026 IOERR_RCV_BUFFER_WAITING) {
9027 phba->fc_stat.NoRcvBuf++;
9028 /* Not enough posted buffers; Try posting more buffers */
9029 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
9030 lpfc_post_buffer(phba, pring, 0);
9034 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
9035 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
9036 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
9037 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
9038 vport = phba->pport;
9040 vport = lpfc_find_vport_by_vpid(phba,
9041 icmd->unsli3.rcvsli3.vpi);
9044 /* If there are no BDEs associated
9045 * with this IOCB, there is nothing to do.
9047 if (icmd->ulpBdeCount == 0)
9050 /* type of ELS cmd is first 32bit word
9053 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9054 elsiocb->context2 = bdeBuf1;
9056 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
9057 icmd->un.cont64[0].addrLow);
9058 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
9062 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9064 * The different unsolicited event handlers would tell us
9065 * if they are done with "mp" by setting context2 to NULL.
9067 if (elsiocb->context2) {
9068 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
9069 elsiocb->context2 = NULL;
9072 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
9073 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
9074 icmd->ulpBdeCount == 2) {
9075 elsiocb->context2 = bdeBuf2;
9076 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9077 /* free mp if we are done with it */
9078 if (elsiocb->context2) {
9079 lpfc_in_buf_free(phba, elsiocb->context2);
9080 elsiocb->context2 = NULL;
9086 lpfc_start_fdmi(struct lpfc_vport *vport)
9088 struct lpfc_nodelist *ndlp;
9090 /* If this is the first time, allocate an ndlp and initialize
9091 * it. Otherwise, make sure the node is enabled and then do the
9094 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9096 ndlp = lpfc_nlp_init(vport, FDMI_DID);
9098 ndlp->nlp_type |= NLP_FABRIC;
9104 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9105 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9109 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
9110 * @phba: pointer to lpfc hba data structure.
9111 * @vport: pointer to a virtual N_Port data structure.
9113 * This routine issues a Port Login (PLOGI) to the Name Server with
9114 * State Change Request (SCR) for a @vport. This routine will create an
9115 * ndlp for the Name Server associated to the @vport if such node does
9116 * not already exist. The PLOGI to Name Server is issued by invoking the
9117 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9118 * (FDMI) is configured to the @vport, a FDMI node will be created and
9119 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9122 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9124 struct lpfc_nodelist *ndlp;
9125 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9128 * If lpfc_delay_discovery parameter is set and the clean address
9129 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9132 spin_lock_irq(shost->host_lock);
9133 if (vport->fc_flag & FC_DISC_DELAYED) {
9134 spin_unlock_irq(shost->host_lock);
9135 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9136 "3334 Delay fc port discovery for %d secs\n",
9138 mod_timer(&vport->delayed_disc_tmo,
9139 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9142 spin_unlock_irq(shost->host_lock);
9144 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9146 ndlp = lpfc_nlp_init(vport, NameServer_DID);
9148 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9149 lpfc_disc_start(vport);
9152 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9153 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9154 "0251 NameServer login: no memory\n");
9159 ndlp->nlp_type |= NLP_FABRIC;
9161 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9163 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9164 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9165 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9166 "0252 Cannot issue NameServer login\n");
9170 if ((phba->cfg_enable_SmartSAN ||
9171 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9172 (vport->load_flag & FC_ALLOW_FDMI))
9173 lpfc_start_fdmi(vport);
9177 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9178 * @phba: pointer to lpfc hba data structure.
9179 * @pmb: pointer to the driver internal queue element for mailbox command.
9181 * This routine is the completion callback function to register new vport
9182 * mailbox command. If the new vport mailbox command completes successfully,
9183 * the fabric registration login shall be performed on physical port (the
9184 * new vport created is actually a physical port, with VPI 0) or the port
9185 * login to Name Server for State Change Request (SCR) will be performed
9186 * on virtual port (real virtual port, with VPI greater than 0).
9189 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9191 struct lpfc_vport *vport = pmb->vport;
9192 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9193 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9194 MAILBOX_t *mb = &pmb->u.mb;
9197 spin_lock_irq(shost->host_lock);
9198 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9199 spin_unlock_irq(shost->host_lock);
9201 if (mb->mbxStatus) {
9202 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9203 "0915 Register VPI failed : Status: x%x"
9204 " upd bit: x%x \n", mb->mbxStatus,
9205 mb->un.varRegVpi.upd);
9206 if (phba->sli_rev == LPFC_SLI_REV4 &&
9207 mb->un.varRegVpi.upd)
9208 goto mbox_err_exit ;
9210 switch (mb->mbxStatus) {
9211 case 0x11: /* unsupported feature */
9212 case 0x9603: /* max_vpi exceeded */
9213 case 0x9602: /* Link event since CLEAR_LA */
9214 /* giving up on vport registration */
9215 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9216 spin_lock_irq(shost->host_lock);
9217 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9218 spin_unlock_irq(shost->host_lock);
9219 lpfc_can_disctmo(vport);
9221 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9223 spin_lock_irq(shost->host_lock);
9224 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9225 spin_unlock_irq(shost->host_lock);
9226 lpfc_init_vpi(phba, pmb, vport->vpi);
9228 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9229 rc = lpfc_sli_issue_mbox(phba, pmb,
9231 if (rc == MBX_NOT_FINISHED) {
9232 lpfc_printf_vlog(vport, KERN_ERR,
9234 "2732 Failed to issue INIT_VPI"
9235 " mailbox command\n");
9242 /* Try to recover from this error */
9243 if (phba->sli_rev == LPFC_SLI_REV4)
9244 lpfc_sli4_unreg_all_rpis(vport);
9245 lpfc_mbx_unreg_vpi(vport);
9246 spin_lock_irq(shost->host_lock);
9247 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9248 spin_unlock_irq(shost->host_lock);
9249 if (mb->mbxStatus == MBX_NOT_FINISHED)
9251 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9252 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9253 if (phba->sli_rev == LPFC_SLI_REV4)
9254 lpfc_issue_init_vfi(vport);
9256 lpfc_initial_flogi(vport);
9258 lpfc_initial_fdisc(vport);
9263 spin_lock_irq(shost->host_lock);
9264 vport->vpi_state |= LPFC_VPI_REGISTERED;
9265 spin_unlock_irq(shost->host_lock);
9266 if (vport == phba->pport) {
9267 if (phba->sli_rev < LPFC_SLI_REV4)
9268 lpfc_issue_fabric_reglogin(vport);
9271 * If the physical port is instantiated using
9272 * FDISC, do not start vport discovery.
9274 if (vport->port_state != LPFC_FDISC)
9275 lpfc_start_fdiscs(phba);
9276 lpfc_do_scr_ns_plogi(phba, vport);
9279 lpfc_do_scr_ns_plogi(phba, vport);
9283 /* Now, we decrement the ndlp reference count held for this
9288 mempool_free(pmb, phba->mbox_mem_pool);
9293 * lpfc_register_new_vport - Register a new vport with a HBA
9294 * @phba: pointer to lpfc hba data structure.
9295 * @vport: pointer to a host virtual N_Port data structure.
9296 * @ndlp: pointer to a node-list data structure.
9298 * This routine registers the @vport as a new virtual port with a HBA.
9299 * It is done through a registering vpi mailbox command.
9302 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9303 struct lpfc_nodelist *ndlp)
9305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9308 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9310 lpfc_reg_vpi(vport, mbox);
9311 mbox->vport = vport;
9312 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9313 if (!mbox->ctx_ndlp) {
9314 mempool_free(mbox, phba->mbox_mem_pool);
9318 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9319 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9320 == MBX_NOT_FINISHED) {
9321 /* mailbox command not success, decrement ndlp
9322 * reference count for this command
9325 mempool_free(mbox, phba->mbox_mem_pool);
9327 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9328 "0253 Register VPI: Can't send mbox\n");
9332 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9333 "0254 Register VPI: no memory\n");
9339 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9340 spin_lock_irq(shost->host_lock);
9341 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9342 spin_unlock_irq(shost->host_lock);
9347 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9348 * @phba: pointer to lpfc hba data structure.
9350 * This routine cancels the retry delay timers to all the vports.
9353 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9355 struct lpfc_vport **vports;
9356 struct lpfc_nodelist *ndlp;
9357 uint32_t link_state;
9360 /* Treat this failure as linkdown for all vports */
9361 link_state = phba->link_state;
9362 lpfc_linkdown(phba);
9363 phba->link_state = link_state;
9365 vports = lpfc_create_vport_work_array(phba);
9368 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9369 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9371 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9372 lpfc_els_flush_cmd(vports[i]);
9374 lpfc_destroy_vport_work_array(phba, vports);
9379 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9380 * @phba: pointer to lpfc hba data structure.
9382 * This routine abort all pending discovery commands and
9383 * start a timer to retry FLOGI for the physical port
9387 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9389 struct lpfc_nodelist *ndlp;
9391 /* Cancel the all vports retry delay retry timers */
9392 lpfc_cancel_all_vport_retry_delay_timer(phba);
9394 /* If fabric require FLOGI, then re-instantiate physical login */
9395 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9399 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9400 spin_lock_irq(&ndlp->lock);
9401 ndlp->nlp_flag |= NLP_DELAY_TMO;
9402 spin_unlock_irq(&ndlp->lock);
9403 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9404 phba->pport->port_state = LPFC_FLOGI;
9409 * lpfc_fabric_login_reqd - Check if FLOGI required.
9410 * @phba: pointer to lpfc hba data structure.
9411 * @cmdiocb: pointer to FDISC command iocb.
9412 * @rspiocb: pointer to FDISC response iocb.
9414 * This routine checks if a FLOGI is reguired for FDISC
9418 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9419 struct lpfc_iocbq *cmdiocb,
9420 struct lpfc_iocbq *rspiocb)
9423 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9424 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9431 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9432 * @phba: pointer to lpfc hba data structure.
9433 * @cmdiocb: pointer to lpfc command iocb data structure.
9434 * @rspiocb: pointer to lpfc response iocb data structure.
9436 * This routine is the completion callback function to a Fabric Discover
9437 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9438 * single threaded, each FDISC completion callback function will reset
9439 * the discovery timer for all vports such that the timers will not get
9440 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9441 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9442 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9443 * assigned to the vport has been changed with the completion of the FDISC
9444 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9445 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9446 * routine is invoked to register new vport with the HBA. Otherwise, the
9447 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9448 * Server for State Change Request (SCR).
9451 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9452 struct lpfc_iocbq *rspiocb)
9454 struct lpfc_vport *vport = cmdiocb->vport;
9455 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9456 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9457 struct lpfc_nodelist *np;
9458 struct lpfc_nodelist *next_np;
9459 IOCB_t *irsp = &rspiocb->iocb;
9460 struct lpfc_iocbq *piocb;
9461 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9462 struct serv_parm *sp;
9463 uint8_t fabric_param_changed;
9465 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9466 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9467 irsp->ulpStatus, irsp->un.ulpWord[4],
9469 /* Since all FDISCs are being single threaded, we
9470 * must reset the discovery timer for ALL vports
9471 * waiting to send FDISC when one completes.
9473 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9474 lpfc_set_disctmo(piocb->vport);
9477 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9478 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9479 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9481 if (irsp->ulpStatus) {
9483 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9484 lpfc_retry_pport_discovery(phba);
9488 /* Check for retry */
9489 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9492 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9493 "0126 FDISC failed. (x%x/x%x)\n",
9494 irsp->ulpStatus, irsp->un.ulpWord[4]);
9497 spin_lock_irq(shost->host_lock);
9498 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9499 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9500 vport->fc_flag |= FC_FABRIC;
9501 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9502 vport->fc_flag |= FC_PUBLIC_LOOP;
9503 spin_unlock_irq(shost->host_lock);
9505 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9506 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9507 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9510 sp = prsp->virt + sizeof(uint32_t);
9511 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9512 memcpy(&vport->fabric_portname, &sp->portName,
9513 sizeof(struct lpfc_name));
9514 memcpy(&vport->fabric_nodename, &sp->nodeName,
9515 sizeof(struct lpfc_name));
9516 if (fabric_param_changed &&
9517 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9518 /* If our NportID changed, we need to ensure all
9519 * remaining NPORTs get unreg_login'ed so we can
9522 list_for_each_entry_safe(np, next_np,
9523 &vport->fc_nodes, nlp_listp) {
9524 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
9525 !(np->nlp_flag & NLP_NPR_ADISC))
9527 spin_lock_irq(&ndlp->lock);
9528 np->nlp_flag &= ~NLP_NPR_ADISC;
9529 spin_unlock_irq(&ndlp->lock);
9530 lpfc_unreg_rpi(vport, np);
9532 lpfc_cleanup_pending_mbox(vport);
9534 if (phba->sli_rev == LPFC_SLI_REV4)
9535 lpfc_sli4_unreg_all_rpis(vport);
9537 lpfc_mbx_unreg_vpi(vport);
9538 spin_lock_irq(shost->host_lock);
9539 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9540 if (phba->sli_rev == LPFC_SLI_REV4)
9541 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9543 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9544 spin_unlock_irq(shost->host_lock);
9545 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9546 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9548 * Driver needs to re-reg VPI in order for f/w
9549 * to update the MAC address.
9551 lpfc_register_new_vport(phba, vport, ndlp);
9552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9556 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9557 lpfc_issue_init_vpi(vport);
9558 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9559 lpfc_register_new_vport(phba, vport, ndlp);
9561 lpfc_do_scr_ns_plogi(phba, vport);
9563 /* The FDISC completed successfully. Move the fabric ndlp to
9564 * UNMAPPED state and register with the transport.
9566 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9570 if (vport->fc_vport &&
9571 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9572 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9573 /* Cancel discovery timer */
9574 lpfc_can_disctmo(vport);
9576 lpfc_els_free_iocb(phba, cmdiocb);
9581 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9582 * @vport: pointer to a virtual N_Port data structure.
9583 * @ndlp: pointer to a node-list data structure.
9584 * @retry: number of retries to the command IOCB.
9586 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9587 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9588 * routine to issue the IOCB, which makes sure only one outstanding fabric
9589 * IOCB will be sent off HBA at any given time.
9591 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9592 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9593 * will be stored into the context1 field of the IOCB for the completion
9594 * callback function to the FDISC ELS command.
9597 * 0 - Successfully issued fdisc iocb command
9598 * 1 - Failed to issue fdisc iocb command
9601 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9604 struct lpfc_hba *phba = vport->phba;
9606 struct lpfc_iocbq *elsiocb;
9607 struct serv_parm *sp;
9610 int did = ndlp->nlp_DID;
9613 vport->port_state = LPFC_FDISC;
9614 vport->fc_myDID = 0;
9615 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9616 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9619 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9620 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9621 "0255 Issue FDISC: no IOCB\n");
9625 icmd = &elsiocb->iocb;
9626 icmd->un.elsreq64.myID = 0;
9627 icmd->un.elsreq64.fl = 1;
9630 * SLI3 ports require a different context type value than SLI4.
9631 * Catch SLI3 ports here and override the prep.
9633 if (phba->sli_rev == LPFC_SLI_REV3) {
9638 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9639 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9640 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9641 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9642 sp = (struct serv_parm *) pcmd;
9643 /* Setup CSPs accordingly for Fabric */
9644 sp->cmn.e_d_tov = 0;
9645 sp->cmn.w2.r_a_tov = 0;
9646 sp->cmn.virtual_fabric_support = 0;
9647 sp->cls1.classValid = 0;
9648 sp->cls2.seqDelivery = 1;
9649 sp->cls3.seqDelivery = 1;
9651 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9652 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9653 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9654 pcmd += sizeof(uint32_t); /* Port Name */
9655 memcpy(pcmd, &vport->fc_portname, 8);
9656 pcmd += sizeof(uint32_t); /* Node Name */
9657 pcmd += sizeof(uint32_t); /* Node Name */
9658 memcpy(pcmd, &vport->fc_nodename, 8);
9659 sp->cmn.valid_vendor_ver_level = 0;
9660 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9661 lpfc_set_disctmo(vport);
9663 phba->fc_stat.elsXmitFDISC++;
9664 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9667 "Issue FDISC: did:x%x",
9670 elsiocb->context1 = lpfc_nlp_get(ndlp);
9671 if (!elsiocb->context1) {
9672 lpfc_els_free_iocb(phba, elsiocb);
9676 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9677 if (rc == IOCB_ERROR) {
9678 lpfc_els_free_iocb(phba, elsiocb);
9683 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9687 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9688 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9689 "0256 Issue FDISC: Cannot send IOCB\n");
9694 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9695 * @phba: pointer to lpfc hba data structure.
9696 * @cmdiocb: pointer to lpfc command iocb data structure.
9697 * @rspiocb: pointer to lpfc response iocb data structure.
9699 * This routine is the completion callback function to the issuing of a LOGO
9700 * ELS command off a vport. It frees the command IOCB and then decrement the
9701 * reference count held on ndlp for this completion function, indicating that
9702 * the reference to the ndlp is no long needed. Note that the
9703 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9704 * callback function and an additional explicit ndlp reference decrementation
9705 * will trigger the actual release of the ndlp.
9708 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9709 struct lpfc_iocbq *rspiocb)
9711 struct lpfc_vport *vport = cmdiocb->vport;
9713 struct lpfc_nodelist *ndlp;
9714 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9716 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9717 irsp = &rspiocb->iocb;
9718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9719 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9720 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9722 /* NPIV LOGO completes to NPort <nlp_DID> */
9723 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9724 "2928 NPIV LOGO completes to NPort x%x "
9725 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
9726 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9727 irsp->ulpTimeout, vport->num_disc_nodes,
9728 kref_read(&ndlp->kref), ndlp->nlp_flag,
9729 ndlp->fc4_xpt_flags);
9731 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9732 spin_lock_irq(shost->host_lock);
9733 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9734 vport->fc_flag &= ~FC_FABRIC;
9735 spin_unlock_irq(shost->host_lock);
9736 lpfc_can_disctmo(vport);
9739 /* Safe to release resources now. */
9740 lpfc_els_free_iocb(phba, cmdiocb);
9742 vport->unreg_vpi_cmpl = VPORT_ERROR;
9746 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9747 * @vport: pointer to a virtual N_Port data structure.
9748 * @ndlp: pointer to a node-list data structure.
9750 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9752 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9753 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9754 * will be stored into the context1 field of the IOCB for the completion
9755 * callback function to the LOGO ELS command.
9758 * 0 - Successfully issued logo off the @vport
9759 * 1 - Failed to issue logo off the @vport
9762 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9765 struct lpfc_hba *phba = vport->phba;
9766 struct lpfc_iocbq *elsiocb;
9770 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9771 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9776 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9777 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9778 pcmd += sizeof(uint32_t);
9780 /* Fill in LOGO payload */
9781 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9782 pcmd += sizeof(uint32_t);
9783 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9786 "Issue LOGO npiv did:x%x flg:x%x",
9787 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9789 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9790 spin_lock_irq(&ndlp->lock);
9791 ndlp->nlp_flag |= NLP_LOGO_SND;
9792 spin_unlock_irq(&ndlp->lock);
9793 elsiocb->context1 = lpfc_nlp_get(ndlp);
9794 if (!elsiocb->context1) {
9795 lpfc_els_free_iocb(phba, elsiocb);
9799 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9800 if (rc == IOCB_ERROR) {
9801 lpfc_els_free_iocb(phba, elsiocb);
9808 spin_lock_irq(&ndlp->lock);
9809 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9810 spin_unlock_irq(&ndlp->lock);
9815 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9816 * @t: timer context used to obtain the lpfc hba.
9818 * This routine is invoked by the fabric iocb block timer after
9819 * timeout. It posts the fabric iocb block timeout event by setting the
9820 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9821 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9822 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9823 * posted event WORKER_FABRIC_BLOCK_TMO.
9826 lpfc_fabric_block_timeout(struct timer_list *t)
9828 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9829 unsigned long iflags;
9830 uint32_t tmo_posted;
9832 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9833 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9835 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9836 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9839 lpfc_worker_wake_up(phba);
9844 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9845 * @phba: pointer to lpfc hba data structure.
9847 * This routine issues one fabric iocb from the driver internal list to
9848 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9849 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9850 * remove one pending fabric iocb from the driver internal list and invokes
9851 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9854 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9856 struct lpfc_iocbq *iocb;
9857 unsigned long iflags;
9863 spin_lock_irqsave(&phba->hbalock, iflags);
9864 /* Post any pending iocb to the SLI layer */
9865 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9866 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9869 /* Increment fabric iocb count to hold the position */
9870 atomic_inc(&phba->fabric_iocb_count);
9872 spin_unlock_irqrestore(&phba->hbalock, iflags);
9874 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9875 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9876 iocb->iocb_flag |= LPFC_IO_FABRIC;
9878 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9879 "Fabric sched1: ste:x%x",
9880 iocb->vport->port_state, 0, 0);
9882 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9884 if (ret == IOCB_ERROR) {
9885 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9886 iocb->fabric_iocb_cmpl = NULL;
9887 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9889 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9890 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9891 iocb->iocb_cmpl(phba, iocb, iocb);
9893 atomic_dec(&phba->fabric_iocb_count);
9900 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9901 * @phba: pointer to lpfc hba data structure.
9903 * This routine unblocks the issuing fabric iocb command. The function
9904 * will clear the fabric iocb block bit and then invoke the routine
9905 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9906 * from the driver internal fabric iocb list.
9909 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9911 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9913 lpfc_resume_fabric_iocbs(phba);
9918 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9919 * @phba: pointer to lpfc hba data structure.
9921 * This routine blocks the issuing fabric iocb for a specified amount of
9922 * time (currently 100 ms). This is done by set the fabric iocb block bit
9923 * and set up a timeout timer for 100ms. When the block bit is set, no more
9924 * fabric iocb will be issued out of the HBA.
9927 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9931 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9932 /* Start a timer to unblock fabric iocbs after 100ms */
9934 mod_timer(&phba->fabric_block_timer,
9935 jiffies + msecs_to_jiffies(100));
9941 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9942 * @phba: pointer to lpfc hba data structure.
9943 * @cmdiocb: pointer to lpfc command iocb data structure.
9944 * @rspiocb: pointer to lpfc response iocb data structure.
9946 * This routine is the callback function that is put to the fabric iocb's
9947 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9948 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9949 * function first restores and invokes the original iocb's callback function
9950 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9951 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9954 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9955 struct lpfc_iocbq *rspiocb)
9959 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9961 switch (rspiocb->iocb.ulpStatus) {
9962 case IOSTAT_NPORT_RJT:
9963 case IOSTAT_FABRIC_RJT:
9964 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9965 lpfc_block_fabric_iocbs(phba);
9969 case IOSTAT_NPORT_BSY:
9970 case IOSTAT_FABRIC_BSY:
9971 lpfc_block_fabric_iocbs(phba);
9975 stat.un.lsRjtError =
9976 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9977 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9978 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9979 lpfc_block_fabric_iocbs(phba);
9983 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9985 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9986 cmdiocb->fabric_iocb_cmpl = NULL;
9987 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9988 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9990 atomic_dec(&phba->fabric_iocb_count);
9991 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9992 /* Post any pending iocbs to HBA */
9993 lpfc_resume_fabric_iocbs(phba);
9998 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9999 * @phba: pointer to lpfc hba data structure.
10000 * @iocb: pointer to lpfc command iocb data structure.
10002 * This routine is used as the top-level API for issuing a fabric iocb command
10003 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
10004 * function makes sure that only one fabric bound iocb will be outstanding at
10005 * any given time. As such, this function will first check to see whether there
10006 * is already an outstanding fabric iocb on the wire. If so, it will put the
10007 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
10008 * issued later. Otherwise, it will issue the iocb on the wire and update the
10009 * fabric iocb count it indicate that there is one fabric iocb on the wire.
10011 * Note, this implementation has a potential sending out fabric IOCBs out of
10012 * order. The problem is caused by the construction of the "ready" boolen does
10013 * not include the condition that the internal fabric IOCB list is empty. As
10014 * such, it is possible a fabric IOCB issued by this routine might be "jump"
10015 * ahead of the fabric IOCBs in the internal list.
10018 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
10019 * IOCB_ERROR - failed to issue fabric iocb
10022 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
10024 unsigned long iflags;
10028 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
10030 spin_lock_irqsave(&phba->hbalock, iflags);
10031 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
10032 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
10035 /* Increment fabric iocb count to hold the position */
10036 atomic_inc(&phba->fabric_iocb_count);
10037 spin_unlock_irqrestore(&phba->hbalock, iflags);
10039 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
10040 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
10041 iocb->iocb_flag |= LPFC_IO_FABRIC;
10043 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
10044 "Fabric sched2: ste:x%x",
10045 iocb->vport->port_state, 0, 0);
10047 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
10049 if (ret == IOCB_ERROR) {
10050 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
10051 iocb->fabric_iocb_cmpl = NULL;
10052 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
10053 atomic_dec(&phba->fabric_iocb_count);
10056 spin_lock_irqsave(&phba->hbalock, iflags);
10057 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
10058 spin_unlock_irqrestore(&phba->hbalock, iflags);
10059 ret = IOCB_SUCCESS;
10065 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
10066 * @vport: pointer to a virtual N_Port data structure.
10068 * This routine aborts all the IOCBs associated with a @vport from the
10069 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10070 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10071 * list, removes each IOCB associated with the @vport off the list, set the
10072 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10073 * associated with the IOCB.
10075 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
10077 LIST_HEAD(completions);
10078 struct lpfc_hba *phba = vport->phba;
10079 struct lpfc_iocbq *tmp_iocb, *piocb;
10081 spin_lock_irq(&phba->hbalock);
10082 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10085 if (piocb->vport != vport)
10088 list_move_tail(&piocb->list, &completions);
10090 spin_unlock_irq(&phba->hbalock);
10092 /* Cancel all the IOCBs from the completions list */
10093 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10094 IOERR_SLI_ABORTED);
10098 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
10099 * @ndlp: pointer to a node-list data structure.
10101 * This routine aborts all the IOCBs associated with an @ndlp from the
10102 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10103 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10104 * list, removes each IOCB associated with the @ndlp off the list, set the
10105 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10106 * associated with the IOCB.
10108 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10110 LIST_HEAD(completions);
10111 struct lpfc_hba *phba = ndlp->phba;
10112 struct lpfc_iocbq *tmp_iocb, *piocb;
10113 struct lpfc_sli_ring *pring;
10115 pring = lpfc_phba_elsring(phba);
10117 if (unlikely(!pring))
10120 spin_lock_irq(&phba->hbalock);
10121 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10123 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10125 list_move_tail(&piocb->list, &completions);
10128 spin_unlock_irq(&phba->hbalock);
10130 /* Cancel all the IOCBs from the completions list */
10131 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10132 IOERR_SLI_ABORTED);
10136 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
10137 * @phba: pointer to lpfc hba data structure.
10139 * This routine aborts all the IOCBs currently on the driver internal
10140 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10141 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10142 * list, removes IOCBs off the list, set the status feild to
10143 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10146 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10148 LIST_HEAD(completions);
10150 spin_lock_irq(&phba->hbalock);
10151 list_splice_init(&phba->fabric_iocb_list, &completions);
10152 spin_unlock_irq(&phba->hbalock);
10154 /* Cancel all the IOCBs from the completions list */
10155 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10156 IOERR_SLI_ABORTED);
10160 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10161 * @vport: pointer to lpfc vport data structure.
10163 * This routine is invoked by the vport cleanup for deletions and the cleanup
10164 * for an ndlp on removal.
10167 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10169 struct lpfc_hba *phba = vport->phba;
10170 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10171 unsigned long iflag = 0;
10173 spin_lock_irqsave(&phba->hbalock, iflag);
10174 spin_lock(&phba->sli4_hba.sgl_list_lock);
10175 list_for_each_entry_safe(sglq_entry, sglq_next,
10176 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10177 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
10178 lpfc_nlp_put(sglq_entry->ndlp);
10179 sglq_entry->ndlp = NULL;
10182 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10183 spin_unlock_irqrestore(&phba->hbalock, iflag);
10188 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10189 * @phba: pointer to lpfc hba data structure.
10190 * @axri: pointer to the els xri abort wcqe structure.
10192 * This routine is invoked by the worker thread to process a SLI4 slow-path
10196 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10197 struct sli4_wcqe_xri_aborted *axri)
10199 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10200 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10203 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10204 unsigned long iflag = 0;
10205 struct lpfc_nodelist *ndlp;
10206 struct lpfc_sli_ring *pring;
10208 pring = lpfc_phba_elsring(phba);
10210 spin_lock_irqsave(&phba->hbalock, iflag);
10211 spin_lock(&phba->sli4_hba.sgl_list_lock);
10212 list_for_each_entry_safe(sglq_entry, sglq_next,
10213 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10214 if (sglq_entry->sli4_xritag == xri) {
10215 list_del(&sglq_entry->list);
10216 ndlp = sglq_entry->ndlp;
10217 sglq_entry->ndlp = NULL;
10218 list_add_tail(&sglq_entry->list,
10219 &phba->sli4_hba.lpfc_els_sgl_list);
10220 sglq_entry->state = SGL_FREED;
10221 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10222 spin_unlock_irqrestore(&phba->hbalock, iflag);
10225 lpfc_set_rrq_active(phba, ndlp,
10226 sglq_entry->sli4_lxritag,
10228 lpfc_nlp_put(ndlp);
10231 /* Check if TXQ queue needs to be serviced */
10232 if (pring && !list_empty(&pring->txq))
10233 lpfc_worker_wake_up(phba);
10237 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10238 lxri = lpfc_sli4_xri_inrange(phba, xri);
10239 if (lxri == NO_XRI) {
10240 spin_unlock_irqrestore(&phba->hbalock, iflag);
10243 spin_lock(&phba->sli4_hba.sgl_list_lock);
10244 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10245 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10246 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10247 spin_unlock_irqrestore(&phba->hbalock, iflag);
10250 sglq_entry->state = SGL_XRI_ABORTED;
10251 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10252 spin_unlock_irqrestore(&phba->hbalock, iflag);
10256 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10257 * @vport: pointer to virtual port object.
10258 * @ndlp: nodelist pointer for the impacted node.
10260 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10261 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10262 * the driver is required to send a LOGO to the remote node before it
10263 * attempts to recover its login to the remote node.
10266 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10267 struct lpfc_nodelist *ndlp)
10269 struct Scsi_Host *shost;
10270 struct lpfc_hba *phba;
10271 unsigned long flags = 0;
10273 shost = lpfc_shost_from_vport(vport);
10274 phba = vport->phba;
10275 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10276 lpfc_printf_log(phba, KERN_INFO,
10277 LOG_SLI, "3093 No rport recovery needed. "
10278 "rport in state 0x%x\n", ndlp->nlp_state);
10281 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10282 "3094 Start rport recovery on shost id 0x%x "
10283 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10285 shost->host_no, ndlp->nlp_DID,
10286 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10289 * The rport is not responding. Remove the FCP-2 flag to prevent
10290 * an ADISC in the follow-up recovery code.
10292 spin_lock_irqsave(&ndlp->lock, flags);
10293 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10294 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10295 spin_unlock_irqrestore(&ndlp->lock, flags);
10296 lpfc_unreg_rpi(vport, ndlp);