1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 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 /* prevent preparing iocb with NULL ndlp reference */
304 elsiocb->context1 = lpfc_nlp_get(ndlp);
305 if (!elsiocb->context1)
306 goto els_iocb_free_pbuf_exit;
307 elsiocb->context2 = pcmd;
308 elsiocb->context3 = pbuflist;
309 elsiocb->retry = retry;
310 elsiocb->vport = vport;
311 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
314 list_add(&prsp->list, &pcmd->list);
317 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
319 "0116 Xmit ELS command x%x to remote "
320 "NPORT x%x I/O tag: x%x, port state:x%x "
321 "rpi x%x fc_flag:x%x\n",
322 elscmd, did, elsiocb->iotag,
323 vport->port_state, ndlp->nlp_rpi,
326 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
327 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
328 "0117 Xmit ELS response x%x to remote "
329 "NPORT x%x I/O tag: x%x, size: x%x "
330 "port_state x%x rpi x%x fc_flag x%x\n",
331 elscmd, ndlp->nlp_DID, elsiocb->iotag,
332 cmdSize, vport->port_state,
333 ndlp->nlp_rpi, vport->fc_flag);
337 els_iocb_free_pbuf_exit:
339 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
342 els_iocb_free_prsp_exit:
343 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
346 els_iocb_free_pcmb_exit:
348 lpfc_sli_release_iocbq(phba, elsiocb);
353 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
354 * @vport: pointer to a host virtual N_Port data structure.
356 * This routine issues a fabric registration login for a @vport. An
357 * active ndlp node with Fabric_DID must already exist for this @vport.
358 * The routine invokes two mailbox commands to carry out fabric registration
359 * login through the HBA firmware: the first mailbox command requests the
360 * HBA to perform link configuration for the @vport; and the second mailbox
361 * command requests the HBA to perform the actual fabric registration login
365 * 0 - successfully issued fabric registration login for @vport
366 * -ENXIO -- failed to issue fabric registration login for @vport
369 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
371 struct lpfc_hba *phba = vport->phba;
373 struct lpfc_dmabuf *mp;
374 struct lpfc_nodelist *ndlp;
375 struct serv_parm *sp;
379 sp = &phba->fc_fabparam;
380 ndlp = lpfc_findnode_did(vport, Fabric_DID);
381 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
386 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
392 vport->port_state = LPFC_FABRIC_CFG_LINK;
393 lpfc_config_link(phba, mbox);
394 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
397 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
398 if (rc == MBX_NOT_FINISHED) {
403 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
408 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
415 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
417 /* increment the reference count on ndlp to hold reference
418 * for the callback routine.
420 mbox->ctx_ndlp = lpfc_nlp_get(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.
435 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
436 lpfc_mbuf_free(phba, mp->virt, mp->phys);
439 mempool_free(mbox, phba->mbox_mem_pool);
442 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
443 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
444 "0249 Cannot issue Register Fabric login: Err %d\n",
450 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
451 * @vport: pointer to a host virtual N_Port data structure.
453 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
454 * the @vport. This mailbox command is necessary for SLI4 port only.
457 * 0 - successfully issued REG_VFI for @vport
458 * A failure code otherwise.
461 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
463 struct lpfc_hba *phba = vport->phba;
464 LPFC_MBOXQ_t *mboxq = NULL;
465 struct lpfc_nodelist *ndlp;
466 struct lpfc_dmabuf *dmabuf = NULL;
469 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
470 if ((phba->sli_rev == LPFC_SLI_REV4) &&
471 !(phba->link_flag & LS_LOOPBACK_MODE) &&
472 !(vport->fc_flag & FC_PT2PT)) {
473 ndlp = lpfc_findnode_did(vport, Fabric_DID);
474 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
480 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
486 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
487 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
488 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
493 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
498 memcpy(dmabuf->virt, &phba->fc_fabparam,
499 sizeof(struct serv_parm));
502 vport->port_state = LPFC_FABRIC_CFG_LINK;
504 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
506 lpfc_reg_vfi(mboxq, vport, 0);
508 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
509 mboxq->vport = vport;
510 mboxq->ctx_buf = dmabuf;
511 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
512 if (rc == MBX_NOT_FINISHED) {
520 mempool_free(mboxq, phba->mbox_mem_pool);
523 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
527 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
528 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
529 "0289 Issue Register VFI failed: Err %d\n", rc);
534 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
535 * @vport: pointer to a host virtual N_Port data structure.
537 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
538 * the @vport. This mailbox command is necessary for SLI4 port only.
541 * 0 - successfully issued REG_VFI for @vport
542 * A failure code otherwise.
545 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
547 struct lpfc_hba *phba = vport->phba;
548 struct Scsi_Host *shost;
552 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
554 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
555 "2556 UNREG_VFI mbox allocation failed"
556 "HBA state x%x\n", phba->pport->port_state);
560 lpfc_unreg_vfi(mboxq, vport);
561 mboxq->vport = vport;
562 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
564 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
565 if (rc == MBX_NOT_FINISHED) {
566 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
567 "2557 UNREG_VFI issue mbox failed rc x%x "
569 rc, phba->pport->port_state);
570 mempool_free(mboxq, phba->mbox_mem_pool);
574 shost = lpfc_shost_from_vport(vport);
575 spin_lock_irq(shost->host_lock);
576 vport->fc_flag &= ~FC_VFI_REGISTERED;
577 spin_unlock_irq(shost->host_lock);
582 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
583 * @vport: pointer to a host virtual N_Port data structure.
584 * @sp: pointer to service parameter data structure.
586 * This routine is called from FLOGI/FDISC completion handler functions.
587 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
588 * node nodename is changed in the completion service parameter else return
589 * 0. This function also set flag in the vport data structure to delay
590 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
591 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
592 * node nodename is changed in the completion service parameter.
595 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
596 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
600 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
601 struct serv_parm *sp)
603 struct lpfc_hba *phba = vport->phba;
604 uint8_t fabric_param_changed = 0;
605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
607 if ((vport->fc_prevDID != vport->fc_myDID) ||
608 memcmp(&vport->fabric_portname, &sp->portName,
609 sizeof(struct lpfc_name)) ||
610 memcmp(&vport->fabric_nodename, &sp->nodeName,
611 sizeof(struct lpfc_name)) ||
612 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
613 fabric_param_changed = 1;
614 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
617 * Word 1 Bit 31 in common service parameter is overloaded.
618 * Word 1 Bit 31 in FLOGI request is multiple NPort request
619 * Word 1 Bit 31 in FLOGI response is clean address bit
621 * If fabric parameter is changed and clean address bit is
622 * cleared delay nport discovery if
623 * - vport->fc_prevDID != 0 (not initial discovery) OR
624 * - lpfc_delay_discovery module parameter is set.
626 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
627 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
628 spin_lock_irq(shost->host_lock);
629 vport->fc_flag |= FC_DISC_DELAYED;
630 spin_unlock_irq(shost->host_lock);
633 return fabric_param_changed;
638 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
639 * @vport: pointer to a host virtual N_Port data structure.
640 * @ndlp: pointer to a node-list data structure.
641 * @sp: pointer to service parameter data structure.
642 * @irsp: pointer to the IOCB within the lpfc response IOCB.
644 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
645 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
646 * port in a fabric topology. It properly sets up the parameters to the @ndlp
647 * from the IOCB response. It also check the newly assigned N_Port ID to the
648 * @vport against the previously assigned N_Port ID. If it is different from
649 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
650 * is invoked on all the remaining nodes with the @vport to unregister the
651 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
652 * is invoked to register login to the fabric.
655 * 0 - Success (currently, always return 0)
658 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
659 struct serv_parm *sp, IOCB_t *irsp)
661 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
662 struct lpfc_hba *phba = vport->phba;
663 struct lpfc_nodelist *np;
664 struct lpfc_nodelist *next_np;
665 uint8_t fabric_param_changed;
667 spin_lock_irq(shost->host_lock);
668 vport->fc_flag |= FC_FABRIC;
669 spin_unlock_irq(shost->host_lock);
671 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
672 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
673 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
675 phba->fc_edtovResol = sp->cmn.edtovResolution;
676 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
678 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
679 spin_lock_irq(shost->host_lock);
680 vport->fc_flag |= FC_PUBLIC_LOOP;
681 spin_unlock_irq(shost->host_lock);
684 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
685 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
686 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
687 ndlp->nlp_class_sup = 0;
688 if (sp->cls1.classValid)
689 ndlp->nlp_class_sup |= FC_COS_CLASS1;
690 if (sp->cls2.classValid)
691 ndlp->nlp_class_sup |= FC_COS_CLASS2;
692 if (sp->cls3.classValid)
693 ndlp->nlp_class_sup |= FC_COS_CLASS3;
694 if (sp->cls4.classValid)
695 ndlp->nlp_class_sup |= FC_COS_CLASS4;
696 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
697 sp->cmn.bbRcvSizeLsb;
699 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
700 if (fabric_param_changed) {
701 /* Reset FDMI attribute masks based on config parameter */
702 if (phba->cfg_enable_SmartSAN ||
703 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
704 /* Setup appropriate attribute masks */
705 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
706 if (phba->cfg_enable_SmartSAN)
707 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
709 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
711 vport->fdmi_hba_mask = 0;
712 vport->fdmi_port_mask = 0;
716 memcpy(&vport->fabric_portname, &sp->portName,
717 sizeof(struct lpfc_name));
718 memcpy(&vport->fabric_nodename, &sp->nodeName,
719 sizeof(struct lpfc_name));
720 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
722 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
723 if (sp->cmn.response_multiple_NPort) {
724 lpfc_printf_vlog(vport, KERN_WARNING,
726 "1816 FLOGI NPIV supported, "
727 "response data 0x%x\n",
728 sp->cmn.response_multiple_NPort);
729 spin_lock_irq(&phba->hbalock);
730 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
731 spin_unlock_irq(&phba->hbalock);
733 /* Because we asked f/w for NPIV it still expects us
734 to call reg_vnpid atleast for the physcial host */
735 lpfc_printf_vlog(vport, KERN_WARNING,
737 "1817 Fabric does not support NPIV "
738 "- configuring single port mode.\n");
739 spin_lock_irq(&phba->hbalock);
740 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
741 spin_unlock_irq(&phba->hbalock);
746 * For FC we need to do some special processing because of the SLI
747 * Port's default settings of the Common Service Parameters.
749 if ((phba->sli_rev == LPFC_SLI_REV4) &&
750 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
751 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
752 if (fabric_param_changed)
753 lpfc_unregister_fcf_prep(phba);
755 /* This should just update the VFI CSPs*/
756 if (vport->fc_flag & FC_VFI_REGISTERED)
757 lpfc_issue_reg_vfi(vport);
760 if (fabric_param_changed &&
761 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
763 /* If our NportID changed, we need to ensure all
764 * remaining NPORTs get unreg_login'ed.
766 list_for_each_entry_safe(np, next_np,
767 &vport->fc_nodes, nlp_listp) {
768 if (!NLP_CHK_NODE_ACT(np))
770 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
771 !(np->nlp_flag & NLP_NPR_ADISC))
773 spin_lock_irq(shost->host_lock);
774 np->nlp_flag &= ~NLP_NPR_ADISC;
775 spin_unlock_irq(shost->host_lock);
776 lpfc_unreg_rpi(vport, np);
778 lpfc_cleanup_pending_mbox(vport);
780 if (phba->sli_rev == LPFC_SLI_REV4) {
781 lpfc_sli4_unreg_all_rpis(vport);
782 lpfc_mbx_unreg_vpi(vport);
783 spin_lock_irq(shost->host_lock);
784 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
785 spin_unlock_irq(shost->host_lock);
789 * For SLI3 and SLI4, the VPI needs to be reregistered in
790 * response to this fabric parameter change event.
792 spin_lock_irq(shost->host_lock);
793 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
794 spin_unlock_irq(shost->host_lock);
795 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
796 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
798 * Driver needs to re-reg VPI in order for f/w
799 * to update the MAC address.
801 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
802 lpfc_register_new_vport(phba, vport, ndlp);
806 if (phba->sli_rev < LPFC_SLI_REV4) {
807 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
808 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
809 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
810 lpfc_register_new_vport(phba, vport, ndlp);
812 lpfc_issue_fabric_reglogin(vport);
814 ndlp->nlp_type |= NLP_FABRIC;
815 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
816 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
817 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
818 lpfc_start_fdiscs(phba);
819 lpfc_do_scr_ns_plogi(phba, vport);
820 } else if (vport->fc_flag & FC_VFI_REGISTERED)
821 lpfc_issue_init_vpi(vport);
823 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
824 "3135 Need register VFI: (x%x/%x)\n",
825 vport->fc_prevDID, vport->fc_myDID);
826 lpfc_issue_reg_vfi(vport);
833 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
834 * @vport: pointer to a host virtual N_Port data structure.
835 * @ndlp: pointer to a node-list data structure.
836 * @sp: pointer to service parameter data structure.
838 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
839 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
840 * in a point-to-point topology. First, the @vport's N_Port Name is compared
841 * with the received N_Port Name: if the @vport's N_Port Name is greater than
842 * the received N_Port Name lexicographically, this node shall assign local
843 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
844 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
845 * this node shall just wait for the remote node to issue PLOGI and assign
853 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
854 struct serv_parm *sp)
856 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
857 struct lpfc_hba *phba = vport->phba;
861 spin_lock_irq(shost->host_lock);
862 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
863 vport->fc_flag |= FC_PT2PT;
864 spin_unlock_irq(shost->host_lock);
866 /* If we are pt2pt with another NPort, force NPIV off! */
867 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
869 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
870 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
871 lpfc_unregister_fcf_prep(phba);
873 spin_lock_irq(shost->host_lock);
874 vport->fc_flag &= ~FC_VFI_REGISTERED;
875 spin_unlock_irq(shost->host_lock);
876 phba->fc_topology_changed = 0;
879 rc = memcmp(&vport->fc_portname, &sp->portName,
880 sizeof(vport->fc_portname));
883 /* This side will initiate the PLOGI */
884 spin_lock_irq(shost->host_lock);
885 vport->fc_flag |= FC_PT2PT_PLOGI;
886 spin_unlock_irq(shost->host_lock);
889 * N_Port ID cannot be 0, set our Id to LocalID
890 * the other side will be RemoteID.
895 vport->fc_myDID = PT2PT_LocalID;
897 /* Decrement ndlp reference count indicating that ndlp can be
898 * safely released when other references to it are done.
902 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
905 * Cannot find existing Fabric ndlp, so allocate a
908 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
911 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
912 ndlp = lpfc_enable_node(vport, ndlp,
913 NLP_STE_UNUSED_NODE);
918 memcpy(&ndlp->nlp_portname, &sp->portName,
919 sizeof(struct lpfc_name));
920 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
921 sizeof(struct lpfc_name));
922 /* Set state will put ndlp onto node list if not already done */
923 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
924 spin_lock_irq(shost->host_lock);
925 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
926 spin_unlock_irq(shost->host_lock);
928 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
932 lpfc_config_link(phba, mbox);
934 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
936 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
937 if (rc == MBX_NOT_FINISHED) {
938 mempool_free(mbox, phba->mbox_mem_pool);
942 /* This side will wait for the PLOGI, decrement ndlp reference
943 * count indicating that ndlp can be released when other
944 * references to it are done.
948 /* Start discovery - this should just do CLEAR_LA */
949 lpfc_disc_start(vport);
958 * lpfc_cmpl_els_flogi - Completion callback function for flogi
959 * @phba: pointer to lpfc hba data structure.
960 * @cmdiocb: pointer to lpfc command iocb data structure.
961 * @rspiocb: pointer to lpfc response iocb data structure.
963 * This routine is the top-level completion callback function for issuing
964 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
965 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
966 * retry has been made (either immediately or delayed with lpfc_els_retry()
967 * returning 1), the command IOCB will be released and function returned.
968 * If the retry attempt has been given up (possibly reach the maximum
969 * number of retries), one additional decrement of ndlp reference shall be
970 * invoked before going out after releasing the command IOCB. This will
971 * actually release the remote node (Note, lpfc_els_free_iocb() will also
972 * invoke one decrement of ndlp reference count). If no error reported in
973 * the IOCB status, the command Port ID field is used to determine whether
974 * this is a point-to-point topology or a fabric topology: if the Port ID
975 * field is assigned, it is a fabric topology; otherwise, it is a
976 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
977 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
978 * specific topology completion conditions.
981 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
982 struct lpfc_iocbq *rspiocb)
984 struct lpfc_vport *vport = cmdiocb->vport;
985 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
986 IOCB_t *irsp = &rspiocb->iocb;
987 struct lpfc_nodelist *ndlp = cmdiocb->context1;
988 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
989 struct serv_parm *sp;
993 /* Check to see if link went down during discovery */
994 if (lpfc_els_chk_latt(vport)) {
995 /* One additional decrement on node reference count to
996 * trigger the release of the node
1002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1003 "FLOGI cmpl: status:x%x/x%x state:x%x",
1004 irsp->ulpStatus, irsp->un.ulpWord[4],
1007 if (irsp->ulpStatus) {
1009 * In case of FIP mode, perform roundrobin FCF failover
1010 * due to new FCF discovery
1012 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1013 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1014 if (phba->link_state < LPFC_LINK_UP)
1015 goto stop_rr_fcf_flogi;
1016 if ((phba->fcoe_cvl_eventtag_attn ==
1017 phba->fcoe_cvl_eventtag) &&
1018 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1019 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1021 goto stop_rr_fcf_flogi;
1023 phba->fcoe_cvl_eventtag_attn =
1024 phba->fcoe_cvl_eventtag;
1025 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1026 "2611 FLOGI failed on FCF (x%x), "
1027 "status:x%x/x%x, tmo:x%x, perform "
1028 "roundrobin FCF failover\n",
1029 phba->fcf.current_rec.fcf_indx,
1030 irsp->ulpStatus, irsp->un.ulpWord[4],
1032 lpfc_sli4_set_fcf_flogi_fail(phba,
1033 phba->fcf.current_rec.fcf_indx);
1034 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1035 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1042 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1043 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1044 IOERR_LOOP_OPEN_FAILURE)))
1045 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1046 "2858 FLOGI failure Status:x%x/x%x TMO"
1047 ":x%x Data x%x x%x\n",
1048 irsp->ulpStatus, irsp->un.ulpWord[4],
1049 irsp->ulpTimeout, phba->hba_flag,
1050 phba->fcf.fcf_flag);
1052 /* Check for retry */
1053 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1056 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1057 "0150 FLOGI failure Status:x%x/x%x "
1058 "xri x%x TMO:x%x\n",
1059 irsp->ulpStatus, irsp->un.ulpWord[4],
1060 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1062 /* If this is not a loop open failure, bail out */
1063 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1064 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1065 IOERR_LOOP_OPEN_FAILURE)))
1068 /* FLOGI failed, so there is no fabric */
1069 spin_lock_irq(shost->host_lock);
1070 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP |
1072 spin_unlock_irq(shost->host_lock);
1074 /* If private loop, then allow max outstanding els to be
1075 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1076 * alpa map would take too long otherwise.
1078 if (phba->alpa_map[0] == 0)
1079 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1080 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1081 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1082 (vport->fc_prevDID != vport->fc_myDID) ||
1083 phba->fc_topology_changed)) {
1084 if (vport->fc_flag & FC_VFI_REGISTERED) {
1085 if (phba->fc_topology_changed) {
1086 lpfc_unregister_fcf_prep(phba);
1087 spin_lock_irq(shost->host_lock);
1088 vport->fc_flag &= ~FC_VFI_REGISTERED;
1089 spin_unlock_irq(shost->host_lock);
1090 phba->fc_topology_changed = 0;
1092 lpfc_sli4_unreg_all_rpis(vport);
1096 /* Do not register VFI if the driver aborted FLOGI */
1097 if (!lpfc_error_lost_link(irsp))
1098 lpfc_issue_reg_vfi(vport);
1104 spin_lock_irq(shost->host_lock);
1105 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1106 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1107 spin_unlock_irq(shost->host_lock);
1110 * The FLogI succeeded. Sync the data for the CPU before
1113 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1116 sp = prsp->virt + sizeof(uint32_t);
1118 /* FLOGI completes successfully */
1119 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1120 "0101 FLOGI completes successfully, I/O tag:x%x, "
1121 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1122 cmdiocb->iotag, cmdiocb->sli4_xritag,
1123 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1124 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1125 vport->port_state, vport->fc_flag);
1127 if (vport->port_state == LPFC_FLOGI) {
1129 * If Common Service Parameters indicate Nport
1130 * we are point to point, if Fport we are Fabric.
1133 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1134 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1135 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1137 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1138 "2831 FLOGI response with cleared Fabric "
1139 "bit fcf_index 0x%x "
1140 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1142 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1143 phba->fcf.current_rec.fcf_indx,
1144 phba->fcf.current_rec.switch_name[0],
1145 phba->fcf.current_rec.switch_name[1],
1146 phba->fcf.current_rec.switch_name[2],
1147 phba->fcf.current_rec.switch_name[3],
1148 phba->fcf.current_rec.switch_name[4],
1149 phba->fcf.current_rec.switch_name[5],
1150 phba->fcf.current_rec.switch_name[6],
1151 phba->fcf.current_rec.switch_name[7],
1152 phba->fcf.current_rec.fabric_name[0],
1153 phba->fcf.current_rec.fabric_name[1],
1154 phba->fcf.current_rec.fabric_name[2],
1155 phba->fcf.current_rec.fabric_name[3],
1156 phba->fcf.current_rec.fabric_name[4],
1157 phba->fcf.current_rec.fabric_name[5],
1158 phba->fcf.current_rec.fabric_name[6],
1159 phba->fcf.current_rec.fabric_name[7]);
1161 spin_lock_irq(&phba->hbalock);
1162 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1163 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1164 spin_unlock_irq(&phba->hbalock);
1165 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1169 /* Mark the FCF discovery process done */
1170 if (phba->hba_flag & HBA_FIP_SUPPORT)
1171 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1173 "2769 FLOGI to FCF (x%x) "
1174 "completed successfully\n",
1175 phba->fcf.current_rec.fcf_indx);
1176 spin_lock_irq(&phba->hbalock);
1177 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1178 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1179 spin_unlock_irq(&phba->hbalock);
1180 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1183 } else if (vport->port_state > LPFC_FLOGI &&
1184 vport->fc_flag & FC_PT2PT) {
1186 * In a p2p topology, it is possible that discovery has
1187 * already progressed, and this completion can be ignored.
1188 * Recheck the indicated topology.
1195 spin_lock_irq(&phba->hbalock);
1196 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1197 spin_unlock_irq(&phba->hbalock);
1201 if (!lpfc_error_lost_link(irsp)) {
1202 /* FLOGI failed, so just use loop map to make discovery list */
1203 lpfc_disc_list_loopmap(vport);
1205 /* Start discovery */
1206 lpfc_disc_start(vport);
1207 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1208 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1209 IOERR_SLI_ABORTED) &&
1210 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1211 IOERR_SLI_DOWN))) &&
1212 (phba->link_state != LPFC_CLEAR_LA)) {
1213 /* If FLOGI failed enable link interrupt. */
1214 lpfc_issue_clear_la(phba, vport);
1217 lpfc_els_free_iocb(phba, cmdiocb);
1221 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1222 * aborted during a link down
1223 * @phba: pointer to lpfc hba data structure.
1224 * @cmdiocb: pointer to lpfc command iocb data structure.
1225 * @rspiocb: pointer to lpfc response iocb data structure.
1229 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1230 struct lpfc_iocbq *rspiocb)
1236 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1238 irsp = &rspiocb->iocb;
1240 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1241 "6445 ELS completes after LINK_DOWN: "
1242 " Status %x/%x cmd x%x flg x%x\n",
1243 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1244 cmdiocb->iocb_flag);
1246 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1247 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1248 atomic_dec(&phba->fabric_iocb_count);
1250 lpfc_els_free_iocb(phba, cmdiocb);
1254 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1255 * @vport: pointer to a host virtual N_Port data structure.
1256 * @ndlp: pointer to a node-list data structure.
1257 * @retry: number of retries to the command IOCB.
1259 * This routine issues a Fabric Login (FLOGI) Request ELS command
1260 * for a @vport. The initiator service parameters are put into the payload
1261 * of the FLOGI Request IOCB and the top-level callback function pointer
1262 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1263 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1264 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1266 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1267 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1268 * will be stored into the context1 field of the IOCB for the completion
1269 * callback function to the FLOGI ELS command.
1272 * 0 - successfully issued flogi iocb for @vport
1273 * 1 - failed to issue flogi iocb for @vport
1276 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1279 struct lpfc_hba *phba = vport->phba;
1280 struct serv_parm *sp;
1282 struct lpfc_iocbq *elsiocb;
1283 struct lpfc_iocbq defer_flogi_acc;
1289 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1290 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1291 ndlp->nlp_DID, ELS_CMD_FLOGI);
1296 icmd = &elsiocb->iocb;
1297 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1299 /* For FLOGI request, remainder of payload is service parameters */
1300 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1301 pcmd += sizeof(uint32_t);
1302 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1303 sp = (struct serv_parm *) pcmd;
1305 /* Setup CSPs accordingly for Fabric */
1306 sp->cmn.e_d_tov = 0;
1307 sp->cmn.w2.r_a_tov = 0;
1308 sp->cmn.virtual_fabric_support = 0;
1309 sp->cls1.classValid = 0;
1310 if (sp->cmn.fcphLow < FC_PH3)
1311 sp->cmn.fcphLow = FC_PH3;
1312 if (sp->cmn.fcphHigh < FC_PH3)
1313 sp->cmn.fcphHigh = FC_PH3;
1315 if (phba->sli_rev == LPFC_SLI_REV4) {
1316 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1317 LPFC_SLI_INTF_IF_TYPE_0) {
1318 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1319 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1320 /* FLOGI needs to be 3 for WQE FCFI */
1321 /* Set the fcfi to the fcfi we registered with */
1322 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1324 /* Can't do SLI4 class2 without support sequence coalescing */
1325 sp->cls2.classValid = 0;
1326 sp->cls2.seqDelivery = 0;
1328 /* Historical, setting sequential-delivery bit for SLI3 */
1329 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1330 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1331 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1332 sp->cmn.request_multiple_Nport = 1;
1333 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1337 sp->cmn.request_multiple_Nport = 0;
1340 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1341 icmd->un.elsreq64.myID = 0;
1342 icmd->un.elsreq64.fl = 1;
1345 tmo = phba->fc_ratov;
1346 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1347 lpfc_set_disctmo(vport);
1348 phba->fc_ratov = tmo;
1350 phba->fc_stat.elsXmitFLOGI++;
1351 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1353 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1354 "Issue FLOGI: opt:x%x",
1355 phba->sli3_options, 0, 0);
1357 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1359 phba->hba_flag |= HBA_FLOGI_ISSUED;
1361 /* Check for a deferred FLOGI ACC condition */
1362 if (phba->defer_flogi_acc_flag) {
1363 did = vport->fc_myDID;
1364 vport->fc_myDID = Fabric_DID;
1366 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1368 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1369 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1370 phba->defer_flogi_acc_ox_id;
1372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1373 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1374 " ox_id: x%x, hba_flag x%x\n",
1375 phba->defer_flogi_acc_rx_id,
1376 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1378 /* Send deferred FLOGI ACC */
1379 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1382 phba->defer_flogi_acc_flag = false;
1384 vport->fc_myDID = did;
1387 if (rc == IOCB_ERROR) {
1388 lpfc_els_free_iocb(phba, elsiocb);
1395 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1396 * @phba: pointer to lpfc hba data structure.
1398 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1399 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1400 * list and issues an abort IOCB commond on each outstanding IOCB that
1401 * contains a active Fabric_DID ndlp. Note that this function is to issue
1402 * the abort IOCB command on all the outstanding IOCBs, thus when this
1403 * function returns, it does not guarantee all the IOCBs are actually aborted.
1406 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1409 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1411 struct lpfc_sli_ring *pring;
1412 struct lpfc_iocbq *iocb, *next_iocb;
1413 struct lpfc_nodelist *ndlp;
1416 /* Abort outstanding I/O on NPort <nlp_DID> */
1417 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1418 "0201 Abort outstanding I/O on NPort x%x\n",
1421 pring = lpfc_phba_elsring(phba);
1422 if (unlikely(!pring))
1426 * Check the txcmplq for an iocb that matches the nport the driver is
1429 spin_lock_irq(&phba->hbalock);
1430 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1432 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1433 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1434 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1435 (ndlp->nlp_DID == Fabric_DID))
1436 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1439 spin_unlock_irq(&phba->hbalock);
1445 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1446 * @vport: pointer to a host virtual N_Port data structure.
1448 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1449 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1450 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1451 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1452 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1453 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1457 * 0 - failed to issue initial flogi for @vport
1458 * 1 - successfully issued initial flogi for @vport
1461 lpfc_initial_flogi(struct lpfc_vport *vport)
1463 struct lpfc_nodelist *ndlp;
1465 vport->port_state = LPFC_FLOGI;
1466 lpfc_set_disctmo(vport);
1468 /* First look for the Fabric ndlp */
1469 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1471 /* Cannot find existing Fabric ndlp, so allocate a new one */
1472 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1475 /* Set the node type */
1476 ndlp->nlp_type |= NLP_FABRIC;
1477 /* Put ndlp onto node list */
1478 lpfc_enqueue_node(vport, ndlp);
1479 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1480 /* re-setup ndlp without removing from node list */
1481 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1486 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1487 /* This decrement of reference count to node shall kick off
1488 * the release of the node.
1497 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1498 * @vport: pointer to a host virtual N_Port data structure.
1500 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1501 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1502 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1503 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1504 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1505 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1509 * 0 - failed to issue initial fdisc for @vport
1510 * 1 - successfully issued initial fdisc for @vport
1513 lpfc_initial_fdisc(struct lpfc_vport *vport)
1515 struct lpfc_nodelist *ndlp;
1517 /* First look for the Fabric ndlp */
1518 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1520 /* Cannot find existing Fabric ndlp, so allocate a new one */
1521 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1524 /* Put ndlp onto node list */
1525 lpfc_enqueue_node(vport, ndlp);
1526 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1527 /* re-setup ndlp without removing from node list */
1528 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1533 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1534 /* decrement node reference count to trigger the release of
1544 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1545 * @vport: pointer to a host virtual N_Port data structure.
1547 * This routine checks whether there are more remaining Port Logins
1548 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1549 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1550 * to issue ELS PLOGIs up to the configured discover threads with the
1551 * @vport (@vport->cfg_discovery_threads). The function also decrement
1552 * the @vport's num_disc_node by 1 if it is not already 0.
1555 lpfc_more_plogi(struct lpfc_vport *vport)
1557 if (vport->num_disc_nodes)
1558 vport->num_disc_nodes--;
1560 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1561 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1562 "0232 Continue discovery with %d PLOGIs to go "
1563 "Data: x%x x%x x%x\n",
1564 vport->num_disc_nodes, vport->fc_plogi_cnt,
1565 vport->fc_flag, vport->port_state);
1566 /* Check to see if there are more PLOGIs to be sent */
1567 if (vport->fc_flag & FC_NLP_MORE)
1568 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1569 lpfc_els_disc_plogi(vport);
1575 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1576 * @phba: pointer to lpfc hba data structure.
1577 * @prsp: pointer to response IOCB payload.
1578 * @ndlp: pointer to a node-list data structure.
1580 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1581 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1582 * The following cases are considered N_Port confirmed:
1583 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1584 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1585 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1586 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1587 * 1) if there is a node on vport list other than the @ndlp with the same
1588 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1589 * on that node to release the RPI associated with the node; 2) if there is
1590 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1591 * into, a new node shall be allocated (or activated). In either case, the
1592 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1593 * be released and the new_ndlp shall be put on to the vport node list and
1594 * its pointer returned as the confirmed node.
1596 * Note that before the @ndlp got "released", the keepDID from not-matching
1597 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1598 * of the @ndlp. This is because the release of @ndlp is actually to put it
1599 * into an inactive state on the vport node list and the vport node list
1600 * management algorithm does not allow two node with a same DID.
1603 * pointer to the PLOGI N_Port @ndlp
1605 static struct lpfc_nodelist *
1606 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1607 struct lpfc_nodelist *ndlp)
1609 struct lpfc_vport *vport = ndlp->vport;
1610 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1611 struct lpfc_nodelist *new_ndlp;
1612 struct lpfc_rport_data *rdata;
1613 struct fc_rport *rport;
1614 struct serv_parm *sp;
1615 uint8_t name[sizeof(struct lpfc_name)];
1616 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1617 uint32_t keep_new_nlp_flag = 0;
1618 uint16_t keep_nlp_state;
1619 u32 keep_nlp_fc4_type = 0;
1620 struct lpfc_nvme_rport *keep_nrport = NULL;
1623 unsigned long *active_rrqs_xri_bitmap = NULL;
1625 /* Fabric nodes can have the same WWPN so we don't bother searching
1626 * by WWPN. Just return the ndlp that was given to us.
1628 if (ndlp->nlp_type & NLP_FABRIC)
1631 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1632 memset(name, 0, sizeof(struct lpfc_name));
1634 /* Now we find out if the NPort we are logging into, matches the WWPN
1635 * we have for that ndlp. If not, we have some work to do.
1637 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1639 /* return immediately if the WWPN matches ndlp */
1640 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1643 if (phba->sli_rev == LPFC_SLI_REV4) {
1644 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1646 if (active_rrqs_xri_bitmap)
1647 memset(active_rrqs_xri_bitmap, 0,
1648 phba->cfg_rrq_xri_bitmap_sz);
1651 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1652 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1653 "new_ndlp x%x x%x x%x\n",
1654 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1655 (new_ndlp ? new_ndlp->nlp_DID : 0),
1656 (new_ndlp ? new_ndlp->nlp_flag : 0),
1657 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1660 rc = memcmp(&ndlp->nlp_portname, name,
1661 sizeof(struct lpfc_name));
1663 if (active_rrqs_xri_bitmap)
1664 mempool_free(active_rrqs_xri_bitmap,
1665 phba->active_rrq_pool);
1668 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1670 if (active_rrqs_xri_bitmap)
1671 mempool_free(active_rrqs_xri_bitmap,
1672 phba->active_rrq_pool);
1675 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1676 rc = memcmp(&ndlp->nlp_portname, name,
1677 sizeof(struct lpfc_name));
1679 if (active_rrqs_xri_bitmap)
1680 mempool_free(active_rrqs_xri_bitmap,
1681 phba->active_rrq_pool);
1684 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1685 NLP_STE_UNUSED_NODE);
1687 if (active_rrqs_xri_bitmap)
1688 mempool_free(active_rrqs_xri_bitmap,
1689 phba->active_rrq_pool);
1692 keepDID = new_ndlp->nlp_DID;
1693 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1694 memcpy(active_rrqs_xri_bitmap,
1695 new_ndlp->active_rrqs_xri_bitmap,
1696 phba->cfg_rrq_xri_bitmap_sz);
1698 keepDID = new_ndlp->nlp_DID;
1699 if (phba->sli_rev == LPFC_SLI_REV4 &&
1700 active_rrqs_xri_bitmap)
1701 memcpy(active_rrqs_xri_bitmap,
1702 new_ndlp->active_rrqs_xri_bitmap,
1703 phba->cfg_rrq_xri_bitmap_sz);
1706 /* At this point in this routine, we know new_ndlp will be
1707 * returned. however, any previous GID_FTs that were done
1708 * would have updated nlp_fc4_type in ndlp, so we must ensure
1709 * new_ndlp has the right value.
1711 if (vport->fc_flag & FC_FABRIC) {
1712 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1713 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1716 lpfc_unreg_rpi(vport, new_ndlp);
1717 new_ndlp->nlp_DID = ndlp->nlp_DID;
1718 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1719 if (phba->sli_rev == LPFC_SLI_REV4)
1720 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1721 ndlp->active_rrqs_xri_bitmap,
1722 phba->cfg_rrq_xri_bitmap_sz);
1724 spin_lock_irq(shost->host_lock);
1725 keep_new_nlp_flag = new_ndlp->nlp_flag;
1726 keep_nlp_flag = ndlp->nlp_flag;
1727 new_ndlp->nlp_flag = ndlp->nlp_flag;
1729 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1730 if (keep_new_nlp_flag & NLP_UNREG_INP)
1731 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1733 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1735 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1736 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1737 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1739 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1741 ndlp->nlp_flag = keep_new_nlp_flag;
1743 /* if ndlp had NLP_UNREG_INP set, keep it */
1744 if (keep_nlp_flag & NLP_UNREG_INP)
1745 ndlp->nlp_flag |= NLP_UNREG_INP;
1747 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1749 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1750 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1751 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1753 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1755 spin_unlock_irq(shost->host_lock);
1757 /* Set nlp_states accordingly */
1758 keep_nlp_state = new_ndlp->nlp_state;
1759 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1761 /* interchange the nvme remoteport structs */
1762 keep_nrport = new_ndlp->nrport;
1763 new_ndlp->nrport = ndlp->nrport;
1765 /* Move this back to NPR state */
1766 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1767 /* The new_ndlp is replacing ndlp totally, so we need
1768 * to put ndlp on UNUSED list and try to free it.
1770 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1771 "3179 PLOGI confirm NEW: %x %x\n",
1772 new_ndlp->nlp_DID, keepDID);
1774 /* Fix up the rport accordingly */
1775 rport = ndlp->rport;
1777 rdata = rport->dd_data;
1778 if (rdata->pnode == ndlp) {
1779 /* break the link before dropping the ref */
1782 rdata->pnode = lpfc_nlp_get(new_ndlp);
1783 new_ndlp->rport = rport;
1785 new_ndlp->nlp_type = ndlp->nlp_type;
1788 /* Fix up the nvme rport */
1790 ndlp->nrport = NULL;
1794 /* We shall actually free the ndlp with both nlp_DID and
1795 * nlp_portname fields equals 0 to avoid any ndlp on the
1796 * nodelist never to be used.
1798 if (ndlp->nlp_DID == 0) {
1799 spin_lock_irq(&phba->ndlp_lock);
1800 NLP_SET_FREE_REQ(ndlp);
1801 spin_unlock_irq(&phba->ndlp_lock);
1804 /* Two ndlps cannot have the same did on the nodelist.
1805 * Note: for this case, ndlp has a NULL WWPN so setting
1806 * the nlp_fc4_type isn't required.
1808 ndlp->nlp_DID = keepDID;
1809 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1810 if (phba->sli_rev == LPFC_SLI_REV4 &&
1811 active_rrqs_xri_bitmap)
1812 memcpy(ndlp->active_rrqs_xri_bitmap,
1813 active_rrqs_xri_bitmap,
1814 phba->cfg_rrq_xri_bitmap_sz);
1816 if (!NLP_CHK_NODE_ACT(ndlp))
1817 lpfc_drop_node(vport, ndlp);
1820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1821 "3180 PLOGI confirm SWAP: %x %x\n",
1822 new_ndlp->nlp_DID, keepDID);
1824 lpfc_unreg_rpi(vport, ndlp);
1826 /* Two ndlps cannot have the same did and the fc4
1827 * type must be transferred because the ndlp is in
1830 ndlp->nlp_DID = keepDID;
1831 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1833 if (phba->sli_rev == LPFC_SLI_REV4 &&
1834 active_rrqs_xri_bitmap)
1835 memcpy(ndlp->active_rrqs_xri_bitmap,
1836 active_rrqs_xri_bitmap,
1837 phba->cfg_rrq_xri_bitmap_sz);
1839 /* Since we are switching over to the new_ndlp,
1840 * reset the old ndlp state
1842 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1843 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1844 keep_nlp_state = NLP_STE_NPR_NODE;
1845 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1847 /* Previous ndlp no longer active with nvme host transport.
1848 * Remove reference from earlier registration unless the
1849 * nvme host took care of it.
1853 ndlp->nrport = keep_nrport;
1855 /* Fix up the rport accordingly */
1856 rport = ndlp->rport;
1858 rdata = rport->dd_data;
1859 put_node = rdata->pnode != NULL;
1860 put_rport = ndlp->rport != NULL;
1861 rdata->pnode = NULL;
1866 put_device(&rport->dev);
1869 if (phba->sli_rev == LPFC_SLI_REV4 &&
1870 active_rrqs_xri_bitmap)
1871 mempool_free(active_rrqs_xri_bitmap,
1872 phba->active_rrq_pool);
1874 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1875 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1876 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1877 new_ndlp->nlp_fc4_type);
1883 * lpfc_end_rscn - Check and handle more rscn for a vport
1884 * @vport: pointer to a host virtual N_Port data structure.
1886 * This routine checks whether more Registration State Change
1887 * Notifications (RSCNs) came in while the discovery state machine was in
1888 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1889 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1890 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1891 * handling the RSCNs.
1894 lpfc_end_rscn(struct lpfc_vport *vport)
1896 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1898 if (vport->fc_flag & FC_RSCN_MODE) {
1900 * Check to see if more RSCNs came in while we were
1901 * processing this one.
1903 if (vport->fc_rscn_id_cnt ||
1904 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1905 lpfc_els_handle_rscn(vport);
1907 spin_lock_irq(shost->host_lock);
1908 vport->fc_flag &= ~FC_RSCN_MODE;
1909 spin_unlock_irq(shost->host_lock);
1915 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1916 * @phba: pointer to lpfc hba data structure.
1917 * @cmdiocb: pointer to lpfc command iocb data structure.
1918 * @rspiocb: pointer to lpfc response iocb data structure.
1920 * This routine will call the clear rrq function to free the rrq and
1921 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1922 * exist then the clear_rrq is still called because the rrq needs to
1927 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1928 struct lpfc_iocbq *rspiocb)
1930 struct lpfc_vport *vport = cmdiocb->vport;
1932 struct lpfc_nodelist *ndlp;
1933 struct lpfc_node_rrq *rrq;
1935 /* we pass cmdiocb to state machine which needs rspiocb as well */
1936 rrq = cmdiocb->context_un.rrq;
1937 cmdiocb->context_un.rsp_iocb = rspiocb;
1939 irsp = &rspiocb->iocb;
1940 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1941 "RRQ cmpl: status:x%x/x%x did:x%x",
1942 irsp->ulpStatus, irsp->un.ulpWord[4],
1943 irsp->un.elsreq64.remoteID);
1945 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1946 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1947 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1948 "2882 RRQ completes to NPort x%x "
1949 "with no ndlp. Data: x%x x%x x%x\n",
1950 irsp->un.elsreq64.remoteID,
1951 irsp->ulpStatus, irsp->un.ulpWord[4],
1956 /* rrq completes to NPort <nlp_DID> */
1957 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1958 "2880 RRQ completes to NPort x%x "
1959 "Data: x%x x%x x%x x%x x%x\n",
1960 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1961 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1963 if (irsp->ulpStatus) {
1964 /* Check for retry */
1965 /* RRQ failed Don't print the vport to vport rjts */
1966 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1967 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1968 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1969 (phba)->pport->cfg_log_verbose & LOG_ELS)
1970 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1971 "2881 RRQ failure DID:%06X Status:"
1973 ndlp->nlp_DID, irsp->ulpStatus,
1974 irsp->un.ulpWord[4]);
1978 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1979 lpfc_els_free_iocb(phba, cmdiocb);
1983 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1984 * @phba: pointer to lpfc hba data structure.
1985 * @cmdiocb: pointer to lpfc command iocb data structure.
1986 * @rspiocb: pointer to lpfc response iocb data structure.
1988 * This routine is the completion callback function for issuing the Port
1989 * Login (PLOGI) command. For PLOGI completion, there must be an active
1990 * ndlp on the vport node list that matches the remote node ID from the
1991 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1992 * ignored and command IOCB released. The PLOGI response IOCB status is
1993 * checked for error conditons. If there is error status reported, PLOGI
1994 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1995 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1996 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1997 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1998 * there are additional N_Port nodes with the vport that need to perform
1999 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
2003 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2004 struct lpfc_iocbq *rspiocb)
2006 struct lpfc_vport *vport = cmdiocb->vport;
2007 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2009 struct lpfc_nodelist *ndlp;
2010 struct lpfc_dmabuf *prsp;
2013 /* we pass cmdiocb to state machine which needs rspiocb as well */
2014 cmdiocb->context_un.rsp_iocb = rspiocb;
2016 irsp = &rspiocb->iocb;
2017 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2018 "PLOGI cmpl: status:x%x/x%x did:x%x",
2019 irsp->ulpStatus, irsp->un.ulpWord[4],
2020 irsp->un.elsreq64.remoteID);
2022 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
2023 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
2024 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2025 "0136 PLOGI completes to NPort x%x "
2026 "with no ndlp. Data: x%x x%x x%x\n",
2027 irsp->un.elsreq64.remoteID,
2028 irsp->ulpStatus, irsp->un.ulpWord[4],
2033 /* Since ndlp can be freed in the disc state machine, note if this node
2034 * is being used during discovery.
2036 spin_lock_irq(shost->host_lock);
2037 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2038 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2039 spin_unlock_irq(shost->host_lock);
2041 /* PLOGI completes to NPort <nlp_DID> */
2042 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2043 "0102 PLOGI completes to NPort x%06x "
2044 "Data: x%x x%x x%x x%x x%x\n",
2045 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2046 irsp->ulpStatus, irsp->un.ulpWord[4],
2047 disc, vport->num_disc_nodes);
2049 /* Check to see if link went down during discovery */
2050 if (lpfc_els_chk_latt(vport)) {
2051 spin_lock_irq(shost->host_lock);
2052 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2053 spin_unlock_irq(shost->host_lock);
2057 if (irsp->ulpStatus) {
2058 /* Check for retry */
2059 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2060 /* ELS command is being retried */
2062 spin_lock_irq(shost->host_lock);
2063 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2064 spin_unlock_irq(shost->host_lock);
2068 /* PLOGI failed Don't print the vport to vport rjts */
2069 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2070 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2071 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2072 (phba)->pport->cfg_log_verbose & LOG_ELS)
2073 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2074 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2075 ndlp->nlp_DID, irsp->ulpStatus,
2076 irsp->un.ulpWord[4]);
2077 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2078 if (!lpfc_error_lost_link(irsp))
2079 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2080 NLP_EVT_CMPL_PLOGI);
2082 /* Good status, call state machine */
2083 prsp = list_entry(((struct lpfc_dmabuf *)
2084 cmdiocb->context2)->list.next,
2085 struct lpfc_dmabuf, list);
2086 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2087 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2088 NLP_EVT_CMPL_PLOGI);
2091 if (disc && vport->num_disc_nodes) {
2092 /* Check to see if there are more PLOGIs to be sent */
2093 lpfc_more_plogi(vport);
2095 if (vport->num_disc_nodes == 0) {
2096 spin_lock_irq(shost->host_lock);
2097 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2098 spin_unlock_irq(shost->host_lock);
2100 lpfc_can_disctmo(vport);
2101 lpfc_end_rscn(vport);
2106 lpfc_els_free_iocb(phba, cmdiocb);
2111 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2112 * @vport: pointer to a host virtual N_Port data structure.
2113 * @did: destination port identifier.
2114 * @retry: number of retries to the command IOCB.
2116 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2117 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2118 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2119 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2120 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2122 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2123 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2124 * will be stored into the context1 field of the IOCB for the completion
2125 * callback function to the PLOGI ELS command.
2128 * 0 - Successfully issued a plogi for @vport
2129 * 1 - failed to issue a plogi for @vport
2132 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2134 struct lpfc_hba *phba = vport->phba;
2135 struct Scsi_Host *shost;
2136 struct serv_parm *sp;
2137 struct lpfc_nodelist *ndlp;
2138 struct lpfc_iocbq *elsiocb;
2143 ndlp = lpfc_findnode_did(vport, did);
2146 /* Defer the processing of the issue PLOGI until after the
2147 * outstanding UNREG_RPI mbox command completes, unless we
2148 * are going offline. This logic does not apply for Fabric DIDs
2150 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2151 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2152 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2153 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2154 "4110 Issue PLOGI x%x deferred "
2155 "on NPort x%x rpi x%x Data: x%px\n",
2156 ndlp->nlp_defer_did, ndlp->nlp_DID,
2157 ndlp->nlp_rpi, ndlp);
2159 /* We can only defer 1st PLOGI */
2160 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2161 ndlp->nlp_defer_did = did;
2164 if (!NLP_CHK_NODE_ACT(ndlp))
2168 /* If ndlp is not NULL, we will bump the reference count on it */
2169 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2170 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2175 shost = lpfc_shost_from_vport(vport);
2176 spin_lock_irq(shost->host_lock);
2177 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2178 spin_unlock_irq(shost->host_lock);
2180 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2182 /* For PLOGI request, remainder of payload is service parameters */
2183 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2184 pcmd += sizeof(uint32_t);
2185 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2186 sp = (struct serv_parm *) pcmd;
2189 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2190 * to device on remote loops work.
2192 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2193 sp->cmn.altBbCredit = 1;
2195 if (sp->cmn.fcphLow < FC_PH_4_3)
2196 sp->cmn.fcphLow = FC_PH_4_3;
2198 if (sp->cmn.fcphHigh < FC_PH3)
2199 sp->cmn.fcphHigh = FC_PH3;
2201 sp->cmn.valid_vendor_ver_level = 0;
2202 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2203 sp->cmn.bbRcvSizeMsb &= 0xF;
2205 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2206 "Issue PLOGI: did:x%x",
2209 /* If our firmware supports this feature, convey that
2210 * information to the target using the vendor specific field.
2212 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2213 sp->cmn.valid_vendor_ver_level = 1;
2214 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2215 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2218 phba->fc_stat.elsXmitPLOGI++;
2219 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2220 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2222 if (ret == IOCB_ERROR) {
2223 lpfc_els_free_iocb(phba, elsiocb);
2230 * lpfc_cmpl_els_prli - Completion callback function for prli
2231 * @phba: pointer to lpfc hba data structure.
2232 * @cmdiocb: pointer to lpfc command iocb data structure.
2233 * @rspiocb: pointer to lpfc response iocb data structure.
2235 * This routine is the completion callback function for a Process Login
2236 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2237 * status. If there is error status reported, PRLI retry shall be attempted
2238 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2239 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2240 * ndlp to mark the PRLI completion.
2243 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2244 struct lpfc_iocbq *rspiocb)
2246 struct lpfc_vport *vport = cmdiocb->vport;
2247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2249 struct lpfc_nodelist *ndlp;
2253 /* we pass cmdiocb to state machine which needs rspiocb as well */
2254 cmdiocb->context_un.rsp_iocb = rspiocb;
2256 irsp = &(rspiocb->iocb);
2257 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2258 spin_lock_irq(shost->host_lock);
2259 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2261 /* Driver supports multiple FC4 types. Counters matter. */
2262 vport->fc_prli_sent--;
2263 ndlp->fc4_prli_sent--;
2264 spin_unlock_irq(shost->host_lock);
2266 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2267 "PRLI cmpl: status:x%x/x%x did:x%x",
2268 irsp->ulpStatus, irsp->un.ulpWord[4],
2271 /* PRLI completes to NPort <nlp_DID> */
2272 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2273 "0103 PRLI completes to NPort x%06x "
2274 "Data: x%x x%x x%x x%x\n",
2275 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2276 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2278 /* Check to see if link went down during discovery */
2279 if (lpfc_els_chk_latt(vport))
2282 if (irsp->ulpStatus) {
2283 /* Check for retry */
2284 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2285 /* ELS command is being retried */
2289 /* If we don't send GFT_ID to Fabric, a PRLI error
2290 * could be expected.
2292 if ((vport->fc_flag & FC_FABRIC) ||
2293 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2295 loglevel = LOG_TRACE_EVENT;
2302 lpfc_printf_vlog(vport, mode, loglevel,
2303 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2305 ndlp->nlp_DID, irsp->ulpStatus,
2306 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2308 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2309 if (lpfc_error_lost_link(irsp))
2312 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2315 /* Good status, call state machine. However, if another
2316 * PRLI is outstanding, don't call the state machine
2317 * because final disposition to Mapped or Unmapped is
2320 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2325 lpfc_els_free_iocb(phba, cmdiocb);
2330 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2331 * @vport: pointer to a host virtual N_Port data structure.
2332 * @ndlp: pointer to a node-list data structure.
2333 * @retry: number of retries to the command IOCB.
2335 * This routine issues a Process Login (PRLI) ELS command for the
2336 * @vport. The PRLI service parameters are set up in the payload of the
2337 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2338 * is put to the IOCB completion callback func field before invoking the
2339 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2341 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2342 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2343 * will be stored into the context1 field of the IOCB for the completion
2344 * callback function to the PRLI ELS command.
2347 * 0 - successfully issued prli iocb command for @vport
2348 * 1 - failed to issue prli iocb command for @vport
2351 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2354 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2355 struct lpfc_hba *phba = vport->phba;
2357 struct lpfc_nvme_prli *npr_nvme;
2358 struct lpfc_iocbq *elsiocb;
2361 u32 local_nlp_type, elscmd;
2364 * If we are in RSCN mode, the FC4 types supported from a
2365 * previous GFT_ID command may not be accurate. So, if we
2366 * are a NVME Initiator, always look for the possibility of
2367 * the remote NPort beng a NVME Target.
2369 if (phba->sli_rev == LPFC_SLI_REV4 &&
2370 vport->fc_flag & FC_RSCN_MODE &&
2371 vport->nvmei_support)
2372 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2373 local_nlp_type = ndlp->nlp_fc4_type;
2375 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2376 * fields here before any of them can complete.
2378 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2379 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2380 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2381 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2382 ndlp->nvme_fb_size = 0;
2385 if (local_nlp_type & NLP_FC4_FCP) {
2386 /* Payload is 4 + 16 = 20 x14 bytes. */
2387 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2388 elscmd = ELS_CMD_PRLI;
2389 } else if (local_nlp_type & NLP_FC4_NVME) {
2390 /* Payload is 4 + 20 = 24 x18 bytes. */
2391 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2392 elscmd = ELS_CMD_NVMEPRLI;
2394 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2395 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2396 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2400 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2401 * FC4 type, implicitly LOGO.
2403 if (phba->sli_rev == LPFC_SLI_REV3 &&
2404 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2405 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2406 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2408 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2412 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2413 ndlp->nlp_DID, elscmd);
2417 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2419 /* For PRLI request, remainder of payload is service parameters */
2420 memset(pcmd, 0, cmdsize);
2422 if (local_nlp_type & NLP_FC4_FCP) {
2423 /* Remainder of payload is FCP PRLI parameter page.
2424 * Note: this data structure is defined as
2425 * BE/LE in the structure definition so no
2426 * byte swap call is made.
2428 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2429 pcmd += sizeof(uint32_t);
2433 * If our firmware version is 3.20 or later,
2434 * set the following bits for FC-TAPE support.
2436 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2437 npr->ConfmComplAllowed = 1;
2439 npr->TaskRetryIdReq = 1;
2441 npr->estabImagePair = 1;
2442 npr->readXferRdyDis = 1;
2443 if (vport->cfg_first_burst_size)
2444 npr->writeXferRdyDis = 1;
2446 /* For FCP support */
2447 npr->prliType = PRLI_FCP_TYPE;
2448 npr->initiatorFunc = 1;
2449 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2451 /* Remove FCP type - processed. */
2452 local_nlp_type &= ~NLP_FC4_FCP;
2453 } else if (local_nlp_type & NLP_FC4_NVME) {
2454 /* Remainder of payload is NVME PRLI parameter page.
2455 * This data structure is the newer definition that
2456 * uses bf macros so a byte swap is required.
2458 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2459 pcmd += sizeof(uint32_t);
2460 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2461 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2462 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2464 bf_set(prli_nsler, npr_nvme, 1);
2465 bf_set(prli_conf, npr_nvme, 1);
2468 /* Only initiators request first burst. */
2469 if ((phba->cfg_nvme_enable_fb) &&
2470 !phba->nvmet_support)
2471 bf_set(prli_fba, npr_nvme, 1);
2473 if (phba->nvmet_support) {
2474 bf_set(prli_tgt, npr_nvme, 1);
2475 bf_set(prli_disc, npr_nvme, 1);
2477 bf_set(prli_init, npr_nvme, 1);
2478 bf_set(prli_conf, npr_nvme, 1);
2481 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2482 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2483 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2485 /* Remove NVME type - processed. */
2486 local_nlp_type &= ~NLP_FC4_NVME;
2489 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2490 "Issue PRLI: did:x%x",
2491 ndlp->nlp_DID, 0, 0);
2493 phba->fc_stat.elsXmitPRLI++;
2494 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2495 spin_lock_irq(shost->host_lock);
2496 ndlp->nlp_flag |= NLP_PRLI_SND;
2498 /* The vport counters are used for lpfc_scan_finished, but
2499 * the ndlp is used to track outstanding PRLIs for different
2502 vport->fc_prli_sent++;
2503 ndlp->fc4_prli_sent++;
2504 spin_unlock_irq(shost->host_lock);
2505 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2507 spin_lock_irq(shost->host_lock);
2508 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2509 spin_unlock_irq(shost->host_lock);
2510 lpfc_els_free_iocb(phba, elsiocb);
2515 /* The driver supports 2 FC4 types. Make sure
2516 * a PRLI is issued for all types before exiting.
2518 if (phba->sli_rev == LPFC_SLI_REV4 &&
2519 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2520 goto send_next_prli;
2526 * lpfc_rscn_disc - Perform rscn discovery for a vport
2527 * @vport: pointer to a host virtual N_Port data structure.
2529 * This routine performs Registration State Change Notification (RSCN)
2530 * discovery for a @vport. If the @vport's node port recovery count is not
2531 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2532 * the nodes that need recovery. If none of the PLOGI were needed through
2533 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2534 * invoked to check and handle possible more RSCN came in during the period
2535 * of processing the current ones.
2538 lpfc_rscn_disc(struct lpfc_vport *vport)
2540 lpfc_can_disctmo(vport);
2542 /* RSCN discovery */
2543 /* go thru NPR nodes and issue ELS PLOGIs */
2544 if (vport->fc_npr_cnt)
2545 if (lpfc_els_disc_plogi(vport))
2548 lpfc_end_rscn(vport);
2552 * lpfc_adisc_done - Complete the adisc phase of discovery
2553 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2555 * This function is called when the final ADISC is completed during discovery.
2556 * This function handles clearing link attention or issuing reg_vpi depending
2557 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2559 * This function is called with no locks held.
2562 lpfc_adisc_done(struct lpfc_vport *vport)
2564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2565 struct lpfc_hba *phba = vport->phba;
2568 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2569 * and continue discovery.
2571 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2572 !(vport->fc_flag & FC_RSCN_MODE) &&
2573 (phba->sli_rev < LPFC_SLI_REV4)) {
2574 /* The ADISCs are complete. Doesn't matter if they
2575 * succeeded or failed because the ADISC completion
2576 * routine guarantees to call the state machine and
2577 * the RPI is either unregistered (failed ADISC response)
2578 * or the RPI is still valid and the node is marked
2579 * mapped for a target. The exchanges should be in the
2580 * correct state. This code is specific to SLI3.
2582 lpfc_issue_clear_la(phba, vport);
2583 lpfc_issue_reg_vpi(phba, vport);
2587 * For SLI2, we need to set port_state to READY
2588 * and continue discovery.
2590 if (vport->port_state < LPFC_VPORT_READY) {
2591 /* If we get here, there is nothing to ADISC */
2592 lpfc_issue_clear_la(phba, vport);
2593 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2594 vport->num_disc_nodes = 0;
2595 /* go thru NPR list, issue ELS PLOGIs */
2596 if (vport->fc_npr_cnt)
2597 lpfc_els_disc_plogi(vport);
2598 if (!vport->num_disc_nodes) {
2599 spin_lock_irq(shost->host_lock);
2600 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2601 spin_unlock_irq(shost->host_lock);
2602 lpfc_can_disctmo(vport);
2603 lpfc_end_rscn(vport);
2606 vport->port_state = LPFC_VPORT_READY;
2608 lpfc_rscn_disc(vport);
2612 * lpfc_more_adisc - Issue more adisc as needed
2613 * @vport: pointer to a host virtual N_Port data structure.
2615 * This routine determines whether there are more ndlps on a @vport
2616 * node list need to have Address Discover (ADISC) issued. If so, it will
2617 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2618 * remaining nodes which need to have ADISC sent.
2621 lpfc_more_adisc(struct lpfc_vport *vport)
2623 if (vport->num_disc_nodes)
2624 vport->num_disc_nodes--;
2625 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2626 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2627 "0210 Continue discovery with %d ADISCs to go "
2628 "Data: x%x x%x x%x\n",
2629 vport->num_disc_nodes, vport->fc_adisc_cnt,
2630 vport->fc_flag, vport->port_state);
2631 /* Check to see if there are more ADISCs to be sent */
2632 if (vport->fc_flag & FC_NLP_MORE) {
2633 lpfc_set_disctmo(vport);
2634 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2635 lpfc_els_disc_adisc(vport);
2637 if (!vport->num_disc_nodes)
2638 lpfc_adisc_done(vport);
2643 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2644 * @phba: pointer to lpfc hba data structure.
2645 * @cmdiocb: pointer to lpfc command iocb data structure.
2646 * @rspiocb: pointer to lpfc response iocb data structure.
2648 * This routine is the completion function for issuing the Address Discover
2649 * (ADISC) command. It first checks to see whether link went down during
2650 * the discovery process. If so, the node will be marked as node port
2651 * recovery for issuing discover IOCB by the link attention handler and
2652 * exit. Otherwise, the response status is checked. If error was reported
2653 * in the response status, the ADISC command shall be retried by invoking
2654 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2655 * the response status, the state machine is invoked to set transition
2656 * with respect to NLP_EVT_CMPL_ADISC event.
2659 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2660 struct lpfc_iocbq *rspiocb)
2662 struct lpfc_vport *vport = cmdiocb->vport;
2663 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2665 struct lpfc_nodelist *ndlp;
2668 /* we pass cmdiocb to state machine which needs rspiocb as well */
2669 cmdiocb->context_un.rsp_iocb = rspiocb;
2671 irsp = &(rspiocb->iocb);
2672 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2675 "ADISC cmpl: status:x%x/x%x did:x%x",
2676 irsp->ulpStatus, irsp->un.ulpWord[4],
2679 /* Since ndlp can be freed in the disc state machine, note if this node
2680 * is being used during discovery.
2682 spin_lock_irq(shost->host_lock);
2683 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2684 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2685 spin_unlock_irq(shost->host_lock);
2686 /* ADISC completes to NPort <nlp_DID> */
2687 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2688 "0104 ADISC completes to NPort x%x "
2689 "Data: x%x x%x x%x x%x x%x\n",
2690 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2691 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2692 /* Check to see if link went down during discovery */
2693 if (lpfc_els_chk_latt(vport)) {
2694 spin_lock_irq(shost->host_lock);
2695 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2696 spin_unlock_irq(shost->host_lock);
2700 if (irsp->ulpStatus) {
2701 /* Check for retry */
2702 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2703 /* ELS command is being retried */
2705 spin_lock_irq(shost->host_lock);
2706 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2707 spin_unlock_irq(shost->host_lock);
2708 lpfc_set_disctmo(vport);
2713 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2714 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2715 ndlp->nlp_DID, irsp->ulpStatus,
2716 irsp->un.ulpWord[4]);
2717 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2718 if (!lpfc_error_lost_link(irsp))
2719 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2720 NLP_EVT_CMPL_ADISC);
2722 /* Good status, call state machine */
2723 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2724 NLP_EVT_CMPL_ADISC);
2726 /* Check to see if there are more ADISCs to be sent */
2727 if (disc && vport->num_disc_nodes)
2728 lpfc_more_adisc(vport);
2730 lpfc_els_free_iocb(phba, cmdiocb);
2735 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2736 * @vport: pointer to a virtual N_Port data structure.
2737 * @ndlp: pointer to a node-list data structure.
2738 * @retry: number of retries to the command IOCB.
2740 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2741 * @vport. It prepares the payload of the ADISC ELS command, updates the
2742 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2743 * to issue the ADISC ELS command.
2745 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2746 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2747 * will be stored into the context1 field of the IOCB for the completion
2748 * callback function to the ADISC ELS command.
2751 * 0 - successfully issued adisc
2752 * 1 - failed to issue adisc
2755 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2758 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2759 struct lpfc_hba *phba = vport->phba;
2761 struct lpfc_iocbq *elsiocb;
2765 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2766 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2767 ndlp->nlp_DID, ELS_CMD_ADISC);
2771 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2773 /* For ADISC request, remainder of payload is service parameters */
2774 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2775 pcmd += sizeof(uint32_t);
2777 /* Fill in ADISC payload */
2778 ap = (ADISC *) pcmd;
2779 ap->hardAL_PA = phba->fc_pref_ALPA;
2780 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2781 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2782 ap->DID = be32_to_cpu(vport->fc_myDID);
2784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2785 "Issue ADISC: did:x%x",
2786 ndlp->nlp_DID, 0, 0);
2788 phba->fc_stat.elsXmitADISC++;
2789 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2790 spin_lock_irq(shost->host_lock);
2791 ndlp->nlp_flag |= NLP_ADISC_SND;
2792 spin_unlock_irq(shost->host_lock);
2793 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2795 spin_lock_irq(shost->host_lock);
2796 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2797 spin_unlock_irq(shost->host_lock);
2798 lpfc_els_free_iocb(phba, elsiocb);
2805 * lpfc_cmpl_els_logo - Completion callback function for logo
2806 * @phba: pointer to lpfc hba data structure.
2807 * @cmdiocb: pointer to lpfc command iocb data structure.
2808 * @rspiocb: pointer to lpfc response iocb data structure.
2810 * This routine is the completion function for issuing the ELS Logout (LOGO)
2811 * command. If no error status was reported from the LOGO response, the
2812 * state machine of the associated ndlp shall be invoked for transition with
2813 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2814 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2817 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2818 struct lpfc_iocbq *rspiocb)
2820 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2821 struct lpfc_vport *vport = ndlp->vport;
2822 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2824 struct lpfcMboxq *mbox;
2825 unsigned long flags;
2826 uint32_t skip_recovery = 0;
2828 /* we pass cmdiocb to state machine which needs rspiocb as well */
2829 cmdiocb->context_un.rsp_iocb = rspiocb;
2831 irsp = &(rspiocb->iocb);
2832 spin_lock_irq(shost->host_lock);
2833 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2834 spin_unlock_irq(shost->host_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 "Data: x%x x%x x%x x%x\n",
2845 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2846 irsp->ulpTimeout, vport->num_disc_nodes);
2848 if (lpfc_els_chk_latt(vport)) {
2853 /* Check to see if link went down during discovery */
2854 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2855 /* NLP_EVT_DEVICE_RM should unregister the RPI
2856 * which should abort all outstanding IOs.
2858 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2864 /* The LOGO will not be retried on failure. A LOGO was
2865 * issued to the remote rport and a ACC or RJT or no Answer are
2866 * all acceptable. Note the failure and move forward with
2867 * discovery. The PLOGI will retry.
2869 if (irsp->ulpStatus) {
2871 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2872 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2873 ndlp->nlp_DID, irsp->ulpStatus,
2874 irsp->un.ulpWord[4]);
2875 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2876 if (lpfc_error_lost_link(irsp)) {
2882 /* Call state machine. This will unregister the rpi if needed. */
2883 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2886 lpfc_els_free_iocb(phba, cmdiocb);
2887 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2888 if ((vport->fc_flag & FC_PT2PT) &&
2889 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2890 phba->pport->fc_myDID = 0;
2892 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2893 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2894 if (phba->nvmet_support)
2895 lpfc_nvmet_update_targetport(phba);
2897 lpfc_nvme_update_localport(phba->pport);
2900 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2902 lpfc_config_link(phba, mbox);
2903 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2904 mbox->vport = vport;
2905 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2907 mempool_free(mbox, phba->mbox_mem_pool);
2914 * If the node is a target, the handling attempts to recover the port.
2915 * For any other port type, the rpi is unregistered as an implicit
2918 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2919 skip_recovery == 0) {
2920 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2921 spin_lock_irqsave(shost->host_lock, flags);
2922 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2923 spin_unlock_irqrestore(shost->host_lock, flags);
2925 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2926 "3187 LOGO completes to NPort x%x: Start "
2927 "Recovery Data: x%x x%x x%x x%x\n",
2928 ndlp->nlp_DID, irsp->ulpStatus,
2929 irsp->un.ulpWord[4], irsp->ulpTimeout,
2930 vport->num_disc_nodes);
2931 lpfc_disc_start(vport);
2937 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2938 * @vport: pointer to a virtual N_Port data structure.
2939 * @ndlp: pointer to a node-list data structure.
2940 * @retry: number of retries to the command IOCB.
2942 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2943 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2944 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2945 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2947 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2948 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2949 * will be stored into the context1 field of the IOCB for the completion
2950 * callback function to the LOGO ELS command.
2952 * Callers of this routine are expected to unregister the RPI first
2955 * 0 - successfully issued logo
2956 * 1 - failed to issue logo
2959 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2962 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2963 struct lpfc_hba *phba = vport->phba;
2964 struct lpfc_iocbq *elsiocb;
2969 spin_lock_irq(shost->host_lock);
2970 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2971 spin_unlock_irq(shost->host_lock);
2974 spin_unlock_irq(shost->host_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 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2992 "Issue LOGO: did:x%x",
2993 ndlp->nlp_DID, 0, 0);
2995 phba->fc_stat.elsXmitLOGO++;
2996 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2997 spin_lock_irq(shost->host_lock);
2998 ndlp->nlp_flag |= NLP_LOGO_SND;
2999 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
3000 spin_unlock_irq(shost->host_lock);
3001 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3002 if (rc == IOCB_ERROR) {
3003 spin_lock_irq(shost->host_lock);
3004 ndlp->nlp_flag &= ~NLP_LOGO_SND;
3005 spin_unlock_irq(shost->host_lock);
3006 lpfc_els_free_iocb(phba, elsiocb);
3010 spin_lock_irq(shost->host_lock);
3011 ndlp->nlp_prev_state = ndlp->nlp_state;
3012 spin_unlock_irq(shost->host_lock);
3013 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3018 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3019 * @phba: pointer to lpfc hba data structure.
3020 * @cmdiocb: pointer to lpfc command iocb data structure.
3021 * @rspiocb: pointer to lpfc response iocb data structure.
3023 * This routine is a generic completion callback function for ELS commands.
3024 * Specifically, it is the callback function which does not need to perform
3025 * any command specific operations. It is currently used by the ELS command
3026 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3027 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3028 * Other than certain debug loggings, this callback function simply invokes the
3029 * lpfc_els_chk_latt() routine to check whether link went down during the
3030 * discovery process.
3033 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3034 struct lpfc_iocbq *rspiocb)
3036 struct lpfc_vport *vport = cmdiocb->vport;
3039 irsp = &rspiocb->iocb;
3041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3042 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3043 irsp->ulpStatus, irsp->un.ulpWord[4],
3044 irsp->un.elsreq64.remoteID);
3046 /* ELS cmd tag <ulpIoTag> completes */
3047 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3048 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3049 irsp->ulpIoTag, irsp->ulpStatus,
3050 irsp->un.ulpWord[4], irsp->ulpTimeout);
3052 /* Check to see if link went down during discovery */
3053 lpfc_els_chk_latt(vport);
3054 lpfc_els_free_iocb(phba, cmdiocb);
3058 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3059 * @phba: pointer to lpfc hba data structure.
3060 * @cmdiocb: pointer to lpfc command iocb data structure.
3061 * @rspiocb: pointer to lpfc response iocb data structure.
3063 * This routine is a generic completion callback function for Discovery ELS cmd.
3064 * Currently used by the ELS command issuing routines for the ELS State Change
3065 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3066 * These commands will be retried once only for ELS timeout errors.
3069 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3070 struct lpfc_iocbq *rspiocb)
3072 struct lpfc_vport *vport = cmdiocb->vport;
3074 struct lpfc_els_rdf_rsp *prdf;
3075 struct lpfc_dmabuf *pcmd, *prsp;
3079 irsp = &rspiocb->iocb;
3081 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3082 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3083 irsp->ulpStatus, irsp->un.ulpWord[4],
3084 irsp->un.elsreq64.remoteID);
3085 /* ELS cmd tag <ulpIoTag> completes */
3086 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3087 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3089 irsp->ulpIoTag, irsp->ulpStatus,
3090 irsp->un.ulpWord[4], irsp->ulpTimeout,
3093 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3097 pdata = (u32 *)pcmd->virt;
3102 /* Only 1 retry for ELS Timeout only */
3103 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3104 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3105 IOERR_SEQUENCE_TIMEOUT)) {
3107 if (cmdiocb->retry <= 1) {
3110 lpfc_issue_els_scr(vport, cmdiocb->retry);
3113 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3114 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3119 phba->fc_stat.elsRetryExceeded++;
3121 if (irsp->ulpStatus) {
3122 /* ELS discovery cmd completes with error */
3123 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3124 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3125 irsp->ulpStatus, irsp->un.ulpWord[4]);
3129 /* The RDF response doesn't have any impact on the running driver
3130 * but the notification descriptors are dumped here for support.
3132 if (cmd == ELS_CMD_RDF) {
3135 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3139 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3143 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3144 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3145 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3146 "4677 Fabric RDF Notification Grant Data: "
3149 prdf->reg_d1.desc_tags[i]));
3153 /* Check to see if link went down during discovery */
3154 lpfc_els_chk_latt(vport);
3155 lpfc_els_free_iocb(phba, cmdiocb);
3160 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3161 * @vport: pointer to a host virtual N_Port data structure.
3162 * @retry: retry counter for the command IOCB.
3164 * This routine issues a State Change Request (SCR) to a fabric node
3165 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3166 * first search the @vport node list to find the matching ndlp. If no such
3167 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3168 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3169 * routine is invoked to send the SCR IOCB.
3171 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3172 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3173 * will be stored into the context1 field of the IOCB for the completion
3174 * callback function to the SCR ELS command.
3177 * 0 - Successfully issued scr command
3178 * 1 - Failed to issue scr command
3181 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3183 struct lpfc_hba *phba = vport->phba;
3184 struct lpfc_iocbq *elsiocb;
3187 struct lpfc_nodelist *ndlp;
3189 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3191 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3193 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3196 lpfc_enqueue_node(vport, ndlp);
3197 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3198 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3203 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3204 ndlp->nlp_DID, ELS_CMD_SCR);
3207 /* This will trigger the release of the node just
3214 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3216 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3217 pcmd += sizeof(uint32_t);
3219 /* For SCR, remainder of payload is SCR parameter page */
3220 memset(pcmd, 0, sizeof(SCR));
3221 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3223 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3224 "Issue SCR: did:x%x",
3225 ndlp->nlp_DID, 0, 0);
3227 phba->fc_stat.elsXmitSCR++;
3228 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3229 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3231 /* The additional lpfc_nlp_put will cause the following
3232 * lpfc_els_free_iocb routine to trigger the rlease of
3236 lpfc_els_free_iocb(phba, elsiocb);
3239 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3240 * trigger the release of node.
3242 if (!(vport->fc_flag & FC_PT2PT))
3248 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3249 * or the other nport (pt2pt).
3250 * @vport: pointer to a host virtual N_Port data structure.
3251 * @retry: number of retries to the command IOCB.
3253 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3254 * when connected to a fabric, or to the remote port when connected
3255 * in point-to-point mode. When sent to the Fabric Controller, it will
3256 * replay the RSCN to registered recipients.
3258 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3259 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3260 * will be stored into the context1 field of the IOCB for the completion
3261 * callback function to the RSCN ELS command.
3264 * 0 - Successfully issued RSCN command
3265 * 1 - Failed to issue RSCN command
3268 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3270 struct lpfc_hba *phba = vport->phba;
3271 struct lpfc_iocbq *elsiocb;
3272 struct lpfc_nodelist *ndlp;
3274 struct fc_els_rscn rscn;
3275 struct fc_els_rscn_page portid;
3278 uint16_t cmdsize = sizeof(*event);
3280 /* Not supported for private loop */
3281 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3282 !(vport->fc_flag & FC_PUBLIC_LOOP))
3285 if (vport->fc_flag & FC_PT2PT) {
3286 /* find any mapped nport - that would be the other nport */
3287 ndlp = lpfc_findnode_mapped(vport);
3291 nportid = FC_FID_FCTRL;
3292 /* find the fabric controller node */
3293 ndlp = lpfc_findnode_did(vport, nportid);
3295 /* if one didn't exist, make one */
3296 ndlp = lpfc_nlp_init(vport, nportid);
3299 lpfc_enqueue_node(vport, ndlp);
3300 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3301 ndlp = lpfc_enable_node(vport, ndlp,
3302 NLP_STE_UNUSED_NODE);
3308 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3309 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3312 /* This will trigger the release of the node just
3319 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3321 event->rscn.rscn_cmd = ELS_RSCN;
3322 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3323 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3325 nportid = vport->fc_myDID;
3326 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3327 event->portid.rscn_page_flags = 0;
3328 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3329 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3330 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3332 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3333 "Issue RSCN: did:x%x",
3334 ndlp->nlp_DID, 0, 0);
3336 phba->fc_stat.elsXmitRSCN++;
3337 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3338 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3340 /* The additional lpfc_nlp_put will cause the following
3341 * lpfc_els_free_iocb routine to trigger the rlease of
3345 lpfc_els_free_iocb(phba, elsiocb);
3348 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3349 * trigger the release of node.
3351 if (!(vport->fc_flag & FC_PT2PT))
3358 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3359 * @vport: pointer to a host virtual N_Port data structure.
3360 * @nportid: N_Port identifier to the remote node.
3361 * @retry: number of retries to the command IOCB.
3363 * This routine issues a Fibre Channel Address Resolution Response
3364 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3365 * is passed into the function. It first search the @vport node list to find
3366 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3367 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3368 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3370 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3371 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3372 * will be stored into the context1 field of the IOCB for the completion
3373 * callback function to the PARPR ELS command.
3376 * 0 - Successfully issued farpr command
3377 * 1 - Failed to issue farpr command
3380 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3382 struct lpfc_hba *phba = vport->phba;
3383 struct lpfc_iocbq *elsiocb;
3388 struct lpfc_nodelist *ondlp;
3389 struct lpfc_nodelist *ndlp;
3391 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3393 ndlp = lpfc_findnode_did(vport, nportid);
3395 ndlp = lpfc_nlp_init(vport, nportid);
3398 lpfc_enqueue_node(vport, ndlp);
3399 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3400 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3405 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3406 ndlp->nlp_DID, ELS_CMD_RNID);
3408 /* This will trigger the release of the node just
3415 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3417 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3418 pcmd += sizeof(uint32_t);
3420 /* Fill in FARPR payload */
3421 fp = (FARP *) (pcmd);
3422 memset(fp, 0, sizeof(FARP));
3423 lp = (uint32_t *) pcmd;
3424 *lp++ = be32_to_cpu(nportid);
3425 *lp++ = be32_to_cpu(vport->fc_myDID);
3427 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3429 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3430 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3431 ondlp = lpfc_findnode_did(vport, nportid);
3432 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3433 memcpy(&fp->OportName, &ondlp->nlp_portname,
3434 sizeof(struct lpfc_name));
3435 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3436 sizeof(struct lpfc_name));
3439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3440 "Issue FARPR: did:x%x",
3441 ndlp->nlp_DID, 0, 0);
3443 phba->fc_stat.elsXmitFARPR++;
3444 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3445 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3447 /* The additional lpfc_nlp_put will cause the following
3448 * lpfc_els_free_iocb routine to trigger the release of
3452 lpfc_els_free_iocb(phba, elsiocb);
3455 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3456 * trigger the release of the node.
3458 /* Don't release reference count as RDF is likely outstanding */
3463 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3464 * @vport: pointer to a host virtual N_Port data structure.
3465 * @retry: retry counter for the command IOCB.
3467 * This routine issues an ELS RDF to the Fabric Controller to register
3468 * for diagnostic functions.
3470 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3471 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3472 * will be stored into the context1 field of the IOCB for the completion
3473 * callback function to the RDF ELS command.
3476 * 0 - Successfully issued rdf command
3477 * 1 - Failed to issue rdf command
3480 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3482 struct lpfc_hba *phba = vport->phba;
3483 struct lpfc_iocbq *elsiocb;
3484 struct lpfc_els_rdf_req *prdf;
3485 struct lpfc_nodelist *ndlp;
3488 cmdsize = sizeof(*prdf);
3490 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3492 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3495 lpfc_enqueue_node(vport, ndlp);
3496 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3497 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3502 /* RDF ELS is not required on an NPIV VN_Port. */
3503 if (vport->port_type == LPFC_NPIV_PORT) {
3508 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3509 ndlp->nlp_DID, ELS_CMD_RDF);
3511 /* This will trigger the release of the node just
3518 /* Configure the payload for the supported FPIN events. */
3519 prdf = (struct lpfc_els_rdf_req *)
3520 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3521 memset(prdf, 0, cmdsize);
3522 prdf->rdf.fpin_cmd = ELS_RDF;
3523 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3524 sizeof(struct fc_els_rdf));
3525 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3526 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3527 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3528 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3529 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3530 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3531 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3532 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3535 "Issue RDF: did:x%x",
3536 ndlp->nlp_DID, 0, 0);
3538 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3539 "6444 Xmit RDF to remote NPORT x%x\n",
3542 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3543 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3545 /* The additional lpfc_nlp_put will cause the following
3546 * lpfc_els_free_iocb routine to trigger the rlease of
3550 lpfc_els_free_iocb(phba, elsiocb);
3554 /* An RDF was issued - this put ensures the ndlp is cleaned up
3555 * when the RDF completes.
3562 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3563 * @vport: pointer to a host virtual N_Port data structure.
3564 * @nlp: pointer to a node-list data structure.
3566 * This routine cancels the timer with a delayed IOCB-command retry for
3567 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3568 * removes the ELS retry event if it presents. In addition, if the
3569 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3570 * commands are sent for the @vport's nodes that require issuing discovery
3574 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3576 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3577 struct lpfc_work_evt *evtp;
3579 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3581 spin_lock_irq(shost->host_lock);
3582 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3583 spin_unlock_irq(shost->host_lock);
3584 del_timer_sync(&nlp->nlp_delayfunc);
3585 nlp->nlp_last_elscmd = 0;
3586 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3587 list_del_init(&nlp->els_retry_evt.evt_listp);
3588 /* Decrement nlp reference count held for the delayed retry */
3589 evtp = &nlp->els_retry_evt;
3590 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3592 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3593 spin_lock_irq(shost->host_lock);
3594 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3595 spin_unlock_irq(shost->host_lock);
3596 if (vport->num_disc_nodes) {
3597 if (vport->port_state < LPFC_VPORT_READY) {
3598 /* Check if there are more ADISCs to be sent */
3599 lpfc_more_adisc(vport);
3601 /* Check if there are more PLOGIs to be sent */
3602 lpfc_more_plogi(vport);
3603 if (vport->num_disc_nodes == 0) {
3604 spin_lock_irq(shost->host_lock);
3605 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3606 spin_unlock_irq(shost->host_lock);
3607 lpfc_can_disctmo(vport);
3608 lpfc_end_rscn(vport);
3617 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3618 * @t: pointer to the timer function associated data (ndlp).
3620 * This routine is invoked by the ndlp delayed-function timer to check
3621 * whether there is any pending ELS retry event(s) with the node. If not, it
3622 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3623 * adds the delayed events to the HBA work list and invokes the
3624 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3625 * event. Note that lpfc_nlp_get() is called before posting the event to
3626 * the work list to hold reference count of ndlp so that it guarantees the
3627 * reference to ndlp will still be available when the worker thread gets
3628 * to the event associated with the ndlp.
3631 lpfc_els_retry_delay(struct timer_list *t)
3633 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3634 struct lpfc_vport *vport = ndlp->vport;
3635 struct lpfc_hba *phba = vport->phba;
3636 unsigned long flags;
3637 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3639 spin_lock_irqsave(&phba->hbalock, flags);
3640 if (!list_empty(&evtp->evt_listp)) {
3641 spin_unlock_irqrestore(&phba->hbalock, flags);
3645 /* We need to hold the node by incrementing the reference
3646 * count until the queued work is done
3648 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3649 if (evtp->evt_arg1) {
3650 evtp->evt = LPFC_EVT_ELS_RETRY;
3651 list_add_tail(&evtp->evt_listp, &phba->work_list);
3652 lpfc_worker_wake_up(phba);
3654 spin_unlock_irqrestore(&phba->hbalock, flags);
3659 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3660 * @ndlp: pointer to a node-list data structure.
3662 * This routine is the worker-thread handler for processing the @ndlp delayed
3663 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3664 * the last ELS command from the associated ndlp and invokes the proper ELS
3665 * function according to the delayed ELS command to retry the command.
3668 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3670 struct lpfc_vport *vport = ndlp->vport;
3671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3672 uint32_t cmd, retry;
3674 spin_lock_irq(shost->host_lock);
3675 cmd = ndlp->nlp_last_elscmd;
3676 ndlp->nlp_last_elscmd = 0;
3678 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3679 spin_unlock_irq(shost->host_lock);
3683 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3684 spin_unlock_irq(shost->host_lock);
3686 * If a discovery event readded nlp_delayfunc after timer
3687 * firing and before processing the timer, cancel the
3690 del_timer_sync(&ndlp->nlp_delayfunc);
3691 retry = ndlp->nlp_retry;
3692 ndlp->nlp_retry = 0;
3696 lpfc_issue_els_flogi(vport, ndlp, retry);
3699 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3700 ndlp->nlp_prev_state = ndlp->nlp_state;
3701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3705 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3706 ndlp->nlp_prev_state = ndlp->nlp_state;
3707 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3711 case ELS_CMD_NVMEPRLI:
3712 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3713 ndlp->nlp_prev_state = ndlp->nlp_state;
3714 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3718 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3719 ndlp->nlp_prev_state = ndlp->nlp_state;
3720 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3724 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3725 lpfc_issue_els_fdisc(vport, ndlp, retry);
3732 * lpfc_link_reset - Issue link reset
3733 * @vport: pointer to a virtual N_Port data structure.
3735 * This routine performs link reset by sending INIT_LINK mailbox command.
3736 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3737 * INIT_LINK mailbox command.
3740 * 0 - Link reset initiated successfully
3741 * 1 - Failed to initiate link reset
3744 lpfc_link_reset(struct lpfc_vport *vport)
3746 struct lpfc_hba *phba = vport->phba;
3751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3752 "2851 Attempt link reset\n");
3753 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3755 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3756 "2852 Failed to allocate mbox memory");
3760 /* Enable Link attention interrupts */
3761 if (phba->sli_rev <= LPFC_SLI_REV3) {
3762 spin_lock_irq(&phba->hbalock);
3763 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3764 control = readl(phba->HCregaddr);
3765 control |= HC_LAINT_ENA;
3766 writel(control, phba->HCregaddr);
3767 readl(phba->HCregaddr); /* flush */
3768 spin_unlock_irq(&phba->hbalock);
3771 lpfc_init_link(phba, mbox, phba->cfg_topology,
3772 phba->cfg_link_speed);
3773 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3774 mbox->vport = vport;
3775 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3776 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3777 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3778 "2853 Failed to issue INIT_LINK "
3779 "mbox command, rc:x%x\n", rc);
3780 mempool_free(mbox, phba->mbox_mem_pool);
3788 * lpfc_els_retry - Make retry decision on an els command iocb
3789 * @phba: pointer to lpfc hba data structure.
3790 * @cmdiocb: pointer to lpfc command iocb data structure.
3791 * @rspiocb: pointer to lpfc response iocb data structure.
3793 * This routine makes a retry decision on an ELS command IOCB, which has
3794 * failed. The following ELS IOCBs use this function for retrying the command
3795 * when previously issued command responsed with error status: FLOGI, PLOGI,
3796 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3797 * returned error status, it makes the decision whether a retry shall be
3798 * issued for the command, and whether a retry shall be made immediately or
3799 * delayed. In the former case, the corresponding ELS command issuing-function
3800 * is called to retry the command. In the later case, the ELS command shall
3801 * be posted to the ndlp delayed event and delayed function timer set to the
3802 * ndlp for the delayed command issusing.
3805 * 0 - No retry of els command is made
3806 * 1 - Immediate or delayed retry of els command is made
3809 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3810 struct lpfc_iocbq *rspiocb)
3812 struct lpfc_vport *vport = cmdiocb->vport;
3813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3814 IOCB_t *irsp = &rspiocb->iocb;
3815 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3816 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3819 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3823 int link_reset = 0, rc;
3826 /* Note: context2 may be 0 for internal driver abort
3827 * of delays ELS command.
3830 if (pcmd && pcmd->virt) {
3831 elscmd = (uint32_t *) (pcmd->virt);
3835 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3836 did = ndlp->nlp_DID;
3838 /* We should only hit this case for retrying PLOGI */
3839 did = irsp->un.elsreq64.remoteID;
3840 ndlp = lpfc_findnode_did(vport, did);
3841 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3842 && (cmd != ELS_CMD_PLOGI))
3846 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3847 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3848 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3850 switch (irsp->ulpStatus) {
3851 case IOSTAT_FCP_RSP_ERROR:
3853 case IOSTAT_REMOTE_STOP:
3854 if (phba->sli_rev == LPFC_SLI_REV4) {
3855 /* This IO was aborted by the target, we don't
3856 * know the rxid and because we did not send the
3857 * ABTS we cannot generate and RRQ.
3859 lpfc_set_rrq_active(phba, ndlp,
3860 cmdiocb->sli4_lxritag, 0, 0);
3863 case IOSTAT_LOCAL_REJECT:
3864 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3865 case IOERR_LOOP_OPEN_FAILURE:
3866 if (cmd == ELS_CMD_FLOGI) {
3867 if (PCI_DEVICE_ID_HORNET ==
3868 phba->pcidev->device) {
3869 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3870 phba->pport->fc_myDID = 0;
3871 phba->alpa_map[0] = 0;
3872 phba->alpa_map[1] = 0;
3875 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3880 case IOERR_ILLEGAL_COMMAND:
3881 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3882 "0124 Retry illegal cmd x%x "
3883 "retry:x%x delay:x%x\n",
3884 cmd, cmdiocb->retry, delay);
3886 /* All command's retry policy */
3888 if (cmdiocb->retry > 2)
3892 case IOERR_NO_RESOURCES:
3893 logerr = 1; /* HBA out of resources */
3895 if (cmdiocb->retry > 100)
3900 case IOERR_ILLEGAL_FRAME:
3905 case IOERR_INVALID_RPI:
3906 if (cmd == ELS_CMD_PLOGI &&
3907 did == NameServer_DID) {
3908 /* Continue forever if plogi to */
3909 /* the nameserver fails */
3916 case IOERR_SEQUENCE_TIMEOUT:
3917 if (cmd == ELS_CMD_PLOGI &&
3918 did == NameServer_DID &&
3919 (cmdiocb->retry + 1) == maxretry) {
3920 /* Reset the Link */
3930 case IOSTAT_NPORT_RJT:
3931 case IOSTAT_FABRIC_RJT:
3932 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3938 case IOSTAT_NPORT_BSY:
3939 case IOSTAT_FABRIC_BSY:
3940 logerr = 1; /* Fabric / Remote NPort out of resources */
3945 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3946 /* Added for Vendor specifc support
3947 * Just keep retrying for these Rsn / Exp codes
3949 if ((vport->fc_flag & FC_PT2PT) &&
3950 cmd == ELS_CMD_NVMEPRLI) {
3951 switch (stat.un.b.lsRjtRsnCode) {
3952 case LSRJT_UNABLE_TPC:
3953 case LSRJT_INVALID_CMD:
3954 case LSRJT_LOGICAL_ERR:
3955 case LSRJT_CMD_UNSUPPORTED:
3956 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3957 "0168 NVME PRLI LS_RJT "
3958 "reason %x port doesn't "
3959 "support NVME, disabling NVME\n",
3960 stat.un.b.lsRjtRsnCode);
3962 vport->fc_flag |= FC_PT2PT_NO_NVME;
3966 switch (stat.un.b.lsRjtRsnCode) {
3967 case LSRJT_UNABLE_TPC:
3968 /* The driver has a VALID PLOGI but the rport has
3969 * rejected the PRLI - can't do it now. Delay
3970 * for 1 second and try again.
3972 * However, if explanation is REQ_UNSUPPORTED there's
3973 * no point to retry PRLI.
3975 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3976 stat.un.b.lsRjtRsnCodeExp !=
3977 LSEXP_REQ_UNSUPPORTED) {
3979 maxretry = lpfc_max_els_tries + 1;
3984 /* Legacy bug fix code for targets with PLOGI delays. */
3985 if (stat.un.b.lsRjtRsnCodeExp ==
3986 LSEXP_CMD_IN_PROGRESS) {
3987 if (cmd == ELS_CMD_PLOGI) {
3994 if (stat.un.b.lsRjtRsnCodeExp ==
3995 LSEXP_CANT_GIVE_DATA) {
3996 if (cmd == ELS_CMD_PLOGI) {
4003 if (cmd == ELS_CMD_PLOGI) {
4005 maxretry = lpfc_max_els_tries + 1;
4009 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4010 (cmd == ELS_CMD_FDISC) &&
4011 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
4012 lpfc_printf_vlog(vport, KERN_ERR,
4014 "0125 FDISC Failed (x%x). "
4015 "Fabric out of resources\n",
4016 stat.un.lsRjtError);
4017 lpfc_vport_set_state(vport,
4018 FC_VPORT_NO_FABRIC_RSCS);
4022 case LSRJT_LOGICAL_BSY:
4023 if ((cmd == ELS_CMD_PLOGI) ||
4024 (cmd == ELS_CMD_PRLI) ||
4025 (cmd == ELS_CMD_NVMEPRLI)) {
4028 } else if (cmd == ELS_CMD_FDISC) {
4029 /* FDISC retry policy */
4031 if (cmdiocb->retry >= 32)
4037 case LSRJT_LOGICAL_ERR:
4038 /* There are some cases where switches return this
4039 * error when they are not ready and should be returning
4040 * Logical Busy. We should delay every time.
4042 if (cmd == ELS_CMD_FDISC &&
4043 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4047 } else if (cmd == ELS_CMD_FLOGI &&
4048 stat.un.b.lsRjtRsnCodeExp ==
4049 LSEXP_NOTHING_MORE) {
4050 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4052 lpfc_printf_vlog(vport, KERN_ERR,
4054 "0820 FLOGI Failed (x%x). "
4055 "BBCredit Not Supported\n",
4056 stat.un.lsRjtError);
4060 case LSRJT_PROTOCOL_ERR:
4061 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4062 (cmd == ELS_CMD_FDISC) &&
4063 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4064 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4066 lpfc_printf_vlog(vport, KERN_ERR,
4068 "0122 FDISC Failed (x%x). "
4069 "Fabric Detected Bad WWN\n",
4070 stat.un.lsRjtError);
4071 lpfc_vport_set_state(vport,
4072 FC_VPORT_FABRIC_REJ_WWN);
4075 case LSRJT_VENDOR_UNIQUE:
4076 if ((stat.un.b.vendorUnique == 0x45) &&
4077 (cmd == ELS_CMD_FLOGI)) {
4081 case LSRJT_CMD_UNSUPPORTED:
4082 /* lpfc nvmet returns this type of LS_RJT when it
4083 * receives an FCP PRLI because lpfc nvmet only
4084 * support NVME. ELS request is terminated for FCP4
4087 if (stat.un.b.lsRjtRsnCodeExp ==
4088 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4089 spin_lock_irq(shost->host_lock);
4090 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4091 spin_unlock_irq(shost->host_lock);
4099 case IOSTAT_INTERMED_RSP:
4108 rc = lpfc_link_reset(vport);
4110 /* Do not give up. Retry PLOGI one more time and attempt
4111 * link reset if PLOGI fails again.
4120 if (did == FDMI_DID)
4123 if ((cmd == ELS_CMD_FLOGI) &&
4124 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4125 !lpfc_error_lost_link(irsp)) {
4126 /* FLOGI retry policy */
4128 /* retry FLOGI forever */
4129 if (phba->link_flag != LS_LOOPBACK_MODE)
4134 if (cmdiocb->retry >= 100)
4136 else if (cmdiocb->retry >= 32)
4138 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4139 /* retry FDISCs every second up to devloss */
4141 maxretry = vport->cfg_devloss_tmo;
4146 if (maxretry && (cmdiocb->retry >= maxretry)) {
4147 phba->fc_stat.elsRetryExceeded++;
4151 if ((vport->load_flag & FC_UNLOADING) != 0)
4156 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4157 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4158 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4159 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4160 "2849 Stop retry ELS command "
4161 "x%x to remote NPORT x%x, "
4162 "Data: x%x x%x\n", cmd, did,
4163 cmdiocb->retry, delay);
4168 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4169 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4170 "0107 Retry ELS command x%x to remote "
4171 "NPORT x%x Data: x%x x%x\n",
4172 cmd, did, cmdiocb->retry, delay);
4174 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4175 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4176 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4177 IOERR_NO_RESOURCES))) {
4178 /* Don't reset timer for no resources */
4180 /* If discovery / RSCN timer is running, reset it */
4181 if (timer_pending(&vport->fc_disctmo) ||
4182 (vport->fc_flag & FC_RSCN_MODE))
4183 lpfc_set_disctmo(vport);
4186 phba->fc_stat.elsXmitRetry++;
4187 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
4188 phba->fc_stat.elsDelayRetry++;
4189 ndlp->nlp_retry = cmdiocb->retry;
4191 /* delay is specified in milliseconds */
4192 mod_timer(&ndlp->nlp_delayfunc,
4193 jiffies + msecs_to_jiffies(delay));
4194 spin_lock_irq(shost->host_lock);
4195 ndlp->nlp_flag |= NLP_DELAY_TMO;
4196 spin_unlock_irq(shost->host_lock);
4198 ndlp->nlp_prev_state = ndlp->nlp_state;
4199 if ((cmd == ELS_CMD_PRLI) ||
4200 (cmd == ELS_CMD_NVMEPRLI))
4201 lpfc_nlp_set_state(vport, ndlp,
4202 NLP_STE_PRLI_ISSUE);
4204 lpfc_nlp_set_state(vport, ndlp,
4206 ndlp->nlp_last_elscmd = cmd;
4212 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4215 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4218 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
4219 ndlp->nlp_prev_state = ndlp->nlp_state;
4220 lpfc_nlp_set_state(vport, ndlp,
4221 NLP_STE_PLOGI_ISSUE);
4223 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4226 ndlp->nlp_prev_state = ndlp->nlp_state;
4227 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4228 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4231 case ELS_CMD_NVMEPRLI:
4232 ndlp->nlp_prev_state = ndlp->nlp_state;
4233 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4234 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4237 ndlp->nlp_prev_state = ndlp->nlp_state;
4238 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4239 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4243 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4245 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4246 "0137 No retry ELS command x%x to remote "
4247 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4248 cmd, did, irsp->ulpStatus,
4249 irsp->un.ulpWord[4]);
4252 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4253 "0108 No retry ELS command x%x to remote "
4254 "NPORT x%x Retried:%d Error:x%x/%x\n",
4255 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4256 irsp->un.ulpWord[4]);
4262 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4263 * @phba: pointer to lpfc hba data structure.
4264 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4266 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4267 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4268 * checks to see whether there is a lpfc DMA buffer associated with the
4269 * response of the command IOCB. If so, it will be released before releasing
4270 * the lpfc DMA buffer associated with the IOCB itself.
4273 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4276 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4278 struct lpfc_dmabuf *buf_ptr;
4280 /* Free the response before processing the command. */
4281 if (!list_empty(&buf_ptr1->list)) {
4282 list_remove_head(&buf_ptr1->list, buf_ptr,
4285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4288 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4294 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4295 * @phba: pointer to lpfc hba data structure.
4296 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4298 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4299 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4303 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4306 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4308 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4314 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4315 * @phba: pointer to lpfc hba data structure.
4316 * @elsiocb: pointer to lpfc els command iocb data structure.
4318 * This routine frees a command IOCB and its associated resources. The
4319 * command IOCB data structure contains the reference to various associated
4320 * resources, these fields must be set to NULL if the associated reference
4322 * context1 - reference to ndlp
4323 * context2 - reference to cmd
4324 * context2->next - reference to rsp
4325 * context3 - reference to bpl
4327 * It first properly decrements the reference count held on ndlp for the
4328 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4329 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4330 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4331 * adds the DMA buffer the @phba data structure for the delayed release.
4332 * If reference to the Buffer Pointer List (BPL) is present, the
4333 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4334 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4335 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4338 * 0 - Success (currently, always return 0)
4341 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4343 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4344 struct lpfc_nodelist *ndlp;
4346 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
4348 if (ndlp->nlp_flag & NLP_DEFER_RM) {
4351 /* If the ndlp is not being used by another discovery
4354 if (!lpfc_nlp_not_used(ndlp)) {
4355 /* If ndlp is being used by another discovery
4356 * thread, just clear NLP_DEFER_RM
4358 ndlp->nlp_flag &= ~NLP_DEFER_RM;
4363 elsiocb->context1 = NULL;
4365 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4366 if (elsiocb->context2) {
4367 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4368 /* Firmware could still be in progress of DMAing
4369 * payload, so don't free data buffer till after
4372 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4373 buf_ptr = elsiocb->context2;
4374 elsiocb->context2 = NULL;
4377 spin_lock_irq(&phba->hbalock);
4378 if (!list_empty(&buf_ptr->list)) {
4379 list_remove_head(&buf_ptr->list,
4380 buf_ptr1, struct lpfc_dmabuf,
4382 INIT_LIST_HEAD(&buf_ptr1->list);
4383 list_add_tail(&buf_ptr1->list,
4387 INIT_LIST_HEAD(&buf_ptr->list);
4388 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4390 spin_unlock_irq(&phba->hbalock);
4393 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4394 lpfc_els_free_data(phba, buf_ptr1);
4395 elsiocb->context2 = NULL;
4399 if (elsiocb->context3) {
4400 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4401 lpfc_els_free_bpl(phba, buf_ptr);
4402 elsiocb->context3 = NULL;
4404 lpfc_sli_release_iocbq(phba, elsiocb);
4409 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4410 * @phba: pointer to lpfc hba data structure.
4411 * @cmdiocb: pointer to lpfc command iocb data structure.
4412 * @rspiocb: pointer to lpfc response iocb data structure.
4414 * This routine is the completion callback function to the Logout (LOGO)
4415 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4416 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4417 * release the ndlp if it has the last reference remaining (reference count
4418 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4419 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4420 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4421 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4422 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4423 * IOCB data structure.
4426 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4427 struct lpfc_iocbq *rspiocb)
4429 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4430 struct lpfc_vport *vport = cmdiocb->vport;
4433 irsp = &rspiocb->iocb;
4434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4435 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4436 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4437 /* ACC to LOGO completes to NPort <nlp_DID> */
4438 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4439 "0109 ACC to LOGO completes to NPort x%x "
4440 "Data: x%x x%x x%x\n",
4441 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4444 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4445 /* NPort Recovery mode or node is just allocated */
4446 if (!lpfc_nlp_not_used(ndlp)) {
4447 /* If the ndlp is being used by another discovery
4448 * thread, just unregister the RPI.
4450 lpfc_unreg_rpi(vport, ndlp);
4452 /* Indicate the node has already released, should
4453 * not reference to it from within lpfc_els_free_iocb.
4455 cmdiocb->context1 = NULL;
4460 * The driver received a LOGO from the rport and has ACK'd it.
4461 * At this point, the driver is done so release the IOCB
4463 lpfc_els_free_iocb(phba, cmdiocb);
4467 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4468 * @phba: pointer to lpfc hba data structure.
4469 * @pmb: pointer to the driver internal queue element for mailbox command.
4471 * This routine is the completion callback function for unregister default
4472 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4473 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4474 * decrements the ndlp reference count held for this completion callback
4475 * function. After that, it invokes the lpfc_nlp_not_used() to check
4476 * whether there is only one reference left on the ndlp. If so, it will
4477 * perform one more decrement and trigger the release of the ndlp.
4480 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4482 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4483 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4485 pmb->ctx_buf = NULL;
4486 pmb->ctx_ndlp = NULL;
4488 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4490 mempool_free(pmb, phba->mbox_mem_pool);
4492 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4493 "0006 rpi%x DID:%x flg:%x %d map:%x x%px\n",
4494 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4495 kref_read(&ndlp->kref),
4496 ndlp->nlp_usg_map, ndlp);
4497 if (NLP_CHK_NODE_ACT(ndlp)) {
4499 /* This is the end of the default RPI cleanup logic for
4500 * this ndlp. If no other discovery threads are using
4501 * this ndlp, free all resources associated with it.
4503 lpfc_nlp_not_used(ndlp);
4505 lpfc_drop_node(ndlp->vport, ndlp);
4513 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4514 * @phba: pointer to lpfc hba data structure.
4515 * @cmdiocb: pointer to lpfc command iocb data structure.
4516 * @rspiocb: pointer to lpfc response iocb data structure.
4518 * This routine is the completion callback function for ELS Response IOCB
4519 * command. In normal case, this callback function just properly sets the
4520 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4521 * field in the command IOCB is not NULL, the referred mailbox command will
4522 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4523 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4524 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4525 * routine shall be invoked trying to release the ndlp if no other threads
4526 * are currently referring it.
4529 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4530 struct lpfc_iocbq *rspiocb)
4532 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4533 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4534 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4537 LPFC_MBOXQ_t *mbox = NULL;
4538 struct lpfc_dmabuf *mp = NULL;
4539 uint32_t ls_rjt = 0;
4541 irsp = &rspiocb->iocb;
4544 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4545 "3177 ELS response failed\n");
4548 if (cmdiocb->context_un.mbox)
4549 mbox = cmdiocb->context_un.mbox;
4551 /* First determine if this is a LS_RJT cmpl. Note, this callback
4552 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4554 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4555 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4556 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4557 /* A LS_RJT associated with Default RPI cleanup has its own
4558 * separate code path.
4560 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4564 /* Check to see if link went down during discovery */
4565 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
4567 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4569 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4572 mempool_free(mbox, phba->mbox_mem_pool);
4574 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4575 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4576 if (lpfc_nlp_not_used(ndlp)) {
4578 /* Indicate the node has already released,
4579 * should not reference to it from within
4580 * the routine lpfc_els_free_iocb.
4582 cmdiocb->context1 = NULL;
4587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4588 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4589 irsp->ulpStatus, irsp->un.ulpWord[4],
4590 cmdiocb->iocb.un.elsreq64.remoteID);
4591 /* ELS response tag <ulpIoTag> completes */
4592 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4593 "0110 ELS response tag x%x completes "
4594 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4595 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4596 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4597 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4600 if ((rspiocb->iocb.ulpStatus == 0)
4601 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4602 if (!lpfc_unreg_rpi(vport, ndlp) &&
4603 (!(vport->fc_flag & FC_PT2PT)) &&
4604 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4605 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4606 lpfc_printf_vlog(vport, KERN_INFO,
4608 "0314 PLOGI recov DID x%x "
4609 "Data: x%x x%x x%x\n",
4610 ndlp->nlp_DID, ndlp->nlp_state,
4611 ndlp->nlp_rpi, ndlp->nlp_flag);
4614 lpfc_mbuf_free(phba, mp->virt,
4618 mempool_free(mbox, phba->mbox_mem_pool);
4622 /* Increment reference count to ndlp to hold the
4623 * reference to ndlp for the callback function.
4625 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4626 mbox->vport = vport;
4627 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4628 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4629 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4632 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4633 ndlp->nlp_prev_state = ndlp->nlp_state;
4634 lpfc_nlp_set_state(vport, ndlp,
4635 NLP_STE_REG_LOGIN_ISSUE);
4638 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4639 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4640 != MBX_NOT_FINISHED)
4643 /* Decrement the ndlp reference count we
4644 * set for this failed mailbox command.
4647 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4649 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4650 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4651 "0138 ELS rsp: Cannot issue reg_login for x%x "
4652 "Data: x%x x%x x%x\n",
4653 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4656 if (lpfc_nlp_not_used(ndlp)) {
4658 /* Indicate node has already been released,
4659 * should not reference to it from within
4660 * the routine lpfc_els_free_iocb.
4662 cmdiocb->context1 = NULL;
4665 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4666 if (!lpfc_error_lost_link(irsp) &&
4667 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4668 if (lpfc_nlp_not_used(ndlp)) {
4670 /* Indicate node has already been
4671 * released, should not reference
4672 * to it from within the routine
4673 * lpfc_els_free_iocb.
4675 cmdiocb->context1 = NULL;
4679 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4681 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4684 mempool_free(mbox, phba->mbox_mem_pool);
4687 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
4688 spin_lock_irq(shost->host_lock);
4690 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4691 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4692 spin_unlock_irq(shost->host_lock);
4694 /* If the node is not being used by another discovery thread,
4695 * and we are sending a reject, we are done with it.
4696 * Release driver reference count here and free associated
4700 if (lpfc_nlp_not_used(ndlp))
4701 /* Indicate node has already been released,
4702 * should not reference to it from within
4703 * the routine lpfc_els_free_iocb.
4705 cmdiocb->context1 = NULL;
4709 lpfc_els_free_iocb(phba, cmdiocb);
4714 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4715 * @vport: pointer to a host virtual N_Port data structure.
4716 * @flag: the els command code to be accepted.
4717 * @oldiocb: pointer to the original lpfc command iocb data structure.
4718 * @ndlp: pointer to a node-list data structure.
4719 * @mbox: pointer to the driver internal queue element for mailbox command.
4721 * This routine prepares and issues an Accept (ACC) response IOCB
4722 * command. It uses the @flag to properly set up the IOCB field for the
4723 * specific ACC response command to be issued and invokes the
4724 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4725 * @mbox pointer is passed in, it will be put into the context_un.mbox
4726 * field of the IOCB for the completion callback function to issue the
4727 * mailbox command to the HBA later when callback is invoked.
4729 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4730 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4731 * will be stored into the context1 field of the IOCB for the completion
4732 * callback function to the corresponding response ELS IOCB command.
4735 * 0 - Successfully issued acc response
4736 * 1 - Failed to issue acc response
4739 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4740 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4744 struct lpfc_hba *phba = vport->phba;
4747 struct lpfc_iocbq *elsiocb;
4749 struct serv_parm *sp;
4752 ELS_PKT *els_pkt_ptr;
4754 oldcmd = &oldiocb->iocb;
4758 cmdsize = sizeof(uint32_t);
4759 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4760 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4762 spin_lock_irq(shost->host_lock);
4763 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4764 spin_unlock_irq(shost->host_lock);
4768 icmd = &elsiocb->iocb;
4769 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4770 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4771 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4772 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4773 pcmd += sizeof(uint32_t);
4775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4776 "Issue ACC: did:x%x flg:x%x",
4777 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4781 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4782 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4783 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4787 icmd = &elsiocb->iocb;
4788 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4789 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4790 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4793 elsiocb->context_un.mbox = mbox;
4795 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4796 pcmd += sizeof(uint32_t);
4797 sp = (struct serv_parm *)pcmd;
4799 if (flag == ELS_CMD_FLOGI) {
4800 /* Copy the received service parameters back */
4801 memcpy(sp, &phba->fc_fabparam,
4802 sizeof(struct serv_parm));
4804 /* Clear the F_Port bit */
4807 /* Mark all class service parameters as invalid */
4808 sp->cls1.classValid = 0;
4809 sp->cls2.classValid = 0;
4810 sp->cls3.classValid = 0;
4811 sp->cls4.classValid = 0;
4813 /* Copy our worldwide names */
4814 memcpy(&sp->portName, &vport->fc_sparam.portName,
4815 sizeof(struct lpfc_name));
4816 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4817 sizeof(struct lpfc_name));
4819 memcpy(pcmd, &vport->fc_sparam,
4820 sizeof(struct serv_parm));
4822 sp->cmn.valid_vendor_ver_level = 0;
4823 memset(sp->un.vendorVersion, 0,
4824 sizeof(sp->un.vendorVersion));
4825 sp->cmn.bbRcvSizeMsb &= 0xF;
4827 /* If our firmware supports this feature, convey that
4828 * info to the target using the vendor specific field.
4830 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4831 sp->cmn.valid_vendor_ver_level = 1;
4832 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4834 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4839 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4840 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4843 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4844 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4845 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4849 icmd = &elsiocb->iocb;
4850 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4851 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4852 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4854 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4855 sizeof(uint32_t) + sizeof(PRLO));
4856 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4857 els_pkt_ptr = (ELS_PKT *) pcmd;
4858 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4861 "Issue ACC PRLO: did:x%x flg:x%x",
4862 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4867 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4868 spin_lock_irq(shost->host_lock);
4869 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4870 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4871 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4872 spin_unlock_irq(shost->host_lock);
4873 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4875 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4878 phba->fc_stat.elsXmitACC++;
4879 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4880 if (rc == IOCB_ERROR) {
4881 lpfc_els_free_iocb(phba, elsiocb);
4888 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4889 * @vport: pointer to a virtual N_Port data structure.
4890 * @rejectError: reject response to issue
4891 * @oldiocb: pointer to the original lpfc command iocb data structure.
4892 * @ndlp: pointer to a node-list data structure.
4893 * @mbox: pointer to the driver internal queue element for mailbox command.
4895 * This routine prepares and issue an Reject (RJT) response IOCB
4896 * command. If a @mbox pointer is passed in, it will be put into the
4897 * context_un.mbox field of the IOCB for the completion callback function
4898 * to issue to the HBA later.
4900 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4901 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4902 * will be stored into the context1 field of the IOCB for the completion
4903 * callback function to the reject response ELS IOCB command.
4906 * 0 - Successfully issued reject response
4907 * 1 - Failed to issue reject response
4910 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4911 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4914 struct lpfc_hba *phba = vport->phba;
4917 struct lpfc_iocbq *elsiocb;
4922 cmdsize = 2 * sizeof(uint32_t);
4923 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4924 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4928 icmd = &elsiocb->iocb;
4929 oldcmd = &oldiocb->iocb;
4930 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4931 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4932 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4934 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4935 pcmd += sizeof(uint32_t);
4936 *((uint32_t *) (pcmd)) = rejectError;
4939 elsiocb->context_un.mbox = mbox;
4941 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4942 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4943 "0129 Xmit ELS RJT x%x response tag x%x "
4944 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4946 rejectError, elsiocb->iotag,
4947 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4948 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4949 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4950 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4951 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4953 phba->fc_stat.elsXmitLSRJT++;
4954 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4955 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4957 if (rc == IOCB_ERROR) {
4958 lpfc_els_free_iocb(phba, elsiocb);
4965 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4966 * @vport: pointer to a virtual N_Port data structure.
4967 * @oldiocb: pointer to the original lpfc command iocb data structure.
4968 * @ndlp: pointer to a node-list data structure.
4970 * This routine prepares and issues an Accept (ACC) response to Address
4971 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4972 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4974 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4975 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4976 * will be stored into the context1 field of the IOCB for the completion
4977 * callback function to the ADISC Accept response ELS IOCB command.
4980 * 0 - Successfully issued acc adisc response
4981 * 1 - Failed to issue adisc acc response
4984 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4985 struct lpfc_nodelist *ndlp)
4987 struct lpfc_hba *phba = vport->phba;
4989 IOCB_t *icmd, *oldcmd;
4990 struct lpfc_iocbq *elsiocb;
4995 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4996 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4997 ndlp->nlp_DID, ELS_CMD_ACC);
5001 icmd = &elsiocb->iocb;
5002 oldcmd = &oldiocb->iocb;
5003 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5004 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5006 /* Xmit ADISC ACC response tag <ulpIoTag> */
5007 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5008 "0130 Xmit ADISC ACC response iotag x%x xri: "
5009 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
5010 elsiocb->iotag, elsiocb->iocb.ulpContext,
5011 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5013 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5015 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5016 pcmd += sizeof(uint32_t);
5018 ap = (ADISC *) (pcmd);
5019 ap->hardAL_PA = phba->fc_pref_ALPA;
5020 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5021 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5022 ap->DID = be32_to_cpu(vport->fc_myDID);
5024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5025 "Issue ACC ADISC: did:x%x flg:x%x",
5026 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5028 phba->fc_stat.elsXmitACC++;
5029 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5030 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5031 if (rc == IOCB_ERROR) {
5032 lpfc_els_free_iocb(phba, elsiocb);
5036 /* Xmit ELS ACC response tag <ulpIoTag> */
5037 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5038 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5039 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5040 "RPI: x%x, fc_flag x%x\n",
5041 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5042 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5043 ndlp->nlp_rpi, vport->fc_flag);
5048 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5049 * @vport: pointer to a virtual N_Port data structure.
5050 * @oldiocb: pointer to the original lpfc command iocb data structure.
5051 * @ndlp: pointer to a node-list data structure.
5053 * This routine prepares and issues an Accept (ACC) response to Process
5054 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5055 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5057 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5058 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5059 * will be stored into the context1 field of the IOCB for the completion
5060 * callback function to the PRLI Accept response ELS IOCB command.
5063 * 0 - Successfully issued acc prli response
5064 * 1 - Failed to issue acc prli response
5067 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5068 struct lpfc_nodelist *ndlp)
5070 struct lpfc_hba *phba = vport->phba;
5072 struct lpfc_nvme_prli *npr_nvme;
5076 struct lpfc_iocbq *elsiocb;
5079 uint32_t prli_fc4_req, *req_payload;
5080 struct lpfc_dmabuf *req_buf;
5084 /* Need the incoming PRLI payload to determine if the ACC is for an
5085 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5087 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5088 req_payload = (((uint32_t *)req_buf->virt) + 1);
5090 /* PRLI type payload is at byte 3 for FCP or NVME. */
5091 prli_fc4_req = be32_to_cpu(*req_payload);
5092 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5093 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5094 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5095 prli_fc4_req, *((uint32_t *)req_payload));
5097 if (prli_fc4_req == PRLI_FCP_TYPE) {
5098 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5099 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5100 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5101 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5102 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5107 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5108 ndlp->nlp_DID, elsrspcmd);
5112 icmd = &elsiocb->iocb;
5113 oldcmd = &oldiocb->iocb;
5114 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5115 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5117 /* Xmit PRLI ACC response tag <ulpIoTag> */
5118 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5119 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5120 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5121 elsiocb->iotag, elsiocb->iocb.ulpContext,
5122 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5124 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5125 memset(pcmd, 0, cmdsize);
5127 *((uint32_t *)(pcmd)) = elsrspcmd;
5128 pcmd += sizeof(uint32_t);
5130 /* For PRLI, remainder of payload is PRLI parameter page */
5133 if (prli_fc4_req == PRLI_FCP_TYPE) {
5135 * If the remote port is a target and our firmware version
5136 * is 3.20 or later, set the following bits for FC-TAPE
5139 npr = (PRLI *) pcmd;
5140 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5141 (vpd->rev.feaLevelHigh >= 0x02)) {
5142 npr->ConfmComplAllowed = 1;
5144 npr->TaskRetryIdReq = 1;
5146 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5147 npr->estabImagePair = 1;
5148 npr->readXferRdyDis = 1;
5149 npr->ConfmComplAllowed = 1;
5150 npr->prliType = PRLI_FCP_TYPE;
5151 npr->initiatorFunc = 1;
5152 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5153 /* Respond with an NVME PRLI Type */
5154 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5155 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5156 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5157 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5158 if (phba->nvmet_support) {
5159 bf_set(prli_tgt, npr_nvme, 1);
5160 bf_set(prli_disc, npr_nvme, 1);
5161 if (phba->cfg_nvme_enable_fb) {
5162 bf_set(prli_fba, npr_nvme, 1);
5164 /* TBD. Target mode needs to post buffers
5165 * that support the configured first burst
5168 bf_set(prli_fb_sz, npr_nvme,
5169 phba->cfg_nvmet_fb_size);
5172 bf_set(prli_init, npr_nvme, 1);
5175 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5176 "6015 NVME issue PRLI ACC word1 x%08x "
5177 "word4 x%08x word5 x%08x flag x%x, "
5178 "fcp_info x%x nlp_type x%x\n",
5179 npr_nvme->word1, npr_nvme->word4,
5180 npr_nvme->word5, ndlp->nlp_flag,
5181 ndlp->nlp_fcp_info, ndlp->nlp_type);
5182 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5183 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5184 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5187 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5188 prli_fc4_req, ndlp->nlp_fc4_type,
5191 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5192 "Issue ACC PRLI: did:x%x flg:x%x",
5193 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5195 phba->fc_stat.elsXmitACC++;
5196 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5198 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5199 if (rc == IOCB_ERROR) {
5200 lpfc_els_free_iocb(phba, elsiocb);
5207 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5208 * @vport: pointer to a virtual N_Port data structure.
5209 * @format: rnid command format.
5210 * @oldiocb: pointer to the original lpfc command iocb data structure.
5211 * @ndlp: pointer to a node-list data structure.
5213 * This routine issues a Request Node Identification Data (RNID) Accept
5214 * (ACC) response. It constructs the RNID ACC response command according to
5215 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5216 * issue the response. Note that this command does not need to hold the ndlp
5217 * reference count for the callback. So, the ndlp reference count taken by
5218 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5219 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5220 * there is no ndlp reference available.
5222 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5223 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5224 * will be stored into the context1 field of the IOCB for the completion
5225 * callback function. However, for the RNID Accept Response ELS command,
5226 * this is undone later by this routine after the IOCB is allocated.
5229 * 0 - Successfully issued acc rnid response
5230 * 1 - Failed to issue acc rnid response
5233 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5234 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5236 struct lpfc_hba *phba = vport->phba;
5238 IOCB_t *icmd, *oldcmd;
5239 struct lpfc_iocbq *elsiocb;
5244 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5245 + (2 * sizeof(struct lpfc_name));
5247 cmdsize += sizeof(RNID_TOP_DISC);
5249 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5250 ndlp->nlp_DID, ELS_CMD_ACC);
5254 icmd = &elsiocb->iocb;
5255 oldcmd = &oldiocb->iocb;
5256 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5257 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5259 /* Xmit RNID ACC response tag <ulpIoTag> */
5260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5261 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5262 elsiocb->iotag, elsiocb->iocb.ulpContext);
5263 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5264 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5265 pcmd += sizeof(uint32_t);
5267 memset(pcmd, 0, sizeof(RNID));
5268 rn = (RNID *) (pcmd);
5269 rn->Format = format;
5270 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5271 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5272 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5275 rn->SpecificLen = 0;
5277 case RNID_TOPOLOGY_DISC:
5278 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5279 memcpy(&rn->un.topologyDisc.portName,
5280 &vport->fc_portname, sizeof(struct lpfc_name));
5281 rn->un.topologyDisc.unitType = RNID_HBA;
5282 rn->un.topologyDisc.physPort = 0;
5283 rn->un.topologyDisc.attachedNodes = 0;
5287 rn->SpecificLen = 0;
5291 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5292 "Issue ACC RNID: did:x%x flg:x%x",
5293 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5295 phba->fc_stat.elsXmitACC++;
5296 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5298 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5299 if (rc == IOCB_ERROR) {
5300 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",
5400 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5402 phba->fc_stat.elsXmitACC++;
5403 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5405 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5406 if (rc == IOCB_ERROR) {
5407 lpfc_els_free_iocb(phba, elsiocb);
5414 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5415 * @vport: pointer to a host virtual N_Port data structure.
5417 * This routine issues Address Discover (ADISC) ELS commands to those
5418 * N_Ports which are in node port recovery state and ADISC has not been issued
5419 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5420 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5421 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5422 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5423 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5424 * IOCBs quit for later pick up. On the other hand, after walking through
5425 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5426 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5427 * no more ADISC need to be sent.
5430 * The number of N_Ports with adisc issued.
5433 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5435 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5436 struct lpfc_nodelist *ndlp, *next_ndlp;
5439 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5440 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5441 if (!NLP_CHK_NODE_ACT(ndlp))
5443 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5444 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5445 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5446 spin_lock_irq(shost->host_lock);
5447 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5448 spin_unlock_irq(shost->host_lock);
5449 ndlp->nlp_prev_state = ndlp->nlp_state;
5450 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5451 lpfc_issue_els_adisc(vport, ndlp, 0);
5453 vport->num_disc_nodes++;
5454 if (vport->num_disc_nodes >=
5455 vport->cfg_discovery_threads) {
5456 spin_lock_irq(shost->host_lock);
5457 vport->fc_flag |= FC_NLP_MORE;
5458 spin_unlock_irq(shost->host_lock);
5463 if (sentadisc == 0) {
5464 spin_lock_irq(shost->host_lock);
5465 vport->fc_flag &= ~FC_NLP_MORE;
5466 spin_unlock_irq(shost->host_lock);
5472 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5473 * @vport: pointer to a host virtual N_Port data structure.
5475 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5476 * which are in node port recovery state, with a @vport. Each time an ELS
5477 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5478 * the per @vport number of discover count (num_disc_nodes) shall be
5479 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5480 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5481 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5482 * later pick up. On the other hand, after walking through all the ndlps with
5483 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5484 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5485 * PLOGI need to be sent.
5488 * The number of N_Ports with plogi issued.
5491 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5494 struct lpfc_nodelist *ndlp, *next_ndlp;
5497 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5498 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5499 if (!NLP_CHK_NODE_ACT(ndlp))
5501 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5502 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5503 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5504 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5505 ndlp->nlp_prev_state = ndlp->nlp_state;
5506 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5507 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5509 vport->num_disc_nodes++;
5510 if (vport->num_disc_nodes >=
5511 vport->cfg_discovery_threads) {
5512 spin_lock_irq(shost->host_lock);
5513 vport->fc_flag |= FC_NLP_MORE;
5514 spin_unlock_irq(shost->host_lock);
5520 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5521 "6452 Discover PLOGI %d flag x%x\n",
5522 sentplogi, vport->fc_flag);
5525 lpfc_set_disctmo(vport);
5528 spin_lock_irq(shost->host_lock);
5529 vport->fc_flag &= ~FC_NLP_MORE;
5530 spin_unlock_irq(shost->host_lock);
5536 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5540 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5541 desc->payload.els_req = word0;
5542 desc->length = cpu_to_be32(sizeof(desc->payload));
5544 return sizeof(struct fc_rdp_link_service_desc);
5548 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5549 uint8_t *page_a0, uint8_t *page_a2)
5551 uint16_t wavelength;
5552 uint16_t temperature;
5558 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5559 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5561 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5563 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5564 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5565 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5566 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5568 if ((trasn_code_byte4->fc_sw_laser) ||
5569 (trasn_code_byte5->fc_sw_laser_sl) ||
5570 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5571 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5572 } else if (trasn_code_byte4->fc_lw_laser) {
5573 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5574 page_a0[SSF_WAVELENGTH_B0];
5575 if (wavelength == SFP_WAVELENGTH_LC1310)
5576 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5577 if (wavelength == SFP_WAVELENGTH_LL1550)
5578 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5580 /* check if its SFP+ */
5581 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5582 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5583 << SFP_FLAG_CT_SHIFT;
5585 /* check if its OPTICAL */
5586 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5587 SFP_FLAG_IS_OPTICAL_PORT : 0)
5588 << SFP_FLAG_IS_OPTICAL_SHIFT;
5590 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5591 page_a2[SFF_TEMPERATURE_B0]);
5592 vcc = (page_a2[SFF_VCC_B1] << 8 |
5593 page_a2[SFF_VCC_B0]);
5594 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5595 page_a2[SFF_TXPOWER_B0]);
5596 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5597 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5598 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5599 page_a2[SFF_RXPOWER_B0]);
5600 desc->sfp_info.temperature = cpu_to_be16(temperature);
5601 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5602 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5603 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5604 desc->sfp_info.vcc = cpu_to_be16(vcc);
5606 desc->sfp_info.flags = cpu_to_be16(flag);
5607 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5609 return sizeof(struct fc_rdp_sfp_desc);
5613 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5618 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5620 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5622 desc->info.port_type = cpu_to_be32(type);
5624 desc->info.link_status.link_failure_cnt =
5625 cpu_to_be32(stat->linkFailureCnt);
5626 desc->info.link_status.loss_of_synch_cnt =
5627 cpu_to_be32(stat->lossSyncCnt);
5628 desc->info.link_status.loss_of_signal_cnt =
5629 cpu_to_be32(stat->lossSignalCnt);
5630 desc->info.link_status.primitive_seq_proto_err =
5631 cpu_to_be32(stat->primSeqErrCnt);
5632 desc->info.link_status.invalid_trans_word =
5633 cpu_to_be32(stat->invalidXmitWord);
5634 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5636 desc->length = cpu_to_be32(sizeof(desc->info));
5638 return sizeof(struct fc_rdp_link_error_status_desc);
5642 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5643 struct lpfc_vport *vport)
5647 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5649 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5650 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5651 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5652 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5653 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5654 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5655 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5657 desc->bbc_info.attached_port_bbc = 0;
5660 desc->bbc_info.rtt = 0;
5661 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5663 return sizeof(struct fc_rdp_bbc_desc);
5667 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5668 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5672 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5674 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5675 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5676 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5677 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5679 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5680 flags |= RDP_OET_HIGH_ALARM;
5681 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5682 flags |= RDP_OET_LOW_ALARM;
5683 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5684 flags |= RDP_OET_HIGH_WARNING;
5685 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5686 flags |= RDP_OET_LOW_WARNING;
5688 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5689 desc->oed_info.function_flags = cpu_to_be32(flags);
5690 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5691 return sizeof(struct fc_rdp_oed_sfp_desc);
5695 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5696 struct fc_rdp_oed_sfp_desc *desc,
5701 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5703 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5704 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5705 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5706 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5708 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5709 flags |= RDP_OET_HIGH_ALARM;
5710 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5711 flags |= RDP_OET_LOW_ALARM;
5712 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5713 flags |= RDP_OET_HIGH_WARNING;
5714 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5715 flags |= RDP_OET_LOW_WARNING;
5717 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5718 desc->oed_info.function_flags = cpu_to_be32(flags);
5719 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5720 return sizeof(struct fc_rdp_oed_sfp_desc);
5724 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5725 struct fc_rdp_oed_sfp_desc *desc,
5730 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5732 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5733 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5734 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5735 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5737 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5738 flags |= RDP_OET_HIGH_ALARM;
5739 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5740 flags |= RDP_OET_LOW_ALARM;
5741 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5742 flags |= RDP_OET_HIGH_WARNING;
5743 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5744 flags |= RDP_OET_LOW_WARNING;
5746 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5747 desc->oed_info.function_flags = cpu_to_be32(flags);
5748 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5749 return sizeof(struct fc_rdp_oed_sfp_desc);
5753 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5754 struct fc_rdp_oed_sfp_desc *desc,
5759 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5761 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5762 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5763 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5764 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5766 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5767 flags |= RDP_OET_HIGH_ALARM;
5768 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5769 flags |= RDP_OET_LOW_ALARM;
5770 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5771 flags |= RDP_OET_HIGH_WARNING;
5772 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5773 flags |= RDP_OET_LOW_WARNING;
5775 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5776 desc->oed_info.function_flags = cpu_to_be32(flags);
5777 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5778 return sizeof(struct fc_rdp_oed_sfp_desc);
5783 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5784 struct fc_rdp_oed_sfp_desc *desc,
5789 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5791 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5792 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5793 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5794 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5796 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5797 flags |= RDP_OET_HIGH_ALARM;
5798 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5799 flags |= RDP_OET_LOW_ALARM;
5800 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5801 flags |= RDP_OET_HIGH_WARNING;
5802 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5803 flags |= RDP_OET_LOW_WARNING;
5805 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5806 desc->oed_info.function_flags = cpu_to_be32(flags);
5807 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5808 return sizeof(struct fc_rdp_oed_sfp_desc);
5812 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5813 uint8_t *page_a0, struct lpfc_vport *vport)
5815 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5816 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5817 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5818 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5819 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5820 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5821 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5822 return sizeof(struct fc_rdp_opd_sfp_desc);
5826 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5828 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5830 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5832 desc->info.CorrectedBlocks =
5833 cpu_to_be32(stat->fecCorrBlkCount);
5834 desc->info.UncorrectableBlocks =
5835 cpu_to_be32(stat->fecUncorrBlkCount);
5837 desc->length = cpu_to_be32(sizeof(desc->info));
5839 return sizeof(struct fc_fec_rdp_desc);
5843 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5845 uint16_t rdp_cap = 0;
5848 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5850 switch (phba->fc_linkspeed) {
5851 case LPFC_LINK_SPEED_1GHZ:
5852 rdp_speed = RDP_PS_1GB;
5854 case LPFC_LINK_SPEED_2GHZ:
5855 rdp_speed = RDP_PS_2GB;
5857 case LPFC_LINK_SPEED_4GHZ:
5858 rdp_speed = RDP_PS_4GB;
5860 case LPFC_LINK_SPEED_8GHZ:
5861 rdp_speed = RDP_PS_8GB;
5863 case LPFC_LINK_SPEED_10GHZ:
5864 rdp_speed = RDP_PS_10GB;
5866 case LPFC_LINK_SPEED_16GHZ:
5867 rdp_speed = RDP_PS_16GB;
5869 case LPFC_LINK_SPEED_32GHZ:
5870 rdp_speed = RDP_PS_32GB;
5872 case LPFC_LINK_SPEED_64GHZ:
5873 rdp_speed = RDP_PS_64GB;
5876 rdp_speed = RDP_PS_UNKNOWN;
5880 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5882 if (phba->lmt & LMT_128Gb)
5883 rdp_cap |= RDP_PS_128GB;
5884 if (phba->lmt & LMT_64Gb)
5885 rdp_cap |= RDP_PS_64GB;
5886 if (phba->lmt & LMT_32Gb)
5887 rdp_cap |= RDP_PS_32GB;
5888 if (phba->lmt & LMT_16Gb)
5889 rdp_cap |= RDP_PS_16GB;
5890 if (phba->lmt & LMT_10Gb)
5891 rdp_cap |= RDP_PS_10GB;
5892 if (phba->lmt & LMT_8Gb)
5893 rdp_cap |= RDP_PS_8GB;
5894 if (phba->lmt & LMT_4Gb)
5895 rdp_cap |= RDP_PS_4GB;
5896 if (phba->lmt & LMT_2Gb)
5897 rdp_cap |= RDP_PS_2GB;
5898 if (phba->lmt & LMT_1Gb)
5899 rdp_cap |= RDP_PS_1GB;
5902 rdp_cap = RDP_CAP_UNKNOWN;
5903 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5904 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5906 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5907 desc->length = cpu_to_be32(sizeof(desc->info));
5908 return sizeof(struct fc_rdp_port_speed_desc);
5912 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5913 struct lpfc_vport *vport)
5916 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5918 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5919 sizeof(desc->port_names.wwnn));
5921 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5922 sizeof(desc->port_names.wwpn));
5924 desc->length = cpu_to_be32(sizeof(desc->port_names));
5925 return sizeof(struct fc_rdp_port_name_desc);
5929 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5930 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5933 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5934 if (vport->fc_flag & FC_FABRIC) {
5935 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5936 sizeof(desc->port_names.wwnn));
5938 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5939 sizeof(desc->port_names.wwpn));
5940 } else { /* Point to Point */
5941 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5942 sizeof(desc->port_names.wwnn));
5944 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5945 sizeof(desc->port_names.wwpn));
5948 desc->length = cpu_to_be32(sizeof(desc->port_names));
5949 return sizeof(struct fc_rdp_port_name_desc);
5953 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5956 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5957 struct lpfc_vport *vport = ndlp->vport;
5958 struct lpfc_iocbq *elsiocb;
5959 struct ulp_bde64 *bpl;
5962 struct ls_rjt *stat;
5963 struct fc_rdp_res_frame *rdp_res;
5964 uint32_t cmdsize, len;
5968 if (status != SUCCESS)
5971 /* This will change once we know the true size of the RDP payload */
5972 cmdsize = sizeof(struct fc_rdp_res_frame);
5974 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5975 lpfc_max_els_tries, rdp_context->ndlp,
5976 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5979 goto free_rdp_context;
5981 icmd = &elsiocb->iocb;
5982 icmd->ulpContext = rdp_context->rx_id;
5983 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5985 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5986 "2171 Xmit RDP response tag x%x xri x%x, "
5987 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5988 elsiocb->iotag, elsiocb->iocb.ulpContext,
5989 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5991 rdp_res = (struct fc_rdp_res_frame *)
5992 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5993 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5994 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5995 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5997 /* Update Alarm and Warning */
5998 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5999 phba->sfp_alarm |= *flag_ptr;
6000 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6001 phba->sfp_warning |= *flag_ptr;
6003 /* For RDP payload */
6005 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6006 (len + pcmd), ELS_CMD_RDP);
6008 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
6009 rdp_context->page_a0, rdp_context->page_a2);
6010 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6012 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6013 (len + pcmd), &rdp_context->link_stat);
6014 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
6015 (len + pcmd), vport);
6016 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6017 (len + pcmd), vport, ndlp);
6018 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
6019 &rdp_context->link_stat);
6020 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6021 &rdp_context->link_stat, vport);
6022 len += lpfc_rdp_res_oed_temp_desc(phba,
6023 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6024 rdp_context->page_a2);
6025 len += lpfc_rdp_res_oed_voltage_desc(phba,
6026 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6027 rdp_context->page_a2);
6028 len += lpfc_rdp_res_oed_txbias_desc(phba,
6029 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6030 rdp_context->page_a2);
6031 len += lpfc_rdp_res_oed_txpower_desc(phba,
6032 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6033 rdp_context->page_a2);
6034 len += lpfc_rdp_res_oed_rxpower_desc(phba,
6035 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6036 rdp_context->page_a2);
6037 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6038 rdp_context->page_a0, vport);
6040 rdp_res->length = cpu_to_be32(len - 8);
6041 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6043 /* Now that we know the true size of the payload, update the BPL */
6044 bpl = (struct ulp_bde64 *)
6045 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6046 bpl->tus.f.bdeSize = len;
6047 bpl->tus.f.bdeFlags = 0;
6048 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6050 phba->fc_stat.elsXmitACC++;
6051 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6052 if (rc == IOCB_ERROR)
6053 lpfc_els_free_iocb(phba, elsiocb);
6059 cmdsize = 2 * sizeof(uint32_t);
6060 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6061 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6064 goto free_rdp_context;
6066 icmd = &elsiocb->iocb;
6067 icmd->ulpContext = rdp_context->rx_id;
6068 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6069 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6071 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6072 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6073 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6075 phba->fc_stat.elsXmitLSRJT++;
6076 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6077 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6079 if (rc == IOCB_ERROR)
6080 lpfc_els_free_iocb(phba, elsiocb);
6086 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6088 LPFC_MBOXQ_t *mbox = NULL;
6091 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6093 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6094 "7105 failed to allocate mailbox memory");
6098 if (lpfc_sli4_dump_page_a0(phba, mbox))
6099 goto prep_mbox_fail;
6100 mbox->vport = rdp_context->ndlp->vport;
6101 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6102 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6103 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6104 if (rc == MBX_NOT_FINISHED)
6105 goto issue_mbox_fail;
6111 mempool_free(mbox, phba->mbox_mem_pool);
6116 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6117 * @vport: pointer to a host virtual N_Port data structure.
6118 * @cmdiocb: pointer to lpfc command iocb data structure.
6119 * @ndlp: pointer to a node-list data structure.
6121 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6122 * IOCB. First, the payload of the unsolicited RDP is checked.
6123 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6124 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6125 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6126 * gather all data and send RDP response.
6129 * 0 - Sent the acc response
6130 * 1 - Sent the reject response.
6133 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6134 struct lpfc_nodelist *ndlp)
6136 struct lpfc_hba *phba = vport->phba;
6137 struct lpfc_dmabuf *pcmd;
6138 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6139 struct fc_rdp_req_frame *rdp_req;
6140 struct lpfc_rdp_context *rdp_context;
6144 if (phba->sli_rev < LPFC_SLI_REV4 ||
6145 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6146 LPFC_SLI_INTF_IF_TYPE_2) {
6147 rjt_err = LSRJT_UNABLE_TPC;
6148 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6152 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6153 rjt_err = LSRJT_UNABLE_TPC;
6154 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6158 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6159 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6161 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6162 "2422 ELS RDP Request "
6163 "dec len %d tag x%x port_id %d len %d\n",
6164 be32_to_cpu(rdp_req->rdp_des_length),
6165 be32_to_cpu(rdp_req->nport_id_desc.tag),
6166 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6167 be32_to_cpu(rdp_req->nport_id_desc.length));
6169 if (sizeof(struct fc_rdp_nport_desc) !=
6170 be32_to_cpu(rdp_req->rdp_des_length))
6172 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6174 if (RDP_NPORT_ID_SIZE !=
6175 be32_to_cpu(rdp_req->nport_id_desc.length))
6177 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6179 rjt_err = LSRJT_UNABLE_TPC;
6183 cmd = &cmdiocb->iocb;
6184 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6185 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6186 rdp_context->rx_id = cmd->ulpContext;
6187 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6188 if (lpfc_get_rdp_info(phba, rdp_context)) {
6189 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6190 "2423 Unable to send mailbox");
6192 rjt_err = LSRJT_UNABLE_TPC;
6200 rjt_err = LSRJT_LOGICAL_ERR;
6203 memset(&stat, 0, sizeof(stat));
6204 stat.un.b.lsRjtRsnCode = rjt_err;
6205 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6206 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6212 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6217 struct lpfc_iocbq *elsiocb;
6218 struct lpfc_nodelist *ndlp;
6219 struct ls_rjt *stat;
6220 union lpfc_sli4_cfg_shdr *shdr;
6221 struct lpfc_lcb_context *lcb_context;
6222 struct fc_lcb_res_frame *lcb_res;
6223 uint32_t cmdsize, shdr_status, shdr_add_status;
6227 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6228 ndlp = lcb_context->ndlp;
6229 pmb->ctx_ndlp = NULL;
6230 pmb->ctx_buf = NULL;
6232 shdr = (union lpfc_sli4_cfg_shdr *)
6233 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6234 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6235 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6237 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6238 "0194 SET_BEACON_CONFIG mailbox "
6239 "completed with status x%x add_status x%x,"
6240 " mbx status x%x\n",
6241 shdr_status, shdr_add_status, mb->mbxStatus);
6243 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6244 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6245 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6246 mempool_free(pmb, phba->mbox_mem_pool);
6250 mempool_free(pmb, phba->mbox_mem_pool);
6251 cmdsize = sizeof(struct fc_lcb_res_frame);
6252 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6253 lpfc_max_els_tries, ndlp,
6254 ndlp->nlp_DID, ELS_CMD_ACC);
6256 /* Decrement the ndlp reference count from previous mbox command */
6260 goto free_lcb_context;
6262 lcb_res = (struct fc_lcb_res_frame *)
6263 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6265 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6266 icmd = &elsiocb->iocb;
6267 icmd->ulpContext = lcb_context->rx_id;
6268 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6270 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6271 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6272 lcb_res->lcb_sub_command = lcb_context->sub_command;
6273 lcb_res->lcb_type = lcb_context->type;
6274 lcb_res->capability = lcb_context->capability;
6275 lcb_res->lcb_frequency = lcb_context->frequency;
6276 lcb_res->lcb_duration = lcb_context->duration;
6277 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6278 phba->fc_stat.elsXmitACC++;
6279 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6280 if (rc == IOCB_ERROR)
6281 lpfc_els_free_iocb(phba, elsiocb);
6287 cmdsize = sizeof(struct fc_lcb_res_frame);
6288 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6289 lpfc_max_els_tries, ndlp,
6290 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6293 goto free_lcb_context;
6295 icmd = &elsiocb->iocb;
6296 icmd->ulpContext = lcb_context->rx_id;
6297 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6298 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6300 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6301 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6302 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6304 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6305 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6307 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6308 phba->fc_stat.elsXmitLSRJT++;
6309 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6310 if (rc == IOCB_ERROR)
6311 lpfc_els_free_iocb(phba, elsiocb);
6317 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6318 struct lpfc_lcb_context *lcb_context,
6319 uint32_t beacon_state)
6321 struct lpfc_hba *phba = vport->phba;
6322 union lpfc_sli4_cfg_shdr *cfg_shdr;
6323 LPFC_MBOXQ_t *mbox = NULL;
6327 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6331 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6332 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6333 sizeof(struct lpfc_sli4_cfg_mhdr);
6334 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6335 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6336 LPFC_SLI4_MBX_EMBED);
6337 mbox->ctx_ndlp = (void *)lcb_context;
6338 mbox->vport = phba->pport;
6339 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6340 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6341 phba->sli4_hba.physical_port);
6342 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6344 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6347 * Check bv1s bit before issuing the mailbox
6348 * if bv1s == 1, LCB V1 supported
6349 * else, LCB V0 supported
6352 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6353 /* COMMON_SET_BEACON_CONFIG_V1 */
6354 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6355 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6356 bf_set(lpfc_mbx_set_beacon_port_type,
6357 &mbox->u.mqe.un.beacon_config, 0);
6358 bf_set(lpfc_mbx_set_beacon_duration_v1,
6359 &mbox->u.mqe.un.beacon_config,
6360 be16_to_cpu(lcb_context->duration));
6362 /* COMMON_SET_BEACON_CONFIG_V0 */
6363 if (be16_to_cpu(lcb_context->duration) != 0) {
6364 mempool_free(mbox, phba->mbox_mem_pool);
6367 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6368 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6369 bf_set(lpfc_mbx_set_beacon_state,
6370 &mbox->u.mqe.un.beacon_config, beacon_state);
6371 bf_set(lpfc_mbx_set_beacon_port_type,
6372 &mbox->u.mqe.un.beacon_config, 1);
6373 bf_set(lpfc_mbx_set_beacon_duration,
6374 &mbox->u.mqe.un.beacon_config,
6375 be16_to_cpu(lcb_context->duration));
6378 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6379 if (rc == MBX_NOT_FINISHED) {
6380 mempool_free(mbox, phba->mbox_mem_pool);
6389 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6390 * @vport: pointer to a host virtual N_Port data structure.
6391 * @cmdiocb: pointer to lpfc command iocb data structure.
6392 * @ndlp: pointer to a node-list data structure.
6394 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6395 * First, the payload of the unsolicited LCB is checked.
6396 * Then based on Subcommand beacon will either turn on or off.
6399 * 0 - Sent the acc response
6400 * 1 - Sent the reject response.
6403 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6404 struct lpfc_nodelist *ndlp)
6406 struct lpfc_hba *phba = vport->phba;
6407 struct lpfc_dmabuf *pcmd;
6409 struct fc_lcb_request_frame *beacon;
6410 struct lpfc_lcb_context *lcb_context;
6411 uint8_t state, rjt_err;
6414 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6415 lp = (uint8_t *)pcmd->virt;
6416 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6418 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6419 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6420 "type x%x frequency %x duration x%x\n",
6421 lp[0], lp[1], lp[2],
6422 beacon->lcb_command,
6423 beacon->lcb_sub_command,
6425 beacon->lcb_frequency,
6426 be16_to_cpu(beacon->lcb_duration));
6428 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6429 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6430 rjt_err = LSRJT_CMD_UNSUPPORTED;
6434 if (phba->sli_rev < LPFC_SLI_REV4 ||
6435 phba->hba_flag & HBA_FCOE_MODE ||
6436 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6437 LPFC_SLI_INTF_IF_TYPE_2)) {
6438 rjt_err = LSRJT_CMD_UNSUPPORTED;
6442 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6444 rjt_err = LSRJT_UNABLE_TPC;
6448 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6449 lcb_context->sub_command = beacon->lcb_sub_command;
6450 lcb_context->capability = 0;
6451 lcb_context->type = beacon->lcb_type;
6452 lcb_context->frequency = beacon->lcb_frequency;
6453 lcb_context->duration = beacon->lcb_duration;
6454 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6455 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6456 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6457 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6458 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6459 "0193 failed to send mail box");
6462 rjt_err = LSRJT_UNABLE_TPC;
6467 memset(&stat, 0, sizeof(stat));
6468 stat.un.b.lsRjtRsnCode = rjt_err;
6469 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6475 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6476 * @vport: pointer to a host virtual N_Port data structure.
6478 * This routine cleans up any Registration State Change Notification
6479 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6480 * @vport together with the host_lock is used to prevent multiple thread
6481 * trying to access the RSCN array on a same @vport at the same time.
6484 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6486 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6487 struct lpfc_hba *phba = vport->phba;
6490 spin_lock_irq(shost->host_lock);
6491 if (vport->fc_rscn_flush) {
6492 /* Another thread is walking fc_rscn_id_list on this vport */
6493 spin_unlock_irq(shost->host_lock);
6496 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6497 vport->fc_rscn_flush = 1;
6498 spin_unlock_irq(shost->host_lock);
6500 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6501 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6502 vport->fc_rscn_id_list[i] = NULL;
6504 spin_lock_irq(shost->host_lock);
6505 vport->fc_rscn_id_cnt = 0;
6506 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6507 spin_unlock_irq(shost->host_lock);
6508 lpfc_can_disctmo(vport);
6509 /* Indicate we are done walking this fc_rscn_id_list */
6510 vport->fc_rscn_flush = 0;
6514 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6515 * @vport: pointer to a host virtual N_Port data structure.
6516 * @did: remote destination port identifier.
6518 * This routine checks whether there is any pending Registration State
6519 * Configuration Notification (RSCN) to a @did on @vport.
6522 * None zero - The @did matched with a pending rscn
6523 * 0 - not able to match @did with a pending rscn
6526 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6531 uint32_t payload_len, i;
6532 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6534 ns_did.un.word = did;
6536 /* Never match fabric nodes for RSCNs */
6537 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6540 /* If we are doing a FULL RSCN rediscovery, match everything */
6541 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6544 spin_lock_irq(shost->host_lock);
6545 if (vport->fc_rscn_flush) {
6546 /* Another thread is walking fc_rscn_id_list on this vport */
6547 spin_unlock_irq(shost->host_lock);
6550 /* Indicate we are walking fc_rscn_id_list on this vport */
6551 vport->fc_rscn_flush = 1;
6552 spin_unlock_irq(shost->host_lock);
6553 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6554 lp = vport->fc_rscn_id_list[i]->virt;
6555 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6556 payload_len -= sizeof(uint32_t); /* take off word 0 */
6557 while (payload_len) {
6558 rscn_did.un.word = be32_to_cpu(*lp++);
6559 payload_len -= sizeof(uint32_t);
6560 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6561 case RSCN_ADDRESS_FORMAT_PORT:
6562 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6563 && (ns_did.un.b.area == rscn_did.un.b.area)
6564 && (ns_did.un.b.id == rscn_did.un.b.id))
6565 goto return_did_out;
6567 case RSCN_ADDRESS_FORMAT_AREA:
6568 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6569 && (ns_did.un.b.area == rscn_did.un.b.area))
6570 goto return_did_out;
6572 case RSCN_ADDRESS_FORMAT_DOMAIN:
6573 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6574 goto return_did_out;
6576 case RSCN_ADDRESS_FORMAT_FABRIC:
6577 goto return_did_out;
6581 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6582 vport->fc_rscn_flush = 0;
6585 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6586 vport->fc_rscn_flush = 0;
6591 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6592 * @vport: pointer to a host virtual N_Port data structure.
6594 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6595 * state machine for a @vport's nodes that are with pending RSCN (Registration
6596 * State Change Notification).
6599 * 0 - Successful (currently alway return 0)
6602 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6604 struct lpfc_nodelist *ndlp = NULL;
6606 /* Move all affected nodes by pending RSCNs to NPR state. */
6607 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6608 if (!NLP_CHK_NODE_ACT(ndlp) ||
6609 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6610 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6613 /* NVME Target mode does not do RSCN Recovery. */
6614 if (vport->phba->nvmet_support)
6617 /* If we are in the process of doing discovery on this
6618 * NPort, let it continue on its own.
6620 switch (ndlp->nlp_state) {
6621 case NLP_STE_PLOGI_ISSUE:
6622 case NLP_STE_ADISC_ISSUE:
6623 case NLP_STE_REG_LOGIN_ISSUE:
6624 case NLP_STE_PRLI_ISSUE:
6625 case NLP_STE_LOGO_ISSUE:
6629 /* Check to see if we need to NVME rescan this target
6632 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6633 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6634 lpfc_nvme_rescan_port(vport, ndlp);
6636 lpfc_disc_state_machine(vport, ndlp, NULL,
6637 NLP_EVT_DEVICE_RECOVERY);
6638 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6644 * lpfc_send_rscn_event - Send an RSCN event to management application
6645 * @vport: pointer to a host virtual N_Port data structure.
6646 * @cmdiocb: pointer to lpfc command iocb data structure.
6648 * lpfc_send_rscn_event sends an RSCN netlink event to management
6652 lpfc_send_rscn_event(struct lpfc_vport *vport,
6653 struct lpfc_iocbq *cmdiocb)
6655 struct lpfc_dmabuf *pcmd;
6656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6657 uint32_t *payload_ptr;
6658 uint32_t payload_len;
6659 struct lpfc_rscn_event_header *rscn_event_data;
6661 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6662 payload_ptr = (uint32_t *) pcmd->virt;
6663 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6665 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6666 payload_len, GFP_KERNEL);
6667 if (!rscn_event_data) {
6668 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6669 "0147 Failed to allocate memory for RSCN event\n");
6672 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6673 rscn_event_data->payload_length = payload_len;
6674 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6677 fc_host_post_vendor_event(shost,
6678 fc_get_event_number(),
6679 sizeof(struct lpfc_rscn_event_header) + payload_len,
6680 (char *)rscn_event_data,
6683 kfree(rscn_event_data);
6687 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6688 * @vport: pointer to a host virtual N_Port data structure.
6689 * @cmdiocb: pointer to lpfc command iocb data structure.
6690 * @ndlp: pointer to a node-list data structure.
6692 * This routine processes an unsolicited RSCN (Registration State Change
6693 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6694 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6695 * discover state machine is about to begin discovery, it just accepts the
6696 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6697 * contains N_Port IDs for other vports on this HBA, it just accepts the
6698 * RSCN and ignore processing it. If the state machine is in the recovery
6699 * state, the fc_rscn_id_list of this @vport is walked and the
6700 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6701 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6702 * routine is invoked to handle the RSCN event.
6705 * 0 - Just sent the acc response
6706 * 1 - Sent the acc response and waited for name server completion
6709 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6710 struct lpfc_nodelist *ndlp)
6712 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6713 struct lpfc_hba *phba = vport->phba;
6714 struct lpfc_dmabuf *pcmd;
6715 uint32_t *lp, *datap;
6716 uint32_t payload_len, length, nportid, *cmd;
6718 int rscn_id = 0, hba_id = 0;
6721 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6722 lp = (uint32_t *) pcmd->virt;
6724 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6725 payload_len -= sizeof(uint32_t); /* take off word 0 */
6727 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6728 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6729 vport->fc_flag, payload_len, *lp,
6730 vport->fc_rscn_id_cnt);
6732 /* Send an RSCN event to the management application */
6733 lpfc_send_rscn_event(vport, cmdiocb);
6735 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6736 fc_host_post_event(shost, fc_get_event_number(),
6737 FCH_EVT_RSCN, lp[i]);
6739 /* Check if RSCN is coming from a direct-connected remote NPort */
6740 if (vport->fc_flag & FC_PT2PT) {
6741 /* If so, just ACC it, no other action needed for now */
6742 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6743 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6744 *lp, vport->fc_flag, payload_len);
6745 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6747 /* Check to see if we need to NVME rescan this target
6750 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6751 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6752 lpfc_nvme_rescan_port(vport, ndlp);
6756 /* If we are about to begin discovery, just ACC the RSCN.
6757 * Discovery processing will satisfy it.
6759 if (vport->port_state <= LPFC_NS_QRY) {
6760 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6761 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6762 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6764 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6768 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6769 * just ACC and ignore it.
6771 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6772 !(vport->cfg_peer_port_login)) {
6777 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6778 i -= sizeof(uint32_t);
6780 if (lpfc_find_vport_by_did(phba, nportid))
6783 if (rscn_id == hba_id) {
6784 /* ALL NPortIDs in RSCN are on HBA */
6785 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6787 "Data: x%x x%x x%x x%x\n",
6788 vport->fc_flag, payload_len,
6789 *lp, vport->fc_rscn_id_cnt);
6790 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6791 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6792 ndlp->nlp_DID, vport->port_state,
6795 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6801 spin_lock_irq(shost->host_lock);
6802 if (vport->fc_rscn_flush) {
6803 /* Another thread is walking fc_rscn_id_list on this vport */
6804 vport->fc_flag |= FC_RSCN_DISCOVERY;
6805 spin_unlock_irq(shost->host_lock);
6807 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6810 /* Indicate we are walking fc_rscn_id_list on this vport */
6811 vport->fc_rscn_flush = 1;
6812 spin_unlock_irq(shost->host_lock);
6813 /* Get the array count after successfully have the token */
6814 rscn_cnt = vport->fc_rscn_id_cnt;
6815 /* If we are already processing an RSCN, save the received
6816 * RSCN payload buffer, cmdiocb->context2 to process later.
6818 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6819 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6820 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6821 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6823 spin_lock_irq(shost->host_lock);
6824 vport->fc_flag |= FC_RSCN_DEFERRED;
6826 /* Restart disctmo if its already running */
6827 if (vport->fc_flag & FC_DISC_TMO) {
6828 tmo = ((phba->fc_ratov * 3) + 3);
6829 mod_timer(&vport->fc_disctmo,
6830 jiffies + msecs_to_jiffies(1000 * tmo));
6832 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6833 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6834 vport->fc_flag |= FC_RSCN_MODE;
6835 spin_unlock_irq(shost->host_lock);
6837 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6838 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6841 (payload_len + length <= LPFC_BPL_SIZE)) {
6842 *cmd &= ELS_CMD_MASK;
6843 *cmd |= cpu_to_be32(payload_len + length);
6844 memcpy(((uint8_t *)cmd) + length, lp,
6847 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6848 vport->fc_rscn_id_cnt++;
6849 /* If we zero, cmdiocb->context2, the calling
6850 * routine will not try to free it.
6852 cmdiocb->context2 = NULL;
6855 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6856 "0235 Deferred RSCN "
6857 "Data: x%x x%x x%x\n",
6858 vport->fc_rscn_id_cnt, vport->fc_flag,
6861 vport->fc_flag |= FC_RSCN_DISCOVERY;
6862 spin_unlock_irq(shost->host_lock);
6863 /* ReDiscovery RSCN */
6864 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6865 "0234 ReDiscovery RSCN "
6866 "Data: x%x x%x x%x\n",
6867 vport->fc_rscn_id_cnt, vport->fc_flag,
6870 /* Indicate we are done walking fc_rscn_id_list on this vport */
6871 vport->fc_rscn_flush = 0;
6873 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6874 /* send RECOVERY event for ALL nodes that match RSCN payload */
6875 lpfc_rscn_recovery_check(vport);
6878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6879 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6880 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6882 spin_lock_irq(shost->host_lock);
6883 vport->fc_flag |= FC_RSCN_MODE;
6884 spin_unlock_irq(shost->host_lock);
6885 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6886 /* Indicate we are done walking fc_rscn_id_list on this vport */
6887 vport->fc_rscn_flush = 0;
6889 * If we zero, cmdiocb->context2, the calling routine will
6890 * not try to free it.
6892 cmdiocb->context2 = NULL;
6893 lpfc_set_disctmo(vport);
6895 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6896 /* send RECOVERY event for ALL nodes that match RSCN payload */
6897 lpfc_rscn_recovery_check(vport);
6898 return lpfc_els_handle_rscn(vport);
6902 * lpfc_els_handle_rscn - Handle rscn for a vport
6903 * @vport: pointer to a host virtual N_Port data structure.
6905 * This routine handles the Registration State Configuration Notification
6906 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6907 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6908 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6909 * NameServer shall be issued. If CT command to the NameServer fails to be
6910 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6911 * RSCN activities with the @vport.
6914 * 0 - Cleaned up rscn on the @vport
6915 * 1 - Wait for plogi to name server before proceed
6918 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6920 struct lpfc_nodelist *ndlp;
6921 struct lpfc_hba *phba = vport->phba;
6923 /* Ignore RSCN if the port is being torn down. */
6924 if (vport->load_flag & FC_UNLOADING) {
6925 lpfc_els_flush_rscn(vport);
6929 /* Start timer for RSCN processing */
6930 lpfc_set_disctmo(vport);
6932 /* RSCN processed */
6933 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6934 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
6935 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6936 vport->port_state, vport->num_disc_nodes,
6939 /* To process RSCN, first compare RSCN data with NameServer */
6940 vport->fc_ns_retry = 0;
6941 vport->num_disc_nodes = 0;
6943 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6944 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6945 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6946 /* Good ndlp, issue CT Request to NameServer. Need to
6947 * know how many gidfts were issued. If none, then just
6948 * flush the RSCN. Otherwise, the outstanding requests
6951 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6952 if (lpfc_issue_gidft(vport) > 0)
6954 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6955 if (lpfc_issue_gidpt(vport) > 0)
6961 /* Nameserver login in question. Revalidate. */
6963 ndlp = lpfc_enable_node(vport, ndlp,
6964 NLP_STE_PLOGI_ISSUE);
6966 lpfc_els_flush_rscn(vport);
6969 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6971 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6973 lpfc_els_flush_rscn(vport);
6976 ndlp->nlp_prev_state = ndlp->nlp_state;
6977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6979 ndlp->nlp_type |= NLP_FABRIC;
6980 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6981 /* Wait for NameServer login cmpl before we can
6987 lpfc_els_flush_rscn(vport);
6992 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6993 * @vport: pointer to a host virtual N_Port data structure.
6994 * @cmdiocb: pointer to lpfc command iocb data structure.
6995 * @ndlp: pointer to a node-list data structure.
6997 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6998 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6999 * point topology. As an unsolicited FLOGI should not be received in a loop
7000 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7001 * lpfc_check_sparm() routine is invoked to check the parameters in the
7002 * unsolicited FLOGI. If parameters validation failed, the routine
7003 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7004 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7005 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7006 * will initiate PLOGI. The higher lexicographical value party shall has
7007 * higher priority (as the winning port) and will initiate PLOGI and
7008 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7009 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7010 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7013 * 0 - Successfully processed the unsolicited flogi
7014 * 1 - Failed to process the unsolicited flogi
7017 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7018 struct lpfc_nodelist *ndlp)
7020 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7021 struct lpfc_hba *phba = vport->phba;
7022 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7023 uint32_t *lp = (uint32_t *) pcmd->virt;
7024 IOCB_t *icmd = &cmdiocb->iocb;
7025 struct serv_parm *sp;
7029 uint32_t fc_flag = 0;
7030 uint32_t port_state = 0;
7033 sp = (struct serv_parm *) lp;
7035 /* FLOGI received */
7037 lpfc_set_disctmo(vport);
7039 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7040 /* We should never receive a FLOGI in loop mode, ignore it */
7041 did = icmd->un.elsreq64.remoteID;
7043 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7045 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7046 "0113 An FLOGI ELS command x%x was "
7047 "received from DID x%x in Loop Mode\n",
7052 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7055 * If our portname is greater than the remote portname,
7056 * then we initiate Nport login.
7059 rc = memcmp(&vport->fc_portname, &sp->portName,
7060 sizeof(struct lpfc_name));
7063 if (phba->sli_rev < LPFC_SLI_REV4) {
7064 mbox = mempool_alloc(phba->mbox_mem_pool,
7068 lpfc_linkdown(phba);
7069 lpfc_init_link(phba, mbox,
7071 phba->cfg_link_speed);
7072 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7073 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7074 mbox->vport = vport;
7075 rc = lpfc_sli_issue_mbox(phba, mbox,
7077 lpfc_set_loopback_flag(phba);
7078 if (rc == MBX_NOT_FINISHED)
7079 mempool_free(mbox, phba->mbox_mem_pool);
7083 /* abort the flogi coming back to ourselves
7084 * due to external loopback on the port.
7086 lpfc_els_abort_flogi(phba);
7089 } else if (rc > 0) { /* greater than */
7090 spin_lock_irq(shost->host_lock);
7091 vport->fc_flag |= FC_PT2PT_PLOGI;
7092 spin_unlock_irq(shost->host_lock);
7094 /* If we have the high WWPN we can assign our own
7095 * myDID; otherwise, we have to WAIT for a PLOGI
7096 * from the remote NPort to find out what it
7099 vport->fc_myDID = PT2PT_LocalID;
7101 vport->fc_myDID = PT2PT_RemoteID;
7105 * The vport state should go to LPFC_FLOGI only
7106 * AFTER we issue a FLOGI, not receive one.
7108 spin_lock_irq(shost->host_lock);
7109 fc_flag = vport->fc_flag;
7110 port_state = vport->port_state;
7111 vport->fc_flag |= FC_PT2PT;
7112 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7114 /* Acking an unsol FLOGI. Count 1 for link bounce
7117 vport->rcv_flogi_cnt++;
7118 spin_unlock_irq(shost->host_lock);
7119 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7120 "3311 Rcv Flogi PS x%x new PS x%x "
7121 "fc_flag x%x new fc_flag x%x\n",
7122 port_state, vport->port_state,
7123 fc_flag, vport->fc_flag);
7126 * We temporarily set fc_myDID to make it look like we are
7127 * a Fabric. This is done just so we end up with the right
7128 * did / sid on the FLOGI ACC rsp.
7130 did = vport->fc_myDID;
7131 vport->fc_myDID = Fabric_DID;
7133 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7135 /* Defer ACC response until AFTER we issue a FLOGI */
7136 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7137 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7138 phba->defer_flogi_acc_ox_id =
7139 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7141 vport->fc_myDID = did;
7143 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7144 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7145 " ox_id: x%x, hba_flag x%x\n",
7146 phba->defer_flogi_acc_rx_id,
7147 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7149 phba->defer_flogi_acc_flag = true;
7155 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7157 /* Now lets put fc_myDID back to what its supposed to be */
7158 vport->fc_myDID = did;
7164 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7165 * @vport: pointer to a host virtual N_Port data structure.
7166 * @cmdiocb: pointer to lpfc command iocb data structure.
7167 * @ndlp: pointer to a node-list data structure.
7169 * This routine processes Request Node Identification Data (RNID) IOCB
7170 * received as an ELS unsolicited event. Only when the RNID specified format
7171 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7172 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7173 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7174 * rejected by invoking the lpfc_els_rsp_reject() routine.
7177 * 0 - Successfully processed rnid iocb (currently always return 0)
7180 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7181 struct lpfc_nodelist *ndlp)
7183 struct lpfc_dmabuf *pcmd;
7188 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7189 lp = (uint32_t *) pcmd->virt;
7196 switch (rn->Format) {
7198 case RNID_TOPOLOGY_DISC:
7200 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7203 /* Reject this request because format not supported */
7204 stat.un.b.lsRjtRsvd0 = 0;
7205 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7206 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7207 stat.un.b.vendorUnique = 0;
7208 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7215 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7216 * @vport: pointer to a host virtual N_Port data structure.
7217 * @cmdiocb: pointer to lpfc command iocb data structure.
7218 * @ndlp: pointer to a node-list data structure.
7221 * 0 - Successfully processed echo iocb (currently always return 0)
7224 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7225 struct lpfc_nodelist *ndlp)
7229 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7231 /* skip over first word of echo command to find echo data */
7232 pcmd += sizeof(uint32_t);
7234 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7239 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7240 * @vport: pointer to a host virtual N_Port data structure.
7241 * @cmdiocb: pointer to lpfc command iocb data structure.
7242 * @ndlp: pointer to a node-list data structure.
7244 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7245 * received as an ELS unsolicited event. Currently, this function just invokes
7246 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7249 * 0 - Successfully processed lirr iocb (currently always return 0)
7252 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7253 struct lpfc_nodelist *ndlp)
7257 /* For now, unconditionally reject this command */
7258 stat.un.b.lsRjtRsvd0 = 0;
7259 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7260 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7261 stat.un.b.vendorUnique = 0;
7262 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7267 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7268 * @vport: pointer to a host virtual N_Port data structure.
7269 * @cmdiocb: pointer to lpfc command iocb data structure.
7270 * @ndlp: pointer to a node-list data structure.
7272 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7273 * received as an ELS unsolicited event. A request to RRQ shall only
7274 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7275 * Nx_Port N_Port_ID of the target Exchange is the same as the
7276 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7277 * not accepted, an LS_RJT with reason code "Unable to perform
7278 * command request" and reason code explanation "Invalid Originator
7279 * S_ID" shall be returned. For now, we just unconditionally accept
7280 * RRQ from the target.
7283 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7284 struct lpfc_nodelist *ndlp)
7286 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7287 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7288 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7292 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7293 * @phba: pointer to lpfc hba data structure.
7294 * @pmb: pointer to the driver internal queue element for mailbox command.
7296 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7297 * mailbox command. This callback function is to actually send the Accept
7298 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7299 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7300 * mailbox command, constructs the RPS response with the link statistics
7301 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7302 * response to the RPS.
7304 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7305 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7306 * will be stored into the context1 field of the IOCB for the completion
7307 * callback function to the RPS Accept Response ELS IOCB command.
7311 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7315 struct RLS_RSP *rls_rsp;
7317 struct lpfc_iocbq *elsiocb;
7318 struct lpfc_nodelist *ndlp;
7325 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7326 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7327 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7328 pmb->ctx_buf = NULL;
7329 pmb->ctx_ndlp = NULL;
7331 if (mb->mbxStatus) {
7332 mempool_free(pmb, phba->mbox_mem_pool);
7336 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7337 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7338 lpfc_max_els_tries, ndlp,
7339 ndlp->nlp_DID, ELS_CMD_ACC);
7341 /* Decrement the ndlp reference count from previous mbox command */
7345 mempool_free(pmb, phba->mbox_mem_pool);
7349 icmd = &elsiocb->iocb;
7350 icmd->ulpContext = rxid;
7351 icmd->unsli3.rcvsli3.ox_id = oxid;
7353 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7354 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7355 pcmd += sizeof(uint32_t); /* Skip past command */
7356 rls_rsp = (struct RLS_RSP *)pcmd;
7358 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7359 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7360 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7361 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7362 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7363 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7364 mempool_free(pmb, phba->mbox_mem_pool);
7365 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7366 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7367 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7368 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7369 elsiocb->iotag, elsiocb->iocb.ulpContext,
7370 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7372 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7373 phba->fc_stat.elsXmitACC++;
7374 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7375 lpfc_els_free_iocb(phba, elsiocb);
7379 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7380 * @vport: pointer to a host virtual N_Port data structure.
7381 * @cmdiocb: pointer to lpfc command iocb data structure.
7382 * @ndlp: pointer to a node-list data structure.
7384 * This routine processes Read Link Status (RLS) IOCB received as an
7385 * ELS unsolicited event. It first checks the remote port state. If the
7386 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7387 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7388 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7389 * for reading the HBA link statistics. It is for the callback function,
7390 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7391 * to actually sending out RPL Accept (ACC) response.
7394 * 0 - Successfully processed rls iocb (currently always return 0)
7397 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7398 struct lpfc_nodelist *ndlp)
7400 struct lpfc_hba *phba = vport->phba;
7404 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7405 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7406 /* reject the unsolicited RLS request and done with it */
7409 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7411 lpfc_read_lnk_stat(phba, mbox);
7412 mbox->ctx_buf = (void *)((unsigned long)
7413 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7414 cmdiocb->iocb.ulpContext)); /* rx_id */
7415 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7416 mbox->vport = vport;
7417 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7418 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7419 != MBX_NOT_FINISHED)
7420 /* Mbox completion will send ELS Response */
7422 /* Decrement reference count used for the failed mbox
7426 mempool_free(mbox, phba->mbox_mem_pool);
7429 /* issue rejection response */
7430 stat.un.b.lsRjtRsvd0 = 0;
7431 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7432 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7433 stat.un.b.vendorUnique = 0;
7434 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7439 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7440 * @vport: pointer to a host virtual N_Port data structure.
7441 * @cmdiocb: pointer to lpfc command iocb data structure.
7442 * @ndlp: pointer to a node-list data structure.
7444 * This routine processes Read Timout Value (RTV) IOCB received as an
7445 * ELS unsolicited event. It first checks the remote port state. If the
7446 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7447 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7448 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7449 * Value (RTV) unsolicited IOCB event.
7451 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7452 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7453 * will be stored into the context1 field of the IOCB for the completion
7454 * callback function to the RTV Accept Response ELS IOCB command.
7457 * 0 - Successfully processed rtv iocb (currently always return 0)
7460 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7461 struct lpfc_nodelist *ndlp)
7463 struct lpfc_hba *phba = vport->phba;
7465 struct RTV_RSP *rtv_rsp;
7467 struct lpfc_iocbq *elsiocb;
7471 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7472 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7473 /* reject the unsolicited RTV request and done with it */
7476 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7477 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7478 lpfc_max_els_tries, ndlp,
7479 ndlp->nlp_DID, ELS_CMD_ACC);
7484 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7485 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7486 pcmd += sizeof(uint32_t); /* Skip past command */
7488 /* use the command's xri in the response */
7489 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7490 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7492 rtv_rsp = (struct RTV_RSP *)pcmd;
7494 /* populate RTV payload */
7495 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7496 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7497 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7498 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7499 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7501 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7502 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7503 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7504 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7505 "Data: x%x x%x x%x\n",
7506 elsiocb->iotag, elsiocb->iocb.ulpContext,
7507 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7509 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7510 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7511 phba->fc_stat.elsXmitACC++;
7512 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7513 lpfc_els_free_iocb(phba, elsiocb);
7517 /* issue rejection response */
7518 stat.un.b.lsRjtRsvd0 = 0;
7519 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7520 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7521 stat.un.b.vendorUnique = 0;
7522 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7526 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7527 * @vport: pointer to a host virtual N_Port data structure.
7528 * @ndlp: pointer to a node-list data structure.
7529 * @did: DID of the target.
7530 * @rrq: Pointer to the rrq struct.
7532 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7533 * Successful the the completion handler will clear the RRQ.
7536 * 0 - Successfully sent rrq els iocb.
7537 * 1 - Failed to send rrq els iocb.
7540 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7541 uint32_t did, struct lpfc_node_rrq *rrq)
7543 struct lpfc_hba *phba = vport->phba;
7544 struct RRQ *els_rrq;
7545 struct lpfc_iocbq *elsiocb;
7551 if (ndlp != rrq->ndlp)
7553 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7556 /* If ndlp is not NULL, we will bump the reference count on it */
7557 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7558 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7563 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7565 /* For RRQ request, remainder of payload is Exchange IDs */
7566 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7567 pcmd += sizeof(uint32_t);
7568 els_rrq = (struct RRQ *) pcmd;
7570 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7571 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7572 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7573 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7574 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7577 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7578 "Issue RRQ: did:x%x",
7579 did, rrq->xritag, rrq->rxid);
7580 elsiocb->context_un.rrq = rrq;
7581 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7582 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7584 if (ret == IOCB_ERROR) {
7585 lpfc_els_free_iocb(phba, elsiocb);
7592 * lpfc_send_rrq - Sends ELS RRQ if needed.
7593 * @phba: pointer to lpfc hba data structure.
7594 * @rrq: pointer to the active rrq.
7596 * This routine will call the lpfc_issue_els_rrq if the rrq is
7597 * still active for the xri. If this function returns a failure then
7598 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7600 * Returns 0 Success.
7604 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7606 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7611 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7612 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7619 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7620 * @vport: pointer to a host virtual N_Port data structure.
7621 * @cmdsize: size of the ELS command.
7622 * @oldiocb: pointer to the original lpfc command iocb data structure.
7623 * @ndlp: pointer to a node-list data structure.
7625 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7626 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7628 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7629 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7630 * will be stored into the context1 field of the IOCB for the completion
7631 * callback function to the RPL Accept Response ELS command.
7634 * 0 - Successfully issued ACC RPL ELS command
7635 * 1 - Failed to issue ACC RPL ELS command
7638 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7639 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7641 struct lpfc_hba *phba = vport->phba;
7642 IOCB_t *icmd, *oldcmd;
7644 struct lpfc_iocbq *elsiocb;
7647 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7648 ndlp->nlp_DID, ELS_CMD_ACC);
7653 icmd = &elsiocb->iocb;
7654 oldcmd = &oldiocb->iocb;
7655 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7656 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7658 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7659 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7660 pcmd += sizeof(uint16_t);
7661 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7662 pcmd += sizeof(uint16_t);
7664 /* Setup the RPL ACC payload */
7665 rpl_rsp.listLen = be32_to_cpu(1);
7667 rpl_rsp.port_num_blk.portNum = 0;
7668 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7669 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7670 sizeof(struct lpfc_name));
7671 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7672 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7673 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7674 "0120 Xmit ELS RPL ACC response tag x%x "
7675 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7677 elsiocb->iotag, elsiocb->iocb.ulpContext,
7678 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7680 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7681 phba->fc_stat.elsXmitACC++;
7682 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7684 lpfc_els_free_iocb(phba, elsiocb);
7691 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7692 * @vport: pointer to a host virtual N_Port data structure.
7693 * @cmdiocb: pointer to lpfc command iocb data structure.
7694 * @ndlp: pointer to a node-list data structure.
7696 * This routine processes Read Port List (RPL) IOCB received as an ELS
7697 * unsolicited event. It first checks the remote port state. If the remote
7698 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7699 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7700 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7701 * to accept the RPL.
7704 * 0 - Successfully processed rpl iocb (currently always return 0)
7707 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7708 struct lpfc_nodelist *ndlp)
7710 struct lpfc_dmabuf *pcmd;
7717 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7718 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7719 /* issue rejection response */
7720 stat.un.b.lsRjtRsvd0 = 0;
7721 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7722 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7723 stat.un.b.vendorUnique = 0;
7724 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7726 /* rejected the unsolicited RPL request and done with it */
7730 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7731 lp = (uint32_t *) pcmd->virt;
7732 rpl = (RPL *) (lp + 1);
7733 maxsize = be32_to_cpu(rpl->maxsize);
7735 /* We support only one port */
7736 if ((rpl->index == 0) &&
7738 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7739 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7741 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7743 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7749 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7750 * @vport: pointer to a virtual N_Port data structure.
7751 * @cmdiocb: pointer to lpfc command iocb data structure.
7752 * @ndlp: pointer to a node-list data structure.
7754 * This routine processes Fibre Channel Address Resolution Protocol
7755 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7756 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7757 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7758 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7759 * remote PortName is compared against the FC PortName stored in the @vport
7760 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7761 * compared against the FC NodeName stored in the @vport data structure.
7762 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7763 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7764 * invoked to send out FARP Response to the remote node. Before sending the
7765 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7766 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7767 * routine is invoked to log into the remote port first.
7770 * 0 - Either the FARP Match Mode not supported or successfully processed
7773 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7774 struct lpfc_nodelist *ndlp)
7776 struct lpfc_dmabuf *pcmd;
7782 icmd = &cmdiocb->iocb;
7783 did = icmd->un.elsreq64.remoteID;
7784 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7785 lp = (uint32_t *) pcmd->virt;
7789 /* FARP-REQ received from DID <did> */
7790 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7791 "0601 FARP-REQ received from DID x%x\n", did);
7792 /* We will only support match on WWPN or WWNN */
7793 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7798 /* If this FARP command is searching for my portname */
7799 if (fp->Mflags & FARP_MATCH_PORT) {
7800 if (memcmp(&fp->RportName, &vport->fc_portname,
7801 sizeof(struct lpfc_name)) == 0)
7805 /* If this FARP command is searching for my nodename */
7806 if (fp->Mflags & FARP_MATCH_NODE) {
7807 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7808 sizeof(struct lpfc_name)) == 0)
7813 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7814 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7815 /* Log back into the node before sending the FARP. */
7816 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7817 ndlp->nlp_prev_state = ndlp->nlp_state;
7818 lpfc_nlp_set_state(vport, ndlp,
7819 NLP_STE_PLOGI_ISSUE);
7820 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7823 /* Send a FARP response to that node */
7824 if (fp->Rflags & FARP_REQUEST_FARPR)
7825 lpfc_issue_els_farpr(vport, did, 0);
7832 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7833 * @vport: pointer to a host virtual N_Port data structure.
7834 * @cmdiocb: pointer to lpfc command iocb data structure.
7835 * @ndlp: pointer to a node-list data structure.
7837 * This routine processes Fibre Channel Address Resolution Protocol
7838 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7839 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7840 * the FARP response request.
7843 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7846 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7847 struct lpfc_nodelist *ndlp)
7849 struct lpfc_dmabuf *pcmd;
7854 icmd = &cmdiocb->iocb;
7855 did = icmd->un.elsreq64.remoteID;
7856 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7857 lp = (uint32_t *) pcmd->virt;
7860 /* FARP-RSP received from DID <did> */
7861 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7862 "0600 FARP-RSP received from DID x%x\n", did);
7863 /* ACCEPT the Farp resp request */
7864 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7870 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7871 * @vport: pointer to a host virtual N_Port data structure.
7872 * @cmdiocb: pointer to lpfc command iocb data structure.
7873 * @fan_ndlp: pointer to a node-list data structure.
7875 * This routine processes a Fabric Address Notification (FAN) IOCB
7876 * command received as an ELS unsolicited event. The FAN ELS command will
7877 * only be processed on a physical port (i.e., the @vport represents the
7878 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7879 * compared against those in the phba data structure. If any of those is
7880 * different, the lpfc_initial_flogi() routine is invoked to initialize
7881 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7882 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7883 * is invoked to register login to the fabric.
7886 * 0 - Successfully processed fan iocb (currently always return 0).
7889 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7890 struct lpfc_nodelist *fan_ndlp)
7892 struct lpfc_hba *phba = vport->phba;
7896 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7897 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7899 /* FAN received; Fan does not have a reply sequence */
7900 if ((vport == phba->pport) &&
7901 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7902 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7903 sizeof(struct lpfc_name))) ||
7904 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7905 sizeof(struct lpfc_name)))) {
7906 /* This port has switched fabrics. FLOGI is required */
7907 lpfc_issue_init_vfi(vport);
7909 /* FAN verified - skip FLOGI */
7910 vport->fc_myDID = vport->fc_prevDID;
7911 if (phba->sli_rev < LPFC_SLI_REV4)
7912 lpfc_issue_fabric_reglogin(vport);
7914 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7915 "3138 Need register VFI: (x%x/%x)\n",
7916 vport->fc_prevDID, vport->fc_myDID);
7917 lpfc_issue_reg_vfi(vport);
7925 * lpfc_els_timeout - Handler funciton to the els timer
7926 * @t: timer context used to obtain the vport.
7928 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7929 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7930 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7931 * up the worker thread. It is for the worker thread to invoke the routine
7932 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7935 lpfc_els_timeout(struct timer_list *t)
7937 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7938 struct lpfc_hba *phba = vport->phba;
7939 uint32_t tmo_posted;
7940 unsigned long iflag;
7942 spin_lock_irqsave(&vport->work_port_lock, iflag);
7943 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7944 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7945 vport->work_port_events |= WORKER_ELS_TMO;
7946 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7948 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7949 lpfc_worker_wake_up(phba);
7955 * lpfc_els_timeout_handler - Process an els timeout event
7956 * @vport: pointer to a virtual N_Port data structure.
7958 * This routine is the actual handler function that processes an ELS timeout
7959 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7960 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7961 * invoking the lpfc_sli_issue_abort_iotag() routine.
7964 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7966 struct lpfc_hba *phba = vport->phba;
7967 struct lpfc_sli_ring *pring;
7968 struct lpfc_iocbq *tmp_iocb, *piocb;
7970 struct lpfc_dmabuf *pcmd;
7971 uint32_t els_command = 0;
7973 uint32_t remote_ID = 0xffffffff;
7974 LIST_HEAD(abort_list);
7977 timeout = (uint32_t)(phba->fc_ratov << 1);
7979 pring = lpfc_phba_elsring(phba);
7980 if (unlikely(!pring))
7983 if (phba->pport->load_flag & FC_UNLOADING)
7986 spin_lock_irq(&phba->hbalock);
7987 if (phba->sli_rev == LPFC_SLI_REV4)
7988 spin_lock(&pring->ring_lock);
7990 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7993 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7994 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7995 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7998 if (piocb->vport != vport)
8001 pcmd = (struct lpfc_dmabuf *) piocb->context2;
8003 els_command = *(uint32_t *) (pcmd->virt);
8005 if (els_command == ELS_CMD_FARP ||
8006 els_command == ELS_CMD_FARPR ||
8007 els_command == ELS_CMD_FDISC)
8010 if (piocb->drvrTimeout > 0) {
8011 if (piocb->drvrTimeout >= timeout)
8012 piocb->drvrTimeout -= timeout;
8014 piocb->drvrTimeout = 0;
8018 remote_ID = 0xffffffff;
8019 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
8020 remote_ID = cmd->un.elsreq64.remoteID;
8022 struct lpfc_nodelist *ndlp;
8023 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
8024 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
8025 remote_ID = ndlp->nlp_DID;
8027 list_add_tail(&piocb->dlist, &abort_list);
8029 if (phba->sli_rev == LPFC_SLI_REV4)
8030 spin_unlock(&pring->ring_lock);
8031 spin_unlock_irq(&phba->hbalock);
8033 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8035 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8036 "0127 ELS timeout Data: x%x x%x x%x "
8037 "x%x\n", els_command,
8038 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8039 spin_lock_irq(&phba->hbalock);
8040 list_del_init(&piocb->dlist);
8041 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8042 spin_unlock_irq(&phba->hbalock);
8045 if (!list_empty(&pring->txcmplq))
8046 if (!(phba->pport->load_flag & FC_UNLOADING))
8047 mod_timer(&vport->els_tmofunc,
8048 jiffies + msecs_to_jiffies(1000 * timeout));
8052 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8053 * @vport: pointer to a host virtual N_Port data structure.
8055 * This routine is used to clean up all the outstanding ELS commands on a
8056 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8057 * routine. After that, it walks the ELS transmit queue to remove all the
8058 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8059 * the IOCBs with a non-NULL completion callback function, the callback
8060 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8061 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8062 * callback function, the IOCB will simply be released. Finally, it walks
8063 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8064 * completion queue IOCB that is associated with the @vport and is not
8065 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8066 * part of the discovery state machine) out to HBA by invoking the
8067 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8068 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8069 * the IOCBs are aborted when this function returns.
8072 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8074 LIST_HEAD(abort_list);
8075 struct lpfc_hba *phba = vport->phba;
8076 struct lpfc_sli_ring *pring;
8077 struct lpfc_iocbq *tmp_iocb, *piocb;
8079 unsigned long iflags = 0;
8081 lpfc_fabric_abort_vport(vport);
8084 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8085 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8086 * ultimately grabs the ring_lock, the driver must splice the list into
8087 * a working list and release the locks before calling the abort.
8089 spin_lock_irqsave(&phba->hbalock, iflags);
8090 pring = lpfc_phba_elsring(phba);
8092 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8093 if (unlikely(!pring)) {
8094 spin_unlock_irqrestore(&phba->hbalock, iflags);
8098 if (phba->sli_rev == LPFC_SLI_REV4)
8099 spin_lock(&pring->ring_lock);
8101 /* First we need to issue aborts to outstanding cmds on txcmpl */
8102 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8103 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8106 if (piocb->vport != vport)
8109 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8112 /* On the ELS ring we can have ELS_REQUESTs or
8113 * GEN_REQUESTs waiting for a response.
8116 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8117 list_add_tail(&piocb->dlist, &abort_list);
8119 /* If the link is down when flushing ELS commands
8120 * the firmware will not complete them till after
8121 * the link comes back up. This may confuse
8122 * discovery for the new link up, so we need to
8123 * change the compl routine to just clean up the iocb
8124 * and avoid any retry logic.
8126 if (phba->link_state == LPFC_LINK_DOWN)
8127 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8129 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8130 list_add_tail(&piocb->dlist, &abort_list);
8133 if (phba->sli_rev == LPFC_SLI_REV4)
8134 spin_unlock(&pring->ring_lock);
8135 spin_unlock_irqrestore(&phba->hbalock, iflags);
8137 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8138 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8139 spin_lock_irqsave(&phba->hbalock, iflags);
8140 list_del_init(&piocb->dlist);
8141 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8142 spin_unlock_irqrestore(&phba->hbalock, iflags);
8144 if (!list_empty(&abort_list))
8145 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8146 "3387 abort list for txq not empty\n");
8147 INIT_LIST_HEAD(&abort_list);
8149 spin_lock_irqsave(&phba->hbalock, iflags);
8150 if (phba->sli_rev == LPFC_SLI_REV4)
8151 spin_lock(&pring->ring_lock);
8153 /* No need to abort the txq list,
8154 * just queue them up for lpfc_sli_cancel_iocbs
8156 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8159 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8163 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8164 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8165 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8166 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8167 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8170 if (piocb->vport != vport)
8173 list_del_init(&piocb->list);
8174 list_add_tail(&piocb->list, &abort_list);
8177 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8178 if (vport == phba->pport) {
8179 list_for_each_entry_safe(piocb, tmp_iocb,
8180 &phba->fabric_iocb_list, list) {
8182 list_del_init(&piocb->list);
8183 list_add_tail(&piocb->list, &abort_list);
8187 if (phba->sli_rev == LPFC_SLI_REV4)
8188 spin_unlock(&pring->ring_lock);
8189 spin_unlock_irqrestore(&phba->hbalock, iflags);
8191 /* Cancel all the IOCBs from the completions list */
8192 lpfc_sli_cancel_iocbs(phba, &abort_list,
8193 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8199 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8200 * @phba: pointer to lpfc hba data structure.
8202 * This routine is used to clean up all the outstanding ELS commands on a
8203 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8204 * routine. After that, it walks the ELS transmit queue to remove all the
8205 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8206 * the IOCBs with the completion callback function associated, the callback
8207 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8208 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8209 * callback function associated, the IOCB will simply be released. Finally,
8210 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8211 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8212 * management plane IOCBs that are not part of the discovery state machine)
8213 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8216 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8218 struct lpfc_vport *vport;
8220 spin_lock_irq(&phba->port_list_lock);
8221 list_for_each_entry(vport, &phba->port_list, listentry)
8222 lpfc_els_flush_cmd(vport);
8223 spin_unlock_irq(&phba->port_list_lock);
8229 * lpfc_send_els_failure_event - Posts an ELS command failure event
8230 * @phba: Pointer to hba context object.
8231 * @cmdiocbp: Pointer to command iocb which reported error.
8232 * @rspiocbp: Pointer to response iocb which reported error.
8234 * This function sends an event when there is an ELS command
8238 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8239 struct lpfc_iocbq *cmdiocbp,
8240 struct lpfc_iocbq *rspiocbp)
8242 struct lpfc_vport *vport = cmdiocbp->vport;
8243 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8244 struct lpfc_lsrjt_event lsrjt_event;
8245 struct lpfc_fabric_event_header fabric_event;
8247 struct lpfc_nodelist *ndlp;
8250 ndlp = cmdiocbp->context1;
8251 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
8254 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8255 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8256 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8257 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8258 sizeof(struct lpfc_name));
8259 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8260 sizeof(struct lpfc_name));
8261 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8262 cmdiocbp->context2)->virt);
8263 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8264 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8265 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8266 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8267 fc_host_post_vendor_event(shost,
8268 fc_get_event_number(),
8269 sizeof(lsrjt_event),
8270 (char *)&lsrjt_event,
8274 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8275 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8276 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8277 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8278 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8280 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8281 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8282 sizeof(struct lpfc_name));
8283 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8284 sizeof(struct lpfc_name));
8285 fc_host_post_vendor_event(shost,
8286 fc_get_event_number(),
8287 sizeof(fabric_event),
8288 (char *)&fabric_event,
8296 * lpfc_send_els_event - Posts unsolicited els event
8297 * @vport: Pointer to vport object.
8298 * @ndlp: Pointer FC node object.
8299 * @payload: ELS command code type.
8301 * This function posts an event when there is an incoming
8302 * unsolicited ELS command.
8305 lpfc_send_els_event(struct lpfc_vport *vport,
8306 struct lpfc_nodelist *ndlp,
8309 struct lpfc_els_event_header *els_data = NULL;
8310 struct lpfc_logo_event *logo_data = NULL;
8311 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8313 if (*payload == ELS_CMD_LOGO) {
8314 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8316 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8317 "0148 Failed to allocate memory "
8318 "for LOGO event\n");
8321 els_data = &logo_data->header;
8323 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8326 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8327 "0149 Failed to allocate memory "
8332 els_data->event_type = FC_REG_ELS_EVENT;
8335 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8338 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8341 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8344 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8345 /* Copy the WWPN in the LOGO payload */
8346 memcpy(logo_data->logo_wwpn, &payload[2],
8347 sizeof(struct lpfc_name));
8353 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8354 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8355 if (*payload == ELS_CMD_LOGO) {
8356 fc_host_post_vendor_event(shost,
8357 fc_get_event_number(),
8358 sizeof(struct lpfc_logo_event),
8363 fc_host_post_vendor_event(shost,
8364 fc_get_event_number(),
8365 sizeof(struct lpfc_els_event_header),
8375 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8376 FC_LS_TLV_DTAG_INIT);
8378 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8379 FC_FPIN_LI_EVT_TYPES_INIT);
8382 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8383 * @vport: Pointer to vport object.
8384 * @tlv: Pointer to the Link Integrity Notification Descriptor.
8386 * This function processes a link integrity FPIN event by
8390 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8392 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8393 const char *li_evt_str;
8396 li_evt = be16_to_cpu(li->event_type);
8397 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8399 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8400 "4680 FPIN Link Integrity %s (x%x) "
8401 "Detecting PN x%016llx Attached PN x%016llx "
8402 "Duration %d mSecs Count %d Port Cnt %d\n",
8404 be64_to_cpu(li->detecting_wwpn),
8405 be64_to_cpu(li->attached_wwpn),
8406 be32_to_cpu(li->event_threshold),
8407 be32_to_cpu(li->event_count),
8408 be32_to_cpu(li->pname_count));
8412 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8415 struct fc_tlv_desc *tlv;
8416 const char *dtag_nm;
8417 uint32_t desc_cnt = 0, bytes_remain;
8420 /* FPINs handled only if we are in the right discovery state */
8421 if (vport->port_state < LPFC_DISC_AUTH)
8424 /* make sure there is the full fpin header */
8425 if (fpin_length < sizeof(struct fc_els_fpin))
8428 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8429 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8430 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8432 /* process each descriptor */
8433 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8434 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8436 dtag = be32_to_cpu(tlv->desc_tag);
8438 case ELS_DTAG_LNK_INTEGRITY:
8439 lpfc_els_rcv_fpin_li(vport, tlv);
8442 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8443 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8444 "4678 skipped FPIN descriptor[%d]: "
8446 desc_cnt, dtag, dtag_nm);
8451 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8452 tlv = fc_tlv_next_desc(tlv);
8455 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8460 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8461 * @phba: pointer to lpfc hba data structure.
8462 * @pring: pointer to a SLI ring.
8463 * @vport: pointer to a host virtual N_Port data structure.
8464 * @elsiocb: pointer to lpfc els command iocb data structure.
8466 * This routine is used for processing the IOCB associated with a unsolicited
8467 * event. It first determines whether there is an existing ndlp that matches
8468 * the DID from the unsolicited IOCB. If not, it will create a new one with
8469 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8470 * IOCB is then used to invoke the proper routine and to set up proper state
8471 * of the discovery state machine.
8474 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8475 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8477 struct Scsi_Host *shost;
8478 struct lpfc_nodelist *ndlp;
8480 uint32_t *payload, payload_len;
8481 uint32_t cmd, did, newnode;
8482 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8483 IOCB_t *icmd = &elsiocb->iocb;
8486 if (!vport || !(elsiocb->context2))
8490 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8491 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8493 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8494 lpfc_post_buffer(phba, pring, 1);
8496 did = icmd->un.rcvels.remoteID;
8497 if (icmd->ulpStatus) {
8498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8499 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8500 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8504 /* Check to see if link went down during discovery */
8505 if (lpfc_els_chk_latt(vport))
8508 /* Ignore traffic received during vport shutdown. */
8509 if (vport->load_flag & FC_UNLOADING)
8512 /* If NPort discovery is delayed drop incoming ELS */
8513 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8514 (cmd != ELS_CMD_PLOGI))
8517 ndlp = lpfc_findnode_did(vport, did);
8519 /* Cannot find existing Fabric ndlp, so allocate a new one */
8520 ndlp = lpfc_nlp_init(vport, did);
8523 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8525 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8526 ndlp->nlp_type |= NLP_FABRIC;
8527 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8528 ndlp = lpfc_enable_node(vport, ndlp,
8529 NLP_STE_UNUSED_NODE);
8532 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8534 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8535 ndlp->nlp_type |= NLP_FABRIC;
8536 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8537 /* This is similar to the new node path */
8538 ndlp = lpfc_nlp_get(ndlp);
8541 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8545 phba->fc_stat.elsRcvFrame++;
8548 * Do not process any unsolicited ELS commands
8549 * if the ndlp is in DEV_LOSS
8551 shost = lpfc_shost_from_vport(vport);
8552 spin_lock_irq(shost->host_lock);
8553 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8554 spin_unlock_irq(shost->host_lock);
8559 spin_unlock_irq(shost->host_lock);
8561 elsiocb->context1 = lpfc_nlp_get(ndlp);
8562 elsiocb->vport = vport;
8564 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8565 cmd &= ELS_CMD_MASK;
8567 /* ELS command <elsCmd> received from NPORT <did> */
8568 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8569 "0112 ELS command x%x received from NPORT x%x "
8570 "Data: x%x x%x x%x x%x\n",
8571 cmd, did, vport->port_state, vport->fc_flag,
8572 vport->fc_myDID, vport->fc_prevDID);
8574 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8575 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8576 (cmd != ELS_CMD_FLOGI) &&
8577 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8578 rjt_err = LSRJT_LOGICAL_BSY;
8579 rjt_exp = LSEXP_NOTHING_MORE;
8585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8586 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8587 did, vport->port_state, ndlp->nlp_flag);
8589 phba->fc_stat.elsRcvPLOGI++;
8590 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8591 if (phba->sli_rev == LPFC_SLI_REV4 &&
8592 (phba->pport->fc_flag & FC_PT2PT)) {
8593 vport->fc_prevDID = vport->fc_myDID;
8594 /* Our DID needs to be updated before registering
8595 * the vfi. This is done in lpfc_rcv_plogi but
8596 * that is called after the reg_vfi.
8598 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8599 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8600 "3312 Remote port assigned DID x%x "
8601 "%x\n", vport->fc_myDID,
8605 lpfc_send_els_event(vport, ndlp, payload);
8607 /* If Nport discovery is delayed, reject PLOGIs */
8608 if (vport->fc_flag & FC_DISC_DELAYED) {
8609 rjt_err = LSRJT_UNABLE_TPC;
8610 rjt_exp = LSEXP_NOTHING_MORE;
8614 if (vport->port_state < LPFC_DISC_AUTH) {
8615 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8616 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8617 rjt_err = LSRJT_UNABLE_TPC;
8618 rjt_exp = LSEXP_NOTHING_MORE;
8623 spin_lock_irq(shost->host_lock);
8624 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8625 spin_unlock_irq(shost->host_lock);
8627 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8633 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8634 did, vport->port_state, ndlp->nlp_flag);
8636 phba->fc_stat.elsRcvFLOGI++;
8638 /* If the driver believes fabric discovery is done and is ready,
8639 * bounce the link. There is some descrepancy.
8641 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8642 vport->fc_flag & FC_PT2PT &&
8643 vport->rcv_flogi_cnt >= 1) {
8644 rjt_err = LSRJT_LOGICAL_BSY;
8645 rjt_exp = LSEXP_NOTHING_MORE;
8650 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8656 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8657 did, vport->port_state, ndlp->nlp_flag);
8659 phba->fc_stat.elsRcvLOGO++;
8660 lpfc_send_els_event(vport, ndlp, payload);
8661 if (vport->port_state < LPFC_DISC_AUTH) {
8662 rjt_err = LSRJT_UNABLE_TPC;
8663 rjt_exp = LSEXP_NOTHING_MORE;
8666 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8669 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8670 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8671 did, vport->port_state, ndlp->nlp_flag);
8673 phba->fc_stat.elsRcvPRLO++;
8674 lpfc_send_els_event(vport, ndlp, payload);
8675 if (vport->port_state < LPFC_DISC_AUTH) {
8676 rjt_err = LSRJT_UNABLE_TPC;
8677 rjt_exp = LSEXP_NOTHING_MORE;
8680 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8683 phba->fc_stat.elsRcvLCB++;
8684 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8687 phba->fc_stat.elsRcvRDP++;
8688 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8691 phba->fc_stat.elsRcvRSCN++;
8692 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8697 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8698 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8699 did, vport->port_state, ndlp->nlp_flag);
8701 lpfc_send_els_event(vport, ndlp, payload);
8702 phba->fc_stat.elsRcvADISC++;
8703 if (vport->port_state < LPFC_DISC_AUTH) {
8704 rjt_err = LSRJT_UNABLE_TPC;
8705 rjt_exp = LSEXP_NOTHING_MORE;
8708 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8712 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8713 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8714 did, vport->port_state, ndlp->nlp_flag);
8716 phba->fc_stat.elsRcvPDISC++;
8717 if (vport->port_state < LPFC_DISC_AUTH) {
8718 rjt_err = LSRJT_UNABLE_TPC;
8719 rjt_exp = LSEXP_NOTHING_MORE;
8722 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8726 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8727 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8728 did, vport->port_state, ndlp->nlp_flag);
8730 phba->fc_stat.elsRcvFARPR++;
8731 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8735 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8736 did, vport->port_state, ndlp->nlp_flag);
8738 phba->fc_stat.elsRcvFARP++;
8739 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8743 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8744 did, vport->port_state, ndlp->nlp_flag);
8746 phba->fc_stat.elsRcvFAN++;
8747 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8750 case ELS_CMD_NVMEPRLI:
8751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8752 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8753 did, vport->port_state, ndlp->nlp_flag);
8755 phba->fc_stat.elsRcvPRLI++;
8756 if ((vport->port_state < LPFC_DISC_AUTH) &&
8757 (vport->fc_flag & FC_FABRIC)) {
8758 rjt_err = LSRJT_UNABLE_TPC;
8759 rjt_exp = LSEXP_NOTHING_MORE;
8762 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8766 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8767 did, vport->port_state, ndlp->nlp_flag);
8769 phba->fc_stat.elsRcvLIRR++;
8770 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8776 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8777 did, vport->port_state, ndlp->nlp_flag);
8779 phba->fc_stat.elsRcvRLS++;
8780 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8786 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8787 did, vport->port_state, ndlp->nlp_flag);
8789 phba->fc_stat.elsRcvRPL++;
8790 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8795 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8796 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8797 did, vport->port_state, ndlp->nlp_flag);
8799 phba->fc_stat.elsRcvRNID++;
8800 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8806 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8807 did, vport->port_state, ndlp->nlp_flag);
8808 phba->fc_stat.elsRcvRTV++;
8809 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8814 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8815 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8816 did, vport->port_state, ndlp->nlp_flag);
8818 phba->fc_stat.elsRcvRRQ++;
8819 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8825 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8826 did, vport->port_state, ndlp->nlp_flag);
8828 phba->fc_stat.elsRcvECHO++;
8829 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8834 /* receive this due to exchange closed */
8835 rjt_err = LSRJT_UNABLE_TPC;
8836 rjt_exp = LSEXP_INVALID_OX_RX;
8839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8840 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8841 did, vport->port_state, ndlp->nlp_flag);
8843 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8846 /* There are no replies, so no rjt codes */
8849 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8850 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8851 cmd, did, vport->port_state);
8853 /* Unsupported ELS command, reject */
8854 rjt_err = LSRJT_CMD_UNSUPPORTED;
8855 rjt_exp = LSEXP_NOTHING_MORE;
8857 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8858 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8859 "0115 Unknown ELS command x%x "
8860 "received from NPORT x%x\n", cmd, did);
8867 /* check if need to LS_RJT received ELS cmd */
8869 memset(&stat, 0, sizeof(stat));
8870 stat.un.b.lsRjtRsnCode = rjt_err;
8871 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8872 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8876 lpfc_nlp_put(elsiocb->context1);
8877 elsiocb->context1 = NULL;
8879 /* Special case. Driver received an unsolicited command that
8880 * unsupportable given the driver's current state. Reset the
8881 * link and start over.
8884 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8887 lpfc_linkdown(phba);
8888 lpfc_init_link(phba, mbox,
8890 phba->cfg_link_speed);
8891 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8892 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8893 mbox->vport = vport;
8894 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8896 mempool_free(mbox, phba->mbox_mem_pool);
8902 if (vport && !(vport->load_flag & FC_UNLOADING))
8903 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8904 "0111 Dropping received ELS cmd "
8905 "Data: x%x x%x x%x\n",
8906 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8907 phba->fc_stat.elsRcvDrop++;
8911 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8912 * @phba: pointer to lpfc hba data structure.
8913 * @pring: pointer to a SLI ring.
8914 * @elsiocb: pointer to lpfc els iocb data structure.
8916 * This routine is used to process an unsolicited event received from a SLI
8917 * (Service Level Interface) ring. The actual processing of the data buffer
8918 * associated with the unsolicited event is done by invoking the routine
8919 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8920 * SLI ring on which the unsolicited event was received.
8923 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8924 struct lpfc_iocbq *elsiocb)
8926 struct lpfc_vport *vport = phba->pport;
8927 IOCB_t *icmd = &elsiocb->iocb;
8929 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8930 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8932 elsiocb->context1 = NULL;
8933 elsiocb->context2 = NULL;
8934 elsiocb->context3 = NULL;
8936 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8937 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8938 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8939 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8940 IOERR_RCV_BUFFER_WAITING) {
8941 phba->fc_stat.NoRcvBuf++;
8942 /* Not enough posted buffers; Try posting more buffers */
8943 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8944 lpfc_post_buffer(phba, pring, 0);
8948 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8949 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8950 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8951 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8952 vport = phba->pport;
8954 vport = lpfc_find_vport_by_vpid(phba,
8955 icmd->unsli3.rcvsli3.vpi);
8958 /* If there are no BDEs associated
8959 * with this IOCB, there is nothing to do.
8961 if (icmd->ulpBdeCount == 0)
8964 /* type of ELS cmd is first 32bit word
8967 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8968 elsiocb->context2 = bdeBuf1;
8970 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8971 icmd->un.cont64[0].addrLow);
8972 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8976 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8978 * The different unsolicited event handlers would tell us
8979 * if they are done with "mp" by setting context2 to NULL.
8981 if (elsiocb->context2) {
8982 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8983 elsiocb->context2 = NULL;
8986 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8987 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8988 icmd->ulpBdeCount == 2) {
8989 elsiocb->context2 = bdeBuf2;
8990 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8991 /* free mp if we are done with it */
8992 if (elsiocb->context2) {
8993 lpfc_in_buf_free(phba, elsiocb->context2);
8994 elsiocb->context2 = NULL;
9000 lpfc_start_fdmi(struct lpfc_vport *vport)
9002 struct lpfc_nodelist *ndlp;
9004 /* If this is the first time, allocate an ndlp and initialize
9005 * it. Otherwise, make sure the node is enabled and then do the
9008 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9010 ndlp = lpfc_nlp_init(vport, FDMI_DID);
9012 ndlp->nlp_type |= NLP_FABRIC;
9017 if (!NLP_CHK_NODE_ACT(ndlp))
9018 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
9021 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9022 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9027 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
9028 * @phba: pointer to lpfc hba data structure.
9029 * @vport: pointer to a virtual N_Port data structure.
9031 * This routine issues a Port Login (PLOGI) to the Name Server with
9032 * State Change Request (SCR) for a @vport. This routine will create an
9033 * ndlp for the Name Server associated to the @vport if such node does
9034 * not already exist. The PLOGI to Name Server is issued by invoking the
9035 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9036 * (FDMI) is configured to the @vport, a FDMI node will be created and
9037 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9040 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9042 struct lpfc_nodelist *ndlp;
9043 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9046 * If lpfc_delay_discovery parameter is set and the clean address
9047 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9050 spin_lock_irq(shost->host_lock);
9051 if (vport->fc_flag & FC_DISC_DELAYED) {
9052 spin_unlock_irq(shost->host_lock);
9053 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9054 "3334 Delay fc port discovery for %d seconds\n",
9056 mod_timer(&vport->delayed_disc_tmo,
9057 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9060 spin_unlock_irq(shost->host_lock);
9062 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9064 ndlp = lpfc_nlp_init(vport, NameServer_DID);
9066 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9067 lpfc_disc_start(vport);
9070 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9071 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9072 "0251 NameServer login: no memory\n");
9075 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
9076 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
9078 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9079 lpfc_disc_start(vport);
9082 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9083 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9084 "0348 NameServer login: node freed\n");
9088 ndlp->nlp_type |= NLP_FABRIC;
9090 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9092 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9093 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9094 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9095 "0252 Cannot issue NameServer login\n");
9099 if ((phba->cfg_enable_SmartSAN ||
9100 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9101 (vport->load_flag & FC_ALLOW_FDMI))
9102 lpfc_start_fdmi(vport);
9106 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9107 * @phba: pointer to lpfc hba data structure.
9108 * @pmb: pointer to the driver internal queue element for mailbox command.
9110 * This routine is the completion callback function to register new vport
9111 * mailbox command. If the new vport mailbox command completes successfully,
9112 * the fabric registration login shall be performed on physical port (the
9113 * new vport created is actually a physical port, with VPI 0) or the port
9114 * login to Name Server for State Change Request (SCR) will be performed
9115 * on virtual port (real virtual port, with VPI greater than 0).
9118 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9120 struct lpfc_vport *vport = pmb->vport;
9121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9122 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9123 MAILBOX_t *mb = &pmb->u.mb;
9126 spin_lock_irq(shost->host_lock);
9127 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9128 spin_unlock_irq(shost->host_lock);
9130 if (mb->mbxStatus) {
9131 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9132 "0915 Register VPI failed : Status: x%x"
9133 " upd bit: x%x \n", mb->mbxStatus,
9134 mb->un.varRegVpi.upd);
9135 if (phba->sli_rev == LPFC_SLI_REV4 &&
9136 mb->un.varRegVpi.upd)
9137 goto mbox_err_exit ;
9139 switch (mb->mbxStatus) {
9140 case 0x11: /* unsupported feature */
9141 case 0x9603: /* max_vpi exceeded */
9142 case 0x9602: /* Link event since CLEAR_LA */
9143 /* giving up on vport registration */
9144 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9145 spin_lock_irq(shost->host_lock);
9146 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9147 spin_unlock_irq(shost->host_lock);
9148 lpfc_can_disctmo(vport);
9150 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9152 spin_lock_irq(shost->host_lock);
9153 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9154 spin_unlock_irq(shost->host_lock);
9155 lpfc_init_vpi(phba, pmb, vport->vpi);
9157 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9158 rc = lpfc_sli_issue_mbox(phba, pmb,
9160 if (rc == MBX_NOT_FINISHED) {
9161 lpfc_printf_vlog(vport, KERN_ERR,
9163 "2732 Failed to issue INIT_VPI"
9164 " mailbox command\n");
9171 /* Try to recover from this error */
9172 if (phba->sli_rev == LPFC_SLI_REV4)
9173 lpfc_sli4_unreg_all_rpis(vport);
9174 lpfc_mbx_unreg_vpi(vport);
9175 spin_lock_irq(shost->host_lock);
9176 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9177 spin_unlock_irq(shost->host_lock);
9178 if (mb->mbxStatus == MBX_NOT_FINISHED)
9180 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9181 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9182 if (phba->sli_rev == LPFC_SLI_REV4)
9183 lpfc_issue_init_vfi(vport);
9185 lpfc_initial_flogi(vport);
9187 lpfc_initial_fdisc(vport);
9192 spin_lock_irq(shost->host_lock);
9193 vport->vpi_state |= LPFC_VPI_REGISTERED;
9194 spin_unlock_irq(shost->host_lock);
9195 if (vport == phba->pport) {
9196 if (phba->sli_rev < LPFC_SLI_REV4)
9197 lpfc_issue_fabric_reglogin(vport);
9200 * If the physical port is instantiated using
9201 * FDISC, do not start vport discovery.
9203 if (vport->port_state != LPFC_FDISC)
9204 lpfc_start_fdiscs(phba);
9205 lpfc_do_scr_ns_plogi(phba, vport);
9208 lpfc_do_scr_ns_plogi(phba, vport);
9211 /* Now, we decrement the ndlp reference count held for this
9216 mempool_free(pmb, phba->mbox_mem_pool);
9221 * lpfc_register_new_vport - Register a new vport with a HBA
9222 * @phba: pointer to lpfc hba data structure.
9223 * @vport: pointer to a host virtual N_Port data structure.
9224 * @ndlp: pointer to a node-list data structure.
9226 * This routine registers the @vport as a new virtual port with a HBA.
9227 * It is done through a registering vpi mailbox command.
9230 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9231 struct lpfc_nodelist *ndlp)
9233 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9236 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9238 lpfc_reg_vpi(vport, mbox);
9239 mbox->vport = vport;
9240 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9241 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9242 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9243 == MBX_NOT_FINISHED) {
9244 /* mailbox command not success, decrement ndlp
9245 * reference count for this command
9248 mempool_free(mbox, phba->mbox_mem_pool);
9250 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9251 "0253 Register VPI: Can't send mbox\n");
9255 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9256 "0254 Register VPI: no memory\n");
9262 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9263 spin_lock_irq(shost->host_lock);
9264 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9265 spin_unlock_irq(shost->host_lock);
9270 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9271 * @phba: pointer to lpfc hba data structure.
9273 * This routine cancels the retry delay timers to all the vports.
9276 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9278 struct lpfc_vport **vports;
9279 struct lpfc_nodelist *ndlp;
9280 uint32_t link_state;
9283 /* Treat this failure as linkdown for all vports */
9284 link_state = phba->link_state;
9285 lpfc_linkdown(phba);
9286 phba->link_state = link_state;
9288 vports = lpfc_create_vport_work_array(phba);
9291 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9292 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9294 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9295 lpfc_els_flush_cmd(vports[i]);
9297 lpfc_destroy_vport_work_array(phba, vports);
9302 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9303 * @phba: pointer to lpfc hba data structure.
9305 * This routine abort all pending discovery commands and
9306 * start a timer to retry FLOGI for the physical port
9310 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9312 struct lpfc_nodelist *ndlp;
9313 struct Scsi_Host *shost;
9315 /* Cancel the all vports retry delay retry timers */
9316 lpfc_cancel_all_vport_retry_delay_timer(phba);
9318 /* If fabric require FLOGI, then re-instantiate physical login */
9319 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9323 shost = lpfc_shost_from_vport(phba->pport);
9324 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9325 spin_lock_irq(shost->host_lock);
9326 ndlp->nlp_flag |= NLP_DELAY_TMO;
9327 spin_unlock_irq(shost->host_lock);
9328 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9329 phba->pport->port_state = LPFC_FLOGI;
9334 * lpfc_fabric_login_reqd - Check if FLOGI required.
9335 * @phba: pointer to lpfc hba data structure.
9336 * @cmdiocb: pointer to FDISC command iocb.
9337 * @rspiocb: pointer to FDISC response iocb.
9339 * This routine checks if a FLOGI is reguired for FDISC
9343 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9344 struct lpfc_iocbq *cmdiocb,
9345 struct lpfc_iocbq *rspiocb)
9348 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9349 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9356 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9357 * @phba: pointer to lpfc hba data structure.
9358 * @cmdiocb: pointer to lpfc command iocb data structure.
9359 * @rspiocb: pointer to lpfc response iocb data structure.
9361 * This routine is the completion callback function to a Fabric Discover
9362 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9363 * single threaded, each FDISC completion callback function will reset
9364 * the discovery timer for all vports such that the timers will not get
9365 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9366 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9367 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9368 * assigned to the vport has been changed with the completion of the FDISC
9369 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9370 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9371 * routine is invoked to register new vport with the HBA. Otherwise, the
9372 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9373 * Server for State Change Request (SCR).
9376 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9377 struct lpfc_iocbq *rspiocb)
9379 struct lpfc_vport *vport = cmdiocb->vport;
9380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9381 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9382 struct lpfc_nodelist *np;
9383 struct lpfc_nodelist *next_np;
9384 IOCB_t *irsp = &rspiocb->iocb;
9385 struct lpfc_iocbq *piocb;
9386 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9387 struct serv_parm *sp;
9388 uint8_t fabric_param_changed;
9390 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9391 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9392 irsp->ulpStatus, irsp->un.ulpWord[4],
9394 /* Since all FDISCs are being single threaded, we
9395 * must reset the discovery timer for ALL vports
9396 * waiting to send FDISC when one completes.
9398 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9399 lpfc_set_disctmo(piocb->vport);
9402 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9403 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9404 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9406 if (irsp->ulpStatus) {
9408 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9409 lpfc_retry_pport_discovery(phba);
9413 /* Check for retry */
9414 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9417 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9418 "0126 FDISC failed. (x%x/x%x)\n",
9419 irsp->ulpStatus, irsp->un.ulpWord[4]);
9422 spin_lock_irq(shost->host_lock);
9423 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9424 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9425 vport->fc_flag |= FC_FABRIC;
9426 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9427 vport->fc_flag |= FC_PUBLIC_LOOP;
9428 spin_unlock_irq(shost->host_lock);
9430 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9431 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9432 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9435 sp = prsp->virt + sizeof(uint32_t);
9436 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9437 memcpy(&vport->fabric_portname, &sp->portName,
9438 sizeof(struct lpfc_name));
9439 memcpy(&vport->fabric_nodename, &sp->nodeName,
9440 sizeof(struct lpfc_name));
9441 if (fabric_param_changed &&
9442 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9443 /* If our NportID changed, we need to ensure all
9444 * remaining NPORTs get unreg_login'ed so we can
9447 list_for_each_entry_safe(np, next_np,
9448 &vport->fc_nodes, nlp_listp) {
9449 if (!NLP_CHK_NODE_ACT(ndlp) ||
9450 (np->nlp_state != NLP_STE_NPR_NODE) ||
9451 !(np->nlp_flag & NLP_NPR_ADISC))
9453 spin_lock_irq(shost->host_lock);
9454 np->nlp_flag &= ~NLP_NPR_ADISC;
9455 spin_unlock_irq(shost->host_lock);
9456 lpfc_unreg_rpi(vport, np);
9458 lpfc_cleanup_pending_mbox(vport);
9460 if (phba->sli_rev == LPFC_SLI_REV4)
9461 lpfc_sli4_unreg_all_rpis(vport);
9463 lpfc_mbx_unreg_vpi(vport);
9464 spin_lock_irq(shost->host_lock);
9465 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9466 if (phba->sli_rev == LPFC_SLI_REV4)
9467 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9469 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9470 spin_unlock_irq(shost->host_lock);
9471 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9472 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9474 * Driver needs to re-reg VPI in order for f/w
9475 * to update the MAC address.
9477 lpfc_register_new_vport(phba, vport, ndlp);
9481 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9482 lpfc_issue_init_vpi(vport);
9483 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9484 lpfc_register_new_vport(phba, vport, ndlp);
9486 lpfc_do_scr_ns_plogi(phba, vport);
9489 if (vport->fc_vport &&
9490 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9491 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9492 /* Cancel discovery timer */
9493 lpfc_can_disctmo(vport);
9496 lpfc_els_free_iocb(phba, cmdiocb);
9500 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9501 * @vport: pointer to a virtual N_Port data structure.
9502 * @ndlp: pointer to a node-list data structure.
9503 * @retry: number of retries to the command IOCB.
9505 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9506 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9507 * routine to issue the IOCB, which makes sure only one outstanding fabric
9508 * IOCB will be sent off HBA at any given time.
9510 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9511 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9512 * will be stored into the context1 field of the IOCB for the completion
9513 * callback function to the FDISC ELS command.
9516 * 0 - Successfully issued fdisc iocb command
9517 * 1 - Failed to issue fdisc iocb command
9520 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9523 struct lpfc_hba *phba = vport->phba;
9525 struct lpfc_iocbq *elsiocb;
9526 struct serv_parm *sp;
9529 int did = ndlp->nlp_DID;
9532 vport->port_state = LPFC_FDISC;
9533 vport->fc_myDID = 0;
9534 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9535 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9538 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9539 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9540 "0255 Issue FDISC: no IOCB\n");
9544 icmd = &elsiocb->iocb;
9545 icmd->un.elsreq64.myID = 0;
9546 icmd->un.elsreq64.fl = 1;
9549 * SLI3 ports require a different context type value than SLI4.
9550 * Catch SLI3 ports here and override the prep.
9552 if (phba->sli_rev == LPFC_SLI_REV3) {
9557 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9558 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9559 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9560 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9561 sp = (struct serv_parm *) pcmd;
9562 /* Setup CSPs accordingly for Fabric */
9563 sp->cmn.e_d_tov = 0;
9564 sp->cmn.w2.r_a_tov = 0;
9565 sp->cmn.virtual_fabric_support = 0;
9566 sp->cls1.classValid = 0;
9567 sp->cls2.seqDelivery = 1;
9568 sp->cls3.seqDelivery = 1;
9570 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9571 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9572 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9573 pcmd += sizeof(uint32_t); /* Port Name */
9574 memcpy(pcmd, &vport->fc_portname, 8);
9575 pcmd += sizeof(uint32_t); /* Node Name */
9576 pcmd += sizeof(uint32_t); /* Node Name */
9577 memcpy(pcmd, &vport->fc_nodename, 8);
9578 sp->cmn.valid_vendor_ver_level = 0;
9579 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9580 lpfc_set_disctmo(vport);
9582 phba->fc_stat.elsXmitFDISC++;
9583 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9586 "Issue FDISC: did:x%x",
9589 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9590 if (rc == IOCB_ERROR) {
9591 lpfc_els_free_iocb(phba, elsiocb);
9592 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9593 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9594 "0256 Issue FDISC: Cannot send IOCB\n");
9597 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9602 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9603 * @phba: pointer to lpfc hba data structure.
9604 * @cmdiocb: pointer to lpfc command iocb data structure.
9605 * @rspiocb: pointer to lpfc response iocb data structure.
9607 * This routine is the completion callback function to the issuing of a LOGO
9608 * ELS command off a vport. It frees the command IOCB and then decrement the
9609 * reference count held on ndlp for this completion function, indicating that
9610 * the reference to the ndlp is no long needed. Note that the
9611 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9612 * callback function and an additional explicit ndlp reference decrementation
9613 * will trigger the actual release of the ndlp.
9616 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9617 struct lpfc_iocbq *rspiocb)
9619 struct lpfc_vport *vport = cmdiocb->vport;
9621 struct lpfc_nodelist *ndlp;
9622 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9624 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9625 irsp = &rspiocb->iocb;
9626 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9627 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9628 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9630 lpfc_els_free_iocb(phba, cmdiocb);
9631 vport->unreg_vpi_cmpl = VPORT_ERROR;
9633 /* Trigger the release of the ndlp after logo */
9636 /* NPIV LOGO completes to NPort <nlp_DID> */
9637 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9638 "2928 NPIV LOGO completes to NPort x%x "
9639 "Data: x%x x%x x%x x%x\n",
9640 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9641 irsp->ulpTimeout, vport->num_disc_nodes);
9643 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9644 spin_lock_irq(shost->host_lock);
9645 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9646 vport->fc_flag &= ~FC_FABRIC;
9647 spin_unlock_irq(shost->host_lock);
9648 lpfc_can_disctmo(vport);
9653 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9654 * @vport: pointer to a virtual N_Port data structure.
9655 * @ndlp: pointer to a node-list data structure.
9657 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9659 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9660 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9661 * will be stored into the context1 field of the IOCB for the completion
9662 * callback function to the LOGO ELS command.
9665 * 0 - Successfully issued logo off the @vport
9666 * 1 - Failed to issue logo off the @vport
9669 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9672 struct lpfc_hba *phba = vport->phba;
9673 struct lpfc_iocbq *elsiocb;
9677 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9678 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9683 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9684 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9685 pcmd += sizeof(uint32_t);
9687 /* Fill in LOGO payload */
9688 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9689 pcmd += sizeof(uint32_t);
9690 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9692 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9693 "Issue LOGO npiv did:x%x flg:x%x",
9694 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9696 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9697 spin_lock_irq(shost->host_lock);
9698 ndlp->nlp_flag |= NLP_LOGO_SND;
9699 spin_unlock_irq(shost->host_lock);
9700 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9702 spin_lock_irq(shost->host_lock);
9703 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9704 spin_unlock_irq(shost->host_lock);
9705 lpfc_els_free_iocb(phba, elsiocb);
9712 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9713 * @t: timer context used to obtain the lpfc hba.
9715 * This routine is invoked by the fabric iocb block timer after
9716 * timeout. It posts the fabric iocb block timeout event by setting the
9717 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9718 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9719 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9720 * posted event WORKER_FABRIC_BLOCK_TMO.
9723 lpfc_fabric_block_timeout(struct timer_list *t)
9725 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9726 unsigned long iflags;
9727 uint32_t tmo_posted;
9729 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9730 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9732 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9733 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9736 lpfc_worker_wake_up(phba);
9741 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9742 * @phba: pointer to lpfc hba data structure.
9744 * This routine issues one fabric iocb from the driver internal list to
9745 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9746 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9747 * remove one pending fabric iocb from the driver internal list and invokes
9748 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9751 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9753 struct lpfc_iocbq *iocb;
9754 unsigned long iflags;
9760 spin_lock_irqsave(&phba->hbalock, iflags);
9761 /* Post any pending iocb to the SLI layer */
9762 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9763 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9766 /* Increment fabric iocb count to hold the position */
9767 atomic_inc(&phba->fabric_iocb_count);
9769 spin_unlock_irqrestore(&phba->hbalock, iflags);
9771 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9772 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9773 iocb->iocb_flag |= LPFC_IO_FABRIC;
9775 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9776 "Fabric sched1: ste:x%x",
9777 iocb->vport->port_state, 0, 0);
9779 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9781 if (ret == IOCB_ERROR) {
9782 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9783 iocb->fabric_iocb_cmpl = NULL;
9784 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9786 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9787 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9788 iocb->iocb_cmpl(phba, iocb, iocb);
9790 atomic_dec(&phba->fabric_iocb_count);
9799 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9800 * @phba: pointer to lpfc hba data structure.
9802 * This routine unblocks the issuing fabric iocb command. The function
9803 * will clear the fabric iocb block bit and then invoke the routine
9804 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9805 * from the driver internal fabric iocb list.
9808 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9810 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9812 lpfc_resume_fabric_iocbs(phba);
9817 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9818 * @phba: pointer to lpfc hba data structure.
9820 * This routine blocks the issuing fabric iocb for a specified amount of
9821 * time (currently 100 ms). This is done by set the fabric iocb block bit
9822 * and set up a timeout timer for 100ms. When the block bit is set, no more
9823 * fabric iocb will be issued out of the HBA.
9826 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9830 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9831 /* Start a timer to unblock fabric iocbs after 100ms */
9833 mod_timer(&phba->fabric_block_timer,
9834 jiffies + msecs_to_jiffies(100));
9840 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9841 * @phba: pointer to lpfc hba data structure.
9842 * @cmdiocb: pointer to lpfc command iocb data structure.
9843 * @rspiocb: pointer to lpfc response iocb data structure.
9845 * This routine is the callback function that is put to the fabric iocb's
9846 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9847 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9848 * function first restores and invokes the original iocb's callback function
9849 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9850 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9853 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9854 struct lpfc_iocbq *rspiocb)
9858 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9860 switch (rspiocb->iocb.ulpStatus) {
9861 case IOSTAT_NPORT_RJT:
9862 case IOSTAT_FABRIC_RJT:
9863 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9864 lpfc_block_fabric_iocbs(phba);
9868 case IOSTAT_NPORT_BSY:
9869 case IOSTAT_FABRIC_BSY:
9870 lpfc_block_fabric_iocbs(phba);
9874 stat.un.lsRjtError =
9875 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9876 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9877 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9878 lpfc_block_fabric_iocbs(phba);
9882 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9884 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9885 cmdiocb->fabric_iocb_cmpl = NULL;
9886 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9887 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9889 atomic_dec(&phba->fabric_iocb_count);
9890 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9891 /* Post any pending iocbs to HBA */
9892 lpfc_resume_fabric_iocbs(phba);
9897 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9898 * @phba: pointer to lpfc hba data structure.
9899 * @iocb: pointer to lpfc command iocb data structure.
9901 * This routine is used as the top-level API for issuing a fabric iocb command
9902 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9903 * function makes sure that only one fabric bound iocb will be outstanding at
9904 * any given time. As such, this function will first check to see whether there
9905 * is already an outstanding fabric iocb on the wire. If so, it will put the
9906 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9907 * issued later. Otherwise, it will issue the iocb on the wire and update the
9908 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9910 * Note, this implementation has a potential sending out fabric IOCBs out of
9911 * order. The problem is caused by the construction of the "ready" boolen does
9912 * not include the condition that the internal fabric IOCB list is empty. As
9913 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9914 * ahead of the fabric IOCBs in the internal list.
9917 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9918 * IOCB_ERROR - failed to issue fabric iocb
9921 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9923 unsigned long iflags;
9927 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9929 spin_lock_irqsave(&phba->hbalock, iflags);
9930 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9931 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9934 /* Increment fabric iocb count to hold the position */
9935 atomic_inc(&phba->fabric_iocb_count);
9936 spin_unlock_irqrestore(&phba->hbalock, iflags);
9938 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9939 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9940 iocb->iocb_flag |= LPFC_IO_FABRIC;
9942 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9943 "Fabric sched2: ste:x%x",
9944 iocb->vport->port_state, 0, 0);
9946 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9948 if (ret == IOCB_ERROR) {
9949 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9950 iocb->fabric_iocb_cmpl = NULL;
9951 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9952 atomic_dec(&phba->fabric_iocb_count);
9955 spin_lock_irqsave(&phba->hbalock, iflags);
9956 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9957 spin_unlock_irqrestore(&phba->hbalock, iflags);
9964 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9965 * @vport: pointer to a virtual N_Port data structure.
9967 * This routine aborts all the IOCBs associated with a @vport from the
9968 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9969 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9970 * list, removes each IOCB associated with the @vport off the list, set the
9971 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9972 * associated with the IOCB.
9974 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9976 LIST_HEAD(completions);
9977 struct lpfc_hba *phba = vport->phba;
9978 struct lpfc_iocbq *tmp_iocb, *piocb;
9980 spin_lock_irq(&phba->hbalock);
9981 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9984 if (piocb->vport != vport)
9987 list_move_tail(&piocb->list, &completions);
9989 spin_unlock_irq(&phba->hbalock);
9991 /* Cancel all the IOCBs from the completions list */
9992 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9997 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9998 * @ndlp: pointer to a node-list data structure.
10000 * This routine aborts all the IOCBs associated with an @ndlp from the
10001 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10002 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10003 * list, removes each IOCB associated with the @ndlp off the list, set the
10004 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10005 * associated with the IOCB.
10007 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10009 LIST_HEAD(completions);
10010 struct lpfc_hba *phba = ndlp->phba;
10011 struct lpfc_iocbq *tmp_iocb, *piocb;
10012 struct lpfc_sli_ring *pring;
10014 pring = lpfc_phba_elsring(phba);
10016 if (unlikely(!pring))
10019 spin_lock_irq(&phba->hbalock);
10020 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10022 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10024 list_move_tail(&piocb->list, &completions);
10027 spin_unlock_irq(&phba->hbalock);
10029 /* Cancel all the IOCBs from the completions list */
10030 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10031 IOERR_SLI_ABORTED);
10035 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
10036 * @phba: pointer to lpfc hba data structure.
10038 * This routine aborts all the IOCBs currently on the driver internal
10039 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10040 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10041 * list, removes IOCBs off the list, set the status feild to
10042 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10045 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10047 LIST_HEAD(completions);
10049 spin_lock_irq(&phba->hbalock);
10050 list_splice_init(&phba->fabric_iocb_list, &completions);
10051 spin_unlock_irq(&phba->hbalock);
10053 /* Cancel all the IOCBs from the completions list */
10054 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10055 IOERR_SLI_ABORTED);
10059 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10060 * @vport: pointer to lpfc vport data structure.
10062 * This routine is invoked by the vport cleanup for deletions and the cleanup
10063 * for an ndlp on removal.
10066 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10068 struct lpfc_hba *phba = vport->phba;
10069 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10070 unsigned long iflag = 0;
10072 spin_lock_irqsave(&phba->hbalock, iflag);
10073 spin_lock(&phba->sli4_hba.sgl_list_lock);
10074 list_for_each_entry_safe(sglq_entry, sglq_next,
10075 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10076 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
10077 sglq_entry->ndlp = NULL;
10079 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10080 spin_unlock_irqrestore(&phba->hbalock, iflag);
10085 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10086 * @phba: pointer to lpfc hba data structure.
10087 * @axri: pointer to the els xri abort wcqe structure.
10089 * This routine is invoked by the worker thread to process a SLI4 slow-path
10093 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10094 struct sli4_wcqe_xri_aborted *axri)
10096 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10097 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10100 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10101 unsigned long iflag = 0;
10102 struct lpfc_nodelist *ndlp;
10103 struct lpfc_sli_ring *pring;
10105 pring = lpfc_phba_elsring(phba);
10107 spin_lock_irqsave(&phba->hbalock, iflag);
10108 spin_lock(&phba->sli4_hba.sgl_list_lock);
10109 list_for_each_entry_safe(sglq_entry, sglq_next,
10110 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10111 if (sglq_entry->sli4_xritag == xri) {
10112 list_del(&sglq_entry->list);
10113 ndlp = sglq_entry->ndlp;
10114 sglq_entry->ndlp = NULL;
10115 list_add_tail(&sglq_entry->list,
10116 &phba->sli4_hba.lpfc_els_sgl_list);
10117 sglq_entry->state = SGL_FREED;
10118 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10119 spin_unlock_irqrestore(&phba->hbalock, iflag);
10120 lpfc_set_rrq_active(phba, ndlp,
10121 sglq_entry->sli4_lxritag,
10124 /* Check if TXQ queue needs to be serviced */
10125 if (pring && !list_empty(&pring->txq))
10126 lpfc_worker_wake_up(phba);
10130 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10131 lxri = lpfc_sli4_xri_inrange(phba, xri);
10132 if (lxri == NO_XRI) {
10133 spin_unlock_irqrestore(&phba->hbalock, iflag);
10136 spin_lock(&phba->sli4_hba.sgl_list_lock);
10137 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10138 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10139 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10140 spin_unlock_irqrestore(&phba->hbalock, iflag);
10143 sglq_entry->state = SGL_XRI_ABORTED;
10144 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10145 spin_unlock_irqrestore(&phba->hbalock, iflag);
10149 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10150 * @vport: pointer to virtual port object.
10151 * @ndlp: nodelist pointer for the impacted node.
10153 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10154 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10155 * the driver is required to send a LOGO to the remote node before it
10156 * attempts to recover its login to the remote node.
10159 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10160 struct lpfc_nodelist *ndlp)
10162 struct Scsi_Host *shost;
10163 struct lpfc_hba *phba;
10164 unsigned long flags = 0;
10166 shost = lpfc_shost_from_vport(vport);
10167 phba = vport->phba;
10168 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10169 lpfc_printf_log(phba, KERN_INFO,
10170 LOG_SLI, "3093 No rport recovery needed. "
10171 "rport in state 0x%x\n", ndlp->nlp_state);
10174 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10175 "3094 Start rport recovery on shost id 0x%x "
10176 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10178 shost->host_no, ndlp->nlp_DID,
10179 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10182 * The rport is not responding. Remove the FCP-2 flag to prevent
10183 * an ADISC in the follow-up recovery code.
10185 spin_lock_irqsave(shost->host_lock, flags);
10186 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10187 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10188 spin_unlock_irqrestore(shost->host_lock, flags);
10189 lpfc_unreg_rpi(vport, ndlp);