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 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
305 elsiocb->retry = retry;
306 elsiocb->vport = vport;
307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
310 list_add(&prsp->list, &pcmd->list);
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
316 "NPORT x%x I/O tag: x%x, port state:x%x "
317 "rpi x%x fc_flag:x%x\n",
318 elscmd, did, elsiocb->iotag,
319 vport->port_state, ndlp->nlp_rpi,
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
325 "NPORT x%x I/O tag: x%x, size: x%x "
326 "port_state x%x rpi x%x fc_flag x%x\n",
327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
328 cmdSize, vport->port_state,
329 ndlp->nlp_rpi, vport->fc_flag);
333 els_iocb_free_pbuf_exit:
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
338 els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
342 els_iocb_free_pcmb_exit:
344 lpfc_sli_release_iocbq(phba, elsiocb);
349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
350 * @vport: pointer to a host virtual N_Port data structure.
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
365 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
367 struct lpfc_hba *phba = vport->phba;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
394 if (rc == MBX_NOT_FINISHED) {
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
416 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
417 if (!mbox->ctx_ndlp) {
422 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
423 if (rc == MBX_NOT_FINISHED) {
425 goto fail_issue_reg_login;
430 fail_issue_reg_login:
431 /* decrement the reference count on ndlp just incremented
432 * for the failed mbox command.
436 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
437 lpfc_mbuf_free(phba, mp->virt, mp->phys);
440 mempool_free(mbox, phba->mbox_mem_pool);
443 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
444 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
445 "0249 Cannot issue Register Fabric login: Err %d\n",
451 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
452 * @vport: pointer to a host virtual N_Port data structure.
454 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
455 * the @vport. This mailbox command is necessary for SLI4 port only.
458 * 0 - successfully issued REG_VFI for @vport
459 * A failure code otherwise.
462 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
464 struct lpfc_hba *phba = vport->phba;
465 LPFC_MBOXQ_t *mboxq = NULL;
466 struct lpfc_nodelist *ndlp;
467 struct lpfc_dmabuf *dmabuf = NULL;
470 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
471 if ((phba->sli_rev == LPFC_SLI_REV4) &&
472 !(phba->link_flag & LS_LOOPBACK_MODE) &&
473 !(vport->fc_flag & FC_PT2PT)) {
474 ndlp = lpfc_findnode_did(vport, Fabric_DID);
481 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
487 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
488 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
489 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
494 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
499 memcpy(dmabuf->virt, &phba->fc_fabparam,
500 sizeof(struct serv_parm));
503 vport->port_state = LPFC_FABRIC_CFG_LINK;
505 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
507 lpfc_reg_vfi(mboxq, vport, 0);
509 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
510 mboxq->vport = vport;
511 mboxq->ctx_buf = dmabuf;
512 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
513 if (rc == MBX_NOT_FINISHED) {
521 mempool_free(mboxq, phba->mbox_mem_pool);
524 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
528 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
529 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
530 "0289 Issue Register VFI failed: Err %d\n", rc);
535 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
536 * @vport: pointer to a host virtual N_Port data structure.
538 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
539 * the @vport. This mailbox command is necessary for SLI4 port only.
542 * 0 - successfully issued REG_VFI for @vport
543 * A failure code otherwise.
546 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
548 struct lpfc_hba *phba = vport->phba;
549 struct Scsi_Host *shost;
553 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
555 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
556 "2556 UNREG_VFI mbox allocation failed"
557 "HBA state x%x\n", phba->pport->port_state);
561 lpfc_unreg_vfi(mboxq, vport);
562 mboxq->vport = vport;
563 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
565 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
566 if (rc == MBX_NOT_FINISHED) {
567 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
568 "2557 UNREG_VFI issue mbox failed rc x%x "
570 rc, phba->pport->port_state);
571 mempool_free(mboxq, phba->mbox_mem_pool);
575 shost = lpfc_shost_from_vport(vport);
576 spin_lock_irq(shost->host_lock);
577 vport->fc_flag &= ~FC_VFI_REGISTERED;
578 spin_unlock_irq(shost->host_lock);
583 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
584 * @vport: pointer to a host virtual N_Port data structure.
585 * @sp: pointer to service parameter data structure.
587 * This routine is called from FLOGI/FDISC completion handler functions.
588 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter else return
590 * 0. This function also set flag in the vport data structure to delay
591 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
592 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
593 * node nodename is changed in the completion service parameter.
596 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
597 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
601 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
602 struct serv_parm *sp)
604 struct lpfc_hba *phba = vport->phba;
605 uint8_t fabric_param_changed = 0;
606 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
608 if ((vport->fc_prevDID != vport->fc_myDID) ||
609 memcmp(&vport->fabric_portname, &sp->portName,
610 sizeof(struct lpfc_name)) ||
611 memcmp(&vport->fabric_nodename, &sp->nodeName,
612 sizeof(struct lpfc_name)) ||
613 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
614 fabric_param_changed = 1;
615 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
618 * Word 1 Bit 31 in common service parameter is overloaded.
619 * Word 1 Bit 31 in FLOGI request is multiple NPort request
620 * Word 1 Bit 31 in FLOGI response is clean address bit
622 * If fabric parameter is changed and clean address bit is
623 * cleared delay nport discovery if
624 * - vport->fc_prevDID != 0 (not initial discovery) OR
625 * - lpfc_delay_discovery module parameter is set.
627 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
628 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
629 spin_lock_irq(shost->host_lock);
630 vport->fc_flag |= FC_DISC_DELAYED;
631 spin_unlock_irq(shost->host_lock);
634 return fabric_param_changed;
639 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
640 * @vport: pointer to a host virtual N_Port data structure.
641 * @ndlp: pointer to a node-list data structure.
642 * @sp: pointer to service parameter data structure.
643 * @irsp: pointer to the IOCB within the lpfc response IOCB.
645 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
646 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
647 * port in a fabric topology. It properly sets up the parameters to the @ndlp
648 * from the IOCB response. It also check the newly assigned N_Port ID to the
649 * @vport against the previously assigned N_Port ID. If it is different from
650 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
651 * is invoked on all the remaining nodes with the @vport to unregister the
652 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
653 * is invoked to register login to the fabric.
656 * 0 - Success (currently, always return 0)
659 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
660 struct serv_parm *sp, IOCB_t *irsp)
662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
663 struct lpfc_hba *phba = vport->phba;
664 struct lpfc_nodelist *np;
665 struct lpfc_nodelist *next_np;
666 uint8_t fabric_param_changed;
668 spin_lock_irq(shost->host_lock);
669 vport->fc_flag |= FC_FABRIC;
670 spin_unlock_irq(shost->host_lock);
672 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
673 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
674 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
676 phba->fc_edtovResol = sp->cmn.edtovResolution;
677 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
679 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
680 spin_lock_irq(shost->host_lock);
681 vport->fc_flag |= FC_PUBLIC_LOOP;
682 spin_unlock_irq(shost->host_lock);
685 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
686 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
687 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
688 ndlp->nlp_class_sup = 0;
689 if (sp->cls1.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS1;
691 if (sp->cls2.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS2;
693 if (sp->cls3.classValid)
694 ndlp->nlp_class_sup |= FC_COS_CLASS3;
695 if (sp->cls4.classValid)
696 ndlp->nlp_class_sup |= FC_COS_CLASS4;
697 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
698 sp->cmn.bbRcvSizeLsb;
700 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
701 if (fabric_param_changed) {
702 /* Reset FDMI attribute masks based on config parameter */
703 if (phba->cfg_enable_SmartSAN ||
704 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
705 /* Setup appropriate attribute masks */
706 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
707 if (phba->cfg_enable_SmartSAN)
708 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
710 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
712 vport->fdmi_hba_mask = 0;
713 vport->fdmi_port_mask = 0;
717 memcpy(&vport->fabric_portname, &sp->portName,
718 sizeof(struct lpfc_name));
719 memcpy(&vport->fabric_nodename, &sp->nodeName,
720 sizeof(struct lpfc_name));
721 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
723 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
724 if (sp->cmn.response_multiple_NPort) {
725 lpfc_printf_vlog(vport, KERN_WARNING,
727 "1816 FLOGI NPIV supported, "
728 "response data 0x%x\n",
729 sp->cmn.response_multiple_NPort);
730 spin_lock_irq(&phba->hbalock);
731 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
732 spin_unlock_irq(&phba->hbalock);
734 /* Because we asked f/w for NPIV it still expects us
735 to call reg_vnpid atleast for the physcial host */
736 lpfc_printf_vlog(vport, KERN_WARNING,
738 "1817 Fabric does not support NPIV "
739 "- configuring single port mode.\n");
740 spin_lock_irq(&phba->hbalock);
741 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
742 spin_unlock_irq(&phba->hbalock);
747 * For FC we need to do some special processing because of the SLI
748 * Port's default settings of the Common Service Parameters.
750 if ((phba->sli_rev == LPFC_SLI_REV4) &&
751 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
752 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
753 if (fabric_param_changed)
754 lpfc_unregister_fcf_prep(phba);
756 /* This should just update the VFI CSPs*/
757 if (vport->fc_flag & FC_VFI_REGISTERED)
758 lpfc_issue_reg_vfi(vport);
761 if (fabric_param_changed &&
762 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
764 /* If our NportID changed, we need to ensure all
765 * remaining NPORTs get unreg_login'ed.
767 list_for_each_entry_safe(np, next_np,
768 &vport->fc_nodes, nlp_listp) {
769 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
770 !(np->nlp_flag & NLP_NPR_ADISC))
772 spin_lock_irq(shost->host_lock);
773 np->nlp_flag &= ~NLP_NPR_ADISC;
774 spin_unlock_irq(shost->host_lock);
775 lpfc_unreg_rpi(vport, np);
777 lpfc_cleanup_pending_mbox(vport);
779 if (phba->sli_rev == LPFC_SLI_REV4) {
780 lpfc_sli4_unreg_all_rpis(vport);
781 lpfc_mbx_unreg_vpi(vport);
782 spin_lock_irq(shost->host_lock);
783 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
784 spin_unlock_irq(shost->host_lock);
788 * For SLI3 and SLI4, the VPI needs to be reregistered in
789 * response to this fabric parameter change event.
791 spin_lock_irq(shost->host_lock);
792 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
793 spin_unlock_irq(shost->host_lock);
794 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
795 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
797 * Driver needs to re-reg VPI in order for f/w
798 * to update the MAC address.
800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
801 lpfc_register_new_vport(phba, vport, ndlp);
805 if (phba->sli_rev < LPFC_SLI_REV4) {
806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
807 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
808 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
809 lpfc_register_new_vport(phba, vport, ndlp);
811 lpfc_issue_fabric_reglogin(vport);
813 ndlp->nlp_type |= NLP_FABRIC;
814 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
815 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
816 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
817 lpfc_start_fdiscs(phba);
818 lpfc_do_scr_ns_plogi(phba, vport);
819 } else if (vport->fc_flag & FC_VFI_REGISTERED)
820 lpfc_issue_init_vpi(vport);
822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
823 "3135 Need register VFI: (x%x/%x)\n",
824 vport->fc_prevDID, vport->fc_myDID);
825 lpfc_issue_reg_vfi(vport);
832 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
833 * @vport: pointer to a host virtual N_Port data structure.
834 * @ndlp: pointer to a node-list data structure.
835 * @sp: pointer to service parameter data structure.
837 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
838 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
839 * in a point-to-point topology. First, the @vport's N_Port Name is compared
840 * with the received N_Port Name: if the @vport's N_Port Name is greater than
841 * the received N_Port Name lexicographically, this node shall assign local
842 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
843 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
844 * this node shall just wait for the remote node to issue PLOGI and assign
852 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 struct serv_parm *sp)
855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
856 struct lpfc_hba *phba = vport->phba;
860 spin_lock_irq(shost->host_lock);
861 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
862 vport->fc_flag |= FC_PT2PT;
863 spin_unlock_irq(shost->host_lock);
865 /* If we are pt2pt with another NPort, force NPIV off! */
866 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
868 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
869 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
870 lpfc_unregister_fcf_prep(phba);
872 spin_lock_irq(shost->host_lock);
873 vport->fc_flag &= ~FC_VFI_REGISTERED;
874 spin_unlock_irq(shost->host_lock);
875 phba->fc_topology_changed = 0;
878 rc = memcmp(&vport->fc_portname, &sp->portName,
879 sizeof(vport->fc_portname));
882 /* This side will initiate the PLOGI */
883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag |= FC_PT2PT_PLOGI;
885 spin_unlock_irq(shost->host_lock);
888 * N_Port ID cannot be 0, set our Id to LocalID
889 * the other side will be RemoteID.
894 vport->fc_myDID = PT2PT_LocalID;
896 /* Decrement ndlp reference count indicating that ndlp can be
897 * safely released when other references to it are done.
901 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
904 * Cannot find existing Fabric ndlp, so allocate a
907 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
912 memcpy(&ndlp->nlp_portname, &sp->portName,
913 sizeof(struct lpfc_name));
914 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
915 sizeof(struct lpfc_name));
916 /* Set state will put ndlp onto node list if not already done */
917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
918 spin_lock_irq(shost->host_lock);
919 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
920 spin_unlock_irq(shost->host_lock);
922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
926 lpfc_config_link(phba, mbox);
928 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
930 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
931 if (rc == MBX_NOT_FINISHED) {
932 mempool_free(mbox, phba->mbox_mem_pool);
936 /* This side will wait for the PLOGI, decrement ndlp reference
937 * count indicating that ndlp can be released when other
938 * references to it are done.
942 /* Start discovery - this should just do CLEAR_LA */
943 lpfc_disc_start(vport);
952 * lpfc_cmpl_els_flogi - Completion callback function for flogi
953 * @phba: pointer to lpfc hba data structure.
954 * @cmdiocb: pointer to lpfc command iocb data structure.
955 * @rspiocb: pointer to lpfc response iocb data structure.
957 * This routine is the top-level completion callback function for issuing
958 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
959 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
960 * retry has been made (either immediately or delayed with lpfc_els_retry()
961 * returning 1), the command IOCB will be released and function returned.
962 * If the retry attempt has been given up (possibly reach the maximum
963 * number of retries), one additional decrement of ndlp reference shall be
964 * invoked before going out after releasing the command IOCB. This will
965 * actually release the remote node (Note, lpfc_els_free_iocb() will also
966 * invoke one decrement of ndlp reference count). If no error reported in
967 * the IOCB status, the command Port ID field is used to determine whether
968 * this is a point-to-point topology or a fabric topology: if the Port ID
969 * field is assigned, it is a fabric topology; otherwise, it is a
970 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
971 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
972 * specific topology completion conditions.
975 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
976 struct lpfc_iocbq *rspiocb)
978 struct lpfc_vport *vport = cmdiocb->vport;
979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
980 IOCB_t *irsp = &rspiocb->iocb;
981 struct lpfc_nodelist *ndlp = cmdiocb->context1;
982 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
983 struct serv_parm *sp;
987 /* Check to see if link went down during discovery */
988 if (lpfc_els_chk_latt(vport)) {
989 /* One additional decrement on node reference count to
990 * trigger the release of the node
996 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
997 "FLOGI cmpl: status:x%x/x%x state:x%x",
998 irsp->ulpStatus, irsp->un.ulpWord[4],
1001 if (irsp->ulpStatus) {
1003 * In case of FIP mode, perform roundrobin FCF failover
1004 * due to new FCF discovery
1006 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1007 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1008 if (phba->link_state < LPFC_LINK_UP)
1009 goto stop_rr_fcf_flogi;
1010 if ((phba->fcoe_cvl_eventtag_attn ==
1011 phba->fcoe_cvl_eventtag) &&
1012 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1013 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1015 goto stop_rr_fcf_flogi;
1017 phba->fcoe_cvl_eventtag_attn =
1018 phba->fcoe_cvl_eventtag;
1019 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1020 "2611 FLOGI failed on FCF (x%x), "
1021 "status:x%x/x%x, tmo:x%x, perform "
1022 "roundrobin FCF failover\n",
1023 phba->fcf.current_rec.fcf_indx,
1024 irsp->ulpStatus, irsp->un.ulpWord[4],
1026 lpfc_sli4_set_fcf_flogi_fail(phba,
1027 phba->fcf.current_rec.fcf_indx);
1028 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1029 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1036 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1037 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1038 IOERR_LOOP_OPEN_FAILURE)))
1039 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1040 "2858 FLOGI failure Status:x%x/x%x TMO"
1041 ":x%x Data x%x x%x\n",
1042 irsp->ulpStatus, irsp->un.ulpWord[4],
1043 irsp->ulpTimeout, phba->hba_flag,
1044 phba->fcf.fcf_flag);
1046 /* Check for retry */
1047 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1050 lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1051 "0150 FLOGI failure Status:x%x/x%x "
1052 "xri x%x TMO:x%x\n",
1053 irsp->ulpStatus, irsp->un.ulpWord[4],
1054 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1056 /* If this is not a loop open failure, bail out */
1057 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1058 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1059 IOERR_LOOP_OPEN_FAILURE)))
1062 /* FLOGI failed, so there is no fabric */
1063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1065 spin_unlock_irq(shost->host_lock);
1067 /* If private loop, then allow max outstanding els to be
1068 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1069 * alpa map would take too long otherwise.
1071 if (phba->alpa_map[0] == 0)
1072 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1073 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1074 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1075 (vport->fc_prevDID != vport->fc_myDID) ||
1076 phba->fc_topology_changed)) {
1077 if (vport->fc_flag & FC_VFI_REGISTERED) {
1078 if (phba->fc_topology_changed) {
1079 lpfc_unregister_fcf_prep(phba);
1080 spin_lock_irq(shost->host_lock);
1081 vport->fc_flag &= ~FC_VFI_REGISTERED;
1082 spin_unlock_irq(shost->host_lock);
1083 phba->fc_topology_changed = 0;
1085 lpfc_sli4_unreg_all_rpis(vport);
1089 /* Do not register VFI if the driver aborted FLOGI */
1090 if (!lpfc_error_lost_link(irsp))
1091 lpfc_issue_reg_vfi(vport);
1098 spin_lock_irq(shost->host_lock);
1099 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1100 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1101 spin_unlock_irq(shost->host_lock);
1104 * The FLogI succeeded. Sync the data for the CPU before
1107 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1110 sp = prsp->virt + sizeof(uint32_t);
1112 /* FLOGI completes successfully */
1113 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1114 "0101 FLOGI completes successfully, I/O tag:x%x, "
1115 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1116 cmdiocb->iotag, cmdiocb->sli4_xritag,
1117 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1118 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1119 vport->port_state, vport->fc_flag);
1121 if (vport->port_state == LPFC_FLOGI) {
1123 * If Common Service Parameters indicate Nport
1124 * we are point to point, if Fport we are Fabric.
1127 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1128 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1129 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1131 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1132 "2831 FLOGI response with cleared Fabric "
1133 "bit fcf_index 0x%x "
1134 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1136 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1137 phba->fcf.current_rec.fcf_indx,
1138 phba->fcf.current_rec.switch_name[0],
1139 phba->fcf.current_rec.switch_name[1],
1140 phba->fcf.current_rec.switch_name[2],
1141 phba->fcf.current_rec.switch_name[3],
1142 phba->fcf.current_rec.switch_name[4],
1143 phba->fcf.current_rec.switch_name[5],
1144 phba->fcf.current_rec.switch_name[6],
1145 phba->fcf.current_rec.switch_name[7],
1146 phba->fcf.current_rec.fabric_name[0],
1147 phba->fcf.current_rec.fabric_name[1],
1148 phba->fcf.current_rec.fabric_name[2],
1149 phba->fcf.current_rec.fabric_name[3],
1150 phba->fcf.current_rec.fabric_name[4],
1151 phba->fcf.current_rec.fabric_name[5],
1152 phba->fcf.current_rec.fabric_name[6],
1153 phba->fcf.current_rec.fabric_name[7]);
1156 spin_lock_irq(&phba->hbalock);
1157 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1158 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1159 spin_unlock_irq(&phba->hbalock);
1160 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1164 /* Mark the FCF discovery process done */
1165 if (phba->hba_flag & HBA_FIP_SUPPORT)
1166 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1168 "2769 FLOGI to FCF (x%x) "
1169 "completed successfully\n",
1170 phba->fcf.current_rec.fcf_indx);
1171 spin_lock_irq(&phba->hbalock);
1172 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1173 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1174 spin_unlock_irq(&phba->hbalock);
1175 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1181 spin_lock_irq(&phba->hbalock);
1182 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1183 spin_unlock_irq(&phba->hbalock);
1186 if (!lpfc_error_lost_link(irsp)) {
1187 /* FLOGI failed, so just use loop map to make discovery list */
1188 lpfc_disc_list_loopmap(vport);
1190 /* Start discovery */
1191 lpfc_disc_start(vport);
1192 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1193 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1194 IOERR_SLI_ABORTED) &&
1195 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1196 IOERR_SLI_DOWN))) &&
1197 (phba->link_state != LPFC_CLEAR_LA)) {
1198 /* If FLOGI failed enable link interrupt. */
1199 lpfc_issue_clear_la(phba, vport);
1202 lpfc_els_free_iocb(phba, cmdiocb);
1207 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1208 * aborted during a link down
1209 * @phba: pointer to lpfc hba data structure.
1210 * @cmdiocb: pointer to lpfc command iocb data structure.
1211 * @rspiocb: pointer to lpfc response iocb data structure.
1215 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1216 struct lpfc_iocbq *rspiocb)
1222 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1224 irsp = &rspiocb->iocb;
1226 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1227 "6445 ELS completes after LINK_DOWN: "
1228 " Status %x/%x cmd x%x flg x%x\n",
1229 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1230 cmdiocb->iocb_flag);
1232 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1233 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1234 atomic_dec(&phba->fabric_iocb_count);
1236 lpfc_els_free_iocb(phba, cmdiocb);
1240 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1241 * @vport: pointer to a host virtual N_Port data structure.
1242 * @ndlp: pointer to a node-list data structure.
1243 * @retry: number of retries to the command IOCB.
1245 * This routine issues a Fabric Login (FLOGI) Request ELS command
1246 * for a @vport. The initiator service parameters are put into the payload
1247 * of the FLOGI Request IOCB and the top-level callback function pointer
1248 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1249 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1250 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1252 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1253 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1254 * will be stored into the context1 field of the IOCB for the completion
1255 * callback function to the FLOGI ELS command.
1258 * 0 - successfully issued flogi iocb for @vport
1259 * 1 - failed to issue flogi iocb for @vport
1262 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1265 struct lpfc_hba *phba = vport->phba;
1266 struct serv_parm *sp;
1268 struct lpfc_iocbq *elsiocb;
1269 struct lpfc_iocbq defer_flogi_acc;
1275 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1276 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1277 ndlp->nlp_DID, ELS_CMD_FLOGI);
1282 icmd = &elsiocb->iocb;
1283 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1285 /* For FLOGI request, remainder of payload is service parameters */
1286 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1287 pcmd += sizeof(uint32_t);
1288 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1289 sp = (struct serv_parm *) pcmd;
1291 /* Setup CSPs accordingly for Fabric */
1292 sp->cmn.e_d_tov = 0;
1293 sp->cmn.w2.r_a_tov = 0;
1294 sp->cmn.virtual_fabric_support = 0;
1295 sp->cls1.classValid = 0;
1296 if (sp->cmn.fcphLow < FC_PH3)
1297 sp->cmn.fcphLow = FC_PH3;
1298 if (sp->cmn.fcphHigh < FC_PH3)
1299 sp->cmn.fcphHigh = FC_PH3;
1301 if (phba->sli_rev == LPFC_SLI_REV4) {
1302 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1303 LPFC_SLI_INTF_IF_TYPE_0) {
1304 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1305 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1306 /* FLOGI needs to be 3 for WQE FCFI */
1307 /* Set the fcfi to the fcfi we registered with */
1308 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1310 /* Can't do SLI4 class2 without support sequence coalescing */
1311 sp->cls2.classValid = 0;
1312 sp->cls2.seqDelivery = 0;
1314 /* Historical, setting sequential-delivery bit for SLI3 */
1315 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1316 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1317 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1318 sp->cmn.request_multiple_Nport = 1;
1319 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1323 sp->cmn.request_multiple_Nport = 0;
1326 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1327 icmd->un.elsreq64.myID = 0;
1328 icmd->un.elsreq64.fl = 1;
1331 tmo = phba->fc_ratov;
1332 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1333 lpfc_set_disctmo(vport);
1334 phba->fc_ratov = tmo;
1336 phba->fc_stat.elsXmitFLOGI++;
1337 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1339 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1340 "Issue FLOGI: opt:x%x",
1341 phba->sli3_options, 0, 0);
1343 elsiocb->context1 = lpfc_nlp_get(ndlp);
1344 if (!elsiocb->context1)
1347 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1348 if (rc == IOCB_ERROR)
1351 phba->hba_flag |= HBA_FLOGI_ISSUED;
1353 /* Check for a deferred FLOGI ACC condition */
1354 if (phba->defer_flogi_acc_flag) {
1355 did = vport->fc_myDID;
1356 vport->fc_myDID = Fabric_DID;
1358 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1360 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1361 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1362 phba->defer_flogi_acc_ox_id;
1364 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1365 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1366 " ox_id: x%x, hba_flag x%x\n",
1367 phba->defer_flogi_acc_rx_id,
1368 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1370 /* Send deferred FLOGI ACC */
1371 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1374 phba->defer_flogi_acc_flag = false;
1376 vport->fc_myDID = did;
1382 lpfc_els_free_iocb(phba, elsiocb);
1387 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1388 * @phba: pointer to lpfc hba data structure.
1390 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1391 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1392 * list and issues an abort IOCB commond on each outstanding IOCB that
1393 * contains a active Fabric_DID ndlp. Note that this function is to issue
1394 * the abort IOCB command on all the outstanding IOCBs, thus when this
1395 * function returns, it does not guarantee all the IOCBs are actually aborted.
1398 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1401 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1403 struct lpfc_sli_ring *pring;
1404 struct lpfc_iocbq *iocb, *next_iocb;
1405 struct lpfc_nodelist *ndlp;
1408 /* Abort outstanding I/O on NPort <nlp_DID> */
1409 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1410 "0201 Abort outstanding I/O on NPort x%x\n",
1413 pring = lpfc_phba_elsring(phba);
1414 if (unlikely(!pring))
1418 * Check the txcmplq for an iocb that matches the nport the driver is
1421 spin_lock_irq(&phba->hbalock);
1422 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1424 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1425 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1426 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
1427 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1430 spin_unlock_irq(&phba->hbalock);
1436 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1437 * @vport: pointer to a host virtual N_Port data structure.
1439 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1440 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1441 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1442 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1443 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1444 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1448 * 0 - failed to issue initial flogi for @vport
1449 * 1 - successfully issued initial flogi for @vport
1452 lpfc_initial_flogi(struct lpfc_vport *vport)
1454 struct lpfc_nodelist *ndlp;
1456 vport->port_state = LPFC_FLOGI;
1457 lpfc_set_disctmo(vport);
1459 /* First look for the Fabric ndlp */
1460 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1462 /* Cannot find existing Fabric ndlp, so allocate a new one */
1463 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1466 /* Set the node type */
1467 ndlp->nlp_type |= NLP_FABRIC;
1469 /* Put ndlp onto node list */
1470 lpfc_enqueue_node(vport, ndlp);
1473 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1474 /* This decrement of reference count to node shall kick off
1475 * the release of the node.
1484 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1485 * @vport: pointer to a host virtual N_Port data structure.
1487 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1488 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1489 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1490 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1491 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1492 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1496 * 0 - failed to issue initial fdisc for @vport
1497 * 1 - successfully issued initial fdisc for @vport
1500 lpfc_initial_fdisc(struct lpfc_vport *vport)
1502 struct lpfc_nodelist *ndlp;
1504 /* First look for the Fabric ndlp */
1505 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1507 /* Cannot find existing Fabric ndlp, so allocate a new one */
1508 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1511 /* Put ndlp onto node list */
1512 lpfc_enqueue_node(vport, ndlp);
1515 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1516 /* decrement node reference count to trigger the release of
1526 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1527 * @vport: pointer to a host virtual N_Port data structure.
1529 * This routine checks whether there are more remaining Port Logins
1530 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1531 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1532 * to issue ELS PLOGIs up to the configured discover threads with the
1533 * @vport (@vport->cfg_discovery_threads). The function also decrement
1534 * the @vport's num_disc_node by 1 if it is not already 0.
1537 lpfc_more_plogi(struct lpfc_vport *vport)
1539 if (vport->num_disc_nodes)
1540 vport->num_disc_nodes--;
1542 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1543 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1544 "0232 Continue discovery with %d PLOGIs to go "
1545 "Data: x%x x%x x%x\n",
1546 vport->num_disc_nodes, vport->fc_plogi_cnt,
1547 vport->fc_flag, vport->port_state);
1548 /* Check to see if there are more PLOGIs to be sent */
1549 if (vport->fc_flag & FC_NLP_MORE)
1550 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1551 lpfc_els_disc_plogi(vport);
1557 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1558 * @phba: pointer to lpfc hba data structure.
1559 * @prsp: pointer to response IOCB payload.
1560 * @ndlp: pointer to a node-list data structure.
1562 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1563 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1564 * The following cases are considered N_Port confirmed:
1565 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1566 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1567 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1568 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1569 * 1) if there is a node on vport list other than the @ndlp with the same
1570 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1571 * on that node to release the RPI associated with the node; 2) if there is
1572 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1573 * into, a new node shall be allocated (or activated). In either case, the
1574 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1575 * be released and the new_ndlp shall be put on to the vport node list and
1576 * its pointer returned as the confirmed node.
1578 * Note that before the @ndlp got "released", the keepDID from not-matching
1579 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1580 * of the @ndlp. This is because the release of @ndlp is actually to put it
1581 * into an inactive state on the vport node list and the vport node list
1582 * management algorithm does not allow two node with a same DID.
1585 * pointer to the PLOGI N_Port @ndlp
1587 static struct lpfc_nodelist *
1588 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1589 struct lpfc_nodelist *ndlp)
1591 struct lpfc_vport *vport = ndlp->vport;
1592 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1593 struct lpfc_nodelist *new_ndlp;
1594 struct serv_parm *sp;
1595 uint8_t name[sizeof(struct lpfc_name)];
1596 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1597 uint32_t keep_new_nlp_flag = 0;
1598 uint16_t keep_nlp_state;
1599 u32 keep_nlp_fc4_type = 0;
1600 struct lpfc_nvme_rport *keep_nrport = NULL;
1601 unsigned long *active_rrqs_xri_bitmap = NULL;
1603 /* Fabric nodes can have the same WWPN so we don't bother searching
1604 * by WWPN. Just return the ndlp that was given to us.
1606 if (ndlp->nlp_type & NLP_FABRIC)
1609 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1610 memset(name, 0, sizeof(struct lpfc_name));
1612 /* Now we find out if the NPort we are logging into, matches the WWPN
1613 * we have for that ndlp. If not, we have some work to do.
1615 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1617 /* return immediately if the WWPN matches ndlp */
1618 if (new_ndlp == ndlp)
1621 if (phba->sli_rev == LPFC_SLI_REV4) {
1622 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1624 if (active_rrqs_xri_bitmap)
1625 memset(active_rrqs_xri_bitmap, 0,
1626 phba->cfg_rrq_xri_bitmap_sz);
1629 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1630 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1631 "new_ndlp x%x x%x x%x\n",
1632 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1633 (new_ndlp ? new_ndlp->nlp_DID : 0),
1634 (new_ndlp ? new_ndlp->nlp_flag : 0),
1635 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1638 rc = memcmp(&ndlp->nlp_portname, name,
1639 sizeof(struct lpfc_name));
1641 if (active_rrqs_xri_bitmap)
1642 mempool_free(active_rrqs_xri_bitmap,
1643 phba->active_rrq_pool);
1646 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1648 if (active_rrqs_xri_bitmap)
1649 mempool_free(active_rrqs_xri_bitmap,
1650 phba->active_rrq_pool);
1654 keepDID = new_ndlp->nlp_DID;
1655 if (phba->sli_rev == LPFC_SLI_REV4 &&
1656 active_rrqs_xri_bitmap)
1657 memcpy(active_rrqs_xri_bitmap,
1658 new_ndlp->active_rrqs_xri_bitmap,
1659 phba->cfg_rrq_xri_bitmap_sz);
1662 /* At this point in this routine, we know new_ndlp will be
1663 * returned. however, any previous GID_FTs that were done
1664 * would have updated nlp_fc4_type in ndlp, so we must ensure
1665 * new_ndlp has the right value.
1667 if (vport->fc_flag & FC_FABRIC) {
1668 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1669 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1672 lpfc_unreg_rpi(vport, new_ndlp);
1673 new_ndlp->nlp_DID = ndlp->nlp_DID;
1674 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1675 if (phba->sli_rev == LPFC_SLI_REV4)
1676 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1677 ndlp->active_rrqs_xri_bitmap,
1678 phba->cfg_rrq_xri_bitmap_sz);
1680 spin_lock_irq(shost->host_lock);
1681 keep_new_nlp_flag = new_ndlp->nlp_flag;
1682 keep_nlp_flag = ndlp->nlp_flag;
1683 new_ndlp->nlp_flag = ndlp->nlp_flag;
1685 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1686 if (keep_new_nlp_flag & NLP_UNREG_INP)
1687 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1689 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1691 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1692 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1693 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1695 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1697 ndlp->nlp_flag = keep_new_nlp_flag;
1699 /* if ndlp had NLP_UNREG_INP set, keep it */
1700 if (keep_nlp_flag & NLP_UNREG_INP)
1701 ndlp->nlp_flag |= NLP_UNREG_INP;
1703 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1705 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1706 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1707 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1709 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1711 spin_unlock_irq(shost->host_lock);
1713 /* Set nlp_states accordingly */
1714 keep_nlp_state = new_ndlp->nlp_state;
1715 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1717 /* interchange the nvme remoteport structs */
1718 keep_nrport = new_ndlp->nrport;
1719 new_ndlp->nrport = ndlp->nrport;
1721 /* Move this back to NPR state */
1722 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1723 /* The new_ndlp is replacing ndlp totally, so we need
1724 * to put ndlp on UNUSED list and try to free it.
1726 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1727 "3179 PLOGI confirm NEW: %x %x\n",
1728 new_ndlp->nlp_DID, keepDID);
1730 /* Two ndlps cannot have the same did on the nodelist.
1731 * Note: for this case, ndlp has a NULL WWPN so setting
1732 * the nlp_fc4_type isn't required.
1734 ndlp->nlp_DID = keepDID;
1735 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1736 if (phba->sli_rev == LPFC_SLI_REV4 &&
1737 active_rrqs_xri_bitmap)
1738 memcpy(ndlp->active_rrqs_xri_bitmap,
1739 active_rrqs_xri_bitmap,
1740 phba->cfg_rrq_xri_bitmap_sz);
1743 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1744 "3180 PLOGI confirm SWAP: %x %x\n",
1745 new_ndlp->nlp_DID, keepDID);
1747 lpfc_unreg_rpi(vport, ndlp);
1749 /* Two ndlps cannot have the same did and the fc4
1750 * type must be transferred because the ndlp is in
1753 ndlp->nlp_DID = keepDID;
1754 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1756 if (phba->sli_rev == LPFC_SLI_REV4 &&
1757 active_rrqs_xri_bitmap)
1758 memcpy(ndlp->active_rrqs_xri_bitmap,
1759 active_rrqs_xri_bitmap,
1760 phba->cfg_rrq_xri_bitmap_sz);
1762 /* Since we are switching over to the new_ndlp,
1763 * reset the old ndlp state
1765 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1766 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1767 keep_nlp_state = NLP_STE_NPR_NODE;
1768 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1769 ndlp->nrport = keep_nrport;
1773 * If ndlp is not associated with any rport we can drop it here else
1774 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1776 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1777 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1779 if (phba->sli_rev == LPFC_SLI_REV4 &&
1780 active_rrqs_xri_bitmap)
1781 mempool_free(active_rrqs_xri_bitmap,
1782 phba->active_rrq_pool);
1784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1785 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1786 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1787 new_ndlp->nlp_fc4_type);
1793 * lpfc_end_rscn - Check and handle more rscn for a vport
1794 * @vport: pointer to a host virtual N_Port data structure.
1796 * This routine checks whether more Registration State Change
1797 * Notifications (RSCNs) came in while the discovery state machine was in
1798 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1799 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1800 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1801 * handling the RSCNs.
1804 lpfc_end_rscn(struct lpfc_vport *vport)
1806 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1808 if (vport->fc_flag & FC_RSCN_MODE) {
1810 * Check to see if more RSCNs came in while we were
1811 * processing this one.
1813 if (vport->fc_rscn_id_cnt ||
1814 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1815 lpfc_els_handle_rscn(vport);
1817 spin_lock_irq(shost->host_lock);
1818 vport->fc_flag &= ~FC_RSCN_MODE;
1819 spin_unlock_irq(shost->host_lock);
1825 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1826 * @phba: pointer to lpfc hba data structure.
1827 * @cmdiocb: pointer to lpfc command iocb data structure.
1828 * @rspiocb: pointer to lpfc response iocb data structure.
1830 * This routine will call the clear rrq function to free the rrq and
1831 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1832 * exist then the clear_rrq is still called because the rrq needs to
1837 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1838 struct lpfc_iocbq *rspiocb)
1840 struct lpfc_vport *vport = cmdiocb->vport;
1842 struct lpfc_nodelist *ndlp;
1843 struct lpfc_node_rrq *rrq;
1845 /* we pass cmdiocb to state machine which needs rspiocb as well */
1846 rrq = cmdiocb->context_un.rrq;
1847 cmdiocb->context_un.rsp_iocb = rspiocb;
1849 irsp = &rspiocb->iocb;
1850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1851 "RRQ cmpl: status:x%x/x%x did:x%x",
1852 irsp->ulpStatus, irsp->un.ulpWord[4],
1853 irsp->un.elsreq64.remoteID);
1855 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1856 if (!ndlp || ndlp != rrq->ndlp) {
1857 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1858 "2882 RRQ completes to NPort x%x "
1859 "with no ndlp. Data: x%x x%x x%x\n",
1860 irsp->un.elsreq64.remoteID,
1861 irsp->ulpStatus, irsp->un.ulpWord[4],
1866 /* rrq completes to NPort <nlp_DID> */
1867 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1868 "2880 RRQ completes to NPort x%x "
1869 "Data: x%x x%x x%x x%x x%x\n",
1870 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1871 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1873 if (irsp->ulpStatus) {
1874 /* Check for retry */
1875 /* RRQ failed Don't print the vport to vport rjts */
1876 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1877 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1878 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1879 (phba)->pport->cfg_log_verbose & LOG_ELS)
1880 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1881 "2881 RRQ failure DID:%06X Status:"
1883 ndlp->nlp_DID, irsp->ulpStatus,
1884 irsp->un.ulpWord[4]);
1888 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1890 lpfc_els_free_iocb(phba, cmdiocb);
1895 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1896 * @phba: pointer to lpfc hba data structure.
1897 * @cmdiocb: pointer to lpfc command iocb data structure.
1898 * @rspiocb: pointer to lpfc response iocb data structure.
1900 * This routine is the completion callback function for issuing the Port
1901 * Login (PLOGI) command. For PLOGI completion, there must be an active
1902 * ndlp on the vport node list that matches the remote node ID from the
1903 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1904 * ignored and command IOCB released. The PLOGI response IOCB status is
1905 * checked for error conditons. If there is error status reported, PLOGI
1906 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1907 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1908 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1909 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1910 * there are additional N_Port nodes with the vport that need to perform
1911 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1915 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1916 struct lpfc_iocbq *rspiocb)
1918 struct lpfc_vport *vport = cmdiocb->vport;
1919 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1921 struct lpfc_nodelist *ndlp, *free_ndlp;
1922 struct lpfc_dmabuf *prsp;
1925 /* we pass cmdiocb to state machine which needs rspiocb as well */
1926 cmdiocb->context_un.rsp_iocb = rspiocb;
1928 irsp = &rspiocb->iocb;
1929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1930 "PLOGI cmpl: status:x%x/x%x did:x%x",
1931 irsp->ulpStatus, irsp->un.ulpWord[4],
1932 irsp->un.elsreq64.remoteID);
1934 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1936 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1937 "0136 PLOGI completes to NPort x%x "
1938 "with no ndlp. Data: x%x x%x x%x\n",
1939 irsp->un.elsreq64.remoteID,
1940 irsp->ulpStatus, irsp->un.ulpWord[4],
1945 /* Since ndlp can be freed in the disc state machine, note if this node
1946 * is being used during discovery.
1948 spin_lock_irq(shost->host_lock);
1949 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1950 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1951 spin_unlock_irq(shost->host_lock);
1953 /* PLOGI completes to NPort <nlp_DID> */
1954 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1955 "0102 PLOGI completes to NPort x%06x "
1956 "Data: x%x x%x x%x x%x x%x\n",
1957 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1958 irsp->ulpStatus, irsp->un.ulpWord[4],
1959 disc, vport->num_disc_nodes);
1961 /* Check to see if link went down during discovery */
1962 if (lpfc_els_chk_latt(vport)) {
1963 spin_lock_irq(shost->host_lock);
1964 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1965 spin_unlock_irq(shost->host_lock);
1969 if (irsp->ulpStatus) {
1970 /* Check for retry */
1971 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1972 /* ELS command is being retried */
1974 spin_lock_irq(shost->host_lock);
1975 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1976 spin_unlock_irq(shost->host_lock);
1980 /* PLOGI failed Don't print the vport to vport rjts */
1981 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1982 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1983 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1984 (phba)->pport->cfg_log_verbose & LOG_ELS)
1985 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1986 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1987 ndlp->nlp_DID, irsp->ulpStatus,
1988 irsp->un.ulpWord[4]);
1989 /* Do not call DSM for lpfc_els_abort'ed ELS cmds. Just execute
1990 * the final node put to free it to the pool.
1992 if (!lpfc_error_lost_link(irsp))
1993 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1996 /* Good status, call state machine */
1997 prsp = list_entry(((struct lpfc_dmabuf *)
1998 cmdiocb->context2)->list.next,
1999 struct lpfc_dmabuf, list);
2000 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2001 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2002 NLP_EVT_CMPL_PLOGI);
2005 if (disc && vport->num_disc_nodes) {
2006 /* Check to see if there are more PLOGIs to be sent */
2007 lpfc_more_plogi(vport);
2009 if (vport->num_disc_nodes == 0) {
2010 spin_lock_irq(shost->host_lock);
2011 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2012 spin_unlock_irq(shost->host_lock);
2014 lpfc_can_disctmo(vport);
2015 lpfc_end_rscn(vport);
2020 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2021 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2022 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2024 /* Release the reference on the original I/O request. */
2025 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
2027 lpfc_els_free_iocb(phba, cmdiocb);
2028 lpfc_nlp_put(free_ndlp);
2033 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2034 * @vport: pointer to a host virtual N_Port data structure.
2035 * @did: destination port identifier.
2036 * @retry: number of retries to the command IOCB.
2038 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2039 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2040 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2041 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2042 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2044 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2045 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2046 * will be stored into the context1 field of the IOCB for the completion
2047 * callback function to the PLOGI ELS command.
2050 * 0 - Successfully issued a plogi for @vport
2051 * 1 - failed to issue a plogi for @vport
2054 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2056 struct lpfc_hba *phba = vport->phba;
2057 struct Scsi_Host *shost;
2058 struct serv_parm *sp;
2059 struct lpfc_nodelist *ndlp;
2060 struct lpfc_iocbq *elsiocb;
2065 ndlp = lpfc_findnode_did(vport, did);
2068 /* Defer the processing of the issue PLOGI until after the
2069 * outstanding UNREG_RPI mbox command completes, unless we
2070 * are going offline. This logic does not apply for Fabric DIDs
2072 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2073 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2074 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2075 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2076 "4110 Issue PLOGI x%x deferred "
2077 "on NPort x%x rpi x%x Data: x%px\n",
2078 ndlp->nlp_defer_did, ndlp->nlp_DID,
2079 ndlp->nlp_rpi, ndlp);
2081 /* We can only defer 1st PLOGI */
2082 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2083 ndlp->nlp_defer_did = did;
2088 /* If ndlp is not NULL, we will bump the reference count on it */
2089 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2090 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2095 shost = lpfc_shost_from_vport(vport);
2096 spin_lock_irq(shost->host_lock);
2097 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2098 spin_unlock_irq(shost->host_lock);
2100 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2102 /* For PLOGI request, remainder of payload is service parameters */
2103 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2104 pcmd += sizeof(uint32_t);
2105 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2106 sp = (struct serv_parm *) pcmd;
2109 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2110 * to device on remote loops work.
2112 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2113 sp->cmn.altBbCredit = 1;
2115 if (sp->cmn.fcphLow < FC_PH_4_3)
2116 sp->cmn.fcphLow = FC_PH_4_3;
2118 if (sp->cmn.fcphHigh < FC_PH3)
2119 sp->cmn.fcphHigh = FC_PH3;
2121 sp->cmn.valid_vendor_ver_level = 0;
2122 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2123 sp->cmn.bbRcvSizeMsb &= 0xF;
2125 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2126 "Issue PLOGI: did:x%x",
2129 /* If our firmware supports this feature, convey that
2130 * information to the target using the vendor specific field.
2132 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2133 sp->cmn.valid_vendor_ver_level = 1;
2134 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2135 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2138 phba->fc_stat.elsXmitPLOGI++;
2139 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2141 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2142 "Issue PLOGI: did:x%x refcnt %d",
2143 did, kref_read(&ndlp->kref), 0);
2144 elsiocb->context1 = lpfc_nlp_get(ndlp);
2145 if (!elsiocb->context1)
2148 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2156 lpfc_els_free_iocb(phba, elsiocb);
2161 * lpfc_cmpl_els_prli - Completion callback function for prli
2162 * @phba: pointer to lpfc hba data structure.
2163 * @cmdiocb: pointer to lpfc command iocb data structure.
2164 * @rspiocb: pointer to lpfc response iocb data structure.
2166 * This routine is the completion callback function for a Process Login
2167 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2168 * status. If there is error status reported, PRLI retry shall be attempted
2169 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2170 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2171 * ndlp to mark the PRLI completion.
2174 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2175 struct lpfc_iocbq *rspiocb)
2177 struct lpfc_vport *vport = cmdiocb->vport;
2178 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2180 struct lpfc_nodelist *ndlp;
2184 /* we pass cmdiocb to state machine which needs rspiocb as well */
2185 cmdiocb->context_un.rsp_iocb = rspiocb;
2187 irsp = &(rspiocb->iocb);
2188 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2189 spin_lock_irq(shost->host_lock);
2190 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2192 /* Driver supports multiple FC4 types. Counters matter. */
2193 vport->fc_prli_sent--;
2194 ndlp->fc4_prli_sent--;
2195 spin_unlock_irq(shost->host_lock);
2197 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2198 "PRLI cmpl: status:x%x/x%x did:x%x",
2199 irsp->ulpStatus, irsp->un.ulpWord[4],
2202 /* PRLI completes to NPort <nlp_DID> */
2203 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2204 "0103 PRLI completes to NPort x%06x "
2205 "Data: x%x x%x x%x x%x\n",
2206 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2207 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2209 /* Check to see if link went down during discovery */
2210 if (lpfc_els_chk_latt(vport))
2213 if (irsp->ulpStatus) {
2214 /* Check for retry */
2215 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2216 /* ELS command is being retried */
2220 /* If we don't send GFT_ID to Fabric, a PRLI error
2221 * could be expected.
2223 if ((vport->fc_flag & FC_FABRIC) ||
2224 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2226 loglevel = LOG_TRACE_EVENT;
2233 lpfc_printf_vlog(vport, mode, loglevel,
2234 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2236 ndlp->nlp_DID, irsp->ulpStatus,
2237 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2239 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2240 if (lpfc_error_lost_link(irsp))
2243 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2246 /* Good status, call state machine. However, if another
2247 * PRLI is outstanding, don't call the state machine
2248 * because final disposition to Mapped or Unmapped is
2251 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2256 lpfc_els_free_iocb(phba, cmdiocb);
2262 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2263 * @vport: pointer to a host virtual N_Port data structure.
2264 * @ndlp: pointer to a node-list data structure.
2265 * @retry: number of retries to the command IOCB.
2267 * This routine issues a Process Login (PRLI) ELS command for the
2268 * @vport. The PRLI service parameters are set up in the payload of the
2269 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2270 * is put to the IOCB completion callback func field before invoking the
2271 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2273 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2274 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2275 * will be stored into the context1 field of the IOCB for the completion
2276 * callback function to the PRLI ELS command.
2279 * 0 - successfully issued prli iocb command for @vport
2280 * 1 - failed to issue prli iocb command for @vport
2283 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2287 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2288 struct lpfc_hba *phba = vport->phba;
2290 struct lpfc_nvme_prli *npr_nvme;
2291 struct lpfc_iocbq *elsiocb;
2294 u32 local_nlp_type, elscmd;
2297 * If we are in RSCN mode, the FC4 types supported from a
2298 * previous GFT_ID command may not be accurate. So, if we
2299 * are a NVME Initiator, always look for the possibility of
2300 * the remote NPort beng a NVME Target.
2302 if (phba->sli_rev == LPFC_SLI_REV4 &&
2303 vport->fc_flag & FC_RSCN_MODE &&
2304 vport->nvmei_support)
2305 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2306 local_nlp_type = ndlp->nlp_fc4_type;
2308 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2309 * fields here before any of them can complete.
2311 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2312 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2313 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2314 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2315 ndlp->nvme_fb_size = 0;
2318 if (local_nlp_type & NLP_FC4_FCP) {
2319 /* Payload is 4 + 16 = 20 x14 bytes. */
2320 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2321 elscmd = ELS_CMD_PRLI;
2322 } else if (local_nlp_type & NLP_FC4_NVME) {
2323 /* Payload is 4 + 20 = 24 x18 bytes. */
2324 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2325 elscmd = ELS_CMD_NVMEPRLI;
2327 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2328 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2329 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2333 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2334 * FC4 type, implicitly LOGO.
2336 if (phba->sli_rev == LPFC_SLI_REV3 &&
2337 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2338 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2339 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2341 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2345 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2346 ndlp->nlp_DID, elscmd);
2350 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2352 /* For PRLI request, remainder of payload is service parameters */
2353 memset(pcmd, 0, cmdsize);
2355 if (local_nlp_type & NLP_FC4_FCP) {
2356 /* Remainder of payload is FCP PRLI parameter page.
2357 * Note: this data structure is defined as
2358 * BE/LE in the structure definition so no
2359 * byte swap call is made.
2361 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2362 pcmd += sizeof(uint32_t);
2366 * If our firmware version is 3.20 or later,
2367 * set the following bits for FC-TAPE support.
2369 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2370 npr->ConfmComplAllowed = 1;
2372 npr->TaskRetryIdReq = 1;
2374 npr->estabImagePair = 1;
2375 npr->readXferRdyDis = 1;
2376 if (vport->cfg_first_burst_size)
2377 npr->writeXferRdyDis = 1;
2379 /* For FCP support */
2380 npr->prliType = PRLI_FCP_TYPE;
2381 npr->initiatorFunc = 1;
2382 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2384 /* Remove FCP type - processed. */
2385 local_nlp_type &= ~NLP_FC4_FCP;
2386 } else if (local_nlp_type & NLP_FC4_NVME) {
2387 /* Remainder of payload is NVME PRLI parameter page.
2388 * This data structure is the newer definition that
2389 * uses bf macros so a byte swap is required.
2391 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2392 pcmd += sizeof(uint32_t);
2393 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2394 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2395 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2397 bf_set(prli_nsler, npr_nvme, 1);
2398 bf_set(prli_conf, npr_nvme, 1);
2401 /* Only initiators request first burst. */
2402 if ((phba->cfg_nvme_enable_fb) &&
2403 !phba->nvmet_support)
2404 bf_set(prli_fba, npr_nvme, 1);
2406 if (phba->nvmet_support) {
2407 bf_set(prli_tgt, npr_nvme, 1);
2408 bf_set(prli_disc, npr_nvme, 1);
2410 bf_set(prli_init, npr_nvme, 1);
2411 bf_set(prli_conf, npr_nvme, 1);
2414 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2415 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2416 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2418 /* Remove NVME type - processed. */
2419 local_nlp_type &= ~NLP_FC4_NVME;
2422 phba->fc_stat.elsXmitPRLI++;
2423 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2424 spin_lock_irq(shost->host_lock);
2425 ndlp->nlp_flag |= NLP_PRLI_SND;
2427 /* The vport counters are used for lpfc_scan_finished, but
2428 * the ndlp is used to track outstanding PRLIs for different
2431 vport->fc_prli_sent++;
2432 ndlp->fc4_prli_sent++;
2433 spin_unlock_irq(shost->host_lock);
2435 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2436 "Issue PRLI: did:x%x refcnt %d",
2437 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2438 elsiocb->context1 = lpfc_nlp_get(ndlp);
2439 if (!elsiocb->context1)
2442 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2443 if (rc == IOCB_ERROR)
2447 /* The driver supports 2 FC4 types. Make sure
2448 * a PRLI is issued for all types before exiting.
2450 if (phba->sli_rev == LPFC_SLI_REV4 &&
2451 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2452 goto send_next_prli;
2459 spin_lock_irq(shost->host_lock);
2460 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2461 spin_unlock_irq(shost->host_lock);
2462 lpfc_els_free_iocb(phba, elsiocb);
2467 * lpfc_rscn_disc - Perform rscn discovery for a vport
2468 * @vport: pointer to a host virtual N_Port data structure.
2470 * This routine performs Registration State Change Notification (RSCN)
2471 * discovery for a @vport. If the @vport's node port recovery count is not
2472 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2473 * the nodes that need recovery. If none of the PLOGI were needed through
2474 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2475 * invoked to check and handle possible more RSCN came in during the period
2476 * of processing the current ones.
2479 lpfc_rscn_disc(struct lpfc_vport *vport)
2481 lpfc_can_disctmo(vport);
2483 /* RSCN discovery */
2484 /* go thru NPR nodes and issue ELS PLOGIs */
2485 if (vport->fc_npr_cnt)
2486 if (lpfc_els_disc_plogi(vport))
2489 lpfc_end_rscn(vport);
2493 * lpfc_adisc_done - Complete the adisc phase of discovery
2494 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2496 * This function is called when the final ADISC is completed during discovery.
2497 * This function handles clearing link attention or issuing reg_vpi depending
2498 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2500 * This function is called with no locks held.
2503 lpfc_adisc_done(struct lpfc_vport *vport)
2505 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2506 struct lpfc_hba *phba = vport->phba;
2509 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2510 * and continue discovery.
2512 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2513 !(vport->fc_flag & FC_RSCN_MODE) &&
2514 (phba->sli_rev < LPFC_SLI_REV4)) {
2515 /* The ADISCs are complete. Doesn't matter if they
2516 * succeeded or failed because the ADISC completion
2517 * routine guarantees to call the state machine and
2518 * the RPI is either unregistered (failed ADISC response)
2519 * or the RPI is still valid and the node is marked
2520 * mapped for a target. The exchanges should be in the
2521 * correct state. This code is specific to SLI3.
2523 lpfc_issue_clear_la(phba, vport);
2524 lpfc_issue_reg_vpi(phba, vport);
2528 * For SLI2, we need to set port_state to READY
2529 * and continue discovery.
2531 if (vport->port_state < LPFC_VPORT_READY) {
2532 /* If we get here, there is nothing to ADISC */
2533 lpfc_issue_clear_la(phba, vport);
2534 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2535 vport->num_disc_nodes = 0;
2536 /* go thru NPR list, issue ELS PLOGIs */
2537 if (vport->fc_npr_cnt)
2538 lpfc_els_disc_plogi(vport);
2539 if (!vport->num_disc_nodes) {
2540 spin_lock_irq(shost->host_lock);
2541 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2542 spin_unlock_irq(shost->host_lock);
2543 lpfc_can_disctmo(vport);
2544 lpfc_end_rscn(vport);
2547 vport->port_state = LPFC_VPORT_READY;
2549 lpfc_rscn_disc(vport);
2553 * lpfc_more_adisc - Issue more adisc as needed
2554 * @vport: pointer to a host virtual N_Port data structure.
2556 * This routine determines whether there are more ndlps on a @vport
2557 * node list need to have Address Discover (ADISC) issued. If so, it will
2558 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2559 * remaining nodes which need to have ADISC sent.
2562 lpfc_more_adisc(struct lpfc_vport *vport)
2564 if (vport->num_disc_nodes)
2565 vport->num_disc_nodes--;
2566 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2567 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2568 "0210 Continue discovery with %d ADISCs to go "
2569 "Data: x%x x%x x%x\n",
2570 vport->num_disc_nodes, vport->fc_adisc_cnt,
2571 vport->fc_flag, vport->port_state);
2572 /* Check to see if there are more ADISCs to be sent */
2573 if (vport->fc_flag & FC_NLP_MORE) {
2574 lpfc_set_disctmo(vport);
2575 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2576 lpfc_els_disc_adisc(vport);
2578 if (!vport->num_disc_nodes)
2579 lpfc_adisc_done(vport);
2584 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2585 * @phba: pointer to lpfc hba data structure.
2586 * @cmdiocb: pointer to lpfc command iocb data structure.
2587 * @rspiocb: pointer to lpfc response iocb data structure.
2589 * This routine is the completion function for issuing the Address Discover
2590 * (ADISC) command. It first checks to see whether link went down during
2591 * the discovery process. If so, the node will be marked as node port
2592 * recovery for issuing discover IOCB by the link attention handler and
2593 * exit. Otherwise, the response status is checked. If error was reported
2594 * in the response status, the ADISC command shall be retried by invoking
2595 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2596 * the response status, the state machine is invoked to set transition
2597 * with respect to NLP_EVT_CMPL_ADISC event.
2600 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2601 struct lpfc_iocbq *rspiocb)
2603 struct lpfc_vport *vport = cmdiocb->vport;
2604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2606 struct lpfc_nodelist *ndlp;
2609 /* we pass cmdiocb to state machine which needs rspiocb as well */
2610 cmdiocb->context_un.rsp_iocb = rspiocb;
2612 irsp = &(rspiocb->iocb);
2613 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2616 "ADISC cmpl: status:x%x/x%x did:x%x",
2617 irsp->ulpStatus, irsp->un.ulpWord[4],
2620 /* Since ndlp can be freed in the disc state machine, note if this node
2621 * is being used during discovery.
2623 spin_lock_irq(shost->host_lock);
2624 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2625 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2626 spin_unlock_irq(shost->host_lock);
2627 /* ADISC completes to NPort <nlp_DID> */
2628 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2629 "0104 ADISC completes to NPort x%x "
2630 "Data: x%x x%x x%x x%x x%x\n",
2631 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2632 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2633 /* Check to see if link went down during discovery */
2634 if (lpfc_els_chk_latt(vport)) {
2635 spin_lock_irq(shost->host_lock);
2636 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2637 spin_unlock_irq(shost->host_lock);
2641 if (irsp->ulpStatus) {
2642 /* Check for retry */
2643 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2644 /* ELS command is being retried */
2646 spin_lock_irq(shost->host_lock);
2647 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2648 spin_unlock_irq(shost->host_lock);
2649 lpfc_set_disctmo(vport);
2654 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2655 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2656 ndlp->nlp_DID, irsp->ulpStatus,
2657 irsp->un.ulpWord[4]);
2658 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2659 if (!lpfc_error_lost_link(irsp))
2660 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2661 NLP_EVT_CMPL_ADISC);
2663 /* Good status, call state machine */
2664 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2665 NLP_EVT_CMPL_ADISC);
2667 /* Check to see if there are more ADISCs to be sent */
2668 if (disc && vport->num_disc_nodes)
2669 lpfc_more_adisc(vport);
2671 lpfc_els_free_iocb(phba, cmdiocb);
2677 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2678 * @vport: pointer to a virtual N_Port data structure.
2679 * @ndlp: pointer to a node-list data structure.
2680 * @retry: number of retries to the command IOCB.
2682 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2683 * @vport. It prepares the payload of the ADISC ELS command, updates the
2684 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2685 * to issue the ADISC ELS command.
2687 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2688 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2689 * will be stored into the context1 field of the IOCB for the completion
2690 * callback function to the ADISC ELS command.
2693 * 0 - successfully issued adisc
2694 * 1 - failed to issue adisc
2697 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2701 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2702 struct lpfc_hba *phba = vport->phba;
2704 struct lpfc_iocbq *elsiocb;
2708 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2709 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2710 ndlp->nlp_DID, ELS_CMD_ADISC);
2714 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2716 /* For ADISC request, remainder of payload is service parameters */
2717 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2718 pcmd += sizeof(uint32_t);
2720 /* Fill in ADISC payload */
2721 ap = (ADISC *) pcmd;
2722 ap->hardAL_PA = phba->fc_pref_ALPA;
2723 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2724 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2725 ap->DID = be32_to_cpu(vport->fc_myDID);
2727 phba->fc_stat.elsXmitADISC++;
2728 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2729 spin_lock_irq(shost->host_lock);
2730 ndlp->nlp_flag |= NLP_ADISC_SND;
2731 spin_unlock_irq(shost->host_lock);
2732 elsiocb->context1 = lpfc_nlp_get(ndlp);
2733 if (!elsiocb->context1)
2736 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2737 "Issue ADISC: did:x%x refcnt %d",
2738 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2739 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2740 if (rc == IOCB_ERROR)
2747 spin_lock_irq(shost->host_lock);
2748 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2749 spin_unlock_irq(shost->host_lock);
2750 lpfc_els_free_iocb(phba, elsiocb);
2755 * lpfc_cmpl_els_logo - Completion callback function for logo
2756 * @phba: pointer to lpfc hba data structure.
2757 * @cmdiocb: pointer to lpfc command iocb data structure.
2758 * @rspiocb: pointer to lpfc response iocb data structure.
2760 * This routine is the completion function for issuing the ELS Logout (LOGO)
2761 * command. If no error status was reported from the LOGO response, the
2762 * state machine of the associated ndlp shall be invoked for transition with
2763 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2764 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2767 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2768 struct lpfc_iocbq *rspiocb)
2770 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2771 struct lpfc_vport *vport = ndlp->vport;
2772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2774 struct lpfcMboxq *mbox;
2775 unsigned long flags;
2776 uint32_t skip_recovery = 0;
2778 /* we pass cmdiocb to state machine which needs rspiocb as well */
2779 cmdiocb->context_un.rsp_iocb = rspiocb;
2781 irsp = &(rspiocb->iocb);
2782 spin_lock_irq(shost->host_lock);
2783 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2784 spin_unlock_irq(shost->host_lock);
2786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2787 "LOGO cmpl: status:x%x/x%x did:x%x",
2788 irsp->ulpStatus, irsp->un.ulpWord[4],
2791 /* LOGO completes to NPort <nlp_DID> */
2792 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2793 "0105 LOGO completes to NPort x%x "
2794 "Data: x%x x%x x%x x%x\n",
2795 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2796 irsp->ulpTimeout, vport->num_disc_nodes);
2798 if (lpfc_els_chk_latt(vport)) {
2803 /* Check to see if link went down during discovery */
2804 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2805 /* NLP_EVT_DEVICE_RM should unregister the RPI
2806 * which should abort all outstanding IOs.
2808 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2814 /* The LOGO will not be retried on failure. A LOGO was
2815 * issued to the remote rport and a ACC or RJT or no Answer are
2816 * all acceptable. Note the failure and move forward with
2817 * discovery. The PLOGI will retry.
2819 if (irsp->ulpStatus) {
2821 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2822 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2823 ndlp->nlp_DID, irsp->ulpStatus,
2824 irsp->un.ulpWord[4]);
2825 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2826 if (lpfc_error_lost_link(irsp)) {
2832 /* Call state machine. This will unregister the rpi if needed. */
2833 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2836 /* Driver is done with the IO. */
2837 lpfc_els_free_iocb(phba, cmdiocb);
2840 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2841 if ((vport->fc_flag & FC_PT2PT) &&
2842 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2843 phba->pport->fc_myDID = 0;
2845 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2846 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2847 if (phba->nvmet_support)
2848 lpfc_nvmet_update_targetport(phba);
2850 lpfc_nvme_update_localport(phba->pport);
2853 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2855 lpfc_config_link(phba, mbox);
2856 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2857 mbox->vport = vport;
2858 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2860 mempool_free(mbox, phba->mbox_mem_pool);
2867 * If the node is a target, the handling attempts to recover the port.
2868 * For any other port type, the rpi is unregistered as an implicit
2871 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2872 skip_recovery == 0) {
2873 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2874 spin_lock_irqsave(shost->host_lock, flags);
2875 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2876 spin_unlock_irqrestore(shost->host_lock, flags);
2878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2879 "3187 LOGO completes to NPort x%x: Start "
2880 "Recovery Data: x%x x%x x%x x%x\n",
2881 ndlp->nlp_DID, irsp->ulpStatus,
2882 irsp->un.ulpWord[4], irsp->ulpTimeout,
2883 vport->num_disc_nodes);
2884 lpfc_disc_start(vport);
2890 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2891 * @vport: pointer to a virtual N_Port data structure.
2892 * @ndlp: pointer to a node-list data structure.
2893 * @retry: number of retries to the command IOCB.
2895 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2896 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2897 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2898 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2900 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2901 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2902 * will be stored into the context1 field of the IOCB for the completion
2903 * callback function to the LOGO ELS command.
2905 * Callers of this routine are expected to unregister the RPI first
2908 * 0 - successfully issued logo
2909 * 1 - failed to issue logo
2912 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2915 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2916 struct lpfc_hba *phba = vport->phba;
2917 struct lpfc_iocbq *elsiocb;
2922 spin_lock_irq(shost->host_lock);
2923 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2924 spin_unlock_irq(shost->host_lock);
2927 spin_unlock_irq(shost->host_lock);
2929 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2930 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2931 ndlp->nlp_DID, ELS_CMD_LOGO);
2935 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2936 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2937 pcmd += sizeof(uint32_t);
2939 /* Fill in LOGO payload */
2940 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2941 pcmd += sizeof(uint32_t);
2942 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2944 phba->fc_stat.elsXmitLOGO++;
2945 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2946 spin_lock_irq(shost->host_lock);
2947 ndlp->nlp_flag |= NLP_LOGO_SND;
2948 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2949 spin_unlock_irq(shost->host_lock);
2950 elsiocb->context1 = lpfc_nlp_get(ndlp);
2951 if (!elsiocb->context1)
2954 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2955 "Issue LOGO: did:x%x refcnt %d",
2956 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2957 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2958 if (rc == IOCB_ERROR)
2961 spin_lock_irq(shost->host_lock);
2962 ndlp->nlp_prev_state = ndlp->nlp_state;
2963 spin_unlock_irq(shost->host_lock);
2964 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2970 spin_lock_irq(shost->host_lock);
2971 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2972 spin_unlock_irq(shost->host_lock);
2973 lpfc_els_free_iocb(phba, elsiocb);
2978 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2979 * @phba: pointer to lpfc hba data structure.
2980 * @cmdiocb: pointer to lpfc command iocb data structure.
2981 * @rspiocb: pointer to lpfc response iocb data structure.
2983 * This routine is a generic completion callback function for ELS commands.
2984 * Specifically, it is the callback function which does not need to perform
2985 * any command specific operations. It is currently used by the ELS command
2986 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
2987 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
2988 * Other than certain debug loggings, this callback function simply invokes the
2989 * lpfc_els_chk_latt() routine to check whether link went down during the
2990 * discovery process.
2993 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2994 struct lpfc_iocbq *rspiocb)
2996 struct lpfc_vport *vport = cmdiocb->vport;
2997 struct lpfc_nodelist *free_ndlp;
3000 irsp = &rspiocb->iocb;
3002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3003 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3004 irsp->ulpStatus, irsp->un.ulpWord[4],
3005 irsp->un.elsreq64.remoteID);
3007 /* ELS cmd tag <ulpIoTag> completes */
3008 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3009 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3010 irsp->ulpIoTag, irsp->ulpStatus,
3011 irsp->un.ulpWord[4], irsp->ulpTimeout);
3013 /* Check to see if link went down during discovery */
3014 lpfc_els_chk_latt(vport);
3016 free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
3018 lpfc_els_free_iocb(phba, cmdiocb);
3019 lpfc_nlp_put(free_ndlp);
3023 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3024 * @phba: pointer to lpfc hba data structure.
3025 * @cmdiocb: pointer to lpfc command iocb data structure.
3026 * @rspiocb: pointer to lpfc response iocb data structure.
3028 * This routine is a generic completion callback function for Discovery ELS cmd.
3029 * Currently used by the ELS command issuing routines for the ELS State Change
3030 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3031 * These commands will be retried once only for ELS timeout errors.
3034 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3035 struct lpfc_iocbq *rspiocb)
3037 struct lpfc_vport *vport = cmdiocb->vport;
3039 struct lpfc_els_rdf_rsp *prdf;
3040 struct lpfc_dmabuf *pcmd, *prsp;
3043 struct lpfc_nodelist *ndlp = cmdiocb->context1;
3045 irsp = &rspiocb->iocb;
3047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3048 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3049 irsp->ulpStatus, irsp->un.ulpWord[4],
3050 irsp->un.elsreq64.remoteID);
3051 /* ELS cmd tag <ulpIoTag> completes */
3052 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3053 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3055 irsp->ulpIoTag, irsp->ulpStatus,
3056 irsp->un.ulpWord[4], irsp->ulpTimeout,
3059 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3063 pdata = (u32 *)pcmd->virt;
3068 /* Only 1 retry for ELS Timeout only */
3069 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3070 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3071 IOERR_SEQUENCE_TIMEOUT)) {
3073 if (cmdiocb->retry <= 1) {
3076 lpfc_issue_els_scr(vport, cmdiocb->retry);
3079 cmdiocb->context1 = NULL; /* save ndlp refcnt */
3080 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3085 phba->fc_stat.elsRetryExceeded++;
3087 if (irsp->ulpStatus) {
3088 /* ELS discovery cmd completes with error */
3089 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3090 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3091 irsp->ulpStatus, irsp->un.ulpWord[4]);
3095 /* The RDF response doesn't have any impact on the running driver
3096 * but the notification descriptors are dumped here for support.
3098 if (cmd == ELS_CMD_RDF) {
3101 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3105 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3109 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3110 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3111 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3112 "4677 Fabric RDF Notification Grant Data: "
3115 prdf->reg_d1.desc_tags[i]));
3119 /* Check to see if link went down during discovery */
3120 lpfc_els_chk_latt(vport);
3121 lpfc_els_free_iocb(phba, cmdiocb);
3127 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3128 * @vport: pointer to a host virtual N_Port data structure.
3129 * @retry: retry counter for the command IOCB.
3131 * This routine issues a State Change Request (SCR) to a fabric node
3132 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3133 * first search the @vport node list to find the matching ndlp. If no such
3134 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3135 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3136 * routine is invoked to send the SCR IOCB.
3138 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3139 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3140 * will be stored into the context1 field of the IOCB for the completion
3141 * callback function to the SCR ELS command.
3144 * 0 - Successfully issued scr command
3145 * 1 - Failed to issue scr command
3148 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3151 struct lpfc_hba *phba = vport->phba;
3152 struct lpfc_iocbq *elsiocb;
3155 struct lpfc_nodelist *ndlp;
3157 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3159 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3161 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3164 lpfc_enqueue_node(vport, ndlp);
3167 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3168 ndlp->nlp_DID, ELS_CMD_SCR);
3173 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3175 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3176 pcmd += sizeof(uint32_t);
3178 /* For SCR, remainder of payload is SCR parameter page */
3179 memset(pcmd, 0, sizeof(SCR));
3180 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3183 "Issue SCR: did:x%x",
3184 ndlp->nlp_DID, 0, 0);
3186 phba->fc_stat.elsXmitSCR++;
3187 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3188 elsiocb->context1 = lpfc_nlp_get(ndlp);
3189 if (!elsiocb->context1)
3192 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3193 "Issue SCR: did:x%x refcnt %d",
3194 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3196 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3197 if (rc == IOCB_ERROR)
3200 /* Keep the ndlp just in case RDF is being sent */
3206 lpfc_els_free_iocb(phba, elsiocb);
3211 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3212 * or the other nport (pt2pt).
3213 * @vport: pointer to a host virtual N_Port data structure.
3214 * @retry: number of retries to the command IOCB.
3216 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3217 * when connected to a fabric, or to the remote port when connected
3218 * in point-to-point mode. When sent to the Fabric Controller, it will
3219 * replay the RSCN to registered recipients.
3221 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3222 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3223 * will be stored into the context1 field of the IOCB for the completion
3224 * callback function to the RSCN ELS command.
3227 * 0 - Successfully issued RSCN command
3228 * 1 - Failed to issue RSCN command
3231 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3234 struct lpfc_hba *phba = vport->phba;
3235 struct lpfc_iocbq *elsiocb;
3236 struct lpfc_nodelist *ndlp;
3238 struct fc_els_rscn rscn;
3239 struct fc_els_rscn_page portid;
3242 uint16_t cmdsize = sizeof(*event);
3244 /* Not supported for private loop */
3245 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3246 !(vport->fc_flag & FC_PUBLIC_LOOP))
3249 if (vport->fc_flag & FC_PT2PT) {
3250 /* find any mapped nport - that would be the other nport */
3251 ndlp = lpfc_findnode_mapped(vport);
3255 nportid = FC_FID_FCTRL;
3256 /* find the fabric controller node */
3257 ndlp = lpfc_findnode_did(vport, nportid);
3259 /* if one didn't exist, make one */
3260 ndlp = lpfc_nlp_init(vport, nportid);
3263 lpfc_enqueue_node(vport, ndlp);
3267 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3268 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3273 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3275 event->rscn.rscn_cmd = ELS_RSCN;
3276 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3277 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3279 nportid = vport->fc_myDID;
3280 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3281 event->portid.rscn_page_flags = 0;
3282 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3283 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3284 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3286 phba->fc_stat.elsXmitRSCN++;
3287 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3288 elsiocb->context1 = lpfc_nlp_get(ndlp);
3289 if (!elsiocb->context1)
3292 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3293 "Issue RSCN: did:x%x",
3294 ndlp->nlp_DID, 0, 0);
3296 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3297 if (rc == IOCB_ERROR)
3300 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3301 * trigger the release of node.
3303 if (!(vport->fc_flag & FC_PT2PT))
3309 lpfc_els_free_iocb(phba, elsiocb);
3314 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3315 * @vport: pointer to a host virtual N_Port data structure.
3316 * @nportid: N_Port identifier to the remote node.
3317 * @retry: number of retries to the command IOCB.
3319 * This routine issues a Fibre Channel Address Resolution Response
3320 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3321 * is passed into the function. It first search the @vport node list to find
3322 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3323 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3324 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3326 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3327 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3328 * will be stored into the context1 field of the IOCB for the completion
3329 * callback function to the PARPR ELS command.
3332 * 0 - Successfully issued farpr command
3333 * 1 - Failed to issue farpr command
3336 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3339 struct lpfc_hba *phba = vport->phba;
3340 struct lpfc_iocbq *elsiocb;
3345 struct lpfc_nodelist *ondlp;
3346 struct lpfc_nodelist *ndlp;
3348 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3350 ndlp = lpfc_findnode_did(vport, nportid);
3352 ndlp = lpfc_nlp_init(vport, nportid);
3355 lpfc_enqueue_node(vport, ndlp);
3358 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3359 ndlp->nlp_DID, ELS_CMD_RNID);
3363 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3365 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3366 pcmd += sizeof(uint32_t);
3368 /* Fill in FARPR payload */
3369 fp = (FARP *) (pcmd);
3370 memset(fp, 0, sizeof(FARP));
3371 lp = (uint32_t *) pcmd;
3372 *lp++ = be32_to_cpu(nportid);
3373 *lp++ = be32_to_cpu(vport->fc_myDID);
3375 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3377 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3378 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3379 ondlp = lpfc_findnode_did(vport, nportid);
3381 memcpy(&fp->OportName, &ondlp->nlp_portname,
3382 sizeof(struct lpfc_name));
3383 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3384 sizeof(struct lpfc_name));
3387 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3388 "Issue FARPR: did:x%x",
3389 ndlp->nlp_DID, 0, 0);
3391 phba->fc_stat.elsXmitFARPR++;
3392 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3393 elsiocb->context1 = lpfc_nlp_get(ndlp);
3394 if (!elsiocb->context1) {
3395 lpfc_els_free_iocb(phba, elsiocb);
3399 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3400 if (rc == IOCB_ERROR) {
3401 /* The additional lpfc_nlp_put will cause the following
3402 * lpfc_els_free_iocb routine to trigger the release of
3406 lpfc_els_free_iocb(phba, elsiocb);
3409 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3410 * trigger the release of the node.
3412 /* Don't release reference count as RDF is likely outstanding */
3417 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3418 * @vport: pointer to a host virtual N_Port data structure.
3419 * @retry: retry counter for the command IOCB.
3421 * This routine issues an ELS RDF to the Fabric Controller to register
3422 * for diagnostic functions.
3424 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3425 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3426 * will be stored into the context1 field of the IOCB for the completion
3427 * callback function to the RDF ELS command.
3430 * 0 - Successfully issued rdf command
3431 * 1 - Failed to issue rdf command
3434 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3436 struct lpfc_hba *phba = vport->phba;
3437 struct lpfc_iocbq *elsiocb;
3438 struct lpfc_els_rdf_req *prdf;
3439 struct lpfc_nodelist *ndlp;
3443 cmdsize = sizeof(*prdf);
3445 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3447 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3450 lpfc_enqueue_node(vport, ndlp);
3453 /* RDF ELS is not required on an NPIV VN_Port. */
3454 if (vport->port_type == LPFC_NPIV_PORT) {
3459 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3460 ndlp->nlp_DID, ELS_CMD_RDF);
3464 /* Configure the payload for the supported FPIN events. */
3465 prdf = (struct lpfc_els_rdf_req *)
3466 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3467 memset(prdf, 0, cmdsize);
3468 prdf->rdf.fpin_cmd = ELS_RDF;
3469 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3470 sizeof(struct fc_els_rdf));
3471 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3472 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3473 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3474 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3475 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3476 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3477 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3478 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3480 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3481 "6444 Xmit RDF to remote NPORT x%x\n",
3484 elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3485 elsiocb->context1 = lpfc_nlp_get(ndlp);
3486 if (!elsiocb->context1)
3489 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3490 "Issue RDF: did:x%x refcnt %d",
3491 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3493 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3494 if (rc == IOCB_ERROR)
3501 lpfc_els_free_iocb(phba, elsiocb);
3506 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3507 * @vport: pointer to a host virtual N_Port data structure.
3508 * @nlp: pointer to a node-list data structure.
3510 * This routine cancels the timer with a delayed IOCB-command retry for
3511 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3512 * removes the ELS retry event if it presents. In addition, if the
3513 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3514 * commands are sent for the @vport's nodes that require issuing discovery
3518 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3521 struct lpfc_work_evt *evtp;
3523 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3525 spin_lock_irq(shost->host_lock);
3526 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3527 spin_unlock_irq(shost->host_lock);
3528 del_timer_sync(&nlp->nlp_delayfunc);
3529 nlp->nlp_last_elscmd = 0;
3530 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3531 list_del_init(&nlp->els_retry_evt.evt_listp);
3532 /* Decrement nlp reference count held for the delayed retry */
3533 evtp = &nlp->els_retry_evt;
3534 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3536 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3537 spin_lock_irq(shost->host_lock);
3538 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3539 spin_unlock_irq(shost->host_lock);
3540 if (vport->num_disc_nodes) {
3541 if (vport->port_state < LPFC_VPORT_READY) {
3542 /* Check if there are more ADISCs to be sent */
3543 lpfc_more_adisc(vport);
3545 /* Check if there are more PLOGIs to be sent */
3546 lpfc_more_plogi(vport);
3547 if (vport->num_disc_nodes == 0) {
3548 spin_lock_irq(shost->host_lock);
3549 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3550 spin_unlock_irq(shost->host_lock);
3551 lpfc_can_disctmo(vport);
3552 lpfc_end_rscn(vport);
3561 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3562 * @t: pointer to the timer function associated data (ndlp).
3564 * This routine is invoked by the ndlp delayed-function timer to check
3565 * whether there is any pending ELS retry event(s) with the node. If not, it
3566 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3567 * adds the delayed events to the HBA work list and invokes the
3568 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3569 * event. Note that lpfc_nlp_get() is called before posting the event to
3570 * the work list to hold reference count of ndlp so that it guarantees the
3571 * reference to ndlp will still be available when the worker thread gets
3572 * to the event associated with the ndlp.
3575 lpfc_els_retry_delay(struct timer_list *t)
3577 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3578 struct lpfc_vport *vport = ndlp->vport;
3579 struct lpfc_hba *phba = vport->phba;
3580 unsigned long flags;
3581 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3583 spin_lock_irqsave(&phba->hbalock, flags);
3584 if (!list_empty(&evtp->evt_listp)) {
3585 spin_unlock_irqrestore(&phba->hbalock, flags);
3589 /* We need to hold the node by incrementing the reference
3590 * count until the queued work is done
3592 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3593 if (evtp->evt_arg1) {
3594 evtp->evt = LPFC_EVT_ELS_RETRY;
3595 list_add_tail(&evtp->evt_listp, &phba->work_list);
3596 lpfc_worker_wake_up(phba);
3598 spin_unlock_irqrestore(&phba->hbalock, flags);
3603 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3604 * @ndlp: pointer to a node-list data structure.
3606 * This routine is the worker-thread handler for processing the @ndlp delayed
3607 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3608 * the last ELS command from the associated ndlp and invokes the proper ELS
3609 * function according to the delayed ELS command to retry the command.
3612 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3614 struct lpfc_vport *vport = ndlp->vport;
3615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3616 uint32_t cmd, retry;
3618 spin_lock_irq(shost->host_lock);
3619 cmd = ndlp->nlp_last_elscmd;
3620 ndlp->nlp_last_elscmd = 0;
3622 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3623 spin_unlock_irq(shost->host_lock);
3627 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3628 spin_unlock_irq(shost->host_lock);
3630 * If a discovery event readded nlp_delayfunc after timer
3631 * firing and before processing the timer, cancel the
3634 del_timer_sync(&ndlp->nlp_delayfunc);
3635 retry = ndlp->nlp_retry;
3636 ndlp->nlp_retry = 0;
3640 lpfc_issue_els_flogi(vport, ndlp, retry);
3643 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3644 ndlp->nlp_prev_state = ndlp->nlp_state;
3645 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3649 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3650 ndlp->nlp_prev_state = ndlp->nlp_state;
3651 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3655 case ELS_CMD_NVMEPRLI:
3656 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3657 ndlp->nlp_prev_state = ndlp->nlp_state;
3658 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3662 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3663 ndlp->nlp_prev_state = ndlp->nlp_state;
3664 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3668 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3669 lpfc_issue_els_fdisc(vport, ndlp, retry);
3676 * lpfc_link_reset - Issue link reset
3677 * @vport: pointer to a virtual N_Port data structure.
3679 * This routine performs link reset by sending INIT_LINK mailbox command.
3680 * For SLI-3 adapter, link attention interrupt is enabled before issuing
3681 * INIT_LINK mailbox command.
3684 * 0 - Link reset initiated successfully
3685 * 1 - Failed to initiate link reset
3688 lpfc_link_reset(struct lpfc_vport *vport)
3690 struct lpfc_hba *phba = vport->phba;
3695 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3696 "2851 Attempt link reset\n");
3697 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3699 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3700 "2852 Failed to allocate mbox memory");
3704 /* Enable Link attention interrupts */
3705 if (phba->sli_rev <= LPFC_SLI_REV3) {
3706 spin_lock_irq(&phba->hbalock);
3707 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3708 control = readl(phba->HCregaddr);
3709 control |= HC_LAINT_ENA;
3710 writel(control, phba->HCregaddr);
3711 readl(phba->HCregaddr); /* flush */
3712 spin_unlock_irq(&phba->hbalock);
3715 lpfc_init_link(phba, mbox, phba->cfg_topology,
3716 phba->cfg_link_speed);
3717 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3718 mbox->vport = vport;
3719 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3720 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3721 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3722 "2853 Failed to issue INIT_LINK "
3723 "mbox command, rc:x%x\n", rc);
3724 mempool_free(mbox, phba->mbox_mem_pool);
3732 * lpfc_els_retry - Make retry decision on an els command iocb
3733 * @phba: pointer to lpfc hba data structure.
3734 * @cmdiocb: pointer to lpfc command iocb data structure.
3735 * @rspiocb: pointer to lpfc response iocb data structure.
3737 * This routine makes a retry decision on an ELS command IOCB, which has
3738 * failed. The following ELS IOCBs use this function for retrying the command
3739 * when previously issued command responsed with error status: FLOGI, PLOGI,
3740 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3741 * returned error status, it makes the decision whether a retry shall be
3742 * issued for the command, and whether a retry shall be made immediately or
3743 * delayed. In the former case, the corresponding ELS command issuing-function
3744 * is called to retry the command. In the later case, the ELS command shall
3745 * be posted to the ndlp delayed event and delayed function timer set to the
3746 * ndlp for the delayed command issusing.
3749 * 0 - No retry of els command is made
3750 * 1 - Immediate or delayed retry of els command is made
3753 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3754 struct lpfc_iocbq *rspiocb)
3756 struct lpfc_vport *vport = cmdiocb->vport;
3757 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3758 IOCB_t *irsp = &rspiocb->iocb;
3759 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3760 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3763 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3767 int link_reset = 0, rc;
3770 /* Note: context2 may be 0 for internal driver abort
3771 * of delays ELS command.
3774 if (pcmd && pcmd->virt) {
3775 elscmd = (uint32_t *) (pcmd->virt);
3780 did = ndlp->nlp_DID;
3782 /* We should only hit this case for retrying PLOGI */
3783 did = irsp->un.elsreq64.remoteID;
3784 ndlp = lpfc_findnode_did(vport, did);
3785 if (!ndlp && (cmd != ELS_CMD_PLOGI))
3789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3790 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3791 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3793 switch (irsp->ulpStatus) {
3794 case IOSTAT_FCP_RSP_ERROR:
3796 case IOSTAT_REMOTE_STOP:
3797 if (phba->sli_rev == LPFC_SLI_REV4) {
3798 /* This IO was aborted by the target, we don't
3799 * know the rxid and because we did not send the
3800 * ABTS we cannot generate and RRQ.
3802 lpfc_set_rrq_active(phba, ndlp,
3803 cmdiocb->sli4_lxritag, 0, 0);
3806 case IOSTAT_LOCAL_REJECT:
3807 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3808 case IOERR_LOOP_OPEN_FAILURE:
3809 if (cmd == ELS_CMD_FLOGI) {
3810 if (PCI_DEVICE_ID_HORNET ==
3811 phba->pcidev->device) {
3812 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3813 phba->pport->fc_myDID = 0;
3814 phba->alpa_map[0] = 0;
3815 phba->alpa_map[1] = 0;
3818 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3823 case IOERR_ILLEGAL_COMMAND:
3824 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3825 "0124 Retry illegal cmd x%x "
3826 "retry:x%x delay:x%x\n",
3827 cmd, cmdiocb->retry, delay);
3829 /* All command's retry policy */
3831 if (cmdiocb->retry > 2)
3835 case IOERR_NO_RESOURCES:
3836 logerr = 1; /* HBA out of resources */
3838 if (cmdiocb->retry > 100)
3843 case IOERR_ILLEGAL_FRAME:
3848 case IOERR_INVALID_RPI:
3849 if (cmd == ELS_CMD_PLOGI &&
3850 did == NameServer_DID) {
3851 /* Continue forever if plogi to */
3852 /* the nameserver fails */
3859 case IOERR_SEQUENCE_TIMEOUT:
3860 if (cmd == ELS_CMD_PLOGI &&
3861 did == NameServer_DID &&
3862 (cmdiocb->retry + 1) == maxretry) {
3863 /* Reset the Link */
3873 case IOSTAT_NPORT_RJT:
3874 case IOSTAT_FABRIC_RJT:
3875 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3881 case IOSTAT_NPORT_BSY:
3882 case IOSTAT_FABRIC_BSY:
3883 logerr = 1; /* Fabric / Remote NPort out of resources */
3888 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3889 /* Added for Vendor specifc support
3890 * Just keep retrying for these Rsn / Exp codes
3892 switch (stat.un.b.lsRjtRsnCode) {
3893 case LSRJT_UNABLE_TPC:
3894 /* The driver has a VALID PLOGI but the rport has
3895 * rejected the PRLI - can't do it now. Delay
3896 * for 1 second and try again.
3898 * However, if explanation is REQ_UNSUPPORTED there's
3899 * no point to retry PRLI.
3901 if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3902 stat.un.b.lsRjtRsnCodeExp !=
3903 LSEXP_REQ_UNSUPPORTED) {
3905 maxretry = lpfc_max_els_tries + 1;
3910 /* Legacy bug fix code for targets with PLOGI delays. */
3911 if (stat.un.b.lsRjtRsnCodeExp ==
3912 LSEXP_CMD_IN_PROGRESS) {
3913 if (cmd == ELS_CMD_PLOGI) {
3920 if (stat.un.b.lsRjtRsnCodeExp ==
3921 LSEXP_CANT_GIVE_DATA) {
3922 if (cmd == ELS_CMD_PLOGI) {
3929 if (cmd == ELS_CMD_PLOGI) {
3931 maxretry = lpfc_max_els_tries + 1;
3935 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3936 (cmd == ELS_CMD_FDISC) &&
3937 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3938 lpfc_printf_vlog(vport, KERN_ERR,
3940 "0125 FDISC Failed (x%x). "
3941 "Fabric out of resources\n",
3942 stat.un.lsRjtError);
3943 lpfc_vport_set_state(vport,
3944 FC_VPORT_NO_FABRIC_RSCS);
3948 case LSRJT_LOGICAL_BSY:
3949 if ((cmd == ELS_CMD_PLOGI) ||
3950 (cmd == ELS_CMD_PRLI) ||
3951 (cmd == ELS_CMD_NVMEPRLI)) {
3954 } else if (cmd == ELS_CMD_FDISC) {
3955 /* FDISC retry policy */
3957 if (cmdiocb->retry >= 32)
3963 case LSRJT_LOGICAL_ERR:
3964 /* There are some cases where switches return this
3965 * error when they are not ready and should be returning
3966 * Logical Busy. We should delay every time.
3968 if (cmd == ELS_CMD_FDISC &&
3969 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3973 } else if (cmd == ELS_CMD_FLOGI &&
3974 stat.un.b.lsRjtRsnCodeExp ==
3975 LSEXP_NOTHING_MORE) {
3976 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3978 lpfc_printf_vlog(vport, KERN_ERR,
3980 "0820 FLOGI Failed (x%x). "
3981 "BBCredit Not Supported\n",
3982 stat.un.lsRjtError);
3986 case LSRJT_PROTOCOL_ERR:
3987 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3988 (cmd == ELS_CMD_FDISC) &&
3989 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3990 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3992 lpfc_printf_vlog(vport, KERN_ERR,
3994 "0122 FDISC Failed (x%x). "
3995 "Fabric Detected Bad WWN\n",
3996 stat.un.lsRjtError);
3997 lpfc_vport_set_state(vport,
3998 FC_VPORT_FABRIC_REJ_WWN);
4001 case LSRJT_VENDOR_UNIQUE:
4002 if ((stat.un.b.vendorUnique == 0x45) &&
4003 (cmd == ELS_CMD_FLOGI)) {
4007 case LSRJT_CMD_UNSUPPORTED:
4008 /* lpfc nvmet returns this type of LS_RJT when it
4009 * receives an FCP PRLI because lpfc nvmet only
4010 * support NVME. ELS request is terminated for FCP4
4013 if (stat.un.b.lsRjtRsnCodeExp ==
4014 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4015 spin_lock_irq(shost->host_lock);
4016 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4017 spin_unlock_irq(shost->host_lock);
4025 case IOSTAT_INTERMED_RSP:
4034 rc = lpfc_link_reset(vport);
4036 /* Do not give up. Retry PLOGI one more time and attempt
4037 * link reset if PLOGI fails again.
4046 if (did == FDMI_DID)
4049 if ((cmd == ELS_CMD_FLOGI) &&
4050 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4051 !lpfc_error_lost_link(irsp)) {
4052 /* FLOGI retry policy */
4054 /* retry FLOGI forever */
4055 if (phba->link_flag != LS_LOOPBACK_MODE)
4060 if (cmdiocb->retry >= 100)
4062 else if (cmdiocb->retry >= 32)
4064 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4065 /* retry FDISCs every second up to devloss */
4067 maxretry = vport->cfg_devloss_tmo;
4072 if (maxretry && (cmdiocb->retry >= maxretry)) {
4073 phba->fc_stat.elsRetryExceeded++;
4077 if ((vport->load_flag & FC_UNLOADING) != 0)
4082 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4083 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4084 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4085 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4086 "2849 Stop retry ELS command "
4087 "x%x to remote NPORT x%x, "
4088 "Data: x%x x%x\n", cmd, did,
4089 cmdiocb->retry, delay);
4094 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4095 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4096 "0107 Retry ELS command x%x to remote "
4097 "NPORT x%x Data: x%x x%x\n",
4098 cmd, did, cmdiocb->retry, delay);
4100 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4101 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4102 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4103 IOERR_NO_RESOURCES))) {
4104 /* Don't reset timer for no resources */
4106 /* If discovery / RSCN timer is running, reset it */
4107 if (timer_pending(&vport->fc_disctmo) ||
4108 (vport->fc_flag & FC_RSCN_MODE))
4109 lpfc_set_disctmo(vport);
4112 phba->fc_stat.elsXmitRetry++;
4113 if (ndlp && delay) {
4114 phba->fc_stat.elsDelayRetry++;
4115 ndlp->nlp_retry = cmdiocb->retry;
4117 /* delay is specified in milliseconds */
4118 mod_timer(&ndlp->nlp_delayfunc,
4119 jiffies + msecs_to_jiffies(delay));
4120 spin_lock_irq(shost->host_lock);
4121 ndlp->nlp_flag |= NLP_DELAY_TMO;
4122 spin_unlock_irq(shost->host_lock);
4124 ndlp->nlp_prev_state = ndlp->nlp_state;
4125 if ((cmd == ELS_CMD_PRLI) ||
4126 (cmd == ELS_CMD_NVMEPRLI))
4127 lpfc_nlp_set_state(vport, ndlp,
4128 NLP_STE_PRLI_ISSUE);
4130 lpfc_nlp_set_state(vport, ndlp,
4132 ndlp->nlp_last_elscmd = cmd;
4138 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4141 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4145 ndlp->nlp_prev_state = ndlp->nlp_state;
4146 lpfc_nlp_set_state(vport, ndlp,
4147 NLP_STE_PLOGI_ISSUE);
4149 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4152 ndlp->nlp_prev_state = ndlp->nlp_state;
4153 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4154 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4157 case ELS_CMD_NVMEPRLI:
4158 ndlp->nlp_prev_state = ndlp->nlp_state;
4159 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4160 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4163 ndlp->nlp_prev_state = ndlp->nlp_state;
4164 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4165 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4169 /* No retry ELS command <elsCmd> to remote NPORT <did> */
4171 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4172 "0137 No retry ELS command x%x to remote "
4173 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4174 cmd, did, irsp->ulpStatus,
4175 irsp->un.ulpWord[4]);
4178 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4179 "0108 No retry ELS command x%x to remote "
4180 "NPORT x%x Retried:%d Error:x%x/%x\n",
4181 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4182 irsp->un.ulpWord[4]);
4188 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4189 * @phba: pointer to lpfc hba data structure.
4190 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4192 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4193 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4194 * checks to see whether there is a lpfc DMA buffer associated with the
4195 * response of the command IOCB. If so, it will be released before releasing
4196 * the lpfc DMA buffer associated with the IOCB itself.
4199 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4202 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4204 struct lpfc_dmabuf *buf_ptr;
4206 /* Free the response before processing the command. */
4207 if (!list_empty(&buf_ptr1->list)) {
4208 list_remove_head(&buf_ptr1->list, buf_ptr,
4211 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4214 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4220 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4221 * @phba: pointer to lpfc hba data structure.
4222 * @buf_ptr: pointer to the lpfc dma buffer data structure.
4224 * This routine releases the lpfc Direct Memory Access (DMA) buffer
4225 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4229 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4232 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4234 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4240 * lpfc_els_free_iocb - Free a command iocb and its associated resources
4241 * @phba: pointer to lpfc hba data structure.
4242 * @elsiocb: pointer to lpfc els command iocb data structure.
4244 * This routine frees a command IOCB and its associated resources. The
4245 * command IOCB data structure contains the reference to various associated
4246 * resources, these fields must be set to NULL if the associated reference
4248 * context1 - reference to ndlp
4249 * context2 - reference to cmd
4250 * context2->next - reference to rsp
4251 * context3 - reference to bpl
4253 * It first properly decrements the reference count held on ndlp for the
4254 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4255 * set, it invokes the lpfc_els_free_data() routine to release the Direct
4256 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4257 * adds the DMA buffer the @phba data structure for the delayed release.
4258 * If reference to the Buffer Pointer List (BPL) is present, the
4259 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4260 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4261 * invoked to release the IOCB data structure back to @phba IOCBQ list.
4264 * 0 - Success (currently, always return 0)
4267 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4269 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4271 /* The I/O job is complete. Clear the context1 data. */
4272 elsiocb->context1 = NULL;
4274 /* context2 = cmd, context2->next = rsp, context3 = bpl */
4275 if (elsiocb->context2) {
4276 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4277 /* Firmware could still be in progress of DMAing
4278 * payload, so don't free data buffer till after
4281 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4282 buf_ptr = elsiocb->context2;
4283 elsiocb->context2 = NULL;
4286 spin_lock_irq(&phba->hbalock);
4287 if (!list_empty(&buf_ptr->list)) {
4288 list_remove_head(&buf_ptr->list,
4289 buf_ptr1, struct lpfc_dmabuf,
4291 INIT_LIST_HEAD(&buf_ptr1->list);
4292 list_add_tail(&buf_ptr1->list,
4296 INIT_LIST_HEAD(&buf_ptr->list);
4297 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4299 spin_unlock_irq(&phba->hbalock);
4302 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4303 lpfc_els_free_data(phba, buf_ptr1);
4304 elsiocb->context2 = NULL;
4308 if (elsiocb->context3) {
4309 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4310 lpfc_els_free_bpl(phba, buf_ptr);
4311 elsiocb->context3 = NULL;
4313 lpfc_sli_release_iocbq(phba, elsiocb);
4318 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4319 * @phba: pointer to lpfc hba data structure.
4320 * @cmdiocb: pointer to lpfc command iocb data structure.
4321 * @rspiocb: pointer to lpfc response iocb data structure.
4323 * This routine is the completion callback function to the Logout (LOGO)
4324 * Accept (ACC) Response ELS command. This routine is invoked to indicate
4325 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4326 * release the ndlp if it has the last reference remaining (reference count
4327 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4328 * field to NULL to inform the following lpfc_els_free_iocb() routine no
4329 * ndlp reference count needs to be decremented. Otherwise, the ndlp
4330 * reference use-count shall be decremented by the lpfc_els_free_iocb()
4331 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4332 * IOCB data structure.
4335 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4336 struct lpfc_iocbq *rspiocb)
4338 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4339 struct lpfc_vport *vport = cmdiocb->vport;
4342 irsp = &rspiocb->iocb;
4343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4344 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4345 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4346 /* ACC to LOGO completes to NPort <nlp_DID> */
4347 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4348 "0109 ACC to LOGO completes to NPort x%x "
4349 "Data: x%x x%x x%x\n",
4350 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4353 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4354 /* NPort Recovery mode or node is just allocated */
4355 if (!lpfc_nlp_not_used(ndlp)) {
4356 /* If the ndlp is being used by another discovery
4357 * thread, just unregister the RPI.
4359 lpfc_unreg_rpi(vport, ndlp);
4361 /* Indicate the node has already released, should
4362 * not reference to it from within lpfc_els_free_iocb.
4364 cmdiocb->context1 = NULL;
4369 * The driver received a LOGO from the rport and has ACK'd it.
4370 * At this point, the driver is done so release the IOCB
4372 lpfc_els_free_iocb(phba, cmdiocb);
4377 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4378 * @phba: pointer to lpfc hba data structure.
4379 * @pmb: pointer to the driver internal queue element for mailbox command.
4381 * This routine is the completion callback function for unregister default
4382 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4383 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4384 * decrements the ndlp reference count held for this completion callback
4385 * function. After that, it invokes the lpfc_nlp_not_used() to check
4386 * whether there is only one reference left on the ndlp. If so, it will
4387 * perform one more decrement and trigger the release of the ndlp.
4390 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4392 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4393 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4395 pmb->ctx_buf = NULL;
4396 pmb->ctx_ndlp = NULL;
4398 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4400 mempool_free(pmb, phba->mbox_mem_pool);
4402 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4403 "0006 rpi x%x DID:%x flg:%x %d x%px\n",
4404 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4405 kref_read(&ndlp->kref),
4407 /* This is the end of the default RPI cleanup logic for
4408 * this ndlp and it could get released. Clear the nlp_flags to
4409 * prevent any further processing.
4411 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4413 lpfc_nlp_not_used(ndlp);
4420 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4421 * @phba: pointer to lpfc hba data structure.
4422 * @cmdiocb: pointer to lpfc command iocb data structure.
4423 * @rspiocb: pointer to lpfc response iocb data structure.
4425 * This routine is the completion callback function for ELS Response IOCB
4426 * command. In normal case, this callback function just properly sets the
4427 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4428 * field in the command IOCB is not NULL, the referred mailbox command will
4429 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4430 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4431 * link down event occurred during the discovery, the lpfc_nlp_not_used()
4432 * routine shall be invoked trying to release the ndlp if no other threads
4433 * are currently referring it.
4436 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4437 struct lpfc_iocbq *rspiocb)
4439 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4440 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4441 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4444 LPFC_MBOXQ_t *mbox = NULL;
4445 struct lpfc_dmabuf *mp = NULL;
4446 uint32_t ls_rjt = 0;
4448 irsp = &rspiocb->iocb;
4451 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4452 "3177 ELS response failed\n");
4455 if (cmdiocb->context_un.mbox)
4456 mbox = cmdiocb->context_un.mbox;
4458 /* First determine if this is a LS_RJT cmpl. Note, this callback
4459 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4461 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4462 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4463 /* A LS_RJT associated with Default RPI cleanup has its own
4464 * separate code path.
4466 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4470 /* Check to see if link went down during discovery */
4471 if (!ndlp || lpfc_els_chk_latt(vport)) {
4473 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4475 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4478 mempool_free(mbox, phba->mbox_mem_pool);
4480 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4481 if (lpfc_nlp_not_used(ndlp)) {
4483 /* Indicate the node has already released,
4484 * should not reference to it from within
4485 * the routine lpfc_els_free_iocb.
4487 cmdiocb->context1 = NULL;
4492 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4493 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4494 irsp->ulpStatus, irsp->un.ulpWord[4],
4495 cmdiocb->iocb.un.elsreq64.remoteID);
4496 /* ELS response tag <ulpIoTag> completes */
4497 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4498 "0110 ELS response tag x%x completes "
4499 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4500 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4501 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4502 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4505 if ((rspiocb->iocb.ulpStatus == 0) &&
4506 (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4507 if (!lpfc_unreg_rpi(vport, ndlp) &&
4508 (!(vport->fc_flag & FC_PT2PT))) {
4509 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
4510 lpfc_printf_vlog(vport, KERN_INFO,
4514 "Data: x%x x%x x%x\n",
4521 lpfc_mbuf_free(phba, mp->virt,
4525 mempool_free(mbox, phba->mbox_mem_pool);
4530 /* Increment reference count to ndlp to hold the
4531 * reference to ndlp for the callback function.
4533 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4534 if (!mbox->ctx_ndlp)
4537 mbox->vport = vport;
4538 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4539 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4540 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4543 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4544 ndlp->nlp_prev_state = ndlp->nlp_state;
4545 lpfc_nlp_set_state(vport, ndlp,
4546 NLP_STE_REG_LOGIN_ISSUE);
4549 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4550 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4551 != MBX_NOT_FINISHED)
4554 /* Decrement the ndlp reference count we
4555 * set for this failed mailbox command.
4558 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4560 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4561 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4562 "0138 ELS rsp: Cannot issue reg_login for x%x "
4563 "Data: x%x x%x x%x\n",
4564 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4567 if (lpfc_nlp_not_used(ndlp)) {
4569 /* Indicate node has already been released,
4570 * should not reference to it from within
4571 * the routine lpfc_els_free_iocb.
4573 cmdiocb->context1 = NULL;
4576 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4577 if (!lpfc_error_lost_link(irsp) &&
4578 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4579 if (lpfc_nlp_not_used(ndlp)) {
4581 /* Indicate node has already been
4582 * released, should not reference
4583 * to it from within the routine
4584 * lpfc_els_free_iocb.
4586 cmdiocb->context1 = NULL;
4590 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4592 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4595 mempool_free(mbox, phba->mbox_mem_pool);
4598 if (ndlp && shost) {
4599 spin_lock_irq(shost->host_lock);
4601 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4602 ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4603 spin_unlock_irq(shost->host_lock);
4605 /* If the node is not being used by another discovery thread,
4606 * and we are sending a reject, we are done with it.
4607 * Release driver reference count here and free associated
4611 if (lpfc_nlp_not_used(ndlp))
4612 /* Indicate node has already been released,
4613 * should not reference to it from within
4614 * the routine lpfc_els_free_iocb.
4616 cmdiocb->context1 = NULL;
4619 /* Release the originating I/O reference. */
4620 lpfc_els_free_iocb(phba, cmdiocb);
4626 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4627 * @vport: pointer to a host virtual N_Port data structure.
4628 * @flag: the els command code to be accepted.
4629 * @oldiocb: pointer to the original lpfc command iocb data structure.
4630 * @ndlp: pointer to a node-list data structure.
4631 * @mbox: pointer to the driver internal queue element for mailbox command.
4633 * This routine prepares and issues an Accept (ACC) response IOCB
4634 * command. It uses the @flag to properly set up the IOCB field for the
4635 * specific ACC response command to be issued and invokes the
4636 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4637 * @mbox pointer is passed in, it will be put into the context_un.mbox
4638 * field of the IOCB for the completion callback function to issue the
4639 * mailbox command to the HBA later when callback is invoked.
4641 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4642 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4643 * will be stored into the context1 field of the IOCB for the completion
4644 * callback function to the corresponding response ELS IOCB command.
4647 * 0 - Successfully issued acc response
4648 * 1 - Failed to issue acc response
4651 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4652 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4655 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4656 struct lpfc_hba *phba = vport->phba;
4659 struct lpfc_iocbq *elsiocb;
4661 struct serv_parm *sp;
4664 ELS_PKT *els_pkt_ptr;
4666 oldcmd = &oldiocb->iocb;
4670 cmdsize = sizeof(uint32_t);
4671 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4672 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4674 spin_lock_irq(shost->host_lock);
4675 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4676 spin_unlock_irq(shost->host_lock);
4680 icmd = &elsiocb->iocb;
4681 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4682 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4683 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4684 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4685 pcmd += sizeof(uint32_t);
4687 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4688 "Issue ACC: did:x%x flg:x%x",
4689 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4693 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4694 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4695 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4699 icmd = &elsiocb->iocb;
4700 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4701 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4702 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4705 elsiocb->context_un.mbox = mbox;
4707 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4708 pcmd += sizeof(uint32_t);
4709 sp = (struct serv_parm *)pcmd;
4711 if (flag == ELS_CMD_FLOGI) {
4712 /* Copy the received service parameters back */
4713 memcpy(sp, &phba->fc_fabparam,
4714 sizeof(struct serv_parm));
4716 /* Clear the F_Port bit */
4719 /* Mark all class service parameters as invalid */
4720 sp->cls1.classValid = 0;
4721 sp->cls2.classValid = 0;
4722 sp->cls3.classValid = 0;
4723 sp->cls4.classValid = 0;
4725 /* Copy our worldwide names */
4726 memcpy(&sp->portName, &vport->fc_sparam.portName,
4727 sizeof(struct lpfc_name));
4728 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4729 sizeof(struct lpfc_name));
4731 memcpy(pcmd, &vport->fc_sparam,
4732 sizeof(struct serv_parm));
4734 sp->cmn.valid_vendor_ver_level = 0;
4735 memset(sp->un.vendorVersion, 0,
4736 sizeof(sp->un.vendorVersion));
4737 sp->cmn.bbRcvSizeMsb &= 0xF;
4739 /* If our firmware supports this feature, convey that
4740 * info to the target using the vendor specific field.
4742 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4743 sp->cmn.valid_vendor_ver_level = 1;
4744 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4746 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4750 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4751 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4752 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4755 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4756 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4757 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4761 icmd = &elsiocb->iocb;
4762 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4763 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4764 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4766 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4767 sizeof(uint32_t) + sizeof(PRLO));
4768 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4769 els_pkt_ptr = (ELS_PKT *) pcmd;
4770 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4773 "Issue ACC PRLO: did:x%x flg:x%x",
4774 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4779 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4780 spin_lock_irq(shost->host_lock);
4781 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4782 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4783 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4784 spin_unlock_irq(shost->host_lock);
4785 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4787 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4790 phba->fc_stat.elsXmitACC++;
4791 elsiocb->context1 = lpfc_nlp_get(ndlp);
4792 if (!elsiocb->context1)
4795 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4796 if (rc == IOCB_ERROR)
4799 /* Xmit ELS ACC response tag <ulpIoTag> */
4800 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4801 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4802 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4803 "RPI: x%x, fc_flag x%x\n",
4804 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4805 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4806 ndlp->nlp_rpi, vport->fc_flag);
4812 lpfc_els_free_iocb(phba, elsiocb);
4817 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4818 * @vport: pointer to a virtual N_Port data structure.
4819 * @rejectError: reject response to issue
4820 * @oldiocb: pointer to the original lpfc command iocb data structure.
4821 * @ndlp: pointer to a node-list data structure.
4822 * @mbox: pointer to the driver internal queue element for mailbox command.
4824 * This routine prepares and issue an Reject (RJT) response IOCB
4825 * command. If a @mbox pointer is passed in, it will be put into the
4826 * context_un.mbox field of the IOCB for the completion callback function
4827 * to issue to the HBA later.
4829 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4830 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4831 * will be stored into the context1 field of the IOCB for the completion
4832 * callback function to the reject response ELS IOCB command.
4835 * 0 - Successfully issued reject response
4836 * 1 - Failed to issue reject response
4839 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4840 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4844 struct lpfc_hba *phba = vport->phba;
4847 struct lpfc_iocbq *elsiocb;
4851 cmdsize = 2 * sizeof(uint32_t);
4852 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4853 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4857 icmd = &elsiocb->iocb;
4858 oldcmd = &oldiocb->iocb;
4859 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4860 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4861 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4863 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4864 pcmd += sizeof(uint32_t);
4865 *((uint32_t *) (pcmd)) = rejectError;
4868 elsiocb->context_un.mbox = mbox;
4870 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4871 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4872 "0129 Xmit ELS RJT x%x response tag x%x "
4873 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4875 rejectError, elsiocb->iotag,
4876 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4877 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4879 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4880 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4882 phba->fc_stat.elsXmitLSRJT++;
4883 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4884 elsiocb->context1 = lpfc_nlp_get(ndlp);
4885 if (!elsiocb->context1)
4888 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4889 if (rc == IOCB_ERROR)
4897 lpfc_els_free_iocb(phba, elsiocb);
4902 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4903 * @vport: pointer to a virtual N_Port data structure.
4904 * @oldiocb: pointer to the original lpfc command iocb data structure.
4905 * @ndlp: pointer to a node-list data structure.
4907 * This routine prepares and issues an Accept (ACC) response to Address
4908 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4909 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4911 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4912 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4913 * will be stored into the context1 field of the IOCB for the completion
4914 * callback function to the ADISC Accept response ELS IOCB command.
4917 * 0 - Successfully issued acc adisc response
4918 * 1 - Failed to issue adisc acc response
4921 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4922 struct lpfc_nodelist *ndlp)
4924 struct lpfc_hba *phba = vport->phba;
4926 IOCB_t *icmd, *oldcmd;
4927 struct lpfc_iocbq *elsiocb;
4932 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4933 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4934 ndlp->nlp_DID, ELS_CMD_ACC);
4938 icmd = &elsiocb->iocb;
4939 oldcmd = &oldiocb->iocb;
4940 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4941 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4943 /* Xmit ADISC ACC response tag <ulpIoTag> */
4944 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4945 "0130 Xmit ADISC ACC response iotag x%x xri: "
4946 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4947 elsiocb->iotag, elsiocb->iocb.ulpContext,
4948 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4950 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4952 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4953 pcmd += sizeof(uint32_t);
4955 ap = (ADISC *) (pcmd);
4956 ap->hardAL_PA = phba->fc_pref_ALPA;
4957 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4958 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4959 ap->DID = be32_to_cpu(vport->fc_myDID);
4961 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4962 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
4963 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
4965 phba->fc_stat.elsXmitACC++;
4966 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4967 elsiocb->context1 = lpfc_nlp_get(ndlp);
4968 if (!elsiocb->context1)
4971 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4972 if (rc == IOCB_ERROR)
4975 /* Xmit ELS ACC response tag <ulpIoTag> */
4976 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4977 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4978 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4979 "RPI: x%x, fc_flag x%x\n",
4980 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4981 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4982 ndlp->nlp_rpi, vport->fc_flag);
4988 lpfc_els_free_iocb(phba, elsiocb);
4993 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4994 * @vport: pointer to a virtual N_Port data structure.
4995 * @oldiocb: pointer to the original lpfc command iocb data structure.
4996 * @ndlp: pointer to a node-list data structure.
4998 * This routine prepares and issues an Accept (ACC) response to Process
4999 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5000 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5002 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5003 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5004 * will be stored into the context1 field of the IOCB for the completion
5005 * callback function to the PRLI Accept response ELS IOCB command.
5008 * 0 - Successfully issued acc prli response
5009 * 1 - Failed to issue acc prli response
5012 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5013 struct lpfc_nodelist *ndlp)
5015 struct lpfc_hba *phba = vport->phba;
5017 struct lpfc_nvme_prli *npr_nvme;
5021 struct lpfc_iocbq *elsiocb;
5024 uint32_t prli_fc4_req, *req_payload;
5025 struct lpfc_dmabuf *req_buf;
5029 /* Need the incoming PRLI payload to determine if the ACC is for an
5030 * FC4 or NVME PRLI type. The PRLI type is at word 1.
5032 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5033 req_payload = (((uint32_t *)req_buf->virt) + 1);
5035 /* PRLI type payload is at byte 3 for FCP or NVME. */
5036 prli_fc4_req = be32_to_cpu(*req_payload);
5037 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5038 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5039 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5040 prli_fc4_req, *((uint32_t *)req_payload));
5042 if (prli_fc4_req == PRLI_FCP_TYPE) {
5043 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5044 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5045 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5046 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5047 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5052 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5053 ndlp->nlp_DID, elsrspcmd);
5057 icmd = &elsiocb->iocb;
5058 oldcmd = &oldiocb->iocb;
5059 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5060 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5062 /* Xmit PRLI ACC response tag <ulpIoTag> */
5063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5064 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5065 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5066 elsiocb->iotag, elsiocb->iocb.ulpContext,
5067 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5069 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5070 memset(pcmd, 0, cmdsize);
5072 *((uint32_t *)(pcmd)) = elsrspcmd;
5073 pcmd += sizeof(uint32_t);
5075 /* For PRLI, remainder of payload is PRLI parameter page */
5078 if (prli_fc4_req == PRLI_FCP_TYPE) {
5080 * If the remote port is a target and our firmware version
5081 * is 3.20 or later, set the following bits for FC-TAPE
5084 npr = (PRLI *) pcmd;
5085 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5086 (vpd->rev.feaLevelHigh >= 0x02)) {
5087 npr->ConfmComplAllowed = 1;
5089 npr->TaskRetryIdReq = 1;
5091 npr->acceptRspCode = PRLI_REQ_EXECUTED;
5092 npr->estabImagePair = 1;
5093 npr->readXferRdyDis = 1;
5094 npr->ConfmComplAllowed = 1;
5095 npr->prliType = PRLI_FCP_TYPE;
5096 npr->initiatorFunc = 1;
5097 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5098 /* Respond with an NVME PRLI Type */
5099 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5100 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5101 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5102 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5103 if (phba->nvmet_support) {
5104 bf_set(prli_tgt, npr_nvme, 1);
5105 bf_set(prli_disc, npr_nvme, 1);
5106 if (phba->cfg_nvme_enable_fb) {
5107 bf_set(prli_fba, npr_nvme, 1);
5109 /* TBD. Target mode needs to post buffers
5110 * that support the configured first burst
5113 bf_set(prli_fb_sz, npr_nvme,
5114 phba->cfg_nvmet_fb_size);
5117 bf_set(prli_init, npr_nvme, 1);
5120 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5121 "6015 NVME issue PRLI ACC word1 x%08x "
5122 "word4 x%08x word5 x%08x flag x%x, "
5123 "fcp_info x%x nlp_type x%x\n",
5124 npr_nvme->word1, npr_nvme->word4,
5125 npr_nvme->word5, ndlp->nlp_flag,
5126 ndlp->nlp_fcp_info, ndlp->nlp_type);
5127 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5128 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5129 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5131 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5132 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5133 prli_fc4_req, ndlp->nlp_fc4_type,
5136 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5137 "Issue ACC PRLI: did:x%x flg:x%x",
5138 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5140 phba->fc_stat.elsXmitACC++;
5141 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5142 elsiocb->context1 = lpfc_nlp_get(ndlp);
5143 if (!elsiocb->context1)
5146 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5147 if (rc == IOCB_ERROR)
5154 lpfc_els_free_iocb(phba, elsiocb);
5159 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5160 * @vport: pointer to a virtual N_Port data structure.
5161 * @format: rnid command format.
5162 * @oldiocb: pointer to the original lpfc command iocb data structure.
5163 * @ndlp: pointer to a node-list data structure.
5165 * This routine issues a Request Node Identification Data (RNID) Accept
5166 * (ACC) response. It constructs the RNID ACC response command according to
5167 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5168 * issue the response. Note that this command does not need to hold the ndlp
5169 * reference count for the callback. So, the ndlp reference count taken by
5170 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5171 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5172 * there is no ndlp reference available.
5174 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5175 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5176 * will be stored into the context1 field of the IOCB for the completion
5177 * callback function. However, for the RNID Accept Response ELS command,
5178 * this is undone later by this routine after the IOCB is allocated.
5181 * 0 - Successfully issued acc rnid response
5182 * 1 - Failed to issue acc rnid response
5185 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5186 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5188 struct lpfc_hba *phba = vport->phba;
5190 IOCB_t *icmd, *oldcmd;
5191 struct lpfc_iocbq *elsiocb;
5196 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5197 + (2 * sizeof(struct lpfc_name));
5199 cmdsize += sizeof(RNID_TOP_DISC);
5201 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5202 ndlp->nlp_DID, ELS_CMD_ACC);
5206 icmd = &elsiocb->iocb;
5207 oldcmd = &oldiocb->iocb;
5208 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5209 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5211 /* Xmit RNID ACC response tag <ulpIoTag> */
5212 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5213 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5214 elsiocb->iotag, elsiocb->iocb.ulpContext);
5215 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5216 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5217 pcmd += sizeof(uint32_t);
5219 memset(pcmd, 0, sizeof(RNID));
5220 rn = (RNID *) (pcmd);
5221 rn->Format = format;
5222 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5223 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5224 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5227 rn->SpecificLen = 0;
5229 case RNID_TOPOLOGY_DISC:
5230 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5231 memcpy(&rn->un.topologyDisc.portName,
5232 &vport->fc_portname, sizeof(struct lpfc_name));
5233 rn->un.topologyDisc.unitType = RNID_HBA;
5234 rn->un.topologyDisc.physPort = 0;
5235 rn->un.topologyDisc.attachedNodes = 0;
5239 rn->SpecificLen = 0;
5243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5244 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
5245 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5247 phba->fc_stat.elsXmitACC++;
5248 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5249 elsiocb->context1 = lpfc_nlp_get(ndlp);
5250 if (!elsiocb->context1)
5253 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5254 if (rc == IOCB_ERROR)
5262 lpfc_els_free_iocb(phba, elsiocb);
5267 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5268 * @vport: pointer to a virtual N_Port data structure.
5269 * @iocb: pointer to the lpfc command iocb data structure.
5270 * @ndlp: pointer to a node-list data structure.
5275 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5276 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5278 struct lpfc_hba *phba = vport->phba;
5283 struct lpfc_node_rrq *prrq;
5286 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5287 pcmd += sizeof(uint32_t);
5288 rrq = (struct RRQ *)pcmd;
5289 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5290 rxid = bf_get(rrq_rxid, rrq);
5292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5293 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5295 be32_to_cpu(bf_get(rrq_did, rrq)),
5296 bf_get(rrq_oxid, rrq),
5298 iocb->iotag, iocb->iocb.ulpContext);
5300 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5301 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5302 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5303 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5304 xri = bf_get(rrq_oxid, rrq);
5307 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5309 lpfc_clr_rrq_active(phba, xri, prrq);
5314 * lpfc_els_rsp_echo_acc - Issue echo acc response
5315 * @vport: pointer to a virtual N_Port data structure.
5316 * @data: pointer to echo data to return in the accept.
5317 * @oldiocb: pointer to the original lpfc command iocb data structure.
5318 * @ndlp: pointer to a node-list data structure.
5321 * 0 - Successfully issued acc echo response
5322 * 1 - Failed to issue acc echo response
5325 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5326 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5328 struct lpfc_hba *phba = vport->phba;
5329 struct lpfc_iocbq *elsiocb;
5334 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5336 /* The accumulated length can exceed the BPL_SIZE. For
5337 * now, use this as the limit
5339 if (cmdsize > LPFC_BPL_SIZE)
5340 cmdsize = LPFC_BPL_SIZE;
5341 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5342 ndlp->nlp_DID, ELS_CMD_ACC);
5346 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5347 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5349 /* Xmit ECHO ACC response tag <ulpIoTag> */
5350 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5351 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5352 elsiocb->iotag, elsiocb->iocb.ulpContext);
5353 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5354 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5355 pcmd += sizeof(uint32_t);
5356 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5359 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
5360 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5362 phba->fc_stat.elsXmitACC++;
5363 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5364 elsiocb->context1 = lpfc_nlp_get(ndlp);
5365 if (!elsiocb->context1)
5368 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5369 if (rc == IOCB_ERROR)
5376 lpfc_els_free_iocb(phba, elsiocb);
5381 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5382 * @vport: pointer to a host virtual N_Port data structure.
5384 * This routine issues Address Discover (ADISC) ELS commands to those
5385 * N_Ports which are in node port recovery state and ADISC has not been issued
5386 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5387 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5388 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5389 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5390 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5391 * IOCBs quit for later pick up. On the other hand, after walking through
5392 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5393 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5394 * no more ADISC need to be sent.
5397 * The number of N_Ports with adisc issued.
5400 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5403 struct lpfc_nodelist *ndlp, *next_ndlp;
5406 /* go thru NPR nodes and issue any remaining ELS ADISCs */
5407 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5408 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5409 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5410 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5411 spin_lock_irq(shost->host_lock);
5412 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5413 spin_unlock_irq(shost->host_lock);
5414 ndlp->nlp_prev_state = ndlp->nlp_state;
5415 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5416 lpfc_issue_els_adisc(vport, ndlp, 0);
5418 vport->num_disc_nodes++;
5419 if (vport->num_disc_nodes >=
5420 vport->cfg_discovery_threads) {
5421 spin_lock_irq(shost->host_lock);
5422 vport->fc_flag |= FC_NLP_MORE;
5423 spin_unlock_irq(shost->host_lock);
5428 if (sentadisc == 0) {
5429 spin_lock_irq(shost->host_lock);
5430 vport->fc_flag &= ~FC_NLP_MORE;
5431 spin_unlock_irq(shost->host_lock);
5437 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5438 * @vport: pointer to a host virtual N_Port data structure.
5440 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5441 * which are in node port recovery state, with a @vport. Each time an ELS
5442 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5443 * the per @vport number of discover count (num_disc_nodes) shall be
5444 * incremented. If the num_disc_nodes reaches a pre-configured threshold
5445 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5446 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5447 * later pick up. On the other hand, after walking through all the ndlps with
5448 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5449 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5450 * PLOGI need to be sent.
5453 * The number of N_Ports with plogi issued.
5456 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5459 struct lpfc_nodelist *ndlp, *next_ndlp;
5462 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5463 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5464 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5465 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5466 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5467 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5468 ndlp->nlp_prev_state = ndlp->nlp_state;
5469 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5470 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5472 vport->num_disc_nodes++;
5473 if (vport->num_disc_nodes >=
5474 vport->cfg_discovery_threads) {
5475 spin_lock_irq(shost->host_lock);
5476 vport->fc_flag |= FC_NLP_MORE;
5477 spin_unlock_irq(shost->host_lock);
5483 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5484 "6452 Discover PLOGI %d flag x%x\n",
5485 sentplogi, vport->fc_flag);
5488 lpfc_set_disctmo(vport);
5491 spin_lock_irq(shost->host_lock);
5492 vport->fc_flag &= ~FC_NLP_MORE;
5493 spin_unlock_irq(shost->host_lock);
5499 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5503 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5504 desc->payload.els_req = word0;
5505 desc->length = cpu_to_be32(sizeof(desc->payload));
5507 return sizeof(struct fc_rdp_link_service_desc);
5511 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5512 uint8_t *page_a0, uint8_t *page_a2)
5514 uint16_t wavelength;
5515 uint16_t temperature;
5521 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5522 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5524 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5526 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5527 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5528 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5529 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5531 if ((trasn_code_byte4->fc_sw_laser) ||
5532 (trasn_code_byte5->fc_sw_laser_sl) ||
5533 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5534 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5535 } else if (trasn_code_byte4->fc_lw_laser) {
5536 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5537 page_a0[SSF_WAVELENGTH_B0];
5538 if (wavelength == SFP_WAVELENGTH_LC1310)
5539 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5540 if (wavelength == SFP_WAVELENGTH_LL1550)
5541 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5543 /* check if its SFP+ */
5544 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5545 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5546 << SFP_FLAG_CT_SHIFT;
5548 /* check if its OPTICAL */
5549 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5550 SFP_FLAG_IS_OPTICAL_PORT : 0)
5551 << SFP_FLAG_IS_OPTICAL_SHIFT;
5553 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5554 page_a2[SFF_TEMPERATURE_B0]);
5555 vcc = (page_a2[SFF_VCC_B1] << 8 |
5556 page_a2[SFF_VCC_B0]);
5557 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5558 page_a2[SFF_TXPOWER_B0]);
5559 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5560 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5561 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5562 page_a2[SFF_RXPOWER_B0]);
5563 desc->sfp_info.temperature = cpu_to_be16(temperature);
5564 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5565 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5566 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5567 desc->sfp_info.vcc = cpu_to_be16(vcc);
5569 desc->sfp_info.flags = cpu_to_be16(flag);
5570 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5572 return sizeof(struct fc_rdp_sfp_desc);
5576 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5581 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5583 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5585 desc->info.port_type = cpu_to_be32(type);
5587 desc->info.link_status.link_failure_cnt =
5588 cpu_to_be32(stat->linkFailureCnt);
5589 desc->info.link_status.loss_of_synch_cnt =
5590 cpu_to_be32(stat->lossSyncCnt);
5591 desc->info.link_status.loss_of_signal_cnt =
5592 cpu_to_be32(stat->lossSignalCnt);
5593 desc->info.link_status.primitive_seq_proto_err =
5594 cpu_to_be32(stat->primSeqErrCnt);
5595 desc->info.link_status.invalid_trans_word =
5596 cpu_to_be32(stat->invalidXmitWord);
5597 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5599 desc->length = cpu_to_be32(sizeof(desc->info));
5601 return sizeof(struct fc_rdp_link_error_status_desc);
5605 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5606 struct lpfc_vport *vport)
5610 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5612 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5613 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5614 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5615 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5616 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5617 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5618 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5620 desc->bbc_info.attached_port_bbc = 0;
5623 desc->bbc_info.rtt = 0;
5624 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5626 return sizeof(struct fc_rdp_bbc_desc);
5630 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5631 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5635 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5637 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5638 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5639 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5640 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5642 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5643 flags |= RDP_OET_HIGH_ALARM;
5644 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5645 flags |= RDP_OET_LOW_ALARM;
5646 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5647 flags |= RDP_OET_HIGH_WARNING;
5648 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5649 flags |= RDP_OET_LOW_WARNING;
5651 flags |= ((0xf & RDP_OED_TEMPERATURE) << 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_voltage_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_VOLTAGE_HIGH_ALARM];
5667 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5668 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5669 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5671 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5672 flags |= RDP_OET_HIGH_ALARM;
5673 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5674 flags |= RDP_OET_LOW_ALARM;
5675 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5676 flags |= RDP_OET_HIGH_WARNING;
5677 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5678 flags |= RDP_OET_LOW_WARNING;
5680 flags |= ((0xf & RDP_OED_VOLTAGE) << 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);
5687 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5688 struct fc_rdp_oed_sfp_desc *desc,
5693 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5695 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5696 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5697 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5698 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5700 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5701 flags |= RDP_OET_HIGH_ALARM;
5702 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5703 flags |= RDP_OET_LOW_ALARM;
5704 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5705 flags |= RDP_OET_HIGH_WARNING;
5706 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5707 flags |= RDP_OET_LOW_WARNING;
5709 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5710 desc->oed_info.function_flags = cpu_to_be32(flags);
5711 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5712 return sizeof(struct fc_rdp_oed_sfp_desc);
5716 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5717 struct fc_rdp_oed_sfp_desc *desc,
5722 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5724 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5725 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5726 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5727 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5729 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5730 flags |= RDP_OET_HIGH_ALARM;
5731 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5732 flags |= RDP_OET_LOW_ALARM;
5733 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5734 flags |= RDP_OET_HIGH_WARNING;
5735 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5736 flags |= RDP_OET_LOW_WARNING;
5738 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5739 desc->oed_info.function_flags = cpu_to_be32(flags);
5740 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5741 return sizeof(struct fc_rdp_oed_sfp_desc);
5746 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5747 struct fc_rdp_oed_sfp_desc *desc,
5752 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5754 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5755 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5756 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5757 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5759 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5760 flags |= RDP_OET_HIGH_ALARM;
5761 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5762 flags |= RDP_OET_LOW_ALARM;
5763 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5764 flags |= RDP_OET_HIGH_WARNING;
5765 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5766 flags |= RDP_OET_LOW_WARNING;
5768 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5769 desc->oed_info.function_flags = cpu_to_be32(flags);
5770 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5771 return sizeof(struct fc_rdp_oed_sfp_desc);
5775 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5776 uint8_t *page_a0, struct lpfc_vport *vport)
5778 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5779 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5780 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5781 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5782 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5783 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5784 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5785 return sizeof(struct fc_rdp_opd_sfp_desc);
5789 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5791 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5793 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5795 desc->info.CorrectedBlocks =
5796 cpu_to_be32(stat->fecCorrBlkCount);
5797 desc->info.UncorrectableBlocks =
5798 cpu_to_be32(stat->fecUncorrBlkCount);
5800 desc->length = cpu_to_be32(sizeof(desc->info));
5802 return sizeof(struct fc_fec_rdp_desc);
5806 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5808 uint16_t rdp_cap = 0;
5811 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5813 switch (phba->fc_linkspeed) {
5814 case LPFC_LINK_SPEED_1GHZ:
5815 rdp_speed = RDP_PS_1GB;
5817 case LPFC_LINK_SPEED_2GHZ:
5818 rdp_speed = RDP_PS_2GB;
5820 case LPFC_LINK_SPEED_4GHZ:
5821 rdp_speed = RDP_PS_4GB;
5823 case LPFC_LINK_SPEED_8GHZ:
5824 rdp_speed = RDP_PS_8GB;
5826 case LPFC_LINK_SPEED_10GHZ:
5827 rdp_speed = RDP_PS_10GB;
5829 case LPFC_LINK_SPEED_16GHZ:
5830 rdp_speed = RDP_PS_16GB;
5832 case LPFC_LINK_SPEED_32GHZ:
5833 rdp_speed = RDP_PS_32GB;
5835 case LPFC_LINK_SPEED_64GHZ:
5836 rdp_speed = RDP_PS_64GB;
5839 rdp_speed = RDP_PS_UNKNOWN;
5843 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5845 if (phba->lmt & LMT_128Gb)
5846 rdp_cap |= RDP_PS_128GB;
5847 if (phba->lmt & LMT_64Gb)
5848 rdp_cap |= RDP_PS_64GB;
5849 if (phba->lmt & LMT_32Gb)
5850 rdp_cap |= RDP_PS_32GB;
5851 if (phba->lmt & LMT_16Gb)
5852 rdp_cap |= RDP_PS_16GB;
5853 if (phba->lmt & LMT_10Gb)
5854 rdp_cap |= RDP_PS_10GB;
5855 if (phba->lmt & LMT_8Gb)
5856 rdp_cap |= RDP_PS_8GB;
5857 if (phba->lmt & LMT_4Gb)
5858 rdp_cap |= RDP_PS_4GB;
5859 if (phba->lmt & LMT_2Gb)
5860 rdp_cap |= RDP_PS_2GB;
5861 if (phba->lmt & LMT_1Gb)
5862 rdp_cap |= RDP_PS_1GB;
5865 rdp_cap = RDP_CAP_UNKNOWN;
5866 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5867 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5869 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5870 desc->length = cpu_to_be32(sizeof(desc->info));
5871 return sizeof(struct fc_rdp_port_speed_desc);
5875 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5876 struct lpfc_vport *vport)
5879 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5881 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5882 sizeof(desc->port_names.wwnn));
5884 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5885 sizeof(desc->port_names.wwpn));
5887 desc->length = cpu_to_be32(sizeof(desc->port_names));
5888 return sizeof(struct fc_rdp_port_name_desc);
5892 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5893 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5896 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5897 if (vport->fc_flag & FC_FABRIC) {
5898 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5899 sizeof(desc->port_names.wwnn));
5901 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5902 sizeof(desc->port_names.wwpn));
5903 } else { /* Point to Point */
5904 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5905 sizeof(desc->port_names.wwnn));
5907 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5908 sizeof(desc->port_names.wwpn));
5911 desc->length = cpu_to_be32(sizeof(desc->port_names));
5912 return sizeof(struct fc_rdp_port_name_desc);
5916 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5919 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5920 struct lpfc_vport *vport = ndlp->vport;
5921 struct lpfc_iocbq *elsiocb;
5922 struct ulp_bde64 *bpl;
5925 struct ls_rjt *stat;
5926 struct fc_rdp_res_frame *rdp_res;
5927 uint32_t cmdsize, len;
5931 if (status != SUCCESS)
5934 /* This will change once we know the true size of the RDP payload */
5935 cmdsize = sizeof(struct fc_rdp_res_frame);
5937 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5938 lpfc_max_els_tries, rdp_context->ndlp,
5939 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5941 goto free_rdp_context;
5943 icmd = &elsiocb->iocb;
5944 icmd->ulpContext = rdp_context->rx_id;
5945 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5948 "2171 Xmit RDP response tag x%x xri x%x, "
5949 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5950 elsiocb->iotag, elsiocb->iocb.ulpContext,
5951 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5953 rdp_res = (struct fc_rdp_res_frame *)
5954 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5955 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5956 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5957 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5959 /* Update Alarm and Warning */
5960 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5961 phba->sfp_alarm |= *flag_ptr;
5962 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5963 phba->sfp_warning |= *flag_ptr;
5965 /* For RDP payload */
5967 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5968 (len + pcmd), ELS_CMD_RDP);
5970 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5971 rdp_context->page_a0, rdp_context->page_a2);
5972 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5974 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5975 (len + pcmd), &rdp_context->link_stat);
5976 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5977 (len + pcmd), vport);
5978 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5979 (len + pcmd), vport, ndlp);
5980 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5981 &rdp_context->link_stat);
5982 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5983 &rdp_context->link_stat, vport);
5984 len += lpfc_rdp_res_oed_temp_desc(phba,
5985 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5986 rdp_context->page_a2);
5987 len += lpfc_rdp_res_oed_voltage_desc(phba,
5988 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5989 rdp_context->page_a2);
5990 len += lpfc_rdp_res_oed_txbias_desc(phba,
5991 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5992 rdp_context->page_a2);
5993 len += lpfc_rdp_res_oed_txpower_desc(phba,
5994 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5995 rdp_context->page_a2);
5996 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5997 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5998 rdp_context->page_a2);
5999 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6000 rdp_context->page_a0, vport);
6002 rdp_res->length = cpu_to_be32(len - 8);
6003 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6005 /* Now that we know the true size of the payload, update the BPL */
6006 bpl = (struct ulp_bde64 *)
6007 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6008 bpl->tus.f.bdeSize = len;
6009 bpl->tus.f.bdeFlags = 0;
6010 bpl->tus.w = le32_to_cpu(bpl->tus.w);
6012 phba->fc_stat.elsXmitACC++;
6013 elsiocb->context1 = lpfc_nlp_get(ndlp);
6014 if (!elsiocb->context1) {
6015 lpfc_els_free_iocb(phba, elsiocb);
6016 goto free_rdp_context;
6019 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6020 if (rc == IOCB_ERROR) {
6022 lpfc_els_free_iocb(phba, elsiocb);
6025 goto free_rdp_context;
6028 cmdsize = 2 * sizeof(uint32_t);
6029 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6030 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6032 goto free_rdp_context;
6034 icmd = &elsiocb->iocb;
6035 icmd->ulpContext = rdp_context->rx_id;
6036 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6037 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6039 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6040 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6041 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6043 phba->fc_stat.elsXmitLSRJT++;
6044 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6045 elsiocb->context1 = lpfc_nlp_get(ndlp);
6046 if (!elsiocb->context1) {
6047 lpfc_els_free_iocb(phba, elsiocb);
6048 goto free_rdp_context;
6051 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6052 if (rc == IOCB_ERROR) {
6054 lpfc_els_free_iocb(phba, elsiocb);
6058 /* This reference put is for the original unsolicited RDP. If the
6059 * iocb prep failed, there is no reference to remove.
6066 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6068 LPFC_MBOXQ_t *mbox = NULL;
6071 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6073 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6074 "7105 failed to allocate mailbox memory");
6078 if (lpfc_sli4_dump_page_a0(phba, mbox))
6079 goto prep_mbox_fail;
6080 mbox->vport = rdp_context->ndlp->vport;
6081 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6082 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6083 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6084 if (rc == MBX_NOT_FINISHED)
6085 goto issue_mbox_fail;
6091 mempool_free(mbox, phba->mbox_mem_pool);
6096 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6097 * @vport: pointer to a host virtual N_Port data structure.
6098 * @cmdiocb: pointer to lpfc command iocb data structure.
6099 * @ndlp: pointer to a node-list data structure.
6101 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6102 * IOCB. First, the payload of the unsolicited RDP is checked.
6103 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6104 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6105 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6106 * gather all data and send RDP response.
6109 * 0 - Sent the acc response
6110 * 1 - Sent the reject response.
6113 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6114 struct lpfc_nodelist *ndlp)
6116 struct lpfc_hba *phba = vport->phba;
6117 struct lpfc_dmabuf *pcmd;
6118 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6119 struct fc_rdp_req_frame *rdp_req;
6120 struct lpfc_rdp_context *rdp_context;
6124 if (phba->sli_rev < LPFC_SLI_REV4 ||
6125 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6126 LPFC_SLI_INTF_IF_TYPE_2) {
6127 rjt_err = LSRJT_UNABLE_TPC;
6128 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6132 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6133 rjt_err = LSRJT_UNABLE_TPC;
6134 rjt_expl = LSEXP_REQ_UNSUPPORTED;
6138 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6139 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6141 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6142 "2422 ELS RDP Request "
6143 "dec len %d tag x%x port_id %d len %d\n",
6144 be32_to_cpu(rdp_req->rdp_des_length),
6145 be32_to_cpu(rdp_req->nport_id_desc.tag),
6146 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6147 be32_to_cpu(rdp_req->nport_id_desc.length));
6149 if (sizeof(struct fc_rdp_nport_desc) !=
6150 be32_to_cpu(rdp_req->rdp_des_length))
6152 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6154 if (RDP_NPORT_ID_SIZE !=
6155 be32_to_cpu(rdp_req->nport_id_desc.length))
6157 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6159 rjt_err = LSRJT_UNABLE_TPC;
6163 cmd = &cmdiocb->iocb;
6164 rdp_context->ndlp = lpfc_nlp_get(ndlp);
6165 if (!rdp_context->ndlp) {
6167 rjt_err = LSRJT_UNABLE_TPC;
6170 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6171 rdp_context->rx_id = cmd->ulpContext;
6172 rdp_context->cmpl = lpfc_els_rdp_cmpl;
6173 if (lpfc_get_rdp_info(phba, rdp_context)) {
6174 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6175 "2423 Unable to send mailbox");
6177 rjt_err = LSRJT_UNABLE_TPC;
6185 rjt_err = LSRJT_LOGICAL_ERR;
6188 memset(&stat, 0, sizeof(stat));
6189 stat.un.b.lsRjtRsnCode = rjt_err;
6190 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6191 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6197 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6202 struct lpfc_iocbq *elsiocb;
6203 struct lpfc_nodelist *ndlp;
6204 struct ls_rjt *stat;
6205 union lpfc_sli4_cfg_shdr *shdr;
6206 struct lpfc_lcb_context *lcb_context;
6207 struct fc_lcb_res_frame *lcb_res;
6208 uint32_t cmdsize, shdr_status, shdr_add_status;
6212 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6213 ndlp = lcb_context->ndlp;
6214 pmb->ctx_ndlp = NULL;
6215 pmb->ctx_buf = NULL;
6217 shdr = (union lpfc_sli4_cfg_shdr *)
6218 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6219 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6220 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6222 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6223 "0194 SET_BEACON_CONFIG mailbox "
6224 "completed with status x%x add_status x%x,"
6225 " mbx status x%x\n",
6226 shdr_status, shdr_add_status, mb->mbxStatus);
6228 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6229 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6230 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6231 mempool_free(pmb, phba->mbox_mem_pool);
6235 mempool_free(pmb, phba->mbox_mem_pool);
6236 cmdsize = sizeof(struct fc_lcb_res_frame);
6237 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6238 lpfc_max_els_tries, ndlp,
6239 ndlp->nlp_DID, ELS_CMD_ACC);
6241 /* Decrement the ndlp reference count from previous mbox command */
6245 goto free_lcb_context;
6247 lcb_res = (struct fc_lcb_res_frame *)
6248 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6250 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6251 icmd = &elsiocb->iocb;
6252 icmd->ulpContext = lcb_context->rx_id;
6253 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6255 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6256 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6257 lcb_res->lcb_sub_command = lcb_context->sub_command;
6258 lcb_res->lcb_type = lcb_context->type;
6259 lcb_res->capability = lcb_context->capability;
6260 lcb_res->lcb_frequency = lcb_context->frequency;
6261 lcb_res->lcb_duration = lcb_context->duration;
6262 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6263 phba->fc_stat.elsXmitACC++;
6265 elsiocb->context1 = lpfc_nlp_get(ndlp);
6266 if (!elsiocb->context1)
6269 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6275 lpfc_els_free_iocb(phba, elsiocb);
6281 cmdsize = sizeof(struct fc_lcb_res_frame);
6282 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6283 lpfc_max_els_tries, ndlp,
6284 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6287 goto free_lcb_context;
6289 icmd = &elsiocb->iocb;
6290 icmd->ulpContext = lcb_context->rx_id;
6291 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6292 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6294 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6295 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6296 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6298 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6299 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6301 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6302 phba->fc_stat.elsXmitLSRJT++;
6303 elsiocb->context1 = lpfc_nlp_get(ndlp);
6304 if (!elsiocb->context1) {
6305 lpfc_els_free_iocb(phba, elsiocb);
6306 goto free_lcb_context;
6309 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6310 if (rc == IOCB_ERROR) {
6312 lpfc_els_free_iocb(phba, elsiocb);
6319 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6320 struct lpfc_lcb_context *lcb_context,
6321 uint32_t beacon_state)
6323 struct lpfc_hba *phba = vport->phba;
6324 union lpfc_sli4_cfg_shdr *cfg_shdr;
6325 LPFC_MBOXQ_t *mbox = NULL;
6329 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6333 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6334 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6335 sizeof(struct lpfc_sli4_cfg_mhdr);
6336 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6337 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6338 LPFC_SLI4_MBX_EMBED);
6339 mbox->ctx_ndlp = (void *)lcb_context;
6340 mbox->vport = phba->pport;
6341 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6342 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6343 phba->sli4_hba.physical_port);
6344 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6346 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6349 * Check bv1s bit before issuing the mailbox
6350 * if bv1s == 1, LCB V1 supported
6351 * else, LCB V0 supported
6354 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6355 /* COMMON_SET_BEACON_CONFIG_V1 */
6356 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6357 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6358 bf_set(lpfc_mbx_set_beacon_port_type,
6359 &mbox->u.mqe.un.beacon_config, 0);
6360 bf_set(lpfc_mbx_set_beacon_duration_v1,
6361 &mbox->u.mqe.un.beacon_config,
6362 be16_to_cpu(lcb_context->duration));
6364 /* COMMON_SET_BEACON_CONFIG_V0 */
6365 if (be16_to_cpu(lcb_context->duration) != 0) {
6366 mempool_free(mbox, phba->mbox_mem_pool);
6369 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6370 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6371 bf_set(lpfc_mbx_set_beacon_state,
6372 &mbox->u.mqe.un.beacon_config, beacon_state);
6373 bf_set(lpfc_mbx_set_beacon_port_type,
6374 &mbox->u.mqe.un.beacon_config, 1);
6375 bf_set(lpfc_mbx_set_beacon_duration,
6376 &mbox->u.mqe.un.beacon_config,
6377 be16_to_cpu(lcb_context->duration));
6380 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6381 if (rc == MBX_NOT_FINISHED) {
6382 mempool_free(mbox, phba->mbox_mem_pool);
6391 * lpfc_els_rcv_lcb - Process an unsolicited LCB
6392 * @vport: pointer to a host virtual N_Port data structure.
6393 * @cmdiocb: pointer to lpfc command iocb data structure.
6394 * @ndlp: pointer to a node-list data structure.
6396 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6397 * First, the payload of the unsolicited LCB is checked.
6398 * Then based on Subcommand beacon will either turn on or off.
6401 * 0 - Sent the acc response
6402 * 1 - Sent the reject response.
6405 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6406 struct lpfc_nodelist *ndlp)
6408 struct lpfc_hba *phba = vport->phba;
6409 struct lpfc_dmabuf *pcmd;
6411 struct fc_lcb_request_frame *beacon;
6412 struct lpfc_lcb_context *lcb_context;
6413 u8 state, rjt_err = 0;
6416 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6417 lp = (uint8_t *)pcmd->virt;
6418 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6420 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6421 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6422 "type x%x frequency %x duration x%x\n",
6423 lp[0], lp[1], lp[2],
6424 beacon->lcb_command,
6425 beacon->lcb_sub_command,
6427 beacon->lcb_frequency,
6428 be16_to_cpu(beacon->lcb_duration));
6430 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6431 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6432 rjt_err = LSRJT_CMD_UNSUPPORTED;
6436 if (phba->sli_rev < LPFC_SLI_REV4 ||
6437 phba->hba_flag & HBA_FCOE_MODE ||
6438 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6439 LPFC_SLI_INTF_IF_TYPE_2)) {
6440 rjt_err = LSRJT_CMD_UNSUPPORTED;
6444 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6446 rjt_err = LSRJT_UNABLE_TPC;
6450 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6451 lcb_context->sub_command = beacon->lcb_sub_command;
6452 lcb_context->capability = 0;
6453 lcb_context->type = beacon->lcb_type;
6454 lcb_context->frequency = beacon->lcb_frequency;
6455 lcb_context->duration = beacon->lcb_duration;
6456 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6457 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6458 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6459 if (!lcb_context->ndlp) {
6460 rjt_err = LSRJT_UNABLE_TPC;
6464 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6465 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6466 "0193 failed to send mail box");
6469 rjt_err = LSRJT_UNABLE_TPC;
6474 memset(&stat, 0, sizeof(stat));
6475 stat.un.b.lsRjtRsnCode = rjt_err;
6476 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6482 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6483 * @vport: pointer to a host virtual N_Port data structure.
6485 * This routine cleans up any Registration State Change Notification
6486 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6487 * @vport together with the host_lock is used to prevent multiple thread
6488 * trying to access the RSCN array on a same @vport at the same time.
6491 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6494 struct lpfc_hba *phba = vport->phba;
6497 spin_lock_irq(shost->host_lock);
6498 if (vport->fc_rscn_flush) {
6499 /* Another thread is walking fc_rscn_id_list on this vport */
6500 spin_unlock_irq(shost->host_lock);
6503 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6504 vport->fc_rscn_flush = 1;
6505 spin_unlock_irq(shost->host_lock);
6507 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6508 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6509 vport->fc_rscn_id_list[i] = NULL;
6511 spin_lock_irq(shost->host_lock);
6512 vport->fc_rscn_id_cnt = 0;
6513 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6514 spin_unlock_irq(shost->host_lock);
6515 lpfc_can_disctmo(vport);
6516 /* Indicate we are done walking this fc_rscn_id_list */
6517 vport->fc_rscn_flush = 0;
6521 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6522 * @vport: pointer to a host virtual N_Port data structure.
6523 * @did: remote destination port identifier.
6525 * This routine checks whether there is any pending Registration State
6526 * Configuration Notification (RSCN) to a @did on @vport.
6529 * None zero - The @did matched with a pending rscn
6530 * 0 - not able to match @did with a pending rscn
6533 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6538 uint32_t payload_len, i;
6539 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6541 ns_did.un.word = did;
6543 /* Never match fabric nodes for RSCNs */
6544 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6547 /* If we are doing a FULL RSCN rediscovery, match everything */
6548 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6551 spin_lock_irq(shost->host_lock);
6552 if (vport->fc_rscn_flush) {
6553 /* Another thread is walking fc_rscn_id_list on this vport */
6554 spin_unlock_irq(shost->host_lock);
6557 /* Indicate we are walking fc_rscn_id_list on this vport */
6558 vport->fc_rscn_flush = 1;
6559 spin_unlock_irq(shost->host_lock);
6560 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6561 lp = vport->fc_rscn_id_list[i]->virt;
6562 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6563 payload_len -= sizeof(uint32_t); /* take off word 0 */
6564 while (payload_len) {
6565 rscn_did.un.word = be32_to_cpu(*lp++);
6566 payload_len -= sizeof(uint32_t);
6567 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6568 case RSCN_ADDRESS_FORMAT_PORT:
6569 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6570 && (ns_did.un.b.area == rscn_did.un.b.area)
6571 && (ns_did.un.b.id == rscn_did.un.b.id))
6572 goto return_did_out;
6574 case RSCN_ADDRESS_FORMAT_AREA:
6575 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6576 && (ns_did.un.b.area == rscn_did.un.b.area))
6577 goto return_did_out;
6579 case RSCN_ADDRESS_FORMAT_DOMAIN:
6580 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6581 goto return_did_out;
6583 case RSCN_ADDRESS_FORMAT_FABRIC:
6584 goto return_did_out;
6588 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6589 vport->fc_rscn_flush = 0;
6592 /* Indicate we are done with walking fc_rscn_id_list on this vport */
6593 vport->fc_rscn_flush = 0;
6598 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6599 * @vport: pointer to a host virtual N_Port data structure.
6601 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6602 * state machine for a @vport's nodes that are with pending RSCN (Registration
6603 * State Change Notification).
6606 * 0 - Successful (currently alway return 0)
6609 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6611 struct lpfc_nodelist *ndlp = NULL;
6613 /* Move all affected nodes by pending RSCNs to NPR state. */
6614 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6615 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6616 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6619 /* NVME Target mode does not do RSCN Recovery. */
6620 if (vport->phba->nvmet_support)
6623 /* If we are in the process of doing discovery on this
6624 * NPort, let it continue on its own.
6626 switch (ndlp->nlp_state) {
6627 case NLP_STE_PLOGI_ISSUE:
6628 case NLP_STE_ADISC_ISSUE:
6629 case NLP_STE_REG_LOGIN_ISSUE:
6630 case NLP_STE_PRLI_ISSUE:
6631 case NLP_STE_LOGO_ISSUE:
6635 /* Check to see if we need to NVME rescan this target
6638 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6639 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6640 lpfc_nvme_rescan_port(vport, ndlp);
6642 lpfc_disc_state_machine(vport, ndlp, NULL,
6643 NLP_EVT_DEVICE_RECOVERY);
6644 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6650 * lpfc_send_rscn_event - Send an RSCN event to management application
6651 * @vport: pointer to a host virtual N_Port data structure.
6652 * @cmdiocb: pointer to lpfc command iocb data structure.
6654 * lpfc_send_rscn_event sends an RSCN netlink event to management
6658 lpfc_send_rscn_event(struct lpfc_vport *vport,
6659 struct lpfc_iocbq *cmdiocb)
6661 struct lpfc_dmabuf *pcmd;
6662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6663 uint32_t *payload_ptr;
6664 uint32_t payload_len;
6665 struct lpfc_rscn_event_header *rscn_event_data;
6667 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6668 payload_ptr = (uint32_t *) pcmd->virt;
6669 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6671 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6672 payload_len, GFP_KERNEL);
6673 if (!rscn_event_data) {
6674 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6675 "0147 Failed to allocate memory for RSCN event\n");
6678 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6679 rscn_event_data->payload_length = payload_len;
6680 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6683 fc_host_post_vendor_event(shost,
6684 fc_get_event_number(),
6685 sizeof(struct lpfc_rscn_event_header) + payload_len,
6686 (char *)rscn_event_data,
6689 kfree(rscn_event_data);
6693 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6694 * @vport: pointer to a host virtual N_Port data structure.
6695 * @cmdiocb: pointer to lpfc command iocb data structure.
6696 * @ndlp: pointer to a node-list data structure.
6698 * This routine processes an unsolicited RSCN (Registration State Change
6699 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6700 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6701 * discover state machine is about to begin discovery, it just accepts the
6702 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6703 * contains N_Port IDs for other vports on this HBA, it just accepts the
6704 * RSCN and ignore processing it. If the state machine is in the recovery
6705 * state, the fc_rscn_id_list of this @vport is walked and the
6706 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6707 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6708 * routine is invoked to handle the RSCN event.
6711 * 0 - Just sent the acc response
6712 * 1 - Sent the acc response and waited for name server completion
6715 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6716 struct lpfc_nodelist *ndlp)
6718 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6719 struct lpfc_hba *phba = vport->phba;
6720 struct lpfc_dmabuf *pcmd;
6721 uint32_t *lp, *datap;
6722 uint32_t payload_len, length, nportid, *cmd;
6724 int rscn_id = 0, hba_id = 0;
6727 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6728 lp = (uint32_t *) pcmd->virt;
6730 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6731 payload_len -= sizeof(uint32_t); /* take off word 0 */
6733 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6734 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6735 vport->fc_flag, payload_len, *lp,
6736 vport->fc_rscn_id_cnt);
6738 /* Send an RSCN event to the management application */
6739 lpfc_send_rscn_event(vport, cmdiocb);
6741 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6742 fc_host_post_event(shost, fc_get_event_number(),
6743 FCH_EVT_RSCN, lp[i]);
6745 /* Check if RSCN is coming from a direct-connected remote NPort */
6746 if (vport->fc_flag & FC_PT2PT) {
6747 /* If so, just ACC it, no other action needed for now */
6748 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6749 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6750 *lp, vport->fc_flag, payload_len);
6751 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6753 /* Check to see if we need to NVME rescan this target
6756 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6757 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6758 lpfc_nvme_rescan_port(vport, ndlp);
6762 /* If we are about to begin discovery, just ACC the RSCN.
6763 * Discovery processing will satisfy it.
6765 if (vport->port_state <= LPFC_NS_QRY) {
6766 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6767 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6768 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6770 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6774 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6775 * just ACC and ignore it.
6777 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6778 !(vport->cfg_peer_port_login)) {
6783 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6784 i -= sizeof(uint32_t);
6786 if (lpfc_find_vport_by_did(phba, nportid))
6789 if (rscn_id == hba_id) {
6790 /* ALL NPortIDs in RSCN are on HBA */
6791 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6793 "Data: x%x x%x x%x x%x\n",
6794 vport->fc_flag, payload_len,
6795 *lp, vport->fc_rscn_id_cnt);
6796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6797 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6798 ndlp->nlp_DID, vport->port_state,
6801 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6807 spin_lock_irq(shost->host_lock);
6808 if (vport->fc_rscn_flush) {
6809 /* Another thread is walking fc_rscn_id_list on this vport */
6810 vport->fc_flag |= FC_RSCN_DISCOVERY;
6811 spin_unlock_irq(shost->host_lock);
6813 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6816 /* Indicate we are walking fc_rscn_id_list on this vport */
6817 vport->fc_rscn_flush = 1;
6818 spin_unlock_irq(shost->host_lock);
6819 /* Get the array count after successfully have the token */
6820 rscn_cnt = vport->fc_rscn_id_cnt;
6821 /* If we are already processing an RSCN, save the received
6822 * RSCN payload buffer, cmdiocb->context2 to process later.
6824 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6826 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6827 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6829 spin_lock_irq(shost->host_lock);
6830 vport->fc_flag |= FC_RSCN_DEFERRED;
6832 /* Restart disctmo if its already running */
6833 if (vport->fc_flag & FC_DISC_TMO) {
6834 tmo = ((phba->fc_ratov * 3) + 3);
6835 mod_timer(&vport->fc_disctmo,
6836 jiffies + msecs_to_jiffies(1000 * tmo));
6838 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6839 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6840 vport->fc_flag |= FC_RSCN_MODE;
6841 spin_unlock_irq(shost->host_lock);
6843 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6844 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6847 (payload_len + length <= LPFC_BPL_SIZE)) {
6848 *cmd &= ELS_CMD_MASK;
6849 *cmd |= cpu_to_be32(payload_len + length);
6850 memcpy(((uint8_t *)cmd) + length, lp,
6853 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6854 vport->fc_rscn_id_cnt++;
6855 /* If we zero, cmdiocb->context2, the calling
6856 * routine will not try to free it.
6858 cmdiocb->context2 = NULL;
6861 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6862 "0235 Deferred RSCN "
6863 "Data: x%x x%x x%x\n",
6864 vport->fc_rscn_id_cnt, vport->fc_flag,
6867 vport->fc_flag |= FC_RSCN_DISCOVERY;
6868 spin_unlock_irq(shost->host_lock);
6869 /* ReDiscovery RSCN */
6870 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6871 "0234 ReDiscovery RSCN "
6872 "Data: x%x x%x x%x\n",
6873 vport->fc_rscn_id_cnt, vport->fc_flag,
6876 /* Indicate we are done walking fc_rscn_id_list on this vport */
6877 vport->fc_rscn_flush = 0;
6879 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6880 /* send RECOVERY event for ALL nodes that match RSCN payload */
6881 lpfc_rscn_recovery_check(vport);
6884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6885 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6886 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6888 spin_lock_irq(shost->host_lock);
6889 vport->fc_flag |= FC_RSCN_MODE;
6890 spin_unlock_irq(shost->host_lock);
6891 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6892 /* Indicate we are done walking fc_rscn_id_list on this vport */
6893 vport->fc_rscn_flush = 0;
6895 * If we zero, cmdiocb->context2, the calling routine will
6896 * not try to free it.
6898 cmdiocb->context2 = NULL;
6899 lpfc_set_disctmo(vport);
6901 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6902 /* send RECOVERY event for ALL nodes that match RSCN payload */
6903 lpfc_rscn_recovery_check(vport);
6904 return lpfc_els_handle_rscn(vport);
6908 * lpfc_els_handle_rscn - Handle rscn for a vport
6909 * @vport: pointer to a host virtual N_Port data structure.
6911 * This routine handles the Registration State Configuration Notification
6912 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6913 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6914 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6915 * NameServer shall be issued. If CT command to the NameServer fails to be
6916 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6917 * RSCN activities with the @vport.
6920 * 0 - Cleaned up rscn on the @vport
6921 * 1 - Wait for plogi to name server before proceed
6924 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6926 struct lpfc_nodelist *ndlp;
6927 struct lpfc_hba *phba = vport->phba;
6929 /* Ignore RSCN if the port is being torn down. */
6930 if (vport->load_flag & FC_UNLOADING) {
6931 lpfc_els_flush_rscn(vport);
6935 /* Start timer for RSCN processing */
6936 lpfc_set_disctmo(vport);
6938 /* RSCN processed */
6939 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6940 "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
6941 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6942 vport->port_state, vport->num_disc_nodes,
6945 /* To process RSCN, first compare RSCN data with NameServer */
6946 vport->fc_ns_retry = 0;
6947 vport->num_disc_nodes = 0;
6949 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6950 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6951 /* Good ndlp, issue CT Request to NameServer. Need to
6952 * know how many gidfts were issued. If none, then just
6953 * flush the RSCN. Otherwise, the outstanding requests
6956 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6957 if (lpfc_issue_gidft(vport) > 0)
6959 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6960 if (lpfc_issue_gidpt(vport) > 0)
6966 /* Nameserver login in question. Revalidate. */
6968 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6969 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6971 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6973 lpfc_els_flush_rscn(vport);
6976 ndlp->nlp_prev_state = ndlp->nlp_state;
6977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6979 ndlp->nlp_type |= NLP_FABRIC;
6980 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6981 /* Wait for NameServer login cmpl before we can
6987 lpfc_els_flush_rscn(vport);
6992 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6993 * @vport: pointer to a host virtual N_Port data structure.
6994 * @cmdiocb: pointer to lpfc command iocb data structure.
6995 * @ndlp: pointer to a node-list data structure.
6997 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6998 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6999 * point topology. As an unsolicited FLOGI should not be received in a loop
7000 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7001 * lpfc_check_sparm() routine is invoked to check the parameters in the
7002 * unsolicited FLOGI. If parameters validation failed, the routine
7003 * lpfc_els_rsp_reject() shall be called with reject reason code set to
7004 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7005 * FLOGI shall be compared with the Port WWN of the @vport to determine who
7006 * will initiate PLOGI. The higher lexicographical value party shall has
7007 * higher priority (as the winning port) and will initiate PLOGI and
7008 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7009 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7010 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7013 * 0 - Successfully processed the unsolicited flogi
7014 * 1 - Failed to process the unsolicited flogi
7017 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7018 struct lpfc_nodelist *ndlp)
7020 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7021 struct lpfc_hba *phba = vport->phba;
7022 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7023 uint32_t *lp = (uint32_t *) pcmd->virt;
7024 IOCB_t *icmd = &cmdiocb->iocb;
7025 struct serv_parm *sp;
7029 uint32_t fc_flag = 0;
7030 uint32_t port_state = 0;
7033 sp = (struct serv_parm *) lp;
7035 /* FLOGI received */
7037 lpfc_set_disctmo(vport);
7039 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7040 /* We should never receive a FLOGI in loop mode, ignore it */
7041 did = icmd->un.elsreq64.remoteID;
7043 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7045 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7046 "0113 An FLOGI ELS command x%x was "
7047 "received from DID x%x in Loop Mode\n",
7052 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7055 * If our portname is greater than the remote portname,
7056 * then we initiate Nport login.
7059 rc = memcmp(&vport->fc_portname, &sp->portName,
7060 sizeof(struct lpfc_name));
7063 if (phba->sli_rev < LPFC_SLI_REV4) {
7064 mbox = mempool_alloc(phba->mbox_mem_pool,
7068 lpfc_linkdown(phba);
7069 lpfc_init_link(phba, mbox,
7071 phba->cfg_link_speed);
7072 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7073 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7074 mbox->vport = vport;
7075 rc = lpfc_sli_issue_mbox(phba, mbox,
7077 lpfc_set_loopback_flag(phba);
7078 if (rc == MBX_NOT_FINISHED)
7079 mempool_free(mbox, phba->mbox_mem_pool);
7083 /* abort the flogi coming back to ourselves
7084 * due to external loopback on the port.
7086 lpfc_els_abort_flogi(phba);
7089 } else if (rc > 0) { /* greater than */
7090 spin_lock_irq(shost->host_lock);
7091 vport->fc_flag |= FC_PT2PT_PLOGI;
7092 spin_unlock_irq(shost->host_lock);
7094 /* If we have the high WWPN we can assign our own
7095 * myDID; otherwise, we have to WAIT for a PLOGI
7096 * from the remote NPort to find out what it
7099 vport->fc_myDID = PT2PT_LocalID;
7101 vport->fc_myDID = PT2PT_RemoteID;
7105 * The vport state should go to LPFC_FLOGI only
7106 * AFTER we issue a FLOGI, not receive one.
7108 spin_lock_irq(shost->host_lock);
7109 fc_flag = vport->fc_flag;
7110 port_state = vport->port_state;
7111 vport->fc_flag |= FC_PT2PT;
7112 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7114 /* Acking an unsol FLOGI. Count 1 for link bounce
7117 vport->rcv_flogi_cnt++;
7118 spin_unlock_irq(shost->host_lock);
7119 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7120 "3311 Rcv Flogi PS x%x new PS x%x "
7121 "fc_flag x%x new fc_flag x%x\n",
7122 port_state, vport->port_state,
7123 fc_flag, vport->fc_flag);
7126 * We temporarily set fc_myDID to make it look like we are
7127 * a Fabric. This is done just so we end up with the right
7128 * did / sid on the FLOGI ACC rsp.
7130 did = vport->fc_myDID;
7131 vport->fc_myDID = Fabric_DID;
7133 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7135 /* Defer ACC response until AFTER we issue a FLOGI */
7136 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7137 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7138 phba->defer_flogi_acc_ox_id =
7139 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7141 vport->fc_myDID = did;
7143 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7144 "3344 Deferring FLOGI ACC: rx_id: x%x,"
7145 " ox_id: x%x, hba_flag x%x\n",
7146 phba->defer_flogi_acc_rx_id,
7147 phba->defer_flogi_acc_ox_id, phba->hba_flag);
7149 phba->defer_flogi_acc_flag = true;
7155 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7157 /* Now lets put fc_myDID back to what its supposed to be */
7158 vport->fc_myDID = did;
7164 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7165 * @vport: pointer to a host virtual N_Port data structure.
7166 * @cmdiocb: pointer to lpfc command iocb data structure.
7167 * @ndlp: pointer to a node-list data structure.
7169 * This routine processes Request Node Identification Data (RNID) IOCB
7170 * received as an ELS unsolicited event. Only when the RNID specified format
7171 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7172 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7173 * Accept (ACC) the RNID ELS command. All the other RNID formats are
7174 * rejected by invoking the lpfc_els_rsp_reject() routine.
7177 * 0 - Successfully processed rnid iocb (currently always return 0)
7180 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7181 struct lpfc_nodelist *ndlp)
7183 struct lpfc_dmabuf *pcmd;
7188 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7189 lp = (uint32_t *) pcmd->virt;
7196 switch (rn->Format) {
7198 case RNID_TOPOLOGY_DISC:
7200 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7203 /* Reject this request because format not supported */
7204 stat.un.b.lsRjtRsvd0 = 0;
7205 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7206 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7207 stat.un.b.vendorUnique = 0;
7208 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7215 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7216 * @vport: pointer to a host virtual N_Port data structure.
7217 * @cmdiocb: pointer to lpfc command iocb data structure.
7218 * @ndlp: pointer to a node-list data structure.
7221 * 0 - Successfully processed echo iocb (currently always return 0)
7224 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7225 struct lpfc_nodelist *ndlp)
7229 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7231 /* skip over first word of echo command to find echo data */
7232 pcmd += sizeof(uint32_t);
7234 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7239 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7240 * @vport: pointer to a host virtual N_Port data structure.
7241 * @cmdiocb: pointer to lpfc command iocb data structure.
7242 * @ndlp: pointer to a node-list data structure.
7244 * This routine processes a Link Incident Report Registration(LIRR) IOCB
7245 * received as an ELS unsolicited event. Currently, this function just invokes
7246 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7249 * 0 - Successfully processed lirr iocb (currently always return 0)
7252 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7253 struct lpfc_nodelist *ndlp)
7257 /* For now, unconditionally reject this command */
7258 stat.un.b.lsRjtRsvd0 = 0;
7259 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7260 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7261 stat.un.b.vendorUnique = 0;
7262 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7267 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7268 * @vport: pointer to a host virtual N_Port data structure.
7269 * @cmdiocb: pointer to lpfc command iocb data structure.
7270 * @ndlp: pointer to a node-list data structure.
7272 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7273 * received as an ELS unsolicited event. A request to RRQ shall only
7274 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7275 * Nx_Port N_Port_ID of the target Exchange is the same as the
7276 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7277 * not accepted, an LS_RJT with reason code "Unable to perform
7278 * command request" and reason code explanation "Invalid Originator
7279 * S_ID" shall be returned. For now, we just unconditionally accept
7280 * RRQ from the target.
7283 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7284 struct lpfc_nodelist *ndlp)
7286 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7287 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7288 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7292 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7293 * @phba: pointer to lpfc hba data structure.
7294 * @pmb: pointer to the driver internal queue element for mailbox command.
7296 * This routine is the completion callback function for the MBX_READ_LNK_STAT
7297 * mailbox command. This callback function is to actually send the Accept
7298 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7299 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7300 * mailbox command, constructs the RPS response with the link statistics
7301 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7302 * response to the RPS.
7304 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7305 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7306 * will be stored into the context1 field of the IOCB for the completion
7307 * callback function to the RPS Accept Response ELS IOCB command.
7311 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7316 struct RLS_RSP *rls_rsp;
7318 struct lpfc_iocbq *elsiocb;
7319 struct lpfc_nodelist *ndlp;
7326 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7327 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7328 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7329 pmb->ctx_buf = NULL;
7330 pmb->ctx_ndlp = NULL;
7332 if (mb->mbxStatus) {
7333 mempool_free(pmb, phba->mbox_mem_pool);
7337 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7338 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7339 lpfc_max_els_tries, ndlp,
7340 ndlp->nlp_DID, ELS_CMD_ACC);
7342 /* Decrement the ndlp reference count from previous mbox command */
7346 mempool_free(pmb, phba->mbox_mem_pool);
7350 icmd = &elsiocb->iocb;
7351 icmd->ulpContext = rxid;
7352 icmd->unsli3.rcvsli3.ox_id = oxid;
7354 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7355 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7356 pcmd += sizeof(uint32_t); /* Skip past command */
7357 rls_rsp = (struct RLS_RSP *)pcmd;
7359 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7360 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7361 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7362 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7363 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7364 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7365 mempool_free(pmb, phba->mbox_mem_pool);
7366 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7367 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7368 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7369 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7370 elsiocb->iotag, elsiocb->iocb.ulpContext,
7371 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7373 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7374 phba->fc_stat.elsXmitACC++;
7375 elsiocb->context1 = lpfc_nlp_get(ndlp);
7376 if (!elsiocb->context1)
7379 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7380 if (rc == IOCB_ERROR)
7387 lpfc_els_free_iocb(phba, elsiocb);
7391 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7392 * @vport: pointer to a host virtual N_Port data structure.
7393 * @cmdiocb: pointer to lpfc command iocb data structure.
7394 * @ndlp: pointer to a node-list data structure.
7396 * This routine processes Read Link Status (RLS) IOCB received as an
7397 * ELS unsolicited event. It first checks the remote port state. If the
7398 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7399 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7400 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7401 * for reading the HBA link statistics. It is for the callback function,
7402 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7403 * to actually sending out RPL Accept (ACC) response.
7406 * 0 - Successfully processed rls iocb (currently always return 0)
7409 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7410 struct lpfc_nodelist *ndlp)
7412 struct lpfc_hba *phba = vport->phba;
7416 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7417 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7418 /* reject the unsolicited RLS request and done with it */
7421 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7423 lpfc_read_lnk_stat(phba, mbox);
7424 mbox->ctx_buf = (void *)((unsigned long)
7425 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7426 cmdiocb->iocb.ulpContext)); /* rx_id */
7427 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7428 if (!mbox->ctx_ndlp)
7430 mbox->vport = vport;
7431 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7432 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7433 != MBX_NOT_FINISHED)
7434 /* Mbox completion will send ELS Response */
7436 /* Decrement reference count used for the failed mbox
7441 mempool_free(mbox, phba->mbox_mem_pool);
7444 /* issue rejection response */
7445 stat.un.b.lsRjtRsvd0 = 0;
7446 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7447 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7448 stat.un.b.vendorUnique = 0;
7449 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7454 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7455 * @vport: pointer to a host virtual N_Port data structure.
7456 * @cmdiocb: pointer to lpfc command iocb data structure.
7457 * @ndlp: pointer to a node-list data structure.
7459 * This routine processes Read Timout Value (RTV) IOCB received as an
7460 * ELS unsolicited event. It first checks the remote port state. If the
7461 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7462 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7463 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7464 * Value (RTV) unsolicited IOCB event.
7466 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7467 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7468 * will be stored into the context1 field of the IOCB for the completion
7469 * callback function to the RTV Accept Response ELS IOCB command.
7472 * 0 - Successfully processed rtv iocb (currently always return 0)
7475 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7476 struct lpfc_nodelist *ndlp)
7479 struct lpfc_hba *phba = vport->phba;
7481 struct RTV_RSP *rtv_rsp;
7483 struct lpfc_iocbq *elsiocb;
7487 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7488 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7489 /* reject the unsolicited RTV request and done with it */
7492 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7493 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7494 lpfc_max_els_tries, ndlp,
7495 ndlp->nlp_DID, ELS_CMD_ACC);
7500 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7501 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7502 pcmd += sizeof(uint32_t); /* Skip past command */
7504 /* use the command's xri in the response */
7505 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7506 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7508 rtv_rsp = (struct RTV_RSP *)pcmd;
7510 /* populate RTV payload */
7511 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7512 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7513 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7514 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7515 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7517 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7518 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7519 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7520 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7521 "Data: x%x x%x x%x\n",
7522 elsiocb->iotag, elsiocb->iocb.ulpContext,
7523 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7525 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7526 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7527 phba->fc_stat.elsXmitACC++;
7528 elsiocb->context1 = lpfc_nlp_get(ndlp);
7529 if (!elsiocb->context1) {
7530 lpfc_els_free_iocb(phba, elsiocb);
7534 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7535 if (rc == IOCB_ERROR) {
7537 lpfc_els_free_iocb(phba, elsiocb);
7542 /* issue rejection response */
7543 stat.un.b.lsRjtRsvd0 = 0;
7544 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7545 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7546 stat.un.b.vendorUnique = 0;
7547 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7551 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7552 * @vport: pointer to a host virtual N_Port data structure.
7553 * @ndlp: pointer to a node-list data structure.
7554 * @did: DID of the target.
7555 * @rrq: Pointer to the rrq struct.
7557 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7558 * Successful the the completion handler will clear the RRQ.
7561 * 0 - Successfully sent rrq els iocb.
7562 * 1 - Failed to send rrq els iocb.
7565 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7566 uint32_t did, struct lpfc_node_rrq *rrq)
7568 struct lpfc_hba *phba = vport->phba;
7569 struct RRQ *els_rrq;
7570 struct lpfc_iocbq *elsiocb;
7576 if (ndlp != rrq->ndlp)
7581 /* If ndlp is not NULL, we will bump the reference count on it */
7582 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7583 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7588 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7590 /* For RRQ request, remainder of payload is Exchange IDs */
7591 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7592 pcmd += sizeof(uint32_t);
7593 els_rrq = (struct RRQ *) pcmd;
7595 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7596 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7597 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7598 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7599 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7602 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7603 "Issue RRQ: did:x%x",
7604 did, rrq->xritag, rrq->rxid);
7605 elsiocb->context_un.rrq = rrq;
7606 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7607 elsiocb->context1 = lpfc_nlp_get(ndlp);
7608 if (!elsiocb->context1)
7611 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7612 if (ret == IOCB_ERROR)
7619 lpfc_els_free_iocb(phba, elsiocb);
7624 * lpfc_send_rrq - Sends ELS RRQ if needed.
7625 * @phba: pointer to lpfc hba data structure.
7626 * @rrq: pointer to the active rrq.
7628 * This routine will call the lpfc_issue_els_rrq if the rrq is
7629 * still active for the xri. If this function returns a failure then
7630 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7632 * Returns 0 Success.
7636 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7638 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7643 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7644 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7651 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7652 * @vport: pointer to a host virtual N_Port data structure.
7653 * @cmdsize: size of the ELS command.
7654 * @oldiocb: pointer to the original lpfc command iocb data structure.
7655 * @ndlp: pointer to a node-list data structure.
7657 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7658 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7660 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7661 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7662 * will be stored into the context1 field of the IOCB for the completion
7663 * callback function to the RPL Accept Response ELS command.
7666 * 0 - Successfully issued ACC RPL ELS command
7667 * 1 - Failed to issue ACC RPL ELS command
7670 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7671 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7674 struct lpfc_hba *phba = vport->phba;
7675 IOCB_t *icmd, *oldcmd;
7677 struct lpfc_iocbq *elsiocb;
7680 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7681 ndlp->nlp_DID, ELS_CMD_ACC);
7686 icmd = &elsiocb->iocb;
7687 oldcmd = &oldiocb->iocb;
7688 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7689 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7691 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7692 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7693 pcmd += sizeof(uint16_t);
7694 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7695 pcmd += sizeof(uint16_t);
7697 /* Setup the RPL ACC payload */
7698 rpl_rsp.listLen = be32_to_cpu(1);
7700 rpl_rsp.port_num_blk.portNum = 0;
7701 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7702 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7703 sizeof(struct lpfc_name));
7704 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7705 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7706 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7707 "0120 Xmit ELS RPL ACC response tag x%x "
7708 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7710 elsiocb->iotag, elsiocb->iocb.ulpContext,
7711 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7713 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7714 phba->fc_stat.elsXmitACC++;
7715 elsiocb->context1 = lpfc_nlp_get(ndlp);
7716 if (!elsiocb->context1)
7719 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7720 if (rc == IOCB_ERROR)
7727 lpfc_els_free_iocb(phba, elsiocb);
7732 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7733 * @vport: pointer to a host virtual N_Port data structure.
7734 * @cmdiocb: pointer to lpfc command iocb data structure.
7735 * @ndlp: pointer to a node-list data structure.
7737 * This routine processes Read Port List (RPL) IOCB received as an ELS
7738 * unsolicited event. It first checks the remote port state. If the remote
7739 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7740 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7741 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7742 * to accept the RPL.
7745 * 0 - Successfully processed rpl iocb (currently always return 0)
7748 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7749 struct lpfc_nodelist *ndlp)
7751 struct lpfc_dmabuf *pcmd;
7758 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7759 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7760 /* issue rejection response */
7761 stat.un.b.lsRjtRsvd0 = 0;
7762 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7763 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7764 stat.un.b.vendorUnique = 0;
7765 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7767 /* rejected the unsolicited RPL request and done with it */
7771 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7772 lp = (uint32_t *) pcmd->virt;
7773 rpl = (RPL *) (lp + 1);
7774 maxsize = be32_to_cpu(rpl->maxsize);
7776 /* We support only one port */
7777 if ((rpl->index == 0) &&
7779 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7780 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7782 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7784 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7790 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7791 * @vport: pointer to a virtual N_Port data structure.
7792 * @cmdiocb: pointer to lpfc command iocb data structure.
7793 * @ndlp: pointer to a node-list data structure.
7795 * This routine processes Fibre Channel Address Resolution Protocol
7796 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7797 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7798 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7799 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7800 * remote PortName is compared against the FC PortName stored in the @vport
7801 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7802 * compared against the FC NodeName stored in the @vport data structure.
7803 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7804 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7805 * invoked to send out FARP Response to the remote node. Before sending the
7806 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7807 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7808 * routine is invoked to log into the remote port first.
7811 * 0 - Either the FARP Match Mode not supported or successfully processed
7814 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7815 struct lpfc_nodelist *ndlp)
7817 struct lpfc_dmabuf *pcmd;
7823 icmd = &cmdiocb->iocb;
7824 did = icmd->un.elsreq64.remoteID;
7825 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7826 lp = (uint32_t *) pcmd->virt;
7830 /* FARP-REQ received from DID <did> */
7831 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7832 "0601 FARP-REQ received from DID x%x\n", did);
7833 /* We will only support match on WWPN or WWNN */
7834 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7839 /* If this FARP command is searching for my portname */
7840 if (fp->Mflags & FARP_MATCH_PORT) {
7841 if (memcmp(&fp->RportName, &vport->fc_portname,
7842 sizeof(struct lpfc_name)) == 0)
7846 /* If this FARP command is searching for my nodename */
7847 if (fp->Mflags & FARP_MATCH_NODE) {
7848 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7849 sizeof(struct lpfc_name)) == 0)
7854 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7855 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7856 /* Log back into the node before sending the FARP. */
7857 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7858 ndlp->nlp_prev_state = ndlp->nlp_state;
7859 lpfc_nlp_set_state(vport, ndlp,
7860 NLP_STE_PLOGI_ISSUE);
7861 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7864 /* Send a FARP response to that node */
7865 if (fp->Rflags & FARP_REQUEST_FARPR)
7866 lpfc_issue_els_farpr(vport, did, 0);
7873 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7874 * @vport: pointer to a host virtual N_Port data structure.
7875 * @cmdiocb: pointer to lpfc command iocb data structure.
7876 * @ndlp: pointer to a node-list data structure.
7878 * This routine processes Fibre Channel Address Resolution Protocol
7879 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7880 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7881 * the FARP response request.
7884 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7887 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7888 struct lpfc_nodelist *ndlp)
7890 struct lpfc_dmabuf *pcmd;
7895 icmd = &cmdiocb->iocb;
7896 did = icmd->un.elsreq64.remoteID;
7897 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7898 lp = (uint32_t *) pcmd->virt;
7901 /* FARP-RSP received from DID <did> */
7902 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7903 "0600 FARP-RSP received from DID x%x\n", did);
7904 /* ACCEPT the Farp resp request */
7905 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7911 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7912 * @vport: pointer to a host virtual N_Port data structure.
7913 * @cmdiocb: pointer to lpfc command iocb data structure.
7914 * @fan_ndlp: pointer to a node-list data structure.
7916 * This routine processes a Fabric Address Notification (FAN) IOCB
7917 * command received as an ELS unsolicited event. The FAN ELS command will
7918 * only be processed on a physical port (i.e., the @vport represents the
7919 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7920 * compared against those in the phba data structure. If any of those is
7921 * different, the lpfc_initial_flogi() routine is invoked to initialize
7922 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7923 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7924 * is invoked to register login to the fabric.
7927 * 0 - Successfully processed fan iocb (currently always return 0).
7930 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7931 struct lpfc_nodelist *fan_ndlp)
7933 struct lpfc_hba *phba = vport->phba;
7937 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7938 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7940 /* FAN received; Fan does not have a reply sequence */
7941 if ((vport == phba->pport) &&
7942 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7943 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7944 sizeof(struct lpfc_name))) ||
7945 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7946 sizeof(struct lpfc_name)))) {
7947 /* This port has switched fabrics. FLOGI is required */
7948 lpfc_issue_init_vfi(vport);
7950 /* FAN verified - skip FLOGI */
7951 vport->fc_myDID = vport->fc_prevDID;
7952 if (phba->sli_rev < LPFC_SLI_REV4)
7953 lpfc_issue_fabric_reglogin(vport);
7955 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7956 "3138 Need register VFI: (x%x/%x)\n",
7957 vport->fc_prevDID, vport->fc_myDID);
7958 lpfc_issue_reg_vfi(vport);
7966 * lpfc_els_timeout - Handler funciton to the els timer
7967 * @t: timer context used to obtain the vport.
7969 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7970 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7971 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7972 * up the worker thread. It is for the worker thread to invoke the routine
7973 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7976 lpfc_els_timeout(struct timer_list *t)
7978 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7979 struct lpfc_hba *phba = vport->phba;
7980 uint32_t tmo_posted;
7981 unsigned long iflag;
7983 spin_lock_irqsave(&vport->work_port_lock, iflag);
7984 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7985 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7986 vport->work_port_events |= WORKER_ELS_TMO;
7987 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7989 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7990 lpfc_worker_wake_up(phba);
7996 * lpfc_els_timeout_handler - Process an els timeout event
7997 * @vport: pointer to a virtual N_Port data structure.
7999 * This routine is the actual handler function that processes an ELS timeout
8000 * event. It walks the ELS ring to get and abort all the IOCBs (except the
8001 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
8002 * invoking the lpfc_sli_issue_abort_iotag() routine.
8005 lpfc_els_timeout_handler(struct lpfc_vport *vport)
8007 struct lpfc_hba *phba = vport->phba;
8008 struct lpfc_sli_ring *pring;
8009 struct lpfc_iocbq *tmp_iocb, *piocb;
8011 struct lpfc_dmabuf *pcmd;
8012 uint32_t els_command = 0;
8014 uint32_t remote_ID = 0xffffffff;
8015 LIST_HEAD(abort_list);
8018 timeout = (uint32_t)(phba->fc_ratov << 1);
8020 pring = lpfc_phba_elsring(phba);
8021 if (unlikely(!pring))
8024 if (phba->pport->load_flag & FC_UNLOADING)
8027 spin_lock_irq(&phba->hbalock);
8028 if (phba->sli_rev == LPFC_SLI_REV4)
8029 spin_lock(&pring->ring_lock);
8031 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8034 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
8035 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
8036 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
8039 if (piocb->vport != vport)
8042 pcmd = (struct lpfc_dmabuf *) piocb->context2;
8044 els_command = *(uint32_t *) (pcmd->virt);
8046 if (els_command == ELS_CMD_FARP ||
8047 els_command == ELS_CMD_FARPR ||
8048 els_command == ELS_CMD_FDISC)
8051 if (piocb->drvrTimeout > 0) {
8052 if (piocb->drvrTimeout >= timeout)
8053 piocb->drvrTimeout -= timeout;
8055 piocb->drvrTimeout = 0;
8059 remote_ID = 0xffffffff;
8060 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
8061 remote_ID = cmd->un.elsreq64.remoteID;
8063 struct lpfc_nodelist *ndlp;
8064 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
8066 remote_ID = ndlp->nlp_DID;
8068 list_add_tail(&piocb->dlist, &abort_list);
8070 if (phba->sli_rev == LPFC_SLI_REV4)
8071 spin_unlock(&pring->ring_lock);
8072 spin_unlock_irq(&phba->hbalock);
8074 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8076 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8077 "0127 ELS timeout Data: x%x x%x x%x "
8078 "x%x\n", els_command,
8079 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8080 spin_lock_irq(&phba->hbalock);
8081 list_del_init(&piocb->dlist);
8082 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8083 spin_unlock_irq(&phba->hbalock);
8086 if (!list_empty(&pring->txcmplq))
8087 if (!(phba->pport->load_flag & FC_UNLOADING))
8088 mod_timer(&vport->els_tmofunc,
8089 jiffies + msecs_to_jiffies(1000 * timeout));
8093 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8094 * @vport: pointer to a host virtual N_Port data structure.
8096 * This routine is used to clean up all the outstanding ELS commands on a
8097 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8098 * routine. After that, it walks the ELS transmit queue to remove all the
8099 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8100 * the IOCBs with a non-NULL completion callback function, the callback
8101 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8102 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8103 * callback function, the IOCB will simply be released. Finally, it walks
8104 * the ELS transmit completion queue to issue an abort IOCB to any transmit
8105 * completion queue IOCB that is associated with the @vport and is not
8106 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8107 * part of the discovery state machine) out to HBA by invoking the
8108 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8109 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8110 * the IOCBs are aborted when this function returns.
8113 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8115 LIST_HEAD(abort_list);
8116 struct lpfc_hba *phba = vport->phba;
8117 struct lpfc_sli_ring *pring;
8118 struct lpfc_iocbq *tmp_iocb, *piocb;
8120 unsigned long iflags = 0;
8122 lpfc_fabric_abort_vport(vport);
8125 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8126 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8127 * ultimately grabs the ring_lock, the driver must splice the list into
8128 * a working list and release the locks before calling the abort.
8130 spin_lock_irqsave(&phba->hbalock, iflags);
8131 pring = lpfc_phba_elsring(phba);
8133 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8134 if (unlikely(!pring)) {
8135 spin_unlock_irqrestore(&phba->hbalock, iflags);
8139 if (phba->sli_rev == LPFC_SLI_REV4)
8140 spin_lock(&pring->ring_lock);
8142 /* First we need to issue aborts to outstanding cmds on txcmpl */
8143 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8144 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8147 if (piocb->vport != vport)
8150 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8153 /* On the ELS ring we can have ELS_REQUESTs or
8154 * GEN_REQUESTs waiting for a response.
8157 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8158 list_add_tail(&piocb->dlist, &abort_list);
8160 /* If the link is down when flushing ELS commands
8161 * the firmware will not complete them till after
8162 * the link comes back up. This may confuse
8163 * discovery for the new link up, so we need to
8164 * change the compl routine to just clean up the iocb
8165 * and avoid any retry logic.
8167 if (phba->link_state == LPFC_LINK_DOWN)
8168 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8170 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8171 list_add_tail(&piocb->dlist, &abort_list);
8174 if (phba->sli_rev == LPFC_SLI_REV4)
8175 spin_unlock(&pring->ring_lock);
8176 spin_unlock_irqrestore(&phba->hbalock, iflags);
8178 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8179 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8180 spin_lock_irqsave(&phba->hbalock, iflags);
8181 list_del_init(&piocb->dlist);
8182 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8183 spin_unlock_irqrestore(&phba->hbalock, iflags);
8185 if (!list_empty(&abort_list))
8186 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8187 "3387 abort list for txq not empty\n");
8188 INIT_LIST_HEAD(&abort_list);
8190 spin_lock_irqsave(&phba->hbalock, iflags);
8191 if (phba->sli_rev == LPFC_SLI_REV4)
8192 spin_lock(&pring->ring_lock);
8194 /* No need to abort the txq list,
8195 * just queue them up for lpfc_sli_cancel_iocbs
8197 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8200 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8204 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8205 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8206 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8207 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8208 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8211 if (piocb->vport != vport)
8214 list_del_init(&piocb->list);
8215 list_add_tail(&piocb->list, &abort_list);
8218 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8219 if (vport == phba->pport) {
8220 list_for_each_entry_safe(piocb, tmp_iocb,
8221 &phba->fabric_iocb_list, list) {
8223 list_del_init(&piocb->list);
8224 list_add_tail(&piocb->list, &abort_list);
8228 if (phba->sli_rev == LPFC_SLI_REV4)
8229 spin_unlock(&pring->ring_lock);
8230 spin_unlock_irqrestore(&phba->hbalock, iflags);
8232 /* Cancel all the IOCBs from the completions list */
8233 lpfc_sli_cancel_iocbs(phba, &abort_list,
8234 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8240 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8241 * @phba: pointer to lpfc hba data structure.
8243 * This routine is used to clean up all the outstanding ELS commands on a
8244 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8245 * routine. After that, it walks the ELS transmit queue to remove all the
8246 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8247 * the IOCBs with the completion callback function associated, the callback
8248 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8249 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8250 * callback function associated, the IOCB will simply be released. Finally,
8251 * it walks the ELS transmit completion queue to issue an abort IOCB to any
8252 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8253 * management plane IOCBs that are not part of the discovery state machine)
8254 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8257 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8259 struct lpfc_vport *vport;
8261 spin_lock_irq(&phba->port_list_lock);
8262 list_for_each_entry(vport, &phba->port_list, listentry)
8263 lpfc_els_flush_cmd(vport);
8264 spin_unlock_irq(&phba->port_list_lock);
8270 * lpfc_send_els_failure_event - Posts an ELS command failure event
8271 * @phba: Pointer to hba context object.
8272 * @cmdiocbp: Pointer to command iocb which reported error.
8273 * @rspiocbp: Pointer to response iocb which reported error.
8275 * This function sends an event when there is an ELS command
8279 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8280 struct lpfc_iocbq *cmdiocbp,
8281 struct lpfc_iocbq *rspiocbp)
8283 struct lpfc_vport *vport = cmdiocbp->vport;
8284 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8285 struct lpfc_lsrjt_event lsrjt_event;
8286 struct lpfc_fabric_event_header fabric_event;
8288 struct lpfc_nodelist *ndlp;
8291 ndlp = cmdiocbp->context1;
8295 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8296 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8297 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8298 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8299 sizeof(struct lpfc_name));
8300 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8301 sizeof(struct lpfc_name));
8302 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8303 cmdiocbp->context2)->virt);
8304 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8305 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8306 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8307 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8308 fc_host_post_vendor_event(shost,
8309 fc_get_event_number(),
8310 sizeof(lsrjt_event),
8311 (char *)&lsrjt_event,
8315 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8316 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8317 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8318 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8319 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8321 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8322 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8323 sizeof(struct lpfc_name));
8324 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8325 sizeof(struct lpfc_name));
8326 fc_host_post_vendor_event(shost,
8327 fc_get_event_number(),
8328 sizeof(fabric_event),
8329 (char *)&fabric_event,
8337 * lpfc_send_els_event - Posts unsolicited els event
8338 * @vport: Pointer to vport object.
8339 * @ndlp: Pointer FC node object.
8340 * @payload: ELS command code type.
8342 * This function posts an event when there is an incoming
8343 * unsolicited ELS command.
8346 lpfc_send_els_event(struct lpfc_vport *vport,
8347 struct lpfc_nodelist *ndlp,
8350 struct lpfc_els_event_header *els_data = NULL;
8351 struct lpfc_logo_event *logo_data = NULL;
8352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8354 if (*payload == ELS_CMD_LOGO) {
8355 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8357 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8358 "0148 Failed to allocate memory "
8359 "for LOGO event\n");
8362 els_data = &logo_data->header;
8364 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8367 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8368 "0149 Failed to allocate memory "
8373 els_data->event_type = FC_REG_ELS_EVENT;
8376 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8379 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8382 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8385 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8386 /* Copy the WWPN in the LOGO payload */
8387 memcpy(logo_data->logo_wwpn, &payload[2],
8388 sizeof(struct lpfc_name));
8394 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8395 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8396 if (*payload == ELS_CMD_LOGO) {
8397 fc_host_post_vendor_event(shost,
8398 fc_get_event_number(),
8399 sizeof(struct lpfc_logo_event),
8404 fc_host_post_vendor_event(shost,
8405 fc_get_event_number(),
8406 sizeof(struct lpfc_els_event_header),
8416 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8417 FC_LS_TLV_DTAG_INIT);
8419 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8420 FC_FPIN_LI_EVT_TYPES_INIT);
8423 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8424 * @vport: Pointer to vport object.
8425 * @tlv: Pointer to the Link Integrity Notification Descriptor.
8427 * This function processes a link integrity FPIN event by
8431 lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8433 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8434 const char *li_evt_str;
8437 li_evt = be16_to_cpu(li->event_type);
8438 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8440 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8441 "4680 FPIN Link Integrity %s (x%x) "
8442 "Detecting PN x%016llx Attached PN x%016llx "
8443 "Duration %d mSecs Count %d Port Cnt %d\n",
8445 be64_to_cpu(li->detecting_wwpn),
8446 be64_to_cpu(li->attached_wwpn),
8447 be32_to_cpu(li->event_threshold),
8448 be32_to_cpu(li->event_count),
8449 be32_to_cpu(li->pname_count));
8453 lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8456 struct fc_tlv_desc *tlv;
8457 const char *dtag_nm;
8458 uint32_t desc_cnt = 0, bytes_remain;
8461 /* FPINs handled only if we are in the right discovery state */
8462 if (vport->port_state < LPFC_DISC_AUTH)
8465 /* make sure there is the full fpin header */
8466 if (fpin_length < sizeof(struct fc_els_fpin))
8469 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8470 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8471 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8473 /* process each descriptor */
8474 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8475 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8477 dtag = be32_to_cpu(tlv->desc_tag);
8479 case ELS_DTAG_LNK_INTEGRITY:
8480 lpfc_els_rcv_fpin_li(vport, tlv);
8483 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8484 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8485 "4678 skipped FPIN descriptor[%d]: "
8487 desc_cnt, dtag, dtag_nm);
8492 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8493 tlv = fc_tlv_next_desc(tlv);
8496 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8501 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8502 * @phba: pointer to lpfc hba data structure.
8503 * @pring: pointer to a SLI ring.
8504 * @vport: pointer to a host virtual N_Port data structure.
8505 * @elsiocb: pointer to lpfc els command iocb data structure.
8507 * This routine is used for processing the IOCB associated with a unsolicited
8508 * event. It first determines whether there is an existing ndlp that matches
8509 * the DID from the unsolicited IOCB. If not, it will create a new one with
8510 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8511 * IOCB is then used to invoke the proper routine and to set up proper state
8512 * of the discovery state machine.
8515 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8516 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8518 struct Scsi_Host *shost;
8519 struct lpfc_nodelist *ndlp;
8521 uint32_t *payload, payload_len;
8522 uint32_t cmd, did, newnode;
8523 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8524 IOCB_t *icmd = &elsiocb->iocb;
8527 if (!vport || !(elsiocb->context2))
8531 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8532 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8534 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8535 lpfc_post_buffer(phba, pring, 1);
8537 did = icmd->un.rcvels.remoteID;
8538 if (icmd->ulpStatus) {
8539 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8540 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8541 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8545 /* Check to see if link went down during discovery */
8546 if (lpfc_els_chk_latt(vport))
8549 /* Ignore traffic received during vport shutdown. */
8550 if (vport->load_flag & FC_UNLOADING)
8553 /* If NPort discovery is delayed drop incoming ELS */
8554 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8555 (cmd != ELS_CMD_PLOGI))
8558 ndlp = lpfc_findnode_did(vport, did);
8560 /* Cannot find existing Fabric ndlp, so allocate a new one */
8561 ndlp = lpfc_nlp_init(vport, did);
8564 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8566 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8567 ndlp->nlp_type |= NLP_FABRIC;
8568 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8569 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8573 phba->fc_stat.elsRcvFrame++;
8576 * Do not process any unsolicited ELS commands
8577 * if the ndlp is in DEV_LOSS
8579 shost = lpfc_shost_from_vport(vport);
8580 spin_lock_irq(shost->host_lock);
8581 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8582 spin_unlock_irq(shost->host_lock);
8587 spin_unlock_irq(shost->host_lock);
8589 elsiocb->context1 = lpfc_nlp_get(ndlp);
8590 if (!elsiocb->context1)
8592 elsiocb->vport = vport;
8594 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8595 cmd &= ELS_CMD_MASK;
8597 /* ELS command <elsCmd> received from NPORT <did> */
8598 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8599 "0112 ELS command x%x received from NPORT x%x "
8600 "Data: x%x x%x x%x x%x\n",
8601 cmd, did, vport->port_state, vport->fc_flag,
8602 vport->fc_myDID, vport->fc_prevDID);
8604 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8605 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8606 (cmd != ELS_CMD_FLOGI) &&
8607 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8608 rjt_err = LSRJT_LOGICAL_BSY;
8609 rjt_exp = LSEXP_NOTHING_MORE;
8615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8616 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8617 did, vport->port_state, ndlp->nlp_flag);
8619 phba->fc_stat.elsRcvPLOGI++;
8620 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8621 if (phba->sli_rev == LPFC_SLI_REV4 &&
8622 (phba->pport->fc_flag & FC_PT2PT)) {
8623 vport->fc_prevDID = vport->fc_myDID;
8624 /* Our DID needs to be updated before registering
8625 * the vfi. This is done in lpfc_rcv_plogi but
8626 * that is called after the reg_vfi.
8628 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8629 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8630 "3312 Remote port assigned DID x%x "
8631 "%x\n", vport->fc_myDID,
8635 lpfc_send_els_event(vport, ndlp, payload);
8637 /* If Nport discovery is delayed, reject PLOGIs */
8638 if (vport->fc_flag & FC_DISC_DELAYED) {
8639 rjt_err = LSRJT_UNABLE_TPC;
8640 rjt_exp = LSEXP_NOTHING_MORE;
8644 if (vport->port_state < LPFC_DISC_AUTH) {
8645 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8646 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8647 rjt_err = LSRJT_UNABLE_TPC;
8648 rjt_exp = LSEXP_NOTHING_MORE;
8653 spin_lock_irq(shost->host_lock);
8654 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8655 spin_unlock_irq(shost->host_lock);
8657 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8663 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8664 did, vport->port_state, ndlp->nlp_flag);
8666 phba->fc_stat.elsRcvFLOGI++;
8668 /* If the driver believes fabric discovery is done and is ready,
8669 * bounce the link. There is some descrepancy.
8671 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8672 vport->fc_flag & FC_PT2PT &&
8673 vport->rcv_flogi_cnt >= 1) {
8674 rjt_err = LSRJT_LOGICAL_BSY;
8675 rjt_exp = LSEXP_NOTHING_MORE;
8680 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8686 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8687 did, vport->port_state, ndlp->nlp_flag);
8689 phba->fc_stat.elsRcvLOGO++;
8690 lpfc_send_els_event(vport, ndlp, payload);
8691 if (vport->port_state < LPFC_DISC_AUTH) {
8692 rjt_err = LSRJT_UNABLE_TPC;
8693 rjt_exp = LSEXP_NOTHING_MORE;
8696 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8699 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8700 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8701 did, vport->port_state, ndlp->nlp_flag);
8703 phba->fc_stat.elsRcvPRLO++;
8704 lpfc_send_els_event(vport, ndlp, payload);
8705 if (vport->port_state < LPFC_DISC_AUTH) {
8706 rjt_err = LSRJT_UNABLE_TPC;
8707 rjt_exp = LSEXP_NOTHING_MORE;
8710 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8713 phba->fc_stat.elsRcvLCB++;
8714 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8717 phba->fc_stat.elsRcvRDP++;
8718 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8721 phba->fc_stat.elsRcvRSCN++;
8722 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8728 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8729 did, vport->port_state, ndlp->nlp_flag);
8731 lpfc_send_els_event(vport, ndlp, payload);
8732 phba->fc_stat.elsRcvADISC++;
8733 if (vport->port_state < LPFC_DISC_AUTH) {
8734 rjt_err = LSRJT_UNABLE_TPC;
8735 rjt_exp = LSEXP_NOTHING_MORE;
8738 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8743 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8744 did, vport->port_state, ndlp->nlp_flag);
8746 phba->fc_stat.elsRcvPDISC++;
8747 if (vport->port_state < LPFC_DISC_AUTH) {
8748 rjt_err = LSRJT_UNABLE_TPC;
8749 rjt_exp = LSEXP_NOTHING_MORE;
8752 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8756 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8757 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8758 did, vport->port_state, ndlp->nlp_flag);
8760 phba->fc_stat.elsRcvFARPR++;
8761 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8765 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8766 did, vport->port_state, ndlp->nlp_flag);
8768 phba->fc_stat.elsRcvFARP++;
8769 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8773 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8774 did, vport->port_state, ndlp->nlp_flag);
8776 phba->fc_stat.elsRcvFAN++;
8777 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8780 case ELS_CMD_NVMEPRLI:
8781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8782 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8783 did, vport->port_state, ndlp->nlp_flag);
8785 phba->fc_stat.elsRcvPRLI++;
8786 if ((vport->port_state < LPFC_DISC_AUTH) &&
8787 (vport->fc_flag & FC_FABRIC)) {
8788 rjt_err = LSRJT_UNABLE_TPC;
8789 rjt_exp = LSEXP_NOTHING_MORE;
8792 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8795 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8796 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8797 did, vport->port_state, ndlp->nlp_flag);
8799 phba->fc_stat.elsRcvLIRR++;
8800 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8806 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8807 did, vport->port_state, ndlp->nlp_flag);
8809 phba->fc_stat.elsRcvRLS++;
8810 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8815 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8816 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8817 did, vport->port_state, ndlp->nlp_flag);
8819 phba->fc_stat.elsRcvRPL++;
8820 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8826 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8827 did, vport->port_state, ndlp->nlp_flag);
8829 phba->fc_stat.elsRcvRNID++;
8830 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8835 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8836 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8837 did, vport->port_state, ndlp->nlp_flag);
8838 phba->fc_stat.elsRcvRTV++;
8839 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8844 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8845 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8846 did, vport->port_state, ndlp->nlp_flag);
8848 phba->fc_stat.elsRcvRRQ++;
8849 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8854 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8855 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8856 did, vport->port_state, ndlp->nlp_flag);
8858 phba->fc_stat.elsRcvECHO++;
8859 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8864 /* receive this due to exchange closed */
8865 rjt_err = LSRJT_UNABLE_TPC;
8866 rjt_exp = LSEXP_INVALID_OX_RX;
8869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8870 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8871 did, vport->port_state, ndlp->nlp_flag);
8873 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8876 /* There are no replies, so no rjt codes */
8879 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8880 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8881 cmd, did, vport->port_state);
8883 /* Unsupported ELS command, reject */
8884 rjt_err = LSRJT_CMD_UNSUPPORTED;
8885 rjt_exp = LSEXP_NOTHING_MORE;
8887 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8888 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8889 "0115 Unknown ELS command x%x "
8890 "received from NPORT x%x\n", cmd, did);
8897 /* check if need to LS_RJT received ELS cmd */
8899 memset(&stat, 0, sizeof(stat));
8900 stat.un.b.lsRjtRsnCode = rjt_err;
8901 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8902 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8904 /* Remove the reference from above for new nodes. */
8909 /* Release the reference on this elsiocb, not the ndlp. */
8910 lpfc_nlp_put(elsiocb->context1);
8911 elsiocb->context1 = NULL;
8913 /* Special case. Driver received an unsolicited command that
8914 * unsupportable given the driver's current state. Reset the
8915 * link and start over.
8918 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8921 lpfc_linkdown(phba);
8922 lpfc_init_link(phba, mbox,
8924 phba->cfg_link_speed);
8925 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8926 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8927 mbox->vport = vport;
8928 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8930 mempool_free(mbox, phba->mbox_mem_pool);
8936 if (vport && !(vport->load_flag & FC_UNLOADING))
8937 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8938 "0111 Dropping received ELS cmd "
8939 "Data: x%x x%x x%x\n",
8940 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8941 phba->fc_stat.elsRcvDrop++;
8945 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8946 * @phba: pointer to lpfc hba data structure.
8947 * @pring: pointer to a SLI ring.
8948 * @elsiocb: pointer to lpfc els iocb data structure.
8950 * This routine is used to process an unsolicited event received from a SLI
8951 * (Service Level Interface) ring. The actual processing of the data buffer
8952 * associated with the unsolicited event is done by invoking the routine
8953 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8954 * SLI ring on which the unsolicited event was received.
8957 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8958 struct lpfc_iocbq *elsiocb)
8960 struct lpfc_vport *vport = phba->pport;
8961 IOCB_t *icmd = &elsiocb->iocb;
8963 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8964 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8966 elsiocb->context1 = NULL;
8967 elsiocb->context2 = NULL;
8968 elsiocb->context3 = NULL;
8970 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8971 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8972 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8973 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8974 IOERR_RCV_BUFFER_WAITING) {
8975 phba->fc_stat.NoRcvBuf++;
8976 /* Not enough posted buffers; Try posting more buffers */
8977 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8978 lpfc_post_buffer(phba, pring, 0);
8982 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8983 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8984 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8985 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8986 vport = phba->pport;
8988 vport = lpfc_find_vport_by_vpid(phba,
8989 icmd->unsli3.rcvsli3.vpi);
8992 /* If there are no BDEs associated
8993 * with this IOCB, there is nothing to do.
8995 if (icmd->ulpBdeCount == 0)
8998 /* type of ELS cmd is first 32bit word
9001 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9002 elsiocb->context2 = bdeBuf1;
9004 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
9005 icmd->un.cont64[0].addrLow);
9006 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
9010 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9012 * The different unsolicited event handlers would tell us
9013 * if they are done with "mp" by setting context2 to NULL.
9015 if (elsiocb->context2) {
9016 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
9017 elsiocb->context2 = NULL;
9020 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
9021 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
9022 icmd->ulpBdeCount == 2) {
9023 elsiocb->context2 = bdeBuf2;
9024 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
9025 /* free mp if we are done with it */
9026 if (elsiocb->context2) {
9027 lpfc_in_buf_free(phba, elsiocb->context2);
9028 elsiocb->context2 = NULL;
9034 lpfc_start_fdmi(struct lpfc_vport *vport)
9036 struct lpfc_nodelist *ndlp;
9038 /* If this is the first time, allocate an ndlp and initialize
9039 * it. Otherwise, make sure the node is enabled and then do the
9042 ndlp = lpfc_findnode_did(vport, FDMI_DID);
9044 ndlp = lpfc_nlp_init(vport, FDMI_DID);
9046 ndlp->nlp_type |= NLP_FABRIC;
9052 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9053 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9057 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
9058 * @phba: pointer to lpfc hba data structure.
9059 * @vport: pointer to a virtual N_Port data structure.
9061 * This routine issues a Port Login (PLOGI) to the Name Server with
9062 * State Change Request (SCR) for a @vport. This routine will create an
9063 * ndlp for the Name Server associated to the @vport if such node does
9064 * not already exist. The PLOGI to Name Server is issued by invoking the
9065 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9066 * (FDMI) is configured to the @vport, a FDMI node will be created and
9067 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9070 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9072 struct lpfc_nodelist *ndlp;
9073 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9076 * If lpfc_delay_discovery parameter is set and the clean address
9077 * bit is cleared and fc fabric parameters chenged, delay FC NPort
9080 spin_lock_irq(shost->host_lock);
9081 if (vport->fc_flag & FC_DISC_DELAYED) {
9082 spin_unlock_irq(shost->host_lock);
9083 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9084 "3334 Delay fc port discovery for %d seconds\n",
9086 mod_timer(&vport->delayed_disc_tmo,
9087 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9090 spin_unlock_irq(shost->host_lock);
9092 ndlp = lpfc_findnode_did(vport, NameServer_DID);
9094 ndlp = lpfc_nlp_init(vport, NameServer_DID);
9096 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9097 lpfc_disc_start(vport);
9100 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9101 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9102 "0251 NameServer login: no memory\n");
9107 ndlp->nlp_type |= NLP_FABRIC;
9109 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9111 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9112 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9113 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9114 "0252 Cannot issue NameServer login\n");
9118 if ((phba->cfg_enable_SmartSAN ||
9119 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9120 (vport->load_flag & FC_ALLOW_FDMI))
9121 lpfc_start_fdmi(vport);
9125 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9126 * @phba: pointer to lpfc hba data structure.
9127 * @pmb: pointer to the driver internal queue element for mailbox command.
9129 * This routine is the completion callback function to register new vport
9130 * mailbox command. If the new vport mailbox command completes successfully,
9131 * the fabric registration login shall be performed on physical port (the
9132 * new vport created is actually a physical port, with VPI 0) or the port
9133 * login to Name Server for State Change Request (SCR) will be performed
9134 * on virtual port (real virtual port, with VPI greater than 0).
9137 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9139 struct lpfc_vport *vport = pmb->vport;
9140 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9141 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9142 MAILBOX_t *mb = &pmb->u.mb;
9145 spin_lock_irq(shost->host_lock);
9146 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9147 spin_unlock_irq(shost->host_lock);
9149 if (mb->mbxStatus) {
9150 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9151 "0915 Register VPI failed : Status: x%x"
9152 " upd bit: x%x \n", mb->mbxStatus,
9153 mb->un.varRegVpi.upd);
9154 if (phba->sli_rev == LPFC_SLI_REV4 &&
9155 mb->un.varRegVpi.upd)
9156 goto mbox_err_exit ;
9158 switch (mb->mbxStatus) {
9159 case 0x11: /* unsupported feature */
9160 case 0x9603: /* max_vpi exceeded */
9161 case 0x9602: /* Link event since CLEAR_LA */
9162 /* giving up on vport registration */
9163 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9164 spin_lock_irq(shost->host_lock);
9165 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9166 spin_unlock_irq(shost->host_lock);
9167 lpfc_can_disctmo(vport);
9169 /* If reg_vpi fail with invalid VPI status, re-init VPI */
9171 spin_lock_irq(shost->host_lock);
9172 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9173 spin_unlock_irq(shost->host_lock);
9174 lpfc_init_vpi(phba, pmb, vport->vpi);
9176 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9177 rc = lpfc_sli_issue_mbox(phba, pmb,
9179 if (rc == MBX_NOT_FINISHED) {
9180 lpfc_printf_vlog(vport, KERN_ERR,
9182 "2732 Failed to issue INIT_VPI"
9183 " mailbox command\n");
9190 /* Try to recover from this error */
9191 if (phba->sli_rev == LPFC_SLI_REV4)
9192 lpfc_sli4_unreg_all_rpis(vport);
9193 lpfc_mbx_unreg_vpi(vport);
9194 spin_lock_irq(shost->host_lock);
9195 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9196 spin_unlock_irq(shost->host_lock);
9197 if (mb->mbxStatus == MBX_NOT_FINISHED)
9199 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9200 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9201 if (phba->sli_rev == LPFC_SLI_REV4)
9202 lpfc_issue_init_vfi(vport);
9204 lpfc_initial_flogi(vport);
9206 lpfc_initial_fdisc(vport);
9211 spin_lock_irq(shost->host_lock);
9212 vport->vpi_state |= LPFC_VPI_REGISTERED;
9213 spin_unlock_irq(shost->host_lock);
9214 if (vport == phba->pport) {
9215 if (phba->sli_rev < LPFC_SLI_REV4)
9216 lpfc_issue_fabric_reglogin(vport);
9219 * If the physical port is instantiated using
9220 * FDISC, do not start vport discovery.
9222 if (vport->port_state != LPFC_FDISC)
9223 lpfc_start_fdiscs(phba);
9224 lpfc_do_scr_ns_plogi(phba, vport);
9227 lpfc_do_scr_ns_plogi(phba, vport);
9231 /* Now, we decrement the ndlp reference count held for this
9236 mempool_free(pmb, phba->mbox_mem_pool);
9241 * lpfc_register_new_vport - Register a new vport with a HBA
9242 * @phba: pointer to lpfc hba data structure.
9243 * @vport: pointer to a host virtual N_Port data structure.
9244 * @ndlp: pointer to a node-list data structure.
9246 * This routine registers the @vport as a new virtual port with a HBA.
9247 * It is done through a registering vpi mailbox command.
9250 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9251 struct lpfc_nodelist *ndlp)
9253 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9256 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9258 lpfc_reg_vpi(vport, mbox);
9259 mbox->vport = vport;
9260 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9261 if (!mbox->ctx_ndlp) {
9262 mempool_free(mbox, phba->mbox_mem_pool);
9266 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9267 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9268 == MBX_NOT_FINISHED) {
9269 /* mailbox command not success, decrement ndlp
9270 * reference count for this command
9273 mempool_free(mbox, phba->mbox_mem_pool);
9275 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9276 "0253 Register VPI: Can't send mbox\n");
9280 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9281 "0254 Register VPI: no memory\n");
9287 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9288 spin_lock_irq(shost->host_lock);
9289 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9290 spin_unlock_irq(shost->host_lock);
9295 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9296 * @phba: pointer to lpfc hba data structure.
9298 * This routine cancels the retry delay timers to all the vports.
9301 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9303 struct lpfc_vport **vports;
9304 struct lpfc_nodelist *ndlp;
9305 uint32_t link_state;
9308 /* Treat this failure as linkdown for all vports */
9309 link_state = phba->link_state;
9310 lpfc_linkdown(phba);
9311 phba->link_state = link_state;
9313 vports = lpfc_create_vport_work_array(phba);
9316 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9317 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9319 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9320 lpfc_els_flush_cmd(vports[i]);
9322 lpfc_destroy_vport_work_array(phba, vports);
9327 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9328 * @phba: pointer to lpfc hba data structure.
9330 * This routine abort all pending discovery commands and
9331 * start a timer to retry FLOGI for the physical port
9335 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9337 struct lpfc_nodelist *ndlp;
9338 struct Scsi_Host *shost;
9340 /* Cancel the all vports retry delay retry timers */
9341 lpfc_cancel_all_vport_retry_delay_timer(phba);
9343 /* If fabric require FLOGI, then re-instantiate physical login */
9344 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9348 shost = lpfc_shost_from_vport(phba->pport);
9349 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9350 spin_lock_irq(shost->host_lock);
9351 ndlp->nlp_flag |= NLP_DELAY_TMO;
9352 spin_unlock_irq(shost->host_lock);
9353 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9354 phba->pport->port_state = LPFC_FLOGI;
9359 * lpfc_fabric_login_reqd - Check if FLOGI required.
9360 * @phba: pointer to lpfc hba data structure.
9361 * @cmdiocb: pointer to FDISC command iocb.
9362 * @rspiocb: pointer to FDISC response iocb.
9364 * This routine checks if a FLOGI is reguired for FDISC
9368 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9369 struct lpfc_iocbq *cmdiocb,
9370 struct lpfc_iocbq *rspiocb)
9373 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9374 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9381 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9382 * @phba: pointer to lpfc hba data structure.
9383 * @cmdiocb: pointer to lpfc command iocb data structure.
9384 * @rspiocb: pointer to lpfc response iocb data structure.
9386 * This routine is the completion callback function to a Fabric Discover
9387 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9388 * single threaded, each FDISC completion callback function will reset
9389 * the discovery timer for all vports such that the timers will not get
9390 * unnecessary timeout. The function checks the FDISC IOCB status. If error
9391 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9392 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9393 * assigned to the vport has been changed with the completion of the FDISC
9394 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9395 * are unregistered from the HBA, and then the lpfc_register_new_vport()
9396 * routine is invoked to register new vport with the HBA. Otherwise, the
9397 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9398 * Server for State Change Request (SCR).
9401 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9402 struct lpfc_iocbq *rspiocb)
9404 struct lpfc_vport *vport = cmdiocb->vport;
9405 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9406 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9407 struct lpfc_nodelist *np;
9408 struct lpfc_nodelist *next_np;
9409 IOCB_t *irsp = &rspiocb->iocb;
9410 struct lpfc_iocbq *piocb;
9411 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9412 struct serv_parm *sp;
9413 uint8_t fabric_param_changed;
9415 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9416 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9417 irsp->ulpStatus, irsp->un.ulpWord[4],
9419 /* Since all FDISCs are being single threaded, we
9420 * must reset the discovery timer for ALL vports
9421 * waiting to send FDISC when one completes.
9423 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9424 lpfc_set_disctmo(piocb->vport);
9427 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9428 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9429 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9431 if (irsp->ulpStatus) {
9433 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9434 lpfc_retry_pport_discovery(phba);
9438 /* Check for retry */
9439 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9442 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9443 "0126 FDISC failed. (x%x/x%x)\n",
9444 irsp->ulpStatus, irsp->un.ulpWord[4]);
9447 spin_lock_irq(shost->host_lock);
9448 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9449 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9450 vport->fc_flag |= FC_FABRIC;
9451 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9452 vport->fc_flag |= FC_PUBLIC_LOOP;
9453 spin_unlock_irq(shost->host_lock);
9455 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9456 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9457 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9460 sp = prsp->virt + sizeof(uint32_t);
9461 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9462 memcpy(&vport->fabric_portname, &sp->portName,
9463 sizeof(struct lpfc_name));
9464 memcpy(&vport->fabric_nodename, &sp->nodeName,
9465 sizeof(struct lpfc_name));
9466 if (fabric_param_changed &&
9467 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9468 /* If our NportID changed, we need to ensure all
9469 * remaining NPORTs get unreg_login'ed so we can
9472 list_for_each_entry_safe(np, next_np,
9473 &vport->fc_nodes, nlp_listp) {
9474 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
9475 !(np->nlp_flag & NLP_NPR_ADISC))
9477 spin_lock_irq(shost->host_lock);
9478 np->nlp_flag &= ~NLP_NPR_ADISC;
9479 spin_unlock_irq(shost->host_lock);
9480 lpfc_unreg_rpi(vport, np);
9482 lpfc_cleanup_pending_mbox(vport);
9484 if (phba->sli_rev == LPFC_SLI_REV4)
9485 lpfc_sli4_unreg_all_rpis(vport);
9487 lpfc_mbx_unreg_vpi(vport);
9488 spin_lock_irq(shost->host_lock);
9489 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9490 if (phba->sli_rev == LPFC_SLI_REV4)
9491 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9493 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9494 spin_unlock_irq(shost->host_lock);
9495 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9496 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9498 * Driver needs to re-reg VPI in order for f/w
9499 * to update the MAC address.
9501 lpfc_register_new_vport(phba, vport, ndlp);
9502 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9506 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9507 lpfc_issue_init_vpi(vport);
9508 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9509 lpfc_register_new_vport(phba, vport, ndlp);
9511 lpfc_do_scr_ns_plogi(phba, vport);
9513 /* The FDISC completed successfully. Move the fabric ndlp to
9514 * UNMAPPED state and register with the transport.
9516 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
9520 if (vport->fc_vport &&
9521 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9522 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9523 /* Cancel discovery timer */
9524 lpfc_can_disctmo(vport);
9526 lpfc_els_free_iocb(phba, cmdiocb);
9531 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9532 * @vport: pointer to a virtual N_Port data structure.
9533 * @ndlp: pointer to a node-list data structure.
9534 * @retry: number of retries to the command IOCB.
9536 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9537 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9538 * routine to issue the IOCB, which makes sure only one outstanding fabric
9539 * IOCB will be sent off HBA at any given time.
9541 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9542 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9543 * will be stored into the context1 field of the IOCB for the completion
9544 * callback function to the FDISC ELS command.
9547 * 0 - Successfully issued fdisc iocb command
9548 * 1 - Failed to issue fdisc iocb command
9551 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9554 struct lpfc_hba *phba = vport->phba;
9556 struct lpfc_iocbq *elsiocb;
9557 struct serv_parm *sp;
9560 int did = ndlp->nlp_DID;
9563 vport->port_state = LPFC_FDISC;
9564 vport->fc_myDID = 0;
9565 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9566 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9569 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9570 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9571 "0255 Issue FDISC: no IOCB\n");
9575 icmd = &elsiocb->iocb;
9576 icmd->un.elsreq64.myID = 0;
9577 icmd->un.elsreq64.fl = 1;
9580 * SLI3 ports require a different context type value than SLI4.
9581 * Catch SLI3 ports here and override the prep.
9583 if (phba->sli_rev == LPFC_SLI_REV3) {
9588 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9589 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9590 pcmd += sizeof(uint32_t); /* CSP Word 1 */
9591 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9592 sp = (struct serv_parm *) pcmd;
9593 /* Setup CSPs accordingly for Fabric */
9594 sp->cmn.e_d_tov = 0;
9595 sp->cmn.w2.r_a_tov = 0;
9596 sp->cmn.virtual_fabric_support = 0;
9597 sp->cls1.classValid = 0;
9598 sp->cls2.seqDelivery = 1;
9599 sp->cls3.seqDelivery = 1;
9601 pcmd += sizeof(uint32_t); /* CSP Word 2 */
9602 pcmd += sizeof(uint32_t); /* CSP Word 3 */
9603 pcmd += sizeof(uint32_t); /* CSP Word 4 */
9604 pcmd += sizeof(uint32_t); /* Port Name */
9605 memcpy(pcmd, &vport->fc_portname, 8);
9606 pcmd += sizeof(uint32_t); /* Node Name */
9607 pcmd += sizeof(uint32_t); /* Node Name */
9608 memcpy(pcmd, &vport->fc_nodename, 8);
9609 sp->cmn.valid_vendor_ver_level = 0;
9610 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9611 lpfc_set_disctmo(vport);
9613 phba->fc_stat.elsXmitFDISC++;
9614 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9617 "Issue FDISC: did:x%x",
9620 elsiocb->context1 = lpfc_nlp_get(ndlp);
9621 if (!elsiocb->context1)
9624 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9625 if (rc == IOCB_ERROR) {
9630 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9634 lpfc_els_free_iocb(phba, elsiocb);
9635 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9636 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9637 "0256 Issue FDISC: Cannot send IOCB\n");
9642 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9643 * @phba: pointer to lpfc hba data structure.
9644 * @cmdiocb: pointer to lpfc command iocb data structure.
9645 * @rspiocb: pointer to lpfc response iocb data structure.
9647 * This routine is the completion callback function to the issuing of a LOGO
9648 * ELS command off a vport. It frees the command IOCB and then decrement the
9649 * reference count held on ndlp for this completion function, indicating that
9650 * the reference to the ndlp is no long needed. Note that the
9651 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9652 * callback function and an additional explicit ndlp reference decrementation
9653 * will trigger the actual release of the ndlp.
9656 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9657 struct lpfc_iocbq *rspiocb)
9659 struct lpfc_vport *vport = cmdiocb->vport;
9661 struct lpfc_nodelist *ndlp;
9662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9664 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9665 irsp = &rspiocb->iocb;
9666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9667 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9668 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9670 /* NPIV LOGO completes to NPort <nlp_DID> */
9671 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9672 "2928 NPIV LOGO completes to NPort x%x "
9673 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
9674 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9675 irsp->ulpTimeout, vport->num_disc_nodes,
9676 kref_read(&ndlp->kref), ndlp->nlp_flag,
9677 ndlp->fc4_xpt_flags);
9679 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9680 spin_lock_irq(shost->host_lock);
9681 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9682 vport->fc_flag &= ~FC_FABRIC;
9683 spin_unlock_irq(shost->host_lock);
9684 lpfc_can_disctmo(vport);
9687 /* Safe to release resources now. */
9688 lpfc_els_free_iocb(phba, cmdiocb);
9690 vport->unreg_vpi_cmpl = VPORT_ERROR;
9694 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9695 * @vport: pointer to a virtual N_Port data structure.
9696 * @ndlp: pointer to a node-list data structure.
9698 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9700 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9701 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9702 * will be stored into the context1 field of the IOCB for the completion
9703 * callback function to the LOGO ELS command.
9706 * 0 - Successfully issued logo off the @vport
9707 * 1 - Failed to issue logo off the @vport
9710 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9713 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9714 struct lpfc_hba *phba = vport->phba;
9715 struct lpfc_iocbq *elsiocb;
9719 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9720 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9725 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9726 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9727 pcmd += sizeof(uint32_t);
9729 /* Fill in LOGO payload */
9730 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9731 pcmd += sizeof(uint32_t);
9732 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9735 "Issue LOGO npiv did:x%x flg:x%x",
9736 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9738 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9739 spin_lock_irq(shost->host_lock);
9740 ndlp->nlp_flag |= NLP_LOGO_SND;
9741 spin_unlock_irq(shost->host_lock);
9742 elsiocb->context1 = lpfc_nlp_get(ndlp);
9743 if (!elsiocb->context1)
9745 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9746 if (rc == IOCB_ERROR)
9753 spin_lock_irq(shost->host_lock);
9754 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9755 spin_unlock_irq(shost->host_lock);
9756 lpfc_els_free_iocb(phba, elsiocb);
9761 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9762 * @t: timer context used to obtain the lpfc hba.
9764 * This routine is invoked by the fabric iocb block timer after
9765 * timeout. It posts the fabric iocb block timeout event by setting the
9766 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9767 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9768 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9769 * posted event WORKER_FABRIC_BLOCK_TMO.
9772 lpfc_fabric_block_timeout(struct timer_list *t)
9774 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9775 unsigned long iflags;
9776 uint32_t tmo_posted;
9778 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9779 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9781 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9782 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9785 lpfc_worker_wake_up(phba);
9790 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9791 * @phba: pointer to lpfc hba data structure.
9793 * This routine issues one fabric iocb from the driver internal list to
9794 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9795 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9796 * remove one pending fabric iocb from the driver internal list and invokes
9797 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9800 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9802 struct lpfc_iocbq *iocb;
9803 unsigned long iflags;
9809 spin_lock_irqsave(&phba->hbalock, iflags);
9810 /* Post any pending iocb to the SLI layer */
9811 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9812 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9815 /* Increment fabric iocb count to hold the position */
9816 atomic_inc(&phba->fabric_iocb_count);
9818 spin_unlock_irqrestore(&phba->hbalock, iflags);
9820 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9821 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9822 iocb->iocb_flag |= LPFC_IO_FABRIC;
9824 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9825 "Fabric sched1: ste:x%x",
9826 iocb->vport->port_state, 0, 0);
9828 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9830 if (ret == IOCB_ERROR) {
9831 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9832 iocb->fabric_iocb_cmpl = NULL;
9833 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9835 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9836 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9837 iocb->iocb_cmpl(phba, iocb, iocb);
9839 atomic_dec(&phba->fabric_iocb_count);
9846 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9847 * @phba: pointer to lpfc hba data structure.
9849 * This routine unblocks the issuing fabric iocb command. The function
9850 * will clear the fabric iocb block bit and then invoke the routine
9851 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9852 * from the driver internal fabric iocb list.
9855 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9857 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9859 lpfc_resume_fabric_iocbs(phba);
9864 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9865 * @phba: pointer to lpfc hba data structure.
9867 * This routine blocks the issuing fabric iocb for a specified amount of
9868 * time (currently 100 ms). This is done by set the fabric iocb block bit
9869 * and set up a timeout timer for 100ms. When the block bit is set, no more
9870 * fabric iocb will be issued out of the HBA.
9873 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9877 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9878 /* Start a timer to unblock fabric iocbs after 100ms */
9880 mod_timer(&phba->fabric_block_timer,
9881 jiffies + msecs_to_jiffies(100));
9887 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9888 * @phba: pointer to lpfc hba data structure.
9889 * @cmdiocb: pointer to lpfc command iocb data structure.
9890 * @rspiocb: pointer to lpfc response iocb data structure.
9892 * This routine is the callback function that is put to the fabric iocb's
9893 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9894 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9895 * function first restores and invokes the original iocb's callback function
9896 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9897 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9900 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9901 struct lpfc_iocbq *rspiocb)
9905 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9907 switch (rspiocb->iocb.ulpStatus) {
9908 case IOSTAT_NPORT_RJT:
9909 case IOSTAT_FABRIC_RJT:
9910 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9911 lpfc_block_fabric_iocbs(phba);
9915 case IOSTAT_NPORT_BSY:
9916 case IOSTAT_FABRIC_BSY:
9917 lpfc_block_fabric_iocbs(phba);
9921 stat.un.lsRjtError =
9922 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9923 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9924 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9925 lpfc_block_fabric_iocbs(phba);
9929 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9931 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9932 cmdiocb->fabric_iocb_cmpl = NULL;
9933 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9934 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9936 atomic_dec(&phba->fabric_iocb_count);
9937 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9938 /* Post any pending iocbs to HBA */
9939 lpfc_resume_fabric_iocbs(phba);
9944 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9945 * @phba: pointer to lpfc hba data structure.
9946 * @iocb: pointer to lpfc command iocb data structure.
9948 * This routine is used as the top-level API for issuing a fabric iocb command
9949 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9950 * function makes sure that only one fabric bound iocb will be outstanding at
9951 * any given time. As such, this function will first check to see whether there
9952 * is already an outstanding fabric iocb on the wire. If so, it will put the
9953 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9954 * issued later. Otherwise, it will issue the iocb on the wire and update the
9955 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9957 * Note, this implementation has a potential sending out fabric IOCBs out of
9958 * order. The problem is caused by the construction of the "ready" boolen does
9959 * not include the condition that the internal fabric IOCB list is empty. As
9960 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9961 * ahead of the fabric IOCBs in the internal list.
9964 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9965 * IOCB_ERROR - failed to issue fabric iocb
9968 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9970 unsigned long iflags;
9974 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9976 spin_lock_irqsave(&phba->hbalock, iflags);
9977 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9978 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9981 /* Increment fabric iocb count to hold the position */
9982 atomic_inc(&phba->fabric_iocb_count);
9983 spin_unlock_irqrestore(&phba->hbalock, iflags);
9985 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9986 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9987 iocb->iocb_flag |= LPFC_IO_FABRIC;
9989 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9990 "Fabric sched2: ste:x%x",
9991 iocb->vport->port_state, 0, 0);
9993 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9995 if (ret == IOCB_ERROR) {
9996 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9997 iocb->fabric_iocb_cmpl = NULL;
9998 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9999 atomic_dec(&phba->fabric_iocb_count);
10002 spin_lock_irqsave(&phba->hbalock, iflags);
10003 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
10004 spin_unlock_irqrestore(&phba->hbalock, iflags);
10005 ret = IOCB_SUCCESS;
10011 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
10012 * @vport: pointer to a virtual N_Port data structure.
10014 * This routine aborts all the IOCBs associated with a @vport from the
10015 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10016 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10017 * list, removes each IOCB associated with the @vport off the list, set the
10018 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10019 * associated with the IOCB.
10021 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
10023 LIST_HEAD(completions);
10024 struct lpfc_hba *phba = vport->phba;
10025 struct lpfc_iocbq *tmp_iocb, *piocb;
10027 spin_lock_irq(&phba->hbalock);
10028 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10031 if (piocb->vport != vport)
10034 list_move_tail(&piocb->list, &completions);
10036 spin_unlock_irq(&phba->hbalock);
10038 /* Cancel all the IOCBs from the completions list */
10039 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10040 IOERR_SLI_ABORTED);
10044 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
10045 * @ndlp: pointer to a node-list data structure.
10047 * This routine aborts all the IOCBs associated with an @ndlp from the
10048 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10049 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10050 * list, removes each IOCB associated with the @ndlp off the list, set the
10051 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10052 * associated with the IOCB.
10054 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10056 LIST_HEAD(completions);
10057 struct lpfc_hba *phba = ndlp->phba;
10058 struct lpfc_iocbq *tmp_iocb, *piocb;
10059 struct lpfc_sli_ring *pring;
10061 pring = lpfc_phba_elsring(phba);
10063 if (unlikely(!pring))
10066 spin_lock_irq(&phba->hbalock);
10067 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10069 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10071 list_move_tail(&piocb->list, &completions);
10074 spin_unlock_irq(&phba->hbalock);
10076 /* Cancel all the IOCBs from the completions list */
10077 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10078 IOERR_SLI_ABORTED);
10082 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
10083 * @phba: pointer to lpfc hba data structure.
10085 * This routine aborts all the IOCBs currently on the driver internal
10086 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10087 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10088 * list, removes IOCBs off the list, set the status feild to
10089 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10092 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10094 LIST_HEAD(completions);
10096 spin_lock_irq(&phba->hbalock);
10097 list_splice_init(&phba->fabric_iocb_list, &completions);
10098 spin_unlock_irq(&phba->hbalock);
10100 /* Cancel all the IOCBs from the completions list */
10101 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10102 IOERR_SLI_ABORTED);
10106 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10107 * @vport: pointer to lpfc vport data structure.
10109 * This routine is invoked by the vport cleanup for deletions and the cleanup
10110 * for an ndlp on removal.
10113 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10115 struct lpfc_hba *phba = vport->phba;
10116 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10117 unsigned long iflag = 0;
10119 spin_lock_irqsave(&phba->hbalock, iflag);
10120 spin_lock(&phba->sli4_hba.sgl_list_lock);
10121 list_for_each_entry_safe(sglq_entry, sglq_next,
10122 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10123 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
10124 lpfc_nlp_put(sglq_entry->ndlp);
10125 sglq_entry->ndlp = NULL;
10128 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10129 spin_unlock_irqrestore(&phba->hbalock, iflag);
10134 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10135 * @phba: pointer to lpfc hba data structure.
10136 * @axri: pointer to the els xri abort wcqe structure.
10138 * This routine is invoked by the worker thread to process a SLI4 slow-path
10142 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10143 struct sli4_wcqe_xri_aborted *axri)
10145 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10146 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10149 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10150 unsigned long iflag = 0;
10151 struct lpfc_nodelist *ndlp;
10152 struct lpfc_sli_ring *pring;
10154 pring = lpfc_phba_elsring(phba);
10156 spin_lock_irqsave(&phba->hbalock, iflag);
10157 spin_lock(&phba->sli4_hba.sgl_list_lock);
10158 list_for_each_entry_safe(sglq_entry, sglq_next,
10159 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10160 if (sglq_entry->sli4_xritag == xri) {
10161 list_del(&sglq_entry->list);
10162 ndlp = sglq_entry->ndlp;
10163 sglq_entry->ndlp = NULL;
10164 list_add_tail(&sglq_entry->list,
10165 &phba->sli4_hba.lpfc_els_sgl_list);
10166 sglq_entry->state = SGL_FREED;
10167 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10168 spin_unlock_irqrestore(&phba->hbalock, iflag);
10171 lpfc_set_rrq_active(phba, ndlp,
10172 sglq_entry->sli4_lxritag,
10174 lpfc_nlp_put(ndlp);
10177 /* Check if TXQ queue needs to be serviced */
10178 if (pring && !list_empty(&pring->txq))
10179 lpfc_worker_wake_up(phba);
10183 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10184 lxri = lpfc_sli4_xri_inrange(phba, xri);
10185 if (lxri == NO_XRI) {
10186 spin_unlock_irqrestore(&phba->hbalock, iflag);
10189 spin_lock(&phba->sli4_hba.sgl_list_lock);
10190 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10191 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10192 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10193 spin_unlock_irqrestore(&phba->hbalock, iflag);
10196 sglq_entry->state = SGL_XRI_ABORTED;
10197 spin_unlock(&phba->sli4_hba.sgl_list_lock);
10198 spin_unlock_irqrestore(&phba->hbalock, iflag);
10202 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10203 * @vport: pointer to virtual port object.
10204 * @ndlp: nodelist pointer for the impacted node.
10206 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10207 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10208 * the driver is required to send a LOGO to the remote node before it
10209 * attempts to recover its login to the remote node.
10212 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10213 struct lpfc_nodelist *ndlp)
10215 struct Scsi_Host *shost;
10216 struct lpfc_hba *phba;
10217 unsigned long flags = 0;
10219 shost = lpfc_shost_from_vport(vport);
10220 phba = vport->phba;
10221 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10222 lpfc_printf_log(phba, KERN_INFO,
10223 LOG_SLI, "3093 No rport recovery needed. "
10224 "rport in state 0x%x\n", ndlp->nlp_state);
10227 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10228 "3094 Start rport recovery on shost id 0x%x "
10229 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10231 shost->host_no, ndlp->nlp_DID,
10232 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10235 * The rport is not responding. Remove the FCP-2 flag to prevent
10236 * an ADISC in the follow-up recovery code.
10238 spin_lock_irqsave(shost->host_lock, flags);
10239 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10240 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10241 spin_unlock_irqrestore(shost->host_lock, flags);
10242 lpfc_unreg_rpi(vport, ndlp);