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);
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);
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 ((np->nlp_state != NLP_STE_NPR_NODE) ||
769 !(np->nlp_flag & NLP_NPR_ADISC))
771 spin_lock_irq(shost->host_lock);
772 np->nlp_flag &= ~NLP_NPR_ADISC;
773 spin_unlock_irq(shost->host_lock);
774 lpfc_unreg_rpi(vport, np);
776 lpfc_cleanup_pending_mbox(vport);
778 if (phba->sli_rev == LPFC_SLI_REV4) {
779 lpfc_sli4_unreg_all_rpis(vport);
780 lpfc_mbx_unreg_vpi(vport);
781 spin_lock_irq(shost->host_lock);
782 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
783 spin_unlock_irq(shost->host_lock);
787 * For SLI3 and SLI4, the VPI needs to be reregistered in
788 * response to this fabric parameter change event.
790 spin_lock_irq(shost->host_lock);
791 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
792 spin_unlock_irq(shost->host_lock);
793 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
794 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
796 * Driver needs to re-reg VPI in order for f/w
797 * to update the MAC address.
799 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
800 lpfc_register_new_vport(phba, vport, ndlp);
804 if (phba->sli_rev < LPFC_SLI_REV4) {
805 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
806 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
807 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
808 lpfc_register_new_vport(phba, vport, ndlp);
810 lpfc_issue_fabric_reglogin(vport);
812 ndlp->nlp_type |= NLP_FABRIC;
813 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
814 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
815 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
816 lpfc_start_fdiscs(phba);
817 lpfc_do_scr_ns_plogi(phba, vport);
818 } else if (vport->fc_flag & FC_VFI_REGISTERED)
819 lpfc_issue_init_vpi(vport);
821 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
822 "3135 Need register VFI: (x%x/%x)\n",
823 vport->fc_prevDID, vport->fc_myDID);
824 lpfc_issue_reg_vfi(vport);
831 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
832 * @vport: pointer to a host virtual N_Port data structure.
833 * @ndlp: pointer to a node-list data structure.
834 * @sp: pointer to service parameter data structure.
836 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
837 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
838 * in a point-to-point topology. First, the @vport's N_Port Name is compared
839 * with the received N_Port Name: if the @vport's N_Port Name is greater than
840 * the received N_Port Name lexicographically, this node shall assign local
841 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
842 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
843 * this node shall just wait for the remote node to issue PLOGI and assign
851 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
852 struct serv_parm *sp)
854 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
855 struct lpfc_hba *phba = vport->phba;
859 spin_lock_irq(shost->host_lock);
860 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
861 vport->fc_flag |= FC_PT2PT;
862 spin_unlock_irq(shost->host_lock);
864 /* If we are pt2pt with another NPort, force NPIV off! */
865 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
867 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
868 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
869 lpfc_unregister_fcf_prep(phba);
871 spin_lock_irq(shost->host_lock);
872 vport->fc_flag &= ~FC_VFI_REGISTERED;
873 spin_unlock_irq(shost->host_lock);
874 phba->fc_topology_changed = 0;
877 rc = memcmp(&vport->fc_portname, &sp->portName,
878 sizeof(vport->fc_portname));
881 /* This side will initiate the PLOGI */
882 spin_lock_irq(shost->host_lock);
883 vport->fc_flag |= FC_PT2PT_PLOGI;
884 spin_unlock_irq(shost->host_lock);
887 * N_Port ID cannot be 0, set our Id to LocalID
888 * the other side will be RemoteID.
893 vport->fc_myDID = PT2PT_LocalID;
895 /* Decrement ndlp reference count indicating that ndlp can be
896 * safely released when other references to it are done.
900 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
903 * Cannot find existing Fabric ndlp, so allocate a
906 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
911 memcpy(&ndlp->nlp_portname, &sp->portName,
912 sizeof(struct lpfc_name));
913 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
914 sizeof(struct lpfc_name));
915 /* Set state will put ndlp onto node list if not already done */
916 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
917 spin_lock_irq(shost->host_lock);
918 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
919 spin_unlock_irq(shost->host_lock);
921 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
925 lpfc_config_link(phba, mbox);
927 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
929 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
930 if (rc == MBX_NOT_FINISHED) {
931 mempool_free(mbox, phba->mbox_mem_pool);
935 /* This side will wait for the PLOGI, decrement ndlp reference
936 * count indicating that ndlp can be released when other
937 * references to it are done.
941 /* Start discovery - this should just do CLEAR_LA */
942 lpfc_disc_start(vport);
951 * lpfc_cmpl_els_flogi - Completion callback function for flogi
952 * @phba: pointer to lpfc hba data structure.
953 * @cmdiocb: pointer to lpfc command iocb data structure.
954 * @rspiocb: pointer to lpfc response iocb data structure.
956 * This routine is the top-level completion callback function for issuing
957 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
958 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
959 * retry has been made (either immediately or delayed with lpfc_els_retry()
960 * returning 1), the command IOCB will be released and function returned.
961 * If the retry attempt has been given up (possibly reach the maximum
962 * number of retries), one additional decrement of ndlp reference shall be
963 * invoked before going out after releasing the command IOCB. This will
964 * actually release the remote node (Note, lpfc_els_free_iocb() will also
965 * invoke one decrement of ndlp reference count). If no error reported in
966 * the IOCB status, the command Port ID field is used to determine whether
967 * this is a point-to-point topology or a fabric topology: if the Port ID
968 * field is assigned, it is a fabric topology; otherwise, it is a
969 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
970 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
971 * specific topology completion conditions.
974 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
975 struct lpfc_iocbq *rspiocb)
977 struct lpfc_vport *vport = cmdiocb->vport;
978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
979 IOCB_t *irsp = &rspiocb->iocb;
980 struct lpfc_nodelist *ndlp = cmdiocb->context1;
981 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
982 struct serv_parm *sp;
986 /* Check to see if link went down during discovery */
987 if (lpfc_els_chk_latt(vport)) {
988 /* One additional decrement on node reference count to
989 * trigger the release of the node
995 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
996 "FLOGI cmpl: status:x%x/x%x state:x%x",
997 irsp->ulpStatus, irsp->un.ulpWord[4],
1000 if (irsp->ulpStatus) {
1002 * In case of FIP mode, perform roundrobin FCF failover
1003 * due to new FCF discovery
1005 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1006 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1007 if (phba->link_state < LPFC_LINK_UP)
1008 goto stop_rr_fcf_flogi;
1009 if ((phba->fcoe_cvl_eventtag_attn ==
1010 phba->fcoe_cvl_eventtag) &&
1011 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1012 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1014 goto stop_rr_fcf_flogi;
1016 phba->fcoe_cvl_eventtag_attn =
1017 phba->fcoe_cvl_eventtag;
1018 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1019 "2611 FLOGI failed on FCF (x%x), "
1020 "status:x%x/x%x, tmo:x%x, perform "
1021 "roundrobin FCF failover\n",
1022 phba->fcf.current_rec.fcf_indx,
1023 irsp->ulpStatus, irsp->un.ulpWord[4],
1025 lpfc_sli4_set_fcf_flogi_fail(phba,
1026 phba->fcf.current_rec.fcf_indx);
1027 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1028 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1035 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1036 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1037 IOERR_LOOP_OPEN_FAILURE)))
1038 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1039 "2858 FLOGI failure Status:x%x/x%x TMO"
1040 ":x%x Data x%x x%x\n",
1041 irsp->ulpStatus, irsp->un.ulpWord[4],
1042 irsp->ulpTimeout, phba->hba_flag,
1043 phba->fcf.fcf_flag);
1045 /* Check for retry */
1046 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1049 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1050 "0150 FLOGI failure Status:x%x/x%x "
1051 "xri x%x TMO:x%x\n",
1052 irsp->ulpStatus, irsp->un.ulpWord[4],
1053 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1055 /* If this is not a loop open failure, bail out */
1056 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1057 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1058 IOERR_LOOP_OPEN_FAILURE)))
1061 /* FLOGI failed, so there is no fabric */
1062 spin_lock_irq(shost->host_lock);
1063 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1064 spin_unlock_irq(shost->host_lock);
1066 /* If private loop, then allow max outstanding els to be
1067 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1068 * alpa map would take too long otherwise.
1070 if (phba->alpa_map[0] == 0)
1071 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1072 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1073 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1074 (vport->fc_prevDID != vport->fc_myDID) ||
1075 phba->fc_topology_changed)) {
1076 if (vport->fc_flag & FC_VFI_REGISTERED) {
1077 if (phba->fc_topology_changed) {
1078 lpfc_unregister_fcf_prep(phba);
1079 spin_lock_irq(shost->host_lock);
1080 vport->fc_flag &= ~FC_VFI_REGISTERED;
1081 spin_unlock_irq(shost->host_lock);
1082 phba->fc_topology_changed = 0;
1084 lpfc_sli4_unreg_all_rpis(vport);
1088 /* Do not register VFI if the driver aborted FLOGI */
1089 if (!lpfc_error_lost_link(irsp))
1090 lpfc_issue_reg_vfi(vport);
1096 spin_lock_irq(shost->host_lock);
1097 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1098 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1099 spin_unlock_irq(shost->host_lock);
1102 * The FLogI succeeded. Sync the data for the CPU before
1105 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1108 sp = prsp->virt + sizeof(uint32_t);
1110 /* FLOGI completes successfully */
1111 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1112 "0101 FLOGI completes successfully, I/O tag:x%x, "
1113 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1114 cmdiocb->iotag, cmdiocb->sli4_xritag,
1115 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1116 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1117 vport->port_state, vport->fc_flag);
1119 if (vport->port_state == LPFC_FLOGI) {
1121 * If Common Service Parameters indicate Nport
1122 * we are point to point, if Fport we are Fabric.
1125 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1126 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1127 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1129 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1130 "2831 FLOGI response with cleared Fabric "
1131 "bit fcf_index 0x%x "
1132 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1134 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1135 phba->fcf.current_rec.fcf_indx,
1136 phba->fcf.current_rec.switch_name[0],
1137 phba->fcf.current_rec.switch_name[1],
1138 phba->fcf.current_rec.switch_name[2],
1139 phba->fcf.current_rec.switch_name[3],
1140 phba->fcf.current_rec.switch_name[4],
1141 phba->fcf.current_rec.switch_name[5],
1142 phba->fcf.current_rec.switch_name[6],
1143 phba->fcf.current_rec.switch_name[7],
1144 phba->fcf.current_rec.fabric_name[0],
1145 phba->fcf.current_rec.fabric_name[1],
1146 phba->fcf.current_rec.fabric_name[2],
1147 phba->fcf.current_rec.fabric_name[3],
1148 phba->fcf.current_rec.fabric_name[4],
1149 phba->fcf.current_rec.fabric_name[5],
1150 phba->fcf.current_rec.fabric_name[6],
1151 phba->fcf.current_rec.fabric_name[7]);
1153 spin_lock_irq(&phba->hbalock);
1154 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1155 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1156 spin_unlock_irq(&phba->hbalock);
1157 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1161 /* Mark the FCF discovery process done */
1162 if (phba->hba_flag & HBA_FIP_SUPPORT)
1163 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1165 "2769 FLOGI to FCF (x%x) "
1166 "completed successfully\n",
1167 phba->fcf.current_rec.fcf_indx);
1168 spin_lock_irq(&phba->hbalock);
1169 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1170 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1171 spin_unlock_irq(&phba->hbalock);
1172 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1178 spin_lock_irq(&phba->hbalock);
1179 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1180 spin_unlock_irq(&phba->hbalock);
1184 if (!lpfc_error_lost_link(irsp)) {
1185 /* FLOGI failed, so just use loop map to make discovery list */
1186 lpfc_disc_list_loopmap(vport);
1188 /* Start discovery */
1189 lpfc_disc_start(vport);
1190 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1191 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1192 IOERR_SLI_ABORTED) &&
1193 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1194 IOERR_SLI_DOWN))) &&
1195 (phba->link_state != LPFC_CLEAR_LA)) {
1196 /* If FLOGI failed enable link interrupt. */
1197 lpfc_issue_clear_la(phba, vport);
1200 lpfc_els_free_iocb(phba, cmdiocb);
1204 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1205 * aborted during a link down
1206 * @phba: pointer to lpfc hba data structure.
1207 * @cmdiocb: pointer to lpfc command iocb data structure.
1208 * @rspiocb: pointer to lpfc response iocb data structure.
1212 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1213 struct lpfc_iocbq *rspiocb)
1219 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1221 irsp = &rspiocb->iocb;
1223 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1224 "6445 ELS completes after LINK_DOWN: "
1225 " Status %x/%x cmd x%x flg x%x\n",
1226 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1227 cmdiocb->iocb_flag);
1229 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1230 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1231 atomic_dec(&phba->fabric_iocb_count);
1233 lpfc_els_free_iocb(phba, cmdiocb);
1237 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1238 * @vport: pointer to a host virtual N_Port data structure.
1239 * @ndlp: pointer to a node-list data structure.
1240 * @retry: number of retries to the command IOCB.
1242 * This routine issues a Fabric Login (FLOGI) Request ELS command
1243 * for a @vport. The initiator service parameters are put into the payload
1244 * of the FLOGI Request IOCB and the top-level callback function pointer
1245 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1246 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1247 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1249 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1250 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1251 * will be stored into the context1 field of the IOCB for the completion
1252 * callback function to the FLOGI ELS command.
1255 * 0 - successfully issued flogi iocb for @vport
1256 * 1 - failed to issue flogi iocb for @vport
1259 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1262 struct lpfc_hba *phba = vport->phba;
1263 struct serv_parm *sp;
1265 struct lpfc_iocbq *elsiocb;
1266 struct lpfc_iocbq defer_flogi_acc;
1272 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1273 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1274 ndlp->nlp_DID, ELS_CMD_FLOGI);
1279 icmd = &elsiocb->iocb;
1280 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1282 /* For FLOGI request, remainder of payload is service parameters */
1283 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1284 pcmd += sizeof(uint32_t);
1285 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1286 sp = (struct serv_parm *) pcmd;
1288 /* Setup CSPs accordingly for Fabric */
1289 sp->cmn.e_d_tov = 0;
1290 sp->cmn.w2.r_a_tov = 0;
1291 sp->cmn.virtual_fabric_support = 0;
1292 sp->cls1.classValid = 0;
1293 if (sp->cmn.fcphLow < FC_PH3)
1294 sp->cmn.fcphLow = FC_PH3;
1295 if (sp->cmn.fcphHigh < FC_PH3)
1296 sp->cmn.fcphHigh = FC_PH3;
1298 if (phba->sli_rev == LPFC_SLI_REV4) {
1299 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1300 LPFC_SLI_INTF_IF_TYPE_0) {
1301 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1302 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1303 /* FLOGI needs to be 3 for WQE FCFI */
1304 /* Set the fcfi to the fcfi we registered with */
1305 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1307 /* Can't do SLI4 class2 without support sequence coalescing */
1308 sp->cls2.classValid = 0;
1309 sp->cls2.seqDelivery = 0;
1311 /* Historical, setting sequential-delivery bit for SLI3 */
1312 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1313 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1314 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1315 sp->cmn.request_multiple_Nport = 1;
1316 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1320 sp->cmn.request_multiple_Nport = 0;
1323 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1324 icmd->un.elsreq64.myID = 0;
1325 icmd->un.elsreq64.fl = 1;
1328 tmo = phba->fc_ratov;
1329 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1330 lpfc_set_disctmo(vport);
1331 phba->fc_ratov = tmo;
1333 phba->fc_stat.elsXmitFLOGI++;
1334 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1336 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1337 "Issue FLOGI: opt:x%x",
1338 phba->sli3_options, 0, 0);
1340 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1342 phba->hba_flag |= HBA_FLOGI_ISSUED;
1344 /* Check for a deferred FLOGI ACC condition */
1345 if (phba->defer_flogi_acc_flag) {
1346 did = vport->fc_myDID;
1347 vport->fc_myDID = Fabric_DID;
1349 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1351 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1352 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1353 phba->defer_flogi_acc_ox_id;
1355 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1356 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1357 " ox_id: x%x, hba_flag x%x\n",
1358 phba->defer_flogi_acc_rx_id,
1359 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1361 /* Send deferred FLOGI ACC */
1362 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1365 phba->defer_flogi_acc_flag = false;
1367 vport->fc_myDID = did;
1370 if (rc == IOCB_ERROR) {
1371 lpfc_els_free_iocb(phba, elsiocb);
1378 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1379 * @phba: pointer to lpfc hba data structure.
1381 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1382 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1383 * list and issues an abort IOCB commond on each outstanding IOCB that
1384 * contains a active Fabric_DID ndlp. Note that this function is to issue
1385 * the abort IOCB command on all the outstanding IOCBs, thus when this
1386 * function returns, it does not guarantee all the IOCBs are actually aborted.
1389 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1392 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1394 struct lpfc_sli_ring *pring;
1395 struct lpfc_iocbq *iocb, *next_iocb;
1396 struct lpfc_nodelist *ndlp;
1399 /* Abort outstanding I/O on NPort <nlp_DID> */
1400 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1401 "0201 Abort outstanding I/O on NPort x%x\n",
1404 pring = lpfc_phba_elsring(phba);
1405 if (unlikely(!pring))
1409 * Check the txcmplq for an iocb that matches the nport the driver is
1412 spin_lock_irq(&phba->hbalock);
1413 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1415 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1416 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1417 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
1418 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1421 spin_unlock_irq(&phba->hbalock);
1427 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1428 * @vport: pointer to a host virtual N_Port data structure.
1430 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1431 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1432 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1433 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1434 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1435 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1439 * 0 - failed to issue initial flogi for @vport
1440 * 1 - successfully issued initial flogi for @vport
1443 lpfc_initial_flogi(struct lpfc_vport *vport)
1445 struct lpfc_nodelist *ndlp;
1447 vport->port_state = LPFC_FLOGI;
1448 lpfc_set_disctmo(vport);
1450 /* First look for the Fabric ndlp */
1451 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1453 /* Cannot find existing Fabric ndlp, so allocate a new one */
1454 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1457 /* Set the node type */
1458 ndlp->nlp_type |= NLP_FABRIC;
1460 /* Put ndlp onto node list */
1461 lpfc_enqueue_node(vport, ndlp);
1464 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1465 /* This decrement of reference count to node shall kick off
1466 * the release of the node.
1475 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1476 * @vport: pointer to a host virtual N_Port data structure.
1478 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1479 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1480 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1481 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1482 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1483 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1487 * 0 - failed to issue initial fdisc for @vport
1488 * 1 - successfully issued initial fdisc for @vport
1491 lpfc_initial_fdisc(struct lpfc_vport *vport)
1493 struct lpfc_nodelist *ndlp;
1495 /* First look for the Fabric ndlp */
1496 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1498 /* Cannot find existing Fabric ndlp, so allocate a new one */
1499 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1502 /* Put ndlp onto node list */
1503 lpfc_enqueue_node(vport, ndlp);
1506 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1507 /* decrement node reference count to trigger the release of
1517 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1518 * @vport: pointer to a host virtual N_Port data structure.
1520 * This routine checks whether there are more remaining Port Logins
1521 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1522 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1523 * to issue ELS PLOGIs up to the configured discover threads with the
1524 * @vport (@vport->cfg_discovery_threads). The function also decrement
1525 * the @vport's num_disc_node by 1 if it is not already 0.
1528 lpfc_more_plogi(struct lpfc_vport *vport)
1530 if (vport->num_disc_nodes)
1531 vport->num_disc_nodes--;
1533 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1534 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1535 "0232 Continue discovery with %d PLOGIs to go "
1536 "Data: x%x x%x x%x\n",
1537 vport->num_disc_nodes, vport->fc_plogi_cnt,
1538 vport->fc_flag, vport->port_state);
1539 /* Check to see if there are more PLOGIs to be sent */
1540 if (vport->fc_flag & FC_NLP_MORE)
1541 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1542 lpfc_els_disc_plogi(vport);
1548 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1549 * @phba: pointer to lpfc hba data structure.
1550 * @prsp: pointer to response IOCB payload.
1551 * @ndlp: pointer to a node-list data structure.
1553 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1554 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1555 * The following cases are considered N_Port confirmed:
1556 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1557 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1558 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1559 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1560 * 1) if there is a node on vport list other than the @ndlp with the same
1561 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1562 * on that node to release the RPI associated with the node; 2) if there is
1563 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1564 * into, a new node shall be allocated (or activated). In either case, the
1565 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1566 * be released and the new_ndlp shall be put on to the vport node list and
1567 * its pointer returned as the confirmed node.
1569 * Note that before the @ndlp got "released", the keepDID from not-matching
1570 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1571 * of the @ndlp. This is because the release of @ndlp is actually to put it
1572 * into an inactive state on the vport node list and the vport node list
1573 * management algorithm does not allow two node with a same DID.
1576 * pointer to the PLOGI N_Port @ndlp
1578 static struct lpfc_nodelist *
1579 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1580 struct lpfc_nodelist *ndlp)
1582 struct lpfc_vport *vport = ndlp->vport;
1583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1584 struct lpfc_nodelist *new_ndlp;
1585 struct lpfc_rport_data *rdata;
1586 struct fc_rport *rport;
1587 struct serv_parm *sp;
1588 uint8_t name[sizeof(struct lpfc_name)];
1589 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1590 uint32_t keep_new_nlp_flag = 0;
1591 uint16_t keep_nlp_state;
1592 u32 keep_nlp_fc4_type = 0;
1593 struct lpfc_nvme_rport *keep_nrport = NULL;
1596 unsigned long *active_rrqs_xri_bitmap = NULL;
1598 /* Fabric nodes can have the same WWPN so we don't bother searching
1599 * by WWPN. Just return the ndlp that was given to us.
1601 if (ndlp->nlp_type & NLP_FABRIC)
1604 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1605 memset(name, 0, sizeof(struct lpfc_name));
1607 /* Now we find out if the NPort we are logging into, matches the WWPN
1608 * we have for that ndlp. If not, we have some work to do.
1610 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1612 /* return immediately if the WWPN matches ndlp */
1613 if (new_ndlp == ndlp)
1616 if (phba->sli_rev == LPFC_SLI_REV4) {
1617 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1619 if (active_rrqs_xri_bitmap)
1620 memset(active_rrqs_xri_bitmap, 0,
1621 phba->cfg_rrq_xri_bitmap_sz);
1624 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1625 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1626 "new_ndlp x%x x%x x%x\n",
1627 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1628 (new_ndlp ? new_ndlp->nlp_DID : 0),
1629 (new_ndlp ? new_ndlp->nlp_flag : 0),
1630 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1633 rc = memcmp(&ndlp->nlp_portname, name,
1634 sizeof(struct lpfc_name));
1636 if (active_rrqs_xri_bitmap)
1637 mempool_free(active_rrqs_xri_bitmap,
1638 phba->active_rrq_pool);
1641 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1643 if (active_rrqs_xri_bitmap)
1644 mempool_free(active_rrqs_xri_bitmap,
1645 phba->active_rrq_pool);
1649 keepDID = new_ndlp->nlp_DID;
1650 if (phba->sli_rev == LPFC_SLI_REV4 &&
1651 active_rrqs_xri_bitmap)
1652 memcpy(active_rrqs_xri_bitmap,
1653 new_ndlp->active_rrqs_xri_bitmap,
1654 phba->cfg_rrq_xri_bitmap_sz);
1657 /* At this point in this routine, we know new_ndlp will be
1658 * returned. however, any previous GID_FTs that were done
1659 * would have updated nlp_fc4_type in ndlp, so we must ensure
1660 * new_ndlp has the right value.
1662 if (vport->fc_flag & FC_FABRIC) {
1663 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1664 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1667 lpfc_unreg_rpi(vport, new_ndlp);
1668 new_ndlp->nlp_DID = ndlp->nlp_DID;
1669 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1670 if (phba->sli_rev == LPFC_SLI_REV4)
1671 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1672 ndlp->active_rrqs_xri_bitmap,
1673 phba->cfg_rrq_xri_bitmap_sz);
1675 spin_lock_irq(shost->host_lock);
1676 keep_new_nlp_flag = new_ndlp->nlp_flag;
1677 keep_nlp_flag = ndlp->nlp_flag;
1678 new_ndlp->nlp_flag = ndlp->nlp_flag;
1680 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1681 if (keep_new_nlp_flag & NLP_UNREG_INP)
1682 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1684 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1686 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1687 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1688 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1690 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1692 ndlp->nlp_flag = keep_new_nlp_flag;
1694 /* if ndlp had NLP_UNREG_INP set, keep it */
1695 if (keep_nlp_flag & NLP_UNREG_INP)
1696 ndlp->nlp_flag |= NLP_UNREG_INP;
1698 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1700 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1701 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1702 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1704 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1706 spin_unlock_irq(shost->host_lock);
1708 /* Set nlp_states accordingly */
1709 keep_nlp_state = new_ndlp->nlp_state;
1710 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1712 /* interchange the nvme remoteport structs */
1713 keep_nrport = new_ndlp->nrport;
1714 new_ndlp->nrport = ndlp->nrport;
1716 /* Move this back to NPR state */
1717 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1718 /* The new_ndlp is replacing ndlp totally, so we need
1719 * to put ndlp on UNUSED list and try to free it.
1721 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1722 "3179 PLOGI confirm NEW: %x %x\n",
1723 new_ndlp->nlp_DID, keepDID);
1725 /* Fix up the rport accordingly */
1726 rport = ndlp->rport;
1728 rdata = rport->dd_data;
1729 if (rdata->pnode == ndlp) {
1730 /* break the link before dropping the ref */
1733 rdata->pnode = lpfc_nlp_get(new_ndlp);
1734 new_ndlp->rport = rport;
1736 new_ndlp->nlp_type = ndlp->nlp_type;
1739 /* Fix up the nvme rport */
1741 ndlp->nrport = NULL;
1745 /* Two ndlps cannot have the same did on the nodelist.
1746 * Note: for this case, ndlp has a NULL WWPN so setting
1747 * the nlp_fc4_type isn't required.
1749 ndlp->nlp_DID = keepDID;
1750 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1751 if (phba->sli_rev == LPFC_SLI_REV4 &&
1752 active_rrqs_xri_bitmap)
1753 memcpy(ndlp->active_rrqs_xri_bitmap,
1754 active_rrqs_xri_bitmap,
1755 phba->cfg_rrq_xri_bitmap_sz);
1758 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1759 "3180 PLOGI confirm SWAP: %x %x\n",
1760 new_ndlp->nlp_DID, keepDID);
1762 lpfc_unreg_rpi(vport, ndlp);
1764 /* Two ndlps cannot have the same did and the fc4
1765 * type must be transferred because the ndlp is in
1768 ndlp->nlp_DID = keepDID;
1769 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1771 if (phba->sli_rev == LPFC_SLI_REV4 &&
1772 active_rrqs_xri_bitmap)
1773 memcpy(ndlp->active_rrqs_xri_bitmap,
1774 active_rrqs_xri_bitmap,
1775 phba->cfg_rrq_xri_bitmap_sz);
1777 /* Since we are switching over to the new_ndlp,
1778 * reset the old ndlp state
1780 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1781 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1782 keep_nlp_state = NLP_STE_NPR_NODE;
1783 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1785 /* Previous ndlp no longer active with nvme host transport.
1786 * Remove reference from earlier registration unless the
1787 * nvme host took care of it.
1791 ndlp->nrport = keep_nrport;
1793 /* Fix up the rport accordingly */
1794 rport = ndlp->rport;
1796 rdata = rport->dd_data;
1797 put_node = rdata->pnode != NULL;
1798 put_rport = ndlp->rport != NULL;
1799 rdata->pnode = NULL;
1804 put_device(&rport->dev);
1809 * If ndlp is not associated with any rport we can drop it here else
1810 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1812 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1813 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1815 if (phba->sli_rev == LPFC_SLI_REV4 &&
1816 active_rrqs_xri_bitmap)
1817 mempool_free(active_rrqs_xri_bitmap,
1818 phba->active_rrq_pool);
1820 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1821 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1822 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1823 new_ndlp->nlp_fc4_type);
1829 * lpfc_end_rscn - Check and handle more rscn for a vport
1830 * @vport: pointer to a host virtual N_Port data structure.
1832 * This routine checks whether more Registration State Change
1833 * Notifications (RSCNs) came in while the discovery state machine was in
1834 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1835 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1836 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1837 * handling the RSCNs.
1840 lpfc_end_rscn(struct lpfc_vport *vport)
1842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1844 if (vport->fc_flag & FC_RSCN_MODE) {
1846 * Check to see if more RSCNs came in while we were
1847 * processing this one.
1849 if (vport->fc_rscn_id_cnt ||
1850 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1851 lpfc_els_handle_rscn(vport);
1853 spin_lock_irq(shost->host_lock);
1854 vport->fc_flag &= ~FC_RSCN_MODE;
1855 spin_unlock_irq(shost->host_lock);
1861 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1862 * @phba: pointer to lpfc hba data structure.
1863 * @cmdiocb: pointer to lpfc command iocb data structure.
1864 * @rspiocb: pointer to lpfc response iocb data structure.
1866 * This routine will call the clear rrq function to free the rrq and
1867 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1868 * exist then the clear_rrq is still called because the rrq needs to
1873 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1874 struct lpfc_iocbq *rspiocb)
1876 struct lpfc_vport *vport = cmdiocb->vport;
1878 struct lpfc_nodelist *ndlp;
1879 struct lpfc_node_rrq *rrq;
1881 /* we pass cmdiocb to state machine which needs rspiocb as well */
1882 rrq = cmdiocb->context_un.rrq;
1883 cmdiocb->context_un.rsp_iocb = rspiocb;
1885 irsp = &rspiocb->iocb;
1886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1887 "RRQ cmpl: status:x%x/x%x did:x%x",
1888 irsp->ulpStatus, irsp->un.ulpWord[4],
1889 irsp->un.elsreq64.remoteID);
1891 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1892 if (!ndlp || ndlp != rrq->ndlp) {
1893 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1894 "2882 RRQ completes to NPort x%x "
1895 "with no ndlp. Data: x%x x%x x%x\n",
1896 irsp->un.elsreq64.remoteID,
1897 irsp->ulpStatus, irsp->un.ulpWord[4],
1902 /* rrq completes to NPort <nlp_DID> */
1903 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1904 "2880 RRQ completes to NPort x%x "
1905 "Data: x%x x%x x%x x%x x%x\n",
1906 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1907 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1909 if (irsp->ulpStatus) {
1910 /* Check for retry */
1911 /* RRQ failed Don't print the vport to vport rjts */
1912 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1913 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1914 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1915 (phba)->pport->cfg_log_verbose & LOG_ELS)
1916 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1917 "2881 RRQ failure DID:%06X Status:"
1919 ndlp->nlp_DID, irsp->ulpStatus,
1920 irsp->un.ulpWord[4]);
1924 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1925 lpfc_els_free_iocb(phba, cmdiocb);
1929 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1930 * @phba: pointer to lpfc hba data structure.
1931 * @cmdiocb: pointer to lpfc command iocb data structure.
1932 * @rspiocb: pointer to lpfc response iocb data structure.
1934 * This routine is the completion callback function for issuing the Port
1935 * Login (PLOGI) command. For PLOGI completion, there must be an active
1936 * ndlp on the vport node list that matches the remote node ID from the
1937 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1938 * ignored and command IOCB released. The PLOGI response IOCB status is
1939 * checked for error conditons. If there is error status reported, PLOGI
1940 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1941 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1942 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1943 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1944 * there are additional N_Port nodes with the vport that need to perform
1945 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1949 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1950 struct lpfc_iocbq *rspiocb)
1952 struct lpfc_vport *vport = cmdiocb->vport;
1953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1955 struct lpfc_nodelist *ndlp;
1956 struct lpfc_dmabuf *prsp;
1959 /* we pass cmdiocb to state machine which needs rspiocb as well */
1960 cmdiocb->context_un.rsp_iocb = rspiocb;
1962 irsp = &rspiocb->iocb;
1963 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1964 "PLOGI cmpl: status:x%x/x%x did:x%x",
1965 irsp->ulpStatus, irsp->un.ulpWord[4],
1966 irsp->un.elsreq64.remoteID);
1968 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1970 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1971 "0136 PLOGI completes to NPort x%x "
1972 "with no ndlp. Data: x%x x%x x%x\n",
1973 irsp->un.elsreq64.remoteID,
1974 irsp->ulpStatus, irsp->un.ulpWord[4],
1979 /* Since ndlp can be freed in the disc state machine, note if this node
1980 * is being used during discovery.
1982 spin_lock_irq(shost->host_lock);
1983 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1984 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1985 spin_unlock_irq(shost->host_lock);
1987 /* PLOGI completes to NPort <nlp_DID> */
1988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1989 "0102 PLOGI completes to NPort x%06x "
1990 "Data: x%x x%x x%x x%x x%x\n",
1991 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1992 irsp->ulpStatus, irsp->un.ulpWord[4],
1993 disc, vport->num_disc_nodes);
1995 /* Check to see if link went down during discovery */
1996 if (lpfc_els_chk_latt(vport)) {
1997 spin_lock_irq(shost->host_lock);
1998 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1999 spin_unlock_irq(shost->host_lock);
2003 if (irsp->ulpStatus) {
2004 /* Check for retry */
2005 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2006 /* ELS command is being retried */
2008 spin_lock_irq(shost->host_lock);
2009 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2010 spin_unlock_irq(shost->host_lock);
2014 /* PLOGI failed Don't print the vport to vport rjts */
2015 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2016 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2017 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2018 (phba)->pport->cfg_log_verbose & LOG_ELS)
2019 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2020 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2021 ndlp->nlp_DID, irsp->ulpStatus,
2022 irsp->un.ulpWord[4]);
2023 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2024 if (!lpfc_error_lost_link(irsp))
2025 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2026 NLP_EVT_CMPL_PLOGI);
2028 /* Good status, call state machine */
2029 prsp = list_entry(((struct lpfc_dmabuf *)
2030 cmdiocb->context2)->list.next,
2031 struct lpfc_dmabuf, list);
2032 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2033 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2034 NLP_EVT_CMPL_PLOGI);
2037 if (disc && vport->num_disc_nodes) {
2038 /* Check to see if there are more PLOGIs to be sent */
2039 lpfc_more_plogi(vport);
2041 if (vport->num_disc_nodes == 0) {
2042 spin_lock_irq(shost->host_lock);
2043 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2044 spin_unlock_irq(shost->host_lock);
2046 lpfc_can_disctmo(vport);
2047 lpfc_end_rscn(vport);
2052 lpfc_els_free_iocb(phba, cmdiocb);
2057 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2058 * @vport: pointer to a host virtual N_Port data structure.
2059 * @did: destination port identifier.
2060 * @retry: number of retries to the command IOCB.
2062 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2063 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2064 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2065 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2066 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2068 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2069 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2070 * will be stored into the context1 field of the IOCB for the completion
2071 * callback function to the PLOGI ELS command.
2074 * 0 - Successfully issued a plogi for @vport
2075 * 1 - failed to issue a plogi for @vport
2078 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2080 struct lpfc_hba *phba = vport->phba;
2081 struct Scsi_Host *shost;
2082 struct serv_parm *sp;
2083 struct lpfc_nodelist *ndlp;
2084 struct lpfc_iocbq *elsiocb;
2089 ndlp = lpfc_findnode_did(vport, did);
2092 /* Defer the processing of the issue PLOGI until after the
2093 * outstanding UNREG_RPI mbox command completes, unless we
2094 * are going offline. This logic does not apply for Fabric DIDs
2096 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2097 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2098 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2099 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2100 "4110 Issue PLOGI x%x deferred "
2101 "on NPort x%x rpi x%x Data: x%px\n",
2102 ndlp->nlp_defer_did, ndlp->nlp_DID,
2103 ndlp->nlp_rpi, ndlp);
2105 /* We can only defer 1st PLOGI */
2106 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2107 ndlp->nlp_defer_did = did;
2112 /* If ndlp is not NULL, we will bump the reference count on it */
2113 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2114 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2119 shost = lpfc_shost_from_vport(vport);
2120 spin_lock_irq(shost->host_lock);
2121 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2122 spin_unlock_irq(shost->host_lock);
2124 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2126 /* For PLOGI request, remainder of payload is service parameters */
2127 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2128 pcmd += sizeof(uint32_t);
2129 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2130 sp = (struct serv_parm *) pcmd;
2133 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2134 * to device on remote loops work.
2136 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2137 sp->cmn.altBbCredit = 1;
2139 if (sp->cmn.fcphLow < FC_PH_4_3)
2140 sp->cmn.fcphLow = FC_PH_4_3;
2142 if (sp->cmn.fcphHigh < FC_PH3)
2143 sp->cmn.fcphHigh = FC_PH3;
2145 sp->cmn.valid_vendor_ver_level = 0;
2146 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2147 sp->cmn.bbRcvSizeMsb &= 0xF;
2149 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2150 "Issue PLOGI: did:x%x",
2153 /* If our firmware supports this feature, convey that
2154 * information to the target using the vendor specific field.
2156 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2157 sp->cmn.valid_vendor_ver_level = 1;
2158 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2159 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2162 phba->fc_stat.elsXmitPLOGI++;
2163 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2164 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2166 if (ret == IOCB_ERROR) {
2167 lpfc_els_free_iocb(phba, elsiocb);
2174 * lpfc_cmpl_els_prli - Completion callback function for prli
2175 * @phba: pointer to lpfc hba data structure.
2176 * @cmdiocb: pointer to lpfc command iocb data structure.
2177 * @rspiocb: pointer to lpfc response iocb data structure.
2179 * This routine is the completion callback function for a Process Login
2180 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2181 * status. If there is error status reported, PRLI retry shall be attempted
2182 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2183 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2184 * ndlp to mark the PRLI completion.
2187 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2188 struct lpfc_iocbq *rspiocb)
2190 struct lpfc_vport *vport = cmdiocb->vport;
2191 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2193 struct lpfc_nodelist *ndlp;
2197 /* we pass cmdiocb to state machine which needs rspiocb as well */
2198 cmdiocb->context_un.rsp_iocb = rspiocb;
2200 irsp = &(rspiocb->iocb);
2201 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2202 spin_lock_irq(shost->host_lock);
2203 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2205 /* Driver supports multiple FC4 types. Counters matter. */
2206 vport->fc_prli_sent--;
2207 ndlp->fc4_prli_sent--;
2208 spin_unlock_irq(shost->host_lock);
2210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2211 "PRLI cmpl: status:x%x/x%x did:x%x",
2212 irsp->ulpStatus, irsp->un.ulpWord[4],
2215 /* PRLI completes to NPort <nlp_DID> */
2216 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2217 "0103 PRLI completes to NPort x%06x "
2218 "Data: x%x x%x x%x x%x\n",
2219 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2220 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2222 /* Check to see if link went down during discovery */
2223 if (lpfc_els_chk_latt(vport))
2226 if (irsp->ulpStatus) {
2227 /* Check for retry */
2228 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2229 /* ELS command is being retried */
2233 /* If we don't send GFT_ID to Fabric, a PRLI error
2234 * could be expected.
2236 if ((vport->fc_flag & FC_FABRIC) ||
2237 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2239 loglevel = LOG_TRACE_EVENT;
2246 lpfc_printf_vlog(vport, mode, loglevel,
2247 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2249 ndlp->nlp_DID, irsp->ulpStatus,
2250 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2252 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2253 if (lpfc_error_lost_link(irsp))
2256 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2259 /* Good status, call state machine. However, if another
2260 * PRLI is outstanding, don't call the state machine
2261 * because final disposition to Mapped or Unmapped is
2264 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2269 lpfc_els_free_iocb(phba, cmdiocb);
2274 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2275 * @vport: pointer to a host virtual N_Port data structure.
2276 * @ndlp: pointer to a node-list data structure.
2277 * @retry: number of retries to the command IOCB.
2279 * This routine issues a Process Login (PRLI) ELS command for the
2280 * @vport. The PRLI service parameters are set up in the payload of the
2281 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2282 * is put to the IOCB completion callback func field before invoking the
2283 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2285 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2286 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2287 * will be stored into the context1 field of the IOCB for the completion
2288 * callback function to the PRLI ELS command.
2291 * 0 - successfully issued prli iocb command for @vport
2292 * 1 - failed to issue prli iocb command for @vport
2295 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2298 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2299 struct lpfc_hba *phba = vport->phba;
2301 struct lpfc_nvme_prli *npr_nvme;
2302 struct lpfc_iocbq *elsiocb;
2305 u32 local_nlp_type, elscmd;
2308 * If we are in RSCN mode, the FC4 types supported from a
2309 * previous GFT_ID command may not be accurate. So, if we
2310 * are a NVME Initiator, always look for the possibility of
2311 * the remote NPort beng a NVME Target.
2313 if (phba->sli_rev == LPFC_SLI_REV4 &&
2314 vport->fc_flag & FC_RSCN_MODE &&
2315 vport->nvmei_support)
2316 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2317 local_nlp_type = ndlp->nlp_fc4_type;
2319 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2320 * fields here before any of them can complete.
2322 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2323 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2324 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2325 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2326 ndlp->nvme_fb_size = 0;
2329 if (local_nlp_type & NLP_FC4_FCP) {
2330 /* Payload is 4 + 16 = 20 x14 bytes. */
2331 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2332 elscmd = ELS_CMD_PRLI;
2333 } else if (local_nlp_type & NLP_FC4_NVME) {
2334 /* Payload is 4 + 20 = 24 x18 bytes. */
2335 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2336 elscmd = ELS_CMD_NVMEPRLI;
2338 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2339 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2340 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2344 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2345 * FC4 type, implicitly LOGO.
2347 if (phba->sli_rev == LPFC_SLI_REV3 &&
2348 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2349 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2350 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2352 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2356 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2357 ndlp->nlp_DID, elscmd);
2361 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2363 /* For PRLI request, remainder of payload is service parameters */
2364 memset(pcmd, 0, cmdsize);
2366 if (local_nlp_type & NLP_FC4_FCP) {
2367 /* Remainder of payload is FCP PRLI parameter page.
2368 * Note: this data structure is defined as
2369 * BE/LE in the structure definition so no
2370 * byte swap call is made.
2372 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2373 pcmd += sizeof(uint32_t);
2377 * If our firmware version is 3.20 or later,
2378 * set the following bits for FC-TAPE support.
2380 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2381 npr->ConfmComplAllowed = 1;
2383 npr->TaskRetryIdReq = 1;
2385 npr->estabImagePair = 1;
2386 npr->readXferRdyDis = 1;
2387 if (vport->cfg_first_burst_size)
2388 npr->writeXferRdyDis = 1;
2390 /* For FCP support */
2391 npr->prliType = PRLI_FCP_TYPE;
2392 npr->initiatorFunc = 1;
2393 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2395 /* Remove FCP type - processed. */
2396 local_nlp_type &= ~NLP_FC4_FCP;
2397 } else if (local_nlp_type & NLP_FC4_NVME) {
2398 /* Remainder of payload is NVME PRLI parameter page.
2399 * This data structure is the newer definition that
2400 * uses bf macros so a byte swap is required.
2402 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2403 pcmd += sizeof(uint32_t);
2404 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2405 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2406 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2408 bf_set(prli_nsler, npr_nvme, 1);
2409 bf_set(prli_conf, npr_nvme, 1);
2412 /* Only initiators request first burst. */
2413 if ((phba->cfg_nvme_enable_fb) &&
2414 !phba->nvmet_support)
2415 bf_set(prli_fba, npr_nvme, 1);
2417 if (phba->nvmet_support) {
2418 bf_set(prli_tgt, npr_nvme, 1);
2419 bf_set(prli_disc, npr_nvme, 1);
2421 bf_set(prli_init, npr_nvme, 1);
2422 bf_set(prli_conf, npr_nvme, 1);
2425 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2426 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2427 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2429 /* Remove NVME type - processed. */
2430 local_nlp_type &= ~NLP_FC4_NVME;
2433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2434 "Issue PRLI: did:x%x",
2435 ndlp->nlp_DID, 0, 0);
2437 phba->fc_stat.elsXmitPRLI++;
2438 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2439 spin_lock_irq(shost->host_lock);
2440 ndlp->nlp_flag |= NLP_PRLI_SND;
2442 /* The vport counters are used for lpfc_scan_finished, but
2443 * the ndlp is used to track outstanding PRLIs for different
2446 vport->fc_prli_sent++;
2447 ndlp->fc4_prli_sent++;
2448 spin_unlock_irq(shost->host_lock);
2449 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2451 spin_lock_irq(shost->host_lock);
2452 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2453 spin_unlock_irq(shost->host_lock);
2454 lpfc_els_free_iocb(phba, elsiocb);
2459 /* The driver supports 2 FC4 types. Make sure
2460 * a PRLI is issued for all types before exiting.
2462 if (phba->sli_rev == LPFC_SLI_REV4 &&
2463 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2464 goto send_next_prli;
2470 * lpfc_rscn_disc - Perform rscn discovery for a vport
2471 * @vport: pointer to a host virtual N_Port data structure.
2473 * This routine performs Registration State Change Notification (RSCN)
2474 * discovery for a @vport. If the @vport's node port recovery count is not
2475 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2476 * the nodes that need recovery. If none of the PLOGI were needed through
2477 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2478 * invoked to check and handle possible more RSCN came in during the period
2479 * of processing the current ones.
2482 lpfc_rscn_disc(struct lpfc_vport *vport)
2484 lpfc_can_disctmo(vport);
2486 /* RSCN discovery */
2487 /* go thru NPR nodes and issue ELS PLOGIs */
2488 if (vport->fc_npr_cnt)
2489 if (lpfc_els_disc_plogi(vport))
2492 lpfc_end_rscn(vport);
2496 * lpfc_adisc_done - Complete the adisc phase of discovery
2497 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2499 * This function is called when the final ADISC is completed during discovery.
2500 * This function handles clearing link attention or issuing reg_vpi depending
2501 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2503 * This function is called with no locks held.
2506 lpfc_adisc_done(struct lpfc_vport *vport)
2508 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2509 struct lpfc_hba *phba = vport->phba;
2512 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2513 * and continue discovery.
2515 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2516 !(vport->fc_flag & FC_RSCN_MODE) &&
2517 (phba->sli_rev < LPFC_SLI_REV4)) {
2518 /* The ADISCs are complete. Doesn't matter if they
2519 * succeeded or failed because the ADISC completion
2520 * routine guarantees to call the state machine and
2521 * the RPI is either unregistered (failed ADISC response)
2522 * or the RPI is still valid and the node is marked
2523 * mapped for a target. The exchanges should be in the
2524 * correct state. This code is specific to SLI3.
2526 lpfc_issue_clear_la(phba, vport);
2527 lpfc_issue_reg_vpi(phba, vport);
2531 * For SLI2, we need to set port_state to READY
2532 * and continue discovery.
2534 if (vport->port_state < LPFC_VPORT_READY) {
2535 /* If we get here, there is nothing to ADISC */
2536 lpfc_issue_clear_la(phba, vport);
2537 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2538 vport->num_disc_nodes = 0;
2539 /* go thru NPR list, issue ELS PLOGIs */
2540 if (vport->fc_npr_cnt)
2541 lpfc_els_disc_plogi(vport);
2542 if (!vport->num_disc_nodes) {
2543 spin_lock_irq(shost->host_lock);
2544 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2545 spin_unlock_irq(shost->host_lock);
2546 lpfc_can_disctmo(vport);
2547 lpfc_end_rscn(vport);
2550 vport->port_state = LPFC_VPORT_READY;
2552 lpfc_rscn_disc(vport);
2556 * lpfc_more_adisc - Issue more adisc as needed
2557 * @vport: pointer to a host virtual N_Port data structure.
2559 * This routine determines whether there are more ndlps on a @vport
2560 * node list need to have Address Discover (ADISC) issued. If so, it will
2561 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2562 * remaining nodes which need to have ADISC sent.
2565 lpfc_more_adisc(struct lpfc_vport *vport)
2567 if (vport->num_disc_nodes)
2568 vport->num_disc_nodes--;
2569 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2570 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2571 "0210 Continue discovery with %d ADISCs to go "
2572 "Data: x%x x%x x%x\n",
2573 vport->num_disc_nodes, vport->fc_adisc_cnt,
2574 vport->fc_flag, vport->port_state);
2575 /* Check to see if there are more ADISCs to be sent */
2576 if (vport->fc_flag & FC_NLP_MORE) {
2577 lpfc_set_disctmo(vport);
2578 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2579 lpfc_els_disc_adisc(vport);
2581 if (!vport->num_disc_nodes)
2582 lpfc_adisc_done(vport);
2587 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2588 * @phba: pointer to lpfc hba data structure.
2589 * @cmdiocb: pointer to lpfc command iocb data structure.
2590 * @rspiocb: pointer to lpfc response iocb data structure.
2592 * This routine is the completion function for issuing the Address Discover
2593 * (ADISC) command. It first checks to see whether link went down during
2594 * the discovery process. If so, the node will be marked as node port
2595 * recovery for issuing discover IOCB by the link attention handler and
2596 * exit. Otherwise, the response status is checked. If error was reported
2597 * in the response status, the ADISC command shall be retried by invoking
2598 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2599 * the response status, the state machine is invoked to set transition
2600 * with respect to NLP_EVT_CMPL_ADISC event.
2603 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2604 struct lpfc_iocbq *rspiocb)
2606 struct lpfc_vport *vport = cmdiocb->vport;
2607 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2609 struct lpfc_nodelist *ndlp;
2612 /* we pass cmdiocb to state machine which needs rspiocb as well */
2613 cmdiocb->context_un.rsp_iocb = rspiocb;
2615 irsp = &(rspiocb->iocb);
2616 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2619 "ADISC cmpl: status:x%x/x%x did:x%x",
2620 irsp->ulpStatus, irsp->un.ulpWord[4],
2623 /* Since ndlp can be freed in the disc state machine, note if this node
2624 * is being used during discovery.
2626 spin_lock_irq(shost->host_lock);
2627 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2628 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2629 spin_unlock_irq(shost->host_lock);
2630 /* ADISC completes to NPort <nlp_DID> */
2631 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2632 "0104 ADISC completes to NPort x%x "
2633 "Data: x%x x%x x%x x%x x%x\n",
2634 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2635 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2636 /* Check to see if link went down during discovery */
2637 if (lpfc_els_chk_latt(vport)) {
2638 spin_lock_irq(shost->host_lock);
2639 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2640 spin_unlock_irq(shost->host_lock);
2644 if (irsp->ulpStatus) {
2645 /* Check for retry */
2646 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2647 /* ELS command is being retried */
2649 spin_lock_irq(shost->host_lock);
2650 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2651 spin_unlock_irq(shost->host_lock);
2652 lpfc_set_disctmo(vport);
2657 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2658 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2659 ndlp->nlp_DID, irsp->ulpStatus,
2660 irsp->un.ulpWord[4]);
2661 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2662 if (!lpfc_error_lost_link(irsp))
2663 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2664 NLP_EVT_CMPL_ADISC);
2666 /* Good status, call state machine */
2667 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2668 NLP_EVT_CMPL_ADISC);
2670 /* Check to see if there are more ADISCs to be sent */
2671 if (disc && vport->num_disc_nodes)
2672 lpfc_more_adisc(vport);
2674 lpfc_els_free_iocb(phba, cmdiocb);
2679 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2680 * @vport: pointer to a virtual N_Port data structure.
2681 * @ndlp: pointer to a node-list data structure.
2682 * @retry: number of retries to the command IOCB.
2684 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2685 * @vport. It prepares the payload of the ADISC ELS command, updates the
2686 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2687 * to issue the ADISC ELS command.
2689 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2690 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2691 * will be stored into the context1 field of the IOCB for the completion
2692 * callback function to the ADISC ELS command.
2695 * 0 - successfully issued adisc
2696 * 1 - failed to issue adisc
2699 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2703 struct lpfc_hba *phba = vport->phba;
2705 struct lpfc_iocbq *elsiocb;
2709 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2710 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2711 ndlp->nlp_DID, ELS_CMD_ADISC);
2715 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2717 /* For ADISC request, remainder of payload is service parameters */
2718 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2719 pcmd += sizeof(uint32_t);
2721 /* Fill in ADISC payload */
2722 ap = (ADISC *) pcmd;
2723 ap->hardAL_PA = phba->fc_pref_ALPA;
2724 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2725 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2726 ap->DID = be32_to_cpu(vport->fc_myDID);
2728 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2729 "Issue ADISC: did:x%x",
2730 ndlp->nlp_DID, 0, 0);
2732 phba->fc_stat.elsXmitADISC++;
2733 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2734 spin_lock_irq(shost->host_lock);
2735 ndlp->nlp_flag |= NLP_ADISC_SND;
2736 spin_unlock_irq(shost->host_lock);
2737 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2739 spin_lock_irq(shost->host_lock);
2740 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2741 spin_unlock_irq(shost->host_lock);
2742 lpfc_els_free_iocb(phba, elsiocb);
2749 * lpfc_cmpl_els_logo - Completion callback function for logo
2750 * @phba: pointer to lpfc hba data structure.
2751 * @cmdiocb: pointer to lpfc command iocb data structure.
2752 * @rspiocb: pointer to lpfc response iocb data structure.
2754 * This routine is the completion function for issuing the ELS Logout (LOGO)
2755 * command. If no error status was reported from the LOGO response, the
2756 * state machine of the associated ndlp shall be invoked for transition with
2757 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2758 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2761 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2762 struct lpfc_iocbq *rspiocb)
2764 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2765 struct lpfc_vport *vport = ndlp->vport;
2766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2768 struct lpfcMboxq *mbox;
2769 unsigned long flags;
2770 uint32_t skip_recovery = 0;
2772 /* we pass cmdiocb to state machine which needs rspiocb as well */
2773 cmdiocb->context_un.rsp_iocb = rspiocb;
2775 irsp = &(rspiocb->iocb);
2776 spin_lock_irq(shost->host_lock);
2777 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2778 spin_unlock_irq(shost->host_lock);
2780 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2781 "LOGO cmpl: status:x%x/x%x did:x%x",
2782 irsp->ulpStatus, irsp->un.ulpWord[4],
2785 /* LOGO completes to NPort <nlp_DID> */
2786 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2787 "0105 LOGO completes to NPort x%x "
2788 "Data: x%x x%x x%x x%x\n",
2789 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2790 irsp->ulpTimeout, vport->num_disc_nodes);
2792 if (lpfc_els_chk_latt(vport)) {
2797 /* Check to see if link went down during discovery */
2798 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2799 /* NLP_EVT_DEVICE_RM should unregister the RPI
2800 * which should abort all outstanding IOs.
2802 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2808 /* The LOGO will not be retried on failure. A LOGO was
2809 * issued to the remote rport and a ACC or RJT or no Answer are
2810 * all acceptable. Note the failure and move forward with
2811 * discovery. The PLOGI will retry.
2813 if (irsp->ulpStatus) {
2815 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2816 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2817 ndlp->nlp_DID, irsp->ulpStatus,
2818 irsp->un.ulpWord[4]);
2819 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2820 if (lpfc_error_lost_link(irsp)) {
2826 /* Call state machine. This will unregister the rpi if needed. */
2827 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2830 lpfc_els_free_iocb(phba, cmdiocb);
2831 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2832 if ((vport->fc_flag & FC_PT2PT) &&
2833 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2834 phba->pport->fc_myDID = 0;
2836 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2837 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2838 if (phba->nvmet_support)
2839 lpfc_nvmet_update_targetport(phba);
2841 lpfc_nvme_update_localport(phba->pport);
2844 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2846 lpfc_config_link(phba, mbox);
2847 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2848 mbox->vport = vport;
2849 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2851 mempool_free(mbox, phba->mbox_mem_pool);
2858 * If the node is a target, the handling attempts to recover the port.
2859 * For any other port type, the rpi is unregistered as an implicit
2862 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2863 skip_recovery == 0) {
2864 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2865 spin_lock_irqsave(shost->host_lock, flags);
2866 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2867 spin_unlock_irqrestore(shost->host_lock, flags);
2869 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2870 "3187 LOGO completes to NPort x%x: Start "
2871 "Recovery Data: x%x x%x x%x x%x\n",
2872 ndlp->nlp_DID, irsp->ulpStatus,
2873 irsp->un.ulpWord[4], irsp->ulpTimeout,
2874 vport->num_disc_nodes);
2875 lpfc_disc_start(vport);
2881 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2882 * @vport: pointer to a virtual N_Port data structure.
2883 * @ndlp: pointer to a node-list data structure.
2884 * @retry: number of retries to the command IOCB.
2886 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2887 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2888 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2889 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2891 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2892 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2893 * will be stored into the context1 field of the IOCB for the completion
2894 * callback function to the LOGO ELS command.
2896 * Callers of this routine are expected to unregister the RPI first
2899 * 0 - successfully issued logo
2900 * 1 - failed to issue logo
2903 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2906 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2907 struct lpfc_hba *phba = vport->phba;
2908 struct lpfc_iocbq *elsiocb;
2913 spin_lock_irq(shost->host_lock);
2914 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2915 spin_unlock_irq(shost->host_lock);
2918 spin_unlock_irq(shost->host_lock);
2920 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2921 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2922 ndlp->nlp_DID, ELS_CMD_LOGO);
2926 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2927 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2928 pcmd += sizeof(uint32_t);
2930 /* Fill in LOGO payload */
2931 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2932 pcmd += sizeof(uint32_t);
2933 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2935 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2936 "Issue LOGO: did:x%x",
2937 ndlp->nlp_DID, 0, 0);
2939 phba->fc_stat.elsXmitLOGO++;
2940 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2941 spin_lock_irq(shost->host_lock);
2942 ndlp->nlp_flag |= NLP_LOGO_SND;
2943 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2944 spin_unlock_irq(shost->host_lock);
2945 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2946 if (rc == IOCB_ERROR) {
2947 spin_lock_irq(shost->host_lock);
2948 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2949 spin_unlock_irq(shost->host_lock);
2950 lpfc_els_free_iocb(phba, elsiocb);
2954 spin_lock_irq(shost->host_lock);
2955 ndlp->nlp_prev_state = ndlp->nlp_state;
2956 spin_unlock_irq(shost->host_lock);
2957 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2962 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2963 * @phba: pointer to lpfc hba data structure.
2964 * @cmdiocb: pointer to lpfc command iocb data structure.
2965 * @rspiocb: pointer to lpfc response iocb data structure.
2967 * This routine is a generic completion callback function for ELS commands.
2968 * Specifically, it is the callback function which does not need to perform
2969 * any command specific operations. It is currently used by the ELS command
2970 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
2971 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
2972 * Other than certain debug loggings, this callback function simply invokes the
2973 * lpfc_els_chk_latt() routine to check whether link went down during the
2974 * discovery process.
2977 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2978 struct lpfc_iocbq *rspiocb)
2980 struct lpfc_vport *vport = cmdiocb->vport;
2983 irsp = &rspiocb->iocb;
2985 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2986 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2987 irsp->ulpStatus, irsp->un.ulpWord[4],
2988 irsp->un.elsreq64.remoteID);
2990 /* ELS cmd tag <ulpIoTag> completes */
2991 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2992 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2993 irsp->ulpIoTag, irsp->ulpStatus,
2994 irsp->un.ulpWord[4], irsp->ulpTimeout);
2996 /* Check to see if link went down during discovery */
2997 lpfc_els_chk_latt(vport);
2998 lpfc_els_free_iocb(phba, cmdiocb);
3002 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3003 * @phba: pointer to lpfc hba data structure.
3004 * @cmdiocb: pointer to lpfc command iocb data structure.
3005 * @rspiocb: pointer to lpfc response iocb data structure.
3007 * This routine is a generic completion callback function for Discovery ELS cmd.
3008 * Currently used by the ELS command issuing routines for the ELS State Change
3009 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3010 * These commands will be retried once only for ELS timeout errors.
3013 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3014 struct lpfc_iocbq *rspiocb)
3016 struct lpfc_vport *vport = cmdiocb->vport;
3018 struct lpfc_els_rdf_rsp *prdf;
3019 struct lpfc_dmabuf *pcmd, *prsp;
3023 irsp = &rspiocb->iocb;
3025 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3026 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3027 irsp->ulpStatus, irsp->un.ulpWord[4],
3028 irsp->un.elsreq64.remoteID);
3029 /* ELS cmd tag <ulpIoTag> completes */
3030 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3031 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3033 irsp->ulpIoTag, irsp->ulpStatus,
3034 irsp->un.ulpWord[4], irsp->ulpTimeout,
3037 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3041 pdata = (u32 *)pcmd->virt;
3046 /* Only 1 retry for ELS Timeout only */
3047 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3048 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3049 IOERR_SEQUENCE_TIMEOUT)) {
3051 if (cmdiocb->retry <= 1) {
3054 lpfc_issue_els_scr(vport, cmdiocb->retry);
3057 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3058 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3063 phba->fc_stat.elsRetryExceeded++;
3065 if (irsp->ulpStatus) {
3066 /* ELS discovery cmd completes with error */
3067 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3068 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3069 irsp->ulpStatus, irsp->un.ulpWord[4]);
3073 /* The RDF response doesn't have any impact on the running driver
3074 * but the notification descriptors are dumped here for support.
3076 if (cmd == ELS_CMD_RDF) {
3079 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3083 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3087 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3088 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3089 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3090 "4677 Fabric RDF Notification Grant Data: "
3093 prdf->reg_d1.desc_tags[i]));
3097 /* Check to see if link went down during discovery */
3098 lpfc_els_chk_latt(vport);
3099 lpfc_els_free_iocb(phba, cmdiocb);
3104 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3105 * @vport: pointer to a host virtual N_Port data structure.
3106 * @retry: retry counter for the command IOCB.
3108 * This routine issues a State Change Request (SCR) to a fabric node
3109 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3110 * first search the @vport node list to find the matching ndlp. If no such
3111 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3112 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3113 * routine is invoked to send the SCR IOCB.
3115 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3116 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3117 * will be stored into the context1 field of the IOCB for the completion
3118 * callback function to the SCR ELS command.
3121 * 0 - Successfully issued scr command
3122 * 1 - Failed to issue scr command
3125 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3127 struct lpfc_hba *phba = vport->phba;
3128 struct lpfc_iocbq *elsiocb;
3131 struct lpfc_nodelist *ndlp;
3133 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3135 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3137 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3140 lpfc_enqueue_node(vport, ndlp);
3143 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3144 ndlp->nlp_DID, ELS_CMD_SCR);
3147 /* This will trigger the release of the node just
3154 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3156 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3157 pcmd += sizeof(uint32_t);
3159 /* For SCR, remainder of payload is SCR parameter page */
3160 memset(pcmd, 0, sizeof(SCR));
3161 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3163 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3164 "Issue SCR: did:x%x",
3165 ndlp->nlp_DID, 0, 0);
3167 phba->fc_stat.elsXmitSCR++;
3168 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3169 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3171 /* The additional lpfc_nlp_put will cause the following
3172 * lpfc_els_free_iocb routine to trigger the rlease of
3176 lpfc_els_free_iocb(phba, elsiocb);
3179 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3180 * trigger the release of node.
3182 if (!(vport->fc_flag & FC_PT2PT))
3188 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3189 * or the other nport (pt2pt).
3190 * @vport: pointer to a host virtual N_Port data structure.
3191 * @retry: number of retries to the command IOCB.
3193 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3194 * when connected to a fabric, or to the remote port when connected
3195 * in point-to-point mode. When sent to the Fabric Controller, it will
3196 * replay the RSCN to registered recipients.
3198 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3199 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3200 * will be stored into the context1 field of the IOCB for the completion
3201 * callback function to the RSCN ELS command.
3204 * 0 - Successfully issued RSCN command
3205 * 1 - Failed to issue RSCN command
3208 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3210 struct lpfc_hba *phba = vport->phba;
3211 struct lpfc_iocbq *elsiocb;
3212 struct lpfc_nodelist *ndlp;
3214 struct fc_els_rscn rscn;
3215 struct fc_els_rscn_page portid;
3218 uint16_t cmdsize = sizeof(*event);
3220 /* Not supported for private loop */
3221 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3222 !(vport->fc_flag & FC_PUBLIC_LOOP))
3225 if (vport->fc_flag & FC_PT2PT) {
3226 /* find any mapped nport - that would be the other nport */
3227 ndlp = lpfc_findnode_mapped(vport);
3231 nportid = FC_FID_FCTRL;
3232 /* find the fabric controller node */
3233 ndlp = lpfc_findnode_did(vport, nportid);
3235 /* if one didn't exist, make one */
3236 ndlp = lpfc_nlp_init(vport, nportid);
3239 lpfc_enqueue_node(vport, ndlp);
3243 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3244 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3247 /* This will trigger the release of the node just
3254 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3256 event->rscn.rscn_cmd = ELS_RSCN;
3257 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3258 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3260 nportid = vport->fc_myDID;
3261 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3262 event->portid.rscn_page_flags = 0;
3263 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3264 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3265 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3268 "Issue RSCN: did:x%x",
3269 ndlp->nlp_DID, 0, 0);
3271 phba->fc_stat.elsXmitRSCN++;
3272 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3273 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3275 /* The additional lpfc_nlp_put will cause the following
3276 * lpfc_els_free_iocb routine to trigger the rlease of
3280 lpfc_els_free_iocb(phba, elsiocb);
3284 /* Only keep the ndlp if RDF is being sent */
3285 if (!phba->cfg_enable_mi ||
3286 phba->sli4_hba.pc_sli4_params.mi_ver < LPFC_MIB3_SUPPORT)
3289 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3290 * trigger the release of node.
3292 if (!(vport->fc_flag & FC_PT2PT))
3299 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3300 * @vport: pointer to a host virtual N_Port data structure.
3301 * @nportid: N_Port identifier to the remote node.
3302 * @retry: number of retries to the command IOCB.
3304 * This routine issues a Fibre Channel Address Resolution Response
3305 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3306 * is passed into the function. It first search the @vport node list to find
3307 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3308 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3309 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3311 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3312 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3313 * will be stored into the context1 field of the IOCB for the completion
3314 * callback function to the PARPR ELS command.
3317 * 0 - Successfully issued farpr command
3318 * 1 - Failed to issue farpr command
3321 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3323 struct lpfc_hba *phba = vport->phba;
3324 struct lpfc_iocbq *elsiocb;
3329 struct lpfc_nodelist *ondlp;
3330 struct lpfc_nodelist *ndlp;
3332 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3334 ndlp = lpfc_findnode_did(vport, nportid);
3336 ndlp = lpfc_nlp_init(vport, nportid);
3339 lpfc_enqueue_node(vport, ndlp);
3342 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3343 ndlp->nlp_DID, ELS_CMD_RNID);
3345 /* This will trigger the release of the node just
3352 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3354 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3355 pcmd += sizeof(uint32_t);
3357 /* Fill in FARPR payload */
3358 fp = (FARP *) (pcmd);
3359 memset(fp, 0, sizeof(FARP));
3360 lp = (uint32_t *) pcmd;
3361 *lp++ = be32_to_cpu(nportid);
3362 *lp++ = be32_to_cpu(vport->fc_myDID);
3364 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3366 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3367 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3368 ondlp = lpfc_findnode_did(vport, nportid);
3370 memcpy(&fp->OportName, &ondlp->nlp_portname,
3371 sizeof(struct lpfc_name));
3372 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3373 sizeof(struct lpfc_name));
3376 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3377 "Issue FARPR: did:x%x",
3378 ndlp->nlp_DID, 0, 0);
3380 phba->fc_stat.elsXmitFARPR++;
3381 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3382 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3384 /* The additional lpfc_nlp_put will cause the following
3385 * lpfc_els_free_iocb routine to trigger the release of
3389 lpfc_els_free_iocb(phba, elsiocb);
3392 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3393 * trigger the release of the node.
3395 /* Don't release reference count as RDF is likely outstanding */
3400 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3401 * @vport: pointer to a host virtual N_Port data structure.
3402 * @retry: retry counter for the command IOCB.
3404 * This routine issues an ELS RDF to the Fabric Controller to register
3405 * for diagnostic functions.
3407 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3408 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3409 * will be stored into the context1 field of the IOCB for the completion
3410 * callback function to the RDF ELS command.
3413 * 0 - Successfully issued rdf command
3414 * 1 - Failed to issue rdf command
3417 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3419 struct lpfc_hba *phba = vport->phba;
3420 struct lpfc_iocbq *elsiocb;
3421 struct lpfc_els_rdf_req *prdf;
3422 struct lpfc_nodelist *ndlp;
3425 cmdsize = sizeof(*prdf);
3427 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3429 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3432 lpfc_enqueue_node(vport, ndlp);
3435 /* RDF ELS is not required on an NPIV VN_Port. */
3436 if (vport->port_type == LPFC_NPIV_PORT) {
3441 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3442 ndlp->nlp_DID, ELS_CMD_RDF);
3444 /* This will trigger the release of the node just
3451 /* Configure the payload for the supported FPIN events. */
3452 prdf = (struct lpfc_els_rdf_req *)
3453 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3454 memset(prdf, 0, cmdsize);
3455 prdf->rdf.fpin_cmd = ELS_RDF;
3456 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3457 sizeof(struct fc_els_rdf));
3458 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3459 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3460 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3461 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3462 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3463 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3464 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3465 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3467 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3468 "Issue RDF: did:x%x",
3469 ndlp->nlp_DID, 0, 0);
3471 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3472 "6444 Xmit RDF to remote NPORT x%x\n",
3475 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3476 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3478 /* The additional lpfc_nlp_put will cause the following
3479 * lpfc_els_free_iocb routine to trigger the rlease of
3483 lpfc_els_free_iocb(phba, elsiocb);
3487 /* An RDF was issued - this put ensures the ndlp is cleaned up
3488 * when the RDF completes.
3495 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3496 * @vport: pointer to a host virtual N_Port data structure.
3497 * @nlp: pointer to a node-list data structure.
3499 * This routine cancels the timer with a delayed IOCB-command retry for
3500 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3501 * removes the ELS retry event if it presents. In addition, if the
3502 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3503 * commands are sent for the @vport's nodes that require issuing discovery
3507 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3510 struct lpfc_work_evt *evtp;
3512 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3514 spin_lock_irq(shost->host_lock);
3515 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3516 spin_unlock_irq(shost->host_lock);
3517 del_timer_sync(&nlp->nlp_delayfunc);
3518 nlp->nlp_last_elscmd = 0;
3519 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3520 list_del_init(&nlp->els_retry_evt.evt_listp);
3521 /* Decrement nlp reference count held for the delayed retry */
3522 evtp = &nlp->els_retry_evt;
3523 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3525 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3526 spin_lock_irq(shost->host_lock);
3527 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3528 spin_unlock_irq(shost->host_lock);
3529 if (vport->num_disc_nodes) {
3530 if (vport->port_state < LPFC_VPORT_READY) {
3531 /* Check if there are more ADISCs to be sent */
3532 lpfc_more_adisc(vport);
3534 /* Check if there are more PLOGIs to be sent */
3535 lpfc_more_plogi(vport);
3536 if (vport->num_disc_nodes == 0) {
3537 spin_lock_irq(shost->host_lock);
3538 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3539 spin_unlock_irq(shost->host_lock);
3540 lpfc_can_disctmo(vport);
3541 lpfc_end_rscn(vport);
3550 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3551 * @t: pointer to the timer function associated data (ndlp).
3553 * This routine is invoked by the ndlp delayed-function timer to check
3554 * whether there is any pending ELS retry event(s) with the node. If not, it
3555 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3556 * adds the delayed events to the HBA work list and invokes the
3557 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3558 * event. Note that lpfc_nlp_get() is called before posting the event to
3559 * the work list to hold reference count of ndlp so that it guarantees the
3560 * reference to ndlp will still be available when the worker thread gets
3561 * to the event associated with the ndlp.
3564 lpfc_els_retry_delay(struct timer_list *t)
3566 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3567 struct lpfc_vport *vport = ndlp->vport;
3568 struct lpfc_hba *phba = vport->phba;
3569 unsigned long flags;
3570 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3572 spin_lock_irqsave(&phba->hbalock, flags);
3573 if (!list_empty(&evtp->evt_listp)) {
3574 spin_unlock_irqrestore(&phba->hbalock, flags);
3578 /* We need to hold the node by incrementing the reference
3579 * count until the queued work is done
3581 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3582 if (evtp->evt_arg1) {
3583 evtp->evt = LPFC_EVT_ELS_RETRY;
3584 list_add_tail(&evtp->evt_listp, &phba->work_list);
3585 lpfc_worker_wake_up(phba);
3587 spin_unlock_irqrestore(&phba->hbalock, flags);
3592 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3593 * @ndlp: pointer to a node-list data structure.
3595 * This routine is the worker-thread handler for processing the @ndlp delayed
3596 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3597 * the last ELS command from the associated ndlp and invokes the proper ELS
3598 * function according to the delayed ELS command to retry the command.
3601 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3603 struct lpfc_vport *vport = ndlp->vport;
3604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3605 uint32_t cmd, retry;
3607 spin_lock_irq(shost->host_lock);
3608 cmd = ndlp->nlp_last_elscmd;
3609 ndlp->nlp_last_elscmd = 0;
3611 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3612 spin_unlock_irq(shost->host_lock);
3616 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3617 spin_unlock_irq(shost->host_lock);
3619 * If a discovery event readded nlp_delayfunc after timer
3620 * firing and before processing the timer, cancel the
3623 del_timer_sync(&ndlp->nlp_delayfunc);
3624 retry = ndlp->nlp_retry;
3625 ndlp->nlp_retry = 0;
3629 lpfc_issue_els_flogi(vport, ndlp, retry);
3632 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3633 ndlp->nlp_prev_state = ndlp->nlp_state;
3634 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3638 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3639 ndlp->nlp_prev_state = ndlp->nlp_state;
3640 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3644 case ELS_CMD_NVMEPRLI:
3645 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3646 ndlp->nlp_prev_state = ndlp->nlp_state;
3647 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3651 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3652 ndlp->nlp_prev_state = ndlp->nlp_state;
3653 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3657 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3658 lpfc_issue_els_fdisc(vport, ndlp, retry);
3665 * lpfc_link_reset - Issue link reset
3666 * @vport: pointer to a virtual N_Port data structure.
3668 * This routine performs link reset by sending INIT_LINK mailbox command.
3669 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3670 * INIT_LINK mailbox command.
3673 * 0 - Link reset initiated successfully
3674 * 1 - Failed to initiate link reset
3677 lpfc_link_reset(struct lpfc_vport *vport)
3679 struct lpfc_hba *phba = vport->phba;
3684 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3685 "2851 Attempt link reset\n");
3686 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3688 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3689 "2852 Failed to allocate mbox memory");
3693 /* Enable Link attention interrupts */
3694 if (phba->sli_rev <= LPFC_SLI_REV3) {
3695 spin_lock_irq(&phba->hbalock);
3696 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3697 control = readl(phba->HCregaddr);
3698 control |= HC_LAINT_ENA;
3699 writel(control, phba->HCregaddr);
3700 readl(phba->HCregaddr); /* flush */
3701 spin_unlock_irq(&phba->hbalock);
3704 lpfc_init_link(phba, mbox, phba->cfg_topology,
3705 phba->cfg_link_speed);
3706 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3707 mbox->vport = vport;
3708 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3709 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3710 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3711 "2853 Failed to issue INIT_LINK "
3712 "mbox command, rc:x%x\n", rc);
3713 mempool_free(mbox, phba->mbox_mem_pool);
3721 * lpfc_els_retry - Make retry decision on an els command iocb
3722 * @phba: pointer to lpfc hba data structure.
3723 * @cmdiocb: pointer to lpfc command iocb data structure.
3724 * @rspiocb: pointer to lpfc response iocb data structure.
3726 * This routine makes a retry decision on an ELS command IOCB, which has
3727 * failed. The following ELS IOCBs use this function for retrying the command
3728 * when previously issued command responsed with error status: FLOGI, PLOGI,
3729 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3730 * returned error status, it makes the decision whether a retry shall be
3731 * issued for the command, and whether a retry shall be made immediately or
3732 * delayed. In the former case, the corresponding ELS command issuing-function
3733 * is called to retry the command. In the later case, the ELS command shall
3734 * be posted to the ndlp delayed event and delayed function timer set to the
3735 * ndlp for the delayed command issusing.
3738 * 0 - No retry of els command is made
3739 * 1 - Immediate or delayed retry of els command is made
3742 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3743 struct lpfc_iocbq *rspiocb)
3745 struct lpfc_vport *vport = cmdiocb->vport;
3746 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3747 IOCB_t *irsp = &rspiocb->iocb;
3748 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3749 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3752 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3756 int link_reset = 0, rc;
3759 /* Note: context2 may be 0 for internal driver abort
3760 * of delays ELS command.
3763 if (pcmd && pcmd->virt) {
3764 elscmd = (uint32_t *) (pcmd->virt);
3769 did = ndlp->nlp_DID;
3771 /* We should only hit this case for retrying PLOGI */
3772 did = irsp->un.elsreq64.remoteID;
3773 ndlp = lpfc_findnode_did(vport, did);
3774 if (!ndlp && (cmd != ELS_CMD_PLOGI))
3778 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3779 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3780 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3782 switch (irsp->ulpStatus) {
3783 case IOSTAT_FCP_RSP_ERROR:
3785 case IOSTAT_REMOTE_STOP:
3786 if (phba->sli_rev == LPFC_SLI_REV4) {
3787 /* This IO was aborted by the target, we don't
3788 * know the rxid and because we did not send the
3789 * ABTS we cannot generate and RRQ.
3791 lpfc_set_rrq_active(phba, ndlp,
3792 cmdiocb->sli4_lxritag, 0, 0);
3795 case IOSTAT_LOCAL_REJECT:
3796 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3797 case IOERR_LOOP_OPEN_FAILURE:
3798 if (cmd == ELS_CMD_FLOGI) {
3799 if (PCI_DEVICE_ID_HORNET ==
3800 phba->pcidev->device) {
3801 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3802 phba->pport->fc_myDID = 0;
3803 phba->alpa_map[0] = 0;
3804 phba->alpa_map[1] = 0;
3807 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3812 case IOERR_ILLEGAL_COMMAND:
3813 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3814 "0124 Retry illegal cmd x%x "
3815 "retry:x%x delay:x%x\n",
3816 cmd, cmdiocb->retry, delay);
3818 /* All command's retry policy */
3820 if (cmdiocb->retry > 2)
3824 case IOERR_NO_RESOURCES:
3825 logerr = 1; /* HBA out of resources */
3827 if (cmdiocb->retry > 100)
3832 case IOERR_ILLEGAL_FRAME:
3837 case IOERR_INVALID_RPI:
3838 if (cmd == ELS_CMD_PLOGI &&
3839 did == NameServer_DID) {
3840 /* Continue forever if plogi to */
3841 /* the nameserver fails */
3848 case IOERR_SEQUENCE_TIMEOUT:
3849 if (cmd == ELS_CMD_PLOGI &&
3850 did == NameServer_DID &&
3851 (cmdiocb->retry + 1) == maxretry) {
3852 /* Reset the Link */
3862 case IOSTAT_NPORT_RJT:
3863 case IOSTAT_FABRIC_RJT:
3864 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3870 case IOSTAT_NPORT_BSY:
3871 case IOSTAT_FABRIC_BSY:
3872 logerr = 1; /* Fabric / Remote NPort out of resources */
3877 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3878 /* Added for Vendor specifc support
3879 * Just keep retrying for these Rsn / Exp codes
3881 switch (stat.un.b.lsRjtRsnCode) {
3882 case LSRJT_UNABLE_TPC:
3883 /* The driver has a VALID PLOGI but the rport has
3884 * rejected the PRLI - can't do it now. Delay
3885 * for 1 second and try again.
3887 * However, if explanation is REQ_UNSUPPORTED there's
3888 * no point to retry PRLI.
3890 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3891 stat.un.b.lsRjtRsnCodeExp !=
3892 LSEXP_REQ_UNSUPPORTED) {
3894 maxretry = lpfc_max_els_tries + 1;
3899 /* Legacy bug fix code for targets with PLOGI delays. */
3900 if (stat.un.b.lsRjtRsnCodeExp ==
3901 LSEXP_CMD_IN_PROGRESS) {
3902 if (cmd == ELS_CMD_PLOGI) {
3909 if (stat.un.b.lsRjtRsnCodeExp ==
3910 LSEXP_CANT_GIVE_DATA) {
3911 if (cmd == ELS_CMD_PLOGI) {
3918 if (cmd == ELS_CMD_PLOGI) {
3920 maxretry = lpfc_max_els_tries + 1;
3924 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3925 (cmd == ELS_CMD_FDISC) &&
3926 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3927 lpfc_printf_vlog(vport, KERN_ERR,
3929 "0125 FDISC Failed (x%x). "
3930 "Fabric out of resources\n",
3931 stat.un.lsRjtError);
3932 lpfc_vport_set_state(vport,
3933 FC_VPORT_NO_FABRIC_RSCS);
3937 case LSRJT_LOGICAL_BSY:
3938 if ((cmd == ELS_CMD_PLOGI) ||
3939 (cmd == ELS_CMD_PRLI) ||
3940 (cmd == ELS_CMD_NVMEPRLI)) {
3943 } else if (cmd == ELS_CMD_FDISC) {
3944 /* FDISC retry policy */
3946 if (cmdiocb->retry >= 32)
3952 case LSRJT_LOGICAL_ERR:
3953 /* There are some cases where switches return this
3954 * error when they are not ready and should be returning
3955 * Logical Busy. We should delay every time.
3957 if (cmd == ELS_CMD_FDISC &&
3958 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3962 } else if (cmd == ELS_CMD_FLOGI &&
3963 stat.un.b.lsRjtRsnCodeExp ==
3964 LSEXP_NOTHING_MORE) {
3965 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3967 lpfc_printf_vlog(vport, KERN_ERR,
3969 "0820 FLOGI Failed (x%x). "
3970 "BBCredit Not Supported\n",
3971 stat.un.lsRjtError);
3975 case LSRJT_PROTOCOL_ERR:
3976 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3977 (cmd == ELS_CMD_FDISC) &&
3978 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3979 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3981 lpfc_printf_vlog(vport, KERN_ERR,
3983 "0122 FDISC Failed (x%x). "
3984 "Fabric Detected Bad WWN\n",
3985 stat.un.lsRjtError);
3986 lpfc_vport_set_state(vport,
3987 FC_VPORT_FABRIC_REJ_WWN);
3990 case LSRJT_VENDOR_UNIQUE:
3991 if ((stat.un.b.vendorUnique == 0x45) &&
3992 (cmd == ELS_CMD_FLOGI)) {
3996 case LSRJT_CMD_UNSUPPORTED:
3997 /* lpfc nvmet returns this type of LS_RJT when it
3998 * receives an FCP PRLI because lpfc nvmet only
3999 * support NVME. ELS request is terminated for FCP4
4002 if (stat.un.b.lsRjtRsnCodeExp ==
4003 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4004 spin_lock_irq(shost->host_lock);
4005 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4006 spin_unlock_irq(shost->host_lock);
4014 case IOSTAT_INTERMED_RSP:
4023 rc = lpfc_link_reset(vport);
4025 /* Do not give up. Retry PLOGI one more time and attempt
4026 * link reset if PLOGI fails again.
4035 if (did == FDMI_DID)
4038 if ((cmd == ELS_CMD_FLOGI) &&
4039 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4040 !lpfc_error_lost_link(irsp)) {
4041 /* FLOGI retry policy */
4043 /* retry FLOGI forever */
4044 if (phba->link_flag != LS_LOOPBACK_MODE)
4049 if (cmdiocb->retry >= 100)
4051 else if (cmdiocb->retry >= 32)
4053 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4054 /* retry FDISCs every second up to devloss */
4056 maxretry = vport->cfg_devloss_tmo;
4061 if (maxretry && (cmdiocb->retry >= maxretry)) {
4062 phba->fc_stat.elsRetryExceeded++;
4066 if ((vport->load_flag & FC_UNLOADING) != 0)
4071 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4072 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4073 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4074 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4075 "2849 Stop retry ELS command "
4076 "x%x to remote NPORT x%x, "
4077 "Data: x%x x%x\n", cmd, did,
4078 cmdiocb->retry, delay);
4083 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4084 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4085 "0107 Retry ELS command x%x to remote "
4086 "NPORT x%x Data: x%x x%x\n",
4087 cmd, did, cmdiocb->retry, delay);
4089 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4090 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4091 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4092 IOERR_NO_RESOURCES))) {
4093 /* Don't reset timer for no resources */
4095 /* If discovery / RSCN timer is running, reset it */
4096 if (timer_pending(&vport->fc_disctmo) ||
4097 (vport->fc_flag & FC_RSCN_MODE))
4098 lpfc_set_disctmo(vport);
4101 phba->fc_stat.elsXmitRetry++;
4102 if (ndlp && delay) {
4103 phba->fc_stat.elsDelayRetry++;
4104 ndlp->nlp_retry = cmdiocb->retry;
4106 /* delay is specified in milliseconds */
4107 mod_timer(&ndlp->nlp_delayfunc,
4108 jiffies + msecs_to_jiffies(delay));
4109 spin_lock_irq(shost->host_lock);
4110 ndlp->nlp_flag |= NLP_DELAY_TMO;
4111 spin_unlock_irq(shost->host_lock);
4113 ndlp->nlp_prev_state = ndlp->nlp_state;
4114 if ((cmd == ELS_CMD_PRLI) ||
4115 (cmd == ELS_CMD_NVMEPRLI))
4116 lpfc_nlp_set_state(vport, ndlp,
4117 NLP_STE_PRLI_ISSUE);
4119 lpfc_nlp_set_state(vport, ndlp,
4121 ndlp->nlp_last_elscmd = cmd;
4127 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4130 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4134 ndlp->nlp_prev_state = ndlp->nlp_state;
4135 lpfc_nlp_set_state(vport, ndlp,
4136 NLP_STE_PLOGI_ISSUE);
4138 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4141 ndlp->nlp_prev_state = ndlp->nlp_state;
4142 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4143 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4146 case ELS_CMD_NVMEPRLI:
4147 ndlp->nlp_prev_state = ndlp->nlp_state;
4148 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4149 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4152 ndlp->nlp_prev_state = ndlp->nlp_state;
4153 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4154 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4158 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4160 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4161 "0137 No retry ELS command x%x to remote "
4162 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4163 cmd, did, irsp->ulpStatus,
4164 irsp->un.ulpWord[4]);
4167 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4168 "0108 No retry ELS command x%x to remote "
4169 "NPORT x%x Retried:%d Error:x%x/%x\n",
4170 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4171 irsp->un.ulpWord[4]);
4177 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4178 * @phba: pointer to lpfc hba data structure.
4179 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4181 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4182 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4183 * checks to see whether there is a lpfc DMA buffer associated with the
4184 * response of the command IOCB. If so, it will be released before releasing
4185 * the lpfc DMA buffer associated with the IOCB itself.
4188 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4191 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4193 struct lpfc_dmabuf *buf_ptr;
4195 /* Free the response before processing the command. */
4196 if (!list_empty(&buf_ptr1->list)) {
4197 list_remove_head(&buf_ptr1->list, buf_ptr,
4200 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4203 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4209 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4210 * @phba: pointer to lpfc hba data structure.
4211 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4213 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4214 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4218 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4221 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4223 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4229 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4230 * @phba: pointer to lpfc hba data structure.
4231 * @elsiocb: pointer to lpfc els command iocb data structure.
4233 * This routine frees a command IOCB and its associated resources. The
4234 * command IOCB data structure contains the reference to various associated
4235 * resources, these fields must be set to NULL if the associated reference
4237 * context1 - reference to ndlp
4238 * context2 - reference to cmd
4239 * context2->next - reference to rsp
4240 * context3 - reference to bpl
4242 * It first properly decrements the reference count held on ndlp for the
4243 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4244 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4245 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4246 * adds the DMA buffer the @phba data structure for the delayed release.
4247 * If reference to the Buffer Pointer List (BPL) is present, the
4248 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4249 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4250 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4253 * 0 - Success (currently, always return 0)
4256 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4258 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4259 struct lpfc_nodelist *ndlp;
4261 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
4263 if (ndlp->nlp_flag & NLP_DEFER_RM) {
4266 /* If the ndlp is not being used by another discovery
4269 if (!lpfc_nlp_not_used(ndlp)) {
4270 /* If ndlp is being used by another discovery
4271 * thread, just clear NLP_DEFER_RM
4273 ndlp->nlp_flag &= ~NLP_DEFER_RM;
4278 elsiocb->context1 = NULL;
4280 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4281 if (elsiocb->context2) {
4282 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4283 /* Firmware could still be in progress of DMAing
4284 * payload, so don't free data buffer till after
4287 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4288 buf_ptr = elsiocb->context2;
4289 elsiocb->context2 = NULL;
4292 spin_lock_irq(&phba->hbalock);
4293 if (!list_empty(&buf_ptr->list)) {
4294 list_remove_head(&buf_ptr->list,
4295 buf_ptr1, struct lpfc_dmabuf,
4297 INIT_LIST_HEAD(&buf_ptr1->list);
4298 list_add_tail(&buf_ptr1->list,
4302 INIT_LIST_HEAD(&buf_ptr->list);
4303 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4305 spin_unlock_irq(&phba->hbalock);
4308 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4309 lpfc_els_free_data(phba, buf_ptr1);
4310 elsiocb->context2 = NULL;
4314 if (elsiocb->context3) {
4315 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4316 lpfc_els_free_bpl(phba, buf_ptr);
4317 elsiocb->context3 = NULL;
4319 lpfc_sli_release_iocbq(phba, elsiocb);
4324 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4325 * @phba: pointer to lpfc hba data structure.
4326 * @cmdiocb: pointer to lpfc command iocb data structure.
4327 * @rspiocb: pointer to lpfc response iocb data structure.
4329 * This routine is the completion callback function to the Logout (LOGO)
4330 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4331 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4332 * release the ndlp if it has the last reference remaining (reference count
4333 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4334 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4335 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4336 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4337 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4338 * IOCB data structure.
4341 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4342 struct lpfc_iocbq *rspiocb)
4344 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4345 struct lpfc_vport *vport = cmdiocb->vport;
4348 irsp = &rspiocb->iocb;
4349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4350 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4351 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4352 /* ACC to LOGO completes to NPort <nlp_DID> */
4353 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4354 "0109 ACC to LOGO completes to NPort x%x "
4355 "Data: x%x x%x x%x\n",
4356 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4359 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4360 /* NPort Recovery mode or node is just allocated */
4361 if (!lpfc_nlp_not_used(ndlp)) {
4362 /* If the ndlp is being used by another discovery
4363 * thread, just unregister the RPI.
4365 lpfc_unreg_rpi(vport, ndlp);
4367 /* Indicate the node has already released, should
4368 * not reference to it from within lpfc_els_free_iocb.
4370 cmdiocb->context1 = NULL;
4375 * The driver received a LOGO from the rport and has ACK'd it.
4376 * At this point, the driver is done so release the IOCB
4378 lpfc_els_free_iocb(phba, cmdiocb);
4382 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4383 * @phba: pointer to lpfc hba data structure.
4384 * @pmb: pointer to the driver internal queue element for mailbox command.
4386 * This routine is the completion callback function for unregister default
4387 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4388 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4389 * decrements the ndlp reference count held for this completion callback
4390 * function. After that, it invokes the lpfc_nlp_not_used() to check
4391 * whether there is only one reference left on the ndlp. If so, it will
4392 * perform one more decrement and trigger the release of the ndlp.
4395 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4397 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4398 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4400 pmb->ctx_buf = NULL;
4401 pmb->ctx_ndlp = NULL;
4403 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4405 mempool_free(pmb, phba->mbox_mem_pool);
4407 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4408 "0006 rpi%x DID:%x flg:%x %d x%px\n",
4409 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4410 kref_read(&ndlp->kref),
4413 /* This is the end of the default RPI cleanup logic for
4414 * this ndlp. If no other discovery threads are using
4415 * this ndlp, free all resources associated with it.
4417 lpfc_nlp_not_used(ndlp);
4424 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4425 * @phba: pointer to lpfc hba data structure.
4426 * @cmdiocb: pointer to lpfc command iocb data structure.
4427 * @rspiocb: pointer to lpfc response iocb data structure.
4429 * This routine is the completion callback function for ELS Response IOCB
4430 * command. In normal case, this callback function just properly sets the
4431 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4432 * field in the command IOCB is not NULL, the referred mailbox command will
4433 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4434 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4435 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4436 * routine shall be invoked trying to release the ndlp if no other threads
4437 * are currently referring it.
4440 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4441 struct lpfc_iocbq *rspiocb)
4443 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4444 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4445 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4448 LPFC_MBOXQ_t *mbox = NULL;
4449 struct lpfc_dmabuf *mp = NULL;
4450 uint32_t ls_rjt = 0;
4452 irsp = &rspiocb->iocb;
4455 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4456 "3177 ELS response failed\n");
4459 if (cmdiocb->context_un.mbox)
4460 mbox = cmdiocb->context_un.mbox;
4462 /* First determine if this is a LS_RJT cmpl. Note, this callback
4463 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4465 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4466 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4467 /* A LS_RJT associated with Default RPI cleanup has its own
4468 * separate code path.
4470 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4474 /* Check to see if link went down during discovery */
4475 if (!ndlp || lpfc_els_chk_latt(vport)) {
4477 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4479 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4482 mempool_free(mbox, phba->mbox_mem_pool);
4484 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4485 if (lpfc_nlp_not_used(ndlp)) {
4487 /* Indicate the node has already released,
4488 * should not reference to it from within
4489 * the routine lpfc_els_free_iocb.
4491 cmdiocb->context1 = NULL;
4496 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4497 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4498 irsp->ulpStatus, irsp->un.ulpWord[4],
4499 cmdiocb->iocb.un.elsreq64.remoteID);
4500 /* ELS response tag <ulpIoTag> completes */
4501 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4502 "0110 ELS response tag x%x completes "
4503 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4504 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4505 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4506 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4509 if ((rspiocb->iocb.ulpStatus == 0)
4510 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4511 if (!lpfc_unreg_rpi(vport, ndlp) &&
4512 (!(vport->fc_flag & FC_PT2PT)) &&
4513 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4514 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4515 lpfc_printf_vlog(vport, KERN_INFO,
4517 "0314 PLOGI recov DID x%x "
4518 "Data: x%x x%x x%x\n",
4519 ndlp->nlp_DID, ndlp->nlp_state,
4520 ndlp->nlp_rpi, ndlp->nlp_flag);
4523 lpfc_mbuf_free(phba, mp->virt,
4527 mempool_free(mbox, phba->mbox_mem_pool);
4531 /* Increment reference count to ndlp to hold the
4532 * reference to ndlp for the callback function.
4534 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4535 mbox->vport = vport;
4536 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4537 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4538 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4541 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4542 ndlp->nlp_prev_state = ndlp->nlp_state;
4543 lpfc_nlp_set_state(vport, ndlp,
4544 NLP_STE_REG_LOGIN_ISSUE);
4547 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4548 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4549 != MBX_NOT_FINISHED)
4552 /* Decrement the ndlp reference count we
4553 * set for this failed mailbox command.
4556 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4558 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4559 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4560 "0138 ELS rsp: Cannot issue reg_login for x%x "
4561 "Data: x%x x%x x%x\n",
4562 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4565 if (lpfc_nlp_not_used(ndlp)) {
4567 /* Indicate node has already been released,
4568 * should not reference to it from within
4569 * the routine lpfc_els_free_iocb.
4571 cmdiocb->context1 = NULL;
4574 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4575 if (!lpfc_error_lost_link(irsp) &&
4576 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4577 if (lpfc_nlp_not_used(ndlp)) {
4579 /* Indicate node has already been
4580 * released, should not reference
4581 * to it from within the routine
4582 * lpfc_els_free_iocb.
4584 cmdiocb->context1 = NULL;
4588 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4590 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4593 mempool_free(mbox, phba->mbox_mem_pool);
4596 if (ndlp && shost) {
4597 spin_lock_irq(shost->host_lock);
4599 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4600 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4601 spin_unlock_irq(shost->host_lock);
4603 /* If the node is not being used by another discovery thread,
4604 * and we are sending a reject, we are done with it.
4605 * Release driver reference count here and free associated
4609 if (lpfc_nlp_not_used(ndlp))
4610 /* Indicate node has already been released,
4611 * should not reference to it from within
4612 * the routine lpfc_els_free_iocb.
4614 cmdiocb->context1 = NULL;
4618 lpfc_els_free_iocb(phba, cmdiocb);
4623 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4624 * @vport: pointer to a host virtual N_Port data structure.
4625 * @flag: the els command code to be accepted.
4626 * @oldiocb: pointer to the original lpfc command iocb data structure.
4627 * @ndlp: pointer to a node-list data structure.
4628 * @mbox: pointer to the driver internal queue element for mailbox command.
4630 * This routine prepares and issues an Accept (ACC) response IOCB
4631 * command. It uses the @flag to properly set up the IOCB field for the
4632 * specific ACC response command to be issued and invokes the
4633 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4634 * @mbox pointer is passed in, it will be put into the context_un.mbox
4635 * field of the IOCB for the completion callback function to issue the
4636 * mailbox command to the HBA later when callback is invoked.
4638 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4639 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4640 * will be stored into the context1 field of the IOCB for the completion
4641 * callback function to the corresponding response ELS IOCB command.
4644 * 0 - Successfully issued acc response
4645 * 1 - Failed to issue acc response
4648 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4649 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4653 struct lpfc_hba *phba = vport->phba;
4656 struct lpfc_iocbq *elsiocb;
4658 struct serv_parm *sp;
4661 ELS_PKT *els_pkt_ptr;
4663 oldcmd = &oldiocb->iocb;
4667 cmdsize = sizeof(uint32_t);
4668 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4669 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4671 spin_lock_irq(shost->host_lock);
4672 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4673 spin_unlock_irq(shost->host_lock);
4677 icmd = &elsiocb->iocb;
4678 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4679 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4680 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4681 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4682 pcmd += sizeof(uint32_t);
4684 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4685 "Issue ACC: did:x%x flg:x%x",
4686 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4690 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4691 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4692 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4696 icmd = &elsiocb->iocb;
4697 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4698 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4699 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4702 elsiocb->context_un.mbox = mbox;
4704 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4705 pcmd += sizeof(uint32_t);
4706 sp = (struct serv_parm *)pcmd;
4708 if (flag == ELS_CMD_FLOGI) {
4709 /* Copy the received service parameters back */
4710 memcpy(sp, &phba->fc_fabparam,
4711 sizeof(struct serv_parm));
4713 /* Clear the F_Port bit */
4716 /* Mark all class service parameters as invalid */
4717 sp->cls1.classValid = 0;
4718 sp->cls2.classValid = 0;
4719 sp->cls3.classValid = 0;
4720 sp->cls4.classValid = 0;
4722 /* Copy our worldwide names */
4723 memcpy(&sp->portName, &vport->fc_sparam.portName,
4724 sizeof(struct lpfc_name));
4725 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4726 sizeof(struct lpfc_name));
4728 memcpy(pcmd, &vport->fc_sparam,
4729 sizeof(struct serv_parm));
4731 sp->cmn.valid_vendor_ver_level = 0;
4732 memset(sp->un.vendorVersion, 0,
4733 sizeof(sp->un.vendorVersion));
4734 sp->cmn.bbRcvSizeMsb &= 0xF;
4736 /* If our firmware supports this feature, convey that
4737 * info to the target using the vendor specific field.
4739 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4740 sp->cmn.valid_vendor_ver_level = 1;
4741 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4743 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4747 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4748 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4749 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4752 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4753 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4754 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4758 icmd = &elsiocb->iocb;
4759 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4760 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4761 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4763 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4764 sizeof(uint32_t) + sizeof(PRLO));
4765 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4766 els_pkt_ptr = (ELS_PKT *) pcmd;
4767 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4770 "Issue ACC PRLO: did:x%x flg:x%x",
4771 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4776 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4777 spin_lock_irq(shost->host_lock);
4778 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4779 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4780 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4781 spin_unlock_irq(shost->host_lock);
4782 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4784 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4787 phba->fc_stat.elsXmitACC++;
4788 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4789 if (rc == IOCB_ERROR) {
4790 lpfc_els_free_iocb(phba, elsiocb);
4797 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4798 * @vport: pointer to a virtual N_Port data structure.
4799 * @rejectError: reject response to issue
4800 * @oldiocb: pointer to the original lpfc command iocb data structure.
4801 * @ndlp: pointer to a node-list data structure.
4802 * @mbox: pointer to the driver internal queue element for mailbox command.
4804 * This routine prepares and issue an Reject (RJT) response IOCB
4805 * command. If a @mbox pointer is passed in, it will be put into the
4806 * context_un.mbox field of the IOCB for the completion callback function
4807 * to issue to the HBA later.
4809 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4810 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4811 * will be stored into the context1 field of the IOCB for the completion
4812 * callback function to the reject response ELS IOCB command.
4815 * 0 - Successfully issued reject response
4816 * 1 - Failed to issue reject response
4819 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4820 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4823 struct lpfc_hba *phba = vport->phba;
4826 struct lpfc_iocbq *elsiocb;
4831 cmdsize = 2 * sizeof(uint32_t);
4832 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4833 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4837 icmd = &elsiocb->iocb;
4838 oldcmd = &oldiocb->iocb;
4839 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4840 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4841 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4843 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4844 pcmd += sizeof(uint32_t);
4845 *((uint32_t *) (pcmd)) = rejectError;
4848 elsiocb->context_un.mbox = mbox;
4850 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4851 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4852 "0129 Xmit ELS RJT x%x response tag x%x "
4853 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4855 rejectError, elsiocb->iotag,
4856 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4857 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4858 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4859 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4860 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4862 phba->fc_stat.elsXmitLSRJT++;
4863 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4864 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4866 if (rc == IOCB_ERROR) {
4867 lpfc_els_free_iocb(phba, elsiocb);
4874 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4875 * @vport: pointer to a virtual N_Port data structure.
4876 * @oldiocb: pointer to the original lpfc command iocb data structure.
4877 * @ndlp: pointer to a node-list data structure.
4879 * This routine prepares and issues an Accept (ACC) response to Address
4880 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4881 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4883 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4884 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4885 * will be stored into the context1 field of the IOCB for the completion
4886 * callback function to the ADISC Accept response ELS IOCB command.
4889 * 0 - Successfully issued acc adisc response
4890 * 1 - Failed to issue adisc acc response
4893 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4894 struct lpfc_nodelist *ndlp)
4896 struct lpfc_hba *phba = vport->phba;
4898 IOCB_t *icmd, *oldcmd;
4899 struct lpfc_iocbq *elsiocb;
4904 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4905 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4906 ndlp->nlp_DID, ELS_CMD_ACC);
4910 icmd = &elsiocb->iocb;
4911 oldcmd = &oldiocb->iocb;
4912 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4913 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4915 /* Xmit ADISC ACC response tag <ulpIoTag> */
4916 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4917 "0130 Xmit ADISC ACC response iotag x%x xri: "
4918 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4919 elsiocb->iotag, elsiocb->iocb.ulpContext,
4920 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4922 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4924 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4925 pcmd += sizeof(uint32_t);
4927 ap = (ADISC *) (pcmd);
4928 ap->hardAL_PA = phba->fc_pref_ALPA;
4929 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4930 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4931 ap->DID = be32_to_cpu(vport->fc_myDID);
4933 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4934 "Issue ACC ADISC: did:x%x flg:x%x",
4935 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4937 phba->fc_stat.elsXmitACC++;
4938 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4939 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4940 if (rc == IOCB_ERROR) {
4941 lpfc_els_free_iocb(phba, elsiocb);
4945 /* Xmit ELS ACC response tag <ulpIoTag> */
4946 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4947 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4948 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4949 "RPI: x%x, fc_flag x%x\n",
4950 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4951 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4952 ndlp->nlp_rpi, vport->fc_flag);
4957 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4958 * @vport: pointer to a virtual N_Port data structure.
4959 * @oldiocb: pointer to the original lpfc command iocb data structure.
4960 * @ndlp: pointer to a node-list data structure.
4962 * This routine prepares and issues an Accept (ACC) response to Process
4963 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4964 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4966 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4967 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4968 * will be stored into the context1 field of the IOCB for the completion
4969 * callback function to the PRLI Accept response ELS IOCB command.
4972 * 0 - Successfully issued acc prli response
4973 * 1 - Failed to issue acc prli response
4976 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4977 struct lpfc_nodelist *ndlp)
4979 struct lpfc_hba *phba = vport->phba;
4981 struct lpfc_nvme_prli *npr_nvme;
4985 struct lpfc_iocbq *elsiocb;
4988 uint32_t prli_fc4_req, *req_payload;
4989 struct lpfc_dmabuf *req_buf;
4993 /* Need the incoming PRLI payload to determine if the ACC is for an
4994 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4996 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4997 req_payload = (((uint32_t *)req_buf->virt) + 1);
4999 /* PRLI type payload is at byte 3 for FCP or NVME. */
5000 prli_fc4_req = be32_to_cpu(*req_payload);
5001 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5002 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5003 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5004 prli_fc4_req, *((uint32_t *)req_payload));
5006 if (prli_fc4_req == PRLI_FCP_TYPE) {
5007 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5008 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5009 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5010 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5011 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5016 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5017 ndlp->nlp_DID, elsrspcmd);
5021 icmd = &elsiocb->iocb;
5022 oldcmd = &oldiocb->iocb;
5023 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5024 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5026 /* Xmit PRLI ACC response tag <ulpIoTag> */
5027 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5028 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5029 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5030 elsiocb->iotag, elsiocb->iocb.ulpContext,
5031 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5033 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5034 memset(pcmd, 0, cmdsize);
5036 *((uint32_t *)(pcmd)) = elsrspcmd;
5037 pcmd += sizeof(uint32_t);
5039 /* For PRLI, remainder of payload is PRLI parameter page */
5042 if (prli_fc4_req == PRLI_FCP_TYPE) {
5044 * If the remote port is a target and our firmware version
5045 * is 3.20 or later, set the following bits for FC-TAPE
5048 npr = (PRLI *) pcmd;
5049 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5050 (vpd->rev.feaLevelHigh >= 0x02)) {
5051 npr->ConfmComplAllowed = 1;
5053 npr->TaskRetryIdReq = 1;
5055 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5056 npr->estabImagePair = 1;
5057 npr->readXferRdyDis = 1;
5058 npr->ConfmComplAllowed = 1;
5059 npr->prliType = PRLI_FCP_TYPE;
5060 npr->initiatorFunc = 1;
5061 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5062 /* Respond with an NVME PRLI Type */
5063 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5064 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5065 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5066 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5067 if (phba->nvmet_support) {
5068 bf_set(prli_tgt, npr_nvme, 1);
5069 bf_set(prli_disc, npr_nvme, 1);
5070 if (phba->cfg_nvme_enable_fb) {
5071 bf_set(prli_fba, npr_nvme, 1);
5073 /* TBD. Target mode needs to post buffers
5074 * that support the configured first burst
5077 bf_set(prli_fb_sz, npr_nvme,
5078 phba->cfg_nvmet_fb_size);
5081 bf_set(prli_init, npr_nvme, 1);
5084 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5085 "6015 NVME issue PRLI ACC word1 x%08x "
5086 "word4 x%08x word5 x%08x flag x%x, "
5087 "fcp_info x%x nlp_type x%x\n",
5088 npr_nvme->word1, npr_nvme->word4,
5089 npr_nvme->word5, ndlp->nlp_flag,
5090 ndlp->nlp_fcp_info, ndlp->nlp_type);
5091 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5092 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5093 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5095 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5096 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5097 prli_fc4_req, ndlp->nlp_fc4_type,
5100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5101 "Issue ACC PRLI: did:x%x flg:x%x",
5102 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5104 phba->fc_stat.elsXmitACC++;
5105 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5107 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5108 if (rc == IOCB_ERROR) {
5109 lpfc_els_free_iocb(phba, elsiocb);
5116 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5117 * @vport: pointer to a virtual N_Port data structure.
5118 * @format: rnid command format.
5119 * @oldiocb: pointer to the original lpfc command iocb data structure.
5120 * @ndlp: pointer to a node-list data structure.
5122 * This routine issues a Request Node Identification Data (RNID) Accept
5123 * (ACC) response. It constructs the RNID ACC response command according to
5124 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5125 * issue the response. Note that this command does not need to hold the ndlp
5126 * reference count for the callback. So, the ndlp reference count taken by
5127 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5128 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5129 * there is no ndlp reference available.
5131 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5132 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5133 * will be stored into the context1 field of the IOCB for the completion
5134 * callback function. However, for the RNID Accept Response ELS command,
5135 * this is undone later by this routine after the IOCB is allocated.
5138 * 0 - Successfully issued acc rnid response
5139 * 1 - Failed to issue acc rnid response
5142 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5143 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5145 struct lpfc_hba *phba = vport->phba;
5147 IOCB_t *icmd, *oldcmd;
5148 struct lpfc_iocbq *elsiocb;
5153 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5154 + (2 * sizeof(struct lpfc_name));
5156 cmdsize += sizeof(RNID_TOP_DISC);
5158 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5159 ndlp->nlp_DID, ELS_CMD_ACC);
5163 icmd = &elsiocb->iocb;
5164 oldcmd = &oldiocb->iocb;
5165 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5166 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5168 /* Xmit RNID ACC response tag <ulpIoTag> */
5169 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5170 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5171 elsiocb->iotag, elsiocb->iocb.ulpContext);
5172 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5173 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5174 pcmd += sizeof(uint32_t);
5176 memset(pcmd, 0, sizeof(RNID));
5177 rn = (RNID *) (pcmd);
5178 rn->Format = format;
5179 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5180 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5181 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5184 rn->SpecificLen = 0;
5186 case RNID_TOPOLOGY_DISC:
5187 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5188 memcpy(&rn->un.topologyDisc.portName,
5189 &vport->fc_portname, sizeof(struct lpfc_name));
5190 rn->un.topologyDisc.unitType = RNID_HBA;
5191 rn->un.topologyDisc.physPort = 0;
5192 rn->un.topologyDisc.attachedNodes = 0;
5196 rn->SpecificLen = 0;
5200 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5201 "Issue ACC RNID: did:x%x flg:x%x",
5202 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5204 phba->fc_stat.elsXmitACC++;
5205 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5207 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5208 if (rc == IOCB_ERROR) {
5209 lpfc_els_free_iocb(phba, elsiocb);
5216 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5217 * @vport: pointer to a virtual N_Port data structure.
5218 * @iocb: pointer to the lpfc command iocb data structure.
5219 * @ndlp: pointer to a node-list data structure.
5224 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5225 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5227 struct lpfc_hba *phba = vport->phba;
5232 struct lpfc_node_rrq *prrq;
5235 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5236 pcmd += sizeof(uint32_t);
5237 rrq = (struct RRQ *)pcmd;
5238 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5239 rxid = bf_get(rrq_rxid, rrq);
5241 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5242 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5244 be32_to_cpu(bf_get(rrq_did, rrq)),
5245 bf_get(rrq_oxid, rrq),
5247 iocb->iotag, iocb->iocb.ulpContext);
5249 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5250 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5251 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5252 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5253 xri = bf_get(rrq_oxid, rrq);
5256 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5258 lpfc_clr_rrq_active(phba, xri, prrq);
5263 * lpfc_els_rsp_echo_acc - Issue echo acc response
5264 * @vport: pointer to a virtual N_Port data structure.
5265 * @data: pointer to echo data to return in the accept.
5266 * @oldiocb: pointer to the original lpfc command iocb data structure.
5267 * @ndlp: pointer to a node-list data structure.
5270 * 0 - Successfully issued acc echo response
5271 * 1 - Failed to issue acc echo response
5274 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5275 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5277 struct lpfc_hba *phba = vport->phba;
5278 struct lpfc_iocbq *elsiocb;
5283 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5285 /* The accumulated length can exceed the BPL_SIZE. For
5286 * now, use this as the limit
5288 if (cmdsize > LPFC_BPL_SIZE)
5289 cmdsize = LPFC_BPL_SIZE;
5290 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5291 ndlp->nlp_DID, ELS_CMD_ACC);
5295 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5296 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5298 /* Xmit ECHO ACC response tag <ulpIoTag> */
5299 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5300 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5301 elsiocb->iotag, elsiocb->iocb.ulpContext);
5302 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5303 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5304 pcmd += sizeof(uint32_t);
5305 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5307 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5308 "Issue ACC ECHO: did:x%x flg:x%x",
5309 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5311 phba->fc_stat.elsXmitACC++;
5312 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5314 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5315 if (rc == IOCB_ERROR) {
5316 lpfc_els_free_iocb(phba, elsiocb);
5323 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5324 * @vport: pointer to a host virtual N_Port data structure.
5326 * This routine issues Address Discover (ADISC) ELS commands to those
5327 * N_Ports which are in node port recovery state and ADISC has not been issued
5328 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5329 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5330 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5331 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5332 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5333 * IOCBs quit for later pick up. On the other hand, after walking through
5334 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5335 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5336 * no more ADISC need to be sent.
5339 * The number of N_Ports with adisc issued.
5342 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5344 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5345 struct lpfc_nodelist *ndlp, *next_ndlp;
5348 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5349 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5350 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5351 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5352 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5353 spin_lock_irq(shost->host_lock);
5354 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5355 spin_unlock_irq(shost->host_lock);
5356 ndlp->nlp_prev_state = ndlp->nlp_state;
5357 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5358 lpfc_issue_els_adisc(vport, ndlp, 0);
5360 vport->num_disc_nodes++;
5361 if (vport->num_disc_nodes >=
5362 vport->cfg_discovery_threads) {
5363 spin_lock_irq(shost->host_lock);
5364 vport->fc_flag |= FC_NLP_MORE;
5365 spin_unlock_irq(shost->host_lock);
5370 if (sentadisc == 0) {
5371 spin_lock_irq(shost->host_lock);
5372 vport->fc_flag &= ~FC_NLP_MORE;
5373 spin_unlock_irq(shost->host_lock);
5379 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5380 * @vport: pointer to a host virtual N_Port data structure.
5382 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5383 * which are in node port recovery state, with a @vport. Each time an ELS
5384 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5385 * the per @vport number of discover count (num_disc_nodes) shall be
5386 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5387 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5388 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5389 * later pick up. On the other hand, after walking through all the ndlps with
5390 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5391 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5392 * PLOGI need to be sent.
5395 * The number of N_Ports with plogi issued.
5398 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5400 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5401 struct lpfc_nodelist *ndlp, *next_ndlp;
5404 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5405 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5406 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5407 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5408 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5409 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5410 ndlp->nlp_prev_state = ndlp->nlp_state;
5411 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5412 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5414 vport->num_disc_nodes++;
5415 if (vport->num_disc_nodes >=
5416 vport->cfg_discovery_threads) {
5417 spin_lock_irq(shost->host_lock);
5418 vport->fc_flag |= FC_NLP_MORE;
5419 spin_unlock_irq(shost->host_lock);
5425 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5426 "6452 Discover PLOGI %d flag x%x\n",
5427 sentplogi, vport->fc_flag);
5430 lpfc_set_disctmo(vport);
5433 spin_lock_irq(shost->host_lock);
5434 vport->fc_flag &= ~FC_NLP_MORE;
5435 spin_unlock_irq(shost->host_lock);
5441 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5445 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5446 desc->payload.els_req = word0;
5447 desc->length = cpu_to_be32(sizeof(desc->payload));
5449 return sizeof(struct fc_rdp_link_service_desc);
5453 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5454 uint8_t *page_a0, uint8_t *page_a2)
5456 uint16_t wavelength;
5457 uint16_t temperature;
5463 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5464 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5466 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5468 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5469 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5470 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5471 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5473 if ((trasn_code_byte4->fc_sw_laser) ||
5474 (trasn_code_byte5->fc_sw_laser_sl) ||
5475 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5476 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5477 } else if (trasn_code_byte4->fc_lw_laser) {
5478 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5479 page_a0[SSF_WAVELENGTH_B0];
5480 if (wavelength == SFP_WAVELENGTH_LC1310)
5481 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5482 if (wavelength == SFP_WAVELENGTH_LL1550)
5483 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5485 /* check if its SFP+ */
5486 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5487 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5488 << SFP_FLAG_CT_SHIFT;
5490 /* check if its OPTICAL */
5491 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5492 SFP_FLAG_IS_OPTICAL_PORT : 0)
5493 << SFP_FLAG_IS_OPTICAL_SHIFT;
5495 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5496 page_a2[SFF_TEMPERATURE_B0]);
5497 vcc = (page_a2[SFF_VCC_B1] << 8 |
5498 page_a2[SFF_VCC_B0]);
5499 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5500 page_a2[SFF_TXPOWER_B0]);
5501 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5502 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5503 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5504 page_a2[SFF_RXPOWER_B0]);
5505 desc->sfp_info.temperature = cpu_to_be16(temperature);
5506 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5507 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5508 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5509 desc->sfp_info.vcc = cpu_to_be16(vcc);
5511 desc->sfp_info.flags = cpu_to_be16(flag);
5512 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5514 return sizeof(struct fc_rdp_sfp_desc);
5518 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5523 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5525 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5527 desc->info.port_type = cpu_to_be32(type);
5529 desc->info.link_status.link_failure_cnt =
5530 cpu_to_be32(stat->linkFailureCnt);
5531 desc->info.link_status.loss_of_synch_cnt =
5532 cpu_to_be32(stat->lossSyncCnt);
5533 desc->info.link_status.loss_of_signal_cnt =
5534 cpu_to_be32(stat->lossSignalCnt);
5535 desc->info.link_status.primitive_seq_proto_err =
5536 cpu_to_be32(stat->primSeqErrCnt);
5537 desc->info.link_status.invalid_trans_word =
5538 cpu_to_be32(stat->invalidXmitWord);
5539 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5541 desc->length = cpu_to_be32(sizeof(desc->info));
5543 return sizeof(struct fc_rdp_link_error_status_desc);
5547 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5548 struct lpfc_vport *vport)
5552 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5554 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5555 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5556 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5557 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5558 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5559 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5560 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5562 desc->bbc_info.attached_port_bbc = 0;
5565 desc->bbc_info.rtt = 0;
5566 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5568 return sizeof(struct fc_rdp_bbc_desc);
5572 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5573 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5577 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5579 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5580 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5581 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5582 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5584 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5585 flags |= RDP_OET_HIGH_ALARM;
5586 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5587 flags |= RDP_OET_LOW_ALARM;
5588 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5589 flags |= RDP_OET_HIGH_WARNING;
5590 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5591 flags |= RDP_OET_LOW_WARNING;
5593 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5594 desc->oed_info.function_flags = cpu_to_be32(flags);
5595 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5596 return sizeof(struct fc_rdp_oed_sfp_desc);
5600 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5601 struct fc_rdp_oed_sfp_desc *desc,
5606 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5608 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5609 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5610 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5611 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5613 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5614 flags |= RDP_OET_HIGH_ALARM;
5615 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5616 flags |= RDP_OET_LOW_ALARM;
5617 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5618 flags |= RDP_OET_HIGH_WARNING;
5619 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5620 flags |= RDP_OET_LOW_WARNING;
5622 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5623 desc->oed_info.function_flags = cpu_to_be32(flags);
5624 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5625 return sizeof(struct fc_rdp_oed_sfp_desc);
5629 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5630 struct fc_rdp_oed_sfp_desc *desc,
5635 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5637 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5638 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5639 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5640 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5642 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5643 flags |= RDP_OET_HIGH_ALARM;
5644 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5645 flags |= RDP_OET_LOW_ALARM;
5646 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5647 flags |= RDP_OET_HIGH_WARNING;
5648 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5649 flags |= RDP_OET_LOW_WARNING;
5651 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5652 desc->oed_info.function_flags = cpu_to_be32(flags);
5653 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5654 return sizeof(struct fc_rdp_oed_sfp_desc);
5658 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5659 struct fc_rdp_oed_sfp_desc *desc,
5664 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5666 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5667 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5668 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5669 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5671 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5672 flags |= RDP_OET_HIGH_ALARM;
5673 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5674 flags |= RDP_OET_LOW_ALARM;
5675 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5676 flags |= RDP_OET_HIGH_WARNING;
5677 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5678 flags |= RDP_OET_LOW_WARNING;
5680 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5681 desc->oed_info.function_flags = cpu_to_be32(flags);
5682 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5683 return sizeof(struct fc_rdp_oed_sfp_desc);
5688 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5689 struct fc_rdp_oed_sfp_desc *desc,
5694 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5696 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5697 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5698 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5699 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5701 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5702 flags |= RDP_OET_HIGH_ALARM;
5703 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5704 flags |= RDP_OET_LOW_ALARM;
5705 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5706 flags |= RDP_OET_HIGH_WARNING;
5707 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5708 flags |= RDP_OET_LOW_WARNING;
5710 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5711 desc->oed_info.function_flags = cpu_to_be32(flags);
5712 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5713 return sizeof(struct fc_rdp_oed_sfp_desc);
5717 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5718 uint8_t *page_a0, struct lpfc_vport *vport)
5720 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5721 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5722 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5723 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5724 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5725 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5726 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5727 return sizeof(struct fc_rdp_opd_sfp_desc);
5731 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5733 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5735 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5737 desc->info.CorrectedBlocks =
5738 cpu_to_be32(stat->fecCorrBlkCount);
5739 desc->info.UncorrectableBlocks =
5740 cpu_to_be32(stat->fecUncorrBlkCount);
5742 desc->length = cpu_to_be32(sizeof(desc->info));
5744 return sizeof(struct fc_fec_rdp_desc);
5748 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5750 uint16_t rdp_cap = 0;
5753 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5755 switch (phba->fc_linkspeed) {
5756 case LPFC_LINK_SPEED_1GHZ:
5757 rdp_speed = RDP_PS_1GB;
5759 case LPFC_LINK_SPEED_2GHZ:
5760 rdp_speed = RDP_PS_2GB;
5762 case LPFC_LINK_SPEED_4GHZ:
5763 rdp_speed = RDP_PS_4GB;
5765 case LPFC_LINK_SPEED_8GHZ:
5766 rdp_speed = RDP_PS_8GB;
5768 case LPFC_LINK_SPEED_10GHZ:
5769 rdp_speed = RDP_PS_10GB;
5771 case LPFC_LINK_SPEED_16GHZ:
5772 rdp_speed = RDP_PS_16GB;
5774 case LPFC_LINK_SPEED_32GHZ:
5775 rdp_speed = RDP_PS_32GB;
5777 case LPFC_LINK_SPEED_64GHZ:
5778 rdp_speed = RDP_PS_64GB;
5781 rdp_speed = RDP_PS_UNKNOWN;
5785 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5787 if (phba->lmt & LMT_128Gb)
5788 rdp_cap |= RDP_PS_128GB;
5789 if (phba->lmt & LMT_64Gb)
5790 rdp_cap |= RDP_PS_64GB;
5791 if (phba->lmt & LMT_32Gb)
5792 rdp_cap |= RDP_PS_32GB;
5793 if (phba->lmt & LMT_16Gb)
5794 rdp_cap |= RDP_PS_16GB;
5795 if (phba->lmt & LMT_10Gb)
5796 rdp_cap |= RDP_PS_10GB;
5797 if (phba->lmt & LMT_8Gb)
5798 rdp_cap |= RDP_PS_8GB;
5799 if (phba->lmt & LMT_4Gb)
5800 rdp_cap |= RDP_PS_4GB;
5801 if (phba->lmt & LMT_2Gb)
5802 rdp_cap |= RDP_PS_2GB;
5803 if (phba->lmt & LMT_1Gb)
5804 rdp_cap |= RDP_PS_1GB;
5807 rdp_cap = RDP_CAP_UNKNOWN;
5808 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5809 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5811 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5812 desc->length = cpu_to_be32(sizeof(desc->info));
5813 return sizeof(struct fc_rdp_port_speed_desc);
5817 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5818 struct lpfc_vport *vport)
5821 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5823 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5824 sizeof(desc->port_names.wwnn));
5826 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5827 sizeof(desc->port_names.wwpn));
5829 desc->length = cpu_to_be32(sizeof(desc->port_names));
5830 return sizeof(struct fc_rdp_port_name_desc);
5834 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5835 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5838 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5839 if (vport->fc_flag & FC_FABRIC) {
5840 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5841 sizeof(desc->port_names.wwnn));
5843 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5844 sizeof(desc->port_names.wwpn));
5845 } else { /* Point to Point */
5846 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5847 sizeof(desc->port_names.wwnn));
5849 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5850 sizeof(desc->port_names.wwpn));
5853 desc->length = cpu_to_be32(sizeof(desc->port_names));
5854 return sizeof(struct fc_rdp_port_name_desc);
5858 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5861 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5862 struct lpfc_vport *vport = ndlp->vport;
5863 struct lpfc_iocbq *elsiocb;
5864 struct ulp_bde64 *bpl;
5867 struct ls_rjt *stat;
5868 struct fc_rdp_res_frame *rdp_res;
5869 uint32_t cmdsize, len;
5873 if (status != SUCCESS)
5876 /* This will change once we know the true size of the RDP payload */
5877 cmdsize = sizeof(struct fc_rdp_res_frame);
5879 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5880 lpfc_max_els_tries, rdp_context->ndlp,
5881 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5884 goto free_rdp_context;
5886 icmd = &elsiocb->iocb;
5887 icmd->ulpContext = rdp_context->rx_id;
5888 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5890 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5891 "2171 Xmit RDP response tag x%x xri x%x, "
5892 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5893 elsiocb->iotag, elsiocb->iocb.ulpContext,
5894 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5896 rdp_res = (struct fc_rdp_res_frame *)
5897 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5898 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5899 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5900 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5902 /* Update Alarm and Warning */
5903 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5904 phba->sfp_alarm |= *flag_ptr;
5905 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5906 phba->sfp_warning |= *flag_ptr;
5908 /* For RDP payload */
5910 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5911 (len + pcmd), ELS_CMD_RDP);
5913 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5914 rdp_context->page_a0, rdp_context->page_a2);
5915 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5917 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5918 (len + pcmd), &rdp_context->link_stat);
5919 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5920 (len + pcmd), vport);
5921 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5922 (len + pcmd), vport, ndlp);
5923 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5924 &rdp_context->link_stat);
5925 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5926 &rdp_context->link_stat, vport);
5927 len += lpfc_rdp_res_oed_temp_desc(phba,
5928 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5929 rdp_context->page_a2);
5930 len += lpfc_rdp_res_oed_voltage_desc(phba,
5931 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5932 rdp_context->page_a2);
5933 len += lpfc_rdp_res_oed_txbias_desc(phba,
5934 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5935 rdp_context->page_a2);
5936 len += lpfc_rdp_res_oed_txpower_desc(phba,
5937 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5938 rdp_context->page_a2);
5939 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5940 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5941 rdp_context->page_a2);
5942 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5943 rdp_context->page_a0, vport);
5945 rdp_res->length = cpu_to_be32(len - 8);
5946 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5948 /* Now that we know the true size of the payload, update the BPL */
5949 bpl = (struct ulp_bde64 *)
5950 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5951 bpl->tus.f.bdeSize = len;
5952 bpl->tus.f.bdeFlags = 0;
5953 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5955 phba->fc_stat.elsXmitACC++;
5956 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5957 if (rc == IOCB_ERROR)
5958 lpfc_els_free_iocb(phba, elsiocb);
5964 cmdsize = 2 * sizeof(uint32_t);
5965 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5966 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5969 goto free_rdp_context;
5971 icmd = &elsiocb->iocb;
5972 icmd->ulpContext = rdp_context->rx_id;
5973 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5974 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5976 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5977 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5978 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5980 phba->fc_stat.elsXmitLSRJT++;
5981 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5982 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5984 if (rc == IOCB_ERROR)
5985 lpfc_els_free_iocb(phba, elsiocb);
5991 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5993 LPFC_MBOXQ_t *mbox = NULL;
5996 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5998 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5999 "7105 failed to allocate mailbox memory");
6003 if (lpfc_sli4_dump_page_a0(phba, mbox))
6004 goto prep_mbox_fail;
6005 mbox->vport = rdp_context->ndlp->vport;
6006 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6007 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6008 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6009 if (rc == MBX_NOT_FINISHED)
6010 goto issue_mbox_fail;
6016 mempool_free(mbox, phba->mbox_mem_pool);
6021 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6022 * @vport: pointer to a host virtual N_Port data structure.
6023 * @cmdiocb: pointer to lpfc command iocb data structure.
6024 * @ndlp: pointer to a node-list data structure.
6026 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6027 * IOCB. First, the payload of the unsolicited RDP is checked.
6028 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6029 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6030 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6031 * gather all data and send RDP response.
6034 * 0 - Sent the acc response
6035 * 1 - Sent the reject response.
6038 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6039 struct lpfc_nodelist *ndlp)
6041 struct lpfc_hba *phba = vport->phba;
6042 struct lpfc_dmabuf *pcmd;
6043 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6044 struct fc_rdp_req_frame *rdp_req;
6045 struct lpfc_rdp_context *rdp_context;
6049 if (phba->sli_rev < LPFC_SLI_REV4 ||
6050 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6051 LPFC_SLI_INTF_IF_TYPE_2) {
6052 rjt_err = LSRJT_UNABLE_TPC;
6053 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6057 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6058 rjt_err = LSRJT_UNABLE_TPC;
6059 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6063 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6064 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6066 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6067 "2422 ELS RDP Request "
6068 "dec len %d tag x%x port_id %d len %d\n",
6069 be32_to_cpu(rdp_req->rdp_des_length),
6070 be32_to_cpu(rdp_req->nport_id_desc.tag),
6071 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6072 be32_to_cpu(rdp_req->nport_id_desc.length));
6074 if (sizeof(struct fc_rdp_nport_desc) !=
6075 be32_to_cpu(rdp_req->rdp_des_length))
6077 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6079 if (RDP_NPORT_ID_SIZE !=
6080 be32_to_cpu(rdp_req->nport_id_desc.length))
6082 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6084 rjt_err = LSRJT_UNABLE_TPC;
6088 cmd = &cmdiocb->iocb;
6089 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6090 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6091 rdp_context->rx_id = cmd->ulpContext;
6092 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6093 if (lpfc_get_rdp_info(phba, rdp_context)) {
6094 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6095 "2423 Unable to send mailbox");
6097 rjt_err = LSRJT_UNABLE_TPC;
6105 rjt_err = LSRJT_LOGICAL_ERR;
6108 memset(&stat, 0, sizeof(stat));
6109 stat.un.b.lsRjtRsnCode = rjt_err;
6110 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6111 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6117 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6122 struct lpfc_iocbq *elsiocb;
6123 struct lpfc_nodelist *ndlp;
6124 struct ls_rjt *stat;
6125 union lpfc_sli4_cfg_shdr *shdr;
6126 struct lpfc_lcb_context *lcb_context;
6127 struct fc_lcb_res_frame *lcb_res;
6128 uint32_t cmdsize, shdr_status, shdr_add_status;
6132 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6133 ndlp = lcb_context->ndlp;
6134 pmb->ctx_ndlp = NULL;
6135 pmb->ctx_buf = NULL;
6137 shdr = (union lpfc_sli4_cfg_shdr *)
6138 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6139 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6140 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6142 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6143 "0194 SET_BEACON_CONFIG mailbox "
6144 "completed with status x%x add_status x%x,"
6145 " mbx status x%x\n",
6146 shdr_status, shdr_add_status, mb->mbxStatus);
6148 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6149 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6150 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6151 mempool_free(pmb, phba->mbox_mem_pool);
6155 mempool_free(pmb, phba->mbox_mem_pool);
6156 cmdsize = sizeof(struct fc_lcb_res_frame);
6157 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6158 lpfc_max_els_tries, ndlp,
6159 ndlp->nlp_DID, ELS_CMD_ACC);
6161 /* Decrement the ndlp reference count from previous mbox command */
6165 goto free_lcb_context;
6167 lcb_res = (struct fc_lcb_res_frame *)
6168 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6170 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6171 icmd = &elsiocb->iocb;
6172 icmd->ulpContext = lcb_context->rx_id;
6173 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6175 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6176 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6177 lcb_res->lcb_sub_command = lcb_context->sub_command;
6178 lcb_res->lcb_type = lcb_context->type;
6179 lcb_res->capability = lcb_context->capability;
6180 lcb_res->lcb_frequency = lcb_context->frequency;
6181 lcb_res->lcb_duration = lcb_context->duration;
6182 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6183 phba->fc_stat.elsXmitACC++;
6184 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6185 if (rc == IOCB_ERROR)
6186 lpfc_els_free_iocb(phba, elsiocb);
6192 cmdsize = sizeof(struct fc_lcb_res_frame);
6193 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6194 lpfc_max_els_tries, ndlp,
6195 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6198 goto free_lcb_context;
6200 icmd = &elsiocb->iocb;
6201 icmd->ulpContext = lcb_context->rx_id;
6202 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6203 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6205 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6206 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6207 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6209 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6210 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6212 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6213 phba->fc_stat.elsXmitLSRJT++;
6214 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6215 if (rc == IOCB_ERROR)
6216 lpfc_els_free_iocb(phba, elsiocb);
6222 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6223 struct lpfc_lcb_context *lcb_context,
6224 uint32_t beacon_state)
6226 struct lpfc_hba *phba = vport->phba;
6227 union lpfc_sli4_cfg_shdr *cfg_shdr;
6228 LPFC_MBOXQ_t *mbox = NULL;
6232 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6236 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6237 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6238 sizeof(struct lpfc_sli4_cfg_mhdr);
6239 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6240 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6241 LPFC_SLI4_MBX_EMBED);
6242 mbox->ctx_ndlp = (void *)lcb_context;
6243 mbox->vport = phba->pport;
6244 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6245 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6246 phba->sli4_hba.physical_port);
6247 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6249 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6252 * Check bv1s bit before issuing the mailbox
6253 * if bv1s == 1, LCB V1 supported
6254 * else, LCB V0 supported
6257 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6258 /* COMMON_SET_BEACON_CONFIG_V1 */
6259 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6260 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6261 bf_set(lpfc_mbx_set_beacon_port_type,
6262 &mbox->u.mqe.un.beacon_config, 0);
6263 bf_set(lpfc_mbx_set_beacon_duration_v1,
6264 &mbox->u.mqe.un.beacon_config,
6265 be16_to_cpu(lcb_context->duration));
6267 /* COMMON_SET_BEACON_CONFIG_V0 */
6268 if (be16_to_cpu(lcb_context->duration) != 0) {
6269 mempool_free(mbox, phba->mbox_mem_pool);
6272 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6273 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6274 bf_set(lpfc_mbx_set_beacon_state,
6275 &mbox->u.mqe.un.beacon_config, beacon_state);
6276 bf_set(lpfc_mbx_set_beacon_port_type,
6277 &mbox->u.mqe.un.beacon_config, 1);
6278 bf_set(lpfc_mbx_set_beacon_duration,
6279 &mbox->u.mqe.un.beacon_config,
6280 be16_to_cpu(lcb_context->duration));
6283 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6284 if (rc == MBX_NOT_FINISHED) {
6285 mempool_free(mbox, phba->mbox_mem_pool);
6294 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6295 * @vport: pointer to a host virtual N_Port data structure.
6296 * @cmdiocb: pointer to lpfc command iocb data structure.
6297 * @ndlp: pointer to a node-list data structure.
6299 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6300 * First, the payload of the unsolicited LCB is checked.
6301 * Then based on Subcommand beacon will either turn on or off.
6304 * 0 - Sent the acc response
6305 * 1 - Sent the reject response.
6308 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6309 struct lpfc_nodelist *ndlp)
6311 struct lpfc_hba *phba = vport->phba;
6312 struct lpfc_dmabuf *pcmd;
6314 struct fc_lcb_request_frame *beacon;
6315 struct lpfc_lcb_context *lcb_context;
6316 uint8_t state, rjt_err;
6319 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6320 lp = (uint8_t *)pcmd->virt;
6321 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6324 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6325 "type x%x frequency %x duration x%x\n",
6326 lp[0], lp[1], lp[2],
6327 beacon->lcb_command,
6328 beacon->lcb_sub_command,
6330 beacon->lcb_frequency,
6331 be16_to_cpu(beacon->lcb_duration));
6333 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6334 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6335 rjt_err = LSRJT_CMD_UNSUPPORTED;
6339 if (phba->sli_rev < LPFC_SLI_REV4 ||
6340 phba->hba_flag & HBA_FCOE_MODE ||
6341 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6342 LPFC_SLI_INTF_IF_TYPE_2)) {
6343 rjt_err = LSRJT_CMD_UNSUPPORTED;
6347 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6349 rjt_err = LSRJT_UNABLE_TPC;
6353 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6354 lcb_context->sub_command = beacon->lcb_sub_command;
6355 lcb_context->capability = 0;
6356 lcb_context->type = beacon->lcb_type;
6357 lcb_context->frequency = beacon->lcb_frequency;
6358 lcb_context->duration = beacon->lcb_duration;
6359 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6360 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6361 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6362 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6363 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6364 "0193 failed to send mail box");
6367 rjt_err = LSRJT_UNABLE_TPC;
6372 memset(&stat, 0, sizeof(stat));
6373 stat.un.b.lsRjtRsnCode = rjt_err;
6374 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6380 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6381 * @vport: pointer to a host virtual N_Port data structure.
6383 * This routine cleans up any Registration State Change Notification
6384 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6385 * @vport together with the host_lock is used to prevent multiple thread
6386 * trying to access the RSCN array on a same @vport at the same time.
6389 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6391 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6392 struct lpfc_hba *phba = vport->phba;
6395 spin_lock_irq(shost->host_lock);
6396 if (vport->fc_rscn_flush) {
6397 /* Another thread is walking fc_rscn_id_list on this vport */
6398 spin_unlock_irq(shost->host_lock);
6401 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6402 vport->fc_rscn_flush = 1;
6403 spin_unlock_irq(shost->host_lock);
6405 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6406 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6407 vport->fc_rscn_id_list[i] = NULL;
6409 spin_lock_irq(shost->host_lock);
6410 vport->fc_rscn_id_cnt = 0;
6411 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6412 spin_unlock_irq(shost->host_lock);
6413 lpfc_can_disctmo(vport);
6414 /* Indicate we are done walking this fc_rscn_id_list */
6415 vport->fc_rscn_flush = 0;
6419 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6420 * @vport: pointer to a host virtual N_Port data structure.
6421 * @did: remote destination port identifier.
6423 * This routine checks whether there is any pending Registration State
6424 * Configuration Notification (RSCN) to a @did on @vport.
6427 * None zero - The @did matched with a pending rscn
6428 * 0 - not able to match @did with a pending rscn
6431 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6436 uint32_t payload_len, i;
6437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6439 ns_did.un.word = did;
6441 /* Never match fabric nodes for RSCNs */
6442 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6445 /* If we are doing a FULL RSCN rediscovery, match everything */
6446 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6449 spin_lock_irq(shost->host_lock);
6450 if (vport->fc_rscn_flush) {
6451 /* Another thread is walking fc_rscn_id_list on this vport */
6452 spin_unlock_irq(shost->host_lock);
6455 /* Indicate we are walking fc_rscn_id_list on this vport */
6456 vport->fc_rscn_flush = 1;
6457 spin_unlock_irq(shost->host_lock);
6458 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6459 lp = vport->fc_rscn_id_list[i]->virt;
6460 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6461 payload_len -= sizeof(uint32_t); /* take off word 0 */
6462 while (payload_len) {
6463 rscn_did.un.word = be32_to_cpu(*lp++);
6464 payload_len -= sizeof(uint32_t);
6465 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6466 case RSCN_ADDRESS_FORMAT_PORT:
6467 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6468 && (ns_did.un.b.area == rscn_did.un.b.area)
6469 && (ns_did.un.b.id == rscn_did.un.b.id))
6470 goto return_did_out;
6472 case RSCN_ADDRESS_FORMAT_AREA:
6473 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6474 && (ns_did.un.b.area == rscn_did.un.b.area))
6475 goto return_did_out;
6477 case RSCN_ADDRESS_FORMAT_DOMAIN:
6478 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6479 goto return_did_out;
6481 case RSCN_ADDRESS_FORMAT_FABRIC:
6482 goto return_did_out;
6486 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6487 vport->fc_rscn_flush = 0;
6490 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6491 vport->fc_rscn_flush = 0;
6496 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6497 * @vport: pointer to a host virtual N_Port data structure.
6499 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6500 * state machine for a @vport's nodes that are with pending RSCN (Registration
6501 * State Change Notification).
6504 * 0 - Successful (currently alway return 0)
6507 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6509 struct lpfc_nodelist *ndlp = NULL;
6511 /* Move all affected nodes by pending RSCNs to NPR state. */
6512 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6513 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6514 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6517 /* NVME Target mode does not do RSCN Recovery. */
6518 if (vport->phba->nvmet_support)
6521 /* If we are in the process of doing discovery on this
6522 * NPort, let it continue on its own.
6524 switch (ndlp->nlp_state) {
6525 case NLP_STE_PLOGI_ISSUE:
6526 case NLP_STE_ADISC_ISSUE:
6527 case NLP_STE_REG_LOGIN_ISSUE:
6528 case NLP_STE_PRLI_ISSUE:
6529 case NLP_STE_LOGO_ISSUE:
6533 /* Check to see if we need to NVME rescan this target
6536 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6537 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6538 lpfc_nvme_rescan_port(vport, ndlp);
6540 lpfc_disc_state_machine(vport, ndlp, NULL,
6541 NLP_EVT_DEVICE_RECOVERY);
6542 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6548 * lpfc_send_rscn_event - Send an RSCN event to management application
6549 * @vport: pointer to a host virtual N_Port data structure.
6550 * @cmdiocb: pointer to lpfc command iocb data structure.
6552 * lpfc_send_rscn_event sends an RSCN netlink event to management
6556 lpfc_send_rscn_event(struct lpfc_vport *vport,
6557 struct lpfc_iocbq *cmdiocb)
6559 struct lpfc_dmabuf *pcmd;
6560 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6561 uint32_t *payload_ptr;
6562 uint32_t payload_len;
6563 struct lpfc_rscn_event_header *rscn_event_data;
6565 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6566 payload_ptr = (uint32_t *) pcmd->virt;
6567 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6569 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6570 payload_len, GFP_KERNEL);
6571 if (!rscn_event_data) {
6572 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6573 "0147 Failed to allocate memory for RSCN event\n");
6576 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6577 rscn_event_data->payload_length = payload_len;
6578 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6581 fc_host_post_vendor_event(shost,
6582 fc_get_event_number(),
6583 sizeof(struct lpfc_rscn_event_header) + payload_len,
6584 (char *)rscn_event_data,
6587 kfree(rscn_event_data);
6591 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6592 * @vport: pointer to a host virtual N_Port data structure.
6593 * @cmdiocb: pointer to lpfc command iocb data structure.
6594 * @ndlp: pointer to a node-list data structure.
6596 * This routine processes an unsolicited RSCN (Registration State Change
6597 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6598 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6599 * discover state machine is about to begin discovery, it just accepts the
6600 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6601 * contains N_Port IDs for other vports on this HBA, it just accepts the
6602 * RSCN and ignore processing it. If the state machine is in the recovery
6603 * state, the fc_rscn_id_list of this @vport is walked and the
6604 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6605 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6606 * routine is invoked to handle the RSCN event.
6609 * 0 - Just sent the acc response
6610 * 1 - Sent the acc response and waited for name server completion
6613 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6614 struct lpfc_nodelist *ndlp)
6616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6617 struct lpfc_hba *phba = vport->phba;
6618 struct lpfc_dmabuf *pcmd;
6619 uint32_t *lp, *datap;
6620 uint32_t payload_len, length, nportid, *cmd;
6622 int rscn_id = 0, hba_id = 0;
6625 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6626 lp = (uint32_t *) pcmd->virt;
6628 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6629 payload_len -= sizeof(uint32_t); /* take off word 0 */
6631 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6632 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6633 vport->fc_flag, payload_len, *lp,
6634 vport->fc_rscn_id_cnt);
6636 /* Send an RSCN event to the management application */
6637 lpfc_send_rscn_event(vport, cmdiocb);
6639 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6640 fc_host_post_event(shost, fc_get_event_number(),
6641 FCH_EVT_RSCN, lp[i]);
6643 /* Check if RSCN is coming from a direct-connected remote NPort */
6644 if (vport->fc_flag & FC_PT2PT) {
6645 /* If so, just ACC it, no other action needed for now */
6646 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6647 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6648 *lp, vport->fc_flag, payload_len);
6649 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6651 /* Check to see if we need to NVME rescan this target
6654 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6655 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6656 lpfc_nvme_rescan_port(vport, ndlp);
6660 /* If we are about to begin discovery, just ACC the RSCN.
6661 * Discovery processing will satisfy it.
6663 if (vport->port_state <= LPFC_NS_QRY) {
6664 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6665 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6666 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6668 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6672 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6673 * just ACC and ignore it.
6675 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6676 !(vport->cfg_peer_port_login)) {
6681 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6682 i -= sizeof(uint32_t);
6684 if (lpfc_find_vport_by_did(phba, nportid))
6687 if (rscn_id == hba_id) {
6688 /* ALL NPortIDs in RSCN are on HBA */
6689 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6691 "Data: x%x x%x x%x x%x\n",
6692 vport->fc_flag, payload_len,
6693 *lp, vport->fc_rscn_id_cnt);
6694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6695 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6696 ndlp->nlp_DID, vport->port_state,
6699 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6705 spin_lock_irq(shost->host_lock);
6706 if (vport->fc_rscn_flush) {
6707 /* Another thread is walking fc_rscn_id_list on this vport */
6708 vport->fc_flag |= FC_RSCN_DISCOVERY;
6709 spin_unlock_irq(shost->host_lock);
6711 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6714 /* Indicate we are walking fc_rscn_id_list on this vport */
6715 vport->fc_rscn_flush = 1;
6716 spin_unlock_irq(shost->host_lock);
6717 /* Get the array count after successfully have the token */
6718 rscn_cnt = vport->fc_rscn_id_cnt;
6719 /* If we are already processing an RSCN, save the received
6720 * RSCN payload buffer, cmdiocb->context2 to process later.
6722 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6723 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6724 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6725 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6727 spin_lock_irq(shost->host_lock);
6728 vport->fc_flag |= FC_RSCN_DEFERRED;
6730 /* Restart disctmo if its already running */
6731 if (vport->fc_flag & FC_DISC_TMO) {
6732 tmo = ((phba->fc_ratov * 3) + 3);
6733 mod_timer(&vport->fc_disctmo,
6734 jiffies + msecs_to_jiffies(1000 * tmo));
6736 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6737 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6738 vport->fc_flag |= FC_RSCN_MODE;
6739 spin_unlock_irq(shost->host_lock);
6741 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6742 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6745 (payload_len + length <= LPFC_BPL_SIZE)) {
6746 *cmd &= ELS_CMD_MASK;
6747 *cmd |= cpu_to_be32(payload_len + length);
6748 memcpy(((uint8_t *)cmd) + length, lp,
6751 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6752 vport->fc_rscn_id_cnt++;
6753 /* If we zero, cmdiocb->context2, the calling
6754 * routine will not try to free it.
6756 cmdiocb->context2 = NULL;
6759 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6760 "0235 Deferred RSCN "
6761 "Data: x%x x%x x%x\n",
6762 vport->fc_rscn_id_cnt, vport->fc_flag,
6765 vport->fc_flag |= FC_RSCN_DISCOVERY;
6766 spin_unlock_irq(shost->host_lock);
6767 /* ReDiscovery RSCN */
6768 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6769 "0234 ReDiscovery RSCN "
6770 "Data: x%x x%x x%x\n",
6771 vport->fc_rscn_id_cnt, vport->fc_flag,
6774 /* Indicate we are done walking fc_rscn_id_list on this vport */
6775 vport->fc_rscn_flush = 0;
6777 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6778 /* send RECOVERY event for ALL nodes that match RSCN payload */
6779 lpfc_rscn_recovery_check(vport);
6782 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6783 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6784 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6786 spin_lock_irq(shost->host_lock);
6787 vport->fc_flag |= FC_RSCN_MODE;
6788 spin_unlock_irq(shost->host_lock);
6789 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6790 /* Indicate we are done walking fc_rscn_id_list on this vport */
6791 vport->fc_rscn_flush = 0;
6793 * If we zero, cmdiocb->context2, the calling routine will
6794 * not try to free it.
6796 cmdiocb->context2 = NULL;
6797 lpfc_set_disctmo(vport);
6799 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6800 /* send RECOVERY event for ALL nodes that match RSCN payload */
6801 lpfc_rscn_recovery_check(vport);
6802 return lpfc_els_handle_rscn(vport);
6806 * lpfc_els_handle_rscn - Handle rscn for a vport
6807 * @vport: pointer to a host virtual N_Port data structure.
6809 * This routine handles the Registration State Configuration Notification
6810 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6811 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6812 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6813 * NameServer shall be issued. If CT command to the NameServer fails to be
6814 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6815 * RSCN activities with the @vport.
6818 * 0 - Cleaned up rscn on the @vport
6819 * 1 - Wait for plogi to name server before proceed
6822 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6824 struct lpfc_nodelist *ndlp;
6825 struct lpfc_hba *phba = vport->phba;
6827 /* Ignore RSCN if the port is being torn down. */
6828 if (vport->load_flag & FC_UNLOADING) {
6829 lpfc_els_flush_rscn(vport);
6833 /* Start timer for RSCN processing */
6834 lpfc_set_disctmo(vport);
6836 /* RSCN processed */
6837 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6838 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
6839 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6840 vport->port_state, vport->num_disc_nodes,
6843 /* To process RSCN, first compare RSCN data with NameServer */
6844 vport->fc_ns_retry = 0;
6845 vport->num_disc_nodes = 0;
6847 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6848 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6849 /* Good ndlp, issue CT Request to NameServer. Need to
6850 * know how many gidfts were issued. If none, then just
6851 * flush the RSCN. Otherwise, the outstanding requests
6854 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6855 if (lpfc_issue_gidft(vport) > 0)
6857 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6858 if (lpfc_issue_gidpt(vport) > 0)
6864 /* Nameserver login in question. Revalidate. */
6866 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6867 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6869 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6871 lpfc_els_flush_rscn(vport);
6874 ndlp->nlp_prev_state = ndlp->nlp_state;
6875 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6877 ndlp->nlp_type |= NLP_FABRIC;
6878 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6879 /* Wait for NameServer login cmpl before we can
6885 lpfc_els_flush_rscn(vport);
6890 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6891 * @vport: pointer to a host virtual N_Port data structure.
6892 * @cmdiocb: pointer to lpfc command iocb data structure.
6893 * @ndlp: pointer to a node-list data structure.
6895 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6896 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6897 * point topology. As an unsolicited FLOGI should not be received in a loop
6898 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6899 * lpfc_check_sparm() routine is invoked to check the parameters in the
6900 * unsolicited FLOGI. If parameters validation failed, the routine
6901 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6902 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6903 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6904 * will initiate PLOGI. The higher lexicographical value party shall has
6905 * higher priority (as the winning port) and will initiate PLOGI and
6906 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6907 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6908 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6911 * 0 - Successfully processed the unsolicited flogi
6912 * 1 - Failed to process the unsolicited flogi
6915 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6916 struct lpfc_nodelist *ndlp)
6918 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6919 struct lpfc_hba *phba = vport->phba;
6920 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6921 uint32_t *lp = (uint32_t *) pcmd->virt;
6922 IOCB_t *icmd = &cmdiocb->iocb;
6923 struct serv_parm *sp;
6927 uint32_t fc_flag = 0;
6928 uint32_t port_state = 0;
6931 sp = (struct serv_parm *) lp;
6933 /* FLOGI received */
6935 lpfc_set_disctmo(vport);
6937 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6938 /* We should never receive a FLOGI in loop mode, ignore it */
6939 did = icmd->un.elsreq64.remoteID;
6941 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6943 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6944 "0113 An FLOGI ELS command x%x was "
6945 "received from DID x%x in Loop Mode\n",
6950 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6953 * If our portname is greater than the remote portname,
6954 * then we initiate Nport login.
6957 rc = memcmp(&vport->fc_portname, &sp->portName,
6958 sizeof(struct lpfc_name));
6961 if (phba->sli_rev < LPFC_SLI_REV4) {
6962 mbox = mempool_alloc(phba->mbox_mem_pool,
6966 lpfc_linkdown(phba);
6967 lpfc_init_link(phba, mbox,
6969 phba->cfg_link_speed);
6970 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6971 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6972 mbox->vport = vport;
6973 rc = lpfc_sli_issue_mbox(phba, mbox,
6975 lpfc_set_loopback_flag(phba);
6976 if (rc == MBX_NOT_FINISHED)
6977 mempool_free(mbox, phba->mbox_mem_pool);
6981 /* abort the flogi coming back to ourselves
6982 * due to external loopback on the port.
6984 lpfc_els_abort_flogi(phba);
6987 } else if (rc > 0) { /* greater than */
6988 spin_lock_irq(shost->host_lock);
6989 vport->fc_flag |= FC_PT2PT_PLOGI;
6990 spin_unlock_irq(shost->host_lock);
6992 /* If we have the high WWPN we can assign our own
6993 * myDID; otherwise, we have to WAIT for a PLOGI
6994 * from the remote NPort to find out what it
6997 vport->fc_myDID = PT2PT_LocalID;
6999 vport->fc_myDID = PT2PT_RemoteID;
7003 * The vport state should go to LPFC_FLOGI only
7004 * AFTER we issue a FLOGI, not receive one.
7006 spin_lock_irq(shost->host_lock);
7007 fc_flag = vport->fc_flag;
7008 port_state = vport->port_state;
7009 vport->fc_flag |= FC_PT2PT;
7010 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7012 /* Acking an unsol FLOGI. Count 1 for link bounce
7015 vport->rcv_flogi_cnt++;
7016 spin_unlock_irq(shost->host_lock);
7017 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7018 "3311 Rcv Flogi PS x%x new PS x%x "
7019 "fc_flag x%x new fc_flag x%x\n",
7020 port_state, vport->port_state,
7021 fc_flag, vport->fc_flag);
7024 * We temporarily set fc_myDID to make it look like we are
7025 * a Fabric. This is done just so we end up with the right
7026 * did / sid on the FLOGI ACC rsp.
7028 did = vport->fc_myDID;
7029 vport->fc_myDID = Fabric_DID;
7031 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7033 /* Defer ACC response until AFTER we issue a FLOGI */
7034 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7035 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7036 phba->defer_flogi_acc_ox_id =
7037 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7039 vport->fc_myDID = did;
7041 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7042 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7043 " ox_id: x%x, hba_flag x%x\n",
7044 phba->defer_flogi_acc_rx_id,
7045 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7047 phba->defer_flogi_acc_flag = true;
7053 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7055 /* Now lets put fc_myDID back to what its supposed to be */
7056 vport->fc_myDID = did;
7062 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7063 * @vport: pointer to a host virtual N_Port data structure.
7064 * @cmdiocb: pointer to lpfc command iocb data structure.
7065 * @ndlp: pointer to a node-list data structure.
7067 * This routine processes Request Node Identification Data (RNID) IOCB
7068 * received as an ELS unsolicited event. Only when the RNID specified format
7069 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7070 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7071 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7072 * rejected by invoking the lpfc_els_rsp_reject() routine.
7075 * 0 - Successfully processed rnid iocb (currently always return 0)
7078 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7079 struct lpfc_nodelist *ndlp)
7081 struct lpfc_dmabuf *pcmd;
7086 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7087 lp = (uint32_t *) pcmd->virt;
7094 switch (rn->Format) {
7096 case RNID_TOPOLOGY_DISC:
7098 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7101 /* Reject this request because format not supported */
7102 stat.un.b.lsRjtRsvd0 = 0;
7103 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7104 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7105 stat.un.b.vendorUnique = 0;
7106 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7113 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7114 * @vport: pointer to a host virtual N_Port data structure.
7115 * @cmdiocb: pointer to lpfc command iocb data structure.
7116 * @ndlp: pointer to a node-list data structure.
7119 * 0 - Successfully processed echo iocb (currently always return 0)
7122 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7123 struct lpfc_nodelist *ndlp)
7127 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7129 /* skip over first word of echo command to find echo data */
7130 pcmd += sizeof(uint32_t);
7132 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7137 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7138 * @vport: pointer to a host virtual N_Port data structure.
7139 * @cmdiocb: pointer to lpfc command iocb data structure.
7140 * @ndlp: pointer to a node-list data structure.
7142 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7143 * received as an ELS unsolicited event. Currently, this function just invokes
7144 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7147 * 0 - Successfully processed lirr iocb (currently always return 0)
7150 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7151 struct lpfc_nodelist *ndlp)
7155 /* For now, unconditionally reject this command */
7156 stat.un.b.lsRjtRsvd0 = 0;
7157 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7158 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7159 stat.un.b.vendorUnique = 0;
7160 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7165 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7166 * @vport: pointer to a host virtual N_Port data structure.
7167 * @cmdiocb: pointer to lpfc command iocb data structure.
7168 * @ndlp: pointer to a node-list data structure.
7170 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7171 * received as an ELS unsolicited event. A request to RRQ shall only
7172 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7173 * Nx_Port N_Port_ID of the target Exchange is the same as the
7174 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7175 * not accepted, an LS_RJT with reason code "Unable to perform
7176 * command request" and reason code explanation "Invalid Originator
7177 * S_ID" shall be returned. For now, we just unconditionally accept
7178 * RRQ from the target.
7181 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7182 struct lpfc_nodelist *ndlp)
7184 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7185 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7186 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7190 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7191 * @phba: pointer to lpfc hba data structure.
7192 * @pmb: pointer to the driver internal queue element for mailbox command.
7194 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7195 * mailbox command. This callback function is to actually send the Accept
7196 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7197 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7198 * mailbox command, constructs the RPS response with the link statistics
7199 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7200 * response to the RPS.
7202 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7203 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7204 * will be stored into the context1 field of the IOCB for the completion
7205 * callback function to the RPS Accept Response ELS IOCB command.
7209 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7213 struct RLS_RSP *rls_rsp;
7215 struct lpfc_iocbq *elsiocb;
7216 struct lpfc_nodelist *ndlp;
7223 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7224 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7225 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7226 pmb->ctx_buf = NULL;
7227 pmb->ctx_ndlp = NULL;
7229 if (mb->mbxStatus) {
7230 mempool_free(pmb, phba->mbox_mem_pool);
7234 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7235 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7236 lpfc_max_els_tries, ndlp,
7237 ndlp->nlp_DID, ELS_CMD_ACC);
7239 /* Decrement the ndlp reference count from previous mbox command */
7243 mempool_free(pmb, phba->mbox_mem_pool);
7247 icmd = &elsiocb->iocb;
7248 icmd->ulpContext = rxid;
7249 icmd->unsli3.rcvsli3.ox_id = oxid;
7251 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7252 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7253 pcmd += sizeof(uint32_t); /* Skip past command */
7254 rls_rsp = (struct RLS_RSP *)pcmd;
7256 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7257 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7258 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7259 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7260 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7261 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7262 mempool_free(pmb, phba->mbox_mem_pool);
7263 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7264 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7265 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7266 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7267 elsiocb->iotag, elsiocb->iocb.ulpContext,
7268 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7270 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7271 phba->fc_stat.elsXmitACC++;
7272 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7273 lpfc_els_free_iocb(phba, elsiocb);
7277 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7278 * @vport: pointer to a host virtual N_Port data structure.
7279 * @cmdiocb: pointer to lpfc command iocb data structure.
7280 * @ndlp: pointer to a node-list data structure.
7282 * This routine processes Read Link Status (RLS) IOCB received as an
7283 * ELS unsolicited event. It first checks the remote port state. If the
7284 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7285 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7286 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7287 * for reading the HBA link statistics. It is for the callback function,
7288 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7289 * to actually sending out RPL Accept (ACC) response.
7292 * 0 - Successfully processed rls iocb (currently always return 0)
7295 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7296 struct lpfc_nodelist *ndlp)
7298 struct lpfc_hba *phba = vport->phba;
7302 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7303 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7304 /* reject the unsolicited RLS request and done with it */
7307 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7309 lpfc_read_lnk_stat(phba, mbox);
7310 mbox->ctx_buf = (void *)((unsigned long)
7311 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7312 cmdiocb->iocb.ulpContext)); /* rx_id */
7313 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7314 mbox->vport = vport;
7315 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7316 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7317 != MBX_NOT_FINISHED)
7318 /* Mbox completion will send ELS Response */
7320 /* Decrement reference count used for the failed mbox
7324 mempool_free(mbox, phba->mbox_mem_pool);
7327 /* issue rejection response */
7328 stat.un.b.lsRjtRsvd0 = 0;
7329 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7330 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7331 stat.un.b.vendorUnique = 0;
7332 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7337 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7338 * @vport: pointer to a host virtual N_Port data structure.
7339 * @cmdiocb: pointer to lpfc command iocb data structure.
7340 * @ndlp: pointer to a node-list data structure.
7342 * This routine processes Read Timout Value (RTV) IOCB received as an
7343 * ELS unsolicited event. It first checks the remote port state. If the
7344 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7345 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7346 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7347 * Value (RTV) unsolicited IOCB event.
7349 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7350 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7351 * will be stored into the context1 field of the IOCB for the completion
7352 * callback function to the RTV Accept Response ELS IOCB command.
7355 * 0 - Successfully processed rtv iocb (currently always return 0)
7358 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7359 struct lpfc_nodelist *ndlp)
7361 struct lpfc_hba *phba = vport->phba;
7363 struct RTV_RSP *rtv_rsp;
7365 struct lpfc_iocbq *elsiocb;
7369 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7370 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7371 /* reject the unsolicited RTV request and done with it */
7374 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7375 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7376 lpfc_max_els_tries, ndlp,
7377 ndlp->nlp_DID, ELS_CMD_ACC);
7382 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7383 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7384 pcmd += sizeof(uint32_t); /* Skip past command */
7386 /* use the command's xri in the response */
7387 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7388 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7390 rtv_rsp = (struct RTV_RSP *)pcmd;
7392 /* populate RTV payload */
7393 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7394 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7395 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7396 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7397 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7399 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7400 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7401 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7402 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7403 "Data: x%x x%x x%x\n",
7404 elsiocb->iotag, elsiocb->iocb.ulpContext,
7405 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7407 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7408 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7409 phba->fc_stat.elsXmitACC++;
7410 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7411 lpfc_els_free_iocb(phba, elsiocb);
7415 /* issue rejection response */
7416 stat.un.b.lsRjtRsvd0 = 0;
7417 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7418 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7419 stat.un.b.vendorUnique = 0;
7420 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7424 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7425 * @vport: pointer to a host virtual N_Port data structure.
7426 * @ndlp: pointer to a node-list data structure.
7427 * @did: DID of the target.
7428 * @rrq: Pointer to the rrq struct.
7430 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7431 * Successful the the completion handler will clear the RRQ.
7434 * 0 - Successfully sent rrq els iocb.
7435 * 1 - Failed to send rrq els iocb.
7438 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7439 uint32_t did, struct lpfc_node_rrq *rrq)
7441 struct lpfc_hba *phba = vport->phba;
7442 struct RRQ *els_rrq;
7443 struct lpfc_iocbq *elsiocb;
7449 if (ndlp != rrq->ndlp)
7454 /* If ndlp is not NULL, we will bump the reference count on it */
7455 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7456 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7461 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7463 /* For RRQ request, remainder of payload is Exchange IDs */
7464 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7465 pcmd += sizeof(uint32_t);
7466 els_rrq = (struct RRQ *) pcmd;
7468 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7469 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7470 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7471 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7472 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7475 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7476 "Issue RRQ: did:x%x",
7477 did, rrq->xritag, rrq->rxid);
7478 elsiocb->context_un.rrq = rrq;
7479 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7480 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7482 if (ret == IOCB_ERROR) {
7483 lpfc_els_free_iocb(phba, elsiocb);
7490 * lpfc_send_rrq - Sends ELS RRQ if needed.
7491 * @phba: pointer to lpfc hba data structure.
7492 * @rrq: pointer to the active rrq.
7494 * This routine will call the lpfc_issue_els_rrq if the rrq is
7495 * still active for the xri. If this function returns a failure then
7496 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7498 * Returns 0 Success.
7502 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7504 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7509 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7510 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7517 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7518 * @vport: pointer to a host virtual N_Port data structure.
7519 * @cmdsize: size of the ELS command.
7520 * @oldiocb: pointer to the original lpfc command iocb data structure.
7521 * @ndlp: pointer to a node-list data structure.
7523 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7524 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7526 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7527 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7528 * will be stored into the context1 field of the IOCB for the completion
7529 * callback function to the RPL Accept Response ELS command.
7532 * 0 - Successfully issued ACC RPL ELS command
7533 * 1 - Failed to issue ACC RPL ELS command
7536 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7537 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7539 struct lpfc_hba *phba = vport->phba;
7540 IOCB_t *icmd, *oldcmd;
7542 struct lpfc_iocbq *elsiocb;
7545 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7546 ndlp->nlp_DID, ELS_CMD_ACC);
7551 icmd = &elsiocb->iocb;
7552 oldcmd = &oldiocb->iocb;
7553 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7554 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7556 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7557 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7558 pcmd += sizeof(uint16_t);
7559 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7560 pcmd += sizeof(uint16_t);
7562 /* Setup the RPL ACC payload */
7563 rpl_rsp.listLen = be32_to_cpu(1);
7565 rpl_rsp.port_num_blk.portNum = 0;
7566 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7567 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7568 sizeof(struct lpfc_name));
7569 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7570 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7571 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7572 "0120 Xmit ELS RPL ACC response tag x%x "
7573 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7575 elsiocb->iotag, elsiocb->iocb.ulpContext,
7576 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7578 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7579 phba->fc_stat.elsXmitACC++;
7580 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7582 lpfc_els_free_iocb(phba, elsiocb);
7589 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7590 * @vport: pointer to a host virtual N_Port data structure.
7591 * @cmdiocb: pointer to lpfc command iocb data structure.
7592 * @ndlp: pointer to a node-list data structure.
7594 * This routine processes Read Port List (RPL) IOCB received as an ELS
7595 * unsolicited event. It first checks the remote port state. If the remote
7596 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7597 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7598 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7599 * to accept the RPL.
7602 * 0 - Successfully processed rpl iocb (currently always return 0)
7605 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7606 struct lpfc_nodelist *ndlp)
7608 struct lpfc_dmabuf *pcmd;
7615 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7616 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7617 /* issue rejection response */
7618 stat.un.b.lsRjtRsvd0 = 0;
7619 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7620 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7621 stat.un.b.vendorUnique = 0;
7622 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7624 /* rejected the unsolicited RPL request and done with it */
7628 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7629 lp = (uint32_t *) pcmd->virt;
7630 rpl = (RPL *) (lp + 1);
7631 maxsize = be32_to_cpu(rpl->maxsize);
7633 /* We support only one port */
7634 if ((rpl->index == 0) &&
7636 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7637 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7639 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7641 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7647 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7648 * @vport: pointer to a virtual N_Port data structure.
7649 * @cmdiocb: pointer to lpfc command iocb data structure.
7650 * @ndlp: pointer to a node-list data structure.
7652 * This routine processes Fibre Channel Address Resolution Protocol
7653 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7654 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7655 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7656 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7657 * remote PortName is compared against the FC PortName stored in the @vport
7658 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7659 * compared against the FC NodeName stored in the @vport data structure.
7660 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7661 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7662 * invoked to send out FARP Response to the remote node. Before sending the
7663 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7664 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7665 * routine is invoked to log into the remote port first.
7668 * 0 - Either the FARP Match Mode not supported or successfully processed
7671 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7672 struct lpfc_nodelist *ndlp)
7674 struct lpfc_dmabuf *pcmd;
7680 icmd = &cmdiocb->iocb;
7681 did = icmd->un.elsreq64.remoteID;
7682 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7683 lp = (uint32_t *) pcmd->virt;
7687 /* FARP-REQ received from DID <did> */
7688 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7689 "0601 FARP-REQ received from DID x%x\n", did);
7690 /* We will only support match on WWPN or WWNN */
7691 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7696 /* If this FARP command is searching for my portname */
7697 if (fp->Mflags & FARP_MATCH_PORT) {
7698 if (memcmp(&fp->RportName, &vport->fc_portname,
7699 sizeof(struct lpfc_name)) == 0)
7703 /* If this FARP command is searching for my nodename */
7704 if (fp->Mflags & FARP_MATCH_NODE) {
7705 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7706 sizeof(struct lpfc_name)) == 0)
7711 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7712 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7713 /* Log back into the node before sending the FARP. */
7714 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7715 ndlp->nlp_prev_state = ndlp->nlp_state;
7716 lpfc_nlp_set_state(vport, ndlp,
7717 NLP_STE_PLOGI_ISSUE);
7718 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7721 /* Send a FARP response to that node */
7722 if (fp->Rflags & FARP_REQUEST_FARPR)
7723 lpfc_issue_els_farpr(vport, did, 0);
7730 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7731 * @vport: pointer to a host virtual N_Port data structure.
7732 * @cmdiocb: pointer to lpfc command iocb data structure.
7733 * @ndlp: pointer to a node-list data structure.
7735 * This routine processes Fibre Channel Address Resolution Protocol
7736 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7737 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7738 * the FARP response request.
7741 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7744 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7745 struct lpfc_nodelist *ndlp)
7747 struct lpfc_dmabuf *pcmd;
7752 icmd = &cmdiocb->iocb;
7753 did = icmd->un.elsreq64.remoteID;
7754 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7755 lp = (uint32_t *) pcmd->virt;
7758 /* FARP-RSP received from DID <did> */
7759 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7760 "0600 FARP-RSP received from DID x%x\n", did);
7761 /* ACCEPT the Farp resp request */
7762 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7768 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7769 * @vport: pointer to a host virtual N_Port data structure.
7770 * @cmdiocb: pointer to lpfc command iocb data structure.
7771 * @fan_ndlp: pointer to a node-list data structure.
7773 * This routine processes a Fabric Address Notification (FAN) IOCB
7774 * command received as an ELS unsolicited event. The FAN ELS command will
7775 * only be processed on a physical port (i.e., the @vport represents the
7776 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7777 * compared against those in the phba data structure. If any of those is
7778 * different, the lpfc_initial_flogi() routine is invoked to initialize
7779 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7780 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7781 * is invoked to register login to the fabric.
7784 * 0 - Successfully processed fan iocb (currently always return 0).
7787 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7788 struct lpfc_nodelist *fan_ndlp)
7790 struct lpfc_hba *phba = vport->phba;
7794 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7795 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7797 /* FAN received; Fan does not have a reply sequence */
7798 if ((vport == phba->pport) &&
7799 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7800 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7801 sizeof(struct lpfc_name))) ||
7802 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7803 sizeof(struct lpfc_name)))) {
7804 /* This port has switched fabrics. FLOGI is required */
7805 lpfc_issue_init_vfi(vport);
7807 /* FAN verified - skip FLOGI */
7808 vport->fc_myDID = vport->fc_prevDID;
7809 if (phba->sli_rev < LPFC_SLI_REV4)
7810 lpfc_issue_fabric_reglogin(vport);
7812 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7813 "3138 Need register VFI: (x%x/%x)\n",
7814 vport->fc_prevDID, vport->fc_myDID);
7815 lpfc_issue_reg_vfi(vport);
7823 * lpfc_els_timeout - Handler funciton to the els timer
7824 * @t: timer context used to obtain the vport.
7826 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7827 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7828 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7829 * up the worker thread. It is for the worker thread to invoke the routine
7830 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7833 lpfc_els_timeout(struct timer_list *t)
7835 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7836 struct lpfc_hba *phba = vport->phba;
7837 uint32_t tmo_posted;
7838 unsigned long iflag;
7840 spin_lock_irqsave(&vport->work_port_lock, iflag);
7841 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7842 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7843 vport->work_port_events |= WORKER_ELS_TMO;
7844 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7846 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7847 lpfc_worker_wake_up(phba);
7853 * lpfc_els_timeout_handler - Process an els timeout event
7854 * @vport: pointer to a virtual N_Port data structure.
7856 * This routine is the actual handler function that processes an ELS timeout
7857 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7858 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7859 * invoking the lpfc_sli_issue_abort_iotag() routine.
7862 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7864 struct lpfc_hba *phba = vport->phba;
7865 struct lpfc_sli_ring *pring;
7866 struct lpfc_iocbq *tmp_iocb, *piocb;
7868 struct lpfc_dmabuf *pcmd;
7869 uint32_t els_command = 0;
7871 uint32_t remote_ID = 0xffffffff;
7872 LIST_HEAD(abort_list);
7875 timeout = (uint32_t)(phba->fc_ratov << 1);
7877 pring = lpfc_phba_elsring(phba);
7878 if (unlikely(!pring))
7881 if (phba->pport->load_flag & FC_UNLOADING)
7884 spin_lock_irq(&phba->hbalock);
7885 if (phba->sli_rev == LPFC_SLI_REV4)
7886 spin_lock(&pring->ring_lock);
7888 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7891 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7892 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7893 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7896 if (piocb->vport != vport)
7899 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7901 els_command = *(uint32_t *) (pcmd->virt);
7903 if (els_command == ELS_CMD_FARP ||
7904 els_command == ELS_CMD_FARPR ||
7905 els_command == ELS_CMD_FDISC)
7908 if (piocb->drvrTimeout > 0) {
7909 if (piocb->drvrTimeout >= timeout)
7910 piocb->drvrTimeout -= timeout;
7912 piocb->drvrTimeout = 0;
7916 remote_ID = 0xffffffff;
7917 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7918 remote_ID = cmd->un.elsreq64.remoteID;
7920 struct lpfc_nodelist *ndlp;
7921 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7923 remote_ID = ndlp->nlp_DID;
7925 list_add_tail(&piocb->dlist, &abort_list);
7927 if (phba->sli_rev == LPFC_SLI_REV4)
7928 spin_unlock(&pring->ring_lock);
7929 spin_unlock_irq(&phba->hbalock);
7931 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7933 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7934 "0127 ELS timeout Data: x%x x%x x%x "
7935 "x%x\n", els_command,
7936 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7937 spin_lock_irq(&phba->hbalock);
7938 list_del_init(&piocb->dlist);
7939 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7940 spin_unlock_irq(&phba->hbalock);
7943 if (!list_empty(&pring->txcmplq))
7944 if (!(phba->pport->load_flag & FC_UNLOADING))
7945 mod_timer(&vport->els_tmofunc,
7946 jiffies + msecs_to_jiffies(1000 * timeout));
7950 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7951 * @vport: pointer to a host virtual N_Port data structure.
7953 * This routine is used to clean up all the outstanding ELS commands on a
7954 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7955 * routine. After that, it walks the ELS transmit queue to remove all the
7956 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7957 * the IOCBs with a non-NULL completion callback function, the callback
7958 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7959 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7960 * callback function, the IOCB will simply be released. Finally, it walks
7961 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7962 * completion queue IOCB that is associated with the @vport and is not
7963 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7964 * part of the discovery state machine) out to HBA by invoking the
7965 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7966 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7967 * the IOCBs are aborted when this function returns.
7970 lpfc_els_flush_cmd(struct lpfc_vport *vport)
7972 LIST_HEAD(abort_list);
7973 struct lpfc_hba *phba = vport->phba;
7974 struct lpfc_sli_ring *pring;
7975 struct lpfc_iocbq *tmp_iocb, *piocb;
7977 unsigned long iflags = 0;
7979 lpfc_fabric_abort_vport(vport);
7982 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7983 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7984 * ultimately grabs the ring_lock, the driver must splice the list into
7985 * a working list and release the locks before calling the abort.
7987 spin_lock_irqsave(&phba->hbalock, iflags);
7988 pring = lpfc_phba_elsring(phba);
7990 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7991 if (unlikely(!pring)) {
7992 spin_unlock_irqrestore(&phba->hbalock, iflags);
7996 if (phba->sli_rev == LPFC_SLI_REV4)
7997 spin_lock(&pring->ring_lock);
7999 /* First we need to issue aborts to outstanding cmds on txcmpl */
8000 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8001 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8004 if (piocb->vport != vport)
8007 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8010 /* On the ELS ring we can have ELS_REQUESTs or
8011 * GEN_REQUESTs waiting for a response.
8014 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8015 list_add_tail(&piocb->dlist, &abort_list);
8017 /* If the link is down when flushing ELS commands
8018 * the firmware will not complete them till after
8019 * the link comes back up. This may confuse
8020 * discovery for the new link up, so we need to
8021 * change the compl routine to just clean up the iocb
8022 * and avoid any retry logic.
8024 if (phba->link_state == LPFC_LINK_DOWN)
8025 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8027 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8028 list_add_tail(&piocb->dlist, &abort_list);
8031 if (phba->sli_rev == LPFC_SLI_REV4)
8032 spin_unlock(&pring->ring_lock);
8033 spin_unlock_irqrestore(&phba->hbalock, iflags);
8035 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8036 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8037 spin_lock_irqsave(&phba->hbalock, iflags);
8038 list_del_init(&piocb->dlist);
8039 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8040 spin_unlock_irqrestore(&phba->hbalock, iflags);
8042 if (!list_empty(&abort_list))
8043 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8044 "3387 abort list for txq not empty\n");
8045 INIT_LIST_HEAD(&abort_list);
8047 spin_lock_irqsave(&phba->hbalock, iflags);
8048 if (phba->sli_rev == LPFC_SLI_REV4)
8049 spin_lock(&pring->ring_lock);
8051 /* No need to abort the txq list,
8052 * just queue them up for lpfc_sli_cancel_iocbs
8054 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8057 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8061 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8062 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8063 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8064 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8065 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8068 if (piocb->vport != vport)
8071 list_del_init(&piocb->list);
8072 list_add_tail(&piocb->list, &abort_list);
8075 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8076 if (vport == phba->pport) {
8077 list_for_each_entry_safe(piocb, tmp_iocb,
8078 &phba->fabric_iocb_list, list) {
8080 list_del_init(&piocb->list);
8081 list_add_tail(&piocb->list, &abort_list);
8085 if (phba->sli_rev == LPFC_SLI_REV4)
8086 spin_unlock(&pring->ring_lock);
8087 spin_unlock_irqrestore(&phba->hbalock, iflags);
8089 /* Cancel all the IOCBs from the completions list */
8090 lpfc_sli_cancel_iocbs(phba, &abort_list,
8091 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8097 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8098 * @phba: pointer to lpfc hba data structure.
8100 * This routine is used to clean up all the outstanding ELS commands on a
8101 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8102 * routine. After that, it walks the ELS transmit queue to remove all the
8103 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8104 * the IOCBs with the completion callback function associated, the callback
8105 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8106 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8107 * callback function associated, the IOCB will simply be released. Finally,
8108 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8109 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8110 * management plane IOCBs that are not part of the discovery state machine)
8111 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8114 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8116 struct lpfc_vport *vport;
8118 spin_lock_irq(&phba->port_list_lock);
8119 list_for_each_entry(vport, &phba->port_list, listentry)
8120 lpfc_els_flush_cmd(vport);
8121 spin_unlock_irq(&phba->port_list_lock);
8127 * lpfc_send_els_failure_event - Posts an ELS command failure event
8128 * @phba: Pointer to hba context object.
8129 * @cmdiocbp: Pointer to command iocb which reported error.
8130 * @rspiocbp: Pointer to response iocb which reported error.
8132 * This function sends an event when there is an ELS command
8136 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8137 struct lpfc_iocbq *cmdiocbp,
8138 struct lpfc_iocbq *rspiocbp)
8140 struct lpfc_vport *vport = cmdiocbp->vport;
8141 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8142 struct lpfc_lsrjt_event lsrjt_event;
8143 struct lpfc_fabric_event_header fabric_event;
8145 struct lpfc_nodelist *ndlp;
8148 ndlp = cmdiocbp->context1;
8152 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8153 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8154 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8155 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8156 sizeof(struct lpfc_name));
8157 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8158 sizeof(struct lpfc_name));
8159 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8160 cmdiocbp->context2)->virt);
8161 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8162 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8163 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8164 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8165 fc_host_post_vendor_event(shost,
8166 fc_get_event_number(),
8167 sizeof(lsrjt_event),
8168 (char *)&lsrjt_event,
8172 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8173 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8174 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8175 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8176 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8178 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8179 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8180 sizeof(struct lpfc_name));
8181 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8182 sizeof(struct lpfc_name));
8183 fc_host_post_vendor_event(shost,
8184 fc_get_event_number(),
8185 sizeof(fabric_event),
8186 (char *)&fabric_event,
8194 * lpfc_send_els_event - Posts unsolicited els event
8195 * @vport: Pointer to vport object.
8196 * @ndlp: Pointer FC node object.
8197 * @payload: ELS command code type.
8199 * This function posts an event when there is an incoming
8200 * unsolicited ELS command.
8203 lpfc_send_els_event(struct lpfc_vport *vport,
8204 struct lpfc_nodelist *ndlp,
8207 struct lpfc_els_event_header *els_data = NULL;
8208 struct lpfc_logo_event *logo_data = NULL;
8209 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8211 if (*payload == ELS_CMD_LOGO) {
8212 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8214 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8215 "0148 Failed to allocate memory "
8216 "for LOGO event\n");
8219 els_data = &logo_data->header;
8221 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8224 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8225 "0149 Failed to allocate memory "
8230 els_data->event_type = FC_REG_ELS_EVENT;
8233 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8236 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8239 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8242 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8243 /* Copy the WWPN in the LOGO payload */
8244 memcpy(logo_data->logo_wwpn, &payload[2],
8245 sizeof(struct lpfc_name));
8251 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8252 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8253 if (*payload == ELS_CMD_LOGO) {
8254 fc_host_post_vendor_event(shost,
8255 fc_get_event_number(),
8256 sizeof(struct lpfc_logo_event),
8261 fc_host_post_vendor_event(shost,
8262 fc_get_event_number(),
8263 sizeof(struct lpfc_els_event_header),
8273 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8274 FC_LS_TLV_DTAG_INIT);
8276 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8277 FC_FPIN_LI_EVT_TYPES_INIT);
8280 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8281 * @vport: Pointer to vport object.
8282 * @tlv: Pointer to the Link Integrity Notification Descriptor.
8284 * This function processes a link integrity FPIN event by
8288 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8290 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8291 const char *li_evt_str;
8294 li_evt = be16_to_cpu(li->event_type);
8295 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8297 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8298 "4680 FPIN Link Integrity %s (x%x) "
8299 "Detecting PN x%016llx Attached PN x%016llx "
8300 "Duration %d mSecs Count %d Port Cnt %d\n",
8302 be64_to_cpu(li->detecting_wwpn),
8303 be64_to_cpu(li->attached_wwpn),
8304 be32_to_cpu(li->event_threshold),
8305 be32_to_cpu(li->event_count),
8306 be32_to_cpu(li->pname_count));
8310 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8313 struct fc_tlv_desc *tlv;
8314 const char *dtag_nm;
8315 uint32_t desc_cnt = 0, bytes_remain;
8318 /* FPINs handled only if we are in the right discovery state */
8319 if (vport->port_state < LPFC_DISC_AUTH)
8322 /* make sure there is the full fpin header */
8323 if (fpin_length < sizeof(struct fc_els_fpin))
8326 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8327 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8328 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8330 /* process each descriptor */
8331 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8332 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8334 dtag = be32_to_cpu(tlv->desc_tag);
8336 case ELS_DTAG_LNK_INTEGRITY:
8337 lpfc_els_rcv_fpin_li(vport, tlv);
8340 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8341 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8342 "4678 skipped FPIN descriptor[%d]: "
8344 desc_cnt, dtag, dtag_nm);
8349 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8350 tlv = fc_tlv_next_desc(tlv);
8353 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8358 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8359 * @phba: pointer to lpfc hba data structure.
8360 * @pring: pointer to a SLI ring.
8361 * @vport: pointer to a host virtual N_Port data structure.
8362 * @elsiocb: pointer to lpfc els command iocb data structure.
8364 * This routine is used for processing the IOCB associated with a unsolicited
8365 * event. It first determines whether there is an existing ndlp that matches
8366 * the DID from the unsolicited IOCB. If not, it will create a new one with
8367 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8368 * IOCB is then used to invoke the proper routine and to set up proper state
8369 * of the discovery state machine.
8372 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8373 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8375 struct Scsi_Host *shost;
8376 struct lpfc_nodelist *ndlp;
8378 uint32_t *payload, payload_len;
8379 uint32_t cmd, did, newnode;
8380 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8381 IOCB_t *icmd = &elsiocb->iocb;
8384 if (!vport || !(elsiocb->context2))
8388 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8389 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8391 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8392 lpfc_post_buffer(phba, pring, 1);
8394 did = icmd->un.rcvels.remoteID;
8395 if (icmd->ulpStatus) {
8396 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8397 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8398 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8402 /* Check to see if link went down during discovery */
8403 if (lpfc_els_chk_latt(vport))
8406 /* Ignore traffic received during vport shutdown. */
8407 if (vport->load_flag & FC_UNLOADING)
8410 /* If NPort discovery is delayed drop incoming ELS */
8411 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8412 (cmd != ELS_CMD_PLOGI))
8415 ndlp = lpfc_findnode_did(vport, did);
8417 /* Cannot find existing Fabric ndlp, so allocate a new one */
8418 ndlp = lpfc_nlp_init(vport, did);
8421 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8423 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8424 ndlp->nlp_type |= NLP_FABRIC;
8425 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8426 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8430 phba->fc_stat.elsRcvFrame++;
8433 * Do not process any unsolicited ELS commands
8434 * if the ndlp is in DEV_LOSS
8436 shost = lpfc_shost_from_vport(vport);
8437 spin_lock_irq(shost->host_lock);
8438 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8439 spin_unlock_irq(shost->host_lock);
8444 spin_unlock_irq(shost->host_lock);
8446 elsiocb->context1 = lpfc_nlp_get(ndlp);
8447 elsiocb->vport = vport;
8449 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8450 cmd &= ELS_CMD_MASK;
8452 /* ELS command <elsCmd> received from NPORT <did> */
8453 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8454 "0112 ELS command x%x received from NPORT x%x "
8455 "Data: x%x x%x x%x x%x\n",
8456 cmd, did, vport->port_state, vport->fc_flag,
8457 vport->fc_myDID, vport->fc_prevDID);
8459 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8460 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8461 (cmd != ELS_CMD_FLOGI) &&
8462 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8463 rjt_err = LSRJT_LOGICAL_BSY;
8464 rjt_exp = LSEXP_NOTHING_MORE;
8470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8471 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8472 did, vport->port_state, ndlp->nlp_flag);
8474 phba->fc_stat.elsRcvPLOGI++;
8475 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8476 if (phba->sli_rev == LPFC_SLI_REV4 &&
8477 (phba->pport->fc_flag & FC_PT2PT)) {
8478 vport->fc_prevDID = vport->fc_myDID;
8479 /* Our DID needs to be updated before registering
8480 * the vfi. This is done in lpfc_rcv_plogi but
8481 * that is called after the reg_vfi.
8483 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8484 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8485 "3312 Remote port assigned DID x%x "
8486 "%x\n", vport->fc_myDID,
8490 lpfc_send_els_event(vport, ndlp, payload);
8492 /* If Nport discovery is delayed, reject PLOGIs */
8493 if (vport->fc_flag & FC_DISC_DELAYED) {
8494 rjt_err = LSRJT_UNABLE_TPC;
8495 rjt_exp = LSEXP_NOTHING_MORE;
8499 if (vport->port_state < LPFC_DISC_AUTH) {
8500 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8501 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8502 rjt_err = LSRJT_UNABLE_TPC;
8503 rjt_exp = LSEXP_NOTHING_MORE;
8508 spin_lock_irq(shost->host_lock);
8509 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8510 spin_unlock_irq(shost->host_lock);
8512 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8517 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8518 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8519 did, vport->port_state, ndlp->nlp_flag);
8521 phba->fc_stat.elsRcvFLOGI++;
8523 /* If the driver believes fabric discovery is done and is ready,
8524 * bounce the link. There is some descrepancy.
8526 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8527 vport->fc_flag & FC_PT2PT &&
8528 vport->rcv_flogi_cnt >= 1) {
8529 rjt_err = LSRJT_LOGICAL_BSY;
8530 rjt_exp = LSEXP_NOTHING_MORE;
8535 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8541 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8542 did, vport->port_state, ndlp->nlp_flag);
8544 phba->fc_stat.elsRcvLOGO++;
8545 lpfc_send_els_event(vport, ndlp, payload);
8546 if (vport->port_state < LPFC_DISC_AUTH) {
8547 rjt_err = LSRJT_UNABLE_TPC;
8548 rjt_exp = LSEXP_NOTHING_MORE;
8551 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8554 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8555 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8556 did, vport->port_state, ndlp->nlp_flag);
8558 phba->fc_stat.elsRcvPRLO++;
8559 lpfc_send_els_event(vport, ndlp, payload);
8560 if (vport->port_state < LPFC_DISC_AUTH) {
8561 rjt_err = LSRJT_UNABLE_TPC;
8562 rjt_exp = LSEXP_NOTHING_MORE;
8565 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8568 phba->fc_stat.elsRcvLCB++;
8569 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8572 phba->fc_stat.elsRcvRDP++;
8573 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8576 phba->fc_stat.elsRcvRSCN++;
8577 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8583 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8584 did, vport->port_state, ndlp->nlp_flag);
8586 lpfc_send_els_event(vport, ndlp, payload);
8587 phba->fc_stat.elsRcvADISC++;
8588 if (vport->port_state < LPFC_DISC_AUTH) {
8589 rjt_err = LSRJT_UNABLE_TPC;
8590 rjt_exp = LSEXP_NOTHING_MORE;
8593 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8597 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8598 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8599 did, vport->port_state, ndlp->nlp_flag);
8601 phba->fc_stat.elsRcvPDISC++;
8602 if (vport->port_state < LPFC_DISC_AUTH) {
8603 rjt_err = LSRJT_UNABLE_TPC;
8604 rjt_exp = LSEXP_NOTHING_MORE;
8607 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8611 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8612 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8613 did, vport->port_state, ndlp->nlp_flag);
8615 phba->fc_stat.elsRcvFARPR++;
8616 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8620 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8621 did, vport->port_state, ndlp->nlp_flag);
8623 phba->fc_stat.elsRcvFARP++;
8624 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8628 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8629 did, vport->port_state, ndlp->nlp_flag);
8631 phba->fc_stat.elsRcvFAN++;
8632 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8635 case ELS_CMD_NVMEPRLI:
8636 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8637 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8638 did, vport->port_state, ndlp->nlp_flag);
8640 phba->fc_stat.elsRcvPRLI++;
8641 if ((vport->port_state < LPFC_DISC_AUTH) &&
8642 (vport->fc_flag & FC_FABRIC)) {
8643 rjt_err = LSRJT_UNABLE_TPC;
8644 rjt_exp = LSEXP_NOTHING_MORE;
8647 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8650 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8651 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8652 did, vport->port_state, ndlp->nlp_flag);
8654 phba->fc_stat.elsRcvLIRR++;
8655 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8660 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8661 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8662 did, vport->port_state, ndlp->nlp_flag);
8664 phba->fc_stat.elsRcvRLS++;
8665 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8670 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8671 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8672 did, vport->port_state, ndlp->nlp_flag);
8674 phba->fc_stat.elsRcvRPL++;
8675 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8680 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8681 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8682 did, vport->port_state, ndlp->nlp_flag);
8684 phba->fc_stat.elsRcvRNID++;
8685 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8690 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8691 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8692 did, vport->port_state, ndlp->nlp_flag);
8693 phba->fc_stat.elsRcvRTV++;
8694 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8699 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8700 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8701 did, vport->port_state, ndlp->nlp_flag);
8703 phba->fc_stat.elsRcvRRQ++;
8704 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8709 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8710 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8711 did, vport->port_state, ndlp->nlp_flag);
8713 phba->fc_stat.elsRcvECHO++;
8714 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8719 /* receive this due to exchange closed */
8720 rjt_err = LSRJT_UNABLE_TPC;
8721 rjt_exp = LSEXP_INVALID_OX_RX;
8724 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8725 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8726 did, vport->port_state, ndlp->nlp_flag);
8728 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8731 /* There are no replies, so no rjt codes */
8734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8735 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8736 cmd, did, vport->port_state);
8738 /* Unsupported ELS command, reject */
8739 rjt_err = LSRJT_CMD_UNSUPPORTED;
8740 rjt_exp = LSEXP_NOTHING_MORE;
8742 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8743 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8744 "0115 Unknown ELS command x%x "
8745 "received from NPORT x%x\n", cmd, did);
8752 /* check if need to LS_RJT received ELS cmd */
8754 memset(&stat, 0, sizeof(stat));
8755 stat.un.b.lsRjtRsnCode = rjt_err;
8756 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8757 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8761 lpfc_nlp_put(elsiocb->context1);
8762 elsiocb->context1 = NULL;
8764 /* Special case. Driver received an unsolicited command that
8765 * unsupportable given the driver's current state. Reset the
8766 * link and start over.
8769 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8772 lpfc_linkdown(phba);
8773 lpfc_init_link(phba, mbox,
8775 phba->cfg_link_speed);
8776 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8777 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8778 mbox->vport = vport;
8779 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8781 mempool_free(mbox, phba->mbox_mem_pool);
8787 if (vport && !(vport->load_flag & FC_UNLOADING))
8788 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8789 "0111 Dropping received ELS cmd "
8790 "Data: x%x x%x x%x\n",
8791 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8792 phba->fc_stat.elsRcvDrop++;
8796 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8797 * @phba: pointer to lpfc hba data structure.
8798 * @pring: pointer to a SLI ring.
8799 * @elsiocb: pointer to lpfc els iocb data structure.
8801 * This routine is used to process an unsolicited event received from a SLI
8802 * (Service Level Interface) ring. The actual processing of the data buffer
8803 * associated with the unsolicited event is done by invoking the routine
8804 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8805 * SLI ring on which the unsolicited event was received.
8808 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8809 struct lpfc_iocbq *elsiocb)
8811 struct lpfc_vport *vport = phba->pport;
8812 IOCB_t *icmd = &elsiocb->iocb;
8814 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8815 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8817 elsiocb->context1 = NULL;
8818 elsiocb->context2 = NULL;
8819 elsiocb->context3 = NULL;
8821 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8822 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8823 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8824 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8825 IOERR_RCV_BUFFER_WAITING) {
8826 phba->fc_stat.NoRcvBuf++;
8827 /* Not enough posted buffers; Try posting more buffers */
8828 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8829 lpfc_post_buffer(phba, pring, 0);
8833 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8834 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8835 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8836 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8837 vport = phba->pport;
8839 vport = lpfc_find_vport_by_vpid(phba,
8840 icmd->unsli3.rcvsli3.vpi);
8843 /* If there are no BDEs associated
8844 * with this IOCB, there is nothing to do.
8846 if (icmd->ulpBdeCount == 0)
8849 /* type of ELS cmd is first 32bit word
8852 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8853 elsiocb->context2 = bdeBuf1;
8855 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8856 icmd->un.cont64[0].addrLow);
8857 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8861 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8863 * The different unsolicited event handlers would tell us
8864 * if they are done with "mp" by setting context2 to NULL.
8866 if (elsiocb->context2) {
8867 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8868 elsiocb->context2 = NULL;
8871 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8872 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8873 icmd->ulpBdeCount == 2) {
8874 elsiocb->context2 = bdeBuf2;
8875 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8876 /* free mp if we are done with it */
8877 if (elsiocb->context2) {
8878 lpfc_in_buf_free(phba, elsiocb->context2);
8879 elsiocb->context2 = NULL;
8885 lpfc_start_fdmi(struct lpfc_vport *vport)
8887 struct lpfc_nodelist *ndlp;
8889 /* If this is the first time, allocate an ndlp and initialize
8890 * it. Otherwise, make sure the node is enabled and then do the
8893 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8895 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8897 ndlp->nlp_type |= NLP_FABRIC;
8903 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8904 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8908 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8909 * @phba: pointer to lpfc hba data structure.
8910 * @vport: pointer to a virtual N_Port data structure.
8912 * This routine issues a Port Login (PLOGI) to the Name Server with
8913 * State Change Request (SCR) for a @vport. This routine will create an
8914 * ndlp for the Name Server associated to the @vport if such node does
8915 * not already exist. The PLOGI to Name Server is issued by invoking the
8916 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8917 * (FDMI) is configured to the @vport, a FDMI node will be created and
8918 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8921 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8923 struct lpfc_nodelist *ndlp;
8924 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8927 * If lpfc_delay_discovery parameter is set and the clean address
8928 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8931 spin_lock_irq(shost->host_lock);
8932 if (vport->fc_flag & FC_DISC_DELAYED) {
8933 spin_unlock_irq(shost->host_lock);
8934 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8935 "3334 Delay fc port discovery for %d seconds\n",
8937 mod_timer(&vport->delayed_disc_tmo,
8938 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8941 spin_unlock_irq(shost->host_lock);
8943 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8945 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8947 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8948 lpfc_disc_start(vport);
8951 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8952 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8953 "0251 NameServer login: no memory\n");
8958 ndlp->nlp_type |= NLP_FABRIC;
8960 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8962 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8963 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8964 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8965 "0252 Cannot issue NameServer login\n");
8969 if ((phba->cfg_enable_SmartSAN ||
8970 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8971 (vport->load_flag & FC_ALLOW_FDMI))
8972 lpfc_start_fdmi(vport);
8976 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8977 * @phba: pointer to lpfc hba data structure.
8978 * @pmb: pointer to the driver internal queue element for mailbox command.
8980 * This routine is the completion callback function to register new vport
8981 * mailbox command. If the new vport mailbox command completes successfully,
8982 * the fabric registration login shall be performed on physical port (the
8983 * new vport created is actually a physical port, with VPI 0) or the port
8984 * login to Name Server for State Change Request (SCR) will be performed
8985 * on virtual port (real virtual port, with VPI greater than 0).
8988 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8990 struct lpfc_vport *vport = pmb->vport;
8991 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8992 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
8993 MAILBOX_t *mb = &pmb->u.mb;
8996 spin_lock_irq(shost->host_lock);
8997 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8998 spin_unlock_irq(shost->host_lock);
9000 if (mb->mbxStatus) {
9001 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9002 "0915 Register VPI failed : Status: x%x"
9003 " upd bit: x%x \n", mb->mbxStatus,
9004 mb->un.varRegVpi.upd);
9005 if (phba->sli_rev == LPFC_SLI_REV4 &&
9006 mb->un.varRegVpi.upd)
9007 goto mbox_err_exit ;
9009 switch (mb->mbxStatus) {
9010 case 0x11: /* unsupported feature */
9011 case 0x9603: /* max_vpi exceeded */
9012 case 0x9602: /* Link event since CLEAR_LA */
9013 /* giving up on vport registration */
9014 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9015 spin_lock_irq(shost->host_lock);
9016 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9017 spin_unlock_irq(shost->host_lock);
9018 lpfc_can_disctmo(vport);
9020 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9022 spin_lock_irq(shost->host_lock);
9023 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9024 spin_unlock_irq(shost->host_lock);
9025 lpfc_init_vpi(phba, pmb, vport->vpi);
9027 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9028 rc = lpfc_sli_issue_mbox(phba, pmb,
9030 if (rc == MBX_NOT_FINISHED) {
9031 lpfc_printf_vlog(vport, KERN_ERR,
9033 "2732 Failed to issue INIT_VPI"
9034 " mailbox command\n");
9041 /* Try to recover from this error */
9042 if (phba->sli_rev == LPFC_SLI_REV4)
9043 lpfc_sli4_unreg_all_rpis(vport);
9044 lpfc_mbx_unreg_vpi(vport);
9045 spin_lock_irq(shost->host_lock);
9046 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9047 spin_unlock_irq(shost->host_lock);
9048 if (mb->mbxStatus == MBX_NOT_FINISHED)
9050 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9051 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9052 if (phba->sli_rev == LPFC_SLI_REV4)
9053 lpfc_issue_init_vfi(vport);
9055 lpfc_initial_flogi(vport);
9057 lpfc_initial_fdisc(vport);
9062 spin_lock_irq(shost->host_lock);
9063 vport->vpi_state |= LPFC_VPI_REGISTERED;
9064 spin_unlock_irq(shost->host_lock);
9065 if (vport == phba->pport) {
9066 if (phba->sli_rev < LPFC_SLI_REV4)
9067 lpfc_issue_fabric_reglogin(vport);
9070 * If the physical port is instantiated using
9071 * FDISC, do not start vport discovery.
9073 if (vport->port_state != LPFC_FDISC)
9074 lpfc_start_fdiscs(phba);
9075 lpfc_do_scr_ns_plogi(phba, vport);
9078 lpfc_do_scr_ns_plogi(phba, vport);
9081 /* Now, we decrement the ndlp reference count held for this
9086 mempool_free(pmb, phba->mbox_mem_pool);
9091 * lpfc_register_new_vport - Register a new vport with a HBA
9092 * @phba: pointer to lpfc hba data structure.
9093 * @vport: pointer to a host virtual N_Port data structure.
9094 * @ndlp: pointer to a node-list data structure.
9096 * This routine registers the @vport as a new virtual port with a HBA.
9097 * It is done through a registering vpi mailbox command.
9100 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9101 struct lpfc_nodelist *ndlp)
9103 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9106 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9108 lpfc_reg_vpi(vport, mbox);
9109 mbox->vport = vport;
9110 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9111 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9112 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9113 == MBX_NOT_FINISHED) {
9114 /* mailbox command not success, decrement ndlp
9115 * reference count for this command
9118 mempool_free(mbox, phba->mbox_mem_pool);
9120 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9121 "0253 Register VPI: Can't send mbox\n");
9125 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9126 "0254 Register VPI: no memory\n");
9132 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9133 spin_lock_irq(shost->host_lock);
9134 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9135 spin_unlock_irq(shost->host_lock);
9140 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9141 * @phba: pointer to lpfc hba data structure.
9143 * This routine cancels the retry delay timers to all the vports.
9146 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9148 struct lpfc_vport **vports;
9149 struct lpfc_nodelist *ndlp;
9150 uint32_t link_state;
9153 /* Treat this failure as linkdown for all vports */
9154 link_state = phba->link_state;
9155 lpfc_linkdown(phba);
9156 phba->link_state = link_state;
9158 vports = lpfc_create_vport_work_array(phba);
9161 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9162 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9164 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9165 lpfc_els_flush_cmd(vports[i]);
9167 lpfc_destroy_vport_work_array(phba, vports);
9172 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9173 * @phba: pointer to lpfc hba data structure.
9175 * This routine abort all pending discovery commands and
9176 * start a timer to retry FLOGI for the physical port
9180 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9182 struct lpfc_nodelist *ndlp;
9183 struct Scsi_Host *shost;
9185 /* Cancel the all vports retry delay retry timers */
9186 lpfc_cancel_all_vport_retry_delay_timer(phba);
9188 /* If fabric require FLOGI, then re-instantiate physical login */
9189 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9193 shost = lpfc_shost_from_vport(phba->pport);
9194 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9195 spin_lock_irq(shost->host_lock);
9196 ndlp->nlp_flag |= NLP_DELAY_TMO;
9197 spin_unlock_irq(shost->host_lock);
9198 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9199 phba->pport->port_state = LPFC_FLOGI;
9204 * lpfc_fabric_login_reqd - Check if FLOGI required.
9205 * @phba: pointer to lpfc hba data structure.
9206 * @cmdiocb: pointer to FDISC command iocb.
9207 * @rspiocb: pointer to FDISC response iocb.
9209 * This routine checks if a FLOGI is reguired for FDISC
9213 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9214 struct lpfc_iocbq *cmdiocb,
9215 struct lpfc_iocbq *rspiocb)
9218 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9219 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9226 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9227 * @phba: pointer to lpfc hba data structure.
9228 * @cmdiocb: pointer to lpfc command iocb data structure.
9229 * @rspiocb: pointer to lpfc response iocb data structure.
9231 * This routine is the completion callback function to a Fabric Discover
9232 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9233 * single threaded, each FDISC completion callback function will reset
9234 * the discovery timer for all vports such that the timers will not get
9235 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9236 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9237 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9238 * assigned to the vport has been changed with the completion of the FDISC
9239 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9240 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9241 * routine is invoked to register new vport with the HBA. Otherwise, the
9242 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9243 * Server for State Change Request (SCR).
9246 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9247 struct lpfc_iocbq *rspiocb)
9249 struct lpfc_vport *vport = cmdiocb->vport;
9250 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9251 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9252 struct lpfc_nodelist *np;
9253 struct lpfc_nodelist *next_np;
9254 IOCB_t *irsp = &rspiocb->iocb;
9255 struct lpfc_iocbq *piocb;
9256 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9257 struct serv_parm *sp;
9258 uint8_t fabric_param_changed;
9260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9261 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9262 irsp->ulpStatus, irsp->un.ulpWord[4],
9264 /* Since all FDISCs are being single threaded, we
9265 * must reset the discovery timer for ALL vports
9266 * waiting to send FDISC when one completes.
9268 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9269 lpfc_set_disctmo(piocb->vport);
9272 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9273 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9274 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9276 if (irsp->ulpStatus) {
9278 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9279 lpfc_retry_pport_discovery(phba);
9283 /* Check for retry */
9284 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9287 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9288 "0126 FDISC failed. (x%x/x%x)\n",
9289 irsp->ulpStatus, irsp->un.ulpWord[4]);
9292 spin_lock_irq(shost->host_lock);
9293 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9294 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9295 vport->fc_flag |= FC_FABRIC;
9296 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9297 vport->fc_flag |= FC_PUBLIC_LOOP;
9298 spin_unlock_irq(shost->host_lock);
9300 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9301 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9302 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9305 sp = prsp->virt + sizeof(uint32_t);
9306 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9307 memcpy(&vport->fabric_portname, &sp->portName,
9308 sizeof(struct lpfc_name));
9309 memcpy(&vport->fabric_nodename, &sp->nodeName,
9310 sizeof(struct lpfc_name));
9311 if (fabric_param_changed &&
9312 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9313 /* If our NportID changed, we need to ensure all
9314 * remaining NPORTs get unreg_login'ed so we can
9317 list_for_each_entry_safe(np, next_np,
9318 &vport->fc_nodes, nlp_listp) {
9319 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
9320 !(np->nlp_flag & NLP_NPR_ADISC))
9322 spin_lock_irq(shost->host_lock);
9323 np->nlp_flag &= ~NLP_NPR_ADISC;
9324 spin_unlock_irq(shost->host_lock);
9325 lpfc_unreg_rpi(vport, np);
9327 lpfc_cleanup_pending_mbox(vport);
9329 if (phba->sli_rev == LPFC_SLI_REV4)
9330 lpfc_sli4_unreg_all_rpis(vport);
9332 lpfc_mbx_unreg_vpi(vport);
9333 spin_lock_irq(shost->host_lock);
9334 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9335 if (phba->sli_rev == LPFC_SLI_REV4)
9336 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9338 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9339 spin_unlock_irq(shost->host_lock);
9340 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9341 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9343 * Driver needs to re-reg VPI in order for f/w
9344 * to update the MAC address.
9346 lpfc_register_new_vport(phba, vport, ndlp);
9350 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9351 lpfc_issue_init_vpi(vport);
9352 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9353 lpfc_register_new_vport(phba, vport, ndlp);
9355 lpfc_do_scr_ns_plogi(phba, vport);
9358 if (vport->fc_vport &&
9359 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9360 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9361 /* Cancel discovery timer */
9362 lpfc_can_disctmo(vport);
9365 lpfc_els_free_iocb(phba, cmdiocb);
9369 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9370 * @vport: pointer to a virtual N_Port data structure.
9371 * @ndlp: pointer to a node-list data structure.
9372 * @retry: number of retries to the command IOCB.
9374 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9375 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9376 * routine to issue the IOCB, which makes sure only one outstanding fabric
9377 * IOCB will be sent off HBA at any given time.
9379 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9380 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9381 * will be stored into the context1 field of the IOCB for the completion
9382 * callback function to the FDISC ELS command.
9385 * 0 - Successfully issued fdisc iocb command
9386 * 1 - Failed to issue fdisc iocb command
9389 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9392 struct lpfc_hba *phba = vport->phba;
9394 struct lpfc_iocbq *elsiocb;
9395 struct serv_parm *sp;
9398 int did = ndlp->nlp_DID;
9401 vport->port_state = LPFC_FDISC;
9402 vport->fc_myDID = 0;
9403 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9404 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9407 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9408 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9409 "0255 Issue FDISC: no IOCB\n");
9413 icmd = &elsiocb->iocb;
9414 icmd->un.elsreq64.myID = 0;
9415 icmd->un.elsreq64.fl = 1;
9418 * SLI3 ports require a different context type value than SLI4.
9419 * Catch SLI3 ports here and override the prep.
9421 if (phba->sli_rev == LPFC_SLI_REV3) {
9426 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9427 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9428 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9429 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9430 sp = (struct serv_parm *) pcmd;
9431 /* Setup CSPs accordingly for Fabric */
9432 sp->cmn.e_d_tov = 0;
9433 sp->cmn.w2.r_a_tov = 0;
9434 sp->cmn.virtual_fabric_support = 0;
9435 sp->cls1.classValid = 0;
9436 sp->cls2.seqDelivery = 1;
9437 sp->cls3.seqDelivery = 1;
9439 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9440 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9441 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9442 pcmd += sizeof(uint32_t); /* Port Name */
9443 memcpy(pcmd, &vport->fc_portname, 8);
9444 pcmd += sizeof(uint32_t); /* Node Name */
9445 pcmd += sizeof(uint32_t); /* Node Name */
9446 memcpy(pcmd, &vport->fc_nodename, 8);
9447 sp->cmn.valid_vendor_ver_level = 0;
9448 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9449 lpfc_set_disctmo(vport);
9451 phba->fc_stat.elsXmitFDISC++;
9452 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9454 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9455 "Issue FDISC: did:x%x",
9458 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9459 if (rc == IOCB_ERROR) {
9460 lpfc_els_free_iocb(phba, elsiocb);
9461 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9462 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9463 "0256 Issue FDISC: Cannot send IOCB\n");
9466 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9471 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9472 * @phba: pointer to lpfc hba data structure.
9473 * @cmdiocb: pointer to lpfc command iocb data structure.
9474 * @rspiocb: pointer to lpfc response iocb data structure.
9476 * This routine is the completion callback function to the issuing of a LOGO
9477 * ELS command off a vport. It frees the command IOCB and then decrement the
9478 * reference count held on ndlp for this completion function, indicating that
9479 * the reference to the ndlp is no long needed. Note that the
9480 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9481 * callback function and an additional explicit ndlp reference decrementation
9482 * will trigger the actual release of the ndlp.
9485 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9486 struct lpfc_iocbq *rspiocb)
9488 struct lpfc_vport *vport = cmdiocb->vport;
9490 struct lpfc_nodelist *ndlp;
9491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9493 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9494 irsp = &rspiocb->iocb;
9495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9496 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9497 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9499 lpfc_els_free_iocb(phba, cmdiocb);
9500 vport->unreg_vpi_cmpl = VPORT_ERROR;
9502 /* Trigger the release of the ndlp after logo */
9505 /* NPIV LOGO completes to NPort <nlp_DID> */
9506 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9507 "2928 NPIV LOGO completes to NPort x%x "
9508 "Data: x%x x%x x%x x%x\n",
9509 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9510 irsp->ulpTimeout, vport->num_disc_nodes);
9512 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9513 spin_lock_irq(shost->host_lock);
9514 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9515 vport->fc_flag &= ~FC_FABRIC;
9516 spin_unlock_irq(shost->host_lock);
9517 lpfc_can_disctmo(vport);
9522 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9523 * @vport: pointer to a virtual N_Port data structure.
9524 * @ndlp: pointer to a node-list data structure.
9526 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9528 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9529 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9530 * will be stored into the context1 field of the IOCB for the completion
9531 * callback function to the LOGO ELS command.
9534 * 0 - Successfully issued logo off the @vport
9535 * 1 - Failed to issue logo off the @vport
9538 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9540 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9541 struct lpfc_hba *phba = vport->phba;
9542 struct lpfc_iocbq *elsiocb;
9546 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9547 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9552 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9553 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9554 pcmd += sizeof(uint32_t);
9556 /* Fill in LOGO payload */
9557 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9558 pcmd += sizeof(uint32_t);
9559 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9561 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9562 "Issue LOGO npiv did:x%x flg:x%x",
9563 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9565 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9566 spin_lock_irq(shost->host_lock);
9567 ndlp->nlp_flag |= NLP_LOGO_SND;
9568 spin_unlock_irq(shost->host_lock);
9569 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9571 spin_lock_irq(shost->host_lock);
9572 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9573 spin_unlock_irq(shost->host_lock);
9574 lpfc_els_free_iocb(phba, elsiocb);
9581 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9582 * @t: timer context used to obtain the lpfc hba.
9584 * This routine is invoked by the fabric iocb block timer after
9585 * timeout. It posts the fabric iocb block timeout event by setting the
9586 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9587 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9588 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9589 * posted event WORKER_FABRIC_BLOCK_TMO.
9592 lpfc_fabric_block_timeout(struct timer_list *t)
9594 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9595 unsigned long iflags;
9596 uint32_t tmo_posted;
9598 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9599 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9601 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9602 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9605 lpfc_worker_wake_up(phba);
9610 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9611 * @phba: pointer to lpfc hba data structure.
9613 * This routine issues one fabric iocb from the driver internal list to
9614 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9615 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9616 * remove one pending fabric iocb from the driver internal list and invokes
9617 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9620 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9622 struct lpfc_iocbq *iocb;
9623 unsigned long iflags;
9629 spin_lock_irqsave(&phba->hbalock, iflags);
9630 /* Post any pending iocb to the SLI layer */
9631 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9632 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9635 /* Increment fabric iocb count to hold the position */
9636 atomic_inc(&phba->fabric_iocb_count);
9638 spin_unlock_irqrestore(&phba->hbalock, iflags);
9640 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9641 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9642 iocb->iocb_flag |= LPFC_IO_FABRIC;
9644 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9645 "Fabric sched1: ste:x%x",
9646 iocb->vport->port_state, 0, 0);
9648 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9650 if (ret == IOCB_ERROR) {
9651 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9652 iocb->fabric_iocb_cmpl = NULL;
9653 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9655 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9656 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9657 iocb->iocb_cmpl(phba, iocb, iocb);
9659 atomic_dec(&phba->fabric_iocb_count);
9668 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9669 * @phba: pointer to lpfc hba data structure.
9671 * This routine unblocks the issuing fabric iocb command. The function
9672 * will clear the fabric iocb block bit and then invoke the routine
9673 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9674 * from the driver internal fabric iocb list.
9677 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9679 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9681 lpfc_resume_fabric_iocbs(phba);
9686 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9687 * @phba: pointer to lpfc hba data structure.
9689 * This routine blocks the issuing fabric iocb for a specified amount of
9690 * time (currently 100 ms). This is done by set the fabric iocb block bit
9691 * and set up a timeout timer for 100ms. When the block bit is set, no more
9692 * fabric iocb will be issued out of the HBA.
9695 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9699 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9700 /* Start a timer to unblock fabric iocbs after 100ms */
9702 mod_timer(&phba->fabric_block_timer,
9703 jiffies + msecs_to_jiffies(100));
9709 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9710 * @phba: pointer to lpfc hba data structure.
9711 * @cmdiocb: pointer to lpfc command iocb data structure.
9712 * @rspiocb: pointer to lpfc response iocb data structure.
9714 * This routine is the callback function that is put to the fabric iocb's
9715 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9716 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9717 * function first restores and invokes the original iocb's callback function
9718 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9719 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9722 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9723 struct lpfc_iocbq *rspiocb)
9727 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9729 switch (rspiocb->iocb.ulpStatus) {
9730 case IOSTAT_NPORT_RJT:
9731 case IOSTAT_FABRIC_RJT:
9732 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9733 lpfc_block_fabric_iocbs(phba);
9737 case IOSTAT_NPORT_BSY:
9738 case IOSTAT_FABRIC_BSY:
9739 lpfc_block_fabric_iocbs(phba);
9743 stat.un.lsRjtError =
9744 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9745 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9746 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9747 lpfc_block_fabric_iocbs(phba);
9751 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9753 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9754 cmdiocb->fabric_iocb_cmpl = NULL;
9755 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9756 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9758 atomic_dec(&phba->fabric_iocb_count);
9759 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9760 /* Post any pending iocbs to HBA */
9761 lpfc_resume_fabric_iocbs(phba);
9766 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9767 * @phba: pointer to lpfc hba data structure.
9768 * @iocb: pointer to lpfc command iocb data structure.
9770 * This routine is used as the top-level API for issuing a fabric iocb command
9771 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9772 * function makes sure that only one fabric bound iocb will be outstanding at
9773 * any given time. As such, this function will first check to see whether there
9774 * is already an outstanding fabric iocb on the wire. If so, it will put the
9775 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9776 * issued later. Otherwise, it will issue the iocb on the wire and update the
9777 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9779 * Note, this implementation has a potential sending out fabric IOCBs out of
9780 * order. The problem is caused by the construction of the "ready" boolen does
9781 * not include the condition that the internal fabric IOCB list is empty. As
9782 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9783 * ahead of the fabric IOCBs in the internal list.
9786 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9787 * IOCB_ERROR - failed to issue fabric iocb
9790 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9792 unsigned long iflags;
9796 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9798 spin_lock_irqsave(&phba->hbalock, iflags);
9799 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9800 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9803 /* Increment fabric iocb count to hold the position */
9804 atomic_inc(&phba->fabric_iocb_count);
9805 spin_unlock_irqrestore(&phba->hbalock, iflags);
9807 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9808 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9809 iocb->iocb_flag |= LPFC_IO_FABRIC;
9811 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9812 "Fabric sched2: ste:x%x",
9813 iocb->vport->port_state, 0, 0);
9815 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9817 if (ret == IOCB_ERROR) {
9818 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9819 iocb->fabric_iocb_cmpl = NULL;
9820 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9821 atomic_dec(&phba->fabric_iocb_count);
9824 spin_lock_irqsave(&phba->hbalock, iflags);
9825 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9826 spin_unlock_irqrestore(&phba->hbalock, iflags);
9833 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9834 * @vport: pointer to a virtual N_Port data structure.
9836 * This routine aborts all the IOCBs associated with a @vport from the
9837 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9838 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9839 * list, removes each IOCB associated with the @vport off the list, set the
9840 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9841 * associated with the IOCB.
9843 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9845 LIST_HEAD(completions);
9846 struct lpfc_hba *phba = vport->phba;
9847 struct lpfc_iocbq *tmp_iocb, *piocb;
9849 spin_lock_irq(&phba->hbalock);
9850 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9853 if (piocb->vport != vport)
9856 list_move_tail(&piocb->list, &completions);
9858 spin_unlock_irq(&phba->hbalock);
9860 /* Cancel all the IOCBs from the completions list */
9861 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9866 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9867 * @ndlp: pointer to a node-list data structure.
9869 * This routine aborts all the IOCBs associated with an @ndlp from the
9870 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9871 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9872 * list, removes each IOCB associated with the @ndlp off the list, set the
9873 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9874 * associated with the IOCB.
9876 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9878 LIST_HEAD(completions);
9879 struct lpfc_hba *phba = ndlp->phba;
9880 struct lpfc_iocbq *tmp_iocb, *piocb;
9881 struct lpfc_sli_ring *pring;
9883 pring = lpfc_phba_elsring(phba);
9885 if (unlikely(!pring))
9888 spin_lock_irq(&phba->hbalock);
9889 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9891 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9893 list_move_tail(&piocb->list, &completions);
9896 spin_unlock_irq(&phba->hbalock);
9898 /* Cancel all the IOCBs from the completions list */
9899 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9904 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9905 * @phba: pointer to lpfc hba data structure.
9907 * This routine aborts all the IOCBs currently on the driver internal
9908 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9909 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9910 * list, removes IOCBs off the list, set the status feild to
9911 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9914 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9916 LIST_HEAD(completions);
9918 spin_lock_irq(&phba->hbalock);
9919 list_splice_init(&phba->fabric_iocb_list, &completions);
9920 spin_unlock_irq(&phba->hbalock);
9922 /* Cancel all the IOCBs from the completions list */
9923 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9928 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9929 * @vport: pointer to lpfc vport data structure.
9931 * This routine is invoked by the vport cleanup for deletions and the cleanup
9932 * for an ndlp on removal.
9935 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9937 struct lpfc_hba *phba = vport->phba;
9938 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9939 unsigned long iflag = 0;
9941 spin_lock_irqsave(&phba->hbalock, iflag);
9942 spin_lock(&phba->sli4_hba.sgl_list_lock);
9943 list_for_each_entry_safe(sglq_entry, sglq_next,
9944 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9945 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
9946 lpfc_nlp_put(sglq_entry->ndlp);
9947 sglq_entry->ndlp = NULL;
9950 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9951 spin_unlock_irqrestore(&phba->hbalock, iflag);
9956 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9957 * @phba: pointer to lpfc hba data structure.
9958 * @axri: pointer to the els xri abort wcqe structure.
9960 * This routine is invoked by the worker thread to process a SLI4 slow-path
9964 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9965 struct sli4_wcqe_xri_aborted *axri)
9967 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9968 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9971 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9972 unsigned long iflag = 0;
9973 struct lpfc_nodelist *ndlp;
9974 struct lpfc_sli_ring *pring;
9976 pring = lpfc_phba_elsring(phba);
9978 spin_lock_irqsave(&phba->hbalock, iflag);
9979 spin_lock(&phba->sli4_hba.sgl_list_lock);
9980 list_for_each_entry_safe(sglq_entry, sglq_next,
9981 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9982 if (sglq_entry->sli4_xritag == xri) {
9983 list_del(&sglq_entry->list);
9984 ndlp = sglq_entry->ndlp;
9985 sglq_entry->ndlp = NULL;
9986 list_add_tail(&sglq_entry->list,
9987 &phba->sli4_hba.lpfc_els_sgl_list);
9988 sglq_entry->state = SGL_FREED;
9989 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9990 spin_unlock_irqrestore(&phba->hbalock, iflag);
9993 lpfc_set_rrq_active(phba, ndlp,
9994 sglq_entry->sli4_lxritag,
9999 /* Check if TXQ queue needs to be serviced */
10000 if (pring && !list_empty(&pring->txq))
10001 lpfc_worker_wake_up(phba);
10005 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10006 lxri = lpfc_sli4_xri_inrange(phba, xri);
10007 if (lxri == NO_XRI) {
10008 spin_unlock_irqrestore(&phba->hbalock, iflag);
10011 spin_lock(&phba->sli4_hba.sgl_list_lock);
10012 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10013 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10014 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10015 spin_unlock_irqrestore(&phba->hbalock, iflag);
10018 sglq_entry->state = SGL_XRI_ABORTED;
10019 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10020 spin_unlock_irqrestore(&phba->hbalock, iflag);
10024 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10025 * @vport: pointer to virtual port object.
10026 * @ndlp: nodelist pointer for the impacted node.
10028 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10029 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10030 * the driver is required to send a LOGO to the remote node before it
10031 * attempts to recover its login to the remote node.
10034 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10035 struct lpfc_nodelist *ndlp)
10037 struct Scsi_Host *shost;
10038 struct lpfc_hba *phba;
10039 unsigned long flags = 0;
10041 shost = lpfc_shost_from_vport(vport);
10042 phba = vport->phba;
10043 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10044 lpfc_printf_log(phba, KERN_INFO,
10045 LOG_SLI, "3093 No rport recovery needed. "
10046 "rport in state 0x%x\n", ndlp->nlp_state);
10049 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10050 "3094 Start rport recovery on shost id 0x%x "
10051 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10053 shost->host_no, ndlp->nlp_DID,
10054 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10057 * The rport is not responding. Remove the FCP-2 flag to prevent
10058 * an ADISC in the follow-up recovery code.
10060 spin_lock_irqsave(shost->host_lock, flags);
10061 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10062 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10063 spin_unlock_irqrestore(shost->host_lock, flags);
10064 lpfc_unreg_rpi(vport, ndlp);